Skip to contentSkip to conversation

xen/arm: Implement MPIDR per VCPU

PATCH Superseded Julien Grall 2 participants 7 messages Jun 7, 2013 – Jun 13, 2013

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: Implement MPIDR per VCPU

Use different affinity for each VCPU and always expose an SMP systems to the guest.

---
 xen/arch/arm/domain.c           |   11 +++++++++--
 xen/include/asm-arm/processor.h |    6 ++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/domain.c +9 -2
index ff1410d..4654c9b 100644
@@ -150,7 +150,8 @@ static void ctxt_switch_to(struct vcpu *n)
     isb();
 
     WRITE_SYSREG32(n->domain->arch.vpidr, VPIDR_EL2);
-    WRITE_SYSREG(n->domain->arch.vmpidr, VMPIDR_EL2);
+    WRITE_SYSREG(n->domain->arch.vmpidr | (n->vcpu_id << MPIDR_AFF0_SHIFT),
+                 VMPIDR_EL2);
 
     /* VGIC */
     gic_restore_state(n);
@@ -495,7 +496,13 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)
 
     /* Default the virtual ID to match the physical */
     d->arch.vpidr = boot_cpu_data.midr.bits;
-    d->arch.vmpidr = boot_cpu_data.mpidr.bits;
+    /*
+     * Expose an SMP systems and remove the AFF0. It will be replace by
+     * the VPCU ID
+     * TODO: handle multi-threading processor
+     */
+    d->arch.vmpidr = boot_cpu_data.mpidr.bits & MPIDR_AFF0_MASK;
+    d->arch.vmpidr = (d->arch.vmpidr & ~MPIDR_UP) | MPIDR_SMP;
 
     /* TODO: retrieve the evtchn IRQ from the guest DTS */
     if ( d->domain_id )
xen/include/asm-arm/processor.h +6 -0
index 1c9d793..5181e7b 100644
@@ -6,6 +6,12 @@
 /* MIDR Main ID Register */
 #define MIDR_MASK    0xff0ffff0
 
+/* MPIDR Multiprocessor Affinity Register */
+#define MPIDR_UP            (1 << 30)
+#define MPIDR_SMP           (1 << 31)
+#define MPIDR_AFF0_SHIFT    (0)
+#define MPIDR_AFF0_MASK     (0xff << MPIDR_AFF0_SHIFT)
+
 /* TTBCR Translation Table Base Control Register */
 #define TTBCR_EAE    0x80000000
 #define TTBCR_N_MASK 0x07
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 14 lines · Julien Grall

Use different affinity for each VCPU and always expose an SMP systems to the guest.

---
 xen/arch/arm/domain.c           |   11 +++++++++--
 xen/include/asm-arm/processor.h |    6 ++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/domain.c +0 -0
index ff1410d..4654c9b 100644

xen/arch/arm/domain.c static void ctxt_switch_to(struct vcpu *n) · line 154

Quoted 6 lines
xen/arch/arm/domain.c +2 -1
@@ -150,7 +150,8 @@ static void ctxt_switch_to(struct vcpu *n)
     isb();
 
     WRITE_SYSREG32(n->domain->arch.vpidr, VPIDR_EL2);
-    WRITE_SYSREG(n->domain->arch.vmpidr, VMPIDR_EL2);
+    WRITE_SYSREG(n->domain->arch.vmpidr | (n->vcpu_id << MPIDR_AFF0_SHIFT),
+                 VMPIDR_EL2);

Perhaps we should add v->arch.vmpidr and use that instead?

xen/arch/arm/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags) · line 501

Quoted 10 lines
xen/arch/arm/domain.c +3 -1
     /* VGIC */
     gic_restore_state(n);
@@ -495,7 +496,13 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)
 
     /* Default the virtual ID to match the physical */
     d->arch.vpidr = boot_cpu_data.midr.bits;
