Skip to contentSkip to conversation

x86: always park offline CPUs

PATCH In review Jan Beulich 3 participants 3 messages Aug 26 – Sep 11

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: always park offline CPUs

While on AMD (or Hygon) CPUs the situation isn't as bad wrt broadcasting of #MC, some "multicast" can still happen. Therefore the reasoning to park CPUs rather than fully offlining them applies everywhere.

Don't retain the dependency on the "mce=" cmdline option either: That option may best be dropped as well, as not enabling MCE will result in a shutdown when #MC would otherwise be raised.

Drop the global variable, using a #define (just like common code does) instead. Outside of common code, simplify expressions / code accordingly. (In common code we still have to cater for x86 wanting it different from everyone else.)

---
As it was never actually used after its introduction, we may want to further consider dropping CPU_REMOVE again.

I was almost certain that we would have at least one place (presumably a CPU notifier handler) were we assumed no parking for AMD/Hygon. Yet I couldn't find anything; did I overlook the crucial bits?

xen/arch/x86/acpi/cpu_idle.c +2 -2
@@ -436,7 +436,7 @@ static void cf_check dump_cx(unsigned ch
 
         if ( cpu_online(cpu) )
             print_acpi_power(cpu, power);
-        else if ( park_offline_cpus )
+        else
             printk("CPU%u parked in state %u (C%u)\n", cpu,
                    power->last_state ? power->last_state->idx : 1,
                    power->last_state ? power->last_state->type : 1);
@@ -1360,7 +1360,7 @@ long set_cx_pminfo(uint32_t acpi_id, str
          * If we've just learned of more available C states, wake the CPU if
          * it's parked, so it can go back to sleep in perhaps a deeper state.
          */
-        if ( park_offline_cpus && apic_id != BAD_APICID )
+        if ( apic_id != BAD_APICID )
         {
             unsigned long flags;
 
xen/arch/x86/cpu/common.c +0 -3
@@ -432,9 +432,6 @@ void __init early_cpu_init(bool verbose)
 		paddr_bits -= (ebx >> 6) & 0x3f;
 	}
 
-	if (!(c->vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)))
-		park_offline_cpus = opt_mce;
-
 	initialize_cpu_data(0);
 }
 
xen/arch/x86/cpu/mcheck/mce.c +1 -8
@@ -716,15 +716,8 @@ static int cf_check cpu_callback(
         rc = cpu_bank_alloc(cpu);
         break;
 
-    case CPU_UP_CANCELED:
-    case CPU_DEAD:
-        if ( !park_offline_cpus )
-            cpu_bank_free(cpu);
-        break;
-
     case CPU_REMOVE:
-        if ( park_offline_cpus )
-            cpu_bank_free(cpu);
+        cpu_bank_free(cpu);
         break;
     }
 
xen/arch/x86/genapic/x2apic.c +1 -5
@@ -181,12 +181,8 @@ static int cf_check update_clusterinfo(
              !cond_alloc_cpumask_var(&per_cpu(scratch_mask, cpu)) )
             err = -ENOMEM;
         break;
-    case CPU_UP_CANCELED:
-    case CPU_DEAD:
+
     case CPU_REMOVE:
