Skip to contentSkip to conversation

x86/fixup_irq: Clean the offlining CPU from the irq affinity mask

PATCH Superseded Chuansheng Liu 2 participants 10 messages Sep 26, 2012 x86

lore
Share & tools
lore
#0 lore raw

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
index d44f782..671d462 100644
@@ -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
#1 lore raw
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_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 +1 -0
index d44f782..671d462 100644
@@ -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 -0
 		chip = irq_data_get_irq_chip(data);
 		if (!irqd_can_move_in_process_context(data) && chip->irq_mask)
#2 lore raw
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 do chip->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�

#3 lore raw
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 do chip->irq_set_affinity(data, affinity, true); further down.

Quoted 5 lines

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;"

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

#4 lore raw
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�

#5 lore raw
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_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?

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

#6 lore raw
In reply to 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�

#7 lore raw
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

#8 lore raw
Quoted 6 lines

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.

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�

#9 lore raw
In reply to Srivatsa S. Bhat
Quoted 2 lines

In that case, we would end up with an incorrect data->affinity right?

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