-    d->arch.vmpidr = boot_cpu_data.mpidr.bits;
+    /*
+     * Expose an SMP systems and remove the AFF0. It will be replace by
+     * the VPCU ID

I wonder if that instead of basing this on the underlying processor we should fabricate an entirely virtual one?

Ian.

Quoted 24 lines
xen/arch/arm/domain.c +4 -0
+     * TODO: handle multi-threading processor
+     */
+    d->arch.vmpidr = boot_cpu_data.mpidr.bits & MPIDR_AFF0_MASK;
+    d->arch.vmpidr = (d->arch.vmpidr & ~MPIDR_UP) | MPIDR_SMP;
 
     /* TODO: retrieve the evtchn IRQ from the guest DTS */
     if ( d->domain_id )
xen/include/asm-arm/processor.h +6 -0
index 1c9d793..5181e7b 100644
@@ -6,6 +6,12 @@
 /* MIDR Main ID Register */
 #define MIDR_MASK    0xff0ffff0
 
+/* MPIDR Multiprocessor Affinity Register */
+#define MPIDR_UP            (1 << 30)
+#define MPIDR_SMP           (1 << 31)
+#define MPIDR_AFF0_SHIFT    (0)
+#define MPIDR_AFF0_MASK     (0xff << MPIDR_AFF0_SHIFT)
+
 /* TTBCR Translation Table Base Control Register */
 #define TTBCR_EAE    0x80000000
 #define TTBCR_N_MASK 0x07
#2 lore raw
Quoted 17 lines · Ian Campbell
Quoted 16 lines · Julien Grall

Use different affinity for each VCPU and always expose an SMP systems to the guest.

---
 xen/arch/arm/domain.c           |   11 +++++++++--
 xen/include/asm-arm/processor.h |    6 ++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/domain.c +0 -0
index ff1410d..4654c9b 100644
@@ -150,7 +150,8 @@ static void ctxt_switch_to(struct vcpu *n)
     isb();
 
Quoted 6 lines

xen/arch/arm/domain.c static void ctxt_switch_to(struct vcpu *n) · line 154

Quoted 4 lines
xen/arch/arm/domain.c +2 -1
     WRITE_SYSREG32(n->domain->arch.vpidr, VPIDR_EL2);
-    WRITE_SYSREG(n->domain->arch.vmpidr, VMPIDR_EL2);
+    WRITE_SYSREG(n->domain->arch.vmpidr | (n->vcpu_id << MPIDR_AFF0_SHIFT),
+                 VMPIDR_EL2);

Perhaps we should add v->arch.vmpidr and use that instead?

As it's a read-only register, why can't we recreate it at each context switch? Adding a new field per cpu is a waste of space mainly when the vcpu structure must not be greater than a page.

Quoted 4 lines
Quoted 4 lines
xen/arch/arm/domain.c +0 -0
     /* VGIC */
     gic_restore_state(n);
@@ -495,7 +496,13 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)
 
Quoted 9 lines

xen/arch/arm/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags) · line 501

Quoted 6 lines
xen/arch/arm/domain.c +3 -1
     /* Default the virtual ID to match the physical */
     d->arch.vpidr = boot_cpu_data.midr.bits;
-    d->arch.vmpidr = boot_cpu_data.mpidr.bits;
+    /*
+     * Expose an SMP systems and remove the AFF0. It will be replace by
+     * the VPCU ID

I wonder if that instead of basing this on the underlying processor we should fabricate an entirely virtual one?

Hum .. right, AFF1 could be different to 0.
Is it okay if xen exposes all the vcpus in the same cluster?

FYI, Linux uses the following approach to interpret MPIDR, in case of an SMP support without mutli-thread support):
- AFF0: Processors
- AFF1: Clusters
- AFF2: Unused

On the TC2 with big.LITTLE enabled, A7 and A5 are on different sockets, ie AFF1 fields are not the same. But it's only used for PMU (Performance monitor unit).

Signature · 1 line
Julien
#3 lore raw
Quoted 26 lines · Julien Grall
Quoted 17 lines · Ian Campbell
Quoted 16 lines · Julien Grall

Use different affinity for each VCPU and always expose an SMP systems to the guest.

---
 xen/arch/arm/domain.c           |   11 +++++++++--
 xen/include/asm-arm/processor.h |    6 ++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/domain.c +0 -0
index ff1410d..4654c9b 100644
@@ -150,7 +150,8 @@ static void ctxt_switch_to(struct vcpu *n)
     isb();
 
Quoted 6 lines

xen/arch/arm/domain.c static void ctxt_switch_to(struct vcpu *n) · line 154

Quoted 4 lines
xen/arch/arm/domain.c +2 -1
     WRITE_SYSREG32(n->domain->arch.vpidr, VPIDR_EL2);
-    WRITE_SYSREG(n->domain->arch.vmpidr, VMPIDR_EL2);
+    WRITE_SYSREG(n->domain->arch.vmpidr | (n->vcpu_id << MPIDR_AFF0_SHIFT),
+                 VMPIDR_EL2);

Perhaps we should add v->arch.vmpidr and use that instead?

Quoted 2 lines

As it's a read-only register, why can't we recreate it at each context switch?

Just to avoid unnecessary calculations on the context switch path. It's two memory accesses, a shift and an or rather than just one memory access. Maybe that's lost in the noise though.

Quoted 2 lines

Adding a new field per cpu is a waste of space mainly when the
vcpu structure must not be greater than a page.

How close are we to this?

Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/arm/domain.c +0 -0
     /* VGIC */
     gic_restore_state(n);
