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
252252 * @nr_sets: The number of interrupt sets for which affinity
253253 * spreading is required
254254 * @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.
255259 */
256260 struct irq_affinity {
257261 unsigned int pre_vectors;
258262 unsigned int post_vectors;
259263 unsigned int nr_sets;
260264 unsigned int set_size[IRQ_AFFINITY_MAX_SETS];
265+ void (*calc_sets)(struct irq_affinity *, unsigned int nvecs);
266+ void *priv;
261267 };
262268
263269 /**
@@ -317,7 +323,7 @@ extern int · 53 unmodified lines
317323 irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify);
318324
319325 struct irq_affinity_desc *
320−irq_create_affinity_masks(unsigned int nvec, const struct irq_affinity *affd);
326+irq_create_affinity_masks(unsigned int nvec, struct irq_affinity *affd);
321327
322328 unsigned int irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,
323329 const struct irq_affinity *affd);
@@ -354,7 +360,7 @@ irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify) · 30 unmodified lines
354360 }
355361
356362 static inline struct irq_affinity_desc *
357−irq_create_affinity_masks(unsigned int nvec, const struct irq_affinity *affd)
363+irq_create_affinity_masks(unsigned int nvec, struct irq_affinity *affd)
358364 {
359365 return NULL;
360366 }
include/linux/pci.h+2−2
@@ -1393,7 +1393,7 @@ static inline int pci_enable_msix_exact(struct pci_dev *dev, · 1392 unmodified lines
13931393 }
13941394 int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
13951395 unsigned int max_vecs, unsigned int flags,
1396− const struct irq_affinity *affd);
1396+ struct irq_affinity *affd);
13971397
13981398 void pci_free_irq_vectors(struct pci_dev *dev);
13991399 int 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
14191419 static inline int
14201420 pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
14211421 unsigned int max_vecs, unsigned int flags,
1422− const struct irq_affinity *aff_desc)
1422+ struct irq_affinity *aff_desc)
14231423 {
14241424 if ((flags & PCI_IRQ_LEGACY) && min_vecs == 1 && dev->irq)
14251425 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