From nobody Thu Nov 6 06:13:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539779212664893.2157761167514; Wed, 17 Oct 2018 05:26:52 -0700 (PDT) Received: from localhost ([::1]:36338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCkuZ-0003jE-Lu for importer@patchew.org; Wed, 17 Oct 2018 08:26:51 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Documentation describing -rtc option updated to better match current implem= entation 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) =20 DEF("rtc", HAS_ARG, QEMU_OPTION_rtc, \ - "-rtc [base=3Dutc|localtime|date][,clock=3Dhost|rt|vm][,driftfix=3Dnon= e|slew]\n" \ + "-rtc [base=3Dutc|localtime|][,clock=3Dhost|rt|vm][,driftfix= =3Dnone|slew]\n" \ " set the RTC base and clock, enable drift fix for cloc= k ticks (x86 only)\n", QEMU_ARCH_ALL) =20 STEXI =20 -@item -rtc [base=3Dutc|localtime|@var{date}][,clock=3Dhost|vm][,driftfix= =3Dnone|slew] +@item -rtc [base=3Dutc|localtime|@var{datetime}][,clock=3Dhost|rt|vm][,dri= ftfix=3Dnone|slew] @findex -rtc Specify @option{base} as @code{utc} or @code{localtime} to let the RTC sta= rt 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{date= time} in the format @code{2006-06-17T16:01:21} or @code{2006-06-17}. The default base i= s UTC. =20 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{c= lock} -to @code{rt} instead. To even prevent it from progressing during suspensi= on, -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 sl= eeping +is off, and no synchronization algorithm is active. =20 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 --=20 2.7.4 From nobody Thu Nov 6 06:13:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539779290510939.4159317838181; Wed, 17 Oct 2018 05:28:10 -0700 (PDT) Received: from localhost ([::1]:36345 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCkvp-0004ho-DX for importer@patchew.org; Wed, 17 Oct 2018 08:28:09 -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) 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) 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) 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: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 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 =3D false; int nb_nics; NICInfo nd_table[MAX_NICS]; int autostart; -static int rtc_utc =3D 1; -static int rtc_date_offset =3D -1; /* -1 means no change */ +static enum { + RTC_BASE_UTC, + RTC_BASE_LOCALTIME, + RTC_BASE_DATETIME, +} rtc_base_type =3D RTC_BASE_UTC; +static int rtc_host_datetime_offset =3D -1; /* valid only for host rtc_clo= ck and + rtc_base_type=3DRTC_BASE_DATE= TIME */ QEMUClockType rtc_clock; int vga_interface_type =3D VGA_NONE; static DisplayOptions dpy; @@ -782,26 +787,30 @@ void qemu_system_vmstop_request(RunState state) /***********************************************************/ /* real time host monotonic timer */ =20 -static time_t qemu_time(void) +static time_t qemu_timedate(void) { return qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000; } =20 /***********************************************************/ -/* host time/date access */ +/* RTC reference time/date access */ void qemu_get_timedate(struct tm *tm, int offset) { - time_t ti =3D qemu_time(); + time_t ti =3D qemu_timedate(); =20 ti +=3D offset; - if (rtc_date_offset =3D=3D -1) { - if (rtc_utc) - gmtime_r(&ti, tm); - else - localtime_r(&ti, tm); - } else { - ti -=3D 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 -=3D rtc_host_datetime_offset; + gmtime_r(&ti, tm); + break; } } =20 @@ -809,23 +818,33 @@ int qemu_timedate_diff(struct tm *tm) { time_t seconds; =20 - if (rtc_date_offset =3D=3D -1) - if (rtc_utc) - seconds =3D mktimegm(tm); - else { - struct tm tmp =3D *tm; - tmp.tm_isdst =3D -1; /* use timezone to figure it out */ - seconds =3D mktime(&tmp); - } - else - seconds =3D mktimegm(tm) + rtc_date_offset; + switch (rtc_base_type) { + case RTC_BASE_UTC: + seconds =3D mktimegm(tm); + break; + case RTC_BASE_LOCALTIME: + { + struct tm tmp =3D *tm; + tmp.tm_isdst =3D -1; /* use timezone to figure it out */ + seconds =3D mktime(&tmp); + break; + } + case RTC_BASE_DATETIME: + seconds =3D mktimegm(tm) + rtc_host_datetime_offset; + break; + default: + /* gcc complains: =E2=80=98seconds=E2=80=99 may be used uninitiali= zed */ + g_assert_not_reached(); + seconds =3D -1; + break; + } =20 - return seconds - qemu_time(); + return seconds - qemu_timedate(); } =20 -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; =20 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 *sta= rtdate) } tm.tm_year -=3D 1900; tm.tm_mon--; - rtc_start_date =3D mktimegm(&tm); - if (rtc_start_date =3D=3D -1) { + rtc_start_datetime =3D mktimegm(&tm); + if (rtc_start_datetime =3D=3D -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 =3D qemu_time() - rtc_start_date; + rtc_host_datetime_offset =3D (qemu_clock_get_ms(QEMU_CLOCK_HOST) / 100= 0) + - rtc_start_datetime; } =20 static void configure_rtc(QemuOpts *opts) @@ -859,15 +879,16 @@ static void configure_rtc(QemuOpts *opts) value =3D qemu_opt_get(opts, "base"); if (value) { if (!strcmp(value, "utc")) { - rtc_utc =3D 1; + rtc_base_type =3D RTC_BASE_UTC; } else if (!strcmp(value, "localtime")) { Error *blocker =3D NULL; - rtc_utc =3D 0; + rtc_base_type =3D RTC_BASE_LOCALTIME; error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "-rtc base=3Dlocaltime"); replay_add_blocker(blocker); } else { - configure_rtc_date_offset(value); + rtc_base_type =3D RTC_BASE_DATETIME; + configure_rtc_host_datetime_offset(value); } } value =3D qemu_opt_get(opts, "clock"); --=20 2.7.4 From nobody Thu Nov 6 06:13:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539779210936541.5373183651798; Wed, 17 Oct 2018 05:26:50 -0700 (PDT) Received: from localhost ([::1]:36337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCkuX-0003iR-UO for importer@patchew.org; Wed, 17 Oct 2018 08:26:49 -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) 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) 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) 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: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 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=3Dvm and sp= ecified 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 =3D RTC_BASE_UTC; -static int rtc_host_datetime_offset =3D -1; /* valid only for host rtc_clo= ck and - rtc_base_type=3DRTC_BASE_DATE= TIME */ +static time_t rtc_ref_start_datetime; +static int rtc_realtime_clock_offset; /* used only with QEMU_CLOCK_REALTIM= E */ +static int rtc_host_datetime_offset =3D -1; /* valid & used only with + RTC_BASE_DATETIME */ QEMUClockType rtc_clock; int vga_interface_type =3D VGA_NONE; static DisplayOptions dpy; @@ -785,32 +787,42 @@ void qemu_system_vmstop_request(RunState state) } =20 /***********************************************************/ -/* 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 =3D qemu_clock_get_ms(rtc_clock) / 1000; + switch (rtc_clock) { + case QEMU_CLOCK_REALTIME: + value -=3D rtc_realtime_clock_offset; + /* no break */ + case QEMU_CLOCK_VIRTUAL: + value +=3D rtc_ref_start_datetime; + break; + case QEMU_CLOCK_HOST: + if (rtc_base_type =3D=3D RTC_BASE_DATETIME) { + value -=3D rtc_host_datetime_offset; + } + break; + default: + assert(0); + } + return value; +} + void qemu_get_timedate(struct tm *tm, int offset) { - time_t ti =3D qemu_timedate(); + time_t ti =3D qemu_ref_timedate(); =20 ti +=3D offset; =20 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 -=3D rtc_host_datetime_offset; - gmtime_r(&ti, tm); - break; } } =20 @@ -819,6 +831,7 @@ int qemu_timedate_diff(struct tm *tm) time_t seconds; =20 switch (rtc_base_type) { + case RTC_BASE_DATETIME: case RTC_BASE_UTC: seconds =3D mktimegm(tm); break; @@ -829,9 +842,6 @@ int qemu_timedate_diff(struct tm *tm) seconds =3D mktime(&tmp); break; } - case RTC_BASE_DATETIME: - seconds =3D mktimegm(tm) + rtc_host_datetime_offset; - break; default: /* gcc complains: =E2=80=98seconds=E2=80=99 may be used uninitiali= zed */ g_assert_not_reached(); @@ -839,10 +849,10 @@ int qemu_timedate_diff(struct tm *tm) break; } =20 - return seconds - qemu_timedate(); + return seconds - qemu_ref_timedate(); } =20 -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 ch= ar *startdate) "'2006-06-17T16:01:21' or '2006-06-17'\n"); exit(1); } - rtc_host_datetime_offset =3D (qemu_clock_get_ms(QEMU_CLOCK_HOST) / 100= 0) - - rtc_start_datetime; + rtc_host_datetime_offset =3D rtc_ref_start_datetime - rtc_start_dateti= me; + rtc_ref_start_datetime =3D rtc_start_datetime; } =20 static void configure_rtc(QemuOpts *opts) @@ -888,7 +898,7 @@ static void configure_rtc(QemuOpts *opts) replay_add_blocker(blocker); } else { rtc_base_type =3D RTC_BASE_DATETIME; - configure_rtc_host_datetime_offset(value); + configure_rtc_base_datetime(value); } } value =3D qemu_opt_get(opts, "clock"); @@ -3039,6 +3049,8 @@ int main(int argc, char **argv, char **envp) exit(1); } rtc_clock =3D QEMU_CLOCK_HOST; + rtc_ref_start_datetime =3D qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000; + rtc_realtime_clock_offset =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME) /= 1000; =20 QLIST_INIT (&vm_change_state_head); os_setup_early_signal_handling(); --=20 2.7.4 From nobody Thu Nov 6 06:13:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539779338265671.1773379538946; Wed, 17 Oct 2018 05:28:58 -0700 (PDT) Received: from localhost ([::1]:36347 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCkwb-0005Je-AZ for importer@patchew.org; Wed, 17 Oct 2018 08:28:57 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Return value of qemu_timedate_diff(), used for calculation offset in QAPI '= RTC_CHANGE' event restored to keep compatibility, although it isn't documen= ted that difference is relative to host clock advancement. Added important note to 'RTC_CHANGE' event description to highlight establi= shed 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) =20 /***********************************************************/ /* RTC reference time/date access */ -static time_t qemu_ref_timedate(void) +static time_t qemu_ref_timedate(QEMUClockType clock) { - time_t value =3D qemu_clock_get_ms(rtc_clock) / 1000; - switch (rtc_clock) { + time_t value =3D qemu_clock_get_ms(clock) / 1000; + switch (clock) { case QEMU_CLOCK_REALTIME: value -=3D rtc_realtime_clock_offset; /* no break */ @@ -811,7 +811,7 @@ static time_t qemu_ref_timedate(void) =20 void qemu_get_timedate(struct tm *tm, int offset) { - time_t ti =3D qemu_ref_timedate(); + time_t ti =3D qemu_ref_timedate(rtc_clock); =20 ti +=3D offset; =20 @@ -849,7 +849,7 @@ int qemu_timedate_diff(struct tm *tm) break; } =20 - return seconds - qemu_ref_timedate(); + return seconds - qemu_ref_timedate(QEMU_CLOCK_HOST); } =20 static void configure_rtc_base_datetime(const char *startdate) --=20 2.7.4