Software Interrupts
Thread Scheduling 4-35
Figure 4-10. Using SWI_dec to Post an SWI
4.3.6 Benefits and Tradeoffs
There are two main benefits to using software interrupts instead of hardware
interrupts.
First, SWI handlers can execute with all hardware interrupts enabled. To
understand this advantage, recall that a typical HWI modifies a data structure
that is also accessed by tasks. Tasks therefore need to disable hardware
interrupts when they wish to access these data structures in a mutually
exclusive way. Obviously, disabling hardware interrupts always has the
potential to degrade the performance of a real-time system.
Conversely, if a shared data structure is modified by an SWI handler instead
of an HWI, mutual exclusion can be achieved by disabling software interrupts
while the task accesses the shared data structure (SWI_disable and
SWI_enable are described later in this chapter). Thus, there is no effect on
the ability of the system to respond to events in real-time using hardware
interrupts.
It often makes sense to break long ISRs into two pieces. The HWI takes care
of the extremely time-critical operation and defers the less critical processing
to an SWI handler.
Program configuration
SWI object myswi Function myswiFxn()
Program
execution
· Calls SWI_dec(&myswi)
· myswi is not posted
· Calls SWI_dec(&myswi)
· myswi is posted
· SWI manager removes
myswi from the posted
SWI queue
· myswiFxn() is scheduled
for execution
· myswiFxn() starts
execution
Mailbox
value
Value returned by
SWI_getmbox
2
1
0
2 0
2 0