Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jq9do-0007ZV-Ei for qemu-devel@nongnu.org; Sun, 27 Apr 2008 12:22:16 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jq9dm-0007WV-74 for qemu-devel@nongnu.org; Sun, 27 Apr 2008 12:22:15 -0400 Received: from [199.232.76.173] (port=42646 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jq9dm-0007WM-2r for qemu-devel@nongnu.org; Sun, 27 Apr 2008 12:22:14 -0400 Received: from bzq-179-150-194.static.bezeqint.net ([212.179.150.194] helo=il.qumranet.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Jq9dj-0005i2-Ui for qemu-devel@nongnu.org; Sun, 27 Apr 2008 12:22:13 -0400 Received: from localhost (karma.qumranet.com [172.16.16.240]) by il.qumranet.com (Postfix) with ESMTP id 16528250136 for ; Sun, 27 Apr 2008 18:45:02 +0300 (IDT) Date: Sun, 27 Apr 2008 18:45:01 +0300 From: Dan Kenigsberg Message-ID: <20080427154501.GA20547@karma.qumranet.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="bp/iNruPH9dso1Pn" Content-Disposition: inline Subject: [Qemu-devel] [Patch] [kinda-resend] persistent real-time-clock Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --bp/iNruPH9dso1Pn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Real PC lets its user set the real-time-clock and store it on CMOS, which advances the clock even when the PC is offline. These patches will allow doing the same with VM: - Before shutting a VM down, use the monitor's info timeoffset to see how much (in seconds) does the rtc differ from the host clock. - Store this offset somewhere. - Use it next time with -startdate now+offset. Please tell me what do you think of it. Dan. --bp/iNruPH9dso1Pn Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-when-specifying-localtime-startdate-is-expressed.patch" >From 7b5505ef931fb900d365d23026698a6865fd3e83 Mon Sep 17 00:00:00 2001 From: Dan Kenigsberg Date: Sun, 27 Apr 2008 13:09:17 +0300 Subject: [PATCH] when specifying -localtime, -startdate is expressed as local time. --- vl.c | 30 +++++++++++++----------------- 1 files changed, 13 insertions(+), 17 deletions(-) diff --git a/vl.c b/vl.c index 78486cf..7f22152 100644 --- a/vl.c +++ b/vl.c @@ -181,7 +181,7 @@ int nb_nics; NICInfo nd_table[MAX_NICS]; int vm_running; static int rtc_utc = 1; -static int rtc_date_offset = -1; /* -1 means no change */ +static int rtc_date_offset = 0; /* 0 means no change */ int cirrus_vga_enabled = 1; int vmsvga_enabled = 0; #ifdef TARGET_SPARC @@ -1574,15 +1574,11 @@ void qemu_get_timedate(struct tm *tm, int offset) time(&ti); ti += offset; - if (rtc_date_offset == -1) { - if (rtc_utc) - ret = gmtime(&ti); - else - ret = localtime(&ti); - } else { - ti -= rtc_date_offset; + ti -= rtc_date_offset; + if (rtc_utc) ret = gmtime(&ti); - } + else + ret = localtime(&ti); memcpy(tm, ret, sizeof(struct tm)); } @@ -1591,13 +1587,10 @@ int qemu_timedate_diff(struct tm *tm) { time_t seconds; - if (rtc_date_offset == -1) - if (rtc_utc) - seconds = mktimegm(tm); - else - seconds = mktime(tm); - else + if (rtc_utc) seconds = mktimegm(tm) + rtc_date_offset; + else + seconds = mktime(tm) + rtc_date_offset; return seconds - time(NULL); } @@ -8785,7 +8778,7 @@ int main(int argc, char **argv) struct tm tm; time_t rtc_start_date; if (!strcmp(optarg, "now")) { - rtc_date_offset = -1; + rtc_date_offset = 0; } else { if (sscanf(optarg, "%d-%d-%dT%d:%d:%d", &tm.tm_year, @@ -8807,7 +8800,10 @@ int main(int argc, char **argv) } tm.tm_year -= 1900; tm.tm_mon--; - rtc_start_date = mktimegm(&tm); + if (rtc_utc) + rtc_start_date = mktimegm(&tm); + else + rtc_start_date = mktime(&tm); if (rtc_start_date == -1) { date_fail: fprintf(stderr, "Invalid date format. Valid format are:\n" -- 1.5.4.5 --bp/iNruPH9dso1Pn Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0002-specify-startdate-offset-from-the-command-line.patch" >From 6fb0e482a932ef77683a54cbf19681b22fe31d34 Mon Sep 17 00:00:00 2001 From: Dan Kenigsberg Date: Sun, 27 Apr 2008 13:49:47 +0300 Subject: [PATCH] specify startdate offset from the command line --- vl.c | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/vl.c b/vl.c index 7f22152..34d8e68 100644 --- a/vl.c +++ b/vl.c @@ -8777,7 +8777,19 @@ int main(int argc, char **argv) { struct tm tm; time_t rtc_start_date; - if (!strcmp(optarg, "now")) { + char sign; + if (sscanf(optarg, "now%c%lu", + &sign, &rtc_date_offset) == 2) { + switch (sign) { + case '+': + rtc_date_offset = -rtc_date_offset; + break; + case '-': + break; + default: + goto date_fail; + } + } else if (!strcmp(optarg, "now")) { rtc_date_offset = 0; } else { if (sscanf(optarg, "%d-%d-%dT%d:%d:%d", @@ -8807,7 +8819,7 @@ int main(int argc, char **argv) if (rtc_start_date == -1) { date_fail: fprintf(stderr, "Invalid date format. Valid format are:\n" - "'now' or '2006-06-17T16:01:21' or '2006-06-17'\n"); + "'now' or 'now{+-}offset' or '2006-06-17T16:01:21' or '2006-06-17'\n"); exit(1); } rtc_date_offset = time(NULL) - rtc_start_date; -- 1.5.4.5 --bp/iNruPH9dso1Pn Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0003-read-current-rtc-offset-guest-vs.-host-from-the-mo.patch" >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 --bp/iNruPH9dso1Pn--