30.12.2012 Views

30°C Power On 12 to 36 watts - for fanless sealed system design ...

30°C Power On 12 to 36 watts - for fanless sealed system design ...

30°C Power On 12 to 36 watts - for fanless sealed system design ...

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.

ESE Magazine Jan/Feb 06 <br />

<strong>36</strong><br />

Minimizing interrupt<br />

response time: 4 simple rules<br />

David Kleidermacher, Green Hills Software, Inc. <br />

A failure <strong>to</strong> meet a response time requirement in a real-time <strong>system</strong> can<br />

be catastrophic. Sound programming coupled with proper RTOS interrupt<br />

architecture can ensure a minimal yet guaranteed worst case response time.<br />

1. Keep interrupt service<br />

routines (ISRs) short<br />

Avoid loops and other constructs which increase<br />

latency. When an interrupt fires, the microprocessor<br />

typically disables interrupts be<strong>for</strong>e<br />

executing the ISR. By keeping ISRs simple,<br />

developers avoid the common pitfall of leaving<br />

interrupts disabled <strong>for</strong> <strong>to</strong>o long, increasing the<br />

latency of higher priority interrupts.<br />

2. Do not disable interrupts<br />

A major contribu<strong>to</strong>r <strong>to</strong> increased latency is the<br />

number and length of regions in which the operating<br />

<strong>system</strong> disables interrupts. By disabling<br />

interrupts, the kernel increases latency of high<br />

priority events that arrive in those disabling windows.<br />

Most operating <strong>system</strong>s employ what we<br />

call a Simple architecture, which is easy <strong>to</strong><br />

implement: in order <strong>to</strong> prevent preemption, the<br />

kernel disables interrupts <strong>for</strong> the duration of the<br />

critical section<br />

By disabling interrupts, the Simple RTOS is<br />

sacrificing the latency of the highest priority<br />

event <strong>to</strong> avoid problems caused by handling of<br />

lower priority interrupts. A better solution,<br />

implemented in the Advanced architecture, is <strong>to</strong><br />

never disable interrupts in kernel service calls.<br />

Not only does the Advanced RTOS guarantee<br />

the minimum possible latency <strong>for</strong> the highest<br />

priority interrupt, but also the worst case latency<br />

can be trivially proven.<br />

3. Avoid improper use of operating<br />

<strong>system</strong> API calls in ISRs<br />

ISRs commonly do not require kernel API<br />

access: the ISR per<strong>for</strong>ms basic operations<br />

be<strong>for</strong>e acknowledging the interrupt and<br />

returning. A more complex ISR is required <strong>to</strong><br />

wake up a thread, such as by releasing a<br />

semaphore, <strong>for</strong> higher level processing. The<br />

RTOS vendor should limit ISRs <strong>to</strong> a small set<br />

of service calls that are necessary and deterministic.<br />

As an example of the peril regarding API<br />

usage in ISRs, consider a queue of threads<br />

waiting <strong>for</strong> a resource (e.g. a semaphore).<br />

Many Simple RTOSes use an ordinary linked<br />

list <strong>to</strong> hold the queue of threads. When the<br />

resource becomes available, the first thread,<br />

regardless of its importance relative <strong>to</strong> other<br />

waiters, is provided the resource. In contrast,<br />

the Advanced RTOS au<strong>to</strong>matically wakes up<br />

the highest priority waiting thread. Some<br />

Simple RTOSes have a service call that pulls<br />

the highest priority thread out of the queue and<br />

jams it on<strong>to</strong> the front. <strong>On</strong>e problem with this<br />

approach is its usability: the developer must<br />

remember <strong>to</strong> insert prioritisation calls and<br />

determine where in the code they belong.<br />

Worse, the RTOS must search linearly through<br />

the unordered list <strong>to</strong> find the highest priority<br />

thread; real-time behaviour is lost.<br />

The Advanced architecture provides a second-level<br />

handler, sometimes termed a callback,<br />

<strong>to</strong> per<strong>for</strong>m higher level processing<br />

when the kernel has returned <strong>to</strong> a consistent<br />

state. If the developer must add a callback in<br />

the ISR and then write code in the callback <strong>to</strong><br />

do the service call, this makes programming<br />

more difficult. Not <strong>to</strong> worry: the Advanced<br />

RTOS hides the details of two-level handling<br />

by allowing the use of a standard API call<br />

which places the callback on behalf of the<br />

programmer.<br />

There are some important advantages <strong>to</strong> the<br />

Advanced architecture’s optional two-level handler.<br />

By pushing work in<strong>to</strong> the callback (where<br />

interrupts are enabled), the Advanced RTOS<br />

reduces the temporal footprint of the ISR, in turn<br />

reducing the latency <strong>for</strong> higher priority interrupts<br />

(Figure 1). Note that the overhead of the twolevel<br />

handling is negligible: a callback entails<br />

merely placing a function address on a list <strong>for</strong><br />

the kernel <strong>to</strong> call; no heavyweight processing or<br />

memory is required.<br />

4. Properly prioritise interrupts<br />

relative <strong>to</strong> threads<br />

When a thread is awakened <strong>for</strong> higher level processing<br />

of the most important event, this thread<br />

becomes the most important thread in the <strong>system</strong>.<br />

The thread must complete its processing<br />

within a fixed period of time.<br />

In the Simple RTOS, the thread runs with all<br />

interrupts enabled. Any low priority interrupt can<br />

fire, delaying the most important thread and<br />

Figure 1: Reducing latency <strong>for</strong> higher<br />

priority interrupts.<br />

Figure 2: Minimum response time <strong>for</strong> events.<br />

causing missed deadlines. In fact, since interrupts<br />

may nest, multiple events, and all of their<br />

associated ISR processing, could delay this high<br />

priority processing by an unpredictable length of<br />

time.<br />

The Advanced RTOS allows interrupts <strong>to</strong> be<br />

prioritised relative <strong>to</strong> threads. When a high priority<br />

thread is awakened during interrupt processing,<br />

the kernel inhibits lower priority interrupts<br />

when switching <strong>to</strong> the high priority thread.<br />

When the high priority thread completes its<br />

work, the kernel reenables lower priority interrupts.<br />

This architecture guarantees the minimum<br />

thread response time <strong>for</strong> the highest priority<br />

real-time events (Figure 2).<br />

Complex embedded <strong>system</strong>s, with multiple<br />

concurrent tasks and interrupt sources, pose a<br />

challenge <strong>for</strong> RTOS interrupt handling architecture.<br />

Developers will achieve the best interrupt<br />

response time by following a few simple rules<br />

and employing an RTOS with an Advanced interrupt<br />

architecture. <br />

www.ghs.com

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

Saved successfully!

Ooh no, something went wrong!