Use Aff1 with mpidr
PATCH v4 1/1 Use Aff1 with mpidr
In order to support up to 128 cores with GIC-500 (GICv3 implementation) affinity1 must be used. GIC-500 support up to 32 clusters with up to 8 cores in a cluster. So for example, if one wishes to have 16 cores, the options are: 2 clusters of 8 cores each, 4 clusters with 4 cores each. It is possible to specify the desired layout by setting arm_cpus_per_cluster variable.
Unfortunately KVM currently has its own idea about CPU affinity assignment scheme. Therefore, if we use KVM we override CPU IDs with those provided by the KVM.
---
Changes since v3:
1. Fixed and/or updated comments and descriptions
2. CPUS_PER_CLUSTER replaced by a variable which can be changed by machine initialization code
3. PSCI looks up processor directly by ID, no more ID->index conversion
4. Added ID fixup for 32-bit KVM
5. Debugging macros removed
6. mpidr field name changed to mp_affinity
--- hw/arm/virt.c | 2 +- target-arm/cpu-qom.h | 3 +++ target-arm/cpu.c | 12 ++++++++++++ target-arm/helper.c | 9 +++------ target-arm/kvm32.c | 15 +++++++++++++++ target-arm/kvm64.c | 15 +++++++++++++++ target-arm/psci.c | 19 +++++++++++++++++-- 7 files changed, 66 insertions(+), 9 deletions(-)
hw/arm/virt.c +1 -1
@@ -306,7 +306,7 @@ static void fdt_add_cpu_nodes(const VirtBoardInfo *vbi) "enable-method", "psci"); } -qemu_fdt_setprop_cell (vbi->fdt, nodename,"reg" , cpu); +qemu_fdt_setprop_cell (vbi->fdt, nodename,"reg" , armcpu->mp_affinity);g_free (nodename); } }
target-arm/cpu-qom.h +3 -0
@@ -159,6 +159,7 @@ typedef struct ARMCPU {uint64_t id_aa64mmfr1;uint32_t dbgdidr;uint32_t clidr; +uint64_t mp_affinity;/* MP ID without feature bits */ /* The elements of this array are the CCSIDR values for each cache, * in the order L1DCache, L1ICache, L2DCache, L2ICache, etc. */
@@ -171,6 +172,8 @@ typedef struct ARMCPU {uint64_t rvbar; }ARMCPU ; +extern int arm_cpus_per_cluster; +#define TYPE_AARCH64_CPU "aarch64-cpu"#define AARCH64_CPU_CLASS (klass) \ OBJECT_CLASS_CHECK(AArch64CPUClass, (klass), TYPE_AARCH64_CPU)
target-arm/cpu.c +12 -0
@@ -383,17 +383,29 @@ static inline void unset_feature(CPUARMState *env, int feature) env->features &= ~(1ULL << feature); } +int arm_cpus_per_cluster =8 ; +static void arm_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);ARMCPU *cpu =ARM_CPU (obj);static bool inited; +uint32_t Aff1, Aff0; cs->env_ptr = &cpu->env;cpu_exec_init (&cpu->env); cpu->cp_regs =g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_free); +/* +* We don't support setting cluster ID ([16..23]) (known as Aff2 +* in later ARM ARM versions), or any of the higher affinity level fields, +* so these bits always RAZ. +*/ + Aff1 = cs->cpu_index / arm_cpus_per_cluster; + Aff0 = cs->cpu_index % arm_cpus_per_cluster; + cpu->mp_affinity = (Aff1 <<8 ) | Aff0; +#ifndef CONFIG_USER_ONLY /* Our inbound IRQ and FIQ lines */ if (kvm_enabled ()) {
target-arm/helper.c +3 -6
@@ -2063,12 +2063,9 @@ static const ARMCPRegInfo strongarm_cp_reginfo[] = {static uint64_t mpidr_read (CPUARMState *env,const ARMCPRegInfo *ri) { -CPUState *cs =CPU (arm_env_get_cpu (env)); -uint32_t mpidr = cs->cpu_index; -/* We don't support setting cluster ID ([8..11]) (known as Aff1 -* in later ARM ARM versions), or any of the higher affinity level fields, -* so these bits always RAZ. -*/ +ARMCPU *cpu =ARM_CPU (arm_env_get_cpu (env)); +uint64_t mpidr = cpu->mp_affinity; +if (arm_feature (env,ARM_FEATURE_V7MP )) { mpidr |= (1U <<31 );/* Cores which are uniprocessor (non-coherent)
target-arm/kvm32.c +15 -0
@@ -153,10 +153,14 @@ bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx) } } +#define ARM_MPIDR_HWID_BITMASK 0xFFFFFF +#define ARM_CPU_ID_MPIDR 0, 0, 0, 5 +int kvm_arch_init_vcpu (CPUState *cs) {int ret;uint64_t v; +uint32_t mpidr;struct kvm_one_reg r;ARMCPU *cpu =ARM_CPU (cs);
@@ -193,6 +197,17 @@ int kvm_arch_init_vcpu(CPUState *cs)return -EINVAL ; } +/* +* When KVM is in use, PSCI is emulated in-kernel and not by qemu. +* Currently KVM has its own idea about MPIDR assignment, so we +* override our defaults with what we get from KVM. +*/ + ret =kvm_get_one_reg (cs,ARM_CP15_REG32 (ARM_CPU_ID_MPIDR ), &mpidr); +if (ret) { +return ret; + } + cpu->mp_affinity = mpidr &ARM_MPIDR_HWID_BITMASK ; +return kvm_arm_init_cpreg_list (cpu); }
target-arm/kvm64.c +15 -0
@@ -77,9 +77,13 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUClass *ahcc)return true; } +#define ARM_MPIDR_HWID_BITMASK 0xFF00FFFFFFULL +#define ARM_CPU_ID_MPIDR 3, 0, 0, 0, 5 +int kvm_arch_init_vcpu (CPUState *cs) {int ret; +uint64_t mpidr;ARMCPU *cpu =ARM_CPU (cs); if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE ||
@@ -107,6 +111,17 @@ int kvm_arch_init_vcpu(CPUState *cs)return ret; } +/* +* When KVM is in use, PSCI is emulated in-kernel and not by qemu. +* Currently KVM has its own idea about MPIDR assignment, so we +* override our defaults with what we get from KVM. +*/ + ret =kvm_get_one_reg (cs,ARM64_SYS_REG (ARM_CPU_ID_MPIDR ), &mpidr); +if (ret) { +return ret; + } + cpu->mp_affinity = mpidr &ARM_MPIDR_HWID_BITMASK ; +return kvm_arm_init_cpreg_list (cpu); }
target-arm/psci.c +17 -2
@@ -72,6 +72,21 @@ bool arm_is_psci_call(ARMCPU *cpu, int excp_type) } } +static CPUState *get_cpu_by_id (uint64_t id) +{ +CPUState *cpu; + +CPU_FOREACH (cpu) { +ARMCPU *armcpu =ARM_CPU (cpu); + +if (armcpu->mp_affinity == id) { +return cpu; + } + } + +return NULL ; +} +void arm_handle_psci_call (ARMCPU *cpu) {/*
@@ -121,7 +136,7 @@ void arm_handle_psci_call(ARMCPU *cpu)switch (param[2 ]) {case 0 : - target_cpu_state =qemu_get_cpu (mpidr &0xff ); + target_cpu_state =get_cpu_by_id (mpidr);if (!target_cpu_state) { ret =QEMU_PSCI_RET_INVALID_PARAMS ;break ;
@@ -153,7 +168,7 @@ void arm_handle_psci_call(ARMCPU *cpu) context_id = param[3 ];/* change to the cpu we are powering up */ - target_cpu_state =qemu_get_cpu (mpidr &0xff ); + target_cpu_state =get_cpu_by_id (mpidr);if (!target_cpu_state) { ret =QEMU_PSCI_RET_INVALID_PARAMS ;break ;
Signature · 1 line
1.9.5.msysgit.0
Quoted 10 lines · Pavel Fedin
target-arm/cpu-qom.h +2
-0+extern int arm_cpus_per_cluster; +#define TYPE_AARCH64_CPU "aarch64-cpu"#define AARCH64_CPU_CLASS (klass) \ OBJECT_CLASS_CHECK(AArch64CPUClass, (klass), TYPE_AARCH64_CPU)target-arm/cpu.c +0
-0
target-arm/cpu.c static inline void unset_feature(CPUARMState *env, int feature) · line 386
Quoted 4 lines
target-arm/cpu.c +1
-0@@ -383,17 +383,29 @@ static inline void unset_feature(CPUARMState *env, int feature) env->features &= ~(1ULL << feature); } +int arm_cpus_per_cluster =8 ;
This doesn't need to be global, it doesn't need to be exposed in a header file, and it definitely doesn't need to be non-constant. I suggest
#define ARM_CPUS_PER_CLUSTER 8
Quoted 11 lines
target-arm/cpu.c +2
-0+static void arm_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);ARMCPU *cpu =ARM_CPU (obj);static bool inited; +uint32_t Aff1, Aff0; cs->env_ptr = &cpu->env;cpu_exec_init (&cpu->env); cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal,
target-arm/cpu.c static inline void unset_feature(CPUARMState *env, int feature) · line 407
Quoted 10 lines
target-arm/cpu.c +8
-0g_free, g_free); +/* +* We don't support setting cluster ID ([16..23]) (known as Aff2 +* in later ARM ARM versions), or any of the higher affinity level fields, +* so these bits always RAZ. +*/ + Aff1 = cs->cpu_index / arm_cpus_per_cluster; + Aff0 = cs->cpu_index % arm_cpus_per_cluster; + cpu->mp_affinity = (Aff1 <<8 ) | Aff0;
Worth also mentioning in the comment that KVM will override this.
These are minor nits so I plan to just fix them as I apply this to target-arm.next, unless you object.
thanks
-- PMM
Hello!
Quoted 6 lines
Quoted 1 line
+int
arm_cpus_per_cluster= 8;This doesn't need to be global, it doesn't need to be exposed in a header file, and it definitely doesn't need to be non-constant. I suggest
#defineARM_CPUS_PER_CLUSTER8
It was a #define in v3, but i decided to change this in order to allow machine models to request different topology as Igor suggested. Of course you can revert to #define if you strictly want to.
Quoted 2 lines
These are minor nits so I plan to just fix them as I apply this to target-arm.next, unless you object.
No, i don't object and of course i'm waiting for the PULL.
Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia
Quoted 11 lines · Pavel Fedin
Hello!
Quoted 6 lines
Quoted 1 line
+int
arm_cpus_per_cluster= 8;This doesn't need to be global, it doesn't need to be exposed in a header file, and it definitely doesn't need to be non-constant. I suggest
#defineARM_CPUS_PER_CLUSTER8It was a #define in v3, but i decided to change this in order to
allow machine models to request different topology as Igor suggested.
For machine models to specify topology we would need a property or properties on the QOM object for the machine model to set, not a global. (And we'd need to have the code to see if KVM supported setting arbitrary MPIDR values, and fail if not.)
thanks
-- PMM
Hello!
Quoted 2 lines
For machine models to specify topology we would need a property or properties on the QOM object for the machine model to set,
On which object? There's no single object inside a machine model. Of course you can expose MP IDs of CPU objects as properties and set them, but isn't it more difficult than just changing one global before setting things up? But, OK, this is just a MHO, and generally i don't object. If you think that your suggestion is architecturally better, do it. I'm out of arguments. :)
Quoted 2 lines
(And we'd need to have the code to see if KVM supported setting arbitrary MPIDR values, and fail if not.)
I believe this is a different story.
Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia
Quoted 6 lines · On Mon, 15 Jun 2015 11:13:52 +0300 Pavel Fedin <[email protected]> wrote:
Hello!
Quoted 2 lines
For machine models to specify topology we would need a property or properties on the QOM object for the machine model to set,
On which object? There's no single object inside a machine model. Of course you can expose MP IDs of CPU objects as properties and set them, but isn't it more difficult than just changing one global before setting things up?
that's how we model it for x86 target, i.e. board sets apic-id property
of CPU's it creates, and that's what I've suggested before (i.e. not a global for sure).
Quoted 14 lines
But, OK, this is just a MHO, and generally i don't object. If you think that your suggestion is architecturally better, do it. I'm out of arguments. :)
Quoted 2 lines
(And we'd need to have the code to see if KVM supported setting arbitrary MPIDR values, and fail if not.)
I believe this is a different story.
Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia