irq: only update affinity in chip set_affinity()
Subsystems (7)
PATCH 1/1 irq: only update affinity in chip set_affinity()
Impact: keep affinity consistent
irq_set_affinity() and move_masked_irq() try to assign affinity before calling chip set_affinity(). some archs are assigning again in set_affinity again.
something like:cpumask_cpy(desc->affinity, mask);desc->chip->set_affinity(mask);
in the failing path, affinity should not be touched.
also set_extra_move_desc() ( called by set_affinity) will rely on the old affinity to decide if need to move irq_desc to different node when logical flat apic mode is used.
So try remove those assignment, and make some missed arch to assign affinity in their set_affinity.
--
arch/alpha/kernel/sys_dp264.c | 6 ++++-- arch/alpha/kernel/sys_titan.c | 3 ++- arch/arm/common/gic.c | 1 + arch/cris/arch-v32/kernel/irq.c | 1 + arch/ia64/kernel/iosapic.c | 3 +++ arch/ia64/sn/kernel/irq.c | 3 +++ arch/mips/cavium-octeon/octeon-irq.c | 6 ++++++ arch/mips/sibyte/bcm1480/irq.c | 2 ++ arch/mips/sibyte/sb1250/irq.c | 2 ++ arch/powerpc/platforms/pseries/xics.c | 5 +++++ arch/powerpc/sysdev/mpic.c | 2 ++ arch/sparc/kernel/irq_64.c | 7 +++++++ drivers/xen/events.c | 2 ++ kernel/irq/manage.c | 6 ++---- kernel/irq/migration.c | 8 +++----- 15 files changed, 45 insertions(+), 12 deletions(-)
arch/alpha/kernel/sys_dp264.c +4 -2
@@ -178,7 +178,8 @@ cpu_set_irq_affinity(unsigned int irq, cstatic void dp264_set_affinity (unsigned int irq,const struct cpumask *affinity) -{ +{ +cpumask_copy (irq_desc[irq].affinity, affinity);spin_lock (&dp264_irq_lock);cpu_set_irq_affinity (irq, *affinity);tsunami_update_irq_hw (cached_irq_mask);
@@ -187,7 +188,8 @@ dp264_set_affinity(unsigned int irq, constatic void clipper_set_affinity (unsigned int irq,const struct cpumask *affinity) -{ +{ +cpumask_copy (irq_desc[irq].affinity, affinity);spin_lock (&dp264_irq_lock);cpu_set_irq_affinity (irq -16 , *affinity);tsunami_update_irq_hw (cached_irq_mask);
arch/alpha/kernel/sys_titan.c +2 -1
@@ -159,7 +159,8 @@ titan_cpu_set_irq_affinity(unsigned intstatic void titan_set_irq_affinity (unsigned int irq,const struct cpumask *affinity) -{ +{ +cpumask_copy (irq_desc[irq].affinity, affinity);spin_lock (&titan_irq_lock);titan_cpu_set_irq_affinity (irq -16 , *affinity);titan_update_irq_hw (titan_cached_irq_mask);
arch/arm/common/gic.c +1 -0
@@ -118,6 +118,7 @@ static void gic_set_cpu(unsigned int irqspin_lock (&irq_controller_lock); irq_desc[irq].cpu = cpu; +cpumask_copy (irq_desc[irq].affinity, mask_val); val =readl (reg) & ~(0xff << shift); val |=1 << (cpu + shift);writel (val, reg);
arch/cris/arch-v32/kernel/irq.c +1 -0
@@ -330,6 +330,7 @@ void set_affinity_crisv32_irq(unsigned iunsigned long flags;spin_lock_irqsave (&irq_lock, flags); irq_allocations[irq -FIRST_IRQ ].mask = *dest; +cpumask_copy (irq_desc[j].affinity, dest);spin_unlock_irqrestore (&irq_lock, flags); }
arch/ia64/kernel/iosapic.c +3 -0
@@ -338,6 +338,7 @@ iosapic_set_affinity(unsigned int irq, cint redir = (irq &IA64_IRQ_REDIRECTED ) ?1 :0 ;struct iosapic_rte_info *rte;struct iosapic *iosapic; +irq_desc_t *idesc = irq_desc + irq; irq &= (~IA64_IRQ_REDIRECTED );
@@ -353,6 +354,8 @@ iosapic_set_affinity(unsigned int irq, cif (!iosapic_intr_info[irq].count)return ;/* not an IOSAPIC interrupt */ +cpumask_copy (desc->affinity, mask); +set_irq_affinity_info (irq, dest, redir);/* dest contains both id and eid */
arch/ia64/sn/kernel/irq.c +3 -0
@@ -232,6 +232,9 @@ static void sn_set_affinity_irq(unsignedstruct sn_irq_info *sn_irq_info, *sn_irq_info_safe;nasid_t nasid;int slice; +struct irq_desc *desc =irq_to_desc (irq); + +cpumask_copy (desc->affinity, mask); nasid =cpuid_to_nasid (cpumask_first (mask)); slice =cpuid_to_slice (cpumask_first (mask));
arch/mips/cavium-octeon/octeon-irq.c +6 -0
@@ -181,6 +181,9 @@ static void octeon_irq_ciu0_set_affinity {int cpu;int bit = irq -OCTEON_IRQ_WORKQ0 ;/* Bit 0-63 of EN0 */ +irq_desc_t *desc = irq_desc + irq; + +cpumask_copy (desc->affinity, dest);write_lock (&octeon_irq_ciu0_rwlock);for_each_online_cpu (cpu) {
@@ -296,6 +299,9 @@ static void octeon_irq_ciu1_set_affinity {int cpu;int bit = irq -OCTEON_IRQ_WDOG0 ;/* Bit 0-63 of EN1 */ +irq_desc_t *desc = irq_desc + irq; + +cpumask_copy (desc->affinity, dest);write_lock (&octeon_irq_ciu1_rwlock);for_each_online_cpu (cpu) {
arch/mips/sibyte/bcm1480/irq.c +2 -0
@@ -123,6 +123,8 @@ static void bcm1480_set_affinity(unsigne } i =cpumask_first (mask); +cpumask_copy (desc->affinity, mask); +/* Convert logical CPU to physical CPU */ cpu =cpu_logical_map (i);
arch/mips/sibyte/sb1250/irq.c +2 -0
@@ -117,6 +117,8 @@ static void sb1250_set_affinity(unsignedreturn ; } +cpumask_copy (desc->affinity, mask); +/* Convert logical CPU to physical CPU */ cpu =cpu_logical_map (i);
arch/powerpc/platforms/pseries/xics.c +5 -0
@@ -339,6 +339,7 @@ static void xics_set_affinity(unsigned iint status;int xics_status[2 ];int irq_server; +struct irq_desc *desc; irq = (unsigned int )irq_map[virq].hwirq;if (irq ==XICS_IPI || irq ==XICS_IRQ_SPURIOUS )
@@ -374,6 +375,10 @@ static void xics_set_affinity(unsigned i __func__, irq, status);return ; } + + desc =get_irq_desc (virq); + +cpumask_copy (desc->affinity, cpumask); }static struct irq_chip xics_pic_direct = {
arch/powerpc/sysdev/mpic.c +2 -0
@@ -811,7 +811,9 @@ void mpic_set_affinity(unsigned int irq, {struct mpic *mpic =mpic_from_irq (irq);unsigned int src =mpic_irq_to_hw (irq); +struct irq_desc *desc =get_irq_desc (irq); +cpumask_copy (desc->affinity, cpumask);if (mpic->flags &MPIC_SINGLE_DEST_CPU ) {int cpuid =irq_choose_cpu (irq);
arch/sparc/kernel/irq_64.c +7 -0
@@ -321,6 +321,9 @@ static void sun4u_irq_enable(unsigned instatic void sun4u_set_affinity (unsigned int virt_irq,const struct cpumask *mask) { +struct irq_desc *desc = irq_desc + virt_irq; + +cpumask_copy (desc->affinity, mask);sun4u_irq_enable (virt_irq); }
@@ -382,8 +385,10 @@ static void sun4v_set_affinity(unsigned {unsigned int ino = virt_irq_table[virt_irq].dev_ino;unsigned long cpuid =irq_choose_cpu (virt_irq); +struct irq_desc *desc = irq_desc + virt_irq;int err; +cpumask_copy (desc->affinity, mask); err =sun4v_intr_settarget (ino, cpuid);if (err !=HV_EOK ) printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): "
@@ -449,8 +454,10 @@ static void sun4v_virt_set_affinity(unsi const struct cpumask *mask) {unsigned long cpuid, dev_handle, dev_ino; +struct irq_desc *desc = irq_desc + virt_irq;int err; +cpumask_copy (desc->affinity, mask); cpuid =irq_choose_cpu (virt_irq); dev_handle = virt_irq_table[virt_irq].dev_handle;
drivers/xen/events.c +2 -0
@@ -713,6 +713,8 @@ static void rebind_irq_to_cpu(unsigned istatic void set_affinity_irq (unsigned irq,const struct cpumask *dest) {unsigned tcpu =cpumask_first (dest); + +cpumask_copy (irq_to_desc (irq)->affinity, mask);rebind_irq_to_cpu (irq, tcpu); }
kernel/irq/manage.c +2 -4
@@ -109,15 +109,13 @@ int irq_set_affinity(unsigned int irq, cspin_lock_irqsave (&desc->lock, flags);#ifdef CONFIG_GENERIC_PENDING_IRQ -if (desc->status &IRQ_MOVE_PCNTXT || desc->status &IRQ_DISABLED ) { -cpumask_copy (desc->affinity, cpumask); +if (desc->status &IRQ_MOVE_PCNTXT || desc->status &IRQ_DISABLED ) desc->chip->set_affinity (irq, cpumask); - }else { +else { desc->status |=IRQ_MOVE_PENDING ;cpumask_copy (desc->pending_mask, cpumask); }#else -cpumask_copy (desc->affinity, cpumask); desc->chip->set_affinity (irq, cpumask);#endif irq_set_thread_affinity (desc, cpumask);
kernel/irq/migration.c +3 -5
@@ -39,11 +39,9 @@ void move_masked_irq(int irq)* masking the irqs. */ if (likely (cpumask_any_and (desc->pending_mask, cpu_online_mask) - < nr_cpu_ids)) { -cpumask_and (desc->affinity, - desc->pending_mask, cpu_online_mask); - desc->chip->set_affinity (irq, desc->affinity); - } + < nr_cpu_ids)) + desc->chip->set_affinity (irq, desc->pending_mask); +cpumask_clear (desc->pending_mask); }
PATCH 1/1 irq: remove wrong ifdef
Impact: fix smp_affinity copying
CPUMASKS_OFFSTACK is not defined anywhere.
and init_allocate_desc_masks called before it set affinity to all cpus...
just remove those #idef to make them get copied
--- include/linux/irq.h | 4 ---- 1 file changed, 4 deletions(-)
include/linux/irq.h +0 -4
@@ -468,20 +468,16 @@ static inline bool init_alloc_desc_masks* @new_desc: pointer to new irq_desc struct * * Insures affinity and pending_masks are copied to new irq_desc. -* If !CONFIG_CPUMASKS_OFFSTACK the cpumasks are embedded in the -* irq_desc struct so the copy is redundant. */ static inline void init_copy_desc_masks (struct irq_desc *old_desc,struct irq_desc *new_desc) { -#ifdef CONFIG_CPUMASKS_OFFSTACK cpumask_copy (new_desc->affinity, old_desc->affinity);#ifdef CONFIG_GENERIC_PENDING_IRQ cpumask_copy (new_desc->pending_mask, old_desc->pending_mask);#endif -#endif }#else /* !CONFIG_SMP */
Re: [PATCH] irq: remove wrong ifdef
Quoted 28 lines · On Saturday 28 March 2009 15:15:34 Yinghai Lu wrote:
Impact: fix
smp_affinitycopying
CPUMASKS_OFFSTACKis not defined anywhere.
andinit_allocate_desc_maskscalled before it set affinity to all cpus...just remove those #idef to make them get copied
Signed-off-by Yinghai Lu <[email protected]>--- include/linux/irq.h | 4 ---- 1 file changed, 4 deletions(-)Index:
linux-2.6/include/linux/irq.h
===================================================================include/linux/irq.h +0
-2@@ -468,20 +468,16 @@ static inline bool init_alloc_desc_masks* @new_desc: pointer to new irq_desc struct * * Insures affinity and pending_masks are copied to new irq_desc. -* If !CONFIG_CPUMASKS_OFFSTACK the cpumasks are embedded in the -* irq_desc struct so the copy is redundant. */ static inline void init_copy_desc_masks (struct irq_desc *old_desc,struct irq_desc *new_desc) {
include/linux/irq.h static inline bool init_alloc_desc_masks · line 483
Quoted 10 lines
include/linux/irq.h +0
-2-#ifdef CONFIG_CPUMASKS_OFFSTACK cpumask_copy (new_desc->affinity, old_desc->affinity);#ifdef CONFIG_GENERIC_PENDING_IRQ cpumask_copy (new_desc->pending_mask, old_desc->pending_mask); #endif -#endif }#else /* !CONFIG_SMP */
Wow, that is supposed to be CONFIG_CPUMASK_OFFSTACK.
The reason it is there is that we already do the memcpy of old_desc: this extra copy is only needed if the cpumasks are external. But perhaps it's an over-optimization.
Thanks,
Rusty.
PATCH 1/1 irq: correct CPUMASKS_OFFSTACK typo -v2
Impact: fix smp_affinity copying when moving irq_desc
CPUMASKS_OFFSTACK is not defined anywhere. it is a typo
and init_allocate_desc_masks called before it set affinity to all cpus...
split init_alloc_desc_masks() into all_desc_masks() and init_desc_masks() so in the init_copy_desc_masks could use CPUMASK_OFFSTACK there. aka copy path will not calling init_desc_masks anymore.
also could use that CPUMASK_OFFSTACK in alloc_desc_masks()
--- include/linux/irq.h | 27 ++++++++++++++++++--------- kernel/irq/handle.c | 9 ++++++--- kernel/irq/numa_migrate.c | 2 +- 3 files changed, 25 insertions(+), 13 deletions(-)
include/linux/irq.h +18 -9
@@ -421,27 +421,25 @@ extern int set_irq_msi(unsigned int irq,#ifdef CONFIG_SMP /** -* init_alloc_desc_masks - allocate cpumasks for irq_desc +* alloc_desc_masks - allocate cpumasks for irq_desc * @desc: pointer to irq_desc struct * @cpu: cpu which will be handling the cpumasks * @boot: true if need bootmem * * Allocates affinity and pending_mask cpumask if required. * Returns true if successful (or not required). -* Side effect: affinity has all bits set, pending_mask has all bits clear. */ -static inline bool init_alloc_desc_masks (struct irq_desc *desc,int cpu, +static inline bool alloc_desc_masks (struct irq_desc *desc,int cpu,bool boot) { +#ifdef CONFIG_CPUMASK_OFFSTACK int node;if (boot) {alloc_bootmem_cpumask_var (&desc->affinity); -cpumask_setall (desc->affinity);#ifdef CONFIG_GENERIC_PENDING_IRQ alloc_bootmem_cpumask_var (&desc->pending_mask); -cpumask_clear (desc->pending_mask);#endif return true; }
@@ -450,18 +448,25 @@ static inline bool init_alloc_desc_masksif (!alloc_cpumask_var_node (&desc->affinity,GFP_ATOMIC , node))return false; -cpumask_setall (desc->affinity);#ifdef CONFIG_GENERIC_PENDING_IRQ if (!alloc_cpumask_var_node (&desc->pending_mask,GFP_ATOMIC , node)) {free_cpumask_var (desc->affinity);return false; } -cpumask_clear (desc->pending_mask); +#endif #endif return true; } +static inline void init_desc_masks (struct irq_desc *desc) +{ +cpumask_setall (desc->affinity); +#ifdef CONFIG_GENERIC_PENDING_IRQ +cpumask_clear (desc->pending_mask); +#endif +} +/** * init_copy_desc_masks - copy cpumasks for irq_desc * @old_desc: pointer to old irq_desc struct
@@ -475,7 +480,7 @@ static inline bool init_alloc_desc_masksstatic inline void init_copy_desc_masks (struct irq_desc *old_desc,struct irq_desc *new_desc) { -#ifdef CONFIG_CPUMASKS_OFFSTACK +#ifdef CONFIG_CPUMASK_OFFSTACK cpumask_copy (new_desc->affinity, old_desc->affinity);#ifdef CONFIG_GENERIC_PENDING_IRQ
@@ -486,12 +491,16 @@ static inline void init_copy_desc_masks(#else /* !CONFIG_SMP */ -static inline bool init_alloc_desc_masks (struct irq_desc *desc,int cpu, +static inline bool alloc_desc_masks (struct irq_desc *desc,int cpu,bool boot) {return true; } +static inline void init_desc_masks (struct irq_desc *desc) +{ +} +static inline void init_copy_desc_masks (struct irq_desc *old_desc,struct irq_desc *new_desc) {
kernel/irq/handle.c +6 -3
@@ -115,10 +115,11 @@ static void init_one_irq_desc(int irq, sprintk (KERN_ERR "can not alloc kstat_irqs\n" );BUG_ON (1 ); } -if (!init_alloc_desc_masks (desc, cpu, false)) { +if (!alloc_desc_masks (desc, cpu, false)) {printk (KERN_ERR "can not alloc irq_desc cpumasks\n" );BUG_ON (1 ); } +init_desc_masks (desc);arch_init_chip_data (desc, cpu); }
@@ -169,7 +170,8 @@ int __init early_irq_init(void) desc[i].irq = i; desc[i].kstat_irqs = kstat_irqs_legacy + i * nr_cpu_ids;lockdep_set_class (&desc[i].lock, &irq_desc_lock_class); -init_alloc_desc_masks (&desc[i],0 , true); +alloc_desc_masks (&desc[i],0 , true); +init_desc_masks (&desc[i]); irq_desc_ptrs[i] = desc + i; }
@@ -256,7 +258,8 @@ int __init early_irq_init(void)for (i =0 ; i < count; i++) { desc[i].irq = i; -init_alloc_desc_masks (&desc[i],0 , true); +alloc_desc_masks (&desc[i],0 , true); +init_desc_masks (&desc[i]); desc[i].kstat_irqs = kstat_irqs_all[i]; }return arch_early_irq_init ();
kernel/irq/numa_migrate.c +1 -1
@@ -37,7 +37,7 @@ static bool init_copy_one_irq_desc(int i struct irq_desc *desc, int cpu) { memcpy(desc, old_desc, sizeof(struct irq_desc)); -if (!init_alloc_desc_masks (desc, cpu, false)) { +if (!alloc_desc_masks (desc, cpu, false)) {printk (KERN_ERR "irq %d: can not get new irq_desc cpumask " "for migration.\n" , irq);return false;
Re: [PATCH] irq: correct CPUMASKS_OFFSTACK typo -v2
Quoted 9 lines · On Sunday 29 March 2009 06:39:37 Yinghai Lu wrote:
Impact: fix
smp_affinitycopying when movingirq_desc
CPUMASKS_OFFSTACKis not defined anywhere. it is a typo
andinit_allocate_desc_maskscalled before it set affinity to all cpus...split
init_alloc_desc_masks()intoall_desc_masks()andinit_desc_masks()so in theinit_copy_desc_maskscould useCPUMASK_OFFSTACKthere. aka copy path will not callinginit_desc_masksanymore.
Thankyou, this code is nicer than what was there before.
Thanks!
Rusty.
Re: [PATCH] irq: remove wrong ifdef
In reply to Rusty RussellQuoted 38 lines · Rusty Russell
Quoted 37 lines · On Saturday 28 March 2009 15:15:34 Yinghai Lu wrote:
Impact: fix
smp_affinitycopying
CPUMASKS_OFFSTACKis not defined anywhere.
andinit_allocate_desc_maskscalled before it set affinity to all cpus...just remove those #idef to make them get copied
Signed-off-by Yinghai Lu <[email protected]>--- include/linux/irq.h | 4 ---- 1 file changed, 4 deletions(-)Index:
linux-2.6/include/linux/irq.h
===================================================================include/linux/irq.h +0
-4@@ -468,20 +468,16 @@ static inline bool init_alloc_desc_masks* @new_desc: pointer to new irq_desc struct * * Insures affinity and pending_masks are copied to new irq_desc. -* If !CONFIG_CPUMASKS_OFFSTACK the cpumasks are embedded in the -* irq_desc struct so the copy is redundant. */ static inline void init_copy_desc_masks (struct irq_desc *old_desc,struct irq_desc *new_desc) { -#ifdef CONFIG_CPUMASKS_OFFSTACK cpumask_copy (new_desc->affinity, old_desc->affinity);#ifdef CONFIG_GENERIC_PENDING_IRQ cpumask_copy (new_desc->pending_mask, old_desc->pending_mask);#endif -#endif }
Quoted 7 lines
include/linux/irq.h static inline bool init_alloc_desc_masks · line 483
Quoted 1 line
include/linux/irq.h +0
-0#else /* !CONFIG_SMP */ Wow, that is supposed to be
CONFIG_CPUMASK_OFFSTACK.The reason it is there is that we already do the memcpy of
old_desc: this extra copy is only needed if the cpumasks are external. But perhaps it's an over-optimization.
please check
[PATCH] irq: correct CPUMASKS_OFFSTACK typo -v2
because init_alloc_desc_masks will set desc->affinity to all cpus even CPUMASK_OFFSET is not set.
-v2 will seperate that function to alloc_desc_masks and init_desc_masks.
YH