From patchwork Tue Sep 15 11:36:04 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 33651 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 8BE42B7BAA for ; Tue, 15 Sep 2009 22:32:51 +1000 (EST) Received: from localhost ([127.0.0.1]:56316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MnXDD-0002QE-U9 for incoming@patchwork.ozlabs.org; Tue, 15 Sep 2009 08:32:48 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MnWx2-0005Zr-0x for qemu-devel@nongnu.org; Tue, 15 Sep 2009 08:16:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MnWwx-0005Tb-JP for qemu-devel@nongnu.org; Tue, 15 Sep 2009 08:16:03 -0400 Received: from [199.232.76.173] (port=49218 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MnWww-0005T1-Q6 for qemu-devel@nongnu.org; Tue, 15 Sep 2009 08:15:58 -0400 Received: from thoth.sbs.de ([192.35.17.2]:19421) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MnWwv-00021y-Cs for qemu-devel@nongnu.org; Tue, 15 Sep 2009 08:15:58 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.12.11.20060308/8.12.11) with ESMTP id n8FCFsHA015536; Tue, 15 Sep 2009 14:15:55 +0200 Received: from [139.25.109.167] (mchn012c.mchp.siemens.de [139.25.109.167] (may be forged)) by mail1.siemens.de (8.12.11.20060308/8.12.11) with ESMTP id n8FCFs7T012164; Tue, 15 Sep 2009 14:15:54 +0200 Resent-From: Jan Kiszka Resent-To: Anthony Liguori Resent-Cc: qemu-devel , Glauber Costa , Blue Swirl , Dor Laor , Jamie Lokier Resent-Date: Tue, 15 Sep 2009 14:15:54 +0200 Resent-Message-Id: <4AAF857A.1060808@siemens.com> Resent-User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 From: Jan Kiszka To: Anthony Liguori Date: Tue, 15 Sep 2009 13:36:04 +0200 Message-ID: <20090915113604.8313.37848.stgit@mchn012c.ww002.siemens.net> In-Reply-To: <20090915113603.8313.49563.stgit@mchn012c.ww002.siemens.net> References: <20090915113603.8313.49563.stgit@mchn012c.ww002.siemens.net> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 Resent-Date: Tue, 15 Sep 2009 08:16:03 -0400 Cc: Blue Swirl , Glauber Costa , Dor Laor , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH v3 4/5] Refactor RTC command line switches X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Deprecate -localtime, -setdate and -rtc-td-hack in favor of a new unified command line switch: -rtc [base=utc|localtime|date][,driftfix=none|slew] Signed-off-by: Jan Kiszka --- qemu-config.c | 17 ++++++++ qemu-config.h | 1 qemu-options.hx | 47 ++++++++++++----------- vl.c | 111 ++++++++++++++++++++++++++++++++++++++----------------- 4 files changed, 119 insertions(+), 57 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 39bf6a9..45a3e09 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -151,6 +151,23 @@ QemuOptsList qemu_device_opts = { }, }; +QemuOptsList qemu_rtc_opts = { + .name = "rtc", + .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), + .desc = { + { + .name = "base", + .type = QEMU_OPT_STRING, +#ifdef TARGET_I386 + },{ + .name = "driftfix", + .type = QEMU_OPT_STRING, +#endif + }, + { /* end if list */ } + }, +}; + static QemuOptsList *lists[] = { &qemu_drive_opts, &qemu_chardev_opts, diff --git a/qemu-config.h b/qemu-config.h index 13b0f19..4ae7b74 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -4,6 +4,7 @@ extern QemuOptsList qemu_drive_opts; extern QemuOptsList qemu_chardev_opts; extern QemuOptsList qemu_device_opts; +extern QemuOptsList qemu_rtc_opts; int qemu_set_option(const char *str); diff --git a/qemu-options.hx b/qemu-options.hx index d3aa55b..586474e 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 -@item -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, @@ -1500,23 +1494,32 @@ 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 -@item -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][,driftfix=none|slew]\n" \ + " set the RTC base, enable drift fix for clock ticks\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 -@item -startdate @var{date} -Set the initial date of the real time clock. Valid formats for -@var{date} are: @code{now} or @code{2006-06-17T16:01:21} or -@code{2006-06-17}. The default value is @code{now}. +@item -rtc [base=utc|localtime|@var{date}][,driftfix=none|slew] +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{driftfix} (i386 targets only) if you experience time drift problems, +specifically with Windows' 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/vl.c b/vl.c index 88113e6..0594ee8 100644 --- a/vl.c +++ b/vl.c @@ -1577,6 +1577,74 @@ 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 formats 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(QemuOpts *opts) +{ + const char *value; + + value = qemu_opt_get(opts, "base"); + if (value) { + if (!strcmp(value, "utc")) { + rtc_utc = 1; + } else if (!strcmp(value, "localtime")) { + rtc_utc = 0; + } else { + configure_rtc_date_offset(value, 0); + } + } +#ifdef CONFIG_TARGET_I386 + value = qemu_opt_get(opts, "driftfix"); + if (value) { + if (!strcmp(buf, "slew")) { + rtc_td_hack = 1; + } else if (!strcmp(buf, "none")) { + rtc_td_hack = 0; + } else { + fprintf(stderr, "qemu: invalid option value '%s'\n", value); + exit(1); + } + } +#endif +} + #ifdef _WIN32 static void socket_cleanup(void) { @@ -5368,42 +5436,15 @@ 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: + opts = qemu_opts_parse(&qemu_rtc_opts, optarg, NULL); + if (!opts) { + fprintf(stderr, "parse error: %s\n", optarg); + exit(1); } + configure_rtc(opts); break; case QEMU_OPTION_tb_size: tb_size = strtol(optarg, NULL, 0);