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.

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG. Scheduling and the real world<br />

Rescheduling — hardware interrupts<br />

Rescheduling due to a hardware interrupt occurs in two cases:<br />

• timers<br />

• other hardware<br />

Rescheduling — kernel calls<br />

The realtime clock generates periodic interrupts for the kernel, causing time-based<br />

rescheduling.<br />

For example, if you issue a sleep (10); call, a number of realtime clock interrupts<br />

will occur; the kernel increments the time-of-day clock at each interrupt. When the<br />

time-of-day clock indicates that 10 seconds have elapsed, the kernel reschedules your<br />

thread as READY.<br />

(This is discussed in more detail in the Clocks, Timers, and <strong>Getting</strong> a Kick Every So<br />

Often chapter.)<br />

Other threads might wait for hardware interrupts from peripherals, such as the serial<br />

port, a hard disk, or an audio card. In this case, they are blocked in the kernel waiting<br />

for a hardware interrupt; the thread will be rescheduled by the kernel only after that<br />

“event” is generated.<br />

If the rescheduling is caused by a thread issuing a kernel call, the rescheduling is done<br />

immediately and can be considered asynchronous to the timer and other interrupts.<br />

For example, above we called sleep(10);. This C library function is eventually<br />

translated into a kernel call. At that point, the kernel made a rescheduling decision to<br />

take your thread off of the READY queue for that priority, and then schedule another<br />

thread that was READY.<br />

There are many kernel calls that cause a process to be rescheduled. Most of them are<br />

fairly obvious. Here are a few:<br />

• timer functions (e.g., sleep())<br />

Rescheduling — exceptions<br />

• messaging functions (e.g., MsgSendv())<br />

• thread primitives, (e.g., pthread_cancel(), pthread_join())<br />

The final cause of rescheduling, a CPU fault, is an exception, somewhere between a<br />

hardware interrupt and a kernel call. It operates asynchronously to the kernel (like an<br />

interrupt) but operates synchronously <strong>with</strong> the user code that caused it (like a kernel<br />

call — for example, a divide-by-zero exception). The same discussion as above (for<br />

hardware interrupts and kernel calls) applies to faults.<br />

April 30, 2009 Chapter 1 • Processes and Threads 77

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

Saved successfully!

Ooh no, something went wrong!