Skip to content

Commit 0d3f542

Browse files
committed
genirq: Introduce effective affinity mask
There is currently no way to evaluate the effective affinity mask of a given interrupt. Many irq chips allow only a single target CPU or a subset of CPUs in the affinity mask. Updating the mask at the time of setting the affinity to the subset would be counterproductive because information for cpu hotplug about assigned interrupt affinities gets lost. On CPU hotplug it's also pointless to force migrate an interrupt, which is not targeted at the CPU effectively. But currently the information is not available. Provide a seperate mask to be updated by the irq_chip->irq_set_affinity() implementations. Implement the read only proc files so the user can see the effective mask as well w/o trying to deduce it from /proc/interrupts. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Jens Axboe <axboe@kernel.dk> Cc: Marc Zyngier <marc.zyngier@arm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Keith Busch <keith.busch@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Christoph Hellwig <hch@lst.de> Link: http://lkml.kernel.org/r/20170619235446.247834245@linutronix.de
1 parent c1a8038 commit 0d3f542

5 files changed

Lines changed: 134 additions & 7 deletions

File tree

‎include/linux/irq.h‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ struct irq_domain;
137137
* @affinity: IRQ affinity on SMP. If this is an IPI
138138
* related irq, then this is the mask of the
139139
* CPUs to which an IPI can be sent.
140+
* @effective_affinity: The effective IRQ affinity on SMP as some irq
141+
* chips do not allow multi CPU destinations.
142+
* A subset of @affinity.
140143
* @msi_desc: MSI descriptor
141144
* @ipi_offset: Offset of first IPI target cpu in @affinity. Optional.
142145
*/
@@ -148,6 +151,9 @@ struct irq_common_data {
148151
void *handler_data;
149152
struct msi_desc *msi_desc;
150153
cpumask_var_t affinity;
154+
#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
155+
cpumask_var_t effective_affinity;
156+
#endif
151157
#ifdef CONFIG_GENERIC_IRQ_IPI
152158
unsigned int ipi_offset;
153159
#endif
@@ -737,6 +743,29 @@ static inline struct cpumask *irq_data_get_affinity_mask(struct irq_data *d)
737743
return d->common->affinity;
738744
}
739745

746+
#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
747+
static inline
748+
struct cpumask *irq_data_get_effective_affinity_mask(struct irq_data *d)
749+
{
750+
return d->common->effective_affinity;
751+
}
752+
static inline void irq_data_update_effective_affinity(struct irq_data *d,
753+
const struct cpumask *m)
754+
{
755+
cpumask_copy(d->common->effective_affinity, m);
756+
}
757+
#else
758+
static inline void irq_data_update_effective_affinity(struct irq_data *d,
759+
const struct cpumask *m)
760+
{
761+
}
762+
static inline
763+
struct cpumask *irq_data_get_effective_affinity_mask(struct irq_data *d)
764+
{
765+
return d->common->affinity;
766+
}
767+
#endif
768+
740769
unsigned int arch_dynirq_lower_bound(unsigned int from);
741770

742771
int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,

‎kernel/irq/Kconfig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ config GENERIC_IRQ_SHOW
2121
config GENERIC_IRQ_SHOW_LEVEL
2222
bool
2323

24+
# Supports effective affinity mask
25+
config GENERIC_IRQ_EFFECTIVE_AFF_MASK
26+
bool
27+
2428
# Facility to allocate a hardware interrupt. This is legacy support
2529
# and should not be used in new code. Use irq domains instead.
2630
config GENERIC_IRQ_LEGACY_ALLOC_HWIRQ

‎kernel/irq/debugfs.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ static void irq_debug_show_masks(struct seq_file *m, struct irq_desc *desc)
3636

3737
msk = irq_data_get_affinity_mask(data);
3838
seq_printf(m, "affinity: %*pbl\n", cpumask_pr_args(msk));
39+
#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
40+
msk = irq_data_get_effective_affinity_mask(data);
41+
seq_printf(m, "effectiv: %*pbl\n", cpumask_pr_args(msk));
42+
#endif
3943
#ifdef CONFIG_GENERIC_PENDING_IRQ
4044
msk = desc->pending_mask;
4145
seq_printf(m, "pending: %*pbl\n", cpumask_pr_args(msk));

‎kernel/irq/irqdesc.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,19 @@ static int alloc_masks(struct irq_desc *desc, int node)
6060
GFP_KERNEL, node))
6161
return -ENOMEM;
6262

63+
#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
64+
if (!zalloc_cpumask_var_node(&desc->irq_common_data.effective_affinity,
65+
GFP_KERNEL, node)) {
66+
free_cpumask_var(desc->irq_common_data.affinity);
67+
return -ENOMEM;
68+
}
69+
#endif
70+
6371
#ifdef CONFIG_GENERIC_PENDING_IRQ
6472
if (!zalloc_cpumask_var_node(&desc->pending_mask, GFP_KERNEL, node)) {
73+
#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
74+
free_cpumask_var(desc->irq_common_data.effective_affinity);
75+
#endif
6576
free_cpumask_var(desc->irq_common_data.affinity);
6677
return -ENOMEM;
6778
}
@@ -324,6 +335,9 @@ static void free_masks(struct irq_desc *desc)
324335
free_cpumask_var(desc->pending_mask);
325336
#endif
326337
free_cpumask_var(desc->irq_common_data.affinity);
338+
#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
339+
free_cpumask_var(desc->irq_common_data.effective_affinity);
340+
#endif
327341
}
328342
#else
329343
static inline void free_masks(struct irq_desc *desc) { }

