qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [Patch] [kinda-resend] persistent real-time-clock
@ 2008-04-27 15:45 Dan Kenigsberg
  2008-04-27 16:39 ` Avi Kivity
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Dan Kenigsberg @ 2008-04-27 15:45 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 432 bytes --]

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.

[-- Attachment #2: 0001-when-specifying-localtime-startdate-is-expressed.patch --]
[-- Type: text/plain, Size: 2595 bytes --]

>From 7b5505ef931fb900d365d23026698a6865fd3e83 Mon Sep 17 00:00:00 2001
From: Dan Kenigsberg <danken@qumranet.com>
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


[-- Attachment #3: 0002-specify-startdate-offset-from-the-command-line.patch --]
[-- Type: text/plain, Size: 1905 bytes --]

>From 6fb0e482a932ef77683a54cbf19681b22fe31d34 Mon Sep 17 00:00:00 2001
From: Dan Kenigsberg <danken@qumranet.com>
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


[-- Attachment #4: 0003-read-current-rtc-offset-guest-vs.-host-from-the-mo.patch --]
[-- Type: text/plain, Size: 2793 bytes --]

>From d8f029819dcf2bf266e93661cf3c2f1503504835 Mon Sep 17 00:00:00 2001
From: Dan Kenigsberg <danken@qumranet.com>
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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2008-05-06  8:53 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-27 15:45 [Qemu-devel] [Patch] [kinda-resend] persistent real-time-clock Dan Kenigsberg
2008-04-27 16:39 ` Avi Kivity
2008-04-28  6:54   ` Dan Kenigsberg
2008-04-28  7:11     ` Avi Kivity
2008-04-30 12:22   ` Sergey Bychkov
2008-04-27 16:58 ` Anthony Liguori
2008-04-28  8:00   ` Dan Kenigsberg
2008-05-01  8:48   ` Dan Kenigsberg
2008-05-05 20:23     ` Anthony Liguori
2008-05-05 21:13       ` Avi Kivity
2008-05-05 22:38         ` Anthony Liguori
2008-05-06  8:26           ` Tristan Gingold
2008-05-06  8:53             ` Laurent Vivier
2008-04-27 21:28 ` Jamie Lokier
2008-04-28  7:27   ` Dan Kenigsberg
2008-04-30 12:21   ` Sergey Bychkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).