Skip to contentSkip to conversation

removing on-demand msix vector allocation

Qemu-devel Michael S. Tsirkin 2 participants 5 messages Dec 6, 2012 – Dec 10, 2012

lore
Share & tools
lore
#0 lore raw

I've been looking at handling of msix masking in qemu. It looks like all of virtio,vfio and device assignment implemented their own similar but slightly different thing.
So I am inclined to move this handling to common code in msix.c, adding irqfd support right there.

While doing this rework, one of the more painful bits of code to change is the code that dynamically allocates msix table entries as we inject msi. If this actually triggers it's going to be painfully slow as route changes are rcu write side in kernel.
Since recent kernels support direct injection, do we care anymore? I think if you run out of vectors, it's better to simply disable irqchip than try to limp along changing routes all the time.

Comments?

Signature · 1 line
MST
#1 lore raw
Quoted 7 lines · Michael S. Tsirkin

I've been looking at handling of msix masking in qemu. It looks like all of virtio,vfio and device assignment implemented their own similar but slightly different thing.
So I am inclined to move this handling to common code in msix.c, adding irqfd support right there.

Quoted 10 lines

While doing this rework, one of the more painful bits of code to change is the code that dynamically allocates msix table entries as we inject msi. If this actually triggers it's going to be painfully slow as route changes are rcu write side in kernel.
Since recent kernels support direct injection, do we care anymore? I think if you run out of vectors, it's better to simply disable irqchip than try to limp along changing routes all the time.

But how would the logic without dynamic allocation look like? Always configure a route in the PCI layer if an MSI/MSI-X entry is enabled? That would also affect emulated devices that don't use irqfd, thus you would waste routing entries. OTOH, if don't set up such routes, you cannot support MSI/-X on older x86 kernels without direct vector injection.

Jan

#2 lore raw
Quoted 19 lines · Jan Kiszka
Quoted 7 lines · Michael S. Tsirkin

I've been looking at handling of msix masking in qemu. It looks like all of virtio,vfio and device assignment implemented their own similar but slightly different thing.
So I am inclined to move this handling to common code in msix.c, adding irqfd support right there.

Quoted 10 lines

While doing this rework, one of the more painful bits of code to change is the code that dynamically allocates msix table entries as we inject msi. If this actually triggers it's going to be painfully slow as route changes are rcu write side in kernel.
Since recent kernels support direct injection, do we care anymore? I think if you run out of vectors, it's better to simply disable irqchip than try to limp along changing routes all the time.

Quoted 4 lines

But how would the logic without dynamic allocation look like? Always configure a route in the PCI layer if an MSI/MSI-X entry is enabled? That would also affect emulated devices that don't use irqfd, thus you would waste routing entries.

Yes.
So we can fail during initialization and ask user to disable irqchip: at the moment, at least in my testing, dynamic swap out of MSI entries performs very badly anyway.

Quoted 6 lines

OTOH, if don't set up such routes, you
cannot support MSI/-X on older x86 kernels without direct vector injection.

Jan

#3 lore raw
Quoted 25 lines · Michael S. Tsirkin
Quoted 19 lines · Jan Kiszka
Quoted 7 lines · Michael S. Tsirkin

I've been looking at handling of msix masking in qemu. It looks like all of virtio,vfio and device assignment implemented their own similar but slightly different thing.
So I am inclined to move this handling to common code in msix.c, adding irqfd support right there.

Quoted 10 lines

While doing this rework, one of the more painful bits of code to change is the code that dynamically allocates msix table entries as we inject msi. If this actually triggers it's going to be painfully slow as route changes are rcu write side in kernel.
Since recent kernels support direct injection, do we care anymore? I think if you run out of vectors, it's better to simply disable irqchip than try to limp along changing routes all the time.

Quoted 4 lines

But how would the logic without dynamic allocation look like? Always configure a route in the PCI layer if an MSI/MSI-X entry is enabled? That would also affect emulated devices that don't use irqfd, thus you would waste routing entries.

Quoted 5 lines

Yes.
So we can fail during initialization and ask user to disable irqchip: at the moment, at least in my testing, dynamic swap out of MSI entries performs very badly anyway.

That would be a poor approach as it regresses needlessly even over latest kernels. We only allocate/flush dynamically over older kernels without direct MSI injections.

What we need is a flag, set e.g. on msi[x]_init, to give the core a hint if it should allocate static routes for irqfd or if it will be able to use direct injection later on. Then we can simply do static allocation unconditionally on kernels without direct injection.

Jan

#4 lore raw
Quoted 37 lines · Jan Kiszka
Quoted 25 lines · Michael S. Tsirkin
Quoted 19 lines · Jan Kiszka
Quoted 7 lines · Michael S. Tsirkin

I've been looking at handling of msix masking in qemu. It looks like all of virtio,vfio and device assignment implemented their own similar but slightly different thing.
So I am inclined to move this handling to common code in msix.c, adding irqfd support right there.

Quoted 10 lines

While doing this rework, one of the more painful bits of code to change is the code that dynamically allocates msix table entries as we inject msi. If this actually triggers it's going to be painfully slow as route changes are rcu write side in kernel.
Since recent kernels support direct injection, do we care anymore? I think if you run out of vectors, it's better to simply disable irqchip than try to limp along changing routes all the time.

Quoted 4 lines

But how would the logic without dynamic allocation look like? Always configure a route in the PCI layer if an MSI/MSI-X entry is enabled? That would also affect emulated devices that don't use irqfd, thus you would waste routing entries.

Quoted 5 lines

Yes.
So we can fail during initialization and ask user to disable irqchip: at the moment, at least in my testing, dynamic swap out of MSI entries performs very badly anyway.

That would be a poor approach as it regresses needlessly even over latest kernels.
We only allocate/flush dynamically over older kernels without direct MSI injections.

Quoted 8 lines

What we need is a flag, set e.g. on msi[x]_init, to give the core a hint if it should allocate static routes for irqfd or if it will be able to use direct injection later on. Then we can simply do static allocation unconditionally on kernels without direct injection.

Jan

Makes sense.

Signature · 1 line
MST