ia64/xen-unstable

changeset 17187:21532468020b

x86: New vcpu_op call to get physical CPU identity.

Some AMD machines have APIC IDs that not equal to CPU IDs. In
the default Xen configuration, ACPI calls on these machines
can get confused. This shows up most noticeably when running
AMD PowerNow!. The only solution is for dom0 to get the
hypervisor's cpuid to apicid table when needed (ie, when dom0
vcpus are pinned).

Add a vcpu op to Xen to allow dom0 to query the hypervisor for
architecture dependent physical cpu information if dom0 vcpus are
pinned.

Signed-off-by: Mark Langsdorf <mark.langsdorf@amd.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Mar 05 10:52:51 2008 +0000 (2008-03-05)
parents 854b0704962b
children e1898e917373
files xen/arch/x86/acpi/boot.c xen/arch/x86/domain.c xen/common/domain.c xen/common/schedule.c xen/include/public/vcpu.h xen/include/xen/acpi.h xen/include/xen/sched.h
line diff
     1.1 --- a/xen/arch/x86/acpi/boot.c	Wed Mar 05 09:43:03 2008 +0000
     1.2 +++ b/xen/arch/x86/acpi/boot.c	Wed Mar 05 10:52:51 2008 +0000
     1.3 @@ -1029,3 +1029,17 @@ int __init acpi_boot_init(void)
     1.4  
     1.5  	return 0;
     1.6  }
     1.7 +
     1.8 +unsigned int acpi_get_processor_id(unsigned int cpu)
     1.9 +{
    1.10 +	unsigned int acpiid, apicid;
    1.11 +
    1.12 +	if ((apicid = x86_cpu_to_apicid[cpu]) == 0xff)
    1.13 +		return 0xff;
    1.14 +
    1.15 +	for (acpiid = 0; acpiid < ARRAY_SIZE(x86_acpiid_to_apicid); acpiid++)
    1.16 +		if (x86_acpiid_to_apicid[acpiid] == apicid)
    1.17 +			return acpiid;
    1.18 +
    1.19 +	return 0xff;
    1.20 +}
     2.1 --- a/xen/arch/x86/domain.c	Wed Mar 05 09:43:03 2008 +0000
     2.2 +++ b/xen/arch/x86/domain.c	Wed Mar 05 10:52:51 2008 +0000
     2.3 @@ -29,6 +29,7 @@
     2.4  #include <xen/console.h>
     2.5  #include <xen/percpu.h>
     2.6  #include <xen/compat.h>
     2.7 +#include <xen/acpi.h>
     2.8  #include <asm/regs.h>
     2.9  #include <asm/mc146818rtc.h>
    2.10  #include <asm/system.h>
    2.11 @@ -952,6 +953,25 @@ arch_do_vcpu_op(
    2.12          break;
    2.13      }
    2.14  
    2.15 +    case VCPUOP_get_physid:
    2.16 +    {
    2.17 +        struct vcpu_get_physid cpu_id;
    2.18 +
    2.19 +        rc = -EINVAL;
    2.20 +        if ( !v->domain->is_pinned )
    2.21 +            break;
    2.22 +
    2.23 +        cpu_id.phys_id = (x86_cpu_to_apicid[v->vcpu_id] |
    2.24 +                          (acpi_get_processor_id(v->vcpu_id) << 8));
    2.25 +
    2.26 +        rc = -EFAULT;
    2.27 +        if ( copy_to_guest(arg, &cpu_id, 1) )
    2.28 +            break;
    2.29 +
    2.30 +        rc = 0;
    2.31 +        break;
    2.32 +    }
    2.33 +
    2.34      default:
    2.35          rc = -ENOSYS;
    2.36          break;
     3.1 --- a/xen/common/domain.c	Wed Mar 05 09:43:03 2008 +0000
     3.2 +++ b/xen/common/domain.c	Wed Mar 05 10:52:51 2008 +0000
     3.3 @@ -30,6 +30,21 @@
     3.4  #include <public/vcpu.h>
     3.5  #include <xsm/xsm.h>
     3.6  
     3.7 +/* opt_dom0_vcpus_pin: If true, dom0 VCPUs are pinned. */
     3.8 +static unsigned int opt_dom0_vcpus_pin;
     3.9 +boolean_param("dom0_vcpus_pin", opt_dom0_vcpus_pin);
    3.10 +
    3.11 +enum cpufreq_controller cpufreq_controller;
    3.12 +static void __init setup_cpufreq_option(char *str)
    3.13 +{
    3.14 +    if ( !strcmp(str, "dom0-kernel") )
    3.15 +    {
    3.16 +        cpufreq_controller = FREQCTL_dom0_kernel;
    3.17 +        opt_dom0_vcpus_pin = 1;
    3.18 +    }
    3.19 +}
    3.20 +custom_param("cpufreq", setup_cpufreq_option);
    3.21 +
    3.22  /* Protect updates/reads (resp.) of domain_list and domain_hash. */
    3.23  DEFINE_SPINLOCK(domlist_update_lock);
    3.24  DEFINE_RCU_READ_LOCK(domlist_read_lock);
    3.25 @@ -198,6 +213,9 @@ struct domain *domain_create(
    3.26      if ( domcr_flags & DOMCRF_hvm )
    3.27          d->is_hvm = 1;
    3.28  
    3.29 +    if ( (domid == 0) && opt_dom0_vcpus_pin )
    3.30 +        d->is_pinned = 1;
    3.31 +
    3.32      rangeset_domain_initialise(d);
    3.33  
    3.34      if ( !is_idle_domain(d) )
     4.1 --- a/xen/common/schedule.c	Wed Mar 05 09:43:03 2008 +0000
     4.2 +++ b/xen/common/schedule.c	Wed Mar 05 10:52:51 2008 +0000
     4.3 @@ -38,21 +38,6 @@
     4.4  static char opt_sched[10] = "credit";
     4.5  string_param("sched", opt_sched);
     4.6  
     4.7 -/* opt_dom0_vcpus_pin: If true, dom0 VCPUs are pinned. */
     4.8 -static unsigned int opt_dom0_vcpus_pin;
     4.9 -boolean_param("dom0_vcpus_pin", opt_dom0_vcpus_pin);
    4.10 -
    4.11 -enum cpufreq_controller cpufreq_controller;
    4.12 -static void __init setup_cpufreq_option(char *str)
    4.13 -{
    4.14 -    if ( !strcmp(str, "dom0-kernel") )
    4.15 -    {
    4.16 -        cpufreq_controller = FREQCTL_dom0_kernel;
    4.17 -        opt_dom0_vcpus_pin = 1;
    4.18 -    }
    4.19 -}
    4.20 -custom_param("cpufreq", setup_cpufreq_option);
    4.21 -
    4.22  #define TIME_SLOP      (s32)MICROSECS(50)     /* allow time to slip a bit */
    4.23  
    4.24  /* Various timer handlers. */
    4.25 @@ -117,7 +102,7 @@ int sched_init_vcpu(struct vcpu *v, unsi
    4.26       * domain-0 VCPUs, are pinned onto their respective physical CPUs.
    4.27       */
    4.28      v->processor = processor;
    4.29 -    if ( is_idle_domain(d) || ((d->domain_id == 0) && opt_dom0_vcpus_pin) )
    4.30 +    if ( is_idle_domain(d) || d->is_pinned )
    4.31          v->cpu_affinity = cpumask_of_cpu(processor);
    4.32      else
    4.33          cpus_setall(v->cpu_affinity);
    4.34 @@ -302,7 +287,7 @@ static int __vcpu_set_affinity(
    4.35  
    4.36  int vcpu_set_affinity(struct vcpu *v, cpumask_t *affinity)
    4.37  {
    4.38 -    if ( (v->domain->domain_id == 0) && opt_dom0_vcpus_pin )
    4.39 +    if ( v->domain->is_pinned )
    4.40          return -EINVAL;
    4.41      return __vcpu_set_affinity(v, affinity, 0, 0);
    4.42  }
     5.1 --- a/xen/include/public/vcpu.h	Wed Mar 05 09:43:03 2008 +0000
     5.2 +++ b/xen/include/public/vcpu.h	Wed Mar 05 10:52:51 2008 +0000
     5.3 @@ -170,7 +170,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_set_singles
     5.4   *
     5.5   * This may be called only once per vcpu.
     5.6   */
     5.7 -#define VCPUOP_register_vcpu_info   10  /* arg == struct vcpu_info */
     5.8 +#define VCPUOP_register_vcpu_info   10  /* arg == vcpu_register_vcpu_info_t */
     5.9  struct vcpu_register_vcpu_info {
    5.10      uint64_t mfn;    /* mfn of page to place vcpu_info */
    5.11      uint32_t offset; /* offset within page */
    5.12 @@ -182,6 +182,22 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_register_vc
    5.13  /* Send an NMI to the specified VCPU. @extra_arg == NULL. */
    5.14  #define VCPUOP_send_nmi             11
    5.15  
    5.16 +/* 
    5.17 + * Get the physical ID information for a pinned vcpu's underlying physical
    5.18 + * processor.  The physical ID informmation is architecture-specific.
    5.19 + * On x86: id[7:0]=apic_id, id[15:8]=acpi_id, id[63:16]=mbz,
    5.20 + *         and an unavailable identifier is returned as 0xff.
    5.21 + * This command returns -EINVAL if it is not a valid operation for this VCPU.
    5.22 + */
    5.23 +#define VCPUOP_get_physid           12 /* arg == vcpu_get_physid_t */
    5.24 +struct vcpu_get_physid {
    5.25 +    uint64_t phys_id;
    5.26 +};
    5.27 +typedef struct vcpu_get_physid vcpu_get_physid_t;
    5.28 +DEFINE_XEN_GUEST_HANDLE(vcpu_get_physid_t);
    5.29 +#define xen_vcpu_physid_to_x86_apicid(physid) ((uint8_t)((physid)>>0))
    5.30 +#define xen_vcpu_physid_to_x86_acpiid(physid) ((uint8_t)((physid)>>8))
    5.31 +
    5.32  #endif /* __XEN_PUBLIC_VCPU_H__ */
    5.33  
    5.34  /*
     6.1 --- a/xen/include/xen/acpi.h	Wed Mar 05 09:43:03 2008 +0000
     6.2 +++ b/xen/include/xen/acpi.h	Wed Mar 05 10:52:51 2008 +0000
     6.3 @@ -447,6 +447,7 @@ extern acpi_table_handler acpi_table_ops
     6.4  
     6.5  typedef int (*acpi_madt_entry_handler) (acpi_table_entry_header *header, const unsigned long end);
     6.6  
     6.7 +unsigned int acpi_get_processor_id (unsigned int cpu);
     6.8  char * __acpi_map_table (unsigned long phys_addr, unsigned long size);
     6.9  unsigned long acpi_find_rsdp (void);
    6.10  int acpi_boot_init (void);
     7.1 --- a/xen/include/xen/sched.h	Wed Mar 05 09:43:03 2008 +0000
     7.2 +++ b/xen/include/xen/sched.h	Wed Mar 05 10:52:51 2008 +0000
     7.3 @@ -199,6 +199,8 @@ struct domain
     7.4      enum { DOMDYING_alive, DOMDYING_dying, DOMDYING_dead } is_dying;
     7.5      /* Domain is paused by controller software? */
     7.6      bool_t           is_paused_by_controller;
     7.7 +    /* Domain's VCPUs are pinned 1:1 to physical CPUs? */
     7.8 +    bool_t           is_pinned;
     7.9  
    7.10      /* Guest has shut down (inc. reason code)? */
    7.11      spinlock_t       shutdown_lock;