IOAPIC vs. PIC

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
itportal
Posts: 18
Joined: Tue May 18, 2010 1:34 am

IOAPIC vs. PIC

Post by itportal »

Hello everyone,

I recently started making some experiments on enabling SMP support in my kernel. I can successfully boot all APs. Now I have some thoughts about interrupt handling which results in some questions.

1. Do I need to go IOAPIC or I can do with the old PIC? I want to get all interrupts on the BSP only.

2. Do I have only one PIC on the board or each core has one? I guess it is only one and is connected to the BSP.

3. Does a signal over the PIC send an interrupt to all CPUs or only the BSP?

4. What do I do if no IOAPIC is present? Use PIC?

Regards,
Martin
AndrewBuckley
Member
Member
Posts: 95
Joined: Thu Jan 29, 2009 9:13 am

Re: IOAPIC vs. PIC

Post by AndrewBuckley »

Rookie Disclaimer!

The PIC in modern x86 processors is emulated. you can use it up until you start using multiple processors. This is where my lanturn flickers out, but I think you will need to have the IOAPIC setup before you can use SMP.
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: IOAPIC vs. PIC

Post by gravaera »

Yo:
Merlin wrote:...you will need to have the IOAPIC setup before you can use SMP.
Not necessarily: you may leave the IO-APIC in virtual wire mode and just have all IRQs sent to the BSP; same with the i8259 PICs :)
itportal wrote:...
1. Do I need to go IOAPIC or I can do with the old PIC? I want to get all interrupts on the BSP only.
2. Do I have only one PIC on the board or each core has one? I guess it is only one and is connected to the BSP.
3. Does a signal over the PIC send an interrupt to all CPUs or only the BSP?
4. What do I do if no IOAPIC is present? Use PIC?
1. If your stated aim is to minimize your workload and only have to handle IRQ routing to a single processor, then yes, the shortest answer is that you can leave the chipset in "legacy" mode and use the i8259s. It is theoretically doable, but since AFAIK no major kernels du jour do this, chipsets may not be expecting it, and may not handle it properly, much like "mixed mode".

2. An IRQ controller takes IRQ pin inputs from multiple devices on the chipset and multiplexes and prioritizes them before they reach the CPU. The CPU does not have an IRQ controller, and it simply receives interrupts from the IRQ controller. There may be one or more IRQ controllers on a board; PCs have the i8259s in tandem, and/or the IO-APICs. The x86 multiprocessor specification requires that an MP capable logical CPU should have a Local APIC unit. The Local APIC unit is not an IRQ controller -- only the i8259s and the IO-APIC units are IRQ controllers. So the answer is that each logical CPU (not each core) has a Local APIC unit, and these Local APIC units intercept IRQ messages from the IRQ controllers on the motherboard.

3. The i8259 IRQ controller does not have the bus logic required for it to address or target specific CPUs. It is connected directly to a single processor, and cannot arbitrate messages to multiple CPUs :) It is impossible for the i8259 to send interrupts to any CPU other than the one it is wired to.

4. You've said that you don't want to get IRQs on any CPU other than the BSP, so you technically don't need to worry about the IO-APICs. If you want to make doubly sure, you may detect the presence of any IO-APIC and explicitly mask off all of its pins, though that shouldn't be necessary theoretically since the "boot state" of the IO-APICs is defined to have all of the pins masked. My answers will be pretty different if you decide not to limit yourself to using only the BSP for IRQs though ;)

--Peace out,
gravaera
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: IOAPIC vs. PIC

Post by Owen »

The PIC could theoretically be wired to one, all or some of the CPUs in your system; be very careful with the IRQ routing if you want to use it in SMP.

In practice, this means understanding the local APIC and IO APIC routing, and ACPI tables sufficiently well that you're pretty much just best off using the IO APIC(s)
rdos
Member
Member
Posts: 3308
Joined: Wed Oct 01, 2008 1:55 pm

Re: IOAPIC vs. PIC

Post by rdos »

The major reason why to use the IO-APIC when present is that it has more channels, and thus it is possible that some devices have no PIC routing at all, or has a lot more IRQ sharing. If you have no IRQ, or a highly shared IRQ, it means poorer interrupt performance or the meed to use timers instead of IRQs, which wastes CPU cycles.
itportal
Posts: 18
Joined: Tue May 18, 2010 1:34 am

Re: IOAPIC vs. PIC

Post by itportal »

Thank you for your answers. I think I will use the I/O APIC, if present.
Post Reply