target-ppc: Implement rtas_get_sysparm(PROCESSOR_MODULE_INFO)
PATCH v2 1/1 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.18 of PAPR v2.7.
We walk the /proc/device-tree to determine the number of chips, cores and modules 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, but we should determine that dynamically somehow later.
Thanks to input from Nishanth Aravamudan and Alexey Kardashevsk.
---
Changelog[v2]:
[Alexey Kardashevsk] 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/Makefile.objs | 1 + hw/ppc/spapr_rtas.c | 35 +++++++ hw/ppc/spapr_rtas_modinfo.c | 230 ++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas_modinfo.h | 12 +++ include/hw/ppc/spapr.h | 1 + 5 files changed, 279 insertions(+) create mode 100644 hw/ppc/spapr_rtas_modinfo.c create mode 100644 hw/ppc/spapr_rtas_modinfo.h
hw/ppc/Makefile.objs +1 -0
@@ -4,6 +4,7 @@ obj-y += ppc.o ppc_booke.o obj-$(CONFIG_PSERIES) += spapr.o spapr_vio.o spapr_events.o obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o +obj-$(CONFIG_PSERIES) += spapr_rtas_modinfo.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endif
hw/ppc/spapr_rtas.c +35 -0
@@ -34,6 +34,8 @@#include "hw/ppc/spapr.h" #include "hw/ppc/spapr_vio.h" #include "qapi-event.h" + +#include "spapr_rtas_modinfo.h" #include "hw/boards.h" #include <libfdt.h>
@@ -240,6 +242,39 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,target_ulong ret =RTAS_OUT_SUCCESS ;switch (parameter) { +case RTAS_SYSPARM_PROCESSOR_MODULE_INFO : { +int i; +int offset =0 ; +int size; +struct rtas_module_info modinfo; + +if (rtas_get_module_info (&modinfo)) { +break ; + } + + size =sizeof (modinfo); + size += (modinfo.module_types -1 ) *sizeof (struct rtas_socket_info ); + +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,"
hw/ppc/spapr_rtas_modinfo.c new file +230 -0
230 lines not on this page · raw message
hw/ppc/spapr_rtas_modinfo.h new file +12 -0
@@ -0,0 +1,12 @@ + +struct rtas_socket_info { +unsigned short sockets; +unsigned short chips; +unsigned short cores_per_chip; +}; +struct rtas_module_info { +unsigned short module_types; +struct rtas_socket_info si[1 ]; +}; + +extern int rtas_get_module_info (struct rtas_module_info *topo);
include/hw/ppc/spapr.h +1 -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
Signature · 1 line
2.5.3
Quoted 4 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.18 of PAPR v2.7.
Quoted 8 lines
We walk the
/proc/device-treeto determine the number of chips, cores and modules 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, but we should determine that dynamically somehow later.Thanks to input from Nishanth Aravamudan and Alexey Kardashevsk.
"iy" is missing :)
Quoted 46 lines
Signed-off-by Sukadev Bhattiprolu <[email protected]>---
Changelog[v2]:
[Alexey Kardashevsk] 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/Makefile.objs | 1 + hw/ppc/spapr_rtas.c | 35 +++++++ hw/ppc/spapr_rtas_modinfo.c | 230 ++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas_modinfo.h | 12 +++ include/hw/ppc/spapr.h | 1 + 5 files changed, 279 insertions(+)create mode 100644
hw/ppc/spapr_rtas_modinfo.c
create mode 100644hw/ppc/spapr_rtas_modinfo.hhw/ppc/Makefile.objs +1
-0@@ -4,6 +4,7 @@ obj-y += ppc.o ppc_booke.o obj-$(CONFIG_PSERIES) += spapr.o spapr_vio.o spapr_events.o obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o +obj-$(CONFIG_PSERIES) += spapr_rtas_modinfo.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endifhw/ppc/spapr_rtas.c +2
-0@@ -34,6 +34,8 @@#include "hw/ppc/spapr.h" #include "hw/ppc/spapr_vio.h" #include "qapi-event.h" + +#include "spapr_rtas_modinfo.h" #include "hw/boards.h" #include <libfdt.h>
hw/ppc/spapr_rtas.c static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, · line 248
Quoted 7 lines
hw/ppc/spapr_rtas.c +4
-0@@ -240,6 +242,39 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,target_ulong ret =RTAS_OUT_SUCCESS ;switch (parameter) { +case RTAS_SYSPARM_PROCESSOR_MODULE_INFO : { +int i; +int offset =0 ; +int size;
Nit - could be one line.
hw/ppc/spapr_rtas.c static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, · line 252
Quoted 4 lines
hw/ppc/spapr_rtas.c +4
-0+struct rtas_module_info modinfo; + +if (rtas_get_module_info (&modinfo)) { +break ;
@ret will be still 0 in this case, set @ret to RTAS_OUT_HW_ERROR here.
Also, rtas_ibm_set_system_parameter() must return RTAS_OUT_NOT_AUTHORIZED on RTAS_SYSPARM_PROCESSOR_MODULE_INFO, as PAPR says.
Quoted 4 lines
hw/ppc/spapr_rtas.c +4
-0+ } + + size =sizeof (modinfo); + size += (modinfo.module_types -1 ) *sizeof (struct rtas_socket_info );
hw/ppc/spapr_rtas.c static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, · line 266
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+ +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);
checkpatch.pl does not warn on this but new lines start under opening brace in the previous line.
In terms on vim, it would be:
set expandtab
set tabstop=4
set shiftwidth=4
set cino=:0,(0
Quoted 20 lines
hw/ppc/spapr_rtas.c +11
-0+ 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,"hw/ppc/spapr_rtas_modinfo.c new file +0
-0
hw/ppc/spapr_rtas_modinfo.c line 4
Quoted 4 lines
hw/ppc/spapr_rtas_modinfo.c new file +4
-0@@ -0,0 +1,230 @@ +/* +* QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator +* +* Hypercall based emulated RTAS
This is a description of hw/ppc/spapr_rtas.c, not of the new file.
Not sure the new code deserves a separate file, I'd either:
- add it into hw/ppc/spapr_rtas.c OR
- move rtas_ibm_get_system_parameter() + rtas_ibm_set_system_parameter() to a separate file (let's call it hw/ppc/spapr_rtas_syspar.c) and add this new parameter there as there will be new parameters in the future anyway.
But I'll leave to the maintainer (David, hi :) ).
Quoted 32 lines
hw/ppc/spapr_rtas_modinfo.c new file +32
-0+* +* Copyright (c) 2015 Sukadev Bhattiprolu, IBM Corporation. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +* +*/ +#include <stdio.h> +#include <dirent.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <errno.h> + +#include <glib.h> +#include "spapr_rtas_modinfo.h" +#include "qemu/error-report.h"
hw/ppc/spapr_rtas_modinfo.c line 46
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+#include "qemu/bswap.h" + +static int file_read_buf (char *file_name,char *buf,int len) +{ +int rc; +FILE *fp; + + fp =fopen (file_name,"r" ); +if (!fp) { +error_report ("%s: Error opening %s\n" , __func__, file_name);
error_report() does not need "\n", remote it here and below.
Another thing - you passed __func__ here but you did not in other places, please make this consistent and pass __func__ everywhere OR make error messages more descriptive, the latter seems to be preferable way in QEMU, either way this should be easily grep'able, for example - "Unable to open %s, error %d" is too generic.
Quoted 8 lines
hw/ppc/spapr_rtas_modinfo.c new file +8
-0+return -1 ; + } + + rc =fread (buf,1 , len, fp); +fclose (fp); + +if (rc != len) { +return -1 ;
hw/ppc/spapr_rtas_modinfo.c line 64
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+ } + +return 0 ; +} + +/* +* Read an identifier from the file @path and add the identifier +* to the hash table @gt unless its already in the table. +*/ +static int hash_table_add_contents (GHashTable *gt,char *path)
Move this helper before count_modules_chips(). I thought for a sec that count_cores() uses it too :)
Quoted 6 lines
hw/ppc/spapr_rtas_modinfo.c new file +6
-0+{ +int idx; +char buf[16 ]; +int *key; + +if (file_read_buf (path, buf,sizeof (int ))) {
hw/ppc/spapr_rtas_modinfo.c line 80
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+return -1 ; + } + + idx =ldl_be_p (buf); + +if (g_hash_table_contains (gt, &idx)) { +return 0 ; + } + + key =g_malloc (sizeof (int ));
I kind of hoped that g_direct_hash() (and probably GINT_TO_POINTER() but I do not see kvm-all.c using it) will let you avoid g_malloc()'ing the keys.
Quoted 25 lines
hw/ppc/spapr_rtas_modinfo.c new file +25
-0+ + *key = idx; +if (!g_hash_table_insert (gt, key,NULL )) { +error_report ("Unable to insert key %d into chips hash table\n" , idx); +g_free (key); +return -1 ; + } + +return 0 ; +} + +/* +* Each core in the system is represented by a directory with the +* prefix 'PowerPC,POWER' in the directory /proc/device-tree/cpus/. +* Process that directory and count the number of cores in the system. +*/ +static int count_cores (int *num_cores) +{ +int rc; +DIR *dir; +struct dirent *ent; +const char *cpus_dir ="/proc/device-tree/cpus" ; +const char *ppc_prefix ="PowerPC,POWER" ; + + dir =opendir (cpus_dir);
hw/ppc/spapr_rtas_modinfo.c line 115
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+if (!dir) { +error_report ("Unable to open %s, error %d\n" , cpus_dir, errno); +return -1 ; + } + + *num_cores =0 ; +while (1 ) { + errno =0 ; + ent =readdir (dir); +if (!ent) {
rc = -errno; ....
hw/ppc/spapr_rtas_modinfo.c line 127
Quoted 12 lines
hw/ppc/spapr_rtas_modinfo.c new file +12
-0+break ; + } + +if (!strncmp (ppc_prefix, ent->d_name,strlen (ppc_prefix))) { + (*num_cores)++; + } + } + + rc =0 ; +if (errno) { + rc =-1 ; + }
... and remove these 4 lines above?
Quoted 11 lines
hw/ppc/spapr_rtas_modinfo.c new file +11
-0+ +closedir (dir); +return rc; +} + +/* +* Each module's (aka socket's) id is contained in the 'ibm,hw-module-id' +* file in the "xscom" directory (/proc/device-tree/xscom*). Similarly each +* chip's id is contained in the 'ibm,chip-id' file in the xscom directory. +* +* A module can contain more than one chip and a chip can contain more
hw/ppc/spapr_rtas_modinfo.c line 148
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+* than one core. So there are likely to be duplicates in the module +* and chip identifiers (i.e more than one xscom directory can contain +* the same module/chip id). +* +* Search the xscom directories and count the number of _UNIQUE_ module +* and chip identifiers in the system. +*/ +static int count_modules_chips (int *num_modules,int *num_chips) +{ +int rc;
int rc = -1;
Quoted 7 lines
hw/ppc/spapr_rtas_modinfo.c new file +7
-0+DIR *dir; +struct dirent *ent; +char path[PATH_MAX ]; +const char *xscom_dir ="/proc/device-tree" ; +const char *xscom_prefix ="xscom@" ; +GHashTable *chips_tbl, *modules_tbl; +
hw/ppc/spapr_rtas_modinfo.c line 165
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+ dir =opendir (xscom_dir); +if (!dir) { +error_report ("Unable to open %s, error %d\n" , xscom_dir, errno); +return -1 ; + } + + modules_tbl =g_hash_table_new_full (g_int_hash, g_int_equal, g_free,NULL ); + chips_tbl =g_hash_table_new_full (g_int_hash, g_int_equal, g_free,NULL ); + + rc =-1 ;
Remove this.
hw/ppc/spapr_rtas_modinfo.c line 115
Quoted 4 lines
hw/ppc/spapr_rtas_modinfo.c new file +4
-0+while (1 ) { + errno =0 ; + ent =readdir (dir); +if (!ent) {
Add this:
rc = -errno;
goto cleanup;
Quoted 11 lines
hw/ppc/spapr_rtas_modinfo.c new file +11
-0+break ; + } + +if (strncmp (xscom_prefix, ent->d_name,strlen (xscom_prefix))) { +continue ; + } + +sprintf (path,"%s/%s/ibm,chip-id" , xscom_dir, ent->d_name); +if (hash_table_add_contents (chips_tbl, path)) { + goto cleanup; + }
hw/ppc/spapr_rtas_modinfo.c line 190
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+ +sprintf (path,"%s/%s/ibm,hw-module-id" , xscom_dir, ent->d_name); +if (hash_table_add_contents (modules_tbl, path)) { + goto cleanup; + } + } + +if (errno) { + goto cleanup; + }
Do not need these 3 lines.
hw/ppc/spapr_rtas_modinfo.c line 194
Quoted 4 lines
hw/ppc/spapr_rtas_modinfo.c new file +4
-0+ + *num_modules =g_hash_table_size (modules_tbl); + *num_chips =g_hash_table_size (chips_tbl); + rc =0 ;
Remove this.
count_modules_chips() and count_cores() do pretty similar things, it would improve the code if error handling was done similar ways.
Quoted 8 lines
hw/ppc/spapr_rtas_modinfo.c new file +8
-0+ +cleanup: +g_hash_table_remove_all (modules_tbl); +g_hash_table_destroy (modules_tbl); + +g_hash_table_remove_all (chips_tbl); +g_hash_table_destroy (chips_tbl); +
hw/ppc/spapr_rtas_modinfo.c line 212
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+closedir (dir); + +return rc; +} + +int rtas_get_module_info (struct rtas_module_info *modinfo) +{ +int cores; +int chips; +int modules;
Nit - could be one line.
hw/ppc/spapr_rtas_modinfo.c line 225
Quoted 13 lines
hw/ppc/spapr_rtas_modinfo.c new file +13
-0+ +memset (modinfo,0 ,sizeof (struct rtas_module_info )); + +if (count_modules_chips (&modules, &chips) ||count_cores (&cores)) { +return -1 ; + } + +/* +* TODO: Hard code number of module_types for now till +* we figure out how to determine it dynamically. +*/ + modinfo->module_types =1 ; + modinfo->si[0 ].sockets = modules;
A "module" here is what modinfo describes so I'd expect @modules to be "1" in the existing code and count_modules_chips() to be named count_sockets_chips() and return @sockets, not @modules.
When exactly does a socket become a module? The SPAPR spec uses "sockets" here.
hw/ppc/spapr_rtas_modinfo.c line 227
Quoted 2 lines
hw/ppc/spapr_rtas_modinfo.c new file +2
-0+ modinfo->si[0 ].chips = chips; + modinfo->si[0 ].cores_per_chip = cores / chips;
What if no "ibm,chip-id" was found and chips == 0?
hw/ppc/spapr_rtas_modinfo.h
Quoted 8 lines
hw/ppc/spapr_rtas_modinfo.c new file +3
-0+ +return 0 ; +}hw/ppc/spapr_rtas_modinfo.h new file +0
-0
This file is missing a license and
#ifndef SPAPR_RTAS_MODINFO_H
#define SPAPR_RTAS_MODINFO_H
#endif
But I'd rather put the content to include/hw/ppc/spapr.h and avoid creating new files.
hw/ppc/spapr_rtas_modinfo.h line 10
Quoted 11 lines
hw/ppc/spapr_rtas_modinfo.h new file +10
-0@@ -0,0 +1,12 @@ + +struct rtas_socket_info { +unsigned short sockets; +unsigned short chips; +unsigned short cores_per_chip; +}; +struct rtas_module_info { +unsigned short module_types; +struct rtas_socket_info si[1 ]; +};
Will the number of rtas_socket_info be always a constant or (sure, in the future) it may take different values?
Normally when you invent API like rtas_get_module_info(), you tell the helper how much memory is allocated in the rtas_module_info struct (in our case it is ARRAY_SIZE(rtas_module_info.si) which is fine) and then the helper signals somehow how many module types it has found (which is missing here).
Quoted 15 lines
hw/ppc/spapr_rtas_modinfo.h new file +2
-0+ +extern int rtas_get_module_info (struct rtas_module_info *topo);include/hw/ppc/spapr.h +1
-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
Signature · 1 line
Alexey
Quoted 141 lines · Alexey Kardashevskiy
Quoted 4 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.18 of PAPR v2.7.Quoted 8 lines
We walk the
/proc/device-treeto determine the number of chips, cores and modules 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, but we should determine that dynamically somehow later.Thanks to input from Nishanth Aravamudan and Alexey Kardashevsk.
"iy" is missing :)
Quoted 46 lines
Signed-off-by Sukadev Bhattiprolu <[email protected]>---
Changelog[v2]:
[Alexey Kardashevsk] 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/Makefile.objs | 1 + hw/ppc/spapr_rtas.c | 35 +++++++ hw/ppc/spapr_rtas_modinfo.c | 230 ++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas_modinfo.h | 12 +++ include/hw/ppc/spapr.h | 1 + 5 files changed, 279 insertions(+) create mode 100644 hw/ppc/spapr_rtas_modinfo.c create mode 100644 hw/ppc/spapr_rtas_modinfo.hhw/ppc/Makefile.objs +1
-0@@ -4,6 +4,7 @@ obj-y += ppc.o ppc_booke.o obj-$(CONFIG_PSERIES) += spapr.o spapr_vio.o spapr_events.o obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o +obj-$(CONFIG_PSERIES) += spapr_rtas_modinfo.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endifhw/ppc/spapr_rtas.c +2
-0@@ -34,6 +34,8 @@#include "hw/ppc/spapr.h" #include "hw/ppc/spapr_vio.h" #include "qapi-event.h" + +#include "spapr_rtas_modinfo.h" #include "hw/boards.h" #include <libfdt.h> hw/ppc/spapr_rtas.c static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, · line 248
Quoted 7 lines
hw/ppc/spapr_rtas.c +4
-0@@ -240,6 +242,39 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,target_ulong ret =RTAS_OUT_SUCCESS ;switch (parameter) { +case RTAS_SYSPARM_PROCESSOR_MODULE_INFO : { +int i; +int offset =0 ; +int size;Nit - could be one line.
hw/ppc/spapr_rtas.c static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, · line 252
Quoted 4 lines
hw/ppc/spapr_rtas.c +4
-0+struct rtas_module_info modinfo; + +if (rtas_get_module_info (&modinfo)) { +break ;@ret will be still 0 in this case, set @ret to
RTAS_OUT_HW_ERRORhere.Also,
rtas_ibm_set_system_parameter()must returnRTAS_OUT_NOT_AUTHORIZEDonRTAS_SYSPARM_PROCESSOR_MODULE_INFO, as PAPR says.Quoted 4 lines
hw/ppc/spapr_rtas.c +4
-0+ } + + size =sizeof (modinfo); + size += (modinfo.module_types -1 ) *sizeof (struct rtas_socket_info );hw/ppc/spapr_rtas.c static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, · line 266
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+ +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);checkpatch.pl does not warn on this but new lines start under opening brace in the previous line.
In terms on vim, it would be:
set expandtab
set tabstop=4
set shiftwidth=4
set cino=:0,(0Quoted 20 lines
hw/ppc/spapr_rtas.c +11
-0+ 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,"hw/ppc/spapr_rtas_modinfo.c new file +0
-0hw/ppc/spapr_rtas_modinfo.c line 4
Quoted 4 lines
hw/ppc/spapr_rtas_modinfo.c new file +4
-0@@ -0,0 +1,230 @@ +/* +* QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator +* +* Hypercall based emulated RTAS This is a description of
hw/ppc/spapr_rtas.c, not of the new file.
Quoted 7 lines
Not sure the new code deserves a separate file, I'd either:
- add it intohw/ppc/spapr_rtas.cOR
- movertas_ibm_get_system_parameter()+rtas_ibm_set_system_parameter()to a separate file (let's call ithw/ppc/spapr_rtas_syspar.c) and add this new parameter there as there will be new parameters in the future anyway.But I'll leave to the maintainer (David, hi :) ).
Actually it probably should go in target-ppc/kvm.c. Looking up things on the host in this way only makes sense for KVM, and we have other code in there that looks in the host /proc/device-tree.
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
Alexey Kardashevskiy [[email protected]] wrote:
| On 11/05/2015 10:06 AM, Sukadev Bhattiprolu 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.18 of PAPR v2.7. | > | >We walk the /proc/device-tree to determine the number of chips, cores and | >modules 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, but we should determine | >that dynamically somehow later. | > | >Thanks to input from Nishanth Aravamudan and Alexey Kardashevsk. | | "iy" is missing :)
Argh. Sorry :-)
Agree with your other comments. Couple of questions/comments below.
|
| checkpatch.pl does not warn on this but new lines start under
| opening brace in the previous line.
|
| In terms on vim, it would be:
| set expandtab
| set tabstop=4
| set shiftwidth=4
| set cino=:0,(0
|
|
|
| >+ 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/hw/ppc/spapr_rtas_modinfo.c b/hw/ppc/spapr_rtas_modinfo.c
| >new file mode 100644
| >index 0000000..068fc2c
| >--- /dev/null
| >+++ b/hw/ppc/spapr_rtas_modinfo.c
| >@@ -0,0 +1,230 @@
| >+/*
| >+ * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator
| >+ *
| >+ * Hypercall based emulated RTAS
|
|
| This is a description of hw/ppc/spapr_rtas.c, not of the new file.Agree.
| | Not sure the new code deserves a separate file, I'd either: | - add it into hw/ppc/spapr_rtas.c OR | - move rtas_ibm_get_system_parameter() + | rtas_ibm_set_system_parameter() to a separate file (let's call it | hw/ppc/spapr_rtas_syspar.c) and add this new parameter there as | there will be new parameters in the future anyway. | | But I'll leave to the maintainer (David, hi :) ).
Will discuss this on the other thread from David (maybe move to target-ppc/kvm.c?)
|
|
<snip>
| >+
| >+static int file_read_buf(char *file_name, char *buf, int len)
| >+{
| >+ int rc;
| >+ FILE *fp;
| >+
| >+ fp = fopen(file_name, "r");
| >+ if (!fp) {
| >+ error_report("%s: Error opening %s\n", __func__, file_name);
|
|
| error_report() does not need "\n", remote it here and below.
|
| Another thing - you passed __func__ here but you did not in other
| places, please make this consistent and pass __func__ everywhere OR
| make error messages more descriptive, the latter seems to be
| preferable way in QEMU, either way this should be easily grep'able,
| for example - "Unable to open %s, error %d" is too generic.will change to "Error opening device tree file %s" and drop the __func__.
|
|
| >+ return -1;
| >+ }
| >+
| >+ rc = fread(buf, 1, len, fp);
| >+ fclose(fp);
| >+
| >+ if (rc != len) {
| >+ return -1;
| >+ }
| >+
| >+ return 0;
| >+}
| >+
| >+/*
| >+ * Read an identifier from the file @path and add the identifier
| >+ * to the hash table @gt unless its already in the table.
| >+ */
| >+static int hash_table_add_contents(GHashTable *gt, char *path)
|
| Move this helper before count_modules_chips(). I thought for a sec
| that count_cores() uses it too :)Ok.
|
|
| >+{
| >+ int idx;
| >+ char buf[16];
| >+ int *key;
| >+
| >+ if (file_read_buf(path, buf, sizeof(int))) {
| >+ return -1;
| >+ }
| >+
| >+ idx = ldl_be_p(buf);
| >+
| >+ if (g_hash_table_contains(gt, &idx)) {
| >+ return 0;
| >+ }
| >+
| >+ key = g_malloc(sizeof(int));
|
|
| I kind of hoped that g_direct_hash() (and probably GINT_TO_POINTER()
| but I do not see kvm-all.c using it) will let you avoid
| g_malloc()'ing the keys.I think g_direct_hash() and GINT_TO_POINTER will work. Will try them out.
|
|
|
| >+
| >+ *key = idx;
| >+ if (!g_hash_table_insert(gt, key, NULL)) {
| >+ error_report("Unable to insert key %d into chips hash table\n", idx);
| >+ g_free(key);
| >+ return -1;
| >+ }
| >+
| >+ return 0;
| >+}
| >+
| >+/*
| >+ * Each core in the system is represented by a directory with the
| >+ * prefix 'PowerPC,POWER' in the directory /proc/device-tree/cpus/.
| >+ * Process that directory and count the number of cores in the system.
| >+ */
| >+static int count_cores(int *num_cores)
| >+{
| >+ int rc;
| >+ DIR *dir;
| >+ struct dirent *ent;
| >+ const char *cpus_dir = "/proc/device-tree/cpus";
| >+ const char *ppc_prefix = "PowerPC,POWER";
| >+
| >+ dir = opendir(cpus_dir);
| >+ if (!dir) {
| >+ error_report("Unable to open %s, error %d\n", cpus_dir, errno);
| >+ return -1;
| >+ }
| >+
| >+ *num_cores = 0;
| >+ while (1) {
| >+ errno = 0;
| >+ ent = readdir(dir);
| >+ if (!ent) {
|
| rc = -errno; ....Yes. Thanks,
|
|
| >+ break;
| >+ }
| >+
| >+ if (!strncmp(ppc_prefix, ent->d_name, strlen(ppc_prefix))) {
| >+ (*num_cores)++;
| >+ }
| >+ }
| >+
| >+ rc = 0;
| >+ if (errno) {
| >+ rc = -1;
| >+ }
|
|
| ... and remove these 4 lines above?Ok.
|
|
|
| >+
| >+ closedir(dir);
| >+ return rc;
| >+}
| >+
| >+/*
| >+ * Each module's (aka socket's) id is contained in the 'ibm,hw-module-id'
| >+ * file in the "xscom" directory (/proc/device-tree/xscom*). Similarly each
| >+ * chip's id is contained in the 'ibm,chip-id' file in the xscom directory.
| >+ *
| >+ * A module can contain more than one chip and a chip can contain more
| >+ * than one core. So there are likely to be duplicates in the module
| >+ * and chip identifiers (i.e more than one xscom directory can contain
| >+ * the same module/chip id).
| >+ *
| >+ * Search the xscom directories and count the number of _UNIQUE_ module
| >+ * and chip identifiers in the system.
| >+ */
| >+static int count_modules_chips(int *num_modules, int *num_chips)
| >+{
| >+ int rc;
|
| int rc = -1;
|
|
| >+ DIR *dir;
| >+ struct dirent *ent;
| >+ char path[PATH_MAX];
| >+ const char *xscom_dir = "/proc/device-tree";
| >+ const char *xscom_prefix = "xscom@";
| >+ GHashTable *chips_tbl, *modules_tbl;
| >+
| >+ dir = opendir(xscom_dir);
| >+ if (!dir) {
| >+ error_report("Unable to open %s, error %d\n", xscom_dir, errno);
| >+ return -1;
| >+ }
| >+
| >+ modules_tbl = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
| >+ chips_tbl = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
| >+
| >+ rc = -1;
|
|
| Remove this.
|
| >+ while (1) {
| >+ errno = 0;
| >+ ent = readdir(dir);
| >+ if (!ent) {
|
| Add this:
| rc = -errno;
| goto cleanup;
|
| >+ break;
| >+ }
| >+
| >+ if (strncmp(xscom_prefix, ent->d_name, strlen(xscom_prefix))) {
| >+ continue;
| >+ }
| >+
| >+ sprintf(path, "%s/%s/ibm,chip-id", xscom_dir, ent->d_name);
| >+ if (hash_table_add_contents(chips_tbl, path)) {
| >+ goto cleanup;
| >+ }
| >+
| >+ sprintf(path, "%s/%s/ibm,hw-module-id", xscom_dir, ent->d_name);
| >+ if (hash_table_add_contents(modules_tbl, path)) {
| >+ goto cleanup;
| >+ }
| >+ }
| >+
| >+ if (errno) {
| >+ goto cleanup;
| >+ }
|
| Do not need these 3 lines.
|
|
| >+
| >+ *num_modules = g_hash_table_size(modules_tbl);
| >+ *num_chips = g_hash_table_size(chips_tbl);
| >+ rc = 0;
|
|
| Remove this.
|
| count_modules_chips() and count_cores() do pretty similar things, it
| would improve the code if error handling was done similar ways.Agree.
|
|
| >+
| >+cleanup:
| >+ g_hash_table_remove_all(modules_tbl);
| >+ g_hash_table_destroy(modules_tbl);
| >+
| >+ g_hash_table_remove_all(chips_tbl);
| >+ g_hash_table_destroy(chips_tbl);
| >+
| >+ closedir(dir);
| >+
| >+ return rc;
| >+}
| >+
| >+int rtas_get_module_info(struct rtas_module_info *modinfo)
| >+{
| >+ int cores;
| >+ int chips;
| >+ int modules;
|
| Nit - could be one line.
|
|
| >+
| >+ memset(modinfo, 0, sizeof(struct rtas_module_info));
| >+
| >+ if (count_modules_chips(&modules, &chips) || count_cores(&cores)) {
| >+ return -1;
| >+ }
| >+
| >+ /*
| >+ * TODO: Hard code number of module_types for now till
| >+ * we figure out how to determine it dynamically.
| >+ */
| >+ modinfo->module_types = 1;
| >+ modinfo->si[0].sockets = modules;
|
|
| A "module" here is what modinfo describes so I'd expect @modules to
| be "1" in the existing code and count_modules_chips() to be named
| count_sockets_chips() and return @sockets, not @modules.
|
| When exactly does a socket become a module? The SPAPR spec uses "sockets" here.I am trying to get the terminology too :-) Is socket a slot where a module is attached?
I will change the variable name 'modules' to 'sockets'.
| | | >+ modinfo->si[0].chips = chips; | >+ modinfo->si[0].cores_per_chip = cores / chips; | | | What if no "ibm,chip-id" was found and chips == 0?
If we fail to readdir(xscom) or fail to read the 'ibm,chip-id', we return an error which we check above.
| | | >+ | >+ return 0; | >+} | >diff --git a/hw/ppc/spapr_rtas_modinfo.h b/hw/ppc/spapr_rtas_modinfo.h | >new file mode 100644 | >index 0000000..356a2b5 | >--- /dev/null | >+++ b/hw/ppc/spapr_rtas_modinfo.h | | | This file is missing a license and | #ifndef SPAPR_RTAS_MODINFO_H | #define SPAPR_RTAS_MODINFO_H | #endif | | But I'd rather put the content to include/hw/ppc/spapr.h and avoid | creating new files.
Ok.
|
|
| >@@ -0,0 +1,12 @@
| >+
| >+struct rtas_socket_info {
| >+ unsigned short sockets;
| >+ unsigned short chips;
| >+ unsigned short cores_per_chip;
| >+};
| >+struct rtas_module_info {
| >+ unsigned short module_types;
| >+ struct rtas_socket_info si[1];
| >+};
|
|
| Will the number of rtas_socket_info be always a constant or (sure,
| in the future) it may take different values?TBH, I am not sure. One thing though, array size of rtas_socket_info depends on number of module _types_. Like Nishanth Aravamudan mentioned offline, we are not sure if both a DCM and SCM types can be on a system at once (or even if they can be added dynamically).
Another thing I have on my list to check is how this works with hotplug CPU (in the host). If the device-tree is properly updated then these calls will return the updated info? The values in the array will change but the number of entries (types) in the array is still 1.
| | Normally when you invent API like rtas_get_module_info(), you tell | the helper how much memory is allocated in the rtas_module_info | struct (in our case it is ARRAY_SIZE(rtas_module_info.si) which is | fine) and then the helper signals somehow how many module types it | has found (which is missing here).
Can we assume that the number of types is static for now i.e both caller and callee know the size (although I should fix the computation of size in spapr_rtas.c and use MAX_MODULE_TYPES that David pointed out).
Thanks
Sukadev
Quoted 73 lines · Sukadev Bhattiprolu
Alexey Kardashevskiy [[email protected]] wrote:
| On 11/05/2015 10:06 AM, Sukadev Bhattiprolu 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.18 of PAPR v2.7. | > | >We walk the /proc/device-tree to determine the number of chips, cores and | >modules 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, but we should determine | >that dynamically somehow later. | > | >Thanks to input from Nishanth Aravamudan and Alexey Kardashevsk. | | "iy" is missing :)Argh. Sorry :-)
Agree with your other comments. Couple of questions/comments below.
| | checkpatch.pl does not warn on this but new lines start under | opening brace in the previous line. | | In terms on vim, it would be: | set expandtab | set tabstop=4 | set shiftwidth=4 | set cino=:0,(0 | | | | >+ 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/hw/ppc/spapr_rtas_modinfo.c b/hw/ppc/spapr_rtas_modinfo.c | >new file mode 100644 | >index 0000000..068fc2c | >--- /dev/null | >+++ b/hw/ppc/spapr_rtas_modinfo.c | >@@ -0,0 +1,230 @@ | >+/* | >+ * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator | >+ * | >+ * Hypercall based emulated RTAS | | | This is a description of hw/ppc/spapr_rtas.c, not of the new file.Agree.
| | Not sure the new code deserves a separate file, I'd either: | - add it into hw/ppc/spapr_rtas.c OR | - move rtas_ibm_get_system_parameter() + | rtas_ibm_set_system_parameter() to a separate file (let's call it | hw/ppc/spapr_rtas_syspar.c) and add this new parameter there as | there will be new parameters in the future anyway. | | But I'll leave to the maintainer (David, hi :) ).
Quoted 2 lines
Will discuss this on the other thread from David (maybe move to
target-ppc/kvm.c?)
Sounds right.
Quoted 283 lines
|
|
<snip>| >+ | >+static int file_read_buf(char *file_name, char *buf, int len) | >+{ | >+ int rc; | >+ FILE *fp; | >+ | >+ fp = fopen(file_name, "r"); | >+ if (!fp) { | >+ error_report("%s: Error opening %s\n", __func__, file_name); | | | error_report() does not need "\n", remote it here and below. | | Another thing - you passed __func__ here but you did not in other | places, please make this consistent and pass __func__ everywhere OR | make error messages more descriptive, the latter seems to be | preferable way in QEMU, either way this should be easily grep'able, | for example - "Unable to open %s, error %d" is too generic.will change to "Error opening device tree file %s" and drop the
__func__.| | | >+ return -1; | >+ } | >+ | >+ rc = fread(buf, 1, len, fp); | >+ fclose(fp); | >+ | >+ if (rc != len) { | >+ return -1; | >+ } | >+ | >+ return 0; | >+} | >+ | >+/* | >+ * Read an identifier from the file @path and add the identifier | >+ * to the hash table @gt unless its already in the table. | >+ */ | >+static int hash_table_add_contents(GHashTable *gt, char *path) | | Move this helper before count_modules_chips(). I thought for a sec | that count_cores() uses it too :)Ok.
| | | >+{ | >+ int idx; | >+ char buf[16]; | >+ int *key; | >+ | >+ if (file_read_buf(path, buf, sizeof(int))) { | >+ return -1; | >+ } | >+ | >+ idx = ldl_be_p(buf); | >+ | >+ if (g_hash_table_contains(gt, &idx)) { | >+ return 0; | >+ } | >+ | >+ key = g_malloc(sizeof(int)); | | | I kind of hoped that g_direct_hash() (and probably GINT_TO_POINTER() | but I do not see kvm-all.c using it) will let you avoid | g_malloc()'ing the keys.I think
g_direct_hash()andGINT_TO_POINTERwill work. Will try them out.| | | | >+ | >+ *key = idx; | >+ if (!g_hash_table_insert(gt, key, NULL)) { | >+ error_report("Unable to insert key %d into chips hash table\n", idx); | >+ g_free(key); | >+ return -1; | >+ } | >+ | >+ return 0; | >+} | >+ | >+/* | >+ * Each core in the system is represented by a directory with the | >+ * prefix 'PowerPC,POWER' in the directory /proc/device-tree/cpus/. | >+ * Process that directory and count the number of cores in the system. | >+ */ | >+static int count_cores(int *num_cores) | >+{ | >+ int rc; | >+ DIR *dir; | >+ struct dirent *ent; | >+ const char *cpus_dir = "/proc/device-tree/cpus"; | >+ const char *ppc_prefix = "PowerPC,POWER"; | >+ | >+ dir = opendir(cpus_dir); | >+ if (!dir) { | >+ error_report("Unable to open %s, error %d\n", cpus_dir, errno); | >+ return -1; | >+ } | >+ | >+ *num_cores = 0; | >+ while (1) { | >+ errno = 0; | >+ ent = readdir(dir); | >+ if (!ent) { | | rc = -errno; ....Yes. Thanks,
| | | >+ break; | >+ } | >+ | >+ if (!strncmp(ppc_prefix, ent->d_name, strlen(ppc_prefix))) { | >+ (*num_cores)++; | >+ } | >+ } | >+ | >+ rc = 0; | >+ if (errno) { | >+ rc = -1; | >+ } | | | ... and remove these 4 lines above?Ok.
| | | | >+ | >+ closedir(dir); | >+ return rc; | >+} | >+ | >+/* | >+ * Each module's (aka socket's) id is contained in the 'ibm,hw-module-id' | >+ * file in the "xscom" directory (/proc/device-tree/xscom*). Similarly each | >+ * chip's id is contained in the 'ibm,chip-id' file in the xscom directory. | >+ * | >+ * A module can contain more than one chip and a chip can contain more | >+ * than one core. So there are likely to be duplicates in the module | >+ * and chip identifiers (i.e more than one xscom directory can contain | >+ * the same module/chip id). | >+ * | >+ * Search the xscom directories and count the number of _UNIQUE_ module | >+ * and chip identifiers in the system. | >+ */ | >+static int count_modules_chips(int *num_modules, int *num_chips) | >+{ | >+ int rc; | | int rc = -1; | | | >+ DIR *dir; | >+ struct dirent *ent; | >+ char path[PATH_MAX]; | >+ const char *xscom_dir = "/proc/device-tree"; | >+ const char *xscom_prefix = "xscom@"; | >+ GHashTable *chips_tbl, *modules_tbl; | >+ | >+ dir = opendir(xscom_dir); | >+ if (!dir) { | >+ error_report("Unable to open %s, error %d\n", xscom_dir, errno); | >+ return -1; | >+ } | >+ | >+ modules_tbl = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL); | >+ chips_tbl = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL); | >+ | >+ rc = -1; | | | Remove this. | | >+ while (1) { | >+ errno = 0; | >+ ent = readdir(dir); | >+ if (!ent) { | | Add this: | rc = -errno; | goto cleanup; | | >+ break; | >+ } | >+ | >+ if (strncmp(xscom_prefix, ent->d_name, strlen(xscom_prefix))) { | >+ continue; | >+ } | >+ | >+ sprintf(path, "%s/%s/ibm,chip-id", xscom_dir, ent->d_name); | >+ if (hash_table_add_contents(chips_tbl, path)) { | >+ goto cleanup; | >+ } | >+ | >+ sprintf(path, "%s/%s/ibm,hw-module-id", xscom_dir, ent->d_name); | >+ if (hash_table_add_contents(modules_tbl, path)) { | >+ goto cleanup; | >+ } | >+ } | >+ | >+ if (errno) { | >+ goto cleanup; | >+ } | | Do not need these 3 lines. | | | >+ | >+ *num_modules = g_hash_table_size(modules_tbl); | >+ *num_chips = g_hash_table_size(chips_tbl); | >+ rc = 0; | | | Remove this. | | count_modules_chips() and count_cores() do pretty similar things, it | would improve the code if error handling was done similar ways.Agree.
| | | >+ | >+cleanup: | >+ g_hash_table_remove_all(modules_tbl); | >+ g_hash_table_destroy(modules_tbl); | >+ | >+ g_hash_table_remove_all(chips_tbl); | >+ g_hash_table_destroy(chips_tbl); | >+ | >+ closedir(dir); | >+ | >+ return rc; | >+} | >+ | >+int rtas_get_module_info(struct rtas_module_info *modinfo) | >+{ | >+ int cores; | >+ int chips; | >+ int modules; | | Nit - could be one line. | | | >+ | >+ memset(modinfo, 0, sizeof(struct rtas_module_info)); | >+ | >+ if (count_modules_chips(&modules, &chips) || count_cores(&cores)) { | >+ return -1; | >+ } | >+ | >+ /* | >+ * TODO: Hard code number of module_types for now till | >+ * we figure out how to determine it dynamically. | >+ */ | >+ modinfo->module_types = 1; | >+ modinfo->si[0].sockets = modules; | | | A "module" here is what modinfo describes so I'd expect @modules to | be "1" in the existing code and count_modules_chips() to be named | count_sockets_chips() and return @sockets, not @modules. | | When exactly does a socket become a module? The SPAPR spec uses "sockets" here.
Quoted 2 lines
I am trying to get the terminology too :-) Is socket a slot where a module is attached?
Sorry, no idea.
Quoted 10 lines
I will change the variable name 'modules' to 'sockets'.
| | | >+ modinfo->si[0].chips = chips; | >+ modinfo->si[0].cores_per_chip = cores / chips; | | | What if no "ibm,chip-id" was found and chips == 0?
Quoted 2 lines
If we fail to readdir(xscom) or fail to read the 'ibm,chip-id', we return an error which we check above.
You assume that if there is /proc/device-tree, then there is always "xscom@" but this might not be always the case, like PR KVM on embedded PPC64.
Quoted 41 lines
| | | >+ | >+ return 0; | >+} | >diff --git a/hw/ppc/spapr_rtas_modinfo.h b/hw/ppc/spapr_rtas_modinfo.h | >new file mode 100644 | >index 0000000..356a2b5 | >--- /dev/null | >+++ b/hw/ppc/spapr_rtas_modinfo.h | | | This file is missing a license and | #ifndef SPAPR_RTAS_MODINFO_H | #define SPAPR_RTAS_MODINFO_H | #endif | | But I'd rather put the content to include/hw/ppc/spapr.h and avoid | creating new files.Ok.
| | | >@@ -0,0 +1,12 @@ | >+ | >+struct rtas_socket_info { | >+ unsigned short sockets; | >+ unsigned short chips; | >+ unsigned short cores_per_chip; | >+}; | >+struct rtas_module_info { | >+ unsigned short module_types; | >+ struct rtas_socket_info si[1]; | >+}; | | | Will the number of rtas_socket_info be always a constant or (sure, | in the future) it may take different values?
Quoted 4 lines
TBH, I am not sure. One thing though, array size of
rtas_socket_infodepends on number of module _types_. Like Nishanth Aravamudan mentioned offline, we are not sure if both a DCM and SCM types can be on a system at once (or even if they can be added dynamically).
What are DCM and SCM? What type do we have in Tuleta?
Quoted 13 lines
Another thing I have on my list to check is how this works with hotplug CPU (in the host). If the device-tree is properly updated then these calls will return the updated info? The values in the array will change but the number of entries (types) in the array is still 1.
| | Normally when you invent API like rtas_get_module_info(), you tell | the helper how much memory is allocated in the rtas_module_info | struct (in our case it is ARRAY_SIZE(rtas_module_info.si) which is | fine) and then the helper signals somehow how many module types it | has found (which is missing here).
Quoted 3 lines
Can we assume that the number of types is static for now i.e both caller and callee know the size (although I should fix the computation of size in
spapr_rtas.cand useMAX_MODULE_TYPESthat David pointed out).
I do not know what these modules can be so I cannot advise on this, sorry. I honestly do not see much point in implementing this system parameter - what will the guest do with this information?
You could get rid of rtas_module_info for now and have a helper for rtas_socket_info only - rtas_get_xxx_module_info() (where xxx is DCM or SCM or whatever it is now and what we support). Then it would be up to rtas_ibm_get_system_parameter() to decide how many modules types we want to expose to the guest (now - one) and when we get a new module type, we will either extend rtas_get_xxx_module_info() or implement another helper.
Signature · 1 line
Alexey
Alexey Kardashevskiy [[email protected]] wrote:
<snip>
| >| When exactly does a socket become a module? The SPAPR spec uses "sockets" here. | > | >I am trying to get the terminology too :-) Is socket a slot where a | >module is attached? | | Sorry, no idea.
Ok.
| | | > | >I will change the variable name 'modules' to 'sockets'. | >| | >| | >| >+ modinfo->si[0].chips = chips; | >| >+ modinfo->si[0].cores_per_chip = cores / chips; | >| | >| | >| What if no "ibm,chip-id" was found and chips == 0? | > | >If we fail to readdir(xscom) or fail to read the 'ibm,chip-id', | >we return an error which we check above. | | | You assume that if there is /proc/device-tree, then there is always | "xscom@" but this might not be always the case, like PR KVM on | embedded PPC64.
For ibm,chip-id, we do try to read the file (and eliminate duplicates chip ids) If we can't read the file (hash_table_add_contents()) we return an error, but will check again.
|
|
|
| >
| >|
| >|
| >| >+
| >| >+ return 0;
| >| >+}
| >| >diff --git a/hw/ppc/spapr_rtas_modinfo.h b/hw/ppc/spapr_rtas_modinfo.h
| >| >new file mode 100644
| >| >index 0000000..356a2b5
| >| >--- /dev/null
| >| >+++ b/hw/ppc/spapr_rtas_modinfo.h
| >|
| >|
| >| This file is missing a license and
| >| #ifndef SPAPR_RTAS_MODINFO_H
| >| #define SPAPR_RTAS_MODINFO_H
| >| #endif
| >|
| >| But I'd rather put the content to include/hw/ppc/spapr.h and avoid
| >| creating new files.
| >
| >Ok.
| >
| >|
| >|
| >| >@@ -0,0 +1,12 @@
| >| >+
| >| >+struct rtas_socket_info {
| >| >+ unsigned short sockets;
| >| >+ unsigned short chips;
| >| >+ unsigned short cores_per_chip;
| >| >+};
| >| >+struct rtas_module_info {
| >| >+ unsigned short module_types;
| >| >+ struct rtas_socket_info si[1];
| >| >+};
| >|
| >|
| >| Will the number of rtas_socket_info be always a constant or (sure,
| >| in the future) it may take different values?
| >
| >TBH, I am not sure. One thing though, array size of rtas_socket_info
| >depends on number of module _types_. Like Nishanth Aravamudan mentioned
| >offline, we are not sure if both a DCM and SCM types can be on a system
| >at once (or even if they can be added dynamically).
|
| What are DCM and SCM? What type do we have in Tuleta?Dual Chip Module and Single Chip Module. Maybe its standard configuration but on our Tuleta, we have a DCM (2 chips per module):
$ lsprop /proc/device-tree/xscom*/ibm,hw-module-id /proc/device-tree/xscom@3fc0000000000/ibm,hw-module-id 00000000 /proc/device-tree/xscom@3fc0800000000/ibm,hw-module-id 00000000 /proc/device-tree/xscom@3fc8000000000/ibm,hw-module-id 00000001 /proc/device-tree/xscom@3fc8800000000/ibm,hw-module-id 00000001
Each xscom represents a chip. Two chips have module id 0, two have module id 1.
| | | >Another thing I have on my list to check is how this works with | >hotplug CPU (in the host). If the device-tree is properly updated | >then these calls will return the updated info? The values in the | >array will change but the number of entries (types) in the array is | >still 1. | > | >| | >| Normally when you invent API like rtas_get_module_info(), you tell | >| the helper how much memory is allocated in the rtas_module_info | >| struct (in our case it is ARRAY_SIZE(rtas_module_info.si) which is | >| fine) and then the helper signals somehow how many module types it | >| has found (which is missing here). | > | >Can we assume that the number of types is static for now i.e both | >caller and callee know the size (although I should fix the computation | >of size in spapr_rtas.c and use MAX_MODULE_TYPES that David pointed out). | | | I do not know what these modules can be so I cannot advise on this, | sorry. I honestly do not see much point in implementing this system | parameter - what will the guest do with this information?
AFAICT, this system parameter is needed for distro licensing on powerKVM :-)
| | You could get rid of rtas_module_info for now and have a helper for | rtas_socket_info only - rtas_get_xxx_module_info() (where xxx is DCM | or SCM or whatever it is now and what we support). Then it would be | up to rtas_ibm_get_system_parameter() to decide how many modules | types we want to expose to the guest (now - one) and when we get a | new module type, we will either extend rtas_get_xxx_module_info() or | implement another helper. | | | -- | Alexey
Quoted 32 lines · Sukadev Bhattiprolu
Alexey Kardashevskiy [[email protected]] wrote:
<snip>| >| When exactly does a socket become a module? The SPAPR spec uses "sockets" here. | > | >I am trying to get the terminology too :-) Is socket a slot where a | >module is attached? | | Sorry, no idea.Ok.
| | | > | >I will change the variable name 'modules' to 'sockets'. | >| | >| | >| >+ modinfo->si[0].chips = chips; | >| >+ modinfo->si[0].cores_per_chip = cores / chips; | >| | >| | >| What if no "ibm,chip-id" was found and chips == 0? | > | >If we fail to readdir(xscom) or fail to read the 'ibm,chip-id', | >we return an error which we check above. | | | You assume that if there is /proc/device-tree, then there is always | "xscom@" but this might not be always the case, like PR KVM on | embedded PPC64.
Quoted 1 line
For ibm,chip-id, we do try to read the file (and eliminate duplicates
No, you do not try reading "ibm,chip-id" if there is no "xscom@" under /proc/device-tree, there is "continue":
+ if (strncmp(xscom_prefix, ent->d_name, strlen(xscom_prefix))) {
+ continue;
+ }
Quoted 2 lines
chip ids) If we can't read the file (
hash_table_add_contents()) we return an error, but will check again.
Signature · 1 line
Alexey
Alexey Kardashevskiy [[email protected]] wrote:
|
|
| No, you do not try reading "ibm,chip-id" if there is no "xscom@"
| under /proc/device-tree, there is "continue":
|
| + if (strncmp(xscom_prefix, ent->d_name, strlen(xscom_prefix))) {
| + continue;
| + }
| Ah, yes, Thanks,
Sukadev.
Quoted 3 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.18 of PAPR v2.7.
PAPR v2.7 isn't available publically. For upstream patches, please reference LoPAPR instead (where it's section 7.3.16.17 AFAICT).
Quoted 10 lines
We walk the
/proc/device-treeto determine the number of chips, cores and modules 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, but we should determine that dynamically somehow later.Thanks to input from Nishanth Aravamudan and Alexey Kardashevsk.
Signed-off-by Sukadev Bhattiprolu <[email protected]>
This isn't ready to go yet - you need to put some more consideration into the uncommon cases: PR KVM, TCG and non-Power hosts.
Quoted 46 lines
---
Changelog[v2]:
[Alexey Kardashevsk] 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/Makefile.objs | 1 + hw/ppc/spapr_rtas.c | 35 +++++++ hw/ppc/spapr_rtas_modinfo.c | 230 ++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas_modinfo.h | 12 +++ include/hw/ppc/spapr.h | 1 + 5 files changed, 279 insertions(+) create mode 100644 hw/ppc/spapr_rtas_modinfo.c create mode 100644 hw/ppc/spapr_rtas_modinfo.hhw/ppc/Makefile.objs +1
-0@@ -4,6 +4,7 @@ obj-y += ppc.o ppc_booke.o obj-$(CONFIG_PSERIES) += spapr.o spapr_vio.o spapr_events.o obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o +obj-$(CONFIG_PSERIES) += spapr_rtas_modinfo.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endifhw/ppc/spapr_rtas.c +2
-0@@ -34,6 +34,8 @@#include "hw/ppc/spapr.h" #include "hw/ppc/spapr_vio.h" #include "qapi-event.h" + +#include "spapr_rtas_modinfo.h" #include "hw/boards.h" #include <libfdt.h> @@ -240,6 +242,39 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,target_ulong ret =RTAS_OUT_SUCCESS ;
hw/ppc/spapr_rtas.c static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, · line 253
Quoted 10 lines
hw/ppc/spapr_rtas.c +9
-0switch (parameter) { +case RTAS_SYSPARM_PROCESSOR_MODULE_INFO : { +int i; +int offset =0 ; +int size; +struct rtas_module_info modinfo; + +if (rtas_get_module_info (&modinfo)) { +break ; + }
So, you handle the variable size of this structure before sending it to the guest, but you don't handle it in allocation of the structure right here. You'll get away with that because for now you only ever have one entry in the sockets array, but it's a bit icky.
hw/ppc/spapr_rtas.c static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, · line 256
Quoted 3 lines
hw/ppc/spapr_rtas.c +3
-0+ + size =sizeof (modinfo); + size += (modinfo.module_types -1 ) *sizeof (struct rtas_socket_info );
More seriously, this calculation will break horribly if you change the size of the array in struct rtas_module_info.
Quoted 56 lines
hw/ppc/spapr_rtas.c +20
-0+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,"hw/ppc/spapr_rtas_modinfo.c new file +27
-0@@ -0,0 +1,230 @@ +/* +* QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator +* +* Hypercall based emulated RTAS +* +* Copyright (c) 2015 Sukadev Bhattiprolu, IBM Corporation. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +* +*/ +#include <stdio.h>
hw/ppc/spapr_rtas_modinfo.c line 37
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+#include <dirent.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <errno.h> + +#include <glib.h> +#include "spapr_rtas_modinfo.h" +#include "qemu/error-report.h" +#include "qemu/bswap.h"
This entirely file assumes that (a) you have a ppc64 Linux host, which may not be true, and (b) that it's ok to expose host details to the guest.
Quoted 22 lines
hw/ppc/spapr_rtas_modinfo.c new file +22
-0+static int file_read_buf (char *file_name,char *buf,int len) +{ +int rc; +FILE *fp; + + fp =fopen (file_name,"r" ); +if (!fp) { +error_report ("%s: Error opening %s\n" , __func__, file_name); +return -1 ; + } + + rc =fread (buf,1 , len, fp); +fclose (fp); + +if (rc != len) { +return -1 ; + } + +return 0 ; +} + +/*
hw/ppc/spapr_rtas_modinfo.c line 70
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+* Read an identifier from the file @path and add the identifier +* to the hash table @gt unless its already in the table. +*/ +static int hash_table_add_contents (GHashTable *gt,char *path) +{ +int idx; +char buf[16 ]; +int *key; + +if (file_read_buf (path, buf,sizeof (int ))) {
If you're just reading sizeof(int), why is the buf 16 bytes? You should allocate buf to be the right size and use sizeof(buf).
Also since this is a value you're getting directly from externally, you should use a fixed width type, rather than 'int'.
hw/ppc/spapr_rtas_modinfo.c line 74
Quoted 4 lines
hw/ppc/spapr_rtas_modinfo.c new file +4
-0+return -1 ; + } + + idx =ldl_be_p (buf);
Easier to use the 'beNN_to_cpu' functions than ldl_be here.
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+if (g_hash_table_contains (gt, &idx)) { +return 0 ; + } + + key =g_malloc (sizeof (int )); + + *key = idx; +if (!g_hash_table_insert (gt, key,NULL )) { +error_report ("Unable to insert key %d into chips hash table\n" , idx); +g_free (key);
hw/ppc/spapr_rtas_modinfo.c line 95
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+return -1 ; + } + +return 0 ; +} + +/* +* Each core in the system is represented by a directory with the +* prefix 'PowerPC,POWER' in the directory /proc/device-tree/cpus/. +* Process that directory and count the number of cores in the system.
True on IBM POWER systems, but not necessarily everywhere - e.g. PR KVM on an embedded PowerPC host.
Quoted 4 lines
hw/ppc/spapr_rtas_modinfo.c new file +4
-0+*/ +static int count_cores (int *num_cores) +{ +int rc;
hw/ppc/spapr_rtas_modinfo.c line 109
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+DIR *dir; +struct dirent *ent; +const char *cpus_dir ="/proc/device-tree/cpus" ; +const char *ppc_prefix ="PowerPC,POWER" ; + + dir =opendir (cpus_dir); +if (!dir) { +error_report ("Unable to open %s, error %d\n" , cpus_dir, errno); +return -1 ; + }
You could probably do this more simply with glob(3).
Quoted 24 lines
hw/ppc/spapr_rtas_modinfo.c new file +24
-0+ *num_cores =0 ; +while (1 ) { + errno =0 ; + ent =readdir (dir); +if (!ent) { +break ; + } + +if (!strncmp (ppc_prefix, ent->d_name,strlen (ppc_prefix))) { + (*num_cores)++; + } + } + + rc =0 ; +if (errno) { + rc =-1 ; + } + +closedir (dir); +return rc; +} + +/* +* Each module's (aka socket's) id is contained in the 'ibm,hw-module-id'
hw/ppc/spapr_rtas_modinfo.c line 144
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+* file in the "xscom" directory (/proc/device-tree/xscom*). Similarly each +* chip's id is contained in the 'ibm,chip-id' file in the xscom directory. +* +* A module can contain more than one chip and a chip can contain more +* than one core. So there are likely to be duplicates in the module +* and chip identifiers (i.e more than one xscom directory can contain +* the same module/chip id). +* +* Search the xscom directories and count the number of _UNIQUE_ module +* and chip identifiers in the system.
There's no direct way to go from a core
(i.e. /proc/device-tree/cpus/cpu@NNN) to the corresponding chip and/or module?
Quoted 17 lines
hw/ppc/spapr_rtas_modinfo.c new file +17
-0+*/ +static int count_modules_chips (int *num_modules,int *num_chips) +{ +int rc; +DIR *dir; +struct dirent *ent; +char path[PATH_MAX ]; +const char *xscom_dir ="/proc/device-tree" ; +const char *xscom_prefix ="xscom@" ; +GHashTable *chips_tbl, *modules_tbl; + + dir =opendir (xscom_dir); +if (!dir) { +error_report ("Unable to open %s, error %d\n" , xscom_dir, errno); +return -1 ; + } +
hw/ppc/spapr_rtas_modinfo.c line 171
Quoted 10 lines
hw/ppc/spapr_rtas_modinfo.c new file +10
-0+ modules_tbl =g_hash_table_new_full (g_int_hash, g_int_equal, g_free,NULL ); + chips_tbl =g_hash_table_new_full (g_int_hash, g_int_equal, g_free,NULL ); + + rc =-1 ; +while (1 ) { + errno =0 ; + ent =readdir (dir); +if (!ent) { +break ; + }
Again glob(3) could simplify this.
Quoted 65 lines
hw/ppc/spapr_rtas_modinfo.c new file +59
-0+ +if (strncmp (xscom_prefix, ent->d_name,strlen (xscom_prefix))) { +continue ; + } + +sprintf (path,"%s/%s/ibm,chip-id" , xscom_dir, ent->d_name); +if (hash_table_add_contents (chips_tbl, path)) { + goto cleanup; + } + +sprintf (path,"%s/%s/ibm,hw-module-id" , xscom_dir, ent->d_name); +if (hash_table_add_contents (modules_tbl, path)) { + goto cleanup; + } + } + +if (errno) { + goto cleanup; + } + + *num_modules =g_hash_table_size (modules_tbl); + *num_chips =g_hash_table_size (chips_tbl); + rc =0 ; + +cleanup: +g_hash_table_remove_all (modules_tbl); +g_hash_table_destroy (modules_tbl); + +g_hash_table_remove_all (chips_tbl); +g_hash_table_destroy (chips_tbl); + +closedir (dir); + +return rc; +} + +int rtas_get_module_info (struct rtas_module_info *modinfo) +{ +int cores; +int chips; +int modules; + +memset (modinfo,0 ,sizeof (struct rtas_module_info )); + +if (count_modules_chips (&modules, &chips) ||count_cores (&cores)) { +return -1 ; + } + +/* +* TODO: Hard code number of module_types for now till +* we figure out how to determine it dynamically. +*/ + modinfo->module_types =1 ; + modinfo->si[0 ].sockets = modules; + modinfo->si[0 ].chips = chips; + modinfo->si[0 ].cores_per_chip = cores / chips; + +return 0 ; +}hw/ppc/spapr_rtas_modinfo.h new file +0
-0
hw/ppc/spapr_rtas_modinfo.h line 9
Quoted 9 lines
hw/ppc/spapr_rtas_modinfo.h new file +9
-0@@ -0,0 +1,12 @@ + +struct rtas_socket_info { +unsigned short sockets; +unsigned short chips; +unsigned short cores_per_chip; +}; +struct rtas_module_info { +unsigned short module_types; +struct rtas_socket_info si[1 ];
You probably want a "MAX_MODULE_TYPES" #define or similar instead of harcoding this to 1.
Quoted 15 lines
hw/ppc/spapr_rtas_modinfo.h new file +3
-0+}; + +extern int rtas_get_module_info (struct rtas_module_info *topo);include/hw/ppc/spapr.h +1
-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
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
David Gibson [[email protected]] wrote:
| On Wed, Nov 04, 2015 at 03:06:05PM -0800, Sukadev Bhattiprolu 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.18 of PAPR v2.7. | | PAPR v2.7 isn't available publically. For upstream patches, please | reference LoPAPR instead (where it's section 7.3.16.17 AFAICT).
Ok.
| | > We walk the /proc/device-tree to determine the number of chips, cores and | > modules 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, but we should determine | > that dynamically somehow later. | > | > Thanks to input from Nishanth Aravamudan and Alexey Kardashevsk. | > | > Signed-off-by: Sukadev Bhattiprolu <[email protected]> | | This isn't ready to go yet - you need to put some more consideration | into the uncommon cases: PR KVM, TCG and non-Power hosts.
Ok. Is there a we can make this code applicable only a Powerpc host? (would moving this code to target-ppc/kvm.c do that?)
|
| > ---
| > Changelog[v2]:
| > [Alexey Kardashevsk] 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/Makefile.objs | 1 +
| > hw/ppc/spapr_rtas.c | 35 +++++++
| > hw/ppc/spapr_rtas_modinfo.c | 230 ++++++++++++++++++++++++++++++++++++++++++++
| > hw/ppc/spapr_rtas_modinfo.h | 12 +++
| > include/hw/ppc/spapr.h | 1 +
| > 5 files changed, 279 insertions(+)
| > create mode 100644 hw/ppc/spapr_rtas_modinfo.c
| > create mode 100644 hw/ppc/spapr_rtas_modinfo.h
| >
| > diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs
| > index c1ffc77..57c6b02 100644
| > --- a/hw/ppc/Makefile.objs
| > +++ b/hw/ppc/Makefile.objs
| > @@ -4,6 +4,7 @@ obj-y += ppc.o ppc_booke.o
| > obj-$(CONFIG_PSERIES) += spapr.o spapr_vio.o spapr_events.o
| > obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o
| > obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o
| > +obj-$(CONFIG_PSERIES) += spapr_rtas_modinfo.o
| > ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy)
| > obj-y += spapr_pci_vfio.o
| > endif
| > diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
| > index 34b12a3..41fd8a6 100644
| > --- a/hw/ppc/spapr_rtas.c
| > +++ b/hw/ppc/spapr_rtas.c
| > @@ -34,6 +34,8 @@
| > #include "hw/ppc/spapr.h"
| > #include "hw/ppc/spapr_vio.h"
| > #include "qapi-event.h"
| > +
| > +#include "spapr_rtas_modinfo.h"
| > #include "hw/boards.h"
| >
| > #include <libfdt.h>
| > @@ -240,6 +242,39 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,
| > target_ulong ret = RTAS_OUT_SUCCESS;
| >
| > switch (parameter) {
| > + case RTAS_SYSPARM_PROCESSOR_MODULE_INFO: {
| > + int i;
| > + int offset = 0;
| > + int size;
| > + struct rtas_module_info modinfo;
| > +
| > + if (rtas_get_module_info(&modinfo)) {
| > + break;
| > + }
|
| So, you handle the variable size of this structure before sending it
| to the guest, but you don't handle it in allocation of the structure
| right here. You'll get away with that because for now you only ever
| have one entry in the sockets array, but it's a bit icky.Can we assume that the size is static for now...
| | > + | > + size = sizeof(modinfo); | > + size += (modinfo.module_types - 1) * sizeof(struct rtas_socket_info); | | More seriously, this calculation will break horribly if you change the | size of the array in struct rtas_module_info.
and just set 'size' to sizeof(modinfo)?.
|
| > + 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/hw/ppc/spapr_rtas_modinfo.c b/hw/ppc/spapr_rtas_modinfo.c
| > new file mode 100644
| > index 0000000..068fc2c
| > --- /dev/null
| > +++ b/hw/ppc/spapr_rtas_modinfo.c
| > @@ -0,0 +1,230 @@
| > +/*
| > + * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator
| > + *
| > + * Hypercall based emulated RTAS
| > + *
| > + * Copyright (c) 2015 Sukadev Bhattiprolu, IBM Corporation.
| > + *
| > + * Permission is hereby granted, free of charge, to any person obtaining a copy
| > + * of this software and associated documentation files (the "Software"), to deal
| > + * in the Software without restriction, including without limitation the rights
| > + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
| > + * copies of the Software, and to permit persons to whom the Software is
| > + * furnished to do so, subject to the following conditions:
| > + *
| > + * The above copyright notice and this permission notice shall be included in
| > + * all copies or substantial portions of the Software.
| > + *
| > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
| > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
| > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
| > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
| > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
| > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
| > + * THE SOFTWARE.
| > + *
| > + */
| > +#include <stdio.h>
| > +#include <dirent.h>
| > +#include <sys/types.h>
| > +#include <sys/stat.h>
| > +#include <string.h>
| > +#include <errno.h>
| > +
| > +#include <glib.h>
| > +#include "spapr_rtas_modinfo.h"
| > +#include "qemu/error-report.h"
| > +#include "qemu/bswap.h"
|
| This entirely file assumes that (a) you have a ppc64 Linux host, which
| may not be true, and (b) that it's ok to expose host details to the guest.Is there a way we can skip/ignore this code if not on a ppc64 Linux host?
Are there steps I should take on other hosts to not expose host details to the guests?
|
| > +static int file_read_buf(char *file_name, char *buf, int len)
| > +{
| > + int rc;
| > + FILE *fp;
| > +
| > + fp = fopen(file_name, "r");
| > + if (!fp) {
| > + error_report("%s: Error opening %s\n", __func__, file_name);
| > + return -1;
| > + }
| > +
| > + rc = fread(buf, 1, len, fp);
| > + fclose(fp);
| > +
| > + if (rc != len) {
| > + return -1;
| > + }
| > +
| > + return 0;
| > +}
| > +
| > +/*
| > + * Read an identifier from the file @path and add the identifier
| > + * to the hash table @gt unless its already in the table.
| > + */
| > +static int hash_table_add_contents(GHashTable *gt, char *path)
| > +{
| > + int idx;
| > + char buf[16];
| > + int *key;
| > +
| > + if (file_read_buf(path, buf, sizeof(int))) {
|
| If you're just reading sizeof(int), why is the buf 16 bytes? You
| should allocate buf to be the right size and use sizeof(buf).
|
| Also since this is a value you're getting directly from externally,
| you should use a fixed width type, rather than 'int'.Maybe uint32_t?
| | > + return -1; | > + } | > + | > + idx = ldl_be_p(buf); | | Easier to use the 'beNN_to_cpu' functions than ldl_be here.
Ok.
|
| > + if (g_hash_table_contains(gt, &idx)) {
| > + return 0;
| > + }
| > +
| > + key = g_malloc(sizeof(int));
| > +
| > + *key = idx;
| > + if (!g_hash_table_insert(gt, key, NULL)) {
| > + error_report("Unable to insert key %d into chips hash table\n", idx);
| > + g_free(key);
| > + return -1;
| > + }
| > +
| > + return 0;
| > +}
| > +
| > +/*
| > + * Each core in the system is represented by a directory with the
| > + * prefix 'PowerPC,POWER' in the directory /proc/device-tree/cpus/.
| > + * Process that directory and count the number of cores in the system.
|
| True on IBM POWER systems, but not necessarily everywhere - e.g. PR
| KVM on an embedded PowerPC host.What is PR KVM?
|
| > + */
| > +static int count_cores(int *num_cores)
| > +{
| > + int rc;
| > + DIR *dir;
| > + struct dirent *ent;
| > + const char *cpus_dir = "/proc/device-tree/cpus";
| > + const char *ppc_prefix = "PowerPC,POWER";
| > +
| > + dir = opendir(cpus_dir);
| > + if (!dir) {
| > + error_report("Unable to open %s, error %d\n", cpus_dir, errno);
| > + return -1;
| > + }
|
| You could probably do this more simply with glob(3).Agree, it simplifiies code a lot. Thanks.
|
| > + *num_cores = 0;
| > + while (1) {
| > + errno = 0;
| > + ent = readdir(dir);
| > + if (!ent) {
| > + break;
| > + }
| > +
| > + if (!strncmp(ppc_prefix, ent->d_name, strlen(ppc_prefix))) {
| > + (*num_cores)++;
| > + }
| > + }
| > +
| > + rc = 0;
| > + if (errno) {
| > + rc = -1;
| > + }
| > +
| > + closedir(dir);
| > + return rc;
| > +}
| > +
| > +/*
| > + * Each module's (aka socket's) id is contained in the 'ibm,hw-module-id'
| > + * file in the "xscom" directory (/proc/device-tree/xscom*). Similarly each
| > + * chip's id is contained in the 'ibm,chip-id' file in the xscom directory.
| > + *
| > + * A module can contain more than one chip and a chip can contain more
| > + * than one core. So there are likely to be duplicates in the module
| > + * and chip identifiers (i.e more than one xscom directory can contain
| > + * the same module/chip id).
| > + *
| > + * Search the xscom directories and count the number of _UNIQUE_ module
| > + * and chip identifiers in the system.
|
| There's no direct way to go from a core
| (i.e. /proc/device-tree/cpus/cpu@NNN) to the corresponding chip and/or
| module?Yes, it would logical to find the chip and module from the core :-)
While 'ibm,chip-id' is in the core dir (/proc/device-tree/cpus/PowerPC,*/), the 'ibm,hw-module-id' is not there (on my Tuleta system). Maybe the 'ibm,hw-module-id' will be added in the future?
I am using the xscom node to be consistent in counting chips and modules.
|
| > + */
| > +static int count_modules_chips(int *num_modules, int *num_chips)
| > +{
| > + int rc;
| > + DIR *dir;
| > + struct dirent *ent;
| > + char path[PATH_MAX];
| > + const char *xscom_dir = "/proc/device-tree";
| > + const char *xscom_prefix = "xscom@";
| > + GHashTable *chips_tbl, *modules_tbl;
| > +
| > + dir = opendir(xscom_dir);
| > + if (!dir) {
| > + error_report("Unable to open %s, error %d\n", xscom_dir, errno);
| > + return -1;
| > + }
| > +
| > + modules_tbl = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
| > + chips_tbl = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
| > +
| > + rc = -1;
| > + while (1) {
| > + errno = 0;
| > + ent = readdir(dir);
| > + if (!ent) {
| > + break;
| > + }
|
| Again glob(3) could simplify this.Agree.
|
| > +
| > + if (strncmp(xscom_prefix, ent->d_name, strlen(xscom_prefix))) {
| > + continue;
| > + }
| > +
| > + sprintf(path, "%s/%s/ibm,chip-id", xscom_dir, ent->d_name);
| > + if (hash_table_add_contents(chips_tbl, path)) {
| > + goto cleanup;
| > + }
| > +
| > + sprintf(path, "%s/%s/ibm,hw-module-id", xscom_dir, ent->d_name);
| > + if (hash_table_add_contents(modules_tbl, path)) {
| > + goto cleanup;
| > + }
| > + }
| > +
| > + if (errno) {
| > + goto cleanup;
| > + }
| > +
| > + *num_modules = g_hash_table_size(modules_tbl);
| > + *num_chips = g_hash_table_size(chips_tbl);
| > + rc = 0;
| > +
| > +cleanup:
| > + g_hash_table_remove_all(modules_tbl);
| > + g_hash_table_destroy(modules_tbl);
| > +
| > + g_hash_table_remove_all(chips_tbl);
| > + g_hash_table_destroy(chips_tbl);
| > +
| > + closedir(dir);
| > +
| > + return rc;
| > +}
| > +
| > +int rtas_get_module_info(struct rtas_module_info *modinfo)
| > +{
| > + int cores;
| > + int chips;
| > + int modules;
| > +
| > + memset(modinfo, 0, sizeof(struct rtas_module_info));
| > +
| > + if (count_modules_chips(&modules, &chips) || count_cores(&cores)) {
| > + return -1;
| > + }
| > +
| > + /*
| > + * TODO: Hard code number of module_types for now till
| > + * we figure out how to determine it dynamically.
| > + */
| > + modinfo->module_types = 1;
| > + modinfo->si[0].sockets = modules;
| > + modinfo->si[0].chips = chips;
| > + modinfo->si[0].cores_per_chip = cores / chips;
| > +
| > + return 0;
| > +}
| > diff --git a/hw/ppc/spapr_rtas_modinfo.h b/hw/ppc/spapr_rtas_modinfo.h
| > new file mode 100644
| > index 0000000..356a2b5
| > --- /dev/null
| > +++ b/hw/ppc/spapr_rtas_modinfo.h
| > @@ -0,0 +1,12 @@
| > +
| > +struct rtas_socket_info {
| > + unsigned short sockets;
| > + unsigned short chips;
| > + unsigned short cores_per_chip;
| > +};
| > +struct rtas_module_info {
| > + unsigned short module_types;
| > + struct rtas_socket_info si[1];
|
| You probably want a "MAX_MODULE_TYPES" #define or similar instead of
| harcoding this to 1.Agree.
| | > +}; | > + | > +extern int rtas_get_module_info(struct rtas_module_info *topo); | > diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h | > index 5baa906..cfe7fa2 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 | | -- | 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
On 10/11/15 05:22, Sukadev Bhattiprolu wrote:
[...]
Quoted 12 lines
| > +static int file_read_buf(char *file_name, char *buf, int len)
| > +{
| > + int rc;
| > + FILE *fp;
| > +
| > + fp = fopen(file_name, "r");
| > + if (!fp) {
| > + error_report("%s: Error opening %s\n", __func__, file_name);
| > + return -1;
| > + }
| > +
| > + rc = fread(buf, 1, len, fp);Quoted 8 lines
| > + fclose(fp);
| > +
| > + if (rc != len) {
| > + return -1;
| > + }
| > +
| > + return 0;
| > +}Could you maybe use g_file_get_contents() instead?
Quoted 9 lines
| > +/* | > + * Each core in the system is represented by a directory with the | > + * prefix 'PowerPC,POWER' in the directory /proc/device-tree/cpus/. | > + * Process that directory and count the number of cores in the system. | | True on IBM POWER systems, but not necessarily everywhere - e.g. PR | KVM on an embedded PowerPC host.What is PR KVM?
On PPC, there are multiple kinds of KVM kernel modules, e.g. KVM-HV and KVM-PR (and further implementations for embedded PPCs, too). KVM-HV is using the hypervisor hardware feature of the current POWER7 and POWER8 chips, while KVM-PR is using the PRoblem state to emulate a virtual machine. KVM-PR thus also works on older PPC hardware.
So there are multiple PPC environments where QEMU can run on, and you must not assume that you always have nodes like "PowerPC,POWER" in the device tree.
(BTW, you can also build kernels without the /proc/device-tree file system as far as I know ... so you never should fully rely on that without a fallback strategy)
Thomas
Thomas Huth [[email protected]] wrote:
| On 10/11/15 05:22, Sukadev Bhattiprolu wrote:
| [...]
| > | > +static int file_read_buf(char *file_name, char *buf, int len)
| > | > +{
| > | > + int rc;
| > | > + FILE *fp;
| > | > +
| > | > + fp = fopen(file_name, "r");
| > | > + if (!fp) {
| > | > + error_report("%s: Error opening %s\n", __func__, file_name);
| > | > + return -1;
| > | > + }
| > | > +
| > | > + rc = fread(buf, 1, len, fp);
| > | > + fclose(fp);
| > | > +
| > | > + if (rc != len) {
| > | > + return -1;
| > | > + }
| > | > +
| > | > + return 0;
| > | > +}
|
| Could you maybe use g_file_get_contents() instead?I guess I could, but since we are moving the new code to target-ppc/kvm.c, I found some existing code in kvmppc_read_int_cpu_dt() that I could reuse. Will post the patch later today, appreciate if you could double check.
| | > | > +/* | > | > + * Each core in the system is represented by a directory with the | > | > + * prefix 'PowerPC,POWER' in the directory /proc/device-tree/cpus/. | > | > + * Process that directory and count the number of cores in the system. | > | | > | True on IBM POWER systems, but not necessarily everywhere - e.g. PR | > | KVM on an embedded PowerPC host. | > | > What is PR KVM? | | On PPC, there are multiple kinds of KVM kernel modules, e.g. KVM-HV and | KVM-PR (and further implementations for embedded PPCs, too). KVM-HV is | using the hypervisor hardware feature of the current POWER7 and POWER8 | chips, while KVM-PR is using the PRoblem state to emulate a virtual | machine. KVM-PR thus also works on older PPC hardware.
Ok. Thanks for the detailed info.
| So there are multiple PPC environments where QEMU can run on, and you | must not assume that you always have nodes like "PowerPC,POWER" in the | device tree. | (BTW, you can also build kernels without the /proc/device-tree file | system as far as I know ... so you never should fully rely on that | without a fallback strategy)
Yes, I am now adding a stub for the #ifndef KVM in target-pcc/kvm_ppc.h. I am checking for zeros in chips, modules and cores but the new RTAS parameter will likely return zeroes on other targets for now - until we can figure out how PR KVM or the embedded PPCs can determine this RTAS info.
| Thomas
|
Quoted 26 lines · Sukadev Bhattiprolu
David Gibson [[email protected]] wrote:
| On Wed, Nov 04, 2015 at 03:06:05PM -0800, Sukadev Bhattiprolu 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.18 of PAPR v2.7. | | PAPR v2.7 isn't available publically. For upstream patches, please | reference LoPAPR instead (where it's section 7.3.16.17 AFAICT).Ok.
| | > We walk the /proc/device-tree to determine the number of chips, cores and | > modules 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, but we should determine | > that dynamically somehow later. | > | > Thanks to input from Nishanth Aravamudan and Alexey Kardashevsk. | > | > Signed-off-by: Sukadev Bhattiprolu <[email protected]> | | This isn't ready to go yet - you need to put some more consideration | into the uncommon cases: PR KVM, TCG and non-Power hosts.
Quoted 2 lines
Ok. Is there a we can make this code applicable only a Powerpc host? (would moving this code to
target-ppc/kvm.cdo that?)
Yes, moving it to target-ppc/kvm.c would mostly do that. You'd need some logic to make sure it fails gracefully in other cases, of course.
[snip]
Quoted 25 lines
| > switch (parameter) { | > + case RTAS_SYSPARM_PROCESSOR_MODULE_INFO: { | > + int i; | > + int offset = 0; | > + int size; | > + struct rtas_module_info modinfo; | > + | > + if (rtas_get_module_info(&modinfo)) { | > + break; | > + } | | So, you handle the variable size of this structure before sending it | to the guest, but you don't handle it in allocation of the structure | right here. You'll get away with that because for now you only ever | have one entry in the sockets array, but it's a bit icky.Can we assume that the size is static for now...
| | > + | > + size = sizeof(modinfo); | > + size += (modinfo.module_types - 1) * sizeof(struct rtas_socket_info); | | More seriously, this calculation will break horribly if you change the | size of the array in struct rtas_module_info.
Quoted 1 line
and just set 'size' to sizeof(modinfo)?.
For purposes of allocation you could just use a fixed size. But the guest might get confused by additional data beyond the declared size, so you do need to get the value correct that you send back to the guest.
[snip]
Quoted 17 lines
| > +/* | > + * Each module's (aka socket's) id is contained in the 'ibm,hw-module-id' | > + * file in the "xscom" directory (/proc/device-tree/xscom*). Similarly each | > + * chip's id is contained in the 'ibm,chip-id' file in the xscom directory. | > + * | > + * A module can contain more than one chip and a chip can contain more | > + * than one core. So there are likely to be duplicates in the module | > + * and chip identifiers (i.e more than one xscom directory can contain | > + * the same module/chip id). | > + * | > + * Search the xscom directories and count the number of _UNIQUE_ module | > + * and chip identifiers in the system. | | There's no direct way to go from a core | (i.e. /proc/device-tree/cpus/cpu@NNN) to the corresponding chip and/or | module?
Quoted 5 lines
Yes, it would logical to find the chip and module from the core :-)
While 'ibm,chip-id' is in the core dir (
/proc/device-tree/cpus/PowerPC,*/), the 'ibm,hw-module-id' is not there (on my Tuleta system). Maybe the 'ibm,hw-module-id' will be added in the future?
Hm, I see. Is there any device node that represents the "chip"?
Quoted 1 line
I am using the xscom node to be consistent in counting chips and modules.
The trouble with xscom is that it's extremely specific to the way the current IBM servers present things. It won't work on other types of host machine (which could happen with PR KVM), and could even break if IBM changes the way it organizes the SCOMs in a future machine.
Working from the nodes in /cpus still has some dependencies on IBM specific properties, but it's at least partially based on OF standards.
There's also another possible approach here, though I don't know if it will work. Instead of looking directly in the device tree, try to get the information from lscpu, or libosinfo. That would at least give you some hope of providing meaningful information on other host types.
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 98 lines · David Gibson
Quoted 26 lines · Sukadev Bhattiprolu
David Gibson [[email protected]] wrote:
| On Wed, Nov 04, 2015 at 03:06:05PM -0800, Sukadev Bhattiprolu 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.18 of PAPR v2.7. | | PAPR v2.7 isn't available publically. For upstream patches, please | reference LoPAPR instead (where it's section 7.3.16.17 AFAICT).Ok.
| | > We walk the /proc/device-tree to determine the number of chips, cores and | > modules 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, but we should determine | > that dynamically somehow later. | > | > Thanks to input from Nishanth Aravamudan and Alexey Kardashevsk. | > | > Signed-off-by: Sukadev Bhattiprolu <[email protected]> | | This isn't ready to go yet - you need to put some more consideration | into the uncommon cases: PR KVM, TCG and non-Power hosts.Quoted 2 lines
Ok. Is there a we can make this code applicable only a Powerpc host? (would moving this code to
target-ppc/kvm.cdo that?)Yes, moving it to
target-ppc/kvm.cwould mostly do that. You'd need some logic to make sure it fails gracefully in other cases, of course.[snip]
Quoted 25 lines
| > switch (parameter) { | > + case RTAS_SYSPARM_PROCESSOR_MODULE_INFO: { | > + int i; | > + int offset = 0; | > + int size; | > + struct rtas_module_info modinfo; | > + | > + if (rtas_get_module_info(&modinfo)) { | > + break; | > + } | | So, you handle the variable size of this structure before sending it | to the guest, but you don't handle it in allocation of the structure | right here. You'll get away with that because for now you only ever | have one entry in the sockets array, but it's a bit icky.Can we assume that the size is static for now...
| | > + | > + size = sizeof(modinfo); | > + size += (modinfo.module_types - 1) * sizeof(struct rtas_socket_info); | | More seriously, this calculation will break horribly if you change the | size of the array in struct rtas_module_info.Quoted 1 line
and just set 'size' to sizeof(modinfo)?.
For purposes of allocation you could just use a fixed size. But the guest might get confused by additional data beyond the declared size, so you do need to get the value correct that you send back to the guest.
[snip]
Quoted 17 lines
| > +/* | > + * Each module's (aka socket's) id is contained in the 'ibm,hw-module-id' | > + * file in the "xscom" directory (/proc/device-tree/xscom*). Similarly each | > + * chip's id is contained in the 'ibm,chip-id' file in the xscom directory. | > + * | > + * A module can contain more than one chip and a chip can contain more | > + * than one core. So there are likely to be duplicates in the module | > + * and chip identifiers (i.e more than one xscom directory can contain | > + * the same module/chip id). | > + * | > + * Search the xscom directories and count the number of _UNIQUE_ module | > + * and chip identifiers in the system. | | There's no direct way to go from a core | (i.e. /proc/device-tree/cpus/cpu@NNN) to the corresponding chip and/or | module?Quoted 5 lines
Yes, it would logical to find the chip and module from the core :-)
While 'ibm,chip-id' is in the core dir (
/proc/device-tree/cpus/PowerPC,*/), the 'ibm,hw-module-id' is not there (on my Tuleta system). Maybe the 'ibm,hw-module-id' will be added in the future?Hm, I see. Is there any device node that represents the "chip"?
Quoted 1 line
I am using the xscom node to be consistent in counting chips and modules.
The trouble with xscom is that it's extremely specific to the way the current IBM servers present things. It won't work on other types of host machine (which could happen with PR KVM), and could even break if IBM changes the way it organizes the SCOMs in a future machine.
Quoted 8 lines
Working from the nodes in /cpus still has some dependencies on IBM specific properties, but it's at least partially based on OF standards.
There's also another possible approach here, though I don't know if it will work. Instead of looking directly in the device tree, try to get the information from lscpu, or libosinfo. That would at least give you some hope of providing meaningful information on other host types.
Heh, the issue that is underlying all of this, is that lscpu itself is quite wrong.
On PAPR-compliant hypervisors (well, PowerVM, at least), the only supported means of determining the underlying hardware CPU information (which is what licensing models want in the end), is to use this RTAS call in an LPAR. lscpu is explicitly incorrect in these environments (it's values are "derived" from sysfs and some are adjusted to ensure the division of values works out).
So, we are trying to at least resolve what PowerKVM guest can see by supporting this RTAS call there. We should report *something* to the guest, if possible, and we can adjust what is reported to the guests as we go, from the host perspective.
I haven't followed along too closely in this thread, but woudl it be reasonable to only report this RTAS call as being supported under KVM? How are other RTAS calls dealt with for PR and non-IBM models currently?
-Nish
Quoted 111 lines · Nishanth Aravamudan
Quoted 98 lines · David Gibson
Quoted 26 lines · Sukadev Bhattiprolu
David Gibson [[email protected]] wrote:
| On Wed, Nov 04, 2015 at 03:06:05PM -0800, Sukadev Bhattiprolu 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.18 of PAPR v2.7. | | PAPR v2.7 isn't available publically. For upstream patches, please | reference LoPAPR instead (where it's section 7.3.16.17 AFAICT).Ok.
| | > We walk the /proc/device-tree to determine the number of chips, cores and | > modules 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, but we should determine | > that dynamically somehow later. | > | > Thanks to input from Nishanth Aravamudan and Alexey Kardashevsk. | > | > Signed-off-by: Sukadev Bhattiprolu <[email protected]> | | This isn't ready to go yet - you need to put some more consideration | into the uncommon cases: PR KVM, TCG and non-Power hosts.Quoted 2 lines
Ok. Is there a we can make this code applicable only a Powerpc host? (would moving this code to
target-ppc/kvm.cdo that?)Yes, moving it to
target-ppc/kvm.cwould mostly do that. You'd need some logic to make sure it fails gracefully in other cases, of course.[snip]
Quoted 25 lines
| > switch (parameter) { | > + case RTAS_SYSPARM_PROCESSOR_MODULE_INFO: { | > + int i; | > + int offset = 0; | > + int size; | > + struct rtas_module_info modinfo; | > + | > + if (rtas_get_module_info(&modinfo)) { | > + break; | > + } | | So, you handle the variable size of this structure before sending it | to the guest, but you don't handle it in allocation of the structure | right here. You'll get away with that because for now you only ever | have one entry in the sockets array, but it's a bit icky.Can we assume that the size is static for now...
| | > + | > + size = sizeof(modinfo); | > + size += (modinfo.module_types - 1) * sizeof(struct rtas_socket_info); | | More seriously, this calculation will break horribly if you change the | size of the array in struct rtas_module_info.Quoted 1 line
and just set 'size' to sizeof(modinfo)?.
For purposes of allocation you could just use a fixed size. But the guest might get confused by additional data beyond the declared size, so you do need to get the value correct that you send back to the guest.
[snip]
Quoted 17 lines
| > +/* | > + * Each module's (aka socket's) id is contained in the 'ibm,hw-module-id' | > + * file in the "xscom" directory (/proc/device-tree/xscom*). Similarly each | > + * chip's id is contained in the 'ibm,chip-id' file in the xscom directory. | > + * | > + * A module can contain more than one chip and a chip can contain more | > + * than one core. So there are likely to be duplicates in the module | > + * and chip identifiers (i.e more than one xscom directory can contain | > + * the same module/chip id). | > + * | > + * Search the xscom directories and count the number of _UNIQUE_ module | > + * and chip identifiers in the system. | | There's no direct way to go from a core | (i.e. /proc/device-tree/cpus/cpu@NNN) to the corresponding chip and/or | module?Quoted 5 lines
Yes, it would logical to find the chip and module from the core :-)
While 'ibm,chip-id' is in the core dir (
/proc/device-tree/cpus/PowerPC,*/), the 'ibm,hw-module-id' is not there (on my Tuleta system). Maybe the 'ibm,hw-module-id' will be added in the future?Hm, I see. Is there any device node that represents the "chip"?
Quoted 1 line
I am using the xscom node to be consistent in counting chips and modules.
The trouble with xscom is that it's extremely specific to the way the current IBM servers present things. It won't work on other types of host machine (which could happen with PR KVM), and could even break if IBM changes the way it organizes the SCOMs in a future machine.
Quoted 8 lines
Working from the nodes in /cpus still has some dependencies on IBM specific properties, but it's at least partially based on OF standards.
There's also another possible approach here, though I don't know if it will work. Instead of looking directly in the device tree, try to get the information from lscpu, or libosinfo. That would at least give you some hope of providing meaningful information on other host types.
Heh, the issue that is underlying all of this, is that
lscpuitself is quite wrong.
Quoted 6 lines
On PAPR-compliant hypervisors (well, PowerVM, at least), the only supported means of determining the underlying hardware CPU information (which is what licensing models want in the end), is to use this RTAS call in an LPAR.
lscpuis explicitly incorrect in these environments (it's values are "derived" from sysfs and some are adjusted to ensure the division of values works out).
So.. I'm not sure if you're just saying that lscpu is wrong because it gives the guest information, or because of other problems.
What I was suggesting is implementing the RTAS call so that it effectively lets the guest get lscpu information from the host.
Quoted 8 lines
So, we are trying to at least resolve what PowerKVM guest can see by supporting this RTAS call there. We should report *something* to the guest, if possible, and we can adjust what is reported to the guests as we go, from the host perspective.
I haven't followed along too closely in this thread, but woudl it be reasonable to only report this RTAS call as being supported under KVM?
Possibly, yes.
Quoted 2 lines
How are other RTAS calls dealt with for PR and non-IBM models currently?
Most of them still make sense in PR or TCG. A few do look in the host device tree, in which case they're likely to fail on non-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
Quoted 3 lines · David Gibson
Quoted 2 lines · Nishanth Aravamudan
Quoted 1 line · David Gibson
On Mon, Nov 09, 2015 at 08:22:32PM -0800, Sukadev Bhattiprolu wrote:
<snip>
Quoted 24 lines
Quoted 17 lines
Quoted 5 lines
The trouble with xscom is that it's extremely specific to the way the current IBM servers present things. It won't work on other types of host machine (which could happen with PR KVM), and could even break if IBM changes the way it organizes the SCOMs in a future machine.
Quoted 8 lines
Working from the nodes in /cpus still has some dependencies on IBM specific properties, but it's at least partially based on OF standards.
There's also another possible approach here, though I don't know if it will work. Instead of looking directly in the device tree, try to get the information from lscpu, or libosinfo. That would at least give you some hope of providing meaningful information on other host types.
Heh, the issue that is underlying all of this, is that
lscpuitself is quite wrong.Quoted 6 lines
On PAPR-compliant hypervisors (well, PowerVM, at least), the only supported means of determining the underlying hardware CPU information (which is what licensing models want in the end), is to use this RTAS call in an LPAR.
lscpuis explicitly incorrect in these environments (it's values are "derived" from sysfs and some are adjusted to ensure the division of values works out).
Quoted 2 lines
So.. I'm not sure if you're just saying that lscpu is wrong because it gives the guest information, or because of other problems.
lscpu's man-page specifically says that on virtualized platforms, the output may be inaccurate. And, in fact, on Power, in a KVM guest (and in a LPAR), lscpu is outputting the guest CPU information, which is completely fake. This is true on x86 KVM guests too, afaict.
*If* we have a valid RTAS implementation on PowerKVM (or under qemu generally), I think we can modify lscpu to do the right thing in at least those two environments.
Quoted 2 lines
What I was suggesting is implementing the RTAS call so that it effectively lets the guest get lscpu information from the host.
A bit of a chicken & egg problem, I'd say. The lscpu output in PowerNV is also wrong :)
Quoted 10 lines
Quoted 8 lines
So, we are trying to at least resolve what PowerKVM guest can see by supporting this RTAS call there. We should report *something* to the guest, if possible, and we can adjust what is reported to the guests as we go, from the host perspective.
I haven't followed along too closely in this thread, but woudl it be reasonable to only report this RTAS call as being supported under KVM?
Possibly, yes.
At least, as a first step, I guess.
Quoted 5 lines
Quoted 2 lines
How are other RTAS calls dealt with for PR and non-IBM models currently?
Most of them still make sense in PR or TCG. A few do look in the host device tree, in which case they're likely to fail on non-KVM.
Got it, thanks.
So my investigation overall led me to this set of conclusions:
1) Under PowerVM, we do not use this RTAS call, which is the only (as asserted by pHyp developers) valid way to get hardware information about the machine. Therefore, the PowerVM lscpu output is the "virtual" CPU information -- where cores are as defined by sharing of the L2-cache.
2) Under PowerKVM, we do not use this RTAS call, because it's not supported, and just spit out whatever the qemu topology is (which has no connection to the host (physical) CPU information).
--> so if we implement the RTAS call of some sort under PowerKVM, then
we can update lscpu to use that RTAS call.
3) Under PowerNV, there is a dependency on the hack that is ibm,chip-id from OPAL, which leads to twice as many sockets potentially being reported. lscpu also uses the sysfs files directly, which may or may not be the physical topology (I'm still tracking all of this down).
*Also* lscpu has no knowledge of offline/online CPUs, so as you online/offline CPUs, the output of lscpu starts to change.
I think what we eventually want to do is add some fields to lscpu to indicate the "physical" data vs. the "virtual" data.
-Nish
-Nish
Quoted 31 lines · Nishanth Aravamudan
Quoted 3 lines · David Gibson
Quoted 2 lines · Nishanth Aravamudan
Quoted 1 line · David Gibson
On Mon, Nov 09, 2015 at 08:22:32PM -0800, Sukadev Bhattiprolu wrote:
<snip>
Quoted 24 lines
Quoted 23 lines
Quoted 5 lines
The trouble with xscom is that it's extremely specific to the way the current IBM servers present things. It won't work on other types of host machine (which could happen with PR KVM), and could even break if IBM changes the way it organizes the SCOMs in a future machine.
Quoted 8 lines
Working from the nodes in /cpus still has some dependencies on IBM specific properties, but it's at least partially based on OF standards.
There's also another possible approach here, though I don't know if it will work. Instead of looking directly in the device tree, try to get the information from lscpu, or libosinfo. That would at least give you some hope of providing meaningful information on other host types.
Heh, the issue that is underlying all of this, is that
lscpuitself is quite wrong.On PAPR-compliant hypervisors (well, PowerVM, at least), the only supported means of determining the underlying hardware CPU information (which is what licensing models want in the end), is to use this RTAS call in an LPAR.
lscpuis explicitly incorrect in these environments (it's values are "derived" from sysfs and some are adjusted to ensure the division of values works out).
Quoted 7 lines
Quoted 2 lines
So.. I'm not sure if you're just saying that lscpu is wrong because it gives the guest information, or because of other problems.
lscpu's man-page specifically says that on virtualized platforms, the output may be inaccurate. And, in fact, on Power, in a KVM guest (and in a LPAR),lscpuis outputting the guest CPU information, which is completely fake. This is true on x86 KVM guests too, afaict.
Um.. yes, I was assuming lscpu reporting information about virtual cpus and sockets was intended and correct behaviour.
Quoted 9 lines
*If* we have a valid RTAS implementation on PowerKVM (or under qemu generally), I think we can modify
lscputo do the right thing in at least those two environments.Quoted 2 lines
What I was suggesting is implementing the RTAS call so that it effectively lets the guest get lscpu information from the host.
A bit of a chicken & egg problem, I'd say. The
lscpuoutput in PowerNV is also wrong :)
Ok.. why is it wrong in PowerNV? This sounds like something you'd want to fix anyway.
Quoted 23 lines
Quoted 10 lines
Quoted 8 lines
So, we are trying to at least resolve what PowerKVM guest can see by supporting this RTAS call there. We should report *something* to the guest, if possible, and we can adjust what is reported to the guests as we go, from the host perspective.
I haven't followed along too closely in this thread, but woudl it be reasonable to only report this RTAS call as being supported under KVM?
Possibly, yes.
At least, as a first step, I guess.
Quoted 5 lines
Quoted 2 lines
How are other RTAS calls dealt with for PR and non-IBM models currently?
Most of them still make sense in PR or TCG. A few do look in the host device tree, in which case they're likely to fail on non-KVM.
Got it, thanks.
So my investigation overall led me to this set of conclusions:
Quoted 8 lines
1) Under PowerVM, we do not use this RTAS call, which is the only (as asserted by pHyp developers) valid way to get hardware information about the machine. Therefore, the PowerVM
lscpuoutput is the "virtual" CPU information -- where cores are as defined by sharing of the L2-cache.2) Under PowerKVM, we do not use this RTAS call, because it's not supported, and just spit out whatever the qemu topology is (which has no connection to the host (physical) CPU information).
Right.. so does that mean nothing is using this call yet?
Quoted 2 lines
--> so if we implement the RTAS call of some sort under PowerKVM, then
we can updatelscputo use that RTAS call.
Yeah, I'm not convinced that's correct. Shouldn't lscpu return the virtual cpu information, at least by default.
Quoted 7 lines
3) Under PowerNV, there is a dependency on the hack that is ibm,chip-id from OPAL, which leads to twice as many sockets potentially being reported.
lscpualso uses the sysfs files directly, which may or may not be the physical topology (I'm still tracking all of this down).*Also*
lscpuhas no knowledge of offline/online CPUs, so as you online/offline CPUs, the output oflscpustarts to change.
Ah, true.
Quoted 2 lines
I think what we eventually want to do is add some fields to
lscputo indicate the "physical" data vs. the "virtual" data.
Ok.
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 35 lines · David Gibson
Quoted 34 lines · Nishanth Aravamudan
Quoted 3 lines · David Gibson
Quoted 2 lines · Nishanth Aravamudan
Quoted 1 line · David Gibson
On Mon, Nov 09, 2015 at 08:22:32PM -0800, Sukadev Bhattiprolu wrote:
<snip>
Quoted 26 lines
Quoted 17 lines
Quoted 5 lines
The trouble with xscom is that it's extremely specific to the way the current IBM servers present things. It won't work on other types of host machine (which could happen with PR KVM), and could even break if IBM changes the way it organizes the SCOMs in a future machine.
Quoted 8 lines
Working from the nodes in /cpus still has some dependencies on IBM specific properties, but it's at least partially based on OF standards.
There's also another possible approach here, though I don't know if it will work. Instead of looking directly in the device tree, try to get the information from lscpu, or libosinfo. That would at least give you some hope of providing meaningful information on other host types.
Heh, the issue that is underlying all of this, is that
lscpuitself is quite wrong.Quoted 6 lines
On PAPR-compliant hypervisors (well, PowerVM, at least), the only supported means of determining the underlying hardware CPU information (which is what licensing models want in the end), is to use this RTAS call in an LPAR.
lscpuis explicitly incorrect in these environments (it's values are "derived" from sysfs and some are adjusted to ensure the division of values works out).So.. I'm not sure if you're just saying that lscpu is wrong because it gives the guest information, or because of other problems.
Quoted 7 lines
Quoted 4 lines
lscpu's man-page specifically says that on virtualized platforms, the output may be inaccurate. And, in fact, on Power, in a KVM guest (and in a LPAR),lscpuis outputting the guest CPU information, which is completely fake. This is true on x86 KVM guests too, afaict.Um.. yes, I was assuming lscpu reporting information about virtual cpus and sockets was intended and correct behaviour.
"lscpu - display information about the CPU architecture"
but at the same time "lscpu gathers CPU architecture information
from sysfs and /proc/cpuinfo" which is explicitly logical (or
virtual).
but at the same time "There is also information about the CPU caches and cache sharing, family, model, bogoMIPS, byte order, and stepping." which seems rather physical to me.
So perhaps, as I kind of stumbled upon myself in my last reply, we should explicitly indicate the physical vs. virtual information.
I will raise this with the lscpu maintainer.
Quoted 4 lines
Quoted 4 lines
*If* we have a valid RTAS implementation on PowerKVM (or under qemu generally), I think we can modify
lscputo do the right thing in at least those two environments.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
What I was suggesting is implementing the RTAS call so that it effectively lets the guest get lscpu information from the host.
A bit of a chicken & egg problem, I'd say. The
lscpuoutput in PowerNV is also wrong :)Ok.. why is it wrong in PowerNV? This sounds like something you'd want to fix anyway.
Yes, I never said we wouldn't? It's wrong on PowerNV because chips are being counted as sockets, i.e. a 2 DCM system is being counted as a 4 socket system, rather than a 2 socket system.
Quoted 28 lines
Quoted 28 lines
Quoted 10 lines
Quoted 8 lines
So, we are trying to at least resolve what PowerKVM guest can see by supporting this RTAS call there. We should report *something* to the guest, if possible, and we can adjust what is reported to the guests as we go, from the host perspective.
I haven't followed along too closely in this thread, but woudl it be reasonable to only report this RTAS call as being supported under KVM?
Possibly, yes.
At least, as a first step, I guess.
Quoted 5 lines
Quoted 2 lines
How are other RTAS calls dealt with for PR and non-IBM models currently?
Most of them still make sense in PR or TCG. A few do look in the host device tree, in which case they're likely to fail on non-KVM.
Got it, thanks.
So my investigation overall led me to this set of conclusions:
1) Under PowerVM, we do not use this RTAS call, which is the only (as asserted by pHyp developers) valid way to get hardware information about the machine. Therefore, the PowerVM
lscpuoutput is the "virtual" CPU information -- where cores are as defined by sharing of the L2-cache.
Quoted 5 lines
Quoted 3 lines
2) Under PowerKVM, we do not use this RTAS call, because it's not supported, and just spit out whatever the qemu topology is (which has no connection to the host (physical) CPU information).
Right.. so does that mean nothing is using this call yet?
Correct.
Quoted 5 lines
Quoted 2 lines
--> so if we implement the RTAS call of some sort under PowerKVM, then
we can updatelscputo use that RTAS call.Yeah, I'm not convinced that's correct. Shouldn't lscpu return the virtual cpu information, at least by default.
I think it should return both. *cough* this is a request from your employer, actually *cough* :) For billing purposes, physical topology is apparently relevant, not virtual (which makes sense, I can make a KVM guest with 100 sockets, but I definitely shouldn't be billed for 100 sockets worth of RH seats, if the physical system only has 2 sockets).
Quoted 9 lines
Quoted 7 lines
3) Under PowerNV, there is a dependency on the hack that is ibm,chip-id from OPAL, which leads to twice as many sockets potentially being reported.
lscpualso uses the sysfs files directly, which may or may not be the physical topology (I'm still tracking all of this down).*Also*
lscpuhas no knowledge of offline/online CPUs, so as you online/offline CPUs, the output oflscpustarts to change.Ah, true.
Yeah, I'm still trying tofigure out the nuances of this out.
-Nish
Quoted 41 lines · Nishanth Aravamudan
Quoted 40 lines · David Gibson
Quoted 38 lines · Nishanth Aravamudan
Quoted 3 lines · David Gibson
Quoted 2 lines · Nishanth Aravamudan
Quoted 1 line · David Gibson
On Mon, Nov 09, 2015 at 08:22:32PM -0800, Sukadev Bhattiprolu wrote:
<snip>
Quoted 24 lines
Quoted 17 lines
Quoted 5 lines
The trouble with xscom is that it's extremely specific to the way the current IBM servers present things. It won't work on other types of host machine (which could happen with PR KVM), and could even break if IBM changes the way it organizes the SCOMs in a future machine.
Quoted 8 lines
Working from the nodes in /cpus still has some dependencies on IBM specific properties, but it's at least partially based on OF standards.
There's also another possible approach here, though I don't know if it will work. Instead of looking directly in the device tree, try to get the information from lscpu, or libosinfo. That would at least give you some hope of providing meaningful information on other host types.
Heh, the issue that is underlying all of this, is that
lscpuitself is quite wrong.Quoted 6 lines
On PAPR-compliant hypervisors (well, PowerVM, at least), the only supported means of determining the underlying hardware CPU information (which is what licensing models want in the end), is to use this RTAS call in an LPAR.
lscpuis explicitly incorrect in these environments (it's values are "derived" from sysfs and some are adjusted to ensure the division of values works out).Quoted 2 lines
So.. I'm not sure if you're just saying that lscpu is wrong because it gives the guest information, or because of other problems.
lscpu's man-page specifically says that on virtualized platforms, the output may be inaccurate. And, in fact, on Power, in a KVM guest (and in a LPAR),lscpuis outputting the guest CPU information, which is completely fake. This is true on x86 KVM guests too, afaict.
Quoted 4 lines
Quoted 2 lines
Um.. yes, I was assuming lscpu reporting information about virtual cpus and sockets was intended and correct behaviour.
"lscpu - display information about the CPU architecture"
Right, without qualification I'd take that as virtual architecture.
Quoted 7 lines
but at the same time "lscpu gathers CPU architecture information
from sysfs and/proc/cpuinfo" which is explicitly logical (or
virtual).but at the same time "There is also information about the CPU caches and cache sharing, family, model, bogoMIPS, byte order, and stepping." which seems rather physical to me.
bogomips and byte order are absolutely properties of a virtual cpu. As are family and model, really, since they're generally at least partially visible to a guest, and there may be some capacity for faking them (x86 is more flexible in this regard than Power). Stepping might be depending on exactly what level the system is virtualized at (it's not for the case of PAPR).
Cache info is probably purely physical but amongst everything else that's a property of the virtual cpu, I don't think that's an argument that lscpu should return host cpu information in general.
Quoted 15 lines
So perhaps, as I kind of stumbled upon myself in my last reply, we should explicitly indicate the physical vs. virtual information.
I will raise this with the lscpu maintainer.
Quoted 10 lines
Quoted 9 lines
*If* we have a valid RTAS implementation on PowerKVM (or under qemu generally), I think we can modify
lscputo do the right thing in at least those two environments.Quoted 2 lines
What I was suggesting is implementing the RTAS call so that it effectively lets the guest get lscpu information from the host.
A bit of a chicken & egg problem, I'd say. The
lscpuoutput in PowerNV is also wrong :)
Quoted 6 lines
Quoted 2 lines
Ok.. why is it wrong in PowerNV? This sounds like something you'd want to fix anyway.
Yes, I never said we wouldn't? It's wrong on PowerNV because chips are being counted as sockets, i.e. a 2 DCM system is being counted as a 4 socket system, rather than a 2 socket system.
Well, sure, but the fact that the tool for the job has a bug doesn't seem like a great reason to re-implement that tool directly in qemu.
I don't see any chicken and egg problem here the *powernv* lscpu has no dependency on the cpu hypercall information.
Quoted 39 lines
Quoted 28 lines
Quoted 28 lines
Quoted 10 lines
Quoted 8 lines
So, we are trying to at least resolve what PowerKVM guest can see by supporting this RTAS call there. We should report *something* to the guest, if possible, and we can adjust what is reported to the guests as we go, from the host perspective.
I haven't followed along too closely in this thread, but woudl it be reasonable to only report this RTAS call as being supported under KVM?
Possibly, yes.
At least, as a first step, I guess.
Quoted 5 lines
Quoted 2 lines
How are other RTAS calls dealt with for PR and non-IBM models currently?
Most of them still make sense in PR or TCG. A few do look in the host device tree, in which case they're likely to fail on non-KVM.
Got it, thanks.
So my investigation overall led me to this set of conclusions:
1) Under PowerVM, we do not use this RTAS call, which is the only (as asserted by pHyp developers) valid way to get hardware information about the machine. Therefore, the PowerVM
lscpuoutput is the "virtual" CPU information -- where cores are as defined by sharing of the L2-cache.Quoted 5 lines
Quoted 3 lines
2) Under PowerKVM, we do not use this RTAS call, because it's not supported, and just spit out whatever the qemu topology is (which has no connection to the host (physical) CPU information).
Right.. so does that mean nothing is using this call yet?
Correct.
Quoted 3 lines
Quoted 2 lines
--> so if we implement the RTAS call of some sort under PowerKVM, then
we can updatelscputo use that RTAS call.
Quoted 8 lines
Quoted 2 lines
Yeah, I'm not convinced that's correct. Shouldn't lscpu return the virtual cpu information, at least by default.
I think it should return both. *cough* this is a request from your employer, actually *cough* :) For billing purposes, physical topology is apparently relevant, not virtual (which makes sense, I can make a KVM guest with 100 sockets, but I definitely shouldn't be billed for 100 sockets worth of RH seats, if the physical system only has 2 sockets).
Well, ok. Do you have any contact information so I can find out internally what it is they actually need?
Quoted 14 lines
Quoted 9 lines
Quoted 7 lines
3) Under PowerNV, there is a dependency on the hack that is ibm,chip-id from OPAL, which leads to twice as many sockets potentially being reported.
lscpualso uses the sysfs files directly, which may or may not be the physical topology (I'm still tracking all of this down).*Also*
lscpuhas no knowledge of offline/online CPUs, so as you online/offline CPUs, the output oflscpustarts to change.Ah, true.
Yeah, I'm still trying tofigure out the nuances of this out.
-Nish
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 42 lines · David Gibson
Quoted 41 lines · Nishanth Aravamudan
Quoted 40 lines · David Gibson
Quoted 38 lines · Nishanth Aravamudan
Quoted 3 lines · David Gibson
Quoted 2 lines · Nishanth Aravamudan
Quoted 1 line · David Gibson
On Mon, Nov 09, 2015 at 08:22:32PM -0800, Sukadev Bhattiprolu wrote:
<snip>
Quoted 24 lines
Quoted 17 lines
Quoted 5 lines
The trouble with xscom is that it's extremely specific to the way the current IBM servers present things. It won't work on other types of host machine (which could happen with PR KVM), and could even break if IBM changes the way it organizes the SCOMs in a future machine.
Quoted 8 lines
Working from the nodes in /cpus still has some dependencies on IBM specific properties, but it's at least partially based on OF standards.
There's also another possible approach here, though I don't know if it will work. Instead of looking directly in the device tree, try to get the information from lscpu, or libosinfo. That would at least give you some hope of providing meaningful information on other host types.
Heh, the issue that is underlying all of this, is that
lscpuitself is quite wrong.Quoted 6 lines
On PAPR-compliant hypervisors (well, PowerVM, at least), the only supported means of determining the underlying hardware CPU information (which is what licensing models want in the end), is to use this RTAS call in an LPAR.
lscpuis explicitly incorrect in these environments (it's values are "derived" from sysfs and some are adjusted to ensure the division of values works out).Quoted 2 lines
So.. I'm not sure if you're just saying that lscpu is wrong because it gives the guest information, or because of other problems.
lscpu's man-page specifically says that on virtualized platforms, the output may be inaccurate. And, in fact, on Power, in a KVM guest (and in a LPAR),lscpuis outputting the guest CPU information, which is completely fake. This is true on x86 KVM guests too, afaict.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Um.. yes, I was assuming lscpu reporting information about virtual cpus and sockets was intended and correct behaviour.
"lscpu - display information about the CPU architecture"
Right, without qualification I'd take that as virtual architecture.
Ok, I did not. I suppose the manpage could be reviewed and/or updated.
Regardless, Suka has gotten a patch merged which at least for power, can display the physical information via lscpu, when the RTAS call is available.
Quoted 9 lines
Quoted 7 lines
but at the same time "lscpu gathers CPU architecture information
from sysfs and/proc/cpuinfo" which is explicitly logical (or
virtual).but at the same time "There is also information about the CPU caches and cache sharing, family, model, bogoMIPS, byte order, and stepping." which seems rather physical to me.
bogomips and byte order are absolutely properties of a virtual cpu.
I think the distinction to be made is they are *also* properties of a virtual CPU. That is, they are properties of both,and where they vary, it might be relevant to know both cases.
Quoted 33 lines
As are family and model, really, since they're generally at least partially visible to a guest, and there may be some capacity for faking them (x86 is more flexible in this regard than Power). Stepping might be depending on exactly what level the system is virtualized at (it's not for the case of PAPR).
Cache info is probably purely physical but amongst everything else that's a property of the virtual cpu, I don't think that's an argument that lscpu should return host cpu information in general.
Quoted 15 lines
So perhaps, as I kind of stumbled upon myself in my last reply, we should explicitly indicate the physical vs. virtual information.
I will raise this with the lscpu maintainer.
Quoted 10 lines
Quoted 9 lines
*If* we have a valid RTAS implementation on PowerKVM (or under qemu generally), I think we can modify
lscputo do the right thing in at least those two environments.Quoted 2 lines
What I was suggesting is implementing the RTAS call so that it effectively lets the guest get lscpu information from the host.
A bit of a chicken & egg problem, I'd say. The
lscpuoutput in PowerNV is also wrong :)Quoted 6 lines
Quoted 2 lines
Ok.. why is it wrong in PowerNV? This sounds like something you'd want to fix anyway.
Yes, I never said we wouldn't? It's wrong on PowerNV because chips are being counted as sockets, i.e. a 2 DCM system is being counted as a 4 socket system, rather than a 2 socket system.
Quoted 5 lines
Well, sure, but the fact that the tool for the job has a bug doesn't seem like a great reason to re-implement that tool directly in qemu.
I don't see any chicken and egg problem here the *powernv* lscpu has no dependency on the cpu hypercall information.
Maybe I'm mistaken, but I think we're simply talking at odds.
There are three cases to consider, which I feel like I've stated before:
1) PowerVM provides this information (# of physical socketc, etc) via an RTAS call.
2) PowerKVM does not currently provide it at all.
3) PowerNV provides it via lscpu and outputs incorrect information.
Suka is fixing 2) by adding the RTAS call to qemu. What the RTAS call uses to populate the data seems to be the root of the question. I guess you are suggesting use lscpu output from the PowerNV environment, even if it's wrong, and once it's right, it's all done for PowerKVM.
Suka is fixing 3) as well, via patches to lscpu, but as you've pointed out separately even in the qemu-side, it's not quite clear how to proceed in the best generic way.
Quoted 42 lines
Quoted 42 lines
Quoted 28 lines
Quoted 28 lines
Quoted 10 lines
Quoted 8 lines
So, we are trying to at least resolve what PowerKVM guest can see by supporting this RTAS call there. We should report *something* to the guest, if possible, and we can adjust what is reported to the guests as we go, from the host perspective.
I haven't followed along too closely in this thread, but woudl it be reasonable to only report this RTAS call as being supported under KVM?
Possibly, yes.
At least, as a first step, I guess.
Quoted 5 lines
Quoted 2 lines
How are other RTAS calls dealt with for PR and non-IBM models currently?
Most of them still make sense in PR or TCG. A few do look in the host device tree, in which case they're likely to fail on non-KVM.
Got it, thanks.
So my investigation overall led me to this set of conclusions:
1) Under PowerVM, we do not use this RTAS call, which is the only (as asserted by pHyp developers) valid way to get hardware information about the machine. Therefore, the PowerVM
lscpuoutput is the "virtual" CPU information -- where cores are as defined by sharing of the L2-cache.Quoted 5 lines
Quoted 3 lines
2) Under PowerKVM, we do not use this RTAS call, because it's not supported, and just spit out whatever the qemu topology is (which has no connection to the host (physical) CPU information).
Right.. so does that mean nothing is using this call yet?
Correct.
Quoted 5 lines
Quoted 2 lines
--> so if we implement the RTAS call of some sort under PowerKVM, then
we can updatelscputo use that RTAS call.Yeah, I'm not convinced that's correct. Shouldn't lscpu return the virtual cpu information, at least by default.
Quoted 8 lines
Quoted 5 lines
I think it should return both. *cough* this is a request from your employer, actually *cough* :) For billing purposes, physical topology is apparently relevant, not virtual (which makes sense, I can make a KVM guest with 100 sockets, but I definitely shouldn't be billed for 100 sockets worth of RH seats, if the physical system only has 2 sockets).
Well, ok. Do you have any contact information so I can find out internally what it is they actually need?
Yes, will send off-list.
-Nish
Quoted 48 lines · Nishanth Aravamudan
Quoted 47 lines · David Gibson
Quoted 45 lines · Nishanth Aravamudan
Quoted 35 lines · David Gibson
Quoted 34 lines · Nishanth Aravamudan
Quoted 3 lines · David Gibson
Quoted 2 lines · Nishanth Aravamudan
Quoted 1 line · David Gibson
On Mon, Nov 09, 2015 at 08:22:32PM -0800, Sukadev Bhattiprolu wrote:
<snip>
Quoted 26 lines
Quoted 17 lines
Quoted 5 lines
The trouble with xscom is that it's extremely specific to the way the current IBM servers present things. It won't work on other types of host machine (which could happen with PR KVM), and could even break if IBM changes the way it organizes the SCOMs in a future machine.
Quoted 8 lines
Working from the nodes in /cpus still has some dependencies on IBM specific properties, but it's at least partially based on OF standards.
There's also another possible approach here, though I don't know if it will work. Instead of looking directly in the device tree, try to get the information from lscpu, or libosinfo. That would at least give you some hope of providing meaningful information on other host types.
Heh, the issue that is underlying all of this, is that
lscpuitself is quite wrong.Quoted 6 lines
On PAPR-compliant hypervisors (well, PowerVM, at least), the only supported means of determining the underlying hardware CPU information (which is what licensing models want in the end), is to use this RTAS call in an LPAR.
lscpuis explicitly incorrect in these environments (it's values are "derived" from sysfs and some are adjusted to ensure the division of values works out).So.. I'm not sure if you're just saying that lscpu is wrong because it gives the guest information, or because of other problems.
Quoted 7 lines
Quoted 4 lines
lscpu's man-page specifically says that on virtualized platforms, the output may be inaccurate. And, in fact, on Power, in a KVM guest (and in a LPAR),lscpuis outputting the guest CPU information, which is completely fake. This is true on x86 KVM guests too, afaict.Um.. yes, I was assuming lscpu reporting information about virtual cpus and sockets was intended and correct behaviour.
"lscpu - display information about the CPU architecture"
Quoted 7 lines
Quoted 1 line
Right, without qualification I'd take that as virtual architecture.
Ok, I did not. I suppose the manpage could be reviewed and/or updated.
Regardless, Suka has gotten a patch merged which at least for power, can display the physical information via
lscpu, when the RTAS call is available.
Ok.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
but at the same time "lscpu gathers CPU architecture information
from sysfs and/proc/cpuinfo" which is explicitly logical (or
virtual).but at the same time "There is also information about the CPU caches and cache sharing, family, model, bogoMIPS, byte order, and stepping." which seems rather physical to me.
Quoted 5 lines
Quoted 1 line
bogomips and byte order are absolutely properties of a virtual cpu.
I think the distinction to be made is they are *also* properties of a virtual CPU. That is, they are properties of both,and where they vary, it might be relevant to know both cases.
No, they're really not.
Byte order isn't even really a property of the cpu at all, but of a particularly piece of software running on it. Bogomips is an internal parameter of the Linux kernel which depends (somewhat) on the CPU. To the guest kernel, the host bogomips is absolutely irrelevant.
Quoted 46 lines
Quoted 33 lines
As are family and model, really, since they're generally at least partially visible to a guest, and there may be some capacity for faking them (x86 is more flexible in this regard than Power). Stepping might be depending on exactly what level the system is virtualized at (it's not for the case of PAPR).
Cache info is probably purely physical but amongst everything else that's a property of the virtual cpu, I don't think that's an argument that lscpu should return host cpu information in general.
Quoted 15 lines
So perhaps, as I kind of stumbled upon myself in my last reply, we should explicitly indicate the physical vs. virtual information.
I will raise this with the lscpu maintainer.
Quoted 10 lines
Quoted 9 lines
*If* we have a valid RTAS implementation on PowerKVM (or under qemu generally), I think we can modify
lscputo do the right thing in at least those two environments.Quoted 2 lines
What I was suggesting is implementing the RTAS call so that it effectively lets the guest get lscpu information from the host.
A bit of a chicken & egg problem, I'd say. The
lscpuoutput in PowerNV is also wrong :)Quoted 6 lines
Quoted 2 lines
Ok.. why is it wrong in PowerNV? This sounds like something you'd want to fix anyway.
Yes, I never said we wouldn't? It's wrong on PowerNV because chips are being counted as sockets, i.e. a 2 DCM system is being counted as a 4 socket system, rather than a 2 socket system.
Quoted 5 lines
Well, sure, but the fact that the tool for the job has a bug doesn't seem like a great reason to re-implement that tool directly in qemu.
I don't see any chicken and egg problem here the *powernv* lscpu has no dependency on the cpu hypercall information.
Maybe I'm mistaken, but I think we're simply talking at odds.
There are three cases to consider, which I feel like I've stated before:
1) PowerVM provides this information (# of physical socketc, etc) via an RTAS call.
Quoted 8 lines
2) PowerKVM does not currently provide it at all.
3) PowerNV provides it via
lscpuand outputs incorrect information.Suka is fixing 2) by adding the RTAS call to qemu. What the RTAS call uses to populate the data seems to be the root of the question. I guess you are suggesting use
lscpuoutput from the PowerNV environment, even if it's wrong, and once it's right, it's all done for PowerKVM.
More or less, yes. It just seems more sensible to fix a mostly-right source of the information in the host, rather than to write a completely new implementation to gather the information.
Quoted 59 lines
Suka is fixing 3) as well, via patches to lscpu, but as you've pointed out separately even in the qemu-side, it's not quite clear how to proceed in the best generic way.
Quoted 42 lines
Quoted 42 lines
Quoted 28 lines
Quoted 28 lines
Quoted 10 lines
Quoted 8 lines
So, we are trying to at least resolve what PowerKVM guest can see by supporting this RTAS call there. We should report *something* to the guest, if possible, and we can adjust what is reported to the guests as we go, from the host perspective.
I haven't followed along too closely in this thread, but woudl it be reasonable to only report this RTAS call as being supported under KVM?
Possibly, yes.
At least, as a first step, I guess.
Quoted 5 lines
Quoted 2 lines
How are other RTAS calls dealt with for PR and non-IBM models currently?
Most of them still make sense in PR or TCG. A few do look in the host device tree, in which case they're likely to fail on non-KVM.
Got it, thanks.
So my investigation overall led me to this set of conclusions:
1) Under PowerVM, we do not use this RTAS call, which is the only (as asserted by pHyp developers) valid way to get hardware information about the machine. Therefore, the PowerVM
lscpuoutput is the "virtual" CPU information -- where cores are as defined by sharing of the L2-cache.Quoted 5 lines
Quoted 3 lines
2) Under PowerKVM, we do not use this RTAS call, because it's not supported, and just spit out whatever the qemu topology is (which has no connection to the host (physical) CPU information).
Right.. so does that mean nothing is using this call yet?
Correct.
Quoted 5 lines
Quoted 2 lines
--> so if we implement the RTAS call of some sort under PowerKVM, then
we can updatelscputo use that RTAS call.Yeah, I'm not convinced that's correct. Shouldn't lscpu return the virtual cpu information, at least by default.
Quoted 8 lines
Quoted 5 lines
I think it should return both. *cough* this is a request from your employer, actually *cough* :) For billing purposes, physical topology is apparently relevant, not virtual (which makes sense, I can make a KVM guest with 100 sockets, but I definitely shouldn't be billed for 100 sockets worth of RH seats, if the physical system only has 2 sockets).
Well, ok. Do you have any contact information so I can find out internally what it is they actually need?
Yes, will send off-list.
-Nish
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
David Gibson [[email protected]] wrote:
| On Mon, Nov 09, 2015 at 08:22:32PM -0800, Sukadev Bhattiprolu wrote: | > David Gibson [[email protected]] wrote: | > | On Wed, Nov 04, 2015 at 03:06:05PM -0800, Sukadev Bhattiprolu 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.18 of PAPR v2.7. | > | | > | PAPR v2.7 isn't available publically. For upstream patches, please | > | reference LoPAPR instead (where it's section 7.3.16.17 AFAICT). | > | > Ok. | > | > | | > | > We walk the /proc/device-tree to determine the number of chips, cores and | > | > modules 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, but we should determine | > | > that dynamically somehow later. | > | > | > | > Thanks to input from Nishanth Aravamudan and Alexey Kardashevsk. | > | > | > | > Signed-off-by: Sukadev Bhattiprolu <[email protected]> | > | | > | This isn't ready to go yet - you need to put some more consideration | > | into the uncommon cases: PR KVM, TCG and non-Power hosts. | > | > Ok. Is there a we can make this code applicable only a Powerpc host? | > (would moving this code to target-ppc/kvm.c do that?) | | Yes, moving it to target-ppc/kvm.c would mostly do that. You'd need | some logic to make sure it fails gracefully in other cases, of course.
Ok. I have added a stub under #ifndef KVM in target-ppc/kvm_ppc.h.
|
| [snip]
| > | > switch (parameter) {
| > | > + case RTAS_SYSPARM_PROCESSOR_MODULE_INFO: {
| > | > + int i;
| > | > + int offset = 0;
| > | > + int size;
| > | > + struct rtas_module_info modinfo;
| > | > +
| > | > + if (rtas_get_module_info(&modinfo)) {
| > | > + break;
| > | > + }
| > |
| > | So, you handle the variable size of this structure before sending it
| > | to the guest, but you don't handle it in allocation of the structure
| > | right here. You'll get away with that because for now you only ever
| > | have one entry in the sockets array, but it's a bit icky.
| >
| > Can we assume that the size is static for now...
| > |
| > | > +
| > | > + size = sizeof(modinfo);
| > | > + size += (modinfo.module_types - 1) * sizeof(struct rtas_socket_info);
| > |
| > | More seriously, this calculation will break horribly if you change the
| > | size of the array in struct rtas_module_info.
| >
| > and just set 'size' to sizeof(modinfo)?.
|
| For purposes of allocation you could just use a fixed size. But the
| guest might get confused by additional data beyond the declared size,
| so you do need to get the value correct that you send back to the guest.If we use a fixed size and memset the buffer to 0 and then set the values would that be sufficient?
| | [snip] | > | > +/* | > | > + * Each module's (aka socket's) id is contained in the 'ibm,hw-module-id' | > | > + * file in the "xscom" directory (/proc/device-tree/xscom*). Similarly each | > | > + * chip's id is contained in the 'ibm,chip-id' file in the xscom directory. | > | > + * | > | > + * A module can contain more than one chip and a chip can contain more | > | > + * than one core. So there are likely to be duplicates in the module | > | > + * and chip identifiers (i.e more than one xscom directory can contain | > | > + * the same module/chip id). | > | > + * | > | > + * Search the xscom directories and count the number of _UNIQUE_ module | > | > + * and chip identifiers in the system. | > | | > | There's no direct way to go from a core | > | (i.e. /proc/device-tree/cpus/cpu@NNN) to the corresponding chip and/or | > | module? | > | > Yes, it would logical to find the chip and module from the core :-) | > | > While 'ibm,chip-id' is in the core dir (/proc/device-tree/cpus/PowerPC,*/), | > the 'ibm,hw-module-id' is not there (on my Tuleta system). Maybe the | > 'ibm,hw-module-id' will be added in the future? | | Hm, I see. Is there any device node that represents the "chip"?
AFAICT, in the current skiboot code, xscom represents a chip.
| | > I am using the xscom node to be consistent in counting chips and modules. | | The trouble with xscom is that it's extremely specific to the way the | current IBM servers present things. It won't work on other types of | host machine (which could happen with PR KVM), and could even break if | IBM changes the way it organizes the SCOMs in a future machine.
Not sure yet how to future proof this at this point. If the SCOMs change or are removed, we will end up returning zeroes (and break the licensing again)
| | Working from the nodes in /cpus still has some dependencies on IBM | specific properties, but it's at least partially based on OF | standards.
yes, I will check with skiboot folks to see if they can add the hw-module-id for each core.
Sukadev