QMP: Introduce RTC_CHANGE event
PATCH 1/1 QMP: Introduce RTC_CHANGE event
Emitted whenever the RTC time changes.
--- QMP/qmp-events.txt | 15 +++++++++++++++ hw/mc146818rtc.c | 2 ++ monitor.c | 3 +++ monitor.h | 1 + sysemu.h | 2 ++ vl.c | 9 +++++++++ 6 files changed, 32 insertions(+), 0 deletions(-)
QMP/qmp-events.txt +15 -0
@@ -38,6 +38,21 @@ Example: { "event": "RESET", "timestamp": { "seconds": 1267041653, "microseconds": 9518 } } +RTC_CHANGE +---------- + +Emitted when the RTC time changes. + +Data: + +- "offset": delta against the host UTC in seconds (json-number) + +Example: + +{ "event": "RTC_CHANGE", + "data": { "offset": 78 }, + "timestamp": { "seconds": 1267020223, "microseconds": 435656 } } + SHUTDOWN --------
hw/mc146818rtc.c +2 -0
@@ -297,6 +297,8 @@ static void rtc_set_time(RTCState *s) tm->tm_mday =rtc_from_bcd (s, s->cmos_data[RTC_DAY_OF_MONTH ]); tm->tm_mon =rtc_from_bcd (s, s->cmos_data[RTC_MONTH ]) -1 ; tm->tm_year =rtc_from_bcd (s, s->cmos_data[RTC_YEAR ]) + s->base_year -1900 ; + +rtc_change_mon_event (tm); }static void rtc_copy_date (RTCState *s)
monitor.c +3 -0
@@ -423,6 +423,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)case QEVENT_BLOCK_IO_ERROR : event_name ="BLOCK_IO_ERROR" ;break ; +case QEVENT_RTC_CHANGE : + event_name ="RTC_CHANGE" ; +break ;default :abort ();break ;
monitor.h +1 -0
@@ -23,6 +23,7 @@ typedef enum MonitorEvent {QEVENT_VNC_INITIALIZED ,QEVENT_VNC_DISCONNECTED ,QEVENT_BLOCK_IO_ERROR , +QEVENT_RTC_CHANGE ,QEVENT_MAX , } MonitorEvent;
sysemu.h +2 -0
@@ -252,6 +252,8 @@ void do_usb_add(Monitor *mon, const QDict *qdict);void do_usb_del (Monitor *mon,const QDict *qdict);void usb_info (Monitor *mon); +void rtc_change_mon_event (struct tm *tm); +void register_devices (void );#endif
vl.c +9 -0
@@ -1488,6 +1488,15 @@ int qemu_timedate_diff(struct tm *tm)return seconds -time (NULL ); } +void rtc_change_mon_event (struct tm *tm) +{ +QObject *data; + + data =qobject_from_jsonf ("{ 'offset': %d }" ,qemu_timedate_diff (tm)); +monitor_protocol_event (QEVENT_RTC_CHANGE , data); +qobject_decref (data); +} +static void configure_rtc_date_offset (const char *startdate,int legacy) {time_t rtc_start_date;
Signature · 1 line
1.7.0.GIT
Anthony Liguori
AppliedQuoted 4 lines · Luiz Capitulino
Emitted whenever the RTC time changes.
Signed-off-by Luiz Capitulino<[email protected]>
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 108 lines
--- QMP/qmp-events.txt | 15 +++++++++++++++ hw/mc146818rtc.c | 2 ++ monitor.c | 3 +++ monitor.h | 1 + sysemu.h | 2 ++ vl.c | 9 +++++++++ 6 files changed, 32 insertions(+), 0 deletions(-)QMP/qmp-events.txt +15
-0@@ -38,6 +38,21 @@ Example: { "event": "RESET", "timestamp": { "seconds": 1267041653, "microseconds": 9518 } } +RTC_CHANGE +---------- + +Emitted when the RTC time changes. + +Data: + +- "offset": delta against the host UTC in seconds (json-number) + +Example: + +{ "event": "RTC_CHANGE", + "data": { "offset": 78 }, + "timestamp": { "seconds": 1267020223, "microseconds": 435656 } } + SHUTDOWN --------hw/mc146818rtc.c +2
-0@@ -297,6 +297,8 @@ static void rtc_set_time(RTCState *s) tm->tm_mday =rtc_from_bcd (s, s->cmos_data[RTC_DAY_OF_MONTH ]); tm->tm_mon =rtc_from_bcd (s, s->cmos_data[RTC_MONTH ]) -1 ; tm->tm_year =rtc_from_bcd (s, s->cmos_data[RTC_YEAR ]) + s->base_year -1900 ; + +rtc_change_mon_event (tm); }static void rtc_copy_date (RTCState *s)monitor.c +3
-0@@ -423,6 +423,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)case QEVENT_BLOCK_IO_ERROR : event_name ="BLOCK_IO_ERROR" ;break ; +case QEVENT_RTC_CHANGE : + event_name ="RTC_CHANGE" ; +break ;default :abort ();break ;monitor.h +1
-0@@ -23,6 +23,7 @@ typedef enum MonitorEvent {QEVENT_VNC_INITIALIZED ,QEVENT_VNC_DISCONNECTED ,QEVENT_BLOCK_IO_ERROR , +QEVENT_RTC_CHANGE ,QEVENT_MAX , } MonitorEvent;sysemu.h +2
-0@@ -252,6 +252,8 @@ void do_usb_add(Monitor *mon, const QDict *qdict);void do_usb_del (Monitor *mon,const QDict *qdict);void usb_info (Monitor *mon); +void rtc_change_mon_event (struct tm *tm); +void register_devices (void );#endif vl.c +9
-0@@ -1488,6 +1488,15 @@ int qemu_timedate_diff(struct tm *tm)return seconds -time (NULL ); } +void rtc_change_mon_event (struct tm *tm) +{ +QObject *data; + + data =qobject_from_jsonf ("{ 'offset': %d }" ,qemu_timedate_diff (tm)); +monitor_protocol_event (QEVENT_RTC_CHANGE , data); +qobject_decref (data); +} +static void configure_rtc_date_offset (const char *startdate,int legacy) {time_t rtc_start_date;
Quoted 4 lines · Luiz Capitulino
Emitted whenever the RTC time changes.
Signed-off-by Luiz Capitulino<[email protected]>
Not that this change isn't acceptable, but I think we need to improve how we handle these events in the future.
Quoted 67 lines
--- QMP/qmp-events.txt | 15 +++++++++++++++ hw/mc146818rtc.c | 2 ++ monitor.c | 3 +++ monitor.h | 1 + sysemu.h | 2 ++ vl.c | 9 +++++++++ 6 files changed, 32 insertions(+), 0 deletions(-)QMP/qmp-events.txt +15
-0@@ -38,6 +38,21 @@ Example: { "event": "RESET", "timestamp": { "seconds": 1267041653, "microseconds": 9518 } } +RTC_CHANGE +---------- + +Emitted when the RTC time changes. + +Data: + +- "offset": delta against the host UTC in seconds (json-number) + +Example: + +{ "event": "RTC_CHANGE", + "data": { "offset": 78 }, + "timestamp": { "seconds": 1267020223, "microseconds": 435656 } } + SHUTDOWN --------hw/mc146818rtc.c +2
-0@@ -297,6 +297,8 @@ static void rtc_set_time(RTCState *s) tm->tm_mday =rtc_from_bcd (s, s->cmos_data[RTC_DAY_OF_MONTH ]); tm->tm_mon =rtc_from_bcd (s, s->cmos_data[RTC_MONTH ]) -1 ; tm->tm_year =rtc_from_bcd (s, s->cmos_data[RTC_YEAR ]) + s->base_year -1900 ; + +rtc_change_mon_event (tm); }static void rtc_copy_date (RTCState *s)monitor.c +3
-0@@ -423,6 +423,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)case QEVENT_BLOCK_IO_ERROR : event_name ="BLOCK_IO_ERROR" ;break ; +case QEVENT_RTC_CHANGE : + event_name ="RTC_CHANGE" ; +break ;default :abort ();break ;monitor.h +0
-0
monitor.h typedef enum MonitorEvent { · line 29
Quoted 7 lines
monitor.h +1
-0@@ -23,6 +23,7 @@ typedef enum MonitorEvent {QEVENT_VNC_INITIALIZED ,QEVENT_VNC_DISCONNECTED ,QEVENT_BLOCK_IO_ERROR , +QEVENT_RTC_CHANGE ,QEVENT_MAX , } MonitorEvent;
This is going against the direction that we're trying to take with qdev. We're trying to modularize devices by having only the device themselves know their existence. That's the beauty of things like -device.
The fact that we're putting knowledge of the RTC into monitor.[ch] and vl.c is a step in the wrong direction. We really ought to be able to generate device specific events entirely within the device.
Regards,
Anthony Liguori
Quoted 34 lines
sysemu.h +2
-0@@ -252,6 +252,8 @@ void do_usb_add(Monitor *mon, const QDict *qdict);void do_usb_del (Monitor *mon,const QDict *qdict);void usb_info (Monitor *mon); +void rtc_change_mon_event (struct tm *tm); +void register_devices (void );#endif vl.c +9
-0@@ -1488,6 +1488,15 @@ int qemu_timedate_diff(struct tm *tm)return seconds -time (NULL ); } +void rtc_change_mon_event (struct tm *tm) +{ +QObject *data; + + data =qobject_from_jsonf ("{ 'offset': %d }" ,qemu_timedate_diff (tm)); +monitor_protocol_event (QEVENT_RTC_CHANGE , data); +qobject_decref (data); +} +static void configure_rtc_date_offset (const char *startdate,int legacy) {time_t rtc_start_date;
Quoted 79 lines · On Tue, 09 Mar 2010 08:20:09 -0600 Anthony Liguori <[email protected]>…
Quoted 4 lines · Luiz Capitulino
Emitted whenever the RTC time changes.
Signed-off-by Luiz Capitulino<[email protected]>Not that this change isn't acceptable, but I think we need to improve how we handle these events in the future.
Quoted 70 lines
--- QMP/qmp-events.txt | 15 +++++++++++++++ hw/mc146818rtc.c | 2 ++ monitor.c | 3 +++ monitor.h | 1 + sysemu.h | 2 ++ vl.c | 9 +++++++++ 6 files changed, 32 insertions(+), 0 deletions(-)QMP/qmp-events.txt +15
-0@@ -38,6 +38,21 @@ Example: { "event": "RESET", "timestamp": { "seconds": 1267041653, "microseconds": 9518 } } +RTC_CHANGE +---------- + +Emitted when the RTC time changes. + +Data: + +- "offset": delta against the host UTC in seconds (json-number) + +Example: + +{ "event": "RTC_CHANGE", + "data": { "offset": 78 }, + "timestamp": { "seconds": 1267020223, "microseconds": 435656 } } + SHUTDOWN --------hw/mc146818rtc.c +2
-0@@ -297,6 +297,8 @@ static void rtc_set_time(RTCState *s) tm->tm_mday =rtc_from_bcd (s, s->cmos_data[RTC_DAY_OF_MONTH ]); tm->tm_mon =rtc_from_bcd (s, s->cmos_data[RTC_MONTH ]) -1 ; tm->tm_year =rtc_from_bcd (s, s->cmos_data[RTC_YEAR ]) + s->base_year -1900 ; + +rtc_change_mon_event (tm); }static void rtc_copy_date (RTCState *s)monitor.c +3
-0@@ -423,6 +423,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)case QEVENT_BLOCK_IO_ERROR : event_name ="BLOCK_IO_ERROR" ;break ; +case QEVENT_RTC_CHANGE : + event_name ="RTC_CHANGE" ; +break ;default :abort ();break ;monitor.h +0
-0@@ -23,6 +23,7 @@ typedef enum MonitorEvent {QEVENT_VNC_INITIALIZED ,QEVENT_VNC_DISCONNECTED , QEVENT_BLOCK_IO_ERROR,
Quoted 8 lines
monitor.h typedef enum MonitorEvent { · line 29
Quoted 4 lines
monitor.h +1
-0+QEVENT_RTC_CHANGE ,QEVENT_MAX , } MonitorEvent;This is going against the direction that we're trying to take with qdev. We're trying to modularize devices by having only the device themselves know their existence. That's the beauty of things like -device.
Okay, we need to integrate with qdev then, as you have already suggested.
Quoted 3 lines
The fact that we're putting knowledge of the RTC into monitor.[ch] and
vl.cis a step in the wrong direction. We really ought to be able to generate device specific events entirely within the device.
Perhaps qdev can export available events to the Monitor, but even then
the Monitor will have to at least know what put on the wire (eg. the event's string name). This can't be on qdev, as it's protocol specific info.
Also, just a small note, I've changed vl.c because RTC code is there
(it should be on its own module).