qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 4/5] Refactor RTC command line switches


From: Jan Kiszka
Subject: [Qemu-devel] [PATCH 4/5] Refactor RTC command line switches
Date: Wed, 09 Sep 2009 17:11:12 +0200
User-agent: StGIT/0.14.3

Deprecate -localtime, -setdate and -rtc-td-hack in favor of a new
unified command line switch:

    -rtc [base=utc|localtime|@var{date}][,drift-fix=on|off]

Signed-off-by: Jan Kiszka <address@hidden>
---

 qemu-options.hx |   46 +++++++++++----------
 sysemu.h        |    1 
 vl.c            |  121 ++++++++++++++++++++++++++++++++++++++-----------------
 3 files changed, 109 insertions(+), 59 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index ce38a3b..ea672ee 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -681,15 +681,9 @@ slows down the IDE transfers).
 ETEXI
 
 #ifdef TARGET_I386
-DEF("rtc-td-hack", 0, QEMU_OPTION_rtc_td_hack,
-    "-rtc-td-hack    use it to fix time drift in Windows ACPI HAL\n")
+HXCOMM Deprecated by -rtc
+DEF("rtc-td-hack", 0, QEMU_OPTION_rtc_td_hack, "")
 #endif
-STEXI
address@hidden -rtc-td-hack
-Use it if you experience time drift problem in Windows with ACPI HAL.
-This option will try to figure out how many timer interrupts were not
-processed by the Windows guest and will re-inject them.
-ETEXI
 
 #ifdef TARGET_I386
 DEF("no-fd-bootchk", 0, QEMU_OPTION_no_fd_bootchk,
@@ -1498,23 +1492,31 @@ Force the use of the given methods for timer alarm. To 
see what timers
 are available use -clock ?.
 ETEXI
 
-DEF("localtime", 0, QEMU_OPTION_localtime, \
-    "-localtime      set the real time clock to local time [default=utc]\n")
-STEXI
address@hidden -localtime
-Set the real time clock to local time (the default is to UTC
-time). This option is needed to have correct date in MS-DOS or
-Windows.
-ETEXI
+HXCOMM Options deprecated by -rtc
+DEF("localtime", 0, QEMU_OPTION_localtime, "")
+DEF("startdate", HAS_ARG, QEMU_OPTION_startdate, "")
+
+#ifdef TARGET_I386
+DEF("rtc", HAS_ARG, QEMU_OPTION_rtc, \
+    "-rtc [base=utc|localtime|date][,drift-fix=on|off]\n" \
+    "                Set the RTC base, enable Windows time drift fix\n")
+#else
+DEF("rtc", HAS_ARG, QEMU_OPTION_rtc, \
+    "-rtc [base=utc|localtime|date]\n" \
+    "                Set the RTC base and clock\n")
+#endif
 
-DEF("startdate", HAS_ARG, QEMU_OPTION_startdate, \
-    "-startdate      select initial date of the clock\n")
 STEXI
 
address@hidden -startdate @var{date}
-Set the initial date of the real time clock. Valid formats for
address@hidden are: @code{now} or @code{2006-06-17T16:01:21} or
address@hidden The default value is @code{now}.
address@hidden -rtc [base=utc|localtime|@var{date}][,drift-fix=on|off]
+Specify @option{base} as @code{utc} or @code{localtime} to let the RTC start 
at the current
+UTC or local time, respectively. @code{localtime} is required for correct date 
in
+MS-DOS or Windows. To start at a specific point in time, provide @var{date} in 
the
+format @code{2006-06-17T16:01:21} or @code{2006-06-17}. The default base is 
UTC.
+
+Enable @option{drift-fix} (i386 targets only) if you experience time drift 
problems
+in Windows with ACPI HAL. This option will try to figure out how many timer
+interrupts were not processed by the Windows guest and will re-inject them.
 ETEXI
 
 DEF("icount", HAS_ARG, QEMU_OPTION_icount, \
diff --git a/sysemu.h b/sysemu.h
index ac16c21..a018b47 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -4,6 +4,7 @@
 
 #include "qemu-common.h"
 #include "qemu-option.h"
+#include "qemu-timer.h"
 #include "sys-queue.h"
 #include "qdict.h"
 
diff --git a/vl.c b/vl.c
index 2e36c6a..8437d2c 100644
--- a/vl.c
+++ b/vl.c
@@ -1588,6 +1588,84 @@ int qemu_timedate_diff(struct tm *tm)
     return seconds - time(NULL);
 }
 
+static void configure_rtc_date_offset(const char *startdate, int legacy)
+{
+    time_t rtc_start_date;
+    struct tm tm;
+
+    if (!strcmp(startdate, "now") && legacy) {
+        rtc_date_offset = -1;
+    } else {
+        if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
+                   &tm.tm_year,
+                   &tm.tm_mon,
+                   &tm.tm_mday,
+                   &tm.tm_hour,
+                   &tm.tm_min,
+                   &tm.tm_sec) == 6) {
+            /* OK */
+        } else if (sscanf(startdate, "%d-%d-%d",
+                          &tm.tm_year,
+                          &tm.tm_mon,
+                          &tm.tm_mday) == 3) {
+            tm.tm_hour = 0;
+            tm.tm_min = 0;
+            tm.tm_sec = 0;
+        } else {
+            goto date_fail;
+        }
+        tm.tm_year -= 1900;
+        tm.tm_mon--;
+        rtc_start_date = mktimegm(&tm);
+        if (rtc_start_date == -1) {
+        date_fail:
+            fprintf(stderr, "Invalid date format. Valid format are:\n"
+                            "'2006-06-17T16:01:21' or '2006-06-17'\n");
+            exit(1);
+        }
+        rtc_date_offset = time(NULL) - rtc_start_date;
+    }
+}
+
+static void configure_rtc(const char *options)
+{
+    static const char * const params[] = {
+        "base",
+#ifdef CONFIG_TARGET_I386
+        "td-hack",
+#endif
+        NULL
+    };
+    char buf[1024];
+
+    if (check_params(buf, sizeof(buf), params, options) < 0) {
+        fprintf(stderr, "qemu: unknown rtc parameter '%s' in '%s'\n",
+                buf, options);
+        exit(1);
+    }
+    if (get_param_value(buf, sizeof(buf), "base", options)) {
+        if (!strcmp(buf, "utc")) {
+            rtc_utc = 1;
+        } else if (!strcmp(buf, "localtime")) {
+            rtc_utc = 0;
+        } else {
+            configure_rtc_date_offset(buf, 0);
+        }
+    }
+#ifdef CONFIG_TARGET_I386
+    if (get_param_value(buf, sizeof(buf), "drift-hack", options)) {
+        if (!strcmp(buf, "on")) {
+            rtc_td_hack = 1;
+        } else if (!strcmp(buf, "off")) {
+            rtc_td_hack = 0;
+        } else {
+            fprintf(stderr, "qemu: invalid option value '%s'\n", buf);
+            exit(1);
+        }
+    }
+#endif
+}
+
 #ifdef _WIN32
 static void socket_cleanup(void)
 {
@@ -4905,6 +4983,8 @@ int main(int argc, char **argv, char **envp)
     CPUState *env;
     int show_vnc_port = 0;
 
+    init_clocks();
+
     qemu_errors_to_file(stderr);
     qemu_cache_utils_init(envp);
 
@@ -5591,42 +5671,10 @@ int main(int argc, char **argv, char **envp)
                 configure_alarms(optarg);
                 break;
             case QEMU_OPTION_startdate:
-                {
-                    struct tm tm;
-                    time_t rtc_start_date;
-                    if (!strcmp(optarg, "now")) {
-                        rtc_date_offset = -1;
-                    } else {
-                        if (sscanf(optarg, "%d-%d-%dT%d:%d:%d",
-                               &tm.tm_year,
-                               &tm.tm_mon,
-                               &tm.tm_mday,
-                               &tm.tm_hour,
-                               &tm.tm_min,
-                               &tm.tm_sec) == 6) {
-                            /* OK */
-                        } else if (sscanf(optarg, "%d-%d-%d",
-                                          &tm.tm_year,
-                                          &tm.tm_mon,
-                                          &tm.tm_mday) == 3) {
-                            tm.tm_hour = 0;
-                            tm.tm_min = 0;
-                            tm.tm_sec = 0;
-                        } else {
-                            goto date_fail;
-                        }
-                        tm.tm_year -= 1900;
-                        tm.tm_mon--;
-                        rtc_start_date = mktimegm(&tm);
-                        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");
-                            exit(1);
-                        }
-                        rtc_date_offset = time(NULL) - rtc_start_date;
-                    }
-                }
+                configure_rtc_date_offset(optarg, 1);
+                break;
+            case QEMU_OPTION_rtc:
+                configure_rtc(optarg);
                 break;
             case QEMU_OPTION_tb_size:
                 tb_size = strtol(optarg, NULL, 0);
@@ -5777,7 +5825,6 @@ int main(int argc, char **argv, char **envp)
     setvbuf(stdout, NULL, _IOLBF, 0);
 #endif
 
-    init_clocks();
     if (init_timer_alarm() < 0) {
         fprintf(stderr, "could not initialize alarm timer\n");
         exit(1);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]