Skip to contentSkip to conversation

IRQ affinity

TECH TOPIC Christoph Hellwig 11 participants 15 messages Jul 15, 2015 – Oct 14, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Many years ago we decided to move setting of IRQ to core affnities to userspace with the irqbalance daemon.

These days we have systems with lots of MSI-X vector, and we have hardware and subsystem support for per-CPU I/O queues in the block layer, the RDMA subsystem and probably the network stack (I'm not too familar with the recent developments there). It would really help the out of the box performance and experience if we could allow such subsystems to bind interrupt vectors to the node that the queue is configured on.

I'd like to discuss if the rationale for moving the IRQ affinity setting fully to userspace are still correct in todays world any any pitfalls we'll have to learn from in irqbalanced and the old in-kernel affinity code.

#1 lore raw
Quoted 11 lines · Christoph Hellwig

Many years ago we decided to move setting of IRQ to core affnities to userspace with the irqbalance daemon.

These days we have systems with lots of MSI-X vector, and we have hardware and subsystem support for per-CPU I/O queues in the block layer, the RDMA subsystem and probably the network stack (I'm not too familar with the recent developments there). It would really help the out of the box performance and experience if we could allow such subsystems to bind interrupt vectors to the node that the queue is configured on.

Quoted 4 lines

I'd like to discuss if the rationale for moving the IRQ affinity setting fully to userspace are still correct in todays world any any pitfalls we'll have to learn from in irqbalanced and the old in-kernel affinity code.

I think setting an initial affinity is not going to create the horror of the old in-kernel irq balancer again. It still could be changed from user space and does not try to be smart by moving interrupts around in circles all the time.

Thanks,

tglx

#2 lore raw
Quoted 17 lines · Thomas Gleixner
Quoted 11 lines · Christoph Hellwig

Many years ago we decided to move setting of IRQ to core affnities to userspace with the irqbalance daemon.

These days we have systems with lots of MSI-X vector, and we have hardware and subsystem support for per-CPU I/O queues in the block layer, the RDMA subsystem and probably the network stack (I'm not too familar with the recent developments there). It would really help the out of the box performance and experience if we could allow such subsystems to bind interrupt vectors to the node that the queue is configured on.

Quoted 4 lines

I'd like to discuss if the rationale for moving the IRQ affinity setting fully to userspace are still correct in todays world any any pitfalls we'll have to learn from in irqbalanced and the old in-kernel affinity code.

Quoted 4 lines

I think setting an initial affinity is not going to create the horror of the old in-kernel irq balancer again. It still could be changed from user space and does not try to be smart by moving interrupts around in circles all the time.

Thanks Thomas for your feedback. But no matter whether IRQ balancing happens in user space or in the kernel, the following issues need to be addressed and have not yet been addressed today:
* irqbalanced is not aware of the relationship between MSI-X vectors. If e.g. two kernel drivers each allocate 24 MSI-X vectors for the PCIe interfaces they control irqbalanced could e.g. decide to associate all MSI-X vectors for the first PCIe interface with a first set of CPUs and the MSI-X vectors of the second PCIe interface with a second set of CPUs. This will result in suboptimal performance if these two PCIe interfaces are used alternatingly instead of simultaneously.
* With blk-mq and scsi-mq optimal performance can only be achieved if the relationship between MSI-X vector and NUMA node does not change over time. This is necessary to allow a blk-mq/scsi-mq driver to ensure that interrupts are processed on the same NUMA node as the node on which the data structures for a communication channel have been allocated. However, today there is no API that allows blk-mq/scsi-mq drivers and irqbalanced to exchange information about the relationship between MSI-X vector ranges and NUMA nodes. The only approach I know of that works today to define IRQ affinity for blk-mq/scsi-mq drivers is to disable irqbalanced and to run a custom script that defines IRQ affinity (see e.g. the spread-mlx4-ib-interrupts attachment of
http://thread.gmane.org/gmane.linux.kernel.device-mapper.devel/21312/focus=98409).

Bart.

#3 lore raw
Quoted 8 lines · Bart Van Assche

* With blk-mq and scsi-mq optimal performance can only be achieved if the relationship between MSI-X vector and NUMA node does not change over time. This is necessary to allow a blk-mq/scsi-mq driver to ensure that interrupts are processed on the same NUMA node as the node on which the data structures for a communication channel have been allocated. However, today there is no API that allows blk-mq/scsi-mq drivers and irqbalanced to exchange information about the relationship between MSI-X vector ranges and NUMA nodes.

We could have low-level drivers provide blk-mq the controller's irq associated with a particular h/w context, and the block layer can provide the context's cpumask to irqbalance with the smp affinity hint.

The nvme driver already uses the hwctx cpumask to set hints, but this doesn't seems like it should be a driver responsibility. It currently doesn't work correctly anyway with hot-cpu since blk-mq could rebalance the h/w contexts without syncing with the low-level driver.

If we can add this to blk-mq, one additional case to consider is if the same interrupt vector is used with multiple h/w contexts. Blk-mq's cpu assignment needs to be aware of this to prevent sharing a vector across NUMA nodes.

Quoted 5 lines

The only approach I know of that works today to define IRQ affinity for blk-mq/scsi-mq drivers is to disable irqbalanced and to run a custom script that defines IRQ affinity (see e.g. the spread-mlx4-ib-interrupts attachment of
http://thread.gmane.org/gmane.linux.kernel.device-mapper.devel/21312/focus=98409).

maintainer
#4 lore raw
Quoted 19 lines · Keith Busch
Quoted 8 lines · Bart Van Assche

* With blk-mq and scsi-mq optimal performance can only be achieved if the relationship between MSI-X vector and NUMA node does not change over time. This is necessary to allow a blk-mq/scsi-mq driver to ensure that interrupts are processed on the same NUMA node as the node on which the data structures for a communication channel have been allocated. However, today there is no API that allows blk-mq/scsi-mq drivers and irqbalanced to exchange information about the relationship between MSI-X vector ranges and NUMA nodes.

We could have low-level drivers provide blk-mq the controller's irq associated with a particular h/w context, and the block layer can provide the context's cpumask to irqbalance with the smp affinity hint.

The nvme driver already uses the hwctx cpumask to set hints, but this doesn't seems like it should be a driver responsibility. It currently doesn't work correctly anyway with hot-cpu since blk-mq could rebalance the h/w contexts without syncing with the low-level driver.

Quoted 4 lines

If we can add this to blk-mq, one additional case to consider is if the same interrupt vector is used with multiple h/w contexts. Blk-mq's cpu assignment needs to be aware of this to prevent sharing a vector across NUMA nodes.

Exactly. I may have promised to do just that at the last LSF/MM conference, just haven't done it yet. The point is to share the mask, I'd ideally like to take it all the way where the driver just asks for a number of vecs through a nice API that takes care of all this. Lots of duplicated code in drivers for this these days, and it's a mess.

Signature · 1 line
Jens Axboe
#5 lore raw
Quoted 25 lines · Jens Axboe
Quoted 19 lines · Keith Busch
Quoted 8 lines · Bart Van Assche

* With blk-mq and scsi-mq optimal performance can only be achieved if the relationship between MSI-X vector and NUMA node does not change over time. This is necessary to allow a blk-mq/scsi-mq driver to ensure that interrupts are processed on the same NUMA node as the node on which the data structures for a communication channel have been allocated. However, today there is no API that allows blk-mq/scsi-mq drivers and irqbalanced to exchange information about the relationship between MSI-X vector ranges and NUMA nodes.

We could have low-level drivers provide blk-mq the controller's irq associated with a particular h/w context, and the block layer can provide the context's cpumask to irqbalance with the smp affinity hint.

The nvme driver already uses the hwctx cpumask to set hints, but this doesn't seems like it should be a driver responsibility. It currently doesn't work correctly anyway with hot-cpu since blk-mq could rebalance the h/w contexts without syncing with the low-level driver.

Quoted 4 lines

If we can add this to blk-mq, one additional case to consider is if the same interrupt vector is used with multiple h/w contexts. Blk-mq's cpu assignment needs to be aware of this to prevent sharing a vector across NUMA nodes.

Quoted 6 lines

Exactly. I may have promised to do just that at the last LSF/MM conference, just haven't done it yet. The point is to share the mask, I'd ideally like to take it all the way where the driver just asks for a number of vecs through a nice API that takes care of all this. Lots of duplicated code in drivers for this these days, and it's a mess.

These are all good points.

But I'm not sure the block layer is always the correct place to take care of msix vector assignments. It's probably a perfect fit for NVME and other storage devices, but if we take RDMA for example, block storage co-exists with file storage, Ethernet traffic and user-space applications that do RDMA. All of which share the device MSI-X vectors. So in this case, the block layer would not be a suitable place to set IRQ affinity since each deployment might present different constraints.

In any event, the irqbalance daemon is not helping here. Unfortunately the common practice is to just turn it off in order to get optimized performance.

Sagi.

#6 lore raw
In reply to Jens Axboe
Quoted 25 lines · Jens Axboe
Quoted 19 lines · Keith Busch
Quoted 8 lines · Bart Van Assche

* With blk-mq and scsi-mq optimal performance can only be achieved if the relationship between MSI-X vector and NUMA node does not change over time. This is necessary to allow a blk-mq/scsi-mq driver to ensure that interrupts are processed on the same NUMA node as the node on which the data structures for a communication channel have been allocated. However, today there is no API that allows blk-mq/scsi-mq drivers and irqbalanced to exchange information about the relationship between MSI-X vector ranges and NUMA nodes.

We could have low-level drivers provide blk-mq the controller's irq associated with a particular h/w context, and the block layer can provide the context's cpumask to irqbalance with the smp affinity hint.

The nvme driver already uses the hwctx cpumask to set hints, but this doesn't seems like it should be a driver responsibility. It currently doesn't work correctly anyway with hot-cpu since blk-mq could rebalance the h/w contexts without syncing with the low-level driver.

Quoted 4 lines

If we can add this to blk-mq, one additional case to consider is if the same interrupt vector is used with multiple h/w contexts. Blk-mq's cpu assignment needs to be aware of this to prevent sharing a vector across NUMA nodes.

Quoted 5 lines

Exactly. I may have promised to do just that at the last LSF/MM conference, just haven't done it yet. The point is to share the mask, I'd ideally like to take it all the way where the driver just asks for a number of vecs through a nice API that takes care of all this. Lots of duplicated code in drivers for this these days, and it's a mess.

Yes. I think the fundamental problem is that our MSI-X API is so funky. We have this incredibly flexible scheme where each MSI-X vector could have its own interrupt handler, but that's not what drivers want. They want to say "Give me eight MSI-X vectors spread across the CPUs, and use this interrupt handler for all of them". That is, instead of the current scheme where each MSI-X vector gets its own Linux interrupt, we should have one interrupt handler (of the per-cpu interrupt type), which shows up with N bits set in its CPU mask.

#7 lore raw
Quoted 32 lines · Matthew Wilcox
Quoted 25 lines · Jens Axboe
Quoted 19 lines · Keith Busch
Quoted 8 lines · Bart Van Assche

* With blk-mq and scsi-mq optimal performance can only be achieved if the relationship between MSI-X vector and NUMA node does not change over time. This is necessary to allow a blk-mq/scsi-mq driver to ensure that interrupts are processed on the same NUMA node as the node on which the data structures for a communication channel have been allocated. However, today there is no API that allows blk-mq/scsi-mq drivers and irqbalanced to exchange information about the relationship between MSI-X vector ranges and NUMA nodes.

We could have low-level drivers provide blk-mq the controller's irq associated with a particular h/w context, and the block layer can provide the context's cpumask to irqbalance with the smp affinity hint.

The nvme driver already uses the hwctx cpumask to set hints, but this doesn't seems like it should be a driver responsibility. It currently doesn't work correctly anyway with hot-cpu since blk-mq could rebalance the h/w contexts without syncing with the low-level driver.

Quoted 4 lines

If we can add this to blk-mq, one additional case to consider is if the same interrupt vector is used with multiple h/w contexts. Blk-mq's cpu assignment needs to be aware of this to prevent sharing a vector across NUMA nodes.

Quoted 5 lines

Exactly. I may have promised to do just that at the last LSF/MM conference, just haven't done it yet. The point is to share the mask, I'd ideally like to take it all the way where the driver just asks for a number of vecs through a nice API that takes care of all this. Lots of duplicated code in drivers for this these days, and it's a mess.

Quoted 8 lines

Yes. I think the fundamental problem is that our MSI-X API is so funky. We have this incredibly flexible scheme where each MSI-X vector could have its own interrupt handler, but that's not what drivers want. They want to say "Give me eight MSI-X vectors spread across the CPUs, and use this interrupt handler for all of them". That is, instead of the current scheme where each MSI-X vector gets its own Linux interrupt, we should have one interrupt handler (of the per-cpu interrupt type), which shows up with N bits set in its CPU mask.

It would definitely be nice to have a way to express that. But it's also pretty common for drivers to have e.g. RX and TX use separate vectors, and these need separate handlers.

Quoted 4 lines

_______________________________________________
Ksummit-discuss mailing list
Ksummit-discuss at lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/ksummit-discuss

#8 lore raw
In reply to Matthew Wilcox
Quoted 32 lines · Matthew Wilcox
Quoted 25 lines · Jens Axboe
Quoted 19 lines · Keith Busch
Quoted 8 lines · Bart Van Assche

* With blk-mq and scsi-mq optimal performance can only be achieved if the relationship between MSI-X vector and NUMA node does not change over time. This is necessary to allow a blk-mq/scsi-mq driver to ensure that interrupts are processed on the same NUMA node as the node on which the data structures for a communication channel have been allocated. However, today there is no API that allows blk-mq/scsi-mq drivers and irqbalanced to exchange information about the relationship between MSI-X vector ranges and NUMA nodes.

We could have low-level drivers provide blk-mq the controller's irq associated with a particular h/w context, and the block layer can provide the context's cpumask to irqbalance with the smp affinity hint.

The nvme driver already uses the hwctx cpumask to set hints, but this doesn't seems like it should be a driver responsibility. It currently doesn't work correctly anyway with hot-cpu since blk-mq could rebalance the h/w contexts without syncing with the low-level driver.

Quoted 4 lines

If we can add this to blk-mq, one additional case to consider is if the same interrupt vector is used with multiple h/w contexts. Blk-mq's cpu assignment needs to be aware of this to prevent sharing a vector across NUMA nodes.

Quoted 5 lines

Exactly. I may have promised to do just that at the last LSF/MM conference, just haven't done it yet. The point is to share the mask, I'd ideally like to take it all the way where the driver just asks for a number of vecs through a nice API that takes care of all this. Lots of duplicated code in drivers for this these days, and it's a mess.

Quoted 8 lines

Yes. I think the fundamental problem is that our MSI-X API is so funky. We have this incredibly flexible scheme where each MSI-X vector could have its own interrupt handler, but that's not what drivers want. They want to say "Give me eight MSI-X vectors spread across the CPUs, and use this interrupt handler for all of them". That is, instead of the current scheme where each MSI-X vector gets its own Linux interrupt, we should have one interrupt handler (of the per-cpu interrupt type), which shows up with N bits set in its CPU mask.

That certainly would help, but I'm definitely not going to open a huge can of worms by providing a side channel for vector allocation with all the variants of irq remapping and whatsoever.

Though we certainly can do better than we do now. We recently reworked the whole interrupt handling of x86 to use hierarchical interrupt domains. This allows us to come up with a clean solution for your issue. The current hierarchy looks like this:

[MSI-domain]

	|
	v
  [optional REMAP-domain]
	|
	v

[Vector-domain]

Now it's simple to add another hierarchy level:

[MSI/X-Multiqueue-domain]

	|
	v
  [MSI-domain]
	|
	v
  [optional REMAP-domain]
	|
	v

[Vector-domain]

The MSI/X-Multiqueue-domain would be the one which is associated to this class of devices. The domain would provide a single virtual interrupt number to the device and hide the underlying details.

This needs a few new interfaces at the irq core level because we cannot map that 1:1 to the per cpu interrupt mechanism which we have on ARM and other architectures.

irqdomain interfaces used from PCI/MSI infrastructure code:

irq_domain_alloc_mq(....., nr_vectors, spread_scheme)

@nr_vectors: The number of vectors to allocate underneath

@spread_scheme: Some form of advice/hint how to spread the vectors
(nodes, cpus, ...)

Returns a unique virtual interrupt number which shows up in /proc/irq. The virtual interrupt cannot be influenced by user space affinity settings (e.g. irqbalanced)

The vectors will have seperate irq numbers and irq descriptors, but those should be supressed in /proc/interrupts. /proc/irq/NNN should expose the information at least for debugging purposes.

One advantage of these seperate descriptors is that the associated data will be cpu/node local according to the spread scheme.

irq_domain_free_mq()

Counterpart to the above

irq core interfaces used from PCI/MSI infrastructure

irq_move_mq_vector()

Move a multiqueue vector to a new target (cpu, node)

That might even replace the underlying irq descriptor with a newly allocated one, if the vector moves across nodes.

Driver relevant interfaces:

msi_alloc_mq_irqs()/msi_free_mq_irqs()

PCI/MSI specific wrappers for the irqdomain interfaces

msi_mq_move_vector(virq, vector_nr, target)

@virq: The virtual interrupt number

@vector_nr: The vector number to move

@target: The target cpu/node information

PCI/MSI specific wrapper around irq_move_mq_vector()

The existing interfaces will behave as follows:

request_irq()
free_irq()
disable_irq()
enable_irq()

They all operate on the virtual irq number and affect all associated vectors.

Now the question is whether we need

en/disable_irq_mq_vector(virq, vector_nr)

to can shut down / reenable a particular vector, but that would be pretty straight forward to do, plus/minus the headache versus the global disable/enable mechanism which operates on the virq.

Thoughts?

tglx

#9 lore raw
In reply to Christoph Hellwig
Quoted 11 lines · Christoph Hellwig

Many years ago we decided to move setting of IRQ to core affnities to userspace with the irqbalance daemon.

These days we have systems with lots of MSI-X vector, and we have hardware and subsystem support for per-CPU I/O queues in the block layer, the RDMA subsystem and probably the network stack (I'm not too familar with the recent developments there). It would really help the out of the box performance and experience if we could allow such subsystems to bind interrupt vectors to the node that the queue is configured on.

Quoted 4 lines

I'd like to discuss if the rationale for moving the IRQ affinity setting fully to userspace are still correct in todays world any any pitfalls we'll have to learn from in irqbalanced and the old in-kernel affinity code.

Configuration with processors that are trying to be OS noise free (NOHZ) would also benefit if device interrupts would be directed to processors that are not in the NOHZ set. Currently we use scripts on bootup that redirect interrupts away from these.

#10 lore raw
In reply to Christoph Hellwig
Quoted 11 lines · Christoph Hellwig

Many years ago we decided to move setting of IRQ to core affnities to userspace with the irqbalance daemon.

These days we have systems with lots of MSI-X vector, and we have hardware and subsystem support for per-CPU I/O queues in the block layer, the RDMA subsystem and probably the network stack (I'm not too familar with the recent developments there). It would really help the out of the box performance and experience if we could allow such subsystems to bind interrupt vectors to the node that the queue is configured on.

Quoted 4 lines

I'd like to discuss if the rationale for moving the IRQ affinity setting fully to userspace are still correct in todays world any any pitfalls we'll have to learn from in irqbalanced and the old in-kernel affinity code.

I've been pondering about having some notion of "grouping", where some interrupts are logically part of the same working set, and it doesn't make much sense to spread it among CPUs, and userspace doesn't really have a clue about this.

A related problem is that some weird HW (things like cascaded interrupt controllers) can only move a bunch of interrupt in one go, which isn't really what userspace expects to see (move one interrupt, see another 31 moving).

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#11 lore raw
In reply to Christoph Hellwig
Quoted 10 lines · Christoph Hellwig

Many years ago we decided to move setting of IRQ to core affnities to userspace with the irqbalance daemon.

These days we have systems with lots of MSI-X vector, and we have hardware and subsystem support for per-CPU I/O queues in the block layer, the RDMA subsystem and probably the network stack (I'm not too familar with the recent developments there). It would really help the out of the box performance and experience if we could allow such subsystems to bind interrupt vectors to the node that the queue is configured on.

I think you are right, it's true for networking.

Whenever someone tries to benchmark networking, first thing done is always disabling irqbalance and pinning IRQs manually away from whereever the benchmark is running, but at the same numa node.

Without that, interrupts don't let the benchmark make progress.

Alternatively, people give up on interrupts completely and start polling hardware aggressively. Nice for a benchmark, not nice for the environment.

Quoted 5 lines

I'd like to discuss if the rationale for moving the IRQ affinity setting fully to userspace are still correct in todays world any any pitfalls we'll have to learn from in irqbalanced and the old in-kernel affinity code.

IMHO there could be a benefit from a better integration with the scheduler. Maybe an interrupt handler can be viewed as a kind of thread, so scheduler can make decisions about where to run it next?

Quoted 4 lines

_______________________________________________
Ksummit-discuss mailing list
Ksummit-discuss at lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/ksummit-discuss

#12 lore raw
In reply to Christoph Hellwig

Hi Christoph,

Do you think this is still an issue that would be worth discsussing at the kernel summit as a technical topic? If so, would you be willing to be responsible for kicking off the discussion for this topic?

Thanks,

- Ted

Quoted 19 lines · Christoph Hellwig

Many years ago we decided to move setting of IRQ to core affnities to userspace with the irqbalance daemon.

These days we have systems with lots of MSI-X vector, and we have hardware and subsystem support for per-CPU I/O queues in the block layer, the RDMA subsystem and probably the network stack (I'm not too familar with the recent developments there). It would really help the out of the box performance and experience if we could allow such subsystems to bind interrupt vectors to the node that the queue is configured on.

I'd like to discuss if the rationale for moving the IRQ affinity setting fully to userspace are still correct in todays world any any pitfalls we'll have to learn from in irqbalanced and the old in-kernel affinity code.
_______________________________________________
Ksummit-discuss mailing list
Ksummit-discuss at lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/ksummit-discuss

#13 lore raw
Quoted 5 lines · Theodore Ts'o

Hi Christoph,

Do you think this is still an issue that would be worth discsussing at the kernel summit as a technical topic? If so, would you be willing to be responsible for kicking off the discussion for this topic?

Hi Ted,

while we have a high level agreement there's still some discussion needed. I can prepare a few slides for 10 minute discussion and then take it to the hallways with the interested people.

#14 lore raw
Quoted 6 lines · Christoph Hellwig

Hi Ted,

while we have a high level agreement there's still some discussion needed. I can prepare a few slides for 10 minute discussion and then take it to the hallways with the interested people.

Thanks,

The Tech session day is designed for just that. We should have plenty of slots so you can stay and have the chat in the room.

Cheers,

- Ted