-        if ( park_offline_cpus == (action != CPU_REMOVE) ||
-             system_state == SYS_STATE_suspend )
-            break;
         if ( per_cpu(cluster_cpus, cpu) )
         {
             cpumask_clear_cpu(cpu, per_cpu(cluster_cpus, cpu));
xen/arch/x86/include/asm/percpu.h +1 -1
@@ -1,7 +1,7 @@
 #ifndef __X86_PERCPU_H__
 #define __X86_PERCPU_H__
 
-#define PARK_OFFLINE_CPUS_VAR
+#define park_offline_cpus true
 
 /*
  * Force uses of per_cpu() with an invalid area to attempt to access the
xen/arch/x86/include/asm/smp.h +0 -6
@@ -25,12 +25,6 @@ DECLARE_PER_CPU(cpumask_var_t, scratch_c
 DECLARE_PER_CPU(cpumask_var_t, hpet_scratch_cpumask);
 DECLARE_PER_CPU(cpumask_var_t, send_ipi_cpumask);
 
-/*
- * Do we, for platform reasons, need to actually keep CPUs online when we
- * would otherwise prefer them to be off?
- */
-extern bool park_offline_cpus;
-
 void smp_send_nmi_allbutself(void);
 
 void send_IPI_mask(const cpumask_t *mask, int vector);
xen/arch/x86/mpparse.c +2 -6
@@ -80,16 +80,12 @@ void __init set_nr_cpu_ids(unsigned int
 	printk(XENLOG_INFO "SMP: Allowing %u CPUs (%d hotplug CPUs)\n",
 	       max_cpus, max_t(int, max_cpus - num_processors, 0));
 
-	if (!park_offline_cpus)
-		tot_cpus = max_cpus;
 	nr_cpu_ids = min(tot_cpus, NR_CPUS + 0u);
 	if (nr_cpu_ids < num_processors)
 	{
 		unaccounted_cpus = true;
-		if (park_offline_cpus)
-			printk(XENLOG_WARNING
-			       "SMP: Cannot bring up %u further CPUs\n",
-			       num_processors - nr_cpu_ids);
+		printk(XENLOG_WARNING "SMP: Cannot bring up %u further CPUs\n",
+		       num_processors - nr_cpu_ids);
 	}
 
 #ifndef nr_cpumask_bits
xen/arch/x86/setup.c +1 -2
@@ -2144,8 +2144,7 @@ void asmlinkage __init noreturn __start_
             /* Set up node_to_cpumask based on cpu_to_node[]. */
             numa_add_cpu(i);
 
-            if ( (park_offline_cpus || num_online_cpus() < max_cpus) &&
-                 !cpu_online(i) )
+            if ( !cpu_online(i) )
             {
                 ret = cpu_up(i);
                 if ( ret != 0 )
xen/arch/x86/smp.c +1 -3
@@ -92,9 +92,7 @@ void send_IPI_mask(const cpumask_t *mask
     if ( system_state > SYS_STATE_smp_boot &&
          !unaccounted_cpus && !disabled_cpus && !cpu_in_hotplug_context() &&
          /* NB: get_cpu_maps lock requires enabled interrupts. */
-         local_irq_is_enabled() && (cpus_locked = get_cpu_maps()) &&
-         (park_offline_cpus ||
-          cpumask_equal(&cpu_online_map, &cpu_present_map)) )
+         local_irq_is_enabled() && (cpus_locked = get_cpu_maps()) )
         cpumask_or(scratch, mask, cpumask_of(smp_processor_id()));
     else
     {
xen/arch/x86/smpboot.c +1 -3
@@ -67,8 +67,6 @@ DEFINE_PER_CPU_READ_MOSTLY(struct stubs,
 cpumask_t cpu_online_map __read_mostly;
 EXPORT_SYMBOL(cpu_online_map);
 
-bool __read_mostly park_offline_cpus;
-
 unsigned int __read_mostly nr_sockets;
 cpumask_t **__read_mostly socket_cpumask;
 static cpumask_t *secondary_socket_cpumask;
@@ -1149,7 +1147,7 @@ static int cf_check cpu_smpboot_callback
         break;
     case CPU_UP_CANCELED:
     case CPU_DEAD:
-        cpu_smpboot_free(cpu, !park_offline_cpus);
+        cpu_smpboot_free(cpu, false);
         break;
     case CPU_REMOVE:
         cpu_smpboot_free(cpu, true);
xen/include/xen/percpu.h +1 -1
@@ -34,7 +34,7 @@
 #include <xen/types.h>
 #include <asm/current.h>
 
-#ifndef PARK_OFFLINE_CPUS_VAR
+#if !defined(PARK_OFFLINE_CPUS_VAR) && !defined(park_offline_cpus)
 /*
  * Do we, for platform reasons, need to actually keep CPUs online when we
  * would otherwise prefer them to be off?
#1 lore raw
Quoted 16 lines · Jan Beulich

While on AMD (or Hygon) CPUs the situation isn't as bad wrt broadcasting of #MC, some "multicast" can still happen. Therefore the reasoning to park CPUs rather than fully offlining them applies everywhere.

Don't retain the dependency on the "mce=" cmdline option either: That option may best be dropped as well, as not enabling MCE will result in a shutdown when #MC would otherwise be raised.

Drop the global variable, using a #define (just like common code does) instead. Outside of common code, simplify expressions / code accordingly. (In common code we still have to cater for x86 wanting it different from everyone else.)

Quoted 7 lines

---
As it was never actually used after its introduction, we may want to further consider dropping CPU_REMOVE again.

I was almost certain that we would have at least one place (presumably a CPU notifier handler) were we assumed no parking for AMD/Hygon. Yet I couldn't find anything; did I overlook the crucial bits?

FWIW, the per-CPU stack mapping bit of the ASI series I have would almost certainly have tripped over such an instance if it existed, but didn't.

I've tested this patch on an Intel box, whose behavior in theory shouldn't change. Not sure if that warrants a Tested-by, given that the main change should happen on an AMD box.

-George

Acked-by on v1 1/1
#2 lore raw
In reply to Jan Beulich
Quoted 8 lines · Jan Beulich

While on AMD (or Hygon) CPUs the situation isn't as bad wrt broadcasting of #MC, some "multicast" can still happen. Therefore the reasoning to park CPUs rather than fully offlining them applies everywhere.

Don't retain the dependency on the "mce=" cmdline option either: That option may best be dropped as well, as not enabling MCE will result in a shutdown when #MC would otherwise be raised.

Quoted 7 lines

Drop the global variable, using a #define (just like common code does) instead. Outside of common code, simplify expressions / code accordingly. (In common code we still have to cater for x86 wanting it different from everyone else.)

Quoted 7 lines

---
As it was never actually used after its introduction, we may want to further consider dropping CPU_REMOVE again.

I was almost certain that we would have at least one place (presumably a CPU notifier handler) were we assumed no parking for AMD/Hygon. Yet I couldn't find anything; did I overlook the crucial bits?

Quite possibly not.  This code very rarely changes.

There will be a lot of cleanup to follow.

~Andrew