From nobody Sun May 5 03:01:33 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500990950623239.08171844075366; Tue, 25 Jul 2017 06:55:50 -0700 (PDT) Received: from localhost ([::1]:60949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da0JP-0002i7-8R for importer@patchew.org; Tue, 25 Jul 2017 09:55:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da0CZ-0005qX-JI for qemu-devel@nongnu.org; Tue, 25 Jul 2017 09:48:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da0CY-0001NZ-Fj for qemu-devel@nongnu.org; Tue, 25 Jul 2017 09:48:43 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:38056) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1da0CY-0001NA-6F for qemu-devel@nongnu.org; Tue, 25 Jul 2017 09:48:42 -0400 Received: by mail-wm0-x243.google.com with SMTP id r123so7037086wmb.5 for ; Tue, 25 Jul 2017 06:48:42 -0700 (PDT) Received: from 640k.lan (94-39-195-172.adsl-ull.clienti.tiscali.it. [94.39.195.172]) by smtp.gmail.com with ESMTPSA id q10sm19034944wrb.3.2017.07.25.06.48.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Jul 2017 06:48:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=yqoicxmgLD445rd6NIXHz3OKqLHMRZw+FF+lpctuUcE=; b=BVvidCZQe6lL5hWcrTWrcUIldyY/nDShqgogLJMLfNCkDkqyfzFa17D9pTKmscGw7w 2sPDs0dZZSy4ZgVur1/TR538qQdrVkx2H267zyiupx2SFRqPmWYr2rZcHRUfW80GOnRW pYIEoH8AcNUmdRPSTLFLIwMaUllqPHjSiuMYVkJRYi7qD4ohEuydzjIZF0gz0322FW0w yBrMCAt1oEnvtkCCK46FJSptuxaqstNzWBE/OFHE7REzOtQFJCI3BsfGBms2L8mBvM0v I5U3bBOTcnoImg8f7cn403f/F0bsDBQIfXPUbTtbR8QIi37Vrm8929uKZd0Wo0m9T3op EQQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=yqoicxmgLD445rd6NIXHz3OKqLHMRZw+FF+lpctuUcE=; b=kMlwU9qBtgEM8L3u6n5BxwmNkak6Io1gfqTZPdbc7BYYabEA3eSZNVpVpDOoIUV5Tz ZrVBYDGrWlf0m1RAND7XrG4wdxAGai5JQImMNLhMobJjhHnQ/LTsB1acsF+KLewA+MQF pv8HK0YmBhmvA008E9I7LGQreYpgry9BqndDN6HWHrzbDIOSMrRWZzryf4rV+0E6vYA8 0nW41CTAfGsX6Dbfr1n/Xki6CvBbiHsORzl4AUhtNjNHTcfjCZdijUpMnr/zhrV9b6J/ P+6/6Lk/1DjG1mPMQd0a+KV4DI/hOvQBxzsd3/pvzuZcoetg2fNH5wyKhnezm1Ro+2kp 0HAg== X-Gm-Message-State: AIVw111kSCLh317FNrF1CxBdosesTPChtaLXvXuX0xZTuP6tNC2u+v+Z /wssGZ52vYV6ScwX1Ts= X-Received: by 10.28.35.77 with SMTP id j74mr7471789wmj.168.1500990519158; Tue, 25 Jul 2017 06:48:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 15:48:31 +0200 Message-Id: <1500990514-30326-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1500990514-30326-1-git-send-email-pbonzini@redhat.com> References: <1500990514-30326-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH 1/4] rtc-test: cleanup register_b_set_flag test 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: peng.hao2@zte.com.cn, liu.yi24@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce set_datetime_bcd/assert_datetime_bcd, and handle UIP correctly. Signed-off-by: Paolo Bonzini --- tests/rtc-test.c | 76 ++++++++++++++++++++++++++++++++++------------------= ---- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/tests/rtc-test.c b/tests/rtc-test.c index e78f701..798cf5e 100644 --- a/tests/rtc-test.c +++ b/tests/rtc-test.c @@ -17,6 +17,8 @@ #include "qemu/timer.h" #include "hw/timer/mc146818rtc_regs.h" =20 +#define UIP_HOLD_LENGTH (8 * NANOSECONDS_PER_SECOND / 32768) + static uint8_t base =3D 0x70; =20 static int bcd2dec(int value) @@ -297,16 +299,30 @@ static void alarm_time(void) g_assert(cmos_read(RTC_REG_C) =3D=3D 0); } =20 +static void set_time_regs(int h, int m, int s) +{ + cmos_write(RTC_HOURS, h); + cmos_write(RTC_MINUTES, m); + cmos_write(RTC_SECONDS, s); +} + static void set_time(int mode, int h, int m, int s) { - /* set BCD 12 hour mode */ cmos_write(RTC_REG_B, mode); - cmos_write(RTC_REG_A, 0x76); + set_time_regs(h, m, s); + cmos_write(RTC_REG_A, 0x26); +} + +static void set_datetime_bcd(int h, int min, int s, int d, int m, int y) +{ cmos_write(RTC_HOURS, h); - cmos_write(RTC_MINUTES, m); + cmos_write(RTC_MINUTES, min); cmos_write(RTC_SECONDS, s); - cmos_write(RTC_REG_A, 0x26); + cmos_write(RTC_YEAR, y & 0xFF); + cmos_write(RTC_CENTURY, y >> 8); + cmos_write(RTC_MONTH, m); + cmos_write(RTC_DAY_OF_MONTH, d); } =20 #define assert_time(h, m, s) \ @@ -316,6 +332,17 @@ static void set_time(int mode, int h, int m, int s) g_assert_cmpint(cmos_read(RTC_SECONDS), =3D=3D, s); \ } while(0) =20 +#define assert_datetime_bcd(h, min, s, d, m, y) \ + do { \ + g_assert_cmpint(cmos_read(RTC_HOURS), =3D=3D, h); \ + g_assert_cmpint(cmos_read(RTC_MINUTES), =3D=3D, min); \ + g_assert_cmpint(cmos_read(RTC_SECONDS), =3D=3D, s); \ + g_assert_cmpint(cmos_read(RTC_DAY_OF_MONTH), =3D=3D, d); \ + g_assert_cmpint(cmos_read(RTC_MONTH), =3D=3D, m); \ + g_assert_cmpint(cmos_read(RTC_YEAR), =3D=3D, (y & 0xFF)); \ + g_assert_cmpint(cmos_read(RTC_CENTURY), =3D=3D, (y >> 8)); \ + } while(0) + static void basic_12h_bcd(void) { /* set BCD 12 hour mode */ @@ -506,41 +533,30 @@ static void fuzz_registers(void) =20 static void register_b_set_flag(void) { + if (cmos_read(RTC_REG_A) & REG_A_UIP) { + clock_step(UIP_HOLD_LENGTH + NANOSECONDS_PER_SECOND / 5); + } + g_assert_cmpint(cmos_read(RTC_REG_A) & REG_A_UIP, =3D=3D, 0); + /* Enable binary-coded decimal (BCD) mode and SET flag in Register B*/ cmos_write(RTC_REG_B, REG_B_24H | REG_B_SET); =20 - cmos_write(RTC_REG_A, 0x76); - cmos_write(RTC_YEAR, 0x11); - cmos_write(RTC_CENTURY, 0x20); - cmos_write(RTC_MONTH, 0x02); - cmos_write(RTC_DAY_OF_MONTH, 0x02); - cmos_write(RTC_HOURS, 0x02); - cmos_write(RTC_MINUTES, 0x04); - cmos_write(RTC_SECONDS, 0x58); - cmos_write(RTC_REG_A, 0x26); + set_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); =20 - /* Since SET flag is still enabled, these are equality checks. */ - g_assert_cmpint(cmos_read(RTC_HOURS), =3D=3D, 0x02); - g_assert_cmpint(cmos_read(RTC_MINUTES), =3D=3D, 0x04); - g_assert_cmpint(cmos_read(RTC_SECONDS), =3D=3D, 0x58); - g_assert_cmpint(cmos_read(RTC_DAY_OF_MONTH), =3D=3D, 0x02); - g_assert_cmpint(cmos_read(RTC_MONTH), =3D=3D, 0x02); - g_assert_cmpint(cmos_read(RTC_YEAR), =3D=3D, 0x11); - g_assert_cmpint(cmos_read(RTC_CENTURY), =3D=3D, 0x20); + assert_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); + + /* Since SET flag is still enabled, time does not advance. */ + clock_step(1000000000LL); + assert_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); =20 /* Disable SET flag in Register B */ cmos_write(RTC_REG_B, cmos_read(RTC_REG_B) & ~REG_B_SET); =20 - g_assert_cmpint(cmos_read(RTC_HOURS), =3D=3D, 0x02); - g_assert_cmpint(cmos_read(RTC_MINUTES), =3D=3D, 0x04); + assert_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); =20 - /* Since SET flag is disabled, this is an inequality check. - * We (reasonably) assume that no (sexagesimal) overflow occurs. */ - g_assert_cmpint(cmos_read(RTC_SECONDS), >=3D, 0x58); - g_assert_cmpint(cmos_read(RTC_DAY_OF_MONTH), =3D=3D, 0x02); - g_assert_cmpint(cmos_read(RTC_MONTH), =3D=3D, 0x02); - g_assert_cmpint(cmos_read(RTC_YEAR), =3D=3D, 0x11); - g_assert_cmpint(cmos_read(RTC_CENTURY), =3D=3D, 0x20); + /* Since SET flag is disabled, the clock now advances. */ + clock_step(1000000000LL); + assert_datetime_bcd(0x02, 0x04, 0x59, 0x02, 0x02, 0x2011); } =20 #define RTC_PERIOD_CODE1 13 /* 8 Hz */ --=20 1.8.3.1 From nobody Sun May 5 03:01:33 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500990735747237.59948252378763; Tue, 25 Jul 2017 06:52:15 -0700 (PDT) Received: from localhost ([::1]:60927 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da0Fu-0008Kb-A6 for importer@patchew.org; Tue, 25 Jul 2017 09:52:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da0CY-0005pv-P4 for qemu-devel@nongnu.org; Tue, 25 Jul 2017 09:48:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da0CX-0001NI-UP for qemu-devel@nongnu.org; Tue, 25 Jul 2017 09:48:42 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:37088) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1da0CX-0001Mw-NB for qemu-devel@nongnu.org; Tue, 25 Jul 2017 09:48:41 -0400 Received: by mail-wr0-x243.google.com with SMTP id 12so11896721wrb.4 for ; Tue, 25 Jul 2017 06:48:41 -0700 (PDT) Received: from 640k.lan (94-39-195-172.adsl-ull.clienti.tiscali.it. [94.39.195.172]) by smtp.gmail.com with ESMTPSA id q10sm19034944wrb.3.2017.07.25.06.48.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Jul 2017 06:48:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=338HV9i/rlAOELeU1l4LLN5teHeFWgGTnm19OcoP+Oc=; b=kxxrU+EzdZhlveb93qQYmvPPMOHYnI9zuXeMC6F9GVlspWnNLeBwL49mh04ELO8x7e Qk7EJLwlXPw2oY29Uu2slxnCBCrwOJ7mqrUJ7lk5SO38aOpSnUIV5XLNghBGF+lhK1jI 9s7oXPhdqitS7SiQLqgPvvcpt2Naj1i2WhEnWE1MuADukZvaiWndADyYgS6g72+fdxms l7PuBi96WZEwQAPti0Pln+HF3hnARlv/gNWVEjKzMfz56lEfU5Sgt2lCSL7Zb1YioCZ1 GRMWd6zELgFqaMMM2NWxDTxahgUvSSxGUBYCi7Zt0Ss8GoOvt7Yz+laCvkejOQ5VYxfy AhHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=338HV9i/rlAOELeU1l4LLN5teHeFWgGTnm19OcoP+Oc=; b=WDlPL6VnLQvFio4+lffZEppPxtNnl1wzOOdWbPWXAFEEaivasmWqGBGGsdc7sswICR +ga2jr06wxuTgdEJ2QH3pnCeYfZd9ZR/wJS/oChTiML/gsfNaQzIqVey+uTUK7mvrQC1 aJeHtYzZpbFxITSvEpztClBXChpkId+D12F/VSx7OiabYo4+EvNNZ3YcJsoJdNU2jtNM mRKktKTktH3FfY+BOKIqiwAyN2Io1E6Eg8KtnCN8CBUXegL9qUHg+RsL6vaZ9hwsOESb eXxQfw4jjVvTBmFKnkzMMebm4LKbKMEk39YNkUD06fVoZ1YQIxdyRWYbuuLSZtdvL2nR F/CA== X-Gm-Message-State: AIVw113uvf7z8Awg7xFtr4/GkGwWc9vnKWsn8qI5mzyfOFp9z2A1SA3R aPYyTdnKwSj5pRgwjok= X-Received: by 10.223.180.88 with SMTP id v24mr19394832wrd.29.1500990520226; Tue, 25 Jul 2017 06:48:40 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 15:48:32 +0200 Message-Id: <1500990514-30326-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1500990514-30326-1-git-send-email-pbonzini@redhat.com> References: <1500990514-30326-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH 2/4] rtc-test: introduce more update tests 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: peng.hao2@zte.com.cn, liu.yi24@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Test divider reset and UIP behavior. Signed-off-by: Paolo Bonzini --- tests/rtc-test.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/tests/rtc-test.c b/tests/rtc-test.c index 798cf5e..d7a96cb 100644 --- a/tests/rtc-test.c +++ b/tests/rtc-test.c @@ -325,6 +325,30 @@ static void set_datetime_bcd(int h, int min, int s, in= t d, int m, int y) cmos_write(RTC_DAY_OF_MONTH, d); } =20 +static void set_datetime_dec(int h, int min, int s, int d, int m, int y) +{ + cmos_write(RTC_HOURS, h); + cmos_write(RTC_MINUTES, min); + cmos_write(RTC_SECONDS, s); + cmos_write(RTC_YEAR, y % 100); + cmos_write(RTC_CENTURY, y / 100); + cmos_write(RTC_MONTH, m); + cmos_write(RTC_DAY_OF_MONTH, d); +} + +static void set_datetime(int mode, int h, int min, int s, int d, int m, in= t y) +{ + cmos_write(RTC_REG_B, mode); + + cmos_write(RTC_REG_A, 0x76); + if (mode & REG_B_DM) { + set_datetime_dec(h, min, s, d, m, y); + } else { + set_datetime_bcd(h, min, s, d, m, y); + } + cmos_write(RTC_REG_A, 0x26); +} + #define assert_time(h, m, s) \ do { \ g_assert_cmpint(cmos_read(RTC_HOURS), =3D=3D, h); \ @@ -559,6 +583,60 @@ static void register_b_set_flag(void) assert_datetime_bcd(0x02, 0x04, 0x59, 0x02, 0x02, 0x2011); } =20 +static void divider_reset(void) +{ + /* Enable binary-coded decimal (BCD) mode in Register B*/ + cmos_write(RTC_REG_B, REG_B_24H); + + /* Enter divider reset */ + cmos_write(RTC_REG_A, 0x76); + set_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); + + assert_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); + + /* Since divider reset flag is still enabled, these are equality check= s. */ + clock_step(1000000000LL); + assert_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); + + /* The first update ends 500 ms after divider reset */ + cmos_write(RTC_REG_A, 0x26); + clock_step(500000000LL - UIP_HOLD_LENGTH - 1); + g_assert_cmpint(cmos_read(RTC_REG_A) & REG_A_UIP, =3D=3D, 0); + assert_datetime_bcd(0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); + + clock_step(1); + g_assert_cmpint(cmos_read(RTC_REG_A) & REG_A_UIP, !=3D, 0); + clock_step(UIP_HOLD_LENGTH); + g_assert_cmpint(cmos_read(RTC_REG_A) & REG_A_UIP, =3D=3D, 0); + + assert_datetime_bcd(0x02, 0x04, 0x59, 0x02, 0x02, 0x2011); +} + +static void uip_stuck(void) +{ + set_datetime(REG_B_24H, 0x02, 0x04, 0x58, 0x02, 0x02, 0x2011); + + /* The first update ends 500 ms after divider reset */ + (void)cmos_read(RTC_REG_C); + clock_step(500000000LL); + g_assert_cmpint(cmos_read(RTC_REG_A) & REG_A_UIP, =3D=3D, 0); + assert_datetime_bcd(0x02, 0x04, 0x59, 0x02, 0x02, 0x2011); + + /* UF is now set. */ + cmos_write(RTC_HOURS_ALARM, 0x02); + cmos_write(RTC_MINUTES_ALARM, 0xC0); + cmos_write(RTC_SECONDS_ALARM, 0xC0); + + /* Because the alarm will fire soon, reading register A will latch UIP= . */ + clock_step(1000000000LL - UIP_HOLD_LENGTH / 2); + g_assert_cmpint(cmos_read(RTC_REG_A) & REG_A_UIP, !=3D, 0); + + /* Move the alarm far away. This must not cause UIP to remain stuck! = */ + cmos_write(RTC_HOURS_ALARM, 0x03); + clock_step(UIP_HOLD_LENGTH); + g_assert_cmpint(cmos_read(RTC_REG_A) & REG_A_UIP, =3D=3D, 0); +} + #define RTC_PERIOD_CODE1 13 /* 8 Hz */ #define RTC_PERIOD_CODE2 15 /* 2 Hz */ =20 @@ -625,7 +703,9 @@ int main(int argc, char **argv) qtest_add_func("/rtc/basic/bcd-12h", basic_12h_bcd); qtest_add_func("/rtc/set-year/20xx", set_year_20xx); qtest_add_func("/rtc/set-year/1980", set_year_1980); - qtest_add_func("/rtc/misc/register_b_set_flag", register_b_set_flag); + qtest_add_func("/rtc/update/register_b_set_flag", register_b_set_flag); + qtest_add_func("/rtc/update/divider-reset", divider_reset); + qtest_add_func("/rtc/update/uip-stuck", uip_stuck); qtest_add_func("/rtc/misc/fuzz-registers", fuzz_registers); qtest_add_func("/rtc/periodic/interrupt", periodic_timer); =20 --=20 1.8.3.1 From nobody Sun May 5 03:01:33 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500990841297898.171084908045; Tue, 25 Jul 2017 06:54:01 -0700 (PDT) Received: from localhost ([::1]:60934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da0Hc-0001DE-Nd for importer@patchew.org; Tue, 25 Jul 2017 09:53:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da0CZ-0005qg-QR for qemu-devel@nongnu.org; Tue, 25 Jul 2017 09:48:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da0CZ-0001Np-0F for qemu-devel@nongnu.org; Tue, 25 Jul 2017 09:48:43 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34705) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1da0CY-0001NO-Qn for qemu-devel@nongnu.org; Tue, 25 Jul 2017 09:48:42 -0400 Received: by mail-wm0-x241.google.com with SMTP id c184so3844395wmd.1 for ; Tue, 25 Jul 2017 06:48:42 -0700 (PDT) Received: from 640k.lan (94-39-195-172.adsl-ull.clienti.tiscali.it. [94.39.195.172]) by smtp.gmail.com with ESMTPSA id q10sm19034944wrb.3.2017.07.25.06.48.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Jul 2017 06:48:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=dG+iyu56XW/obUQkWcuw67KxEU+Y+LmpLS1SgZQsaGQ=; b=JMBHasT7mj2XVCVhNv2Qz+Ei64m/3tfY0qX0SJenIZPcYawl6AddImOuVdybB2YEZp +ASZ/TSnjTCcvP4veeeuEI9go+ZyECEbDjhP4MnJrvfH6npc5xqxKHULLlHCtQSzitfu bLkziyfc6+WrS2czTwi8Xo2RtOBOQtdxGmNN5XokWYZGTdVX3hWL0SodMRRwaCjQD0xh Vk/Xn0ZsY8ZMqJlXsVKtRh76iEFzBg7G5+xpl0gr2Zl+su6ncfJD/OLiBt9RLZpV9bTY 7GFCf0+2y6mTkDLzR8LMMW5XYAwH4EUxWMxRWPrqxAuawla581U2zcOFt7thIgMJNKCG atSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=dG+iyu56XW/obUQkWcuw67KxEU+Y+LmpLS1SgZQsaGQ=; b=E3pyH9+/taWPwjgCVps/uvMqLrDxkR2zKnk0plXc83tsqjWpLMvb+a8+U+YhSm1xKR aaxg+Qx7fN0bws6jmDZoRUDDeC6G6GJxvRtO44NuVUTPW53rt+eQLI+yp5G3WwlKyPgh 49WCBi/AyaRhwZhg4OYkA563h5cKifoi4LYn4Pn3W8RMmZXh3hSV3rUuPlLK6DutELpo z8dJLsDoemgWtyMT0hrp2dmA+POohOV+OYpr5FZQHkzOkecHMZIPddE4Letsa12hoQ52 vk2JrrRbhUi/XKJZ2yvaymuIi7UvVM8r8R2z49CjpmD1G9CKjDujBPNpx2KJ1f+Q78T+ g0hQ== X-Gm-Message-State: AIVw110ucAq08jbbxnrTTSAsEvwn56jzy2Wqd3lQxxD2PBiWSTOAL7le Jj/rdZk/tybKOPrmpdM= X-Received: by 10.28.147.200 with SMTP id v191mr7584376wmd.95.1500990521344; Tue, 25 Jul 2017 06:48:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 15:48:33 +0200 Message-Id: <1500990514-30326-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1500990514-30326-1-git-send-email-pbonzini@redhat.com> References: <1500990514-30326-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH 3/4] mc146818rtc: simplify check_update_timer 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: peng.hao2@zte.com.cn, liu.yi24@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move all the optimized cases together, since they all have UF=3D1 in common. Signed-off-by: Paolo Bonzini --- hw/timer/mc146818rtc.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 1b8d3d7..ffb2c6a 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -291,26 +291,14 @@ static void check_update_timer(RTCState *s) =20 /* From the data sheet: "Holding the dividers in reset prevents * interrupts from operating, while setting the SET bit allows" - * them to occur. However, it will prevent an alarm interrupt - * from occurring, because the time of day is not updated. + * them to occur. */ if ((s->cmos_data[RTC_REG_A] & 0x60) =3D=3D 0x60) { timer_del(s->update_timer); return; } - if ((s->cmos_data[RTC_REG_C] & REG_C_UF) && - (s->cmos_data[RTC_REG_B] & REG_B_SET)) { - timer_del(s->update_timer); - return; - } - if ((s->cmos_data[RTC_REG_C] & REG_C_UF) && - (s->cmos_data[RTC_REG_C] & REG_C_AF)) { - timer_del(s->update_timer); - return; - } =20 guest_nsec =3D get_guest_rtc_ns(s) % NANOSECONDS_PER_SECOND; - /* if UF is clear, reprogram to next second */ next_update_time =3D qemu_clock_get_ns(rtc_clock) + NANOSECONDS_PER_SECOND - guest_nsec; =20 @@ -321,7 +309,17 @@ static void check_update_timer(RTCState *s) s->next_alarm_time =3D next_update_time + (next_alarm_sec - 1) * NANOSECONDS_PER_SECOND; =20 + /* If UF is already set, we might be able to optimize. */ if (s->cmos_data[RTC_REG_C] & REG_C_UF) { + /* If AF cannot change (i.e. either it is set already, or SET=3D1 + * and then the time of day is not updated), nothing to do. + */ + if ((s->cmos_data[RTC_REG_B] & REG_B_SET) || + (s->cmos_data[RTC_REG_C] & REG_C_AF)) { + timer_del(s->update_timer); + return; + } + /* UF is set, but AF is clear. Program the timer to target * the alarm time. */ next_update_time =3D s->next_alarm_time; --=20 1.8.3.1 From nobody Sun May 5 03:01:33 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500990726660412.5890530033315; Tue, 25 Jul 2017 06:52:06 -0700 (PDT) Received: from localhost ([::1]:60926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da0Fo-0008GM-Tf for importer@patchew.org; Tue, 25 Jul 2017 09:52:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da0Cb-0005s0-5p for qemu-devel@nongnu.org; Tue, 25 Jul 2017 09:48:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da0Ca-0001OM-7S for qemu-devel@nongnu.org; Tue, 25 Jul 2017 09:48:45 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:32797) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1da0Ca-0001O1-1Q for qemu-devel@nongnu.org; Tue, 25 Jul 2017 09:48:44 -0400 Received: by mail-wm0-x241.google.com with SMTP id q189so5186839wmd.0 for ; Tue, 25 Jul 2017 06:48:43 -0700 (PDT) Received: from 640k.lan (94-39-195-172.adsl-ull.clienti.tiscali.it. [94.39.195.172]) by smtp.gmail.com with ESMTPSA id q10sm19034944wrb.3.2017.07.25.06.48.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Jul 2017 06:48:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Nl+uIu0q2Pkh4HPD3oQQUQpDEPYElYerO412e/K03wc=; b=AKsKDWuSwnIGfUkcbXcE2ikDUqh6cxTRfp8X8K2hCOXXHAjON5sFCV+5BxRqCrO0ww yE8br2LEAYuEL/rkFDp3Q371cG8QOeESt+aroEK1qeDkFfdaf2FXZ9lKgMZRwzoAuWh2 fAEwXf9v8KAuZQgvlJpoSBuGtrUaBF/vSIMqRCLOfBkqEoQRYn42eN0JHzbwq1nQWAN6 Eyl64J9s/nmm3q5NyAd3xup+A4/eAytYFnEhcLrIBajW5+EGHFeCEQYkEnGDdZx9lK9S 3EclYDLxkXfLmQmhEXX5Y2/61D6UK+16t/ZubB+Pqcmix/zp3Ge1foSrBA/Gnm1BCBoe 3KtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Nl+uIu0q2Pkh4HPD3oQQUQpDEPYElYerO412e/K03wc=; b=LBHNSj8kJLE2fK0z870e2BzxGCBNAtQkAd4fqp8wgDaDj2/+uwCsN/LwM9PNNgrs7S q/JXwhQqy1Ik5KCJI4Qi+XcR0QbLDxZotBLGZkCblqBvZdpfySAHY/FgkxDbiqn4mlbS 93/gbsF2cqgls6+t5FoLXLW7HA2/q9LyslqRImpADFiigFGCtjAYoWb2qpBDZR66MYut lggGaEps/JFqx2RTpTv0pd8EalAtHxxdzN+j/PbRC7y82lQSAZSR5L4+zLlmMzb4SSzT jAjZWiUvohgQWBaM69YvEetQ/kRPM1NyfhyVHc9BtdR1JeZP3nb7zRKLBsyV1mg8QtP6 +wlw== X-Gm-Message-State: AIVw111tIqvnoakP5XGtOJIulPctgYlSFyrEM4L3BJlvLEItXQGXUqIh AW0Yu1Dr6ME1YbwWOw8= X-Received: by 10.28.140.66 with SMTP id o63mr7664420wmd.95.1500990522471; Tue, 25 Jul 2017 06:48:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 15:48:34 +0200 Message-Id: <1500990514-30326-5-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1500990514-30326-1-git-send-email-pbonzini@redhat.com> References: <1500990514-30326-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH 4/4] mc146818rtc: implement UIP latching as intended 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: peng.hao2@zte.com.cn, liu.yi24@zte.com.cn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In some cases, the guest can observe the wrong ordering of UIP and interrupts. This can happen if the VCPU exit is timed like this (the interrupt is supposed to happen at time t): iothread VCPU ... wait for interrupt ... t-100ns read register A t wake up, take BQL t+100ns update_in_progress return false return UIP=3D0 trigger interrupt The interrupt is late; the VCPU expected the falling edge of UIP to happen after the interrupt. update_in_progress is already trying to cover this case by latching UIP if the timer is going to fire soon, and the fix is documented in the commit message for commit 56038ef623 ("RTC: Update the RTC clock only when reading it", 2012-09-10). It cannot be tested with qtest, because its timing of interrupts vs. reads is exact. However, the implementation was incorrect because UIP cmos_ioport_read cleared register A instead of leaving that to rtc_update_timer. Fixing the implementation of cmos_ioport_read to match the commit message, however, breaks the "uip-stuck" test case from the previous patch. To fix it, skip update timer optimizations if UIP has been latched. Signed-off-by: Paolo Bonzini --- hw/timer/mc146818rtc.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index ffb2c6a..82843ed 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -294,6 +294,7 @@ static void check_update_timer(RTCState *s) * them to occur. */ if ((s->cmos_data[RTC_REG_A] & 0x60) =3D=3D 0x60) { + assert((s->cmos_data[RTC_REG_A] & REG_A_UIP) =3D=3D 0); timer_del(s->update_timer); return; } @@ -309,8 +310,12 @@ static void check_update_timer(RTCState *s) s->next_alarm_time =3D next_update_time + (next_alarm_sec - 1) * NANOSECONDS_PER_SECOND; =20 - /* If UF is already set, we might be able to optimize. */ - if (s->cmos_data[RTC_REG_C] & REG_C_UF) { + /* If update_in_progress latched the UIP bit, we must keep the timer + * programmed to the next second, so that UIP is cleared. Otherwise, + * if UF is already set, we might be able to optimize. + */ + if (!(s->cmos_data[RTC_REG_A] & REG_A_UIP) && + (s->cmos_data[RTC_REG_C] & REG_C_UF)) { /* If AF cannot change (i.e. either it is set already, or SET=3D1 * and then the time of day is not updated), nothing to do. */ @@ -725,12 +730,10 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr= addr, ret =3D s->cmos_data[s->cmos_index]; break; case RTC_REG_A: + ret =3D s->cmos_data[s->cmos_index]; if (update_in_progress(s)) { - s->cmos_data[s->cmos_index] |=3D REG_A_UIP; - } else { - s->cmos_data[s->cmos_index] &=3D ~REG_A_UIP; + ret |=3D REG_A_UIP; } - ret =3D s->cmos_data[s->cmos_index]; break; case RTC_REG_C: ret =3D s->cmos_data[s->cmos_index]; --=20 1.8.3.1