* Philippe Mathieu-Daudé (f4...@amsat.org) wrote: > Add a command to display current devices temperature in the monitor: > > (qemu) info temp > Temperatures (in C): > videocore 25.00 > bcm2835-thermal-0 25.00 > > Signed-off-by: Philippe Mathieu-Daudé <f4...@amsat.org>
How do I set the temperature? > --- > include/monitor/hmp.h | 1 + > hw/misc/temp-sensor.c | 29 +++++++++++++++++++++++++++++ > hmp-commands-info.hx | 11 +++++++++++ > 3 files changed, 41 insertions(+) > > diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h > index e33ca5a911..f023230bd1 100644 > --- a/include/monitor/hmp.h > +++ b/include/monitor/hmp.h > @@ -129,5 +129,6 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict > *qdict); > void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict); > void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict); > void hmp_info_sev(Monitor *mon, const QDict *qdict); > +void hmp_info_temp(Monitor *mon, const QDict *qdict); > > #endif > diff --git a/hw/misc/temp-sensor.c b/hw/misc/temp-sensor.c > index 27750c533d..5f591bd9c3 100644 > --- a/hw/misc/temp-sensor.c > +++ b/hw/misc/temp-sensor.c > @@ -12,6 +12,8 @@ > #include "hw/misc/temp-sensor.h" > #include "qapi/qapi-commands-misc.h" > #include "qapi/error.h" > +#include "monitor/monitor.h" > +#include "monitor/hmp.h" > > static int query_temperature_sensors_foreach(Object *obj, void *opaque) > { > @@ -59,6 +61,33 @@ TemperatureSensorList *qmp_query_temperature_sensors(Error > **errp) > return list; > } > > +void hmp_info_temp(Monitor *mon, const QDict *qdict) > +{ > + TemperatureSensorList *list, *sensor; > + Error *err = NULL; > + > + list = qmp_query_temperature_sensors(&err); > + if (!list) { > + monitor_printf(mon, "No temperature sensors\n"); > + return; > + } > + if (err) { > + monitor_printf(mon, "Error while getting temperatures: %s\n", > + error_get_pretty(err)); > + error_free(err); Maybe use hmp_handle_error > + goto out; > + } > + > + monitor_printf(mon, "Temperatures (in C):\n"); > + for (sensor = list; sensor; sensor = sensor->next) { > + monitor_printf(mon, "%-33s %6.2f\n", sensor->value->name, > + sensor->value->temperature); See my question on the earlier patch; I'm curious here whether we want device name, and then subname within that device. Dave > + } > + > +out: > + qapi_free_TemperatureSensorList(list); > +} > + > static TypeInfo tempsensor_interface_type_info = { > .name = TYPE_TEMPSENSOR_INTERFACE, > .parent = TYPE_INTERFACE, > diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx > index ca5198438d..77f1c43ce3 100644 > --- a/hmp-commands-info.hx > +++ b/hmp-commands-info.hx > @@ -880,4 +880,15 @@ SRST > Show SEV information. > ERST > > + { > + .name = "temp", > + .args_type = "", > + .params = "", > + .help = "show device temperatures", > + .cmd = hmp_info_temp, > + }, > > +SRST > + ``info temp`` > + Show device temperatures. > +ERST > -- > 2.21.1 > -- Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK