Re: [RFC PATCH v1 13/70] x86, x2apic_cluster: _FROZEN Cleanup

From: Chen, Gong
Date: Mon Jul 28 2014 - 02:36:16 EST


On Wed, Jul 23, 2014 at 10:36:28PM +0200, Borislav Petkov wrote:
> Those checks dealing with CPU_TASKS_FROZEN in-between make the whole
> switch statement hard to follow.
>
> How about we go a step further and deal with CPU_UP_CANCELED_FROZEN
> upfront and even simplify the rest:
>

--------8<--------
Subject: [RFC PATCH v2 13/70] x86, x2apic_cluster: _FROZEN Cleanup

Remove XXX_FROZEN state from x86/x2apic_cluster.

Signed-off-by: Chen, Gong <gong.chen@xxxxxxxxxxxxxxx>
Suggested-by: Borislav Petkov <bp@xxxxxxxxx>
---
arch/x86/kernel/apic/x2apic_cluster.c | 37 +++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
index e66766b..b8a6ea8 100644
--- a/arch/x86/kernel/apic/x2apic_cluster.c
+++ b/arch/x86/kernel/apic/x2apic_cluster.c
@@ -144,6 +144,20 @@ static void init_x2apic_ldr(void)
}
}

+static void __update_clusterinfo(unsigned int this_cpu)
+{
+ unsigned int cpu;
+
+ for_each_online_cpu(cpu) {
+ if (x2apic_cluster(this_cpu) != x2apic_cluster(cpu))
+ continue;
+ __cpu_clear(this_cpu, per_cpu(cpus_in_cluster, cpu));
+ __cpu_clear(cpu, per_cpu(cpus_in_cluster, this_cpu));
+ }
+ free_cpumask_var(per_cpu(cpus_in_cluster, this_cpu));
+ free_cpumask_var(per_cpu(ipi_mask, this_cpu));
+}
+
/*
* At CPU state changes, update the x2apic cluster sibling info.
*/
@@ -151,34 +165,31 @@ static int
update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
{
unsigned int this_cpu = (unsigned long)hcpu;
- unsigned int cpu;
int err = 0;

switch (action) {
case CPU_UP_PREPARE:
if (!zalloc_cpumask_var(&per_cpu(cpus_in_cluster, this_cpu),
- GFP_KERNEL)) {
+ GFP_KERNEL))
err = -ENOMEM;
- } else if (!zalloc_cpumask_var(&per_cpu(ipi_mask, this_cpu),
- GFP_KERNEL)) {
+ else if (!zalloc_cpumask_var(&per_cpu(ipi_mask, this_cpu),
+ GFP_KERNEL)) {
free_cpumask_var(per_cpu(cpus_in_cluster, this_cpu));
err = -ENOMEM;
}
break;
case CPU_UP_CANCELED:
- case CPU_UP_CANCELED_FROZEN:
case CPU_DEAD:
- for_each_online_cpu(cpu) {
- if (x2apic_cluster(this_cpu) != x2apic_cluster(cpu))
- continue;
- __cpu_clear(this_cpu, per_cpu(cpus_in_cluster, cpu));
- __cpu_clear(cpu, per_cpu(cpus_in_cluster, this_cpu));
- }
- free_cpumask_var(per_cpu(cpus_in_cluster, this_cpu));
- free_cpumask_var(per_cpu(ipi_mask, this_cpu));
+ __update_clusterinfo(this_cpu);
+ break;
+ default:
break;
}

+ if (test_and_clear_bit(CPU_TASKS_FROZEN, &action) &&
+ (action == CPU_UP_CANCELED))
+ __update_clusterinfo(this_cpu);
+
return notifier_from_errno(err);
}

--
2.0.0.rc2

Attachment: signature.asc
Description: Digital signature