From patchwork Thu Oct 11 12:23:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Pisarenko X-Patchwork-Id: 10636581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3AAC016B1 for ; Thu, 11 Oct 2018 12:27:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B6F02B40A for ; Thu, 11 Oct 2018 12:27:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FDE82B435; Thu, 11 Oct 2018 12:27:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B7DE72B40A for ; Thu, 11 Oct 2018 12:27:48 +0000 (UTC) Received: from localhost ([::1]:34130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAa4B-0007Ed-7T for patchwork-qemu-devel@patchwork.kernel.org; Thu, 11 Oct 2018 08:27:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41251) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAa39-00064I-H8 for qemu-devel@nongnu.org; Thu, 11 Oct 2018 08:26:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gAa38-00075i-FS for qemu-devel@nongnu.org; Thu, 11 Oct 2018 08:26:43 -0400 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]:34456) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gAa38-00074w-7l for qemu-devel@nongnu.org; Thu, 11 Oct 2018 08:26:42 -0400 Received: by mail-lj1-x244.google.com with SMTP id j17-v6so8049502lja.1 for ; Thu, 11 Oct 2018 05:26:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=gzWDSZUzWgGXQ9uuXM46zuT9yZpYXYodmEukxQ4Glsw=; b=Ridifx6PdY6q9N9AvlVuZfQ4mUj4UdFs8/F2byDysY8LDqNzD2BNeHmWnZLw4gO1DV rDhwp3IAi8jHb0OlZXhYBs7MP51HlQ5p8Jh89598pbAvl5R+HNAEQ/6ikR99uc/KuXcV 6rSMdEP6o3r2xms5uCgjduZywlhfBevjJ1MassV3MSXkosyCbTQCZdEtpMDBU+lX67zK mRp8AuwiEC2floTjjs9f+4D6SJB5DkJ34OAC5CCGSq/FXlUbA44F3lUgnnG4b1GRuGui 43riRU/pvMJP4lDxgA3JlL8DOEK9mlkWJ6c1qEcmtBDN+9TSeh+2/2M1lCGJj6YWnUX8 JIUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=gzWDSZUzWgGXQ9uuXM46zuT9yZpYXYodmEukxQ4Glsw=; b=gGp1neif1mfHVwK5t1dttKY9Bt5qqCfLAaCDWSQ88DkjyJ5V7Sb1Lg7M1anY6CI0VB M93YYeKrzxYKBrraBH2uibdytpu5Gyma9vyDQh9P1KR1NcKH41q8v8B/gbQccaVPUNTN TQG2hYqHytu2JBSGkjT01zBv4be8otn6PLVP0HVzMQo7gDpvmaCV0po+TdcT3ztW4NjA O8oJ8DJijmO/d4TCOr3DEDl4W0kKWKbgI5RxujDWesnodN4rLAMNayrRpLPKjcR1t6mn QgabOgi6rKOyIYn4Cr+U2QXWV+dDqjOq17S9zemsCC8w50lLcLBYt/jQTZhPY3eLD9yQ Vdvg== X-Gm-Message-State: ABuFfogMBpwouou1GYlFTFoaYgjguJrcUugvVe7GaMVJZz4RMaOQnBPl LWYHV/t/GjEPAtHNFynMYCNZ/tMB X-Google-Smtp-Source: ACcGV60CYddFMmEGstgEgktF3EbPtpW2w2JJs8y0o2u5TrkJfFS2r3ZJ20owMhVL1zlCQNWXCNoAHQ== X-Received: by 2002:a2e:6d0a:: with SMTP id i10-v6mr1189905ljc.14.1539260800501; Thu, 11 Oct 2018 05:26:40 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id 33-v6sm5713890lfu.64.2018.10.11.05.26.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Oct 2018 05:26:39 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Thu, 11 Oct 2018 18:23:16 +0600 Message-Id: <4088cc0a4affe3d68a3280013370fc9027fa6ccc.1539259394.git.artem.k.pisarenko@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::244 Subject: [Qemu-devel] [PATCH 1/4] vl: improve/fix documentation related to RTC function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Artem Pisarenko Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Documentation describing -rtc option updated to better match current implementation and highlight some important specifics. Signed-off-by: Artem Pisarenko --- qemu-options.hx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index f139459..4a9c065 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3458,25 +3458,29 @@ HXCOMM Silently ignored for compatibility DEF("clock", HAS_ARG, QEMU_OPTION_clock, "", QEMU_ARCH_ALL) DEF("rtc", HAS_ARG, QEMU_OPTION_rtc, \ - "-rtc [base=utc|localtime|date][,clock=host|rt|vm][,driftfix=none|slew]\n" \ + "-rtc [base=utc|localtime|][,clock=host|rt|vm][,driftfix=none|slew]\n" \ " set the RTC base and clock, enable drift fix for clock ticks (x86 only)\n", QEMU_ARCH_ALL) STEXI -@item -rtc [base=utc|localtime|@var{date}][,clock=host|vm][,driftfix=none|slew] +@item -rtc [base=utc|localtime|@var{datetime}][,clock=host|rt|vm][,driftfix=none|slew] @findex -rtc 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 +MS-DOS or Windows. To start at a specific point in time, provide @var{datetime} in the format @code{2006-06-17T16:01:21} or @code{2006-06-17}. The default base is UTC. By default the RTC is driven by the host system time. This allows using of the RTC as accurate reference clock inside the guest, specifically if the host time is smoothly following an accurate external reference clock, e.g. via NTP. If you want to isolate the guest time from the host, you can set @option{clock} -to @code{rt} instead. To even prevent it from progressing during suspension, -you can set it to @code{vm}. +to @code{rt} instead, which provides host monotonic clock if host support it. +To even prevent it from progressing during suspension, you can set it to +@code{vm} (virtual clock). Virtual clock is the clock seen by guest, +In icount mode of emulation its (long term) speed will be different from +any host clock, when icount configured to non-auto value or virtual cpu sleeping +is off, and no synchronization algorithm is active. 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 From patchwork Thu Oct 11 12:23:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Pisarenko X-Patchwork-Id: 10636583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 30CBC16B1 for ; Thu, 11 Oct 2018 12:28:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 246622B3F1 for ; Thu, 11 Oct 2018 12:28:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 177802B3F9; Thu, 11 Oct 2018 12:28:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 91E092B3F1 for ; Thu, 11 Oct 2018 12:28:38 +0000 (UTC) Received: from localhost ([::1]:34132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAa4z-0007uS-L8 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 11 Oct 2018 08:28:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAa3h-0006X2-9V for qemu-devel@nongnu.org; Thu, 11 Oct 2018 08:27:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gAa3c-0007Wg-5H for qemu-devel@nongnu.org; Thu, 11 Oct 2018 08:27:15 -0400 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]:43682) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gAa3b-0007Ta-QH for qemu-devel@nongnu.org; Thu, 11 Oct 2018 08:27:12 -0400 Received: by mail-lf1-x12a.google.com with SMTP id p34-v6so6519274lfg.10 for ; Thu, 11 Oct 2018 05:27:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=AwBVyk/YwtevkvfRia9eCprmQWk8hGxtTrFN2c2/fwE=; b=eB6IjwGsVle6KI2Nyb2sla/lXYxAzhcooLO2NMYh5WcbcD72sOZQ26g9srANwVvGTy ohwlgTw+5AR1SUTVFxwJDti/yjZn5UxHePUwRuL0Z7biR4SDmOwCQreDrmy8SFz/X0sR f7a1CdcbyAQVXE0h8UmH4e/z23jIMIBUZJCs00ILnJsIoNS5ls9a1wqai4hH+iTpCWfX yiKs4AoGKBD97sDBWZnFY+aLPRNV2YzHBMJS9rNTvR2dZ6JuPyM4PJUZITo9EFFv5pwH rSEHYibYKCJ/wjlIhjVsNbsn/tiZ5LKSx2ydTxgdOGIkfo+oKcIgyOr/1q6LH2G58fFl PmAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=AwBVyk/YwtevkvfRia9eCprmQWk8hGxtTrFN2c2/fwE=; b=udX2gsfTR5kvmYMLoRe4kCAwniH/7ZUI0c42+qZJQGDU6NVSkQIA0lbmkEc7xYnVX8 jd5GI9uCGPCZme+dvPTFh7oP0nOQ5HUBUVbMW6EEwC2qWKVrgPJkRQZiuEO8RO5ejU2K B4tkf9jwW/hP8IaeBexH02/0fngivy7JaxacHQlGA7rf2F1hr4S8EGCPCLTACewBEjZx lvk06QnlPvfHZU/WLyu8XrG6LfeSedC6//4iNRkSccu/OwnIHXIP7zOjNP6mI63bfgpU +OoK4JdbwMfbeabjV+IOmMuUR4MssuU2o9R7+hXMeCWvyox8wnb1Bjz9PCFVgcS/U5TC G8JA== X-Gm-Message-State: ABuFfohRa+7Cr2h51rWCQzm5WL6r92F25emPBwZBK8oFIVT0xTfgAIQQ QwtqJZtvQGXmNEYctrF0NTcn/x1H X-Google-Smtp-Source: ACcGV62ES4Z4NOIf+/pr6IiSV2PwC94Cd/NGHXXdKr5d7CBjul5Yk9YsdW1qhSOJQddRXnzKnPP04g== X-Received: by 2002:a19:4411:: with SMTP id r17-v6mr1062573lfa.87.1539260829037; Thu, 11 Oct 2018 05:27:09 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id 33-v6sm5713890lfu.64.2018.10.11.05.27.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Oct 2018 05:27:08 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Thu, 11 Oct 2018 18:23:17 +0600 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::12a Subject: [Qemu-devel] [PATCH 2/4] vl: refactor -rtc option references X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Artem Pisarenko Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Improve code readability and prepare for fixing bug #1797033 Signed-off-by: Artem Pisarenko --- vl.c | 82 +++++++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/vl.c b/vl.c index 4e25c78..3a1346f 100644 --- a/vl.c +++ b/vl.c @@ -147,8 +147,13 @@ bool enable_cpu_pm = false; int nb_nics; NICInfo nd_table[MAX_NICS]; int autostart; -static int rtc_utc = 1; -static int rtc_date_offset = -1; /* -1 means no change */ +static enum { + RTC_BASE_UTC, + RTC_BASE_LOCALTIME, + RTC_BASE_DATETIME, +} rtc_base_type = RTC_BASE_UTC; +static int rtc_host_datetime_offset = -1; /* valid only for host rtc_clock and + rtc_base_type=RTC_BASE_DATETIME */ QEMUClockType rtc_clock; int vga_interface_type = VGA_NONE; static DisplayOptions dpy; @@ -782,26 +787,30 @@ void qemu_system_vmstop_request(RunState state) /***********************************************************/ /* real time host monotonic timer */ -static time_t qemu_time(void) +static time_t qemu_timedate(void) { return qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000; } /***********************************************************/ -/* host time/date access */ +/* RTC reference time/date access */ void qemu_get_timedate(struct tm *tm, int offset) { - time_t ti = qemu_time(); + time_t ti = qemu_timedate(); ti += offset; - if (rtc_date_offset == -1) { - if (rtc_utc) - gmtime_r(&ti, tm); - else - localtime_r(&ti, tm); - } else { - ti -= rtc_date_offset; + + switch (rtc_base_type) { + case RTC_BASE_UTC: + gmtime_r(&ti, tm); + break; + case RTC_BASE_LOCALTIME: + localtime_r(&ti, tm); + break; + case RTC_BASE_DATETIME: + ti -= rtc_host_datetime_offset; gmtime_r(&ti, tm); + break; } } @@ -809,23 +818,28 @@ int qemu_timedate_diff(struct tm *tm) { time_t seconds; - if (rtc_date_offset == -1) - if (rtc_utc) - seconds = mktimegm(tm); - else { - struct tm tmp = *tm; - tmp.tm_isdst = -1; /* use timezone to figure it out */ - seconds = mktime(&tmp); - } - else - seconds = mktimegm(tm) + rtc_date_offset; - - return seconds - qemu_time(); + switch (rtc_base_type) { + case RTC_BASE_UTC: + seconds = mktimegm(tm); + break; + case RTC_BASE_LOCALTIME: + { + struct tm tmp = *tm; + tmp.tm_isdst = -1; /* use timezone to figure it out */ + seconds = mktime(&tmp); + break; + } + case RTC_BASE_DATETIME: + seconds = mktimegm(tm) + rtc_host_datetime_offset; + break; + } + + return seconds - qemu_timedate(); } -static void configure_rtc_date_offset(const char *startdate) +static void configure_rtc_host_datetime_offset(const char *startdate) { - time_t rtc_start_date; + time_t rtc_start_datetime; struct tm tm; if (sscanf(startdate, "%d-%d-%dT%d:%d:%d", &tm.tm_year, &tm.tm_mon, @@ -841,15 +855,16 @@ static void configure_rtc_date_offset(const char *startdate) } tm.tm_year -= 1900; tm.tm_mon--; - rtc_start_date = mktimegm(&tm); - if (rtc_start_date == -1) { + rtc_start_datetime = mktimegm(&tm); + if (rtc_start_datetime == -1) { date_fail: - error_report("invalid date format"); + error_report("invalid datetime format"); error_printf("valid formats: " "'2006-06-17T16:01:21' or '2006-06-17'\n"); exit(1); } - rtc_date_offset = qemu_time() - rtc_start_date; + rtc_host_datetime_offset = (qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000) + - rtc_start_datetime; } static void configure_rtc(QemuOpts *opts) @@ -859,15 +874,16 @@ static void configure_rtc(QemuOpts *opts) value = qemu_opt_get(opts, "base"); if (value) { if (!strcmp(value, "utc")) { - rtc_utc = 1; + rtc_base_type = RTC_BASE_UTC; } else if (!strcmp(value, "localtime")) { Error *blocker = NULL; - rtc_utc = 0; + rtc_base_type = RTC_BASE_LOCALTIME; error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "-rtc base=localtime"); replay_add_blocker(blocker); } else { - configure_rtc_date_offset(value); + rtc_base_type = RTC_BASE_DATETIME; + configure_rtc_host_datetime_offset(value); } } value = qemu_opt_get(opts, "clock"); From patchwork Thu Oct 11 12:23:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Pisarenko X-Patchwork-Id: 10636585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F6F25CAF for ; Thu, 11 Oct 2018 12:30:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82A262B434 for ; Thu, 11 Oct 2018 12:30:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76F752B43A; Thu, 11 Oct 2018 12:30:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EF1092B434 for ; Thu, 11 Oct 2018 12:30:09 +0000 (UTC) Received: from localhost ([::1]:34143 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAa6T-0000dN-8c for patchwork-qemu-devel@patchwork.kernel.org; Thu, 11 Oct 2018 08:30:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAa3l-0006bg-Q9 for qemu-devel@nongnu.org; Thu, 11 Oct 2018 08:27:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gAa3k-0007e3-RM for qemu-devel@nongnu.org; Thu, 11 Oct 2018 08:27:21 -0400 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]:44771) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gAa3k-0007d7-JI for qemu-devel@nongnu.org; Thu, 11 Oct 2018 08:27:20 -0400 Received: by mail-lj1-x243.google.com with SMTP id v6-v6so8008899ljc.11 for ; Thu, 11 Oct 2018 05:27:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=iTpvEwhCW3Qu2a9KnBZWV1Ybe4KijxMSs52g6aOUgXo=; b=mHTB06mI8zqAqyqmicAGzj+WGonTXr1eXm01/OndPndCXOMubMNVAI69M7LrnpRlaU UDVcz6U1i1zTb62Ak2wwCXCcZdrwRZwObDm4H/oHNJMsMmhpJnlRQ1I9F9dQhHfZLU3Y sUBKn6AOThu/kv4OedMpI9pGqhhqdmUjWeZ7FvjNHS8JovrpJHIiOGNT1yDkRzHVHQ5I HEUQeNgxaF/g4tknIw2h+do/+UgXLKhUn4/u7mP+E8nm4Yae5iXT854h1pRKrYhEU2BU db6Rb8mE19kbvzV1eAmwNVR1lS7chURBIPmuffZEn1G2+5brSg6XsBIUK7KIOWzjlOVd /8Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=iTpvEwhCW3Qu2a9KnBZWV1Ybe4KijxMSs52g6aOUgXo=; b=r3kSI7q8NR2Hnwnxz00pToVSXbsV/Zi+6Ac/lfnz8UsO+NiOkunpqiwFM/JxLGaWdm +kbGl56d8aslDyUoZO8I6xYJJ7Pt0X8Pg8kZAPz2FB91gDAQiZRI++HOo3HLTuDF1L3M AmXZuoSs1jDHmU/WRvCBY0GuqYCBxqPaHegUD29o0sAaGpo8gCq7rGgAK9exWOKHm6a/ Af3bMTIFYRYOy+y4vT2RThtVrqk7UFpRtAFMpGdrZoFNibL5jMCPFkeM9nlIXffT5z8q na2TY3qKGAPxEHCbbTYVTwZ4otHN6c7uC1k5p/Dw5Dl2g6gzdq34jIdTjDy5QpG57mxU LC6w== X-Gm-Message-State: ABuFfoh9WQPb/+hBxXE7YwVpdtfdMhBjUoalBtjmfhVxzz6Iztc1eipG m5l1rnS7jGDPfXJmZROwglZsDq/j X-Google-Smtp-Source: ACcGV60Hvn5Qo984nmmEMfmtgUINfBiBIiaWJZj5z/vrvTfM80VxpkyeN5UvcGpkyXkTvliKnfvS1Q== X-Received: by 2002:a2e:21d2:: with SMTP id h79-v6mr1094087lji.46.1539260838474; Thu, 11 Oct 2018 05:27:18 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id 33-v6sm5713890lfu.64.2018.10.11.05.27.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Oct 2018 05:27:17 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Thu, 11 Oct 2018 18:23:18 +0600 Message-Id: <5299b9caab102ac99411cfb51e48f9ac5bb8027b.1539259394.git.artem.k.pisarenko@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::243 Subject: [Qemu-devel] [PATCH 3/4] Fixes RTC bug with base datetime shifts in clock=vm X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Artem Pisarenko Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This makes all current "-rtc" option parameters combinations produce fixed/unambiguous RTC timedate reference for hardware emulation frontends. It restores determinism of guest execution when used with clock=vm and specified base value. Buglink: https://bugs.launchpad.net/qemu/+bug/1797033 Signed-off-by: Artem Pisarenko --- vl.c | 54 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/vl.c b/vl.c index 3a1346f..d60018f 100644 --- a/vl.c +++ b/vl.c @@ -152,8 +152,10 @@ static enum { RTC_BASE_LOCALTIME, RTC_BASE_DATETIME, } rtc_base_type = RTC_BASE_UTC; -static int rtc_host_datetime_offset = -1; /* valid only for host rtc_clock and - rtc_base_type=RTC_BASE_DATETIME */ +static time_t rtc_ref_start_datetime; +static int rtc_realtime_clock_offset; /* used only with QEMU_CLOCK_REALTIME */ +static int rtc_host_datetime_offset = -1; /* valid & used only with + RTC_BASE_DATETIME */ QEMUClockType rtc_clock; int vga_interface_type = VGA_NONE; static DisplayOptions dpy; @@ -785,32 +787,42 @@ void qemu_system_vmstop_request(RunState state) } /***********************************************************/ -/* real time host monotonic timer */ - -static time_t qemu_timedate(void) +/* RTC reference time/date access */ +static time_t qemu_ref_timedate(void) { - return qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000; + time_t value = qemu_clock_get_ms(rtc_clock) / 1000; + switch (rtc_clock) { + case QEMU_CLOCK_REALTIME: + value -= rtc_realtime_clock_offset; + /* no break */ + case QEMU_CLOCK_VIRTUAL: + value += rtc_ref_start_datetime; + break; + case QEMU_CLOCK_HOST: + if (rtc_base_type == RTC_BASE_DATETIME) { + value -= rtc_host_datetime_offset; + } + break; + default: + assert(0); + } + return value; } -/***********************************************************/ -/* RTC reference time/date access */ void qemu_get_timedate(struct tm *tm, int offset) { - time_t ti = qemu_timedate(); + time_t ti = qemu_ref_timedate(); ti += offset; switch (rtc_base_type) { + case RTC_BASE_DATETIME: case RTC_BASE_UTC: gmtime_r(&ti, tm); break; case RTC_BASE_LOCALTIME: localtime_r(&ti, tm); break; - case RTC_BASE_DATETIME: - ti -= rtc_host_datetime_offset; - gmtime_r(&ti, tm); - break; } } @@ -819,6 +831,7 @@ int qemu_timedate_diff(struct tm *tm) time_t seconds; switch (rtc_base_type) { + case RTC_BASE_DATETIME: case RTC_BASE_UTC: seconds = mktimegm(tm); break; @@ -829,15 +842,12 @@ int qemu_timedate_diff(struct tm *tm) seconds = mktime(&tmp); break; } - case RTC_BASE_DATETIME: - seconds = mktimegm(tm) + rtc_host_datetime_offset; - break; } - return seconds - qemu_timedate(); + return seconds - qemu_ref_timedate(); } -static void configure_rtc_host_datetime_offset(const char *startdate) +static void configure_rtc_base_datetime(const char *startdate) { time_t rtc_start_datetime; struct tm tm; @@ -863,8 +873,8 @@ static void configure_rtc_host_datetime_offset(const char *startdate) "'2006-06-17T16:01:21' or '2006-06-17'\n"); exit(1); } - rtc_host_datetime_offset = (qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000) - - rtc_start_datetime; + rtc_host_datetime_offset = rtc_ref_start_datetime - rtc_start_datetime; + rtc_ref_start_datetime = rtc_start_datetime; } static void configure_rtc(QemuOpts *opts) @@ -883,7 +893,7 @@ static void configure_rtc(QemuOpts *opts) replay_add_blocker(blocker); } else { rtc_base_type = RTC_BASE_DATETIME; - configure_rtc_host_datetime_offset(value); + configure_rtc_base_datetime(value); } } value = qemu_opt_get(opts, "clock"); @@ -3034,6 +3044,8 @@ int main(int argc, char **argv, char **envp) exit(1); } rtc_clock = QEMU_CLOCK_HOST; + rtc_ref_start_datetime = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000; + rtc_realtime_clock_offset = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000; QLIST_INIT (&vm_change_state_head); os_setup_early_signal_handling(); From patchwork Thu Oct 11 12:23:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Pisarenko X-Patchwork-Id: 10636587 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4701916B1 for ; Thu, 11 Oct 2018 12:30:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39A0D2B434 for ; Thu, 11 Oct 2018 12:30:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DF372B43A; Thu, 11 Oct 2018 12:30:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A36AC2B434 for ; Thu, 11 Oct 2018 12:30:31 +0000 (UTC) Received: from localhost ([::1]:34147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAa6p-0000wK-05 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 11 Oct 2018 08:30:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41464) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAa46-0007B1-Kx for qemu-devel@nongnu.org; Thu, 11 Oct 2018 08:27:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gAa42-00082d-Nj for qemu-devel@nongnu.org; Thu, 11 Oct 2018 08:27:42 -0400 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]:46837) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gAa42-00081X-AR for qemu-devel@nongnu.org; Thu, 11 Oct 2018 08:27:38 -0400 Received: by mail-lj1-x241.google.com with SMTP id x3-v6so8009684lji.13 for ; Thu, 11 Oct 2018 05:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=grwMuXdwxT2SR3m60LssPVc9MuHTUquDCMMf5rAv7NI=; b=jxf3zFsbYmF7EBIU6PDBtTRlAgvdgJ1gSt/phUPTb1THfaxOJihBreb8WioAWlvmfp PYJMUVazioYwl2KoNQcxWd/i2+U6TtNXrKxmWZrbIbeV6USKQmbwRMr8tvkb7Qgg6EJt SMn9NM56oIDFSu8NMQFAoOb/MM7TXQo3WH2YY3FsBk6i0WLKFUuKFu+NOHU3c/Fq438G B85pH2A2r7Q7L8HO1TvjQa2CchHSPso+Jwky5or+pHOgRNOZbcj1jitXFV2ZylIWFJ2b ppMBkHbRAke0uymsqgnqEoArQJxDumYj95xHap3B7mf7M/fjBCvJXTURqhF5+jNN9kxw 9RIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=grwMuXdwxT2SR3m60LssPVc9MuHTUquDCMMf5rAv7NI=; b=LKq6fDNjAWAgWWycG9j9HeN4R0J5lPNiYT9jG7XryQS8agHD3M/PBa+Lyq4YCNG+Y0 m5Q0TjmdlixXUCpNNVXEcc7svdveu6nLDSIvC+voTnNdnVgeXTX3dPzfviySIuAxgv3I z0LFrrYK4RHxEFJt0QOAeNYP/a+KxbGeCgERu4mbmAeBGswVXrHyFBV8KVjGCx/LLfSd I09M4GFmz6ufhzE+xwjt6eKOqodYMuXmb+eR5exoKInw4OxfPjGxdzijV0xKKwHHRyYk LaPahvzUCkNlgPuXIRNo3zmj2YbWXPKpgSp3yN4U/NMFwskDfEBhq41raDtUjF3TDE0O PORw== X-Gm-Message-State: ABuFfojqtY9fLYIWdX1n8qxRusQTPqLa6R9sAZp6/nmBZMsMq4hp3htn JbjQcbEFAv6bYhAIYd1SXH6bPseE X-Google-Smtp-Source: ACcGV62xCS58SXIiFbkpkc2+u1jU4uYXdvWuTDxx8mNOy485edx1JUR+aYxTu4X6nNBwECwzkEY4EQ== X-Received: by 2002:a2e:651d:: with SMTP id z29-v6mr1174991ljb.36.1539260856594; Thu, 11 Oct 2018 05:27:36 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id 33-v6sm5713890lfu.64.2018.10.11.05.27.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Oct 2018 05:27:35 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Thu, 11 Oct 2018 18:23:19 +0600 Message-Id: <27268f8d488b4ec134a4475139bf0b50459cbf96.1539259394.git.artem.k.pisarenko@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::241 Subject: [Qemu-devel] [PATCH 4/4] vl, qapi: offset value calculation in RTC_CHANGE event reverted to match behavior before #1797033 bugfix and documented X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Artem Pisarenko , Markus Armbruster , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Return value of qemu_timedate_diff(), used for calculation offset in QAPI 'RTC_CHANGE' event restored to keep compatibility, although it isn't documented that difference is relative to host clock advancement. Added important note to 'RTC_CHANGE' event description to highlight established implementation specifics. Signed-off-by: Artem Pisarenko --- qapi/misc.json | 3 ++- vl.c | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/qapi/misc.json b/qapi/misc.json index ada9af5..ed866f2 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -3070,7 +3070,8 @@ # Emitted when the guest changes the RTC time. # # @offset: offset between base RTC clock (as specified by -rtc base), and -# new RTC clock value +# new RTC clock value. Note that value will be different depending +# on clock choosen to drive RTC (specified by -rtc clock). # # Note: This event is rate-limited. # diff --git a/vl.c b/vl.c index d60018f..72a4173 100644 --- a/vl.c +++ b/vl.c @@ -788,10 +788,10 @@ void qemu_system_vmstop_request(RunState state) /***********************************************************/ /* RTC reference time/date access */ -static time_t qemu_ref_timedate(void) +static time_t qemu_ref_timedate(QEMUClockType clock) { - time_t value = qemu_clock_get_ms(rtc_clock) / 1000; - switch (rtc_clock) { + time_t value = qemu_clock_get_ms(clock) / 1000; + switch (clock) { case QEMU_CLOCK_REALTIME: value -= rtc_realtime_clock_offset; /* no break */ @@ -811,7 +811,7 @@ static time_t qemu_ref_timedate(void) void qemu_get_timedate(struct tm *tm, int offset) { - time_t ti = qemu_ref_timedate(); + time_t ti = qemu_ref_timedate(rtc_clock); ti += offset; @@ -844,7 +844,7 @@ int qemu_timedate_diff(struct tm *tm) } } - return seconds - qemu_ref_timedate(); + return seconds - qemu_ref_timedate(QEMU_CLOCK_HOST); } static void configure_rtc_base_datetime(const char *startdate)