vpmu: separate architecture specific PMU initialisation
authorDietmar Hahn <dietmar.hahn@ts.fujitsu.com>
Fri, 20 Jan 2012 10:40:16 +0000 (10:40 +0000)
committerDietmar Hahn <dietmar.hahn@ts.fujitsu.com>
Fri, 20 Jan 2012 10:40:16 +0000 (10:40 +0000)
This patch moves the architecture specific initialisation of the PMU
into the archicture specific directory.

Signed-off-by: Dietmar Hahn <dietmar.hahn@ts.fujitsu.com>
Signed-off-by: Keir Fraser <keir@xen.org>
Committed-by: Keir Fraser <keir@xen.org>
xen/arch/x86/hvm/svm/vpmu.c
xen/arch/x86/hvm/vmx/vpmu_core2.c
xen/arch/x86/hvm/vpmu.c
xen/include/asm-x86/hvm/vpmu.h

index 30288a4fc59c05a395016f7d2f406c31329b593b..1a69249ca4bc30812018738a5820667a7da1b555 100644 (file)
@@ -296,7 +296,7 @@ static void amd_vpmu_initialise(struct vcpu *v)
 {
     struct amd_vpmu_context *ctxt = NULL;
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
-    __u8 family = current_cpu_data.x86;
+    uint8_t family = current_cpu_data.x86;
 
     if ( vpmu->flags & VPMU_CONTEXT_ALLOCATED )
         return;
@@ -362,3 +362,25 @@ struct arch_vpmu_ops amd_vpmu_ops = {
     .arch_vpmu_save = amd_vpmu_save,
     .arch_vpmu_load = amd_vpmu_restore
 };
+
+int svm_vpmu_initialise(struct vcpu *v)
+{
+    struct vpmu_struct *vpmu = vcpu_vpmu(v);
+    uint8_t family = current_cpu_data.x86;
+
+    switch ( family )
+    {
+    case 0x10:
+    case 0x12:
+    case 0x14:
+    case 0x15:
+        vpmu->arch_vpmu_ops = &amd_vpmu_ops;
+        return 0;
+    }
+
+    printk("VPMU: Initialization failed. "
+           "AMD processor family %d has not "
+           "been supported\n", family);
+    return -EINVAL;
+}
+
index 19ac9cbb0477828be501a478278090a745592cd7..35ef78a5fdd8a5dc3b56d906d98b7f5e44c55e5e 100644 (file)
@@ -607,3 +607,32 @@ struct arch_vpmu_ops core2_vpmu_ops = {
     .arch_vpmu_save = core2_vpmu_save,
     .arch_vpmu_load = core2_vpmu_load
 };
+
+int vmx_vpmu_initialise(struct vcpu *v)
+{
+    struct vpmu_struct *vpmu = vcpu_vpmu(v);
+    uint8_t family = current_cpu_data.x86;
+    uint8_t cpu_model = current_cpu_data.x86_model;
+
+    if ( family == 6 )
+    {
+        switch ( cpu_model )
+        {
+        case 15:
+        case 23:
+        case 26:
+        case 29:
+        case 42:
+        case 46:
+        case 47:
+            vpmu->arch_vpmu_ops = &core2_vpmu_ops;
+            return 0;
+        }
+    }
+
+    printk("VPMU: Initialization failed. "
+           "Intel processor family %d model %d has not "
+           "been supported\n", family, cpu_model);
+    return -EINVAL;
+}
+
index d761fb2c91f5582acbdefaeb4a72f36a3cc7dc41..bae6eedcf419c1ea73c5403db9309b20b02feb13 100644 (file)
@@ -81,9 +81,7 @@ void vpmu_load(struct vcpu *v)
 void vpmu_initialise(struct vcpu *v)
 {
     struct vpmu_struct *vpmu = vcpu_vpmu(v);
-    __u8 vendor = current_cpu_data.x86_vendor;
-    __u8 family = current_cpu_data.x86;
-    __u8 cpu_model = current_cpu_data.x86_model;
+    uint8_t vendor = current_cpu_data.x86_vendor;
 
     if ( !opt_vpmu_enabled )
         return;
@@ -94,47 +92,19 @@ void vpmu_initialise(struct vcpu *v)
     switch ( vendor )
     {
     case X86_VENDOR_AMD:
-        switch ( family )
-        {
-        case 0x10:
-        case 0x12:
-        case 0x14:
-        case 0x15:
-            vpmu->arch_vpmu_ops = &amd_vpmu_ops;
-            break;
-        default:
-            printk("VPMU: Initialization failed. "
-                   "AMD processor family %d has not "
-                   "been supported\n", family);
-            return;
-        }
+        if ( svm_vpmu_initialise(v) != 0 )
+            opt_vpmu_enabled = 0;
         break;
 
     case X86_VENDOR_INTEL:
-        if ( family == 6 )
-        {
-            switch ( cpu_model )
-            {
-            case 15:
-            case 23:
-            case 26:
-            case 29:
-            case 42:
-            case 46:
-            case 47:
-                vpmu->arch_vpmu_ops = &core2_vpmu_ops;
-                break;
-            }
-        }
-        if ( vpmu->arch_vpmu_ops == NULL )
-            printk("VPMU: Initialization failed. "
-                   "Intel processor family %d model %d has not "
-                   "been supported\n", family, cpu_model);
+        if ( vmx_vpmu_initialise(v) != 0 )
+            opt_vpmu_enabled = 0;
         break;
 
     default:
         printk("VPMU: Initialization failed. "
                "Unknown CPU vendor %d\n", vendor);
+        opt_vpmu_enabled = 0;
         break;
     }
 
index 276333fd8046aa965b8300482118116f2361114c..d08bbc6214e768d4df9ece81023c8a3d32c85ce8 100644 (file)
@@ -56,8 +56,8 @@ struct arch_vpmu_ops {
     void (*arch_vpmu_load)(struct vcpu *v);
 };
 
-extern struct arch_vpmu_ops core2_vpmu_ops;
-extern struct arch_vpmu_ops amd_vpmu_ops;
+int vmx_vpmu_initialise(struct vcpu *v);
+int svm_vpmu_initialise(struct vcpu *v);
 
 struct vpmu_struct {
     u32 flags;