From patchwork Wed Oct 17 12:23:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Pisarenko X-Patchwork-Id: 985343 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Sx6LJibw"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42ZrxM6yh4z9s8J for ; Wed, 17 Oct 2018 23:25:43 +1100 (AEDT) Received: from localhost ([::1]:36329 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCktR-0002er-JP for incoming@patchwork.ozlabs.org; Wed, 17 Oct 2018 08:25:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCksa-0002X5-92 for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:24:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCksW-00070L-EB for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:24:48 -0400 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]:42512) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gCksW-0006yK-0Q for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:24:44 -0400 Received: by mail-lj1-x241.google.com with SMTP id y71-v6so24115913lje.9 for ; Wed, 17 Oct 2018 05:24: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=Sx6LJibwSXFczntTNw6wERlVsyIrkn8BgTOP4SazEGTzAeCtn2R0mMPan12n7juFPC yrx8eB6U4eU0wtamPI+C0C01TPAjCCSPpbnvkbG/ZYoDpE19z68fnS3o1wgZ3+cU3Hhj 1SPxjwKNi6FSGWW9LCa3lFgjD/EhjkZ9dIuk7tQU6d156bt7lvzPBipJP+4Cidv8gKp1 aQGhVFf3I72JfFsdWy253NsENglSOTXWmPAhazu6orwetwHTz4E0n1JTi+3QRP14DHTT POgr4v1k7vz+SdKypS9vE0xwFD9b/8dqkR1EEl+LbkiF+MebaxvkKfuR2XziAJR2ZJ6t N1pg== 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=hgpz/AFcYPeIBgFOwMon12v8NmfFn1mpbbLIUpZ9u9V8qFFMTY3eiafWRGc26UB3pc pxGUemHrKNQvovAV8JjosTQRKT2aYiIJZfR3dS6Zi0eRkN4t1mo91Gj4VHxlRzvSYgnA v4EMlXCx0I3NtZTvk1nWM0Xh66a1ccrZkPDL0PTqf14pfgyzLJD48gUrmn3s8WDwpVLk 5AH0T4kMzC7Ffv/VuOYHA1usCBanpl2Zi/2V644Po74iIVUZDkn16MWmaEi/8rS4vyhW r+FLMlcuy1BGJivSsEUZ4Cv94J8OsdDH2YaIM/zHlaj5EMQOcb/rK8y8U0MXRbg5aSrW lhTg== X-Gm-Message-State: ABuFfojY6xfHm1WTQQWuNBrU/8vrcF25rc23BTcWfDMWnh8LfTb5/nA+ DcPmt5KMl3lOzGEEkJ2Uskhm/P+npbo= X-Google-Smtp-Source: ACcGV62UXBsXP1mnyIJhno4Qqeyksdlrw/PTaD5fq8g6uTJVL7uwsf0f08dyUcXSosxteYPR/AwmEA== X-Received: by 2002:a2e:9615:: with SMTP id v21-v6mr16662831ljh.150.1539779081344; Wed, 17 Oct 2018 05:24:41 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id z67-v6sm3704118lfa.14.2018.10.17.05.24.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Oct 2018 05:24:40 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 18:23:00 +0600 Message-Id: <4088cc0a4affe3d68a3280013370fc9027fa6ccc.1539778764.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 v2 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Wed Oct 17 12:23:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Artem Pisarenko X-Patchwork-Id: 985344 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hJZO+k76"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Zrz35kgjz9s9J for ; Wed, 17 Oct 2018 23:27:11 +1100 (AEDT) Received: from localhost ([::1]:36340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCkun-0003pr-Ki for incoming@patchwork.ozlabs.org; Wed, 17 Oct 2018 08:27:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCkse-0002aC-8e for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:24:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCksd-00077A-8m for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:24:52 -0400 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]:42576) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gCksd-00076I-11 for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:24:51 -0400 Received: by mail-lj1-x235.google.com with SMTP id y71-v6so24116293lje.9 for ; Wed, 17 Oct 2018 05:24:50 -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 :mime-version:in-reply-to:references:content-transfer-encoding; bh=ddJ5zRtYlVtYtiBfL/OHyIASkhKnfJAXo1rrTA7IZ5c=; b=hJZO+k76AikPflD7FzQd4wqQfOV4jeLvO3mtzK6eF7l4czd+jzznA9vQM2xZFmywKR fqj3Gm50Ut1EUOWP2+HFFObwTTpSvjdmcQUGguiRQhwM9YhMNVRDYkLSMzW1OEG3ZgxF 8aNt8Jd8lnu4sRz4L+GDXpytX84Ag2At7u/ihMKayhCyqn3gzm64XLyw7PL+X2XQqJdE Tl/bTc0ULXYgeLjrRx+wshukEGMAKLKt8tkTc6f5rNM7pZt8oupxTVyCyNCN2Lw4dgqt iwGRGP1zU4tkPGY5Fi7LTjSYWkgTF4yCRnjhtJWTWEodrUPrXvY+ssvwJYO163oF1XGg sBZA== 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:mime-version:in-reply-to:references :content-transfer-encoding; bh=ddJ5zRtYlVtYtiBfL/OHyIASkhKnfJAXo1rrTA7IZ5c=; b=bXpZ6HlNNSgoqpYr+0g/EMcvHrSOxn2m989j1CtRedBPn910DF/WDL36qNmfh154pC w6iX0mzys2ZpZGdV+GWVHhwRjsGQLk2bfiFTGUbHqRjB4uRVA5ka+o+W3jVplk7DcJfn jf4UHv8EMZCCRAOEEjxEbEbHr6RANFByHV6haBF3u3/xctfUheNdVHX+ekgJLUlwHT2E BHR0JoUxeiIDOzFdQ0aGrkhZFIwvVvXwoBQDyD3UMgFSYM9OPpEK/APYKTwgvx19OZG/ 20FVQ8LdSfrydxUQKDLzwZ8JOM/wzbtO4lhC35LFS6Giczo0i1boBWtH1YQFNmpJ0Mvp nhMg== X-Gm-Message-State: ABuFfog78//ve7ZKMl1Rf7o8nKDvusClmHnNPwtk8UlQNAlo+I6N4lN2 76bxzmkgBbfKcZU/ka2kFX/H5eRpFYU= X-Google-Smtp-Source: ACcGV61zL1EZspkH8s88yTaEpxiJhdHmPn4gxQ0QT+5kAD9vRZXB25E1jouxTg2Gv8GvZj4l8p5Nwg== X-Received: by 2002:a2e:3101:: with SMTP id x1-v6mr16745962ljx.83.1539779089366; Wed, 17 Oct 2018 05:24:49 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id z67-v6sm3704118lfa.14.2018.10.17.05.24.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Oct 2018 05:24:48 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 18:23:01 +0600 Message-Id: <670f9397a16efca2646f571e811d44c0cfc5599d.1539778764.git.artem.k.pisarenko@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: MIME-Version: 1.0 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::235 Subject: [Qemu-devel] [PATCH v2 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Improve code readability and prepare for fixing bug #1797033 Signed-off-by: Artem Pisarenko --- Notes: v2: fixed compiler warning vl.c | 85 ++++++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 32 deletions(-) diff --git a/vl.c b/vl.c index 4e25c78..10c4275 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,33 @@ 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; + 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; + default: + /* gcc complains: ‘seconds’ may be used uninitialized */ + g_assert_not_reached(); + seconds = -1; + break; + } - return seconds - qemu_time(); + 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 +860,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 +879,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 Wed Oct 17 12:23:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Artem Pisarenko X-Patchwork-Id: 985342 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="i6ld8l9z"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42ZrxL72GVz9s4s for ; Wed, 17 Oct 2018 23:25:42 +1100 (AEDT) Received: from localhost ([::1]:36328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCktQ-0002eH-HJ for incoming@patchwork.ozlabs.org; Wed, 17 Oct 2018 08:25:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCksf-0002bI-NF for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:24:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCkse-00078Y-O9 for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:24:53 -0400 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]:42577) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gCkse-00077Y-GO for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:24:52 -0400 Received: by mail-lj1-x236.google.com with SMTP id y71-v6so24116357lje.9 for ; Wed, 17 Oct 2018 05:24:52 -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 :mime-version:in-reply-to:references:content-transfer-encoding; bh=MCM1zBAgDKGmY6C66wTdYlaeKrnybPqhU4VHrj7g+j8=; b=i6ld8l9zPV6uuplBj1tubWcX8biZlt85tfGSS7qnVmEb8odOdFdVmuoSKnEj3MPIIx Aojm/9tE/j38ZadxBi9XFta7bQq4Ed3c26fjYrmcc5pm8XoQ72gnzzi8nxaG7RQbKu8c wrM3AW4ISA1AvHHk8eME4yE5ztpACMAuVAbdvldUCsKQTELWxVTQp8X/HgcwPv4ogiOg gMc6HzPldpEI5CHkEKVrqdtGD3y5sR22wJLvB2/o9phAhT44QE77HYGFH58h/2a9z9nb t0dQgKV0U96uFuxiQUQjcxM3l+bKKcwqFNKXwrMXPtsRJlt+sp0+W0Sbrn2y7uR7/pwb bu0A== 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:mime-version:in-reply-to:references :content-transfer-encoding; bh=MCM1zBAgDKGmY6C66wTdYlaeKrnybPqhU4VHrj7g+j8=; b=oWtOMuPW3klKhyvEVoUhn+nvP3t5TZO0icjo2Dw6cxQNrSRj/nXBT8Wi1k9fxqXy4u hMSwVxqwHC07+EKJ+HHaa0DER0KSRmzLzh1YyRWtPg4XqYK9vexGX9View+0mpvDAwX+ UlGYeJhqUgjfEeG35tIRd7AkE4hTSsRkpYGypiRtp5MJghwbUNLx2htxlf3TTvI+IW+6 S850XRaWXcxUtOnFTrFvdgIorERnd7PIBre2AgelPBbpudH8oLNX5haqll6kfCsLKLnJ pv53Tq3RwinefprXJ9MPT6N6WHZv3afRILnUy00EjuBvEoApT6+d22A2ZnOoQH4Kimht 02Nw== X-Gm-Message-State: ABuFfoinibq1Blnix5ZyoS/s0R16FJ7A2HsVwufW9dv2gaKGNLwQllvR Ttz1cUp6Mdj0Ynb6DiuzzT248ekiWBQ= X-Google-Smtp-Source: ACcGV60Zz2Tr4nofmVTnGjXmePJc6WpE88UqGZpe7iLwtpI8HSDAMUPM6/APsvHKnZ4ipNcZly6G7w== X-Received: by 2002:a2e:6e08:: with SMTP id j8-v6mr18257103ljc.61.1539779090797; Wed, 17 Oct 2018 05:24:50 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id z67-v6sm3704118lfa.14.2018.10.17.05.24.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Oct 2018 05:24:50 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 18:23:02 +0600 Message-Id: <4632b5a4c97dcf4ccdb11ec0c4fe3a26e792ffa6.1539778764.git.artem.k.pisarenko@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: MIME-Version: 1.0 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::236 Subject: [Qemu-devel] [PATCH v2 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 | 58 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/vl.c b/vl.c index 10c4275..78a8a68 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) -{ - return qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000; -} - -/***********************************************************/ /* RTC reference time/date access */ +static time_t qemu_ref_timedate(void) +{ + 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; +} + 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,9 +842,6 @@ int qemu_timedate_diff(struct tm *tm) seconds = mktime(&tmp); break; } - case RTC_BASE_DATETIME: - seconds = mktimegm(tm) + rtc_host_datetime_offset; - break; default: /* gcc complains: ‘seconds’ may be used uninitialized */ g_assert_not_reached(); @@ -839,10 +849,10 @@ int qemu_timedate_diff(struct tm *tm) 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; @@ -868,8 +878,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) @@ -888,7 +898,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"); @@ -3039,6 +3049,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 Wed Oct 17 12:23:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Pisarenko X-Patchwork-Id: 985345 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="R2lwDyQk"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Zs0C5LwCz9s4s for ; Wed, 17 Oct 2018 23:28:11 +1100 (AEDT) Received: from localhost ([::1]:36343 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCkvp-0004dv-Bd for incoming@patchwork.ozlabs.org; Wed, 17 Oct 2018 08:28:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCksj-0002dY-2x for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:24:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCksg-0007C1-6k for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:24:56 -0400 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]:44703) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gCksf-00079h-VF for qemu-devel@nongnu.org; Wed, 17 Oct 2018 08:24:54 -0400 Received: by mail-lj1-x242.google.com with SMTP id v6-v6so24105813ljc.11 for ; Wed, 17 Oct 2018 05:24:53 -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=0IysXCiBWRfOiFIJKC2Hz4a4JgGaqRoCw413cn6G+RY=; b=R2lwDyQkTHX89lJ5B7besPxWj9eR2lsXuRXyoXwu2P8fVG2QW5IqqpbvOROiLNeXrF WcU7XjuDHQYaFPvMviwVpnK2V80fEI0x4iK7RPBbf+W572GoYRNpB8x50nhxMfuNmcJu LB+Ru8+QuWxrOkz370czlg4jQy0a0xOZeYzCkWI9XOE3LlA6MqwY4p8BR/PQhicXq64N S2xs2K5L0W+0cAxgXRy36Rkl35+3TplBJQAL/AAD2nspSxhBCSlZ+HN6luFMV69O1kl7 Oud3iERbptJZPZcIgXu0Z0pL7rI8nDUYslc8upa9mly4ofw7xbKyw/GW70FeK0YiwsFG gSTQ== 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=0IysXCiBWRfOiFIJKC2Hz4a4JgGaqRoCw413cn6G+RY=; b=bIDAEPqSWnicCsoyfji2bw0Wn8ZkyT+95f7JrTgL+2BQpUJlwEwcQ4oqTJzGHKzsWi DlAc6a7ZDM6PjyR9l3eXWWbQzjIA5cmNmuNWrFGy+qJq99wUZ4/92grH50Y/tlqYpOOc vQg+XYVlQXkVQjZXNZ3M+IbuLrOZmt4T1w/v4CIGN6vqVbm8VB+FyWKYVT91wflKDe86 shFMRT++EoJGGMvpCNSvh17Rw//MoJCOlO3hpwOMSmEyYlpYNDQuS5eWU3hlfOtOtd5C 5vrsLQbg0kSrUYw/+gAG0qLqfSUEn1/7ad5F6lHPJmVgKTUfc3/vIqqbF5z5yAeoSHGd Qy6g== X-Gm-Message-State: ABuFfoglxhggMTkE56KFGSc3s6w80QytplnPELRdKFaHyQOfSZFCL6lC 86ts2Vrwp5ftUyVcRjCu/jJpm2WnQeU= X-Google-Smtp-Source: ACcGV63CwGje1N94jglx1EC5knKbR1tJ6mcOD1KvfvZCGwNtirf1pMoSaTREbJ/bk5webjsq1GP6FA== X-Received: by 2002:a2e:59db:: with SMTP id g88-v6mr17161399ljf.79.1539779092284; Wed, 17 Oct 2018 05:24:52 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id z67-v6sm3704118lfa.14.2018.10.17.05.24.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Oct 2018 05:24:51 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 18:23:03 +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::242 Subject: [Qemu-devel] [PATCH v2 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 78a8a68..c350aba 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; @@ -849,7 +849,7 @@ int qemu_timedate_diff(struct tm *tm) break; } - return seconds - qemu_ref_timedate(); + return seconds - qemu_ref_timedate(QEMU_CLOCK_HOST); } static void configure_rtc_base_datetime(const char *startdate)