@@ -495,7 +496,13 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)
 
Quoted 9 lines

xen/arch/arm/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags) · line 501

Quoted 6 lines
xen/arch/arm/domain.c +3 -1
     /* Default the virtual ID to match the physical */
     d->arch.vpidr = boot_cpu_data.midr.bits;
-    d->arch.vmpidr = boot_cpu_data.mpidr.bits;
+    /*
+     * Expose an SMP systems and remove the AFF0. It will be replace by
+     * the VPCU ID

I wonder if that instead of basing this on the underlying processor we should fabricate an entirely virtual one?

Quoted 2 lines

Hum .. right, AFF1 could be different to 0.
Is it okay if xen exposes all the vcpus in the same cluster?

When Xen becomes multicluster aware then we will have to rethink but I think all vcpus in the same cluster is the correct thing to do for the time being.

Quoted 5 lines

FYI, Linux uses the following approach to interpret MPIDR, in case of an SMP support without mutli-thread support):
- AFF0: Processors
- AFF1: Clusters
- AFF2: Unused

This is implementation defined but this interpretation is consistent with example 2 of table B4-12 in the "Recommended use of the MPIDR" section of the ARM ARM.

On first glance example 1 seems to fit our use case better but on second reading I think "virtual CPU" in that context is referring to what we would call hyper-threads on x86 and not VCPU in the Xen sense. So following example 2 seems like the way to go.

Quoted 4 lines

On the TC2 with big.LITTLE enabled, A7 and A5 are on different sockets, ie AFF1 fields are not the same. But it's only used for PMU (Performance monitor unit).

#4 lore raw
Quoted 30 lines · Ian Campbell
Quoted 26 lines · Julien Grall
Quoted 17 lines · Ian Campbell
Quoted 16 lines · Julien Grall

Use different affinity for each VCPU and always expose an SMP systems to the guest.

---
 xen/arch/arm/domain.c           |   11 +++++++++--
 xen/include/asm-arm/processor.h |    6 ++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/domain.c +0 -0
index ff1410d..4654c9b 100644
@@ -150,7 +150,8 @@ static void ctxt_switch_to(struct vcpu *n)
     isb();
 
Quoted 6 lines

xen/arch/arm/domain.c static void ctxt_switch_to(struct vcpu *n) · line 154

Quoted 4 lines
xen/arch/arm/domain.c +2 -1
     WRITE_SYSREG32(n->domain->arch.vpidr, VPIDR_EL2);
-    WRITE_SYSREG(n->domain->arch.vmpidr, VMPIDR_EL2);
+    WRITE_SYSREG(n->domain->arch.vmpidr | (n->vcpu_id << MPIDR_AFF0_SHIFT),
+                 VMPIDR_EL2);

Perhaps we should add v->arch.vmpidr and use that instead?

Quoted 2 lines

As it's a read-only register, why can't we recreate it at each context switch?

Quoted 8 lines

Just to avoid unnecessary calculations on the context switch path. It's two memory accesses, a shift and an or rather than just one memory access. Maybe that's lost in the noise though.

Quoted 2 lines

Adding a new field per cpu is a waste of space mainly when the
vcpu structure must not be greater than a page.

How close are we to this?

The current size of each vcpu structure are:
- arm32 : 2304 bytes
- arm64 : 3328 bytes

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

xen/arch/arm/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags) · line 501

Quoted 12 lines
xen/arch/arm/domain.c +3 -1
     /* VGIC */
     gic_restore_state(n);
