History

genirq/affinity: Add new callback for (re)calculating interrupt sets

The interrupt affinity spreading mechanism supports to spread out affinities for one or more interrupt sets. A interrupt set contains one or more interrupts. Each set is mapped to a specific functionality of a device, e.g. general I/O queues and read I/O queus of multiqueue block devices. The number of interrupts per set is defined by the driver. It depends on the total number of available interrupts for the device, which is determined by the PCI capabilites and the availability of underlying CPU resources, and the number of queues which the device provides and the driver wants to instantiate. The driver passes initial configuration for the interrupt allocation via a pointer to struct irq_affinity. Right now the allocation mechanism is complex as it requires to have a loop in the driver to determine the maximum number of interrupts which are provided by the PCI capabilities and the underlying CPU resources. This loop would have to be replicated in every driver which wants to utilize this mechanism. That's unwanted code duplication and error prone. In order to move this into generic facilities it is required to have a mechanism, which allows the recalculation of the interrupt sets and their size, in the core code. As the core code does not have any knowledge about the underlying device, a driver specific callback is required in struct irq_affinity, which can be invoked by the core code. The callback gets the number of available interupts as an argument, so the driver can calculate the corresponding number and size of interrupt sets. At the moment the struct irq_affinity pointer which is handed in from the driver and passed through to several core functions is marked 'const', but for the callback to be able to modify the data in the struct it's required to remove the 'const' qualifier. Add the optional callback to struct irq_affinity, which allows drivers to recalculate the number and size of interrupt sets and remove the 'const' qualifier. For simple invocations, which do not supply a callback, a default callback is installed, which just sets nr_sets to 1 and transfers the number of spreadable vectors to the set_size array at index 0. This is for now guarded by a check for nr_sets != 0 to keep the NVME driver working until it is converted to the callback mechanism. To make sure that the driver configuration is correct under all circumstances the callback is invoked even when there are no interrupts for queues left, i.e. the pre/post requirements already exhaust the numner of available interrupts. At the PCI layer irq_create_affinity_masks() has to be invoked even for the case where the legacy interrupt is used. That ensures that the callback is invoked and the device driver can adjust to that situation. [ tglx: Fixed the simple case (no sets required). Moved the sanity check for nr_sets after the invocation of the callback so it catches broken drivers. Fixed the kernel doc comments for struct irq_affinity and de-'This patch'-ed the changelog ]

Ming Lei committed 7 years ago

Commit c66d4bd1 parent 9cfef555 files · +71 −32Browse files

Showing the changes to include/linux (2 of 5 files). Show all

Unified · Split

2 files
  1. include/linux/interrupt.h +8 −2
  2. include/linux/pci.h +2 −2
include/linux/interrupt.h+8−2
@@ -252,12 +252,18 @@ struct irq_affinity_notify { · 251 unmodified lines
252 * @nr_sets: The number of interrupt sets for which affinity252 * @nr_sets: The number of interrupt sets for which affinity
253 * spreading is required253 * spreading is required
254 * @set_size: Array holding the size of each interrupt set254 * @set_size: Array holding the size of each interrupt set
255 * @calc_sets: Callback for calculating the number and size
256 * of interrupt sets
257 * @priv: Private data for usage by @calc_sets, usually a
258 * pointer to driver/device specific data.
255 */259 */
256struct irq_affinity {260struct irq_affinity {
257 unsigned int pre_vectors;261 unsigned int pre_vectors;
258 unsigned int post_vectors;262 unsigned int post_vectors;
259 unsigned int nr_sets;263 unsigned int nr_sets;
260 unsigned int set_size[IRQ_AFFINITY_MAX_SETS];264 unsigned int set_size[IRQ_AFFINITY_MAX_SETS];
265 void (*calc_sets)(struct irq_affinity *, unsigned int nvecs);
266 void *priv;
261};267};
262 268
263/**269/**
@@ -317,7 +323,7 @@ extern int · 53 unmodified lines
317irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify);323irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify);
318 324
319struct irq_affinity_desc *325struct irq_affinity_desc *
320irq_create_affinity_masks(unsigned int nvec, const struct irq_affinity *affd);326irq_create_affinity_masks(unsigned int nvec, struct irq_affinity *affd);
321 327
322unsigned int irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,328unsigned int irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,
323 const struct irq_affinity *affd);329 const struct irq_affinity *affd);
@@ -354,7 +360,7 @@ irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify) · 30 unmodified lines
354}360}
355 361
356static inline struct irq_affinity_desc *362static inline struct irq_affinity_desc *
357irq_create_affinity_masks(unsigned int nvec, const struct irq_affinity *affd)363irq_create_affinity_masks(unsigned int nvec, struct irq_affinity *affd)
358{364{
359 return NULL;365 return NULL;
360}366}
include/linux/pci.h+2−2
@@ -1393,7 +1393,7 @@ static inline int pci_enable_msix_exact(struct pci_dev *dev, · 1392 unmodified lines
1393}1393}
1394int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,1394int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
1395 unsigned int max_vecs, unsigned int flags,1395 unsigned int max_vecs, unsigned int flags,
1396 const struct irq_affinity *affd);1396 struct irq_affinity *affd);
1397 1397
1398void pci_free_irq_vectors(struct pci_dev *dev);1398void pci_free_irq_vectors(struct pci_dev *dev);
1399int pci_irq_vector(struct pci_dev *dev, unsigned int nr);1399int pci_irq_vector(struct pci_dev *dev, unsigned int nr);
@@ -1419,7 +1419,7 @@ static inline int pci_enable_msix_exact(struct pci_dev *dev, · 19 unmodified lines
1419static inline int1419static inline int
1420pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,1420pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
1421 unsigned int max_vecs, unsigned int flags,1421 unsigned int max_vecs, unsigned int flags,
1422 const struct irq_affinity *aff_desc)1422 struct irq_affinity *aff_desc)
1423{1423{
1424 if ((flags & PCI_IRQ_LEGACY) && min_vecs == 1 && dev->irq)1424 if ((flags & PCI_IRQ_LEGACY) && min_vecs == 1 && dev->irq)
1425 return 1;1425 return 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t