‎kernel/irq/proc.c‎

Lines changed: 83 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,47 @@ static struct proc_dir_entry *root_irq_dir;
3737

3838
#ifdef CONFIG_SMP
3939

40+
enum {
41+
AFFINITY,
42+
AFFINITY_LIST,
43+
EFFECTIVE,
44+
EFFECTIVE_LIST,
45+
};
46+
4047
static int show_irq_affinity(int type, struct seq_file *m)
4148
{
4249
struct irq_desc *desc = irq_to_desc((long)m->private);
43-
const struct cpumask *mask = desc->irq_common_data.affinity;
50+
const struct cpumask *mask;
4451

52+
switch (type) {
53+
case AFFINITY:
54+
case AFFINITY_LIST:
55+
mask = desc->irq_common_data.affinity;
4556
#ifdef CONFIG_GENERIC_PENDING_IRQ
46-
if (irqd_is_setaffinity_pending(&desc->irq_data))
47-
mask = desc->pending_mask;
57+
if (irqd_is_setaffinity_pending(&desc->irq_data))
58+
mask = desc->pending_mask;
4859
#endif
49-
if (type)
60+
break;
61+
case EFFECTIVE:
62+
case EFFECTIVE_LIST:
63+
#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
64+
mask = desc->irq_common_data.effective_affinity;
65+
break;
66+
#else
67+
return -EINVAL;
68+
#endif
69+
};
70+
71+
switch (type) {
72+
case AFFINITY_LIST:
73+
case EFFECTIVE_LIST:
5074
seq_printf(m, "%*pbl\n", cpumask_pr_args(mask));
51-
else
75+
break;
76+
case AFFINITY:
77+
case EFFECTIVE:
5278
seq_printf(m, "%*pb\n", cpumask_pr_args(mask));
79+
break;
80+
}
5381
return 0;
5482
}
5583

@@ -80,12 +108,12 @@ static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
80108
int no_irq_affinity;
81109
static int irq_affinity_proc_show(struct seq_file *m, void *v)
82110
{
83-
return show_irq_affinity(0, m);
111+
return show_irq_affinity(AFFINITY, m);
84112
}
85113

86114
static int irq_affinity_list_proc_show(struct seq_file *m, void *v)
87115
{
88-
return show_irq_affinity(1, m);
116+
return show_irq_affinity(AFFINITY_LIST, m);
89117
}
90118

91119

@@ -185,6 +213,44 @@ static const struct file_operations irq_affinity_list_proc_fops = {
185213
.write = irq_affinity_list_proc_write,
186214
};
187215

216+
#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
217+
static int irq_effective_aff_proc_show(struct seq_file *m, void *v)
218+
{
219+
return show_irq_affinity(EFFECTIVE, m);
220+
}
221+
222+
static int irq_effective_aff_list_proc_show(struct seq_file *m, void *v)
223+
{
224+
return show_irq_affinity(EFFECTIVE_LIST, m);
225+
}
226+
227+
static int irq_effective_aff_proc_open(struct inode *inode, struct file *file)
228+
{
229+
return single_open(file, irq_effective_aff_proc_show, PDE_DATA(inode));
230+
}
231+
232+
static int irq_effective_aff_list_proc_open(struct inode *inode,
233+
struct file *file)
234+
{
235+
return single_open(file, irq_effective_aff_list_proc_show,
236+
PDE_DATA(inode));
237+
}
238+
239+
static const struct file_operations irq_effective_aff_proc_fops = {
240+
.open = irq_effective_aff_proc_open,
241+
.read = seq_read,
242+
.llseek = seq_lseek,
243+
.release = single_release,
244+
};
245+
246+
static const struct file_operations irq_effective_aff_list_proc_fops = {
247+
.open = irq_effective_aff_list_proc_open,
248+
.read = seq_read,
249+
.llseek = seq_lseek,
250+
.release = single_release,
251+
};
252+
#endif
253+
188254
static int default_affinity_show(struct seq_file *m, void *v)
189255
{
190256
seq_printf(m, "%*pb\n", cpumask_pr_args(irq_default_affinity));
@@ -364,6 +430,12 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)
364430

365431
proc_create_data("node", 0444, desc->dir,
366432
&irq_node_proc_fops, irqp);
433+
# ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
434+
proc_create_data("effective_affinity", 0444, desc->dir,
435+
&irq_effective_aff_proc_fops, irqp);
436+
proc_create_data("effective_affinity_list", 0444, desc->dir,
437+
&irq_effective_aff_list_proc_fops, irqp);
438+
# endif
367439
#endif
368440
proc_create_data("spurious", 0444, desc->dir,
369441
&irq_spurious_proc_fops, (void *)(long)irq);
@@ -383,6 +455,10 @@ void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)
383455
remove_proc_entry("affinity_hint", desc->dir);
384456
remove_proc_entry("smp_affinity_list", desc->dir);
385457
remove_proc_entry("node", desc->dir);
458+
# ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
459+
remove_proc_entry("effective_affinity", desc->dir);
460+
remove_proc_entry("effective_affinity_list", desc->dir);
461+
# endif
386462
#endif
387463
remove_proc_entry("spurious", desc->dir);
388464

0 commit comments

Comments
 (0)