@@ -495,7 +496,13 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)
 
     /* Default the virtual ID to match the physical */
     d->arch.vpidr = boot_cpu_data.midr.bits;
-    d->arch.vmpidr = boot_cpu_data.mpidr.bits;
+    /*
+     * Expose an SMP systems and remove the AFF0. It will be replace by
+     * the VPCU ID

I wonder if that instead of basing this on the underlying processor we should fabricate an entirely virtual one?

Quoted 6 lines
Quoted 2 lines

Hum .. right, AFF1 could be different to 0.
Is it okay if xen exposes all the vcpus in the same cluster?

When Xen becomes multicluster aware then we will have to rethink but I think all vcpus in the same cluster is the correct thing to do for the time being.

I will rewrite the patch with a virtual MPIDR.

Signature · 1 line
Julien
#5 lore raw
In reply to Julien Grall
Quoted 2 lines · Julien Grall

Use different affinity for each VCPU and always expose an SMP systems to the guest.

What is the bad effect of not doing this for 4.3? Does it fix an observable bug?

Quoted 53 lines
---
 xen/arch/arm/domain.c           |   11 +++++++++--
 xen/include/asm-arm/processor.h |    6 ++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/domain.c +9 -2
index ff1410d..4654c9b 100644
@@ -150,7 +150,8 @@ static void ctxt_switch_to(struct vcpu *n)
     isb();
 
     WRITE_SYSREG32(n->domain->arch.vpidr, VPIDR_EL2);
-    WRITE_SYSREG(n->domain->arch.vmpidr, VMPIDR_EL2);
+    WRITE_SYSREG(n->domain->arch.vmpidr | (n->vcpu_id << MPIDR_AFF0_SHIFT),
+                 VMPIDR_EL2);
 
     /* VGIC */
     gic_restore_state(n);
@@ -495,7 +496,13 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)
 
     /* Default the virtual ID to match the physical */
     d->arch.vpidr = boot_cpu_data.midr.bits;
-    d->arch.vmpidr = boot_cpu_data.mpidr.bits;
+    /*
+     * Expose an SMP systems and remove the AFF0. It will be replace by
+     * the VPCU ID
+     * TODO: handle multi-threading processor
+     */
+    d->arch.vmpidr = boot_cpu_data.mpidr.bits & MPIDR_AFF0_MASK;
+    d->arch.vmpidr = (d->arch.vmpidr & ~MPIDR_UP) | MPIDR_SMP;
 
     /* TODO: retrieve the evtchn IRQ from the guest DTS */
     if ( d->domain_id )
xen/include/asm-arm/processor.h +6 -0
index 1c9d793..5181e7b 100644
@@ -6,6 +6,12 @@
 /* MIDR Main ID Register */
 #define MIDR_MASK    0xff0ffff0
 
+/* MPIDR Multiprocessor Affinity Register */
+#define MPIDR_UP            (1 << 30)
+#define MPIDR_SMP           (1 << 31)
+#define MPIDR_AFF0_SHIFT    (0)
+#define MPIDR_AFF0_MASK     (0xff << MPIDR_AFF0_SHIFT)
+
 /* TTBCR Translation Table Base Control Register */
 #define TTBCR_EAE    0x80000000
 #define TTBCR_N_MASK 0x07
#6 lore raw
Quoted 6 lines · Ian Campbell
Quoted 2 lines · Julien Grall

Use different affinity for each VCPU and always expose an SMP systems to the guest.

What is the bad effect of not doing this for 4.3? Does it fix an observable bug?

I didn't notice a specific bug, Linux uses the MPDIR mainly for optimizing scheduling. Unlike Xen, Linux doesn't use it to know which CPU is booting so we can defer it.

Signature · 1 line
Julien