Best way of mapping MSI-X interrupts to IDT interrupts

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
Ethin
Member
Member
Posts: 625
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Best way of mapping MSI-X interrupts to IDT interrupts

Post by Ethin »

So I'm curious what the best way of mapping MSI-X interrupts is. Right now I converge all the MSI-X vectors on a single IDT vector, but this has the major downside of making it impossible to tell what vector actually got triggered. I know that I can use the range 0x10-0xFE for the vector, but I'm hesitant to use anything below 0x20 because I don't want my MSI-X interrupts being considered CPU exceptions. I could map MSI-X vectors to any interrupt beyond interrupt 47, and though that works for devices with a low vector count, it becomes a problem for a device that has more than 207 vectors. So what's the best way of handling this? Is there any way to convey the "real" vector that was triggered if I mask the vector behind other IDT entries?
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: Best way of mapping MSI-X interrupts to IDT interrupts

Post by Octocontrabass »

From what I've seen, hardware usually gives you so many MSI-X vectors so that you can direct each vector to a specific CPU. This way, each CPU can access the same piece of hardware (mostly) independently from other CPUs.

To use a NVMe controller as an example, you would use all of those vectors to assign each CPU its own submission and completion queues.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Best way of mapping MSI-X interrupts to IDT interrupts

Post by Korona »

In general you do not want to use all possible vectors on all devices. Having more than one vector per device and CPU (which is what Octocontrabass suggests) does not really make sense.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
rdos
Member
Member
Posts: 3297
Joined: Wed Oct 01, 2008 1:55 pm

Re: Best way of mapping MSI-X interrupts to IDT interrupts

Post by rdos »

I have an allocation mechanism for IRQs, which includes allocating a number of consequitive entries for MSI and MSI-X. Although, for MSI-X you don't need consequitive entries, but I use the same method there anyway. Having different IDTs per CPU or core might be possible, but I don't use that rather have global IRQs. The old-style IRQs have fixed mappings and so those must be shared between CPUs anyway.

The kernel automatically calculates links between IRQs and server threads, and when a link is detected the scheduler will make sure the IRQ is delivered to the same core as the server thread runs on. This allows for migrating IRQs and servers between cores.

I wouldn't say the maximum possible used IRQs should be used for each device since IRQs are a scarse resource. I usually put some limit like no more than four per device.
Post Reply