[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command |
Date: |
Tue, 21 Apr 2020 14:16:12 +0200 |
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é <address@hidden>
---
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);
+ 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);
+ }
+
+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
- [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command,
Philippe Mathieu-Daudé <=
- [RFC PATCH 01/17] hw/misc: Introduce the temperature sensor interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 06/17] hw/misc/tmp421: Add definition for SENSORS_COUNT, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 08/17] hw/misc/tmp421: Extract set_temp_mC() helper, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 04/17] hw/misc/tmp105: Extract get_temp_mC() and set_temp_mC() helpers, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 05/17] hw/misc/tmp105: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 09/17] hw/misc/tmp421: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 10/17] hw/misc/bcm2835_thermal: Hold the temperature in the device state, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 07/17] hw/misc/tmp421: Extract get_temp_mC() helper, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 11/17] hw/misc/bcm2835_thermal: Implement the 'temperature-sensor' interface, Philippe Mathieu-Daudé, 2020/04/21