IRQ and Number of Devices

Hello everyone. I feel that I'm about to answer my own question, but I just want to be sure that I'm right. I know computers all use, at a very low level, the IRQ system of interrupting the CPU when it needs something. My questions are as follows:

  1. Does the device in question, say.. a mouse, need to use the interrupt wire every single time, I use it? Say if the CPU is potentially idle, and I tap a few keys, even though the CPU wasn't busy, will it still use the interrupt feature? Or intteruppting the CPU only done when it has other things it's busy with?

  2. How can there only be 16 IRQ devices? Also considering that 3 of them are already taken, (timer, keyboard, and clock) and that 2 & 9 are the same. Doesn't this mean that if I plug in 16 devices into a 20port usb hub that I'd be out of device room? Or does the usb bus count as 1 device? Same goes for SATA ports? I have 4 SATA ports on my motherboard. if I plug in 4 SATA hard drives, does that mean i'm filling up 4 seperate IRQ slots?

Thanks for the help in advance!

The CPU is able to temporarily ignore interrupts if it's busy doing something really important, like a device driver or an even higher-priority interrupt. Otherwise, yes, it does get interrupted very often. In the old days, if you left a stapler on your keyboard, it could waste a lot of CPU time!

Of course, the CPU gets interrupted frequently even if you don't. The clock interrupt cannot be ignored. (Some OSes like modern Linux are 'clockless', doing away with the 18-times-a-second interrupt and adjusting the timer on the fly. This gives a little efficiency boost.)

This is fine, not much performance loss, because interrupts are a hardware feature. The CPU does all the legwork.

If you remember computers having ISA slots, they couldn't share IRQ's, which made installing anything a maddening struggle of jumpers. ISA plug-and-play was even more of a joke; slow, unreliable, and most hardware couldn't do anything but tell you which hardwired IRQ it was demanding anyway.

PCI changed everything -- IRQ's can be shared! It has a built-in mechanism to tell the computer not just which interrupt, but which card on which interrupt. Resource conflicts mostly don't happen any more, and good riddance. Only the lowest-number IRQ's you mention are unshared now. I'll show you cat /proc/interrupts from my machine:

           CPU0       CPU1
  0:   17523426 1159587364   IO-APIC-edge      timer
  1:          0          8   IO-APIC-edge      i8042
  4:      19747    1576187   IO-APIC-edge
  7:          1          0   IO-APIC-edge      parport0
  8:          0         71   IO-APIC-edge      rtc0
  9:          0          0   IO-APIC-fasteoi   acpi
 14:     290784    8136376   IO-APIC-edge      pata_amd
 15:          0          0   IO-APIC-edge      pata_amd
 16:    2893418  135850554   IO-APIC-fasteoi   ohci_hcd:usb6, serial
 17:      93428     948486   IO-APIC-fasteoi   ehci_hcd:usb3
 18:          0          0   IO-APIC-fasteoi   ahci, ohci_hcd:usb8
 19:          0          0   IO-APIC-fasteoi   ahci, ohci_hcd:usb7
 20:          0         20   IO-APIC-fasteoi   ehci_hcd:usb2
 21:          2         93   IO-APIC-fasteoi   ehci_hcd:usb1, hda_intel
 22:     637342    8907010   IO-APIC-fasteoi   ohci_hcd:usb5
 23:   11385776  185922221   IO-APIC-fasteoi   ahci, ohci_hcd:usb4
 47:    5784110  240348995   PCI-MSI-edge      lan

It doesn't show individual USB ports, it shows individual USB controllers, each of which handles a couple of ports. The number is inflated because of the three differing kinds of USB, which apparently call different interrupts? Not sure.