x86/fixup_irq: Clean the offlining CPU from the irq affinity mask
PATCH 1/1 x86/fixup_irq: Clean the offlining CPU from the irq affinity mask
When one CPU is going offline, and fixup_irqs() will re-set the irq affinity in some cases, we should clean the offlining CPU from the irq affinity.
The reason is setting offlining CPU as of the affinity is useless. Moreover, the smp_affinity value will be confusing when the offlining CPU come back again.
Example:
For irq 93 with 4 CPUS, the default affinity f(1111), normal cases: 4 CPUS will receive the irq93 interrupts.
When echo 0 > /sys/devices/system/cpu/cpu3/online, just CPU0,1,2 will receive the interrupts.
But after the CPU3 is online again, we will not set affinity,the result will be:
the smp_affinity is f, but still just CPU0,1,2 can receive the interrupts.
So we should clean the offlining CPU from irq affinity mask in fixup_irqs().
--- arch/x86/kernel/irq.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
arch/x86/kernel/irq.c +3 -1
@@ -239,6 +239,7 @@ void fixup_irqs(void)struct irq_desc *desc;struct irq_data *data;struct irq_chip *chip; +int cpu =smp_processor_id ();for_each_irq_desc (irq, desc) {int break_affinity =0 ;
@@ -271,7 +272,8 @@ void fixup_irqs(void)if (cpumask_any_and (affinity, cpu_online_mask) >= nr_cpu_ids) { break_affinity =1 ; affinity = cpu_online_mask; - } + }else if (cpumask_test_cpu (cpu, data->affinity)) +cpumask_clear_cpu (cpu, data->affinity); chip =irq_data_get_irq_chip (data);if (!irqd_can_move_in_process_context (data) && chip->irq_mask)
Signature · 1 line
1.7.0.4
Quoted 41 lines · Chuansheng Liu
When one CPU is going offline, and
fixup_irqs()will re-set the irq affinity in some cases, we should clean the offlining CPU from the irq affinity.The reason is setting offlining CPU as of the affinity is useless. Moreover, the
smp_affinityvalue will be confusing when the offlining CPU come back again.Example:
For irq 93 with 4 CPUS, the default affinity f(1111), normal cases: 4 CPUS will receive the irq93 interrupts.When echo 0 >
/sys/devices/system/cpu/cpu3/online, just CPU0,1,2 will receive the interrupts.But after the CPU3 is online again, we will not set affinity,the result will be:
thesmp_affinityis f, but still just CPU0,1,2 can receive the interrupts.So we should clean the offlining CPU from irq affinity mask in
fixup_irqs().Signed-off-by liu chuansheng <[email protected]>--- arch/x86/kernel/irq.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)arch/x86/kernel/irq.c +1
-0@@ -239,6 +239,7 @@ void fixup_irqs(void)struct irq_desc *desc;struct irq_data *data;struct irq_chip *chip; +int cpu =smp_processor_id ();for_each_irq_desc (irq, desc) {int break_affinity =0 ;
arch/x86/kernel/irq.c void fixup_irqs(void) · line 277
Quoted 7 lines
arch/x86/kernel/irq.c +2
-1@@ -271,7 +272,8 @@ void fixup_irqs(void)if (cpumask_any_and (affinity, cpu_online_mask) >= nr_cpu_ids) { break_affinity =1 ; affinity = cpu_online_mask; - } + }else if (cpumask_test_cpu (cpu, data->affinity)) +cpumask_clear_cpu (cpu, data->affinity);
You meant to use 'affinity' (instead of data->affinity) in the above 2 statements right? Note that we do chip->irq_set_affinity(data, affinity, true); further down.
Regards,
Srivatsa S. Bhat
Quoted 3 lines
arch/x86/kernel/irq.c +0
-0chip =irq_data_get_irq_chip (data);if (!irqd_can_move_in_process_context (data) && chip->irq_mask)
Quoted 7 lines
arch/x86/kernel/irq.c void fixup_irqs(void) · line 276
Quoted 3 lines
arch/x86/kernel/irq.c +2
-0+ }else if (cpumask_test_cpu (cpu, data->affinity)) +cpumask_clear_cpu (cpu, data->affinity);You meant to use 'affinity' (instead of
data->affinity) in the above 2 statements right? Note that we dochip->irq_set_affinity(data, affinity, true); further down.
Yes, I have noticed it, used data->affinity here is just for avoiding compile warning.
in fact affinity == data->affinity, but affinity pointer is const type,
And cpumask_clear_cpu needs non-const type,so here I am using data->affinity,
instead of changing code "const struct cpumask *affinity;" ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Quoted 8 lines · Chuansheng
Quoted 7 lines
arch/x86/kernel/irq.c void fixup_irqs(void) · line 276
Quoted 3 lines
arch/x86/kernel/irq.c +2
-0+ }else if (cpumask_test_cpu (cpu, data->affinity)) +cpumask_clear_cpu (cpu, data->affinity);You meant to use 'affinity' (instead of
data->affinity) in the above 2 statements right? Note that we dochip->irq_set_affinity(data, affinity, true); further down.
Quoted 5 lines
Yes, I have noticed it, used
data->affinityhere is just for avoiding compile warning. in fact affinity ==data->affinity, but affinity pointer is const type, Andcpumask_clear_cpuneeds non-const type,so here I am usingdata->affinity, instead of changing code "const struct cpumask *affinity;"
Hmm.. Then what happens to error handling in the case that you can't set the affinity?
ie., if we take the 'else' branch in:
if (chip->irq_set_affinity)
chip->irq_set_affinity(data, affinity, true);
else if (!(warned++))
set_affinity = 0;In that case, we would end up with an incorrect data->affinity right?
Btw, on a slightly different note, I'm also rather surprised that the above code doesn't care about the return value of chip->irq_set_affinity() .. Shouldn't we warn if that fails?
Regards,
Srivatsa S. Bhat
Quoted 3 lines
Btw, on a slightly different note, I'm also rather surprised that the above code doesn't care about the return value of
chip->irq_set_affinity().. Shouldn't we warn if that fails?
It seems another case when irq_set_affinity is NULL whenever affinity is changed or not before that, For this case, I suppose the chip is not supporting set_affinity, then the chip should set all related irqs into just CPU0, otherwise, it will bring some trouble, do you agree?
I guess this case should be covered outside fixup_irqs() code.
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Quoted 8 lines · Chuansheng
Quoted 3 lines
Btw, on a slightly different note, I'm also rather surprised that the above code doesn't care about the return value of
chip->irq_set_affinity().. Shouldn't we warn if that fails?It seems another case when
irq_set_affinityis NULL whenever affinity is changed or not before that, For this case, I suppose the chip is not supportingset_affinity, then the chip should set all related irqs into just CPU0, otherwise, it will bring some trouble, do you agree?
Hmm.. no, I wouldn't jump to do that. Moreover, note that there are patches in -tip to enable CPU 0 hotplug. So doing the above might not be terribly helpful going forward.
Quoted 2 lines
I guess this case should be covered outside
fixup_irqs()code.
Regards,
Srivatsa S. Bhat
Quoted 1 line
Shouldn't we warn if that fails?
printk("Cannot set affinity for irq %i\n", irq);
This is the warning when set affinity failed. ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Quoted 4 lines · Chuansheng
Quoted 1 line
Shouldn't we warn if that fails?
printk("Cannot set affinity for irq %i\n", irq);
This is the warning when set affinity failed.
I know.. What I meant is, the code warns only if chip->irq_set_affinity is NULL and doesn't care if chip->irq_set_affinity was not NULL and the function failed to set the affinity (ie., when chip->irq_set_affinity() returns error). In other words, I meant to say that this is one more case where we need to warn about our failure to set the irq affinity.
Regards,
Srivatsa S. Bhat
Quoted 6 lines
I know.. What I meant is, the code warns only if
chip->irq_set_affinityis NULL and doesn't care ifchip->irq_set_affinitywas not NULL and the function failed to set the affinity (ie., whenchip->irq_set_affinity()returns error). In other words, I meant to say that this is one more case where we need to warn about our failure to set the irq affinity.
Got it, has resent the patch to include it, thanks your review. ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Quoted 2 lines
In that case, we would end up with an incorrect
data->affinityright?
Moving the clean cpu mask code into if (chip->irq_set_affinity)?
Will resend the patch and will judge the chip->irq_set_affinity(data, affinity, true)
return value. ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