>From d8f029819dcf2bf266e93661cf3c2f1503504835 Mon Sep 17 00:00:00 2001 From: Dan Kenigsberg Date: Sun, 27 Apr 2008 18:10:00 +0300 Subject: [PATCH] read current rtc offset (guest vs. host) from the monitor. this allows management software to notice rtc changes from the guest. --- console.h | 5 +++++ hw/mc146818rtc.c | 5 +++++ hw/pc.c | 6 ++++++ monitor.c | 4 ++++ vl.c | 12 ++++++++++++ 5 files changed, 32 insertions(+), 0 deletions(-) diff --git a/console.h b/console.h index c7f29f5..44d0dad 100644 --- a/console.h +++ b/console.h @@ -149,6 +149,11 @@ int vnc_display_open(DisplayState *ds, const char *display); int vnc_display_password(DisplayState *ds, const char *password); void do_info_vnc(void); +#if defined(TARGET_I386) +/* pc.c */ +void do_info_timeoffset(void); +#endif + /* curses.c */ void curses_display_init(DisplayState *ds, int full_screen); diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c index 30bb044..3294363 100644 --- a/hw/mc146818rtc.c +++ b/hw/mc146818rtc.c @@ -487,6 +487,11 @@ RTCState *rtc_init(int base, qemu_irq irq) return s; } +int rtc_get_timeoffset(RTCState *s) +{ + return qemu_timedate_offset(&s->current_tm); +} + /* Memory mapped interface */ static uint32_t cmos_mm_readb (void *opaque, target_phys_addr_t addr) { diff --git a/hw/pc.c b/hw/pc.c index 44a021b..ff440c7 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -50,6 +50,12 @@ static PITState *pit; static IOAPICState *ioapic; static PCIDevice *i440fx_state; +void do_info_timeoffset(void) +{ + int rtc_get_timeoffset(RTCState *s); + term_printf("now%+d\n", rtc_get_timeoffset(rtc_state)); +} + static void ioport80_write(void *opaque, uint32_t addr, uint32_t data) { } diff --git a/monitor.c b/monitor.c index 574973d..76817e1 100644 --- a/monitor.c +++ b/monitor.c @@ -1406,6 +1406,10 @@ static term_cmd_t info_cmds[] = { "", "show which guest mouse is receiving events" }, { "vnc", "", do_info_vnc, "", "show the vnc server status"}, +#if defined(TARGET_I386) + { "timeoffset", "", do_info_timeoffset, + "", "show how much the VM real time clock differ from host time" }, +#endif { "name", "", do_info_name, "", "show the current VM name" }, #if defined(TARGET_PPC) diff --git a/vl.c b/vl.c index 34d8e68..c3c575c 100644 --- a/vl.c +++ b/vl.c @@ -1595,6 +1595,18 @@ int qemu_timedate_diff(struct tm *tm) return seconds - time(NULL); } +int qemu_timedate_offset(struct tm *tm) +{ + time_t seconds; + + if (rtc_utc) + seconds = mktimegm(tm); + else + seconds = mktime(tm); + + return seconds - time(NULL); +} + /***********************************************************/ /* character device */ -- 1.5.4.5