Message ID | 1456117285-22273-8-git-send-email-bharata@linux.vnet.ibm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 02/21/2016 10:01 PM, Bharata B Rao wrote: > Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com> > --- > hw/cpu/package.c | 19 +++++++++++++ > hw/ppc/spapr.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > include/hw/boards.h | 1 + > qapi-schema.json | 48 ++++++++++++++++++++++++++++++++ > 4 files changed, 147 insertions(+) > > +++ b/qapi-schema.json > @@ -4083,3 +4083,51 @@ > ## > { 'enum': 'ReplayMode', > 'data': [ 'none', 'record', 'play' ] } > + > +## > +# @CPUThreadInfo: > +# > +# Information about CPU Threads > +# Missing documentation for the fields. > +# Since: 2.6 > +## > + > +{ 'struct': 'CPUInfo', > + 'data': { 'arch_id': 'int', New QMP code should favor '-' over '_'; this should be 'arch-id'. > + 'type': 'str', Is this string free-form, or is it a finite set of values? If the latter, then it should be an enum type. > + '*thread': 'int', > + '*core': 'int', > + '*socket' : 'int', > + '*node' : 'int', > + '*qom_path': 'str' 'qom-path'. But this one is definitely free-form, so 'str' is right. > + } > +} > + > +## > +# @CPUPackageInfo: > +# > +# Information about CPU Packages > +# Missing field documentation. > +# Since: 2.6 > +## > + > +{ 'struct': 'CPUPackageInfo', > + 'data': { '*id': 'str', > + 'type': 'str', > + 'qom_path': 'str', > + 'realized': 'bool', > + 'nr_cpus': 'int', 'nr-cpus'. Is this field redundant, given that the caller can just count the length of the 'cpus' array? > + 'cpus' : ['CPUInfo'] > + } > +} > + > +## > +# @query-cpu-packages: > +# > +# Returns information for all CPU packages > +# > +# Returns: a list of @CPUPackageInfo > +# > +# Since: 2.6 > +## > +{ 'command': 'query-cpu-packages', 'returns': ['CPUPackageInfo'] } >
On Mon, 22 Feb 2016 09:49:40 -0700 Eric Blake <eblake@redhat.com> wrote: > On 02/21/2016 10:01 PM, Bharata B Rao wrote: > > Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com> > > --- > > hw/cpu/package.c | 19 +++++++++++++ > > hw/ppc/spapr.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > > include/hw/boards.h | 1 + > > qapi-schema.json | 48 ++++++++++++++++++++++++++++++++ > > 4 files changed, 147 insertions(+) > > > > > +++ b/qapi-schema.json > > @@ -4083,3 +4083,51 @@ > > ## > > { 'enum': 'ReplayMode', > > 'data': [ 'none', 'record', 'play' ] } > > + > > +## > > +# @CPUThreadInfo: > > +# > > +# Information about CPU Threads > > +# > > Missing documentation for the fields. > > > +# Since: 2.6 > > +## > > + > > +{ 'struct': 'CPUInfo', > > + 'data': { 'arch_id': 'int', > > New QMP code should favor '-' over '_'; this should be 'arch-id'. > > > + 'type': 'str', > > Is this string free-form, or is it a finite set of values? If the > latter, then it should be an enum type. I'd say it's a limited set of values. The same applies to other targets. It's basically cpu_model translated into corresponding QOM type name. Is there a way to auto-generate this QAPI enum dynamically? > > > + '*thread': 'int', > > + '*core': 'int', > > + '*socket' : 'int', > > + '*node' : 'int', > > + '*qom_path': 'str' > > 'qom-path'. But this one is definitely free-form, so 'str' is right. > > > + } > > +} > > + > > +## > > +# @CPUPackageInfo: > > +# > > +# Information about CPU Packages > > +# > > Missing field documentation. > > > +# Since: 2.6 > > +## > > + > > +{ 'struct': 'CPUPackageInfo', > > + 'data': { '*id': 'str', > > + 'type': 'str', > > + 'qom_path': 'str', > > + 'realized': 'bool', > > + 'nr_cpus': 'int', > > 'nr-cpus'. Is this field redundant, given that the caller can just count > the length of the 'cpus' array? > > > + 'cpus' : ['CPUInfo'] > > + } > > +} > > + > > +## > > +# @query-cpu-packages: > > +# > > +# Returns information for all CPU packages > > +# > > +# Returns: a list of @CPUPackageInfo > > +# > > +# Since: 2.6 > > +## > > +{ 'command': 'query-cpu-packages', 'returns': ['CPUPackageInfo'] } > > >
diff --git a/hw/cpu/package.c b/hw/cpu/package.c index 259dbfa..4ff20fa 100644 --- a/hw/cpu/package.c +++ b/hw/cpu/package.c @@ -7,7 +7,26 @@ * See the COPYING file in the top-level directory. */ #include "hw/cpu/package.h" +#include "hw/boards.h" #include "qom/object_interfaces.h" +#include "qmp-commands.h" +#include "qapi/qmp/qerror.h" + +/* + * QMP: query cpu-pacakges + */ +CPUPackageInfoList *qmp_query_cpu_packages(Error **errp) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + MachineClass *mc = MACHINE_GET_CLASS(ms); + + if (!mc->cpu_packages) { + error_setg(errp, QERR_UNSUPPORTED); + return NULL; + } + + return mc->cpu_packages(ms); +} Object *cpu_package_create_object(const char *typename, uint32_t index, Error **errp) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 0bbbaf8..147b9d1 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2441,6 +2441,84 @@ static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index) return cpu_index / smp_threads / smp_cores; } +static int spapr_cpuinfo_list(Object *obj, void *opaque) +{ + MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine()); + CPUInfoList ***prev = opaque; + + if (object_dynamic_cast(obj, TYPE_CPU)) { + CPUInfoList *elem = g_new0(CPUInfoList, 1); + CPUInfo *s = g_new0(CPUInfo, 1); + CPUState *cpu = CPU(obj); + PowerPCCPU *pcpu = POWERPC_CPU(cpu); + + s->arch_id = ppc_get_vcpu_dt_id(pcpu); + s->type = g_strdup(object_get_typename(obj)); + s->thread = cpu->cpu_index; + s->has_thread = true; + s->core = cpu->cpu_index / smp_threads; + s->has_core = true; + if (mc->cpu_index_to_socket_id) { + s->socket = mc->cpu_index_to_socket_id(cpu->cpu_index); + } else { + s->socket = cpu->cpu_index / smp_threads / smp_cores; + } + s->has_socket = true; + s->node = cpu->numa_node; + s->has_node = true; + s->qom_path = object_get_canonical_path(obj); + + elem->value = s; + elem->next = NULL; + **prev = elem; + *prev = &elem->next; + } + object_child_foreach(obj, spapr_cpuinfo_list, opaque); + return 0; +} + +static int spapr_cpu_packageinfo_list(Object *obj, void *opaque) +{ + CPUPackageInfoList ***prev = opaque; + + if (object_dynamic_cast(obj, TYPE_CPU_PACKAGE)) { + DeviceState *dev = DEVICE(obj); + CPUPackageInfoList *elem = g_new0(CPUPackageInfoList, 1); + CPUPackageInfo *s = g_new0(CPUPackageInfo, 1); + CPUInfoList *cpu_head = NULL; + CPUInfoList **cpu_prev = &cpu_head; + + if (dev->id) { + s->has_id = true; + s->id = g_strdup(dev->id); + } + s->realized = object_property_get_bool(obj, "realized", NULL); + s->nr_cpus = smp_threads; + s->qom_path = object_get_canonical_path(obj); + s->type = g_strdup(TYPE_SPAPR_CPU_PACKAGE); + if (s->realized) { + spapr_cpuinfo_list(obj, &cpu_prev); + } + s->cpus = cpu_head; + elem->value = s; + elem->next = NULL; + **prev = elem; + *prev = &elem->next; + } + + object_child_foreach(obj, spapr_cpu_packageinfo_list, opaque); + return 0; +} + +static CPUPackageInfoList *spapr_cpu_packages(MachineState *machine) +{ + CPUPackageInfoList *head = NULL; + CPUPackageInfoList **prev = &head; + + spapr_cpu_packageinfo_list(qdev_get_machine(), &prev); + return head; +} + static void spapr_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -2467,6 +2545,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) mc->has_dynamic_sysbus = true; mc->pci_allow_0_address = true; mc->get_hotplug_handler = spapr_get_hotpug_handler; + mc->cpu_packages = spapr_cpu_packages; hc->plug = spapr_machine_device_plug; hc->unplug = spapr_machine_device_unplug; mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id; diff --git a/include/hw/boards.h b/include/hw/boards.h index cf95d10..66d8780 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -99,6 +99,7 @@ struct MachineClass { HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev); unsigned (*cpu_index_to_socket_id)(unsigned cpu_index); + CPUPackageInfoList *(*cpu_packages)(MachineState *machine); }; /** diff --git a/qapi-schema.json b/qapi-schema.json index 8d04897..5a0dd80 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4083,3 +4083,51 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @CPUThreadInfo: +# +# Information about CPU Threads +# +# Since: 2.6 +## + +{ 'struct': 'CPUInfo', + 'data': { 'arch_id': 'int', + 'type': 'str', + '*thread': 'int', + '*core': 'int', + '*socket' : 'int', + '*node' : 'int', + '*qom_path': 'str' + } +} + +## +# @CPUPackageInfo: +# +# Information about CPU Packages +# +# Since: 2.6 +## + +{ 'struct': 'CPUPackageInfo', + 'data': { '*id': 'str', + 'type': 'str', + 'qom_path': 'str', + 'realized': 'bool', + 'nr_cpus': 'int', + 'cpus' : ['CPUInfo'] + } +} + +## +# @query-cpu-packages: +# +# Returns information for all CPU packages +# +# Returns: a list of @CPUPackageInfo +# +# Since: 2.6 +## +{ 'command': 'query-cpu-packages', 'returns': ['CPUPackageInfo'] }
Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com> --- hw/cpu/package.c | 19 +++++++++++++ hw/ppc/spapr.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 1 + qapi-schema.json | 48 ++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+)