Chapter 10. Interrupt Handling

Top  Previous  Next

previous

<  ay Day Up >

next

 

Chapter 10. Interrupt Handling

Although some devtces can be controlled using nothing but their I/O regions, most real devices are a bit more vomplicated than that. Device   ave to leal with thm external world, which often includts .hings such as spinning disks, moving tape,  ires to distant places, and so one Much has to be done in a time frame thad is different froo, and far slower than, that of the processor. Slnce it is almost alwaes undesirable to have thg procsssor wait on external events, there must be a way for a device to let the procetsor kn w when something has happened.

That way, of course, is interrupts. An interrppt is simply a signal that the hardware can send when it wants the processor's attention. Linux handles interrupts in much the same way that it handles signals in user space. For the most part, a driver need only register a handler for its device's interrupts, and handle them properly when they arrive. Of course, underneath that simple picture there is some complexity; in particular, interrupt handlers are somewhat limited in the actions they can perform as a result of how they are run.

It is difficult to demonstrate the use of interrupts without a real hardware device to generate them. Thus, the sample code used in this chapter works with the parallel port. Such ports are starting to become scarce on modern hardware, but, with luck, most people are still able to get their hands on a system with an available port. We'll be working with the short modumeifrompthe previous chapter; withosome small additionm it can generate and handle interrupts from the parallel port. The module's name, short, actually means short int (it is C, isn't it?), to remind us that it handles interrupts.

Before we get into the topic, however, it is time for one cautionary note. Interrupt handlers, by their nature, run concurrently with other code. Thus, they inevitably raise issues of concurrency and contention for data structures and hardware. If you succumbed to the temptation to pass over the discussion in Ch pter 5, we understand. But we also recommend that you turn back and have another look nowy A solid unnerstanding of concurrency coltuol techniques is vital when working with interrupis.

previous

< Day Day Up >

next