qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensor


From: Dr. David Alan Gilbert
Subject: Re: [RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command
Date: Tue, 21 Apr 2020 17:27:05 +0100
User-agent: Mutt/1.13.4 (2020-02-15)

* Philippe Mathieu-Daudé (address@hidden) wrote:
> Add a command to query current temperature from all sensors able
> to report it:
> 
>   { "execute": "query-temperature-sensors" }
>   {
>       "return": [
>           {
>               "temperature": 25,
>               "name": "videocore"
>           },
>           {
>               "temperature": 25,
>               "name": "bcm2835-thermal-0"
>           }
>       ]
>   }
> 
> Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
> ---
>  qapi/misc.json        | 24 ++++++++++++++++++++++
>  hw/misc/temp-sensor.c | 48 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 72 insertions(+)
> 
> diff --git a/qapi/misc.json b/qapi/misc.json
> index 99b90ac80b..51881931e2 100644
> --- a/qapi/misc.json
> +++ b/qapi/misc.json
> @@ -1550,3 +1550,27 @@
>  ##
>  { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }
>  
> +##
> +# @TemperatureSensor:
> +#
> +# Temperature sensor information.
> +#
> +# @name: the name of the sensor
> +#
> +# @temperature: the current temperature of the sensor (in C)
> +#
> +# Since: 5.1
> +##
> +{ 'struct': 'TemperatureSensor',
> +  'data': { 'name': 'str',
> +            'temperature': 'number' } }
> +
> +##
> +# @query-temperature-sensors:
> +#
> +# Return a list of TemperatureSensor for devices that support
> +# the TYPE_TEMPSENSOR_INTERFACE.
> +#
> +# Since: 5.1
> +##
> +{ 'command': 'query-temperature-sensors', 'returns': ['TemperatureSensor']}
> diff --git a/hw/misc/temp-sensor.c b/hw/misc/temp-sensor.c
> index b7c1eb2d87..27750c533d 100644
> --- a/hw/misc/temp-sensor.c
> +++ b/hw/misc/temp-sensor.c
> @@ -10,6 +10,54 @@
>  
>  #include "qemu/osdep.h"
>  #include "hw/misc/temp-sensor.h"
> +#include "qapi/qapi-commands-misc.h"
> +#include "qapi/error.h"
> +
> +static int query_temperature_sensors_foreach(Object *obj, void *opaque)
> +{
> +    TemperatureSensorList **list = opaque;
> +    TempSensor *sensor;
> +    TempSensorClass *k;
> +
> +    if (!object_dynamic_cast(obj, TYPE_TEMPSENSOR_INTERFACE)) {
> +        return 0;
> +    }
> +
> +    k = TEMPSENSOR_INTERFACE_GET_CLASS(obj);
> +    if (!k->get_temperature) {
> +        return 0;
> +    }
> +
> +    sensor = TEMPSENSOR_INTERFACE(obj);
> +    for (size_t i = 0; i < k->sensor_count; i++) {
> +        TemperatureSensorList *info = g_malloc0(sizeof(*info));
> +        TemperatureSensor *value = g_malloc0(sizeof(*value));
> +
> +        if (k->get_name) {
> +            value->name = g_strdup(k->get_name(sensor, i));
> +        } else {
> +            value->name = g_strdup_printf("%s-%zu",
> +                                          object_get_typename(obj), i);
> +        }

How do the names work if you've got multiple of the same device; e.g.
is the get_name() method supposed to return the device path as well as
the sensor name?  if I have an emulated PCI device with two sensors on
and I then instantiate two of the PCI devices, do I get a name with the
PCI path in?

Dave

> +        value->temperature = k->get_temperature(sensor, i);
> +
> +        info->value = value;
> +        info->next = *list;
> +        *list = info;
> +    }
> +
> +    return 0;
> +}
> +
> +TemperatureSensorList *qmp_query_temperature_sensors(Error **errp)
> +{
> +    TemperatureSensorList *list = NULL;
> +
> +    object_child_foreach_recursive(object_get_root(),
> +                                   query_temperature_sensors_foreach,
> +                                   &list);
> +    return list;
> +}
>  
>  static TypeInfo tempsensor_interface_type_info = {
>      .name = TYPE_TEMPSENSOR_INTERFACE,
> -- 
> 2.21.1
> 
--
Dr. David Alan Gilbert / address@hidden / Manchester, UK




reply via email to

[Prev in Thread] Current Thread [Next in Thread]