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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

<strong>Neutrino</strong> and interrupts<br />

In this section, we’ll take a look at interrupts, how we deal <strong>with</strong> them under <strong>Neutrino</strong>,<br />

their impact on scheduling and realtime, and some interrupt-management strategies.<br />

The first thing we need to ask is, “What’s an interrupt?”<br />

An interrupt is exactly what it sounds like — an interruption of whatever was going on<br />

and a diversion to another task.<br />

For example, suppose you’re sitting at your desk working on job “A.” Suddenly, the<br />

phone rings. A Very Important Customer (VIC) needs you to immediately answer<br />

some skill-testing question. When you’ve answered the question, you may go back to<br />

working on job “A,” or the VIC may have changed your priorities so that you push job<br />

“A” off to the side and immediately start on job “B.”<br />

Now let’s put that into perspective under <strong>Neutrino</strong>.<br />

At any moment in time, the processor is busy processing the work for the<br />

highest-priority READY thread (this will be a thread that’s in the RUNNING state). To<br />

cause an interrupt, a piece of hardware on the computer’s bus asserts an interrupt line<br />

(in our analogy, this was the phone ringing).<br />

As soon as the interrupt line is asserted, the kernel jumps to a piece of code that sets<br />

up the environment to run an interrupt service routine (ISR), a piece of software that<br />

determines what should happen when that interrupt is detected.<br />

The amount of time that elapses between the time that the interrupt line is asserted by<br />

the hardware and the first instruction of the ISR being executed is called the interrupt<br />

latency. Interrupt latency is measured in microseconds. Different processors have<br />

different interrupt latency times; it’s a function of the processor speed, cache<br />

architecture, memory speed, and, of course, the efficiency of the operating system.<br />

In our analogy, if you’re listening to some music in your headphones and ignoring the<br />

ringing phone, it will take you longer to notice this phone “interrupt.” Under <strong>Neutrino</strong>,<br />

the same thing can happen; there’s a processor instruction that disables interrupts (cli<br />

on the x86, for example). The processor won’t notice any interrupts until it reenables<br />

interrupts (on the x86, this is the sti opcode).<br />

To avoid CPU-specific assembly language calls, <strong>Neutrino</strong> provides the following calls:<br />

InterruptEnable() and InterruptDisable(), and InterruptLock() and InterruptUnlock().<br />

These take care of all the low-level details on all supported platforms.<br />

The ISR usually performs the minimum amount of work possible, and then ends (in<br />

our analogy, this was the conversation on the telephone <strong>with</strong> the VIC — we usually<br />

don’t put the customer on hold and do several hours of work; we just tell the customer,<br />

“Okay, I’ll get right on that!”). When the ISR ends, it can tell the kernel either that<br />

nothing should happen (meaning the ISR has completely handled the event and<br />

nothing else needs to be done about it) or that the kernel should perform some action<br />

that might cause a thread to become READY.<br />

April 30, 2009 Chapter 4 • Interrupts 169

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

Saved successfully!

Ooh no, something went wrong!