target-ppc: Define kvmppc_read_int_dt()
PATCH v3 1/2 target-ppc: Define kvmppc_read_int_dt()
Extract code from the function kvmppc_read_int_cpu_dt() that actually reads the file into a separate function, so it can be called from other places.
--- target-ppc/kvm.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)
target-ppc/kvm.c +22 -14
@@ -1838,13 +1838,8 @@ static int kvmppc_find_cpu_dt(char *buf, int buf_len)return 0 ; } -/* Read a CPU node property from the host device tree that's a single -* integer (32-bit or 64-bit). Returns 0 if anything goes wrong -* (can't find or open the property, or doesn't understand the -* format) */ -static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +static uint64_t kvmppc_read_int_dt (const char *filename) { -char buf[PATH_MAX ], *tmp;union {uint32_t v32;uint64_t v64;
@@ -1852,14 +1847,7 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname)FILE *f;int len; -if (kvmppc_find_cpu_dt (buf,sizeof (buf))) { -return -1 ; - } - - tmp =g_strdup_printf ("%s/%s" , buf, propname); - - f =fopen (tmp,"rb" ); -g_free (tmp); + f =fopen (filename,"rb" );if (!f) {return -1 ; }
@@ -1877,6 +1865,26 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname)return 0 ; } +/* Read a CPU node property from the host device tree that's a single +* integer (32-bit or 64-bit). Returns 0 if anything goes wrong +* (can't find or open the property, or doesn't understand the +* format) */ +static uint64_t kvmppc_read_int_cpu_dt (const char *propname) +{ +char buf[PATH_MAX ], *tmp; +uint64_t val; + +if (kvmppc_find_cpu_dt (buf,sizeof (buf))) { +return -1 ; + } + + tmp =g_strdup_printf ("%s/%s" , buf, propname); + val =kvmppc_read_int_dt (tmp); +g_free (tmp); + +return val; +} +uint64_t kvmppc_get_clockfreq (void ) {return kvmppc_read_int_cpu_dt ("clock-frequency" );
Signature · 1 line
2.1.0
PATCH v3 2/2 target-ppc: Implement rtas_get_sysparm(PROCESSOR_MODULE_INFO)
Implement RTAS_SYSPARM_PROCESSOR_MODULE_INFO parameter to rtas_get_sysparm() call in qemu. This call returns the processor module (socket), chip and core information as specified in section 7.3.16.17 of LoPAPR v2.7.
We walk the /proc/device-tree to determine the number of modules(aka sockets), chips and cores in the _host_ system and return this info to the guest application that makes the rtas_get_sysparm() call.
We currently hard code the number of module_types to 1 (we currently don't have systems with more than one module type) but we should determine that dynamically somehow later.
Thanks to input from Nishanth Aravamudan, Alexey Kardashevskiy, David Gibson, Thomas Huth.
---
Changelog[v3]:
[David Gibson] Use glob() to simplify pattern matching path names.
Move new code into target-ppc/{kvm.c,kvm_ppc.h} to not impact other targets and avoid creating new files.
[Alexey Kardashevskiy] Fix indentation, error messages; fold new
code into existing files and avoid creating new files for this parameter; since the keys are integer, use g_direct_hash() and GINT_TO_POINTER() and avoid allocating/freeing memory.
Changelog[v2]:
[Alexey Kardashevskiy] Use existing interfaces like ldl_be_p(),
stw_be_phys(), g_hash_table_new_full(), error_report() rather than re-inventing; fix indentation, function prottypes etc; Drop the fts() interface (which doesn't seem to be available on mingw32/mingw64) and use opendir() to walk specific directories in the directory tree.
--- hw/ppc/spapr_rtas.c | 31 +++++++++++ include/hw/ppc/spapr.h | 13 +++++ target-ppc/kvm.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++ target-ppc/kvm_ppc.h | 8 +++ 4 files changed, 193 insertions(+)
hw/ppc/spapr_rtas.c +31 -0
@@ -38,6 +38,7 @@#include <libfdt.h> #include "hw/ppc/spapr_drc.h" +#include "kvm_ppc.h" /* #define DEBUG_SPAPR */
@@ -240,6 +241,36 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,target_ulong ret =RTAS_OUT_SUCCESS ;switch (parameter) { +case RTAS_SYSPARM_PROCESSOR_MODULE_INFO : { +struct sPAPRRTASModuleInfo modinfo; +int i, size =sizeof (modinfo), offset =0 ; + +memset (&modinfo,0 , size); +if (kvmppc_rtas_get_module_info (&modinfo)) { + ret =RTAS_OUT_HW_ERROR ; +break ; + } + +stw_be_phys (&address_space_memory, buffer+offset, size); + offset +=2 ; + +stw_be_phys (&address_space_memory, buffer+offset, modinfo.module_types); + offset +=2 ; + +for (i =0 ; i < modinfo.module_types; i++) { +stw_be_phys (&address_space_memory, buffer+offset, + modinfo.si[i].sockets); + offset +=2 ; +stw_be_phys (&address_space_memory, buffer+offset, + modinfo.si[i].chips); + offset +=2 ; +stw_be_phys (&address_space_memory, buffer+offset, + modinfo.si[i].cores_per_chip); + offset +=2 ; + } +break ; + } +case RTAS_SYSPARM_SPLPAR_CHARACTERISTICS : {char *param_val =g_strdup_printf ("MaxEntCap=%d," "DesMem=%llu,"
include/hw/ppc/spapr.h +13 -0
@@ -463,6 +463,7 @@ int spapr_allocate_irq_block(int num, bool lsi, bool msi);/* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20#define RTAS_SYSPARM_DIAGNOSTICS_RUN_MODE 42 +#define RTAS_SYSPARM_PROCESSOR_MODULE_INFO 43#define RTAS_SYSPARM_UUID 48/* RTAS indicator/sensor types
@@ -646,4 +647,16 @@ int spapr_rng_populate_dt(void *fdt);*/ #define SPAPR_LMB_FLAGS_ASSIGNED 0x00000008 +#define SPAPR_MAX_MODULE_TYPES 1 + +struct sPAPRRTASSocketInfo { +unsigned short sockets; +unsigned short chips; +unsigned short cores_per_chip; +}; +struct sPAPRRTASModuleInfo { +unsigned short module_types; +struct sPAPRRTASSocketInfo si[SPAPR_MAX_MODULE_TYPES ]; +}; +#endif /* !defined (__HW_SPAPR_H__) */
target-ppc/kvm.c +141 -0
150 lines not on this page · raw message
target-ppc/kvm_ppc.h +8 -0
@@ -10,6 +10,7 @@#define __KVM_PPC_H__#define TYPE_HOST_POWERPC_CPU "host-" TYPE_POWERPC_CPU +#include "hw/ppc/spapr.h" #ifdef CONFIG_KVM
@@ -55,6 +56,7 @@ void kvmppc_hash64_write_pte(CPUPPCState *env, target_ulong pte_index, target_ulong pte0, target_ulong pte1);bool kvmppc_has_cap_fixup_hcalls (void );int kvmppc_enable_hwrng (void ); +int kvmppc_rtas_get_module_info (struct sPAPRRTASModuleInfo *modinfo);#else
@@ -256,6 +258,12 @@ static inline int kvmppc_enable_hwrng(void) {return -1 ; } + +static inline int kvmppc_rtas_get_module_info (struct sPAPRRTASModuleInfo *mi) +{ +return -1 ; +} +#endif #ifndef CONFIG_KVM
Signature · 1 line
2.1.0
Quoted 5 lines · Sukadev Bhattiprolu
Extract code from the function
kvmppc_read_int_cpu_dt()that actually reads the file into a separate function, so it can be called from other places.Signed-off-by Sukadev Bhattiprolu <[email protected]>
Looks like a nice generalization, I've applied this to my ppc-for-2.6 branch.
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v3 2/2] target-ppc: Implement rtas_get_sysparm(PROCESSOR_MODULE_INFO)
In reply to Sukadev BhattiproluDavid, Alexey,
Any comments on this patch?
Suka
Sukadev Bhattiprolu [[email protected]] wrote:
| Implement RTAS_SYSPARM_PROCESSOR_MODULE_INFO parameter to rtas_get_sysparm() | call in qemu. This call returns the processor module (socket), chip and core | information as specified in section 7.3.16.17 of LoPAPR v2.7. | | We walk the /proc/device-tree to determine the number of modules(aka sockets), | chips and cores in the _host_ system and return this info to the guest | application that makes the rtas_get_sysparm() call. | | We currently hard code the number of module_types to 1 (we currently don't | have systems with more than one module type) but we should determine that | dynamically somehow later. | | Thanks to input from Nishanth Aravamudan, Alexey Kardashevskiy, David Gibson, | Thomas Huth. | | Signed-off-by: Sukadev Bhattiprolu <[email protected]> | --- | Changelog[v3]: | [David Gibson] Use glob() to simplify pattern matching path names. | Move new code into target-ppc/{kvm.c,kvm_ppc.h} to not impact | other targets and avoid creating new files. | [Alexey Kardashevskiy] Fix indentation, error messages; fold new | code into existing files and avoid creating new files for this | parameter; since the keys are integer, use g_direct_hash() and | GINT_TO_POINTER() and avoid allocating/freeing memory. | | Changelog[v2]: | [Alexey Kardashevskiy] Use existing interfaces like ldl_be_p(), | stw_be_phys(), g_hash_table_new_full(), error_report() rather | than re-inventing; fix indentation, function prottypes etc; | Drop the fts() interface (which doesn't seem to be available | on mingw32/mingw64) and use opendir() to walk specific | directories in the directory tree. | --- | hw/ppc/spapr_rtas.c | 31 +++++++++++ | include/hw/ppc/spapr.h | 13 +++++ | target-ppc/kvm.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++ | target-ppc/kvm_ppc.h | 8 +++ | 4 files changed, 193 insertions(+) | | diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c | index 34b12a3..44b2537 100644 | --- a/hw/ppc/spapr_rtas.c | +++ b/hw/ppc/spapr_rtas.c | @@ -38,6 +38,7 @@ | | #include <libfdt.h> | #include "hw/ppc/spapr_drc.h" | +#include "kvm_ppc.h" | | /* #define DEBUG_SPAPR */ | | @@ -240,6 +241,36 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, | target_ulong ret = RTAS_OUT_SUCCESS; | | switch (parameter) { | + case RTAS_SYSPARM_PROCESSOR_MODULE_INFO: { | + struct sPAPRRTASModuleInfo modinfo; | + int i, size = sizeof(modinfo), offset = 0; | + | + memset(&modinfo, 0, size); | + if (kvmppc_rtas_get_module_info(&modinfo)) { | + ret = RTAS_OUT_HW_ERROR; | + break; | + } | + | + stw_be_phys(&address_space_memory, buffer+offset, size); | + offset += 2; | + | + stw_be_phys(&address_space_memory, buffer+offset, modinfo.module_types); | + offset += 2; | + | + for (i = 0; i < modinfo.module_types; i++) { | + stw_be_phys(&address_space_memory, buffer+offset, | + modinfo.si[i].sockets); | + offset += 2; | + stw_be_phys(&address_space_memory, buffer+offset, | + modinfo.si[i].chips); | + offset += 2; | + stw_be_phys(&address_space_memory, buffer+offset, | + modinfo.si[i].cores_per_chip); | + offset += 2; | + } | + break; | + } | + | case RTAS_SYSPARM_SPLPAR_CHARACTERISTICS: { | char *param_val = g_strdup_printf("MaxEntCap=%d," | "DesMem=%llu," | diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h | index 5baa906..f793465 100644 | --- a/include/hw/ppc/spapr.h | +++ b/include/hw/ppc/spapr.h | @@ -463,6 +463,7 @@ int spapr_allocate_irq_block(int num, bool lsi, bool msi); | /* RTAS ibm,get-system-parameter token values */ | #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20 | #define RTAS_SYSPARM_DIAGNOSTICS_RUN_MODE 42 | +#define RTAS_SYSPARM_PROCESSOR_MODULE_INFO 43 | #define RTAS_SYSPARM_UUID 48 | | /* RTAS indicator/sensor types | @@ -646,4 +647,16 @@ int spapr_rng_populate_dt(void *fdt); | */ | #define SPAPR_LMB_FLAGS_ASSIGNED 0x00000008 | | +#define SPAPR_MAX_MODULE_TYPES 1 | + | +struct sPAPRRTASSocketInfo { | + unsigned short sockets; | + unsigned short chips; | + unsigned short cores_per_chip; | +}; | +struct sPAPRRTASModuleInfo { | + unsigned short module_types; | + struct sPAPRRTASSocketInfo si[SPAPR_MAX_MODULE_TYPES]; | +}; | + | #endif /* !defined (__HW_SPAPR_H__) */ | diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c | index 9940a90..bbef78c 100644 | --- a/target-ppc/kvm.c | +++ b/target-ppc/kvm.c | @@ -15,6 +15,7 @@ | */ | | #include <dirent.h> | +#include <glob.h> | #include <sys/types.h> | #include <sys/ioctl.h> | #include <sys/mman.h> | @@ -2518,3 +2519,143 @@ int kvmppc_enable_hwrng(void) | | return kvmppc_enable_hcall(kvm_state, H_RANDOM); | } | + | +/* Read an identifier from the file @path and add the identifier | + * to the hash table @gt unless its already in the table. | + */ | +static int kvmppc_hash_file_contents(GHashTable *gt, char *path) | +{ | + uint32_t idx; | + | + idx = kvmppc_read_int_dt(path); | + if (idx == -1) { | + return -1; | + } | + | + if (g_hash_table_contains(gt, GINT_TO_POINTER(idx))) { | + return 0; | + } | + | + if (!g_hash_table_insert(gt, GINT_TO_POINTER(idx), NULL)) { | + fprintf(stderr, "%s() Unable to add key %d\n", __func__, idx); | + return -1; | + } | + | + return 0; | +} | + | +static int kvmppc_glob_count_ids_dt(const char *pattern, int *count) | +{ | + int i, rc; | + glob_t dtglob; | + GHashTable *htbl; | + | + rc = glob(pattern, GLOB_NOSORT, NULL, &dtglob); | + if (rc) { | + fprintf(stderr, "%s() glob(%s) returns %d, errno %d\n", __func__, | + pattern, rc, errno); | + return -1; | + } | + | + rc = -1; | + htbl = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); | + | + for (i = 0; i < dtglob.gl_pathc; i++) { | + if (kvmppc_hash_file_contents(htbl, dtglob.gl_pathv[i])) { | + goto cleanup; | + } | + } | + | + *count = g_hash_table_size(htbl); | + rc = 0; | + | +cleanup: | + globfree(&dtglob); | + g_hash_table_remove_all(htbl); | + g_hash_table_destroy(htbl); | + | + return rc; | +} | + | +/* Each socket's (aka module's) id is contained in the 'ibm,hw-module-id' | + * file in an "xscom" directory (/proc/device-tree/xscom*). Similarly each | + * chip's id is contained in the 'ibm,chip-id' file in an xscom directory. | + * | + * Since a module can have more than one chip and a chip can have more than | + * one core, there are likely to be duplicates in the module and chip ids | + * i.e more than one xscom directory can contain the same module/chip id. | + * | + * Search the xscom directories and count the number of _UNIQUE_ modules | + * and chips in the system. | + * | + * Return 0 if one or more modules and chips each are found. Return -1 | + * otherwise. | + */ | +static int kvmppc_count_sockets_chips_dt(int *num_sockets, int *num_chips) | +{ | + const char *chip_pattern = "/proc/device-tree/xscom@*/ibm,chip-id"; | + const char *module_pattern = "/proc/device-tree/xscom@*/ibm,hw-module-id"; | + | + if (kvmppc_glob_count_ids_dt(module_pattern, num_sockets) | + || kvmppc_glob_count_ids_dt(chip_pattern, num_chips)) { | + return -1; | + } | + | + if (*num_sockets == 0 || *num_chips == 0) { | + return -1; | + } | + | + return 0; | +} | + | +/* Each core in the system is represented by a directory with the prefix | + * 'PowerPC,POWER' in directory /proc/device-tree/cpus/. Process that | + * directory and count the number of cores in the system. | + * | + * Return 0 if one or more cores are found. Return -1 otherwise. | + */ | +static int kvmppc_count_cores_dt(int *num_cores) | +{ | + int rc; | + glob_t dtglob; | + const char *cpus_pattern = "/proc/device-tree/cpus/PowerPC,POWER*"; | + | + rc = glob(cpus_pattern, GLOB_NOSORT, NULL, &dtglob); | + if (rc) { | + fprintf(stderr, "%s() glob(%s) returns %d, errno %d\n", __func__, | + cpus_pattern, rc, errno); | + return -1; | + } | + | + *num_cores = dtglob.gl_pathc; | + globfree(&dtglob); | + | + if (*num_cores == 0) { | + return -1; | + } | + | + return 0; | +} | + | +int kvmppc_rtas_get_module_info(struct sPAPRRTASModuleInfo *modinfo) | +{ | + int cores, chips, sockets; | + | + if (kvmppc_count_sockets_chips_dt(&sockets, &chips) | + || kvmppc_count_cores_dt(&cores)) { | + return -1; | + } | + | + /* TODO: Although the interface allows multiple module types, Power | + * systems currently support only one module type per system - | + * either Single Chip Module(SCM) or Dual Chip Module(DCM), | + * but not both types in the same system. Hard code module_types | + * for now till we can determine it dynamically. | + */ | + modinfo->module_types = 1; | + modinfo->si[0].sockets = sockets; | + modinfo->si[0].chips = chips; | + modinfo->si[0].cores_per_chip = cores / chips; | + | + return 0; | +} | diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h | index 309cbe0..46a2768 100644 | --- a/target-ppc/kvm_ppc.h | +++ b/target-ppc/kvm_ppc.h | @@ -10,6 +10,7 @@ | #define __KVM_PPC_H__ | | #define TYPE_HOST_POWERPC_CPU "host-" TYPE_POWERPC_CPU | +#include "hw/ppc/spapr.h" | | #ifdef CONFIG_KVM | | @@ -55,6 +56,7 @@ void kvmppc_hash64_write_pte(CPUPPCState *env, target_ulong pte_index, | target_ulong pte0, target_ulong pte1); | bool kvmppc_has_cap_fixup_hcalls(void); | int kvmppc_enable_hwrng(void); | +int kvmppc_rtas_get_module_info(struct sPAPRRTASModuleInfo *modinfo); | | #else | | @@ -256,6 +258,12 @@ static inline int kvmppc_enable_hwrng(void) | { | return -1; | } | + | +static inline int kvmppc_rtas_get_module_info(struct sPAPRRTASModuleInfo *mi) | +{ | + return -1; | +} | + | #endif | | #ifndef CONFIG_KVM | -- | 2.1.0 |
Re: [Qemu-devel] [PATCH v3 2/2] target-ppc: Implement rtas_get_sysparm(PROCESSOR_MODULE_INFO)
In reply to Sukadev BhattiproluQuoted 57 lines · Sukadev Bhattiprolu
Implement
RTAS_SYSPARM_PROCESSOR_MODULE_INFOparameter tortas_get_sysparm()call in qemu. This call returns the processor module (socket), chip and core information as specified in section 7.3.16.17 of LoPAPR v2.7.We walk the
/proc/device-treeto determine the number of modules(aka sockets), chips and cores in the _host_ system and return this info to the guest application that makes thertas_get_sysparm()call.We currently hard code the number of
module_typesto 1 (we currently don't have systems with more than one module type) but we should determine that dynamically somehow later.Thanks to input from Nishanth Aravamudan, Alexey Kardashevskiy, David Gibson, Thomas Huth.
Signed-off-by Sukadev Bhattiprolu <[email protected]>---
Changelog[v3]:
[David Gibson] Useglob()to simplify pattern matching path names.
Move new code into target-ppc/{kvm.c,kvm_ppc.h} to not impact other targets and avoid creating new files.
[Alexey Kardashevskiy] Fix indentation, error messages; fold new
code into existing files and avoid creating new files for this parameter; since the keys are integer, useg_direct_hash()andGINT_TO_POINTER()and avoid allocating/freeing memory.Changelog[v2]:
[Alexey Kardashevskiy] Use existing interfaces likeldl_be_p(),
stw_be_phys(),g_hash_table_new_full(),error_report()rather than re-inventing; fix indentation, function prottypes etc; Drop thefts()interface (which doesn't seem to be available on mingw32/mingw64) and useopendir()to walk specific directories in the directory tree.--- hw/ppc/spapr_rtas.c | 31 +++++++++++ include/hw/ppc/spapr.h | 13 +++++ target-ppc/kvm.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++ target-ppc/kvm_ppc.h | 8 +++ 4 files changed, 193 insertions(+)hw/ppc/spapr_rtas.c +2
-0@@ -38,6 +38,7 @@#include <libfdt.h> #include "hw/ppc/spapr_drc.h" +#include "kvm_ppc.h" /* #define DEBUG_SPAPR */ @@ -240,6 +241,36 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,target_ulong ret =RTAS_OUT_SUCCESS ;switch (parameter) { +case RTAS_SYSPARM_PROCESSOR_MODULE_INFO : {
hw/ppc/spapr_rtas.c static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, · line 254
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+struct sPAPRRTASModuleInfo modinfo; +int i, size =sizeof (modinfo), offset =0 ; + +memset (&modinfo,0 , size); +if (kvmppc_rtas_get_module_info (&modinfo)) { + ret =RTAS_OUT_HW_ERROR ; +break ; + } + +stw_be_phys (&address_space_memory, buffer+offset, size);
You're still advertising the full structure size to the guest, even though it may be only partially populated.
That will probably work in practice, but I think we should be PAPRishly correct and only output the size that we actually use here.
Quoted 157 lines
hw/ppc/spapr_rtas.c +19
-0+ offset +=2 ; + +stw_be_phys (&address_space_memory, buffer+offset, modinfo.module_types); + offset +=2 ; + +for (i =0 ; i < modinfo.module_types; i++) { +stw_be_phys (&address_space_memory, buffer+offset, + modinfo.si[i].sockets); + offset +=2 ; +stw_be_phys (&address_space_memory, buffer+offset, + modinfo.si[i].chips); + offset +=2 ; +stw_be_phys (&address_space_memory, buffer+offset, + modinfo.si[i].cores_per_chip); + offset +=2 ; + } +break ; + } +case RTAS_SYSPARM_SPLPAR_CHARACTERISTICS : {char *param_val =g_strdup_printf ("MaxEntCap=%d," "DesMem=%llu,"include/hw/ppc/spapr.h +13
-0@@ -463,6 +463,7 @@ int spapr_allocate_irq_block(int num, bool lsi, bool msi);/* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20#define RTAS_SYSPARM_DIAGNOSTICS_RUN_MODE 42 +#define RTAS_SYSPARM_PROCESSOR_MODULE_INFO 43#define RTAS_SYSPARM_UUID 48/* RTAS indicator/sensor types @@ -646,4 +647,16 @@ int spapr_rng_populate_dt(void *fdt);*/ #define SPAPR_LMB_FLAGS_ASSIGNED 0x00000008 +#define SPAPR_MAX_MODULE_TYPES 1 + +struct sPAPRRTASSocketInfo { +unsigned short sockets; +unsigned short chips; +unsigned short cores_per_chip; +}; +struct sPAPRRTASModuleInfo { +unsigned short module_types; +struct sPAPRRTASSocketInfo si[SPAPR_MAX_MODULE_TYPES ]; +}; +#endif /* !defined (__HW_SPAPR_H__) */ target-ppc/kvm.c +91
-0@@ -15,6 +15,7 @@*/ #include <dirent.h> +#include <glob.h> #include <sys/types.h> #include <sys/ioctl.h> #include <sys/mman.h> @@ -2518,3 +2519,143 @@ int kvmppc_enable_hwrng(void)return kvmppc_enable_hcall (kvm_state,H_RANDOM ); } + +/* Read an identifier from the file @path and add the identifier +* to the hash table @gt unless its already in the table. +*/ +static int kvmppc_hash_file_contents (GHashTable *gt,char *path) +{ +uint32_t idx; + + idx =kvmppc_read_int_dt (path); +if (idx ==-1 ) { +return -1 ; + } + +if (g_hash_table_contains (gt,GINT_TO_POINTER (idx))) { +return 0 ; + } + +if (!g_hash_table_insert (gt,GINT_TO_POINTER (idx),NULL )) { +fprintf (stderr,"%s() Unable to add key %d\n" , __func__, idx); +return -1 ; + } + +return 0 ; +} + +static int kvmppc_glob_count_ids_dt (const char *pattern,int *count) +{ +int i, rc; +glob_t dtglob; +GHashTable *htbl; + + rc =glob (pattern,GLOB_NOSORT ,NULL , &dtglob); +if (rc) { +fprintf (stderr,"%s() glob(%s) returns %d, errno %d\n" , __func__, + pattern, rc, errno); +return -1 ; + } + + rc =-1 ; + htbl =g_hash_table_new_full (g_direct_hash, g_direct_equal,NULL ,NULL ); + +for (i =0 ; i < dtglob.gl_pathc; i++) { +if (kvmppc_hash_file_contents (htbl, dtglob.gl_pathv[i])) { + goto cleanup; + } + } + + *count =g_hash_table_size (htbl); + rc =0 ; + +cleanup: +globfree (&dtglob); +g_hash_table_remove_all (htbl); +g_hash_table_destroy (htbl); + +return rc; +} + +/* Each socket's (aka module's) id is contained in the 'ibm,hw-module-id' +* file in an "xscom" directory (/proc/device-tree/xscom*). Similarly each +* chip's id is contained in the 'ibm,chip-id' file in an xscom directory. +* +* Since a module can have more than one chip and a chip can have more than +* one core, there are likely to be duplicates in the module and chip ids +* i.e more than one xscom directory can contain the same module/chip id. +* +* Search the xscom directories and count the number of _UNIQUE_ modules +* and chips in the system. +* +* Return 0 if one or more modules and chips each are found. Return -1 +* otherwise. +*/ +static int kvmppc_count_sockets_chips_dt (int *num_sockets,int *num_chips) +{ +const char *chip_pattern ="/proc/device-tree/xscom@*/ibm,chip-id" ; +const char *module_pattern ="/proc/device-tree/xscom@*/ibm,hw-module-id" ; + +if (kvmppc_glob_count_ids_dt (module_pattern, num_sockets) + ||kvmppc_glob_count_ids_dt (chip_pattern, num_chips)) { +return -1 ; + } + +if (*num_sockets ==0 || *num_chips ==0 ) { +return -1 ; + } + +return 0 ; +} + +/* Each core in the system is represented by a directory with the prefix
target-ppc/kvm.c int kvmppc_enable_hwrng(void) · line 2621
Quoted 10 lines
target-ppc/kvm.c +10
-0+* 'PowerPC,POWER' in directory /proc/device-tree/cpus/. Process that +* directory and count the number of cores in the system. +* +* Return 0 if one or more cores are found. Return -1 otherwise. +*/ +static int kvmppc_count_cores_dt (int *num_cores) +{ +int rc; +glob_t dtglob; +const char *cpus_pattern ="/proc/device-tree/cpus/PowerPC,POWER*" ;
Under KVM PR, this could still be too specific to IBM machines. I think it's probably safer to just use /proc/device-tree/cpus/*, I don't *think* we get anything under /cpus that isn't a cpu node.
In a number of ways I'd actually prefer to move to /cpus/cpu@NNN in general, since that follows the OF generic names recommendation we follow for most other nodes.
Quoted 72 lines
target-ppc/kvm.c +39
-0+ rc =glob (cpus_pattern,GLOB_NOSORT ,NULL , &dtglob); +if (rc) { +fprintf (stderr,"%s() glob(%s) returns %d, errno %d\n" , __func__, + cpus_pattern, rc, errno); +return -1 ; + } + + *num_cores = dtglob.gl_pathc; +globfree (&dtglob); + +if (*num_cores ==0 ) { +return -1 ; + } + +return 0 ; +} + +int kvmppc_rtas_get_module_info (struct sPAPRRTASModuleInfo *modinfo) +{ +int cores, chips, sockets; + +if (kvmppc_count_sockets_chips_dt (&sockets, &chips) + ||kvmppc_count_cores_dt (&cores)) { +return -1 ; + } + +/* TODO: Although the interface allows multiple module types, Power +* systems currently support only one module type per system - +* either Single Chip Module(SCM) or Dual Chip Module(DCM), +* but not both types in the same system. Hard code module_types +* for now till we can determine it dynamically. +*/ + modinfo->module_types =1 ; + modinfo->si[0 ].sockets = sockets; + modinfo->si[0 ].chips = chips; + modinfo->si[0 ].cores_per_chip = cores / chips; + +return 0 ; +}target-ppc/kvm_ppc.h +8
-0@@ -10,6 +10,7 @@#define __KVM_PPC_H__#define TYPE_HOST_POWERPC_CPU "host-" TYPE_POWERPC_CPU +#include "hw/ppc/spapr.h" #ifdef CONFIG_KVM @@ -55,6 +56,7 @@ void kvmppc_hash64_write_pte(CPUPPCState *env, target_ulong pte_index, target_ulong pte0, target_ulong pte1);bool kvmppc_has_cap_fixup_hcalls (void );int kvmppc_enable_hwrng (void ); +int kvmppc_rtas_get_module_info (struct sPAPRRTASModuleInfo *modinfo);#else @@ -256,6 +258,12 @@ static inline int kvmppc_enable_hwrng(void) {return -1 ; } + +static inline int kvmppc_rtas_get_module_info (struct sPAPRRTASModuleInfo *mi) +{ +return -1 ; +} +#endif #ifndef CONFIG_KVM
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v3 2/2] target-ppc: Implement rtas_get_sysparm(PROCESSOR_MODULE_INFO)
In reply to Sukadev BhattiproluQuoted 3 lines · Sukadev Bhattiprolu
David, Alexey,
Any comments on this patch?
Sorry, I've been busy, I've sent comments now.
Quoted 315 lines
Suka
Sukadev Bhattiprolu [[email protected]] wrote:
| Implement RTAS_SYSPARM_PROCESSOR_MODULE_INFO parameter to rtas_get_sysparm() | call in qemu. This call returns the processor module (socket), chip and core | information as specified in section 7.3.16.17 of LoPAPR v2.7. | | We walk the /proc/device-tree to determine the number of modules(aka sockets), | chips and cores in the _host_ system and return this info to the guest | application that makes the rtas_get_sysparm() call. | | We currently hard code the number of module_types to 1 (we currently don't | have systems with more than one module type) but we should determine that | dynamically somehow later. | | Thanks to input from Nishanth Aravamudan, Alexey Kardashevskiy, David Gibson, | Thomas Huth. | | Signed-off-by: Sukadev Bhattiprolu <[email protected]> | --- | Changelog[v3]: | [David Gibson] Use glob() to simplify pattern matching path names. | Move new code into target-ppc/{kvm.c,kvm_ppc.h} to not impact | other targets and avoid creating new files. | [Alexey Kardashevskiy] Fix indentation, error messages; fold new | code into existing files and avoid creating new files for this | parameter; since the keys are integer, use g_direct_hash() and | GINT_TO_POINTER() and avoid allocating/freeing memory. | | Changelog[v2]: | [Alexey Kardashevskiy] Use existing interfaces like ldl_be_p(), | stw_be_phys(), g_hash_table_new_full(), error_report() rather | than re-inventing; fix indentation, function prottypes etc; | Drop the fts() interface (which doesn't seem to be available | on mingw32/mingw64) and use opendir() to walk specific | directories in the directory tree. | --- | hw/ppc/spapr_rtas.c | 31 +++++++++++ | include/hw/ppc/spapr.h | 13 +++++ | target-ppc/kvm.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++ | target-ppc/kvm_ppc.h | 8 +++ | 4 files changed, 193 insertions(+) | | diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c | index 34b12a3..44b2537 100644 | --- a/hw/ppc/spapr_rtas.c | +++ b/hw/ppc/spapr_rtas.c | @@ -38,6 +38,7 @@ | | #include <libfdt.h> | #include "hw/ppc/spapr_drc.h" | +#include "kvm_ppc.h" | | /* #define DEBUG_SPAPR */ | | @@ -240,6 +241,36 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, | target_ulong ret = RTAS_OUT_SUCCESS; | | switch (parameter) { | + case RTAS_SYSPARM_PROCESSOR_MODULE_INFO: { | + struct sPAPRRTASModuleInfo modinfo; | + int i, size = sizeof(modinfo), offset = 0; | + | + memset(&modinfo, 0, size); | + if (kvmppc_rtas_get_module_info(&modinfo)) { | + ret = RTAS_OUT_HW_ERROR; | + break; | + } | + | + stw_be_phys(&address_space_memory, buffer+offset, size); | + offset += 2; | + | + stw_be_phys(&address_space_memory, buffer+offset, modinfo.module_types); | + offset += 2; | + | + for (i = 0; i < modinfo.module_types; i++) { | + stw_be_phys(&address_space_memory, buffer+offset, | + modinfo.si[i].sockets); | + offset += 2; | + stw_be_phys(&address_space_memory, buffer+offset, | + modinfo.si[i].chips); | + offset += 2; | + stw_be_phys(&address_space_memory, buffer+offset, | + modinfo.si[i].cores_per_chip); | + offset += 2; | + } | + break; | + } | + | case RTAS_SYSPARM_SPLPAR_CHARACTERISTICS: { | char *param_val = g_strdup_printf("MaxEntCap=%d," | "DesMem=%llu," | diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h | index 5baa906..f793465 100644 | --- a/include/hw/ppc/spapr.h | +++ b/include/hw/ppc/spapr.h | @@ -463,6 +463,7 @@ int spapr_allocate_irq_block(int num, bool lsi, bool msi); | /* RTAS ibm,get-system-parameter token values */ | #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20 | #define RTAS_SYSPARM_DIAGNOSTICS_RUN_MODE 42 | +#define RTAS_SYSPARM_PROCESSOR_MODULE_INFO 43 | #define RTAS_SYSPARM_UUID 48 | | /* RTAS indicator/sensor types | @@ -646,4 +647,16 @@ int spapr_rng_populate_dt(void *fdt); | */ | #define SPAPR_LMB_FLAGS_ASSIGNED 0x00000008 | | +#define SPAPR_MAX_MODULE_TYPES 1 | + | +struct sPAPRRTASSocketInfo { | + unsigned short sockets; | + unsigned short chips; | + unsigned short cores_per_chip; | +}; | +struct sPAPRRTASModuleInfo { | + unsigned short module_types; | + struct sPAPRRTASSocketInfo si[SPAPR_MAX_MODULE_TYPES]; | +}; | + | #endif /* !defined (__HW_SPAPR_H__) */ | diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c | index 9940a90..bbef78c 100644 | --- a/target-ppc/kvm.c | +++ b/target-ppc/kvm.c | @@ -15,6 +15,7 @@ | */ | | #include <dirent.h> | +#include <glob.h> | #include <sys/types.h> | #include <sys/ioctl.h> | #include <sys/mman.h> | @@ -2518,3 +2519,143 @@ int kvmppc_enable_hwrng(void) | | return kvmppc_enable_hcall(kvm_state, H_RANDOM); | } | + | +/* Read an identifier from the file @path and add the identifier | + * to the hash table @gt unless its already in the table. | + */ | +static int kvmppc_hash_file_contents(GHashTable *gt, char *path) | +{ | + uint32_t idx; | + | + idx = kvmppc_read_int_dt(path); | + if (idx == -1) { | + return -1; | + } | + | + if (g_hash_table_contains(gt, GINT_TO_POINTER(idx))) { | + return 0; | + } | + | + if (!g_hash_table_insert(gt, GINT_TO_POINTER(idx), NULL)) { | + fprintf(stderr, "%s() Unable to add key %d\n", __func__, idx); | + return -1; | + } | + | + return 0; | +} | + | +static int kvmppc_glob_count_ids_dt(const char *pattern, int *count) | +{ | + int i, rc; | + glob_t dtglob; | + GHashTable *htbl; | + | + rc = glob(pattern, GLOB_NOSORT, NULL, &dtglob); | + if (rc) { | + fprintf(stderr, "%s() glob(%s) returns %d, errno %d\n", __func__, | + pattern, rc, errno); | + return -1; | + } | + | + rc = -1; | + htbl = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); | + | + for (i = 0; i < dtglob.gl_pathc; i++) { | + if (kvmppc_hash_file_contents(htbl, dtglob.gl_pathv[i])) { | + goto cleanup; | + } | + } | + | + *count = g_hash_table_size(htbl); | + rc = 0; | + | +cleanup: | + globfree(&dtglob); | + g_hash_table_remove_all(htbl); | + g_hash_table_destroy(htbl); | + | + return rc; | +} | + | +/* Each socket's (aka module's) id is contained in the 'ibm,hw-module-id' | + * file in an "xscom" directory (/proc/device-tree/xscom*). Similarly each | + * chip's id is contained in the 'ibm,chip-id' file in an xscom directory. | + * | + * Since a module can have more than one chip and a chip can have more than | + * one core, there are likely to be duplicates in the module and chip ids | + * i.e more than one xscom directory can contain the same module/chip id. | + * | + * Search the xscom directories and count the number of _UNIQUE_ modules | + * and chips in the system. | + * | + * Return 0 if one or more modules and chips each are found. Return -1 | + * otherwise. | + */ | +static int kvmppc_count_sockets_chips_dt(int *num_sockets, int *num_chips) | +{ | + const char *chip_pattern = "/proc/device-tree/xscom@*/ibm,chip-id"; | + const char *module_pattern = "/proc/device-tree/xscom@*/ibm,hw-module-id"; | + | + if (kvmppc_glob_count_ids_dt(module_pattern, num_sockets) | + || kvmppc_glob_count_ids_dt(chip_pattern, num_chips)) { | + return -1; | + } | + | + if (*num_sockets == 0 || *num_chips == 0) { | + return -1; | + } | + | + return 0; | +} | + | +/* Each core in the system is represented by a directory with the prefix | + * 'PowerPC,POWER' in directory /proc/device-tree/cpus/. Process that | + * directory and count the number of cores in the system. | + * | + * Return 0 if one or more cores are found. Return -1 otherwise. | + */ | +static int kvmppc_count_cores_dt(int *num_cores) | +{ | + int rc; | + glob_t dtglob; | + const char *cpus_pattern = "/proc/device-tree/cpus/PowerPC,POWER*"; | + | + rc = glob(cpus_pattern, GLOB_NOSORT, NULL, &dtglob); | + if (rc) { | + fprintf(stderr, "%s() glob(%s) returns %d, errno %d\n", __func__, | + cpus_pattern, rc, errno); | + return -1; | + } | + | + *num_cores = dtglob.gl_pathc; | + globfree(&dtglob); | + | + if (*num_cores == 0) { | + return -1; | + } | + | + return 0; | +} | + | +int kvmppc_rtas_get_module_info(struct sPAPRRTASModuleInfo *modinfo) | +{ | + int cores, chips, sockets; | + | + if (kvmppc_count_sockets_chips_dt(&sockets, &chips) | + || kvmppc_count_cores_dt(&cores)) { | + return -1; | + } | + | + /* TODO: Although the interface allows multiple module types, Power | + * systems currently support only one module type per system - | + * either Single Chip Module(SCM) or Dual Chip Module(DCM), | + * but not both types in the same system. Hard code module_types | + * for now till we can determine it dynamically. | + */ | + modinfo->module_types = 1; | + modinfo->si[0].sockets = sockets; | + modinfo->si[0].chips = chips; | + modinfo->si[0].cores_per_chip = cores / chips; | + | + return 0; | +} | diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h | index 309cbe0..46a2768 100644 | --- a/target-ppc/kvm_ppc.h | +++ b/target-ppc/kvm_ppc.h | @@ -10,6 +10,7 @@ | #define __KVM_PPC_H__ | | #define TYPE_HOST_POWERPC_CPU "host-" TYPE_POWERPC_CPU | +#include "hw/ppc/spapr.h" | | #ifdef CONFIG_KVM | | @@ -55,6 +56,7 @@ void kvmppc_hash64_write_pte(CPUPPCState *env, target_ulong pte_index, | target_ulong pte0, target_ulong pte1); | bool kvmppc_has_cap_fixup_hcalls(void); | int kvmppc_enable_hwrng(void); | +int kvmppc_rtas_get_module_info(struct sPAPRRTASModuleInfo *modinfo); | | #else | | @@ -256,6 +258,12 @@ static inline int kvmppc_enable_hwrng(void) | { | return -1; | } | + | +static inline int kvmppc_rtas_get_module_info(struct sPAPRRTASModuleInfo *mi) | +{ | + return -1; | +} | + | #endif | | #ifndef CONFIG_KVM | -- | 2.1.0 |
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
Re: [Qemu-devel] [PATCH v3 2/2] target-ppc: Implement rtas_get_sysparm(PROCESSOR_MODULE_INFO)
In reply to David GibsonDavid Gibson [[email protected]] wrote:
| > @@ -240,6 +241,36 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,
| > target_ulong ret = RTAS_OUT_SUCCESS;
| >
| > switch (parameter) {
| > + case RTAS_SYSPARM_PROCESSOR_MODULE_INFO: {
| > + struct sPAPRRTASModuleInfo modinfo;
| > + int i, size = sizeof(modinfo), offset = 0;
| > +
| > + memset(&modinfo, 0, size);
| > + if (kvmppc_rtas_get_module_info(&modinfo)) {
| > + ret = RTAS_OUT_HW_ERROR;
| > + break;
| > + }
| > +
| > + stw_be_phys(&address_space_memory, buffer+offset, size);
|
| You're still advertising the full structure size to the guest, even
| though it may be only partially populated.
|
| That will probably work in practice, but I think we should be
| PAPRishly correct and only output the size that we actually use here.Ok. Will have kvmppc_rtas_get_module_info() take/update a size parameter and use that here.
|
<snip>
| > +/* Each core in the system is represented by a directory with the prefix
| > + * 'PowerPC,POWER' in directory /proc/device-tree/cpus/. Process that
| > + * directory and count the number of cores in the system.
| > + *
| > + * Return 0 if one or more cores are found. Return -1 otherwise.
| > + */
| > +static int kvmppc_count_cores_dt(int *num_cores)
| > +{
| > + int rc;
| > + glob_t dtglob;
| > + const char *cpus_pattern = "/proc/device-tree/cpus/PowerPC,POWER*";
|
| Under KVM PR, this could still be too specific to IBM machines. I
| think it's probably safer to just use /proc/device-tree/cpus/*, I
| don't *think* we get anything under /cpus that isn't a cpu node.Well, on my Tuleta system (3.18.22-355.el7_1.pkvm3_1_0.3700.3.ppc64le) I see several l2-cache, l3-cache entries as well as some properties (like phandle, #size-cells) besides the PowerPC,POWER* entries.
$ cd /proc/device-tree/cpus
$ lsprop l3-cache@30000020/device_type l3-cache@30000020/device_type "cache"
$ lsprop l2-cache@200008f0/device_type l2-cache@200008f0/device_type "cache"
$ lsprop PowerPC,POWER8@860/device_type PowerPC,POWER8@860/device_type "cpu"
Should we walk the /proc/device-tree/cpus/ tree and count only dirs with device-type "cpu" (rather than relying on the pattern PowerPC,POWER*)?
| | In a number of ways I'd actually prefer to move to /cpus/cpu@NNN in | general, since that follows the OF generic names recommendation we | follow for most other nodes.
Do you mean rename '/proc/device-tree/cpus/PowerPC,POWER8@NNN' to /proc/device-tree/cpus/cpu@NNN?
Thanks,
Sukadev
Re: [Qemu-devel] [PATCH v3 2/2] target-ppc: Implement rtas_get_sysparm(PROCESSOR_MODULE_INFO)
Quoted 56 lines · Sukadev Bhattiprolu
David Gibson [[email protected]] wrote:
| > @@ -240,6 +241,36 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, | > target_ulong ret = RTAS_OUT_SUCCESS; | > | > switch (parameter) { | > + case RTAS_SYSPARM_PROCESSOR_MODULE_INFO: { | > + struct sPAPRRTASModuleInfo modinfo; | > + int i, size = sizeof(modinfo), offset = 0; | > + | > + memset(&modinfo, 0, size); | > + if (kvmppc_rtas_get_module_info(&modinfo)) { | > + ret = RTAS_OUT_HW_ERROR; | > + break; | > + } | > + | > + stw_be_phys(&address_space_memory, buffer+offset, size); | | You're still advertising the full structure size to the guest, even | though it may be only partially populated. | | That will probably work in practice, but I think we should be | PAPRishly correct and only output the size that we actually use here.Ok. Will have
kvmppc_rtas_get_module_info()take/update a size parameter and use that here.|
<snip>
| > +/* Each core in the system is represented by a directory with the prefix | > + * 'PowerPC,POWER' in directory /proc/device-tree/cpus/. Process that | > + * directory and count the number of cores in the system. | > + * | > + * Return 0 if one or more cores are found. Return -1 otherwise. | > + */ | > +static int kvmppc_count_cores_dt(int *num_cores) | > +{ | > + int rc; | > + glob_t dtglob; | > + const char *cpus_pattern = "/proc/device-tree/cpus/PowerPC,POWER*"; | | Under KVM PR, this could still be too specific to IBM machines. I | think it's probably safer to just use /proc/device-tree/cpus/*, I | don't *think* we get anything under /cpus that isn't a cpu node.Well, on my Tuleta system (3.18.22-355.el7_1.pkvm3_1_0.3700.3.ppc64le) I see several l2-cache, l3-cache entries as well as some properties (like phandle, #size-cells) besides the PowerPC,POWER* entries.
$ cd /proc/device-tree/cpus$ lsprop l3-cache@30000020/device_type l3-cache@30000020/device_type "cache"
Quoted 7 lines
$ lsprop l2-cache@200008f0/device_type l2-cache@200008f0/device_type "cache"$ lsprop PowerPC,POWER8@860/device_type PowerPC,POWER8@860/device_type "cpu"
Ah.. right, guess I was wrong.
Quoted 2 lines
Should we walk the
/proc/device-tree/cpus/tree and count only dirs with device-type "cpu" (rather than relying on the pattern PowerPC,POWER*)?
Yes, I think you'll have to.
Quoted 7 lines
| | In a number of ways I'd actually prefer to move to /cpus/cpu@NNN in | general, since that follows the OF generic names recommendation we | follow for most other nodes.Do you mean rename '
/proc/device-tree/cpus/PowerPC,POWER8@NNN' to/proc/device-tree/cpus/cpu@NNN?
Yes. This is a firmware matter, so it's not something that can simply be changed everywhere, but it's the approach that I'd prefer to encourage for people making future machines and firmwares.
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH v3 2/2] target-ppc: Implement rtas_get_sysparm(PROCESSOR_MODULE_INFO)
David Gibson [[email protected]] wrote:
| > Should we walk the /proc/device-tree/cpus/ tree and count only dirs with | > device-type "cpu" (rather than relying on the pattern PowerPC,POWER*)? | | Yes, I think you'll have to. |
Ok. Are we ok with the xscom check I have (copied below):
+static int kvmppc_count_sockets_chips_dt(int *num_sockets, int *num_chips) +{
+ const char *chip_pattern = "/proc/device-tree/xscom@*/ibm,chip-id";
+ const char *module_pattern = "/proc/device-tree/xscom@*/ibm,hw-module-id";
---
I am not sure of a reliable way to detect number of chips besides the xscom. I do see that sysfs has node entries:
for i in `ls -d /sys/bus/cpu/devices/cpu*`; > do > basename $i/node* > done | sort | uniq node0 node1 node16 node17
which seems to correspond to
$ lsprop /proc/device-tree/xscom@*/ibm,chip-id /proc/device-tree/xscom@3fc0000000000/ibm,chip-id 00000000 /proc/device-tree/xscom@3fc0800000000/ibm,chip-id 00000001 /proc/device-tree/xscom@3fc8000000000/ibm,chip-id 00000010 (16) /proc/device-tree/xscom@3fc8800000000/ibm,chip-id 00000011 (17)
but is that reliable?
Quoted 1 line
+
| > | | > | In a number of ways I'd actually prefer to move to /cpus/cpu@NNN in | > | general, since that follows the OF generic names recommendation we | > | follow for most other nodes. | > | > Do you mean rename '/proc/device-tree/cpus/PowerPC,POWER8@NNN' to | > /proc/device-tree/cpus/cpu@NNN? | | Yes. This is a firmware matter, so it's not something that can simply | be changed everywhere, but it's the approach that I'd prefer to | encourage for people making future machines and firmwares.
Sure. ppc64_cpu also seems to rely on '/proc/device-tree/cpus/PowerPC' to count cores present and maybe there are other utilities that would need to be updated.
Sukadev