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.

TIME<br />

TIME<br />

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

(like “faster” or “better”) probably won’t suffice. We’ll need to look at a few pictures<br />

and scenarios.<br />

Here’s what happens when we use InterruptAttach():<br />

Interrupt<br />

thread 1<br />

kernel<br />

ISR<br />

kernel<br />

(resched)<br />

thread 2<br />

Control flow <strong>with</strong> InterruptAttach().<br />

The thread that’s currently running (“thread1”) gets interrupted, and we go into the<br />

kernel. The kernel saves the context of “thread1.” The kernel then does a lookup to see<br />

who’s responsible for handling the interrupt and decides that “ISR1” is responsible. At<br />

this point, the kernel sets up the context for “ISR1” and transfers control. “ISR1”<br />

looks at the hardware and decides to return a struct sigevent. The kernel notices<br />

the return value, figures out who needs to handle it, and makes them READY. This<br />

may cause the kernel to schedule a different thread to run, “thread2.”<br />

Now, let’s contrast that <strong>with</strong> what happens when we use InterruptAttachEvent():<br />

Interrupt<br />

thread 1<br />

kernel<br />

(resched)<br />

thread 2<br />

Control flow <strong>with</strong> InterruptAttachEvent().<br />

In this case, the servicing path is much shorter. We made one context switch from the<br />

currently running thread (“thread1”) into the kernel. Instead of doing another context<br />

switch into the ISR, the kernel simply “pretended” that the ISR returned a struct<br />

sigevent and acted on it, rescheduling “thread2” to run.<br />

Now you’re thinking, “Great! I’m going to forget all about InterruptAttach() and just<br />

use the easier InterruptAttachEvent().”<br />

April 30, 2009 Chapter 4 • Interrupts 183

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

Saved successfully!

Ooh no, something went wrong!