26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The kernel’s role<br />

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG.<br />

Running<br />

255<br />

D<br />

10<br />

B<br />

Priority<br />

5<br />

A<br />

Blocked<br />

0<br />

C<br />

Two threads on the READY queue, one blocked, one running.<br />

This shows the kernel’s internal READY queue, which the kernel uses to decide who<br />

to schedule next. Note that thread “C” is not on the READY queue, because it’s<br />

blocked, and thread “D” isn’t on the READY queue either because it’s running.<br />

Round Robin<br />

The RR scheduling algorithm is identical to FIFO, except that the thread will not run<br />

forever if there’s another thread at the same priority. It runs only for a system-defined<br />

timeslice whose value you can determine by using the function<br />

sched_rr_get_interval(). The timeslice is usually 4 ms, but it’s actually 4 times the<br />

ticksize, which you can query or set <strong>with</strong> ClockPeriod().<br />

What happens is that the kernel starts an RR thread, and notes the time. If the RR<br />

thread is running for a while, the time allotted to it will be up (the timeslice will have<br />

expired). The kernel looks to see if there is another thread at the same priority that’s<br />

ready. If there is, the kernel runs it. If not, then the kernel will continue running the<br />

RR thread (i.e., the kernel grants the thread another timeslice).<br />

The rules<br />

Let’s summarize the scheduling rules (for a single CPU), in order of importance:<br />

• Only one thread can run at a time.<br />

• The highest-priority ready thread will run.<br />

• A thread will run until it blocks or exits.<br />

• An RR thread will run for its timeslice, and then the kernel will reschedule it (if<br />

required).<br />

22 Chapter 1 • Processes and Threads April 30, 2009

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!