xcp-1.6-updates/xen-4.1.hg

changeset 23251:f141db2fe4c1

x86: AMD core-pair topology detection code

This patch is to support core-pair topology introduced by AMD CPUs,
which introduces a new concept of [core, compute unit]. There is a new
feature bit for topology extension in CPUID:0x80000001. Also a new
CPUID 0x8000001E is introduced for CPU topology enumeration. This
patch collects the sibling information from the new CPUID and will be
stored in the sibling map in Xen hypervisor.

Signed-off-by: Wei Huang <wei.huang2@amd.com>
xen-unstable changeset: 23611:c2c12b2dafb5
xen-unstable date: Tue Jun 28 09:13:53 2011 +0100
author Wei Huang <wei.huang2@amd.com>
date Wed Mar 07 09:24:20 2012 +0000 (2012-03-07)
parents a168569a7659
children 6c3a6fb7013d
files xen/arch/x86/cpu/amd.c xen/arch/x86/cpu/common.c xen/arch/x86/smpboot.c xen/include/asm-x86/processor.h
line diff
     1.1 --- a/xen/arch/x86/cpu/amd.c	Wed Mar 07 09:23:41 2012 +0000
     1.2 +++ b/xen/arch/x86/cpu/amd.c	Wed Mar 07 09:24:20 2012 +0000
     1.3 @@ -344,6 +344,49 @@ static void check_syscfg_dram_mod_en(voi
     1.4  	wrmsrl(MSR_K8_SYSCFG, syscfg);
     1.5  }
     1.6  
     1.7 +static void __devinit amd_get_topology(struct cpuinfo_x86 *c)
     1.8 +{
     1.9 +#ifdef CONFIG_X86_HT
    1.10 +        int cpu;
    1.11 +        unsigned bits;
    1.12 +
    1.13 +        if (c->x86_max_cores <= 1)
    1.14 +                return;
    1.15 +        /*
    1.16 +         * On a AMD multi core setup the lower bits of the APIC id
    1.17 +         * distingush the cores.
    1.18 +         */
    1.19 +        cpu = smp_processor_id();
    1.20 +        bits = (cpuid_ecx(0x80000008) >> 12) & 0xf;
    1.21 +
    1.22 +        if (bits == 0) {
    1.23 +                while ((1 << bits) < c->x86_max_cores)
    1.24 +                        bits++;
    1.25 +        }
    1.26 +
    1.27 +        /* Low order bits define the core id */
    1.28 +        c->cpu_core_id = c->phys_proc_id & ((1<<bits)-1);
    1.29 +        /* Convert local APIC ID into the socket ID */
    1.30 +        c->phys_proc_id >>= bits;
    1.31 +        /* Collect compute unit ID if available */
    1.32 +        if (cpu_has(c, X86_FEATURE_TOPOEXT)) {
    1.33 +                u32 eax, ebx, ecx, edx;
    1.34 +
    1.35 +                cpuid(0x8000001e, &eax, &ebx, &ecx, &edx);
    1.36 +                c->compute_unit_id = ebx & 0xFF;
    1.37 +                c->x86_num_siblings = ((ebx >> 8) & 0x3) + 1;
    1.38 +        }
    1.39 +        
    1.40 +        if (opt_cpu_info)
    1.41 +                printk("CPU %d(%d) -> Processor %d, %s %d\n",
    1.42 +                       cpu, c->x86_max_cores, c->phys_proc_id,
    1.43 +                       cpu_has(c, X86_FEATURE_TOPOEXT) ? "Compute Unit" : 
    1.44 +                                                         "Core",
    1.45 +                       cpu_has(c, X86_FEATURE_TOPOEXT) ? c->compute_unit_id :
    1.46 +                                                         c->cpu_core_id);
    1.47 +#endif
    1.48 +}
    1.49 +
    1.50  static void __devinit init_amd(struct cpuinfo_x86 *c)
    1.51  {
    1.52  	u32 l, h;
    1.53 @@ -566,26 +609,7 @@ static void __devinit init_amd(struct cp
    1.54  		}
    1.55  	}
    1.56  
    1.57 -#ifdef CONFIG_X86_HT
    1.58 -	/*
    1.59 -	 * On a AMD multi core setup the lower bits of the APIC id
    1.60 -	 * distingush the cores.
    1.61 -	 */
    1.62 -	if (c->x86_max_cores > 1) {
    1.63 -		int cpu = smp_processor_id();
    1.64 -		unsigned bits = (cpuid_ecx(0x80000008) >> 12) & 0xf;
    1.65 -
    1.66 -		if (bits == 0) {
    1.67 -			while ((1 << bits) < c->x86_max_cores)
    1.68 -				bits++;
    1.69 -		}
    1.70 -		c->cpu_core_id = c->phys_proc_id & ((1<<bits)-1);
    1.71 -		c->phys_proc_id >>= bits;
    1.72 -		if (opt_cpu_info)
    1.73 -			printk("CPU %d(%d) -> Core %d\n",
    1.74 -			       cpu, c->x86_max_cores, c->cpu_core_id);
    1.75 -	}
    1.76 -#endif
    1.77 +        amd_get_topology(c);
    1.78  
    1.79  	/* Pointless to use MWAIT on Family10 as it does not deep sleep. */
    1.80  	if (c->x86 >= 0x10 && !force_mwait)
     2.1 --- a/xen/arch/x86/cpu/common.c	Wed Mar 07 09:23:41 2012 +0000
     2.2 +++ b/xen/arch/x86/cpu/common.c	Wed Mar 07 09:24:20 2012 +0000
     2.3 @@ -364,6 +364,7 @@ void __cpuinit identify_cpu(struct cpuin
     2.4  	c->x86_clflush_size = 0;
     2.5  	c->phys_proc_id = BAD_APICID;
     2.6  	c->cpu_core_id = BAD_APICID;
     2.7 +	c->compute_unit_id = BAD_APICID;
     2.8  	memset(&c->x86_capability, 0, sizeof c->x86_capability);
     2.9  
    2.10  	if (!have_cpuid_p()) {
     3.1 --- a/xen/arch/x86/smpboot.c	Wed Mar 07 09:23:41 2012 +0000
     3.2 +++ b/xen/arch/x86/smpboot.c	Wed Mar 07 09:24:20 2012 +0000
     3.3 @@ -241,6 +241,14 @@ static int booting_cpu;
     3.4  /* CPUs for which sibling maps can be computed. */
     3.5  static cpumask_t cpu_sibling_setup_map;
     3.6  
     3.7 +static void link_thread_siblings(int cpu1, int cpu2)
     3.8 +{
     3.9 +    cpu_set(cpu1, per_cpu(cpu_sibling_map, cpu2));
    3.10 +    cpu_set(cpu2, per_cpu(cpu_sibling_map, cpu1));
    3.11 +    cpu_set(cpu1, per_cpu(cpu_core_map, cpu2));
    3.12 +    cpu_set(cpu2, per_cpu(cpu_core_map, cpu1));
    3.13 +}
    3.14 +
    3.15  static void set_cpu_sibling_map(int cpu)
    3.16  {
    3.17      int i;
    3.18 @@ -252,13 +260,13 @@ static void set_cpu_sibling_map(int cpu)
    3.19      {
    3.20          for_each_cpu_mask ( i, cpu_sibling_setup_map )
    3.21          {
    3.22 -            if ( (c[cpu].phys_proc_id == c[i].phys_proc_id) &&
    3.23 -                 (c[cpu].cpu_core_id == c[i].cpu_core_id) )
    3.24 -            {
    3.25 -                cpu_set(i, per_cpu(cpu_sibling_map, cpu));
    3.26 -                cpu_set(cpu, per_cpu(cpu_sibling_map, i));
    3.27 -                cpu_set(i, per_cpu(cpu_core_map, cpu));
    3.28 -                cpu_set(cpu, per_cpu(cpu_core_map, i));
    3.29 +            if ( cpu_has(c, X86_FEATURE_TOPOEXT) ) {
    3.30 +                if ( (c[cpu].phys_proc_id == c[i].phys_proc_id) &&
    3.31 +                     (c[cpu].compute_unit_id == c[i].compute_unit_id) )
    3.32 +                    link_thread_siblings(cpu, i);
    3.33 +            } else if ( (c[cpu].phys_proc_id == c[i].phys_proc_id) &&
    3.34 +                        (c[cpu].cpu_core_id == c[i].cpu_core_id) ) {
    3.35 +                link_thread_siblings(cpu, i);
    3.36              }
    3.37          }
    3.38      }
    3.39 @@ -854,6 +862,7 @@ remove_siblinginfo(int cpu)
    3.40      cpus_clear(per_cpu(cpu_core_map, cpu));
    3.41      c[cpu].phys_proc_id = BAD_APICID;
    3.42      c[cpu].cpu_core_id = BAD_APICID;
    3.43 +    c[cpu].compute_unit_id = BAD_APICID;
    3.44      cpu_clear(cpu, cpu_sibling_setup_map);
    3.45  }
    3.46  
     4.1 --- a/xen/include/asm-x86/processor.h	Wed Mar 07 09:23:41 2012 +0000
     4.2 +++ b/xen/include/asm-x86/processor.h	Wed Mar 07 09:24:20 2012 +0000
     4.3 @@ -175,9 +175,10 @@ struct cpuinfo_x86 {
     4.4      __u32 x86_max_cores; /* cpuid returned max cores value */
     4.5      __u32 booted_cores;  /* number of cores as seen by OS */
     4.6      __u32 x86_num_siblings; /* cpuid logical cpus per chip value */
     4.7 +    __u32 apicid;
     4.8      int   phys_proc_id; /* package ID of each logical CPU */
     4.9      int   cpu_core_id; /* core ID of each logical CPU*/
    4.10 -    __u32 apicid;
    4.11 +    int   compute_unit_id; /* AMD compute unit ID of each logical CPU */
    4.12      unsigned short x86_clflush_size;
    4.13  } __cacheline_aligned;
    4.14