ppc/spapr: Add implementation of hcall H_PURR
PATCH 1/2 ppc/spapr: Add implementation of hcall H_PURR
The hcall H_PURR is used by a guest to read the PURR (processor utilisation of resources register). A guest expects that this register will count at a rate of timebase scaled by the number of guest vcpus present in the vcore. That is the per vcpu purr will count at a rate of timebase / # vcpus per vcore.
Implement a handler for the H_PURR hcall and return the purr value divided by smp_threads so that the sum of the purr deltas across the vcpus of a vcore equals the timebase delta
--- hw/ppc/spapr_hcall.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
hw/ppc/spapr_hcall.c +24 -0
@@ -1819,6 +1819,27 @@ static target_ulong h_update_dt(PowerPCCPU *cpu, SpaprMachineState *spapr,return H_SUCCESS ; } +static target_ulong h_purr (PowerPCCPU *cpu,SpaprMachineState *spapr, +target_ulong opcode,target_ulong *args) +{ +CPUPPCState *env = &cpu->env; +target_ulong purr; + +if (kvm_enabled ()) { +cpu_synchronize_state (CPU (cpu)); +/* +* Divide by smp_threads so that the sum of the purr deltas across the +* vcpus of a vcore equal the timebase delta. +*/ + purr = env->spr[SPR_PURR ] / smp_threads; + }else { + purr =cpu_ppc_load_purr (env); + } + args[0 ] = purr; + +return H_SUCCESS ; +} +static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE /4 ) +1 ];static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX -KVMPPC_HCALL_BASE +1 ];
@@ -1915,6 +1936,9 @@ static void hypercall_register_types(void)spapr_register_hypercall (H_LOGICAL_DCBF , h_logical_dcbf);spapr_register_hypercall (KVMPPC_H_LOGICAL_MEMOP , h_logical_memop); +/* hcall-purr */ +spapr_register_hypercall (H_PURR , h_purr); +/* qemu/KVM-PPC specific hcalls */ spapr_register_hypercall (KVMPPC_H_RTAS , h_rtas);
Signature · 1 line
2.13.6
PATCH 2/2 ppc/spapr: Enable H_PURR in-kernel handling
Enable in-kernel handling of the hcall H_PURR. This means that if the kernel implements an hcall handler for H_PURR, it will be used.
--- hw/ppc/spapr.c | 3 +++ target/ppc/kvm.c | 5 +++++ target/ppc/kvm_ppc.h | 5 +++++ 3 files changed, 13 insertions(+)
hw/ppc/spapr.c +3 -0
@@ -2851,6 +2851,9 @@ static void spapr_machine_init(MachineState *machine)/* Enable H_PAGE_INIT */ kvmppc_enable_h_page_init (); + +/* Enable H_PURR */ +kvmppc_enable_h_purr (); }/* allocate RAM */
target/ppc/kvm.c +5 -0
@@ -2075,6 +2075,11 @@ void kvmppc_enable_h_page_init(void)kvmppc_enable_hcall (kvm_state,H_PAGE_INIT ); } +void kvmppc_enable_h_purr (void ) +{ +kvmppc_enable_hcall (kvm_state,H_PURR ); +} +void kvmppc_set_papr (PowerPCCPU *cpu) {CPUState *cs =CPU (cpu);
target/ppc/kvm_ppc.h +5 -0
@@ -24,6 +24,7 @@ void kvmppc_enable_logical_ci_hcalls(void);void kvmppc_enable_set_mode_hcall (void );void kvmppc_enable_clear_ref_mod_hcalls (void );void kvmppc_enable_h_page_init (void ); +void kvmppc_enable_h_purr (void );void kvmppc_set_papr (PowerPCCPU *cpu);int kvmppc_set_compat (PowerPCCPU *cpu,uint32_t compat_pvr);void kvmppc_set_mpic_proxy (PowerPCCPU *cpu,int mpic_proxy);
@@ -145,6 +146,10 @@ static inline void kvmppc_enable_h_page_init(void) { } +static inline void kvmppc_enable_h_purr (void ) +{ +} +static inline void kvmppc_set_papr (PowerPCCPU *cpu) { }
Signature · 1 line
2.13.6
Quoted 11 lines · Suraj Jitindar Singh
The hcall
H_PURRis used by a guest to read the PURR (processor utilisation of resources register). A guest expects that this register will count at a rate of timebase scaled by the number of guest vcpus present in the vcore. That is the per vcpu purr will count at a rate of timebase / # vcpus per vcore.Implement a handler for the
H_PURRhcall and return the purr value divided bysmp_threadsso that the sum of the purr deltas across the vcpus of a vcore equals the timebase deltaSigned-off-by Suraj Jitindar Singh <[email protected]>
Does this need something new advertised in the hypertas DT entry?
Quoted 46 lines
--- hw/ppc/spapr_hcall.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)hw/ppc/spapr_hcall.c +24
-0@@ -1819,6 +1819,27 @@ static target_ulong h_update_dt(PowerPCCPU *cpu, SpaprMachineState *spapr,return H_SUCCESS ; } +static target_ulong h_purr (PowerPCCPU *cpu,SpaprMachineState *spapr, +target_ulong opcode,target_ulong *args) +{ +CPUPPCState *env = &cpu->env; +target_ulong purr; + +if (kvm_enabled ()) { +cpu_synchronize_state (CPU (cpu)); +/* +* Divide by smp_threads so that the sum of the purr deltas across the +* vcpus of a vcore equal the timebase delta. +*/ + purr = env->spr[SPR_PURR ] / smp_threads; + }else { + purr =cpu_ppc_load_purr (env); + } + args[0 ] = purr; + +return H_SUCCESS ; +} +static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE /4 ) +1 ];static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX -KVMPPC_HCALL_BASE +1 ];@@ -1915,6 +1936,9 @@ static void hypercall_register_types(void)spapr_register_hypercall (H_LOGICAL_DCBF , h_logical_dcbf);spapr_register_hypercall (KVMPPC_H_LOGICAL_MEMOP , h_logical_memop); +/* hcall-purr */ +spapr_register_hypercall (H_PURR , h_purr); +/* qemu/KVM-PPC specific hcalls */ spapr_register_hypercall (KVMPPC_H_RTAS , h_rtas);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 10 lines · David Gibson
Quoted 9 lines · Suraj Jitindar Singh
The hcall
H_PURRis used by a guest to read the PURR (processor utilisation of resources register). A guest expects that this register
will count at a rate of timebase scaled by the number of guest vcpus
present in the vcore. That is the per vcpu purr will count at a rate of
timebase / # vcpus per vcore.
Quoted 8 lines
Quoted 6 lines
Implement a handler for the
H_PURRhcall and return the purr value divided bysmp_threadsso that the sum of the purr deltas across the
vcpus of a vcore equals the timebase deltaSigned-off-by Suraj Jitindar Singh <[email protected]>Does this need something new advertised in the hypertas DT entry?
Hi David,
There doesn't seem to be a concensus on what the return value from the H_PURR hcall should be, whether it just returns the hardware value or does some adjusting of the value based on guest smt mode as I've implemented in the patch below.
As such please drop this patch series.
The guest can just read the purr register directly anyway and then interpret the values as it pleases.
Kind Regards,
Suraj
Quoted 56 lines
Quoted 54 lines
--- hw/ppc/spapr_hcall.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)hw/ppc/spapr_hcall.c +10
-0@@ -1819,6 +1819,27 @@ static target_ulong h_update_dt(PowerPCCPU *cpu, SpaprMachineState *spapr, return H_SUCCESS; } +static target_ulong h_purr (PowerPCCPU *cpu,SpaprMachineState *spapr, +target_ulong opcode,target_ulong *args) +{ +CPUPPCState *env = &cpu->env; +target_ulong purr; + +if (kvm_enabled ()) { +cpu_synchronize_state (CPU (cpu)); +/* +* Divide by smp_threads so that the sum of the purr deltas across the
hw/ppc/spapr_hcall.c +12
-0+* vcpus of a vcore equal the timebase delta. +*/ + purr = env->spr[SPR_PURR ] / smp_threads; + }else { + purr =cpu_ppc_load_purr (env); + } + args[0 ] = purr; + +return H_SUCCESS ; +} +static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE /4 ) + 1]; static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX -
KVMPPC_HCALL_BASE+ 1];hw/ppc/spapr_hcall.c +3
-0@@ -1915,6 +1936,9 @@ static void hypercall_register_types(void)spapr_register_hypercall (H_LOGICAL_DCBF , h_logical_dcbf);spapr_register_hypercall (KVMPPC_H_LOGICAL_MEMOP , h_logical_memop); +/* hcall-purr */ +spapr_register_hypercall (H_PURR , h_purr); +/* qemu/KVM-PPC specific hcalls */ spapr_register_hypercall (KVMPPC_H_RTAS , h_rtas);
Quoted 18 lines · Suraj Jitindar Singh
Quoted 17 lines · David Gibson
Quoted 15 lines · Suraj Jitindar Singh
The hcall
H_PURRis used by a guest to read the PURR (processor utilisation of resources register). A guest expects that this register
will count at a rate of timebase scaled by the number of guest vcpus
present in the vcore. That is the per vcpu purr will count at a rate of
timebase / # vcpus per vcore.Implement a handler for the
H_PURRhcall and return the purr value divided bysmp_threadsso that the sum of the purr deltas across the
vcpus of a vcore equals the timebase deltaSigned-off-by Suraj Jitindar Singh <[email protected]>
Quoted 8 lines
Quoted 1 line
Does this need something new advertised in the hypertas DT entry?
Hi David,
There doesn't seem to be a concensus on what the return value from the
H_PURRhcall should be, whether it just returns the hardware value or does some adjusting of the value based on guest smt mode as I've implemented in the patch below.
*eyeroll*. Lack of forethought in PAPR strikes again.
Quoted 1 line
As such please drop this patch series.
Ok, will do.
Quoted 64 lines
The guest can just read the purr register directly anyway and then interpret the values as it pleases.
Kind Regards,
SurajQuoted 56 lines
Quoted 54 lines
--- hw/ppc/spapr_hcall.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)hw/ppc/spapr_hcall.c +10
-0@@ -1819,6 +1819,27 @@ static target_ulong h_update_dt(PowerPCCPU *cpu, SpaprMachineState *spapr, return H_SUCCESS; } +static target_ulong h_purr (PowerPCCPU *cpu,SpaprMachineState *spapr, +target_ulong opcode,target_ulong *args) +{ +CPUPPCState *env = &cpu->env; +target_ulong purr; + +if (kvm_enabled ()) { +cpu_synchronize_state (CPU (cpu)); +/* +* Divide by smp_threads so that the sum of the purr deltas across the
hw/ppc/spapr_hcall.c +12
-0+* vcpus of a vcore equal the timebase delta. +*/ + purr = env->spr[SPR_PURR ] / smp_threads; + }else { + purr =cpu_ppc_load_purr (env); + } + args[0 ] = purr; + +return H_SUCCESS ; +} +static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE /4 ) + 1]; static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX -
KVMPPC_HCALL_BASE+ 1];hw/ppc/spapr_hcall.c +3
-0@@ -1915,6 +1936,9 @@ static void hypercall_register_types(void)spapr_register_hypercall (H_LOGICAL_DCBF , h_logical_dcbf);spapr_register_hypercall (KVMPPC_H_LOGICAL_MEMOP , h_logical_memop); +/* hcall-purr */ +spapr_register_hypercall (H_PURR , h_purr); +/* qemu/KVM-PPC specific hcalls */ spapr_register_hypercall (KVMPPC_H_RTAS , h_rtas);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson