From nobody Thu May 2 18:40:35 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.zoho.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 149389936855974.1989524140887; Thu, 4 May 2017 05:02:48 -0700 (PDT) Received: from localhost ([::1]:41336 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FT4-0004VG-7j for importer@patchew.org; Thu, 04 May 2017 08:02:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FQb-0002VI-7z for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6FQZ-0006d5-OG for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:13 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:36056) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d6FQZ-0006cU-I2 for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:11 -0400 Received: by mail-pg0-x244.google.com with SMTP id v1so2011964pgv.3 for ; Thu, 04 May 2017 05:00:11 -0700 (PDT) Received: from eric.tencent.com ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id p7sm3698261pfb.125.2017.05.04.05.00.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 May 2017 05:00: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; bh=s63d/d9Ct+4iwdhqUjdWr5K2eUVPHwTFpMV9Gkue+r4=; b=rH89LCyOUofHeJkCp0p9cMrRWrixSYfQLkRneYNkVi4CkJrm+r6bJyBxHrU4EFf4LJ LfghM7tXz3J4Jx+6dh+W9qY6c5SWQsdry5tJXswu7YH0i5IQ5KB3J6QfPXE+LqdBBCfJ 44mechQlhgswESOorIjb/4d57PVl2m0oX/9e5ZvyB+C6IUQI0QcEfK+uKJDZvt3f9uhG MeSHzJVP/b9xwNr/0q/Ph67Obd2ZZI1GEO1B/ImxOrzL4aZoL/oKF9XVu15jqEBMmZ3H f01KBZ7QSokNEEP5df6X1hx2kuvjN34vQPlMhc6xfEXb05qlW5nyvLCPnnHAQV7mjrPC N8pg== 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; bh=s63d/d9Ct+4iwdhqUjdWr5K2eUVPHwTFpMV9Gkue+r4=; b=FHP0tpOuZB3dA/W9XlV6lZV3TDkx1fXDeRwUmVAD4oBvvNf/rB8lKVjGsp2of+ykDp uSl2bxGa2XDMH0E1U9uMKQXZYGiX/BgfyTbhgIzNlP27H0V9UGQZv14fYJPJfriSOykY QgymnL3LEUSQ5QjB//RC4CWUsmVvvUcSKxbLOn7X61WZU0fD1L/gR1ZSlsh1z3qt64uO RDr8RyKjG0TVILQr+GO3ljMTpyh97JI4kM5QXfUvToJcKAoSYq9VFfPqVG3GpA/T2B0J gUZzTpHdLPZOGXPvZ4FMdcSlKGNdTwZAr+Uw2huwosgHDs1mYQSdY/16wzAbMcA5olc9 6w7g== X-Gm-Message-State: AN3rC/4ZQtThfjXeU5mvfTZoB+Fqa8LW/djH21Oy6mKL7I5c+mTrbV7J j71eJ4IIjuJVQw== X-Received: by 10.99.232.69 with SMTP id a5mr44674067pgk.167.1493899210554; Thu, 04 May 2017 05:00:10 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Thu, 4 May 2017 19:59:44 +0800 Message-Id: <20170504115948.3048-2-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170504115948.3048-1-xiaoguangrong@tencent.com> References: <20170504115948.3048-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH v2 1/5] mc146818rtc: update periodic timer only if it is needed 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: Xiao Guangrong , yunfangtai@tencent.com, qemu-devel@nongnu.org, kvm@vger.kernel.org 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" From: Xiao Guangrong Currently, the timer is updated whenever RegA or RegB is written even if the periodic timer related configuration is not changed This patch optimizes it slightly to make the update happen only if its period or enable-status is changed, also later patches are depend on this optimization Signed-off-by: Xiao Guangrong --- hw/timer/mc146818rtc.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 4165450..5cccb2a 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -391,6 +391,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, uint64_t data, unsigned size) { RTCState *s =3D opaque; + bool update_periodic_timer; =20 if ((addr & 1) =3D=3D 0) { s->cmos_index =3D data & 0x7f; @@ -423,6 +424,8 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, } break; case RTC_REG_A: + update_periodic_timer =3D (s->cmos_data[RTC_REG_A] ^ data) & 0= x0f; + if ((data & 0x60) =3D=3D 0x60) { if (rtc_running(s)) { rtc_update_time(s); @@ -445,10 +448,17 @@ static void cmos_ioport_write(void *opaque, hwaddr ad= dr, /* UIP bit is read only */ s->cmos_data[RTC_REG_A] =3D (data & ~REG_A_UIP) | (s->cmos_data[RTC_REG_A] & REG_A_UIP); - periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + + if (update_periodic_timer) { + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + } + check_update_timer(s); break; case RTC_REG_B: + update_periodic_timer =3D (s->cmos_data[RTC_REG_B] ^ data) + & REG_B_PIE; + if (data & REG_B_SET) { /* update cmos to when the rtc was stopping */ if (rtc_running(s)) { @@ -475,7 +485,11 @@ static void cmos_ioport_write(void *opaque, hwaddr add= r, qemu_irq_lower(s->irq); } s->cmos_data[RTC_REG_B] =3D data; - periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + + if (update_periodic_timer) { + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + } + check_update_timer(s); break; case RTC_REG_C: --=20 2.9.3 From nobody Thu May 2 18:40:35 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.zoho.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 1493899345700834.7702684580872; Thu, 4 May 2017 05:02:25 -0700 (PDT) Received: from localhost ([::1]:41335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FSi-0004Cy-9d for importer@patchew.org; Thu, 04 May 2017 08:02:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FQi-0002hh-R6 for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6FQc-0006fS-DI for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:20 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:34406) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d6FQc-0006es-5g for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:14 -0400 Received: by mail-pf0-x242.google.com with SMTP id d1so1840466pfe.1 for ; Thu, 04 May 2017 05:00:13 -0700 (PDT) Received: from eric.tencent.com ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id p7sm3698261pfb.125.2017.05.04.05.00.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 May 2017 05:00:12 -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:content-transfer-encoding; bh=RWjwBdDiGPbzFIUTbkZ97AcjRH2V5AGgQAmd2aDE4s4=; b=AVdSobYlPDMusfVZt45Ni23SViuuTjKICM465/F8uas5RKWuYotf46Alr9Wym6FFAZ qgM9q+OIxwPHiBUyWaVGYOq72YuyMQ2SdlbJRUQBq6+QSaRl09ZsUNURU+o5IAb0OGQj wtjRXO711KwzT5ZUTRa0na521CyqmIAnqzej30vpBDg7dg/13DtCvXJGe6qH54CRK0b2 c2KQE5hAwRy2gq/RplrvTTOLzHEccgzWNfIxiFjtF2+LgdtlcV1O0RM4XfaYQFAm6FlA m4Rmj5GRouAaPpv92//yN/uyh2g/TS0ttbGR6I+d4w1NL5V4WebbjJhpTTemR510P0Tj VJdw== 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:content-transfer-encoding; bh=RWjwBdDiGPbzFIUTbkZ97AcjRH2V5AGgQAmd2aDE4s4=; b=F19qd2p39upoBdcpCXolL417LeJ5bYz9eGZwC+OjQbztJWTllsitw1YF31mnNAa+wQ urK2566E9Xa9y5Vl1fqc2tvzJUuujp1xUZvrJ1pmzylTH4iXCoKCGMv0FYXEL4hpDsSE ho9wz0TxZj15ujqpn+z1OqLyEOKizFd0uP9XyOgpCAp7VZ4ycnzBxzD+ajR/r5odB3BJ YMhtKWYdtilx1FUHF4F3YgZeXDOSXzGHm3H+HlHkgnsMI8SgmI+elU9NOqtSYxz7hhKN zavLk97X40OGvlc4oYcvaPpnEwx8oqyhI7Rn3pt5eCzUJ/UtJqvFyyklf+m9+zE4bSpT vipg== X-Gm-Message-State: AN3rC/6pEBmVFdD/1VkcsHBMoIZCQ3fSx5YZk8IuppmuwKuf3To2TFgd g90u/KwqzBBGQsi2 X-Received: by 10.99.117.67 with SMTP id f3mr45361179pgn.51.1493899212977; Thu, 04 May 2017 05:00:12 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Thu, 4 May 2017 19:59:45 +0800 Message-Id: <20170504115948.3048-3-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170504115948.3048-1-xiaoguangrong@tencent.com> References: <20170504115948.3048-1-xiaoguangrong@tencent.com> MIME-Version: 1.0 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: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH v2 2/5] mc146818rtc: precisely count the clock for periodic 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: Xiao Guangrong , yunfangtai@tencent.com, qemu-devel@nongnu.org, kvm@vger.kernel.org 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 From: Tai Yunfang There are two issues in current code: 1) If the period is changed by re-configuring RegA, the coalesced irq will be scaled to reflect the new period, however, it calculates the new interrupt number like this: s->irq_coalesced =3D (s->irq_coalesced * s->period) / period; There are some clocks will be lost if they are not enough to be squeezed to a single new period that will cause the VM clock slower In order to fix the issue, we calculate the interrupt window based on the precise clock rather than period, then the clocks lost during period is scaled can be compensated properly 2) If periodic_timer_update() is called due to RegA reconfiguration, i.e, the period is updated, current time is not the start point for the next periodic timer, instead, which should start from the last interrupt, otherwise, the clock in VM will become slow This patch takes the clocks from last interrupt to current clock into account and compensates the clocks for the next interrupt, especially=EF=BC=8Cif a complete interrupt was lost in this window, the time can be caught up by LOST_TICK_POLICY_SLEW [ Xiao: redesign the algorithm based on Yunfang's original work. ] Signed-off-by: Xiao Guangrong Signed-off-by: Tai Yunfang --- hw/timer/mc146818rtc.c | 116 ++++++++++++++++++++++++++++++++++++++++-----= ---- 1 file changed, 96 insertions(+), 20 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 5cccb2a..14bde1a 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -146,31 +146,104 @@ static void rtc_coalesced_timer(void *opaque) } #endif =20 -/* handle periodic timer */ -static void periodic_timer_update(RTCState *s, int64_t current_time) +static int period_code_to_clock(int period_code) +{ + /* periodic timer is disabled. */ + if (!period_code) { + return 0; + } + + if (period_code <=3D 2) { + period_code +=3D 7; + } + + /* period in 32 Khz cycles */ + return 1 << (period_code - 1); +} + +/* + * handle periodic timer. @old_period indicates the periodic timer update + * is just due to period adjustment. + */ +static void +periodic_timer_update(RTCState *s, int64_t current_time, int old_period) { int period_code, period; - int64_t cur_clock, next_irq_clock; + int64_t cur_clock, next_irq_clock, lost_clock =3D 0; =20 period_code =3D s->cmos_data[RTC_REG_A] & 0x0f; if (period_code !=3D 0 && (s->cmos_data[RTC_REG_B] & REG_B_PIE)) { - if (period_code <=3D 2) - period_code +=3D 7; - /* period in 32 Khz cycles */ - period =3D 1 << (period_code - 1); -#ifdef TARGET_I386 - if (period !=3D s->period) { - s->irq_coalesced =3D (s->irq_coalesced * s->period) / period; - DPRINTF_C("cmos: coalesced irqs scaled to %d\n", s->irq_coales= ced); - } - s->period =3D period; -#endif + period =3D period_code_to_clock(period_code); + /* compute 32 khz clock */ cur_clock =3D muldiv64(current_time, RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND); =20 - next_irq_clock =3D (cur_clock & ~(period - 1)) + period; + /* + * if the periodic timer's update is due to period re-configuration, + * we should count the clock since last interrupt. + */ + if (old_period) { + int64_t last_periodic_clock; + + last_periodic_clock =3D muldiv64(s->next_periodic_time, + RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND= ); + /* + * if the next interrupt has not happened yet, we recall the l= ast + * interrupt based on the original period. + */ + if (last_periodic_clock > cur_clock) { + last_periodic_clock -=3D period_code_to_clock(old_period); + + /* the last interrupt must have happened. */ + assert(cur_clock >=3D last_periodic_clock); + } + + /* calculate the clock since last interrupt. */ + lost_clock =3D cur_clock - last_periodic_clock; + } + +#ifdef TARGET_I386 + /* + * recalculate the coalesced irqs for two reasons: + * a) the lost_clock is more that a period, i,e. the timer + * interrupt has been lost, we should catch up the time. + * + * b) the period may be reconfigured, under this case, when + * switching from a shorter to a longer period, scale down + * the missing ticks since we expect the OS handler to + * treat the delayed ticks as longer. Any leftovers are + * put back into lost_clock. + * When switching to a shorter period, scale up the missing + * ticks since we expect the OS handler to treat the delayed + * ticks as shorter. + */ + if (s->lost_tick_policy =3D=3D LOST_TICK_POLICY_SLEW) { + uint32_t cur_irq_coalesced =3D s->irq_coalesced; + uint32_t cur_period =3D s->period; + + lost_clock +=3D cur_irq_coalesced * cur_period; + s->irq_coalesced =3D lost_clock / period; + lost_clock %=3D period; + s->period =3D period; + if ((cur_irq_coalesced !=3D s->irq_coalesced) || + (cur_period |=3D s->period)) { + DPRINTF_C("cmos: coalesced irqs scaled from %d to %d, " + "period scaled from %d to %d\n", cur_irq_coalesc= ed, + s->irq_coalesced, cur_period, s->period); + rtc_coalesced_timer_update(s); + } + } +#endif + /* + * no way to compensate the interrupt if LOST_TICK_POLICY_SLEW + * is not used, we should make the time progress anyway. + */ + lost_clock =3D MIN(lost_clock, period); + assert(lost_clock >=3D 0); + + next_irq_clock =3D cur_clock + period - lost_clock; s->next_periodic_time =3D muldiv64(next_irq_clock, NANOSECONDS_PER= _SECOND, RTC_CLOCK_RATE) + 1; timer_mod(s->periodic_timer, s->next_periodic_time); @@ -186,7 +259,7 @@ static void rtc_periodic_timer(void *opaque) { RTCState *s =3D opaque; =20 - periodic_timer_update(s, s->next_periodic_time); + periodic_timer_update(s, s->next_periodic_time, 0); s->cmos_data[RTC_REG_C] |=3D REG_C_PF; if (s->cmos_data[RTC_REG_B] & REG_B_PIE) { s->cmos_data[RTC_REG_C] |=3D REG_C_IRQF; @@ -391,6 +464,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, uint64_t data, unsigned size) { RTCState *s =3D opaque; + int cur_period; bool update_periodic_timer; =20 if ((addr & 1) =3D=3D 0) { @@ -424,6 +498,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, } break; case RTC_REG_A: + cur_period =3D s->cmos_data[RTC_REG_A] & 0xf; update_periodic_timer =3D (s->cmos_data[RTC_REG_A] ^ data) & 0= x0f; =20 if ((data & 0x60) =3D=3D 0x60) { @@ -450,7 +525,8 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, (s->cmos_data[RTC_REG_A] & REG_A_UIP); =20 if (update_periodic_timer) { - periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock), + cur_period); } =20 check_update_timer(s); @@ -487,7 +563,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, s->cmos_data[RTC_REG_B] =3D data; =20 if (update_periodic_timer) { - periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock), 0); } =20 check_update_timer(s); @@ -757,7 +833,7 @@ static int rtc_post_load(void *opaque, int version_id) uint64_t now =3D qemu_clock_get_ns(rtc_clock); if (now < s->next_periodic_time || now > (s->next_periodic_time + get_max_clock_jump())) { - periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock), 0); } } =20 @@ -822,7 +898,7 @@ static void rtc_notify_clock_reset(Notifier *notifier, = void *data) int64_t now =3D *(int64_t *)data; =20 rtc_set_date_from_host(ISA_DEVICE(s)); - periodic_timer_update(s, now); + periodic_timer_update(s, now, 0); check_update_timer(s); #ifdef TARGET_I386 if (s->lost_tick_policy =3D=3D LOST_TICK_POLICY_SLEW) { --=20 2.9.3 From nobody Thu May 2 18:40:35 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.zoho.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 1493899472616524.6646727783186; Thu, 4 May 2017 05:04:32 -0700 (PDT) Received: from localhost ([::1]:41407 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FUl-0006DN-8l for importer@patchew.org; Thu, 04 May 2017 08:04:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FQk-0002j4-HA for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6FQe-0006iM-Gw for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:22 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:35225) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d6FQe-0006gv-BY for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:16 -0400 Received: by mail-pg0-x242.google.com with SMTP id i63so2023777pgd.2 for ; Thu, 04 May 2017 05:00:16 -0700 (PDT) Received: from eric.tencent.com ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id p7sm3698261pfb.125.2017.05.04.05.00.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 May 2017 05:00:14 -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; bh=GwcARz/o9a9Fjifns/6C2cRWjAODO2E3LU9WQhqoBsI=; b=Rytd0rmvD8CvYiNLgcHz1w8Zzg2CYIbKW5d+AEwMQNo/7ziTkTJDW5HzA0k792hkNO v8UXri2czqn9MudCIrlQskvLDdGD5XZENYUmS+QEsQbRI6G+svWQdIT5J78OdO1ywIVb 9tRz8fCya/pDoAvNd3a9KV2N4SbkTczfEnE9vZSUZ1emZRNQJXK82k5PVg3DaVrH9EMI hlVMFEvGIO4HUXz1MJEFH/U9EyRt0J61N8Z0Aog630eW7k169ZFp9n6scw/7va8W4Pq2 bZJ8JRNldUbnhMlvCXen7l7jQmevX7S5vfEV0LLrrfa0/eWbN6l+kVnKdDZrGQb1Ll2J Z63g== 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; bh=GwcARz/o9a9Fjifns/6C2cRWjAODO2E3LU9WQhqoBsI=; b=IJIzFg0FNcS7UmptCYZvIsXIuj175hy6LdwvQKmbBfqbNM1U382Cl+/6XNbejntYBy AaXzIGjUG4ostxcQJsEGqj4XEdspqSiPHwHREqFhS8G2bED1Jc5aKzdmqiQB2+85vrX4 0QnYpa/MzL/szx0PtB5UwRTv9KjopSNGZXTjisY3Z3O2IryNWFkuUSAEkCpadQUaY9GY MDzcW+DrBFEThILV20Zj/YAX87D/QuY5Y2x1wS+DFyeq/WwPacMl/PxQRqQvBbBdyL4B oizcAJk860Lhrr+80zot0rouHmDx+jIvXAl80RXFGFrPY3P9NdTGdu8sWmPNjmjOGLwJ H9mQ== X-Gm-Message-State: AN3rC/6m0WGVoveBU1hG9RUaTrYAkgOCi/QALasbjZk5iCb0bb6sq2AB 2TPLqRmLnH3/5A== X-Received: by 10.98.67.8 with SMTP id q8mr10584570pfa.67.1493899215337; Thu, 04 May 2017 05:00:15 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Thu, 4 May 2017 19:59:46 +0800 Message-Id: <20170504115948.3048-4-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170504115948.3048-1-xiaoguangrong@tencent.com> References: <20170504115948.3048-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH v2 3/5] mc146818rtc: ensure LOST_TICK_POLICY_SLEW is only enabled on TARGET_I386 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: Xiao Guangrong , yunfangtai@tencent.com, qemu-devel@nongnu.org, kvm@vger.kernel.org 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" From: Xiao Guangrong Any tick policy specified on other platforms rather on TARGET_I386 will fall back to LOST_TICK_POLICY_DISCARD silently, this patch makes sure only TARGET_I386 can enable LOST_TICK_POLICY_SLEW After that, we can enable LOST_TICK_POLICY_SLEW in the common code which need not use '#ifdef TARGET_I386' to make these code be x86 specific anymore Signed-off-by: Xiao Guangrong --- hw/timer/mc146818rtc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 14bde1a..7f2e975 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -976,19 +976,19 @@ static void rtc_realizefn(DeviceState *dev, Error **e= rrp) =20 rtc_set_date_from_host(isadev); =20 -#ifdef TARGET_I386 switch (s->lost_tick_policy) { +#ifdef TARGET_I386 case LOST_TICK_POLICY_SLEW: s->coalesced_timer =3D timer_new_ns(rtc_clock, rtc_coalesced_timer, s); break; +#endif case LOST_TICK_POLICY_DISCARD: break; default: error_setg(errp, "Invalid lost tick policy."); return; } -#endif =20 s->periodic_timer =3D timer_new_ns(rtc_clock, rtc_periodic_timer, s); s->update_timer =3D timer_new_ns(rtc_clock, rtc_update_timer, s); --=20 2.9.3 From nobody Thu May 2 18:40:35 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.zoho.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 149389933240849.88252861157696; Thu, 4 May 2017 05:02:12 -0700 (PDT) Received: from localhost ([::1]:41334 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FST-0003zh-Uq for importer@patchew.org; Thu, 04 May 2017 08:02:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51424) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FQn-0002mq-48 for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6FQi-0006oI-Th for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:25 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:33751) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d6FQi-0006nS-MQ for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:20 -0400 Received: by mail-pf0-x242.google.com with SMTP id b23so1846090pfc.0 for ; Thu, 04 May 2017 05:00:20 -0700 (PDT) Received: from eric.tencent.com ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id p7sm3698261pfb.125.2017.05.04.05.00.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 May 2017 05:00:17 -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; bh=XUTHKkVUnJx3fE1PDKqKKJpoJFnqLdQg0CvJjEJyCOU=; b=azwKbKOai0n2AIU/Tbb4r3saIpxArtlwRDd+n0HP8sFR6ws03EIvGHeU4aKpH+4qpe 4YCKeEUIjTKS71+jFfcNgAaCfqO4dPKdslDEz9YC0I4jsg5DY1mrCJYGCR0sBJq29AB5 Yk1cTXLXtmm2lEqBkdyoS0teW4ZFIyV6Rvbov0CN5zyUjc6t6QWoZSEaSoIGXjWI26p7 nijUrG6qCPUA6/SAFZznKeuPnU4bUWDzEvHyyKX6bcGL5nItca2Z1Td9sRLi3oy0tEUI IvX+t8Cl3dRaUMOkZG4ZdP2a2TGH+3la1z9lOsi2GV6r8Ai5WqAR0t44PI38Gnx19Q4p YxIg== 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; bh=XUTHKkVUnJx3fE1PDKqKKJpoJFnqLdQg0CvJjEJyCOU=; b=oETaTJVHfOfiGpfjv+R7q5UwI+A/pcPaD72NndbSQxjgEQh8dwaGRQEKV5Jszz+OD4 AAoSUGtrbQpHgFSFoxj28qhlxRRs47jMl9T/S99Bb7dWtGHzIoaoVLnTJMOGLufqIImq oAxkOX2AEXO/wZLl7UIi6HKlpKrjBjpCCq+UDUN1b8mJh4o0C2NgY63bcyoK4k0nbvHV 4ytjNMR4u5TT/2G4BDD8dpuEY6bQWr9fIP0e6s2tp5orImegY4K2PY3+fr6xMTbq5mTM pjYSs6xoLrL5smwgj37g4CRxn0KchV1ntDBBz8zn7gs73kQoGV1tlmWUffGlFsrc2/A+ apyg== X-Gm-Message-State: AN3rC/5R+duqyn3YzZKoOkmjlULcQ9BG+N6E3W+V6VDPW4EXdZoDJUB0 3/xFCzcQeIGeHQ== X-Received: by 10.98.142.25 with SMTP id k25mr10340277pfe.238.1493899217776; Thu, 04 May 2017 05:00:17 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Thu, 4 May 2017 19:59:47 +0800 Message-Id: <20170504115948.3048-5-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170504115948.3048-1-xiaoguangrong@tencent.com> References: <20170504115948.3048-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH v2 4/5] mc146818rtc: drop unnecessary '#ifdef TARGET_I386' 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: Xiao Guangrong , yunfangtai@tencent.com, qemu-devel@nongnu.org, kvm@vger.kernel.org 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" From: Xiao Guangrong If the code purely depends on LOST_TICK_POLICY_SLEW, we can simply drop '#ifdef TARGET_I386' as only x86 can enable this tick policy Signed-off-by: Xiao Guangrong --- hw/timer/mc146818rtc.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 7f2e975..8fc9313 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -112,7 +112,6 @@ static uint64_t get_guest_rtc_ns(RTCState *s) guest_clock - s->last_update + s->offset; } =20 -#ifdef TARGET_I386 static void rtc_coalesced_timer_update(RTCState *s) { if (s->irq_coalesced =3D=3D 0) { @@ -126,6 +125,7 @@ static void rtc_coalesced_timer_update(RTCState *s) } } =20 +#ifdef TARGET_I386 static void rtc_coalesced_timer(void *opaque) { RTCState *s =3D opaque; @@ -204,7 +204,6 @@ periodic_timer_update(RTCState *s, int64_t current_time= , int old_period) lost_clock =3D cur_clock - last_periodic_clock; } =20 -#ifdef TARGET_I386 /* * recalculate the coalesced irqs for two reasons: * a) the lost_clock is more that a period, i,e. the timer @@ -235,7 +234,7 @@ periodic_timer_update(RTCState *s, int64_t current_time= , int old_period) rtc_coalesced_timer_update(s); } } -#endif + /* * no way to compensate the interrupt if LOST_TICK_POLICY_SLEW * is not used, we should make the time progress anyway. @@ -248,9 +247,7 @@ periodic_timer_update(RTCState *s, int64_t current_time= , int old_period) RTC_CLOCK_RATE) + 1; timer_mod(s->periodic_timer, s->next_periodic_time); } else { -#ifdef TARGET_I386 s->irq_coalesced =3D 0; -#endif timer_del(s->periodic_timer); } } @@ -837,13 +834,11 @@ static int rtc_post_load(void *opaque, int version_id) } } =20 -#ifdef TARGET_I386 if (version_id >=3D 2) { if (s->lost_tick_policy =3D=3D LOST_TICK_POLICY_SLEW) { rtc_coalesced_timer_update(s); } } -#endif return 0; } =20 @@ -900,11 +895,10 @@ static void rtc_notify_clock_reset(Notifier *notifier= , void *data) rtc_set_date_from_host(ISA_DEVICE(s)); periodic_timer_update(s, now, 0); check_update_timer(s); -#ifdef TARGET_I386 + if (s->lost_tick_policy =3D=3D LOST_TICK_POLICY_SLEW) { rtc_coalesced_timer_update(s); } -#endif } =20 /* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE) @@ -925,12 +919,10 @@ static void rtc_reset(void *opaque) =20 qemu_irq_lower(s->irq); =20 -#ifdef TARGET_I386 if (s->lost_tick_policy =3D=3D LOST_TICK_POLICY_SLEW) { s->irq_coalesced =3D 0; s->irq_reinject_on_ack_count =3D 0; =09 } -#endif } =20 static const MemoryRegionOps cmos_ops =3D { --=20 2.9.3 From nobody Thu May 2 18:40:35 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.zoho.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 1493899573525819.034883797577; Thu, 4 May 2017 05:06:13 -0700 (PDT) Received: from localhost ([::1]:41477 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FWN-0007bK-1n for importer@patchew.org; Thu, 04 May 2017 08:06:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51422) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FQn-0002me-1b for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6FQj-0006p0-F4 for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:25 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:35238) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d6FQj-0006nw-6z for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:21 -0400 Received: by mail-pg0-x243.google.com with SMTP id i63so2024129pgd.2 for ; Thu, 04 May 2017 05:00:21 -0700 (PDT) Received: from eric.tencent.com ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id p7sm3698261pfb.125.2017.05.04.05.00.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 May 2017 05:00:19 -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; bh=64NB/7sVptwekHMgItUQKGnEHyxMdaNZoERtIZ1zQu0=; b=gsRasEwycPQ1WvkX0ESNH9kBX0SJY5/cyChHRjbcFNXB/VCgoawArtetG3At8Bmf9w /rwkacLXlkXyKGX0/EX3qFBm+A90sza1HbJWq6emb0RNWLpzSjZGE6cUA1U6IfeAmNhI yU208m6CjuBcKeyQOmYuOQAjukYMIcsFHh4TJZk/qdM/NOzzileRX5izOEjNd3tbOOgd JmKmbXtwGITEhfTZgtfIZR4lyTr6iE9sBX/HAIdKYvQ4kkLDgeDNviCfw84yOfd0ocpV YH60ZFmgY9rnCbZEZh+kwwaYO+hQGdSokx2qxqIUS/KLPnBa4vbDSAAE7alIiabf6stb /ZBA== 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; bh=64NB/7sVptwekHMgItUQKGnEHyxMdaNZoERtIZ1zQu0=; b=qu8N88JQdtTu7rHWGtGUynw8lBtixRqr/453+YtwAEnyJC2TZjCJ38KenKYsTCenF5 ll4cPAR8dAImiildE72jgH9XvqxxQUCR8UyDsJbUuMnLT3373PgQOb0PiYUq684eKDD0 2og5bVPqBC/i7WFcYgqt2fCbZ/jr7Z30JVt0dFy65JJ/bChQskr9K+YAjrBiy+tysdoy vQajDSPEVqro7KHzZn2j+x0UEeo6P8HvqXBiA94/ShKzq3f8M9SAO9CwRC+3SIw5kLpN 7MtdJ4ddbYInu95toca91iH/TNklwKg46ltfeuM4QxP6S1MAkSsgA2xspU2RfqiBMc6J M22g== X-Gm-Message-State: AN3rC/6nestJYtAWlUqb0LBJJoPCBhUg5Y0gQARtZiW0tdgxGqaXSuUU q5GLWnHRNMyqcQ== X-Received: by 10.84.216.26 with SMTP id m26mr38160481pli.79.1493899220216; Thu, 04 May 2017 05:00:20 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Thu, 4 May 2017 19:59:48 +0800 Message-Id: <20170504115948.3048-6-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170504115948.3048-1-xiaoguangrong@tencent.com> References: <20170504115948.3048-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH v2 5/5] mc146818rtc: embrace all x86 specific code 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: Xiao Guangrong , yunfangtai@tencent.com, qemu-devel@nongnu.org, kvm@vger.kernel.org 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" From: Xiao Guangrong Introduce a function, rtc_policy_slew_deliver_irq(), which delivers irq if LOST_TICK_POLICY_SLEW is used, as which is only supported on x86, other platforms call it will trigger a assert After that, we can move the x86 specific code to the common place Signed-off-by: Xiao Guangrong --- hw/timer/mc146818rtc.c | 60 ++++++++++++++++++++++++++--------------------= ---- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 8fc9313..987160c 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -125,17 +125,34 @@ static void rtc_coalesced_timer_update(RTCState *s) } } =20 +static QLIST_HEAD(, RTCState) rtc_devices =3D + QLIST_HEAD_INITIALIZER(rtc_devices); + #ifdef TARGET_I386 +void qmp_rtc_reset_reinjection(Error **errp) +{ + RTCState *s; + + QLIST_FOREACH(s, &rtc_devices, link) { + s->irq_coalesced =3D 0; + } +} + +static bool rtc_policy_slew_deliver_irq(RTCState *s) +{ + apic_reset_irq_delivered(); + qemu_irq_raise(s->irq); + return apic_get_irq_delivered(); +} + static void rtc_coalesced_timer(void *opaque) { RTCState *s =3D opaque; =20 if (s->irq_coalesced !=3D 0) { - apic_reset_irq_delivered(); s->cmos_data[RTC_REG_C] |=3D 0xc0; DPRINTF_C("cmos: injecting from timer\n"); - qemu_irq_raise(s->irq); - if (apic_get_irq_delivered()) { + if (rtc_policy_slew_deliver_irq(s)) { s->irq_coalesced--; DPRINTF_C("cmos: coalesced irqs decreased to %d\n", s->irq_coalesced); @@ -144,6 +161,12 @@ static void rtc_coalesced_timer(void *opaque) =20 rtc_coalesced_timer_update(s); } +#else +static bool rtc_policy_slew_deliver_irq(RTCState *s) +{ + assert(0); + return false; +} #endif =20 static int period_code_to_clock(int period_code) @@ -260,21 +283,17 @@ static void rtc_periodic_timer(void *opaque) s->cmos_data[RTC_REG_C] |=3D REG_C_PF; if (s->cmos_data[RTC_REG_B] & REG_B_PIE) { s->cmos_data[RTC_REG_C] |=3D REG_C_IRQF; -#ifdef TARGET_I386 if (s->lost_tick_policy =3D=3D LOST_TICK_POLICY_SLEW) { if (s->irq_reinject_on_ack_count >=3D RTC_REINJECT_ON_ACK_COUN= T) - s->irq_reinject_on_ack_count =3D 0; =09 - apic_reset_irq_delivered(); - qemu_irq_raise(s->irq); - if (!apic_get_irq_delivered()) { + s->irq_reinject_on_ack_count =3D 0; + if (!rtc_policy_slew_deliver_irq(s)) { s->irq_coalesced++; rtc_coalesced_timer_update(s); DPRINTF_C("cmos: coalesced irqs increased to %d\n", s->irq_coalesced); } } else -#endif - qemu_irq_raise(s->irq); + qemu_irq_raise(s->irq); } } =20 @@ -616,20 +635,6 @@ static void rtc_get_time(RTCState *s, struct tm *tm) rtc_from_bcd(s, s->cmos_data[RTC_CENTURY]) * 100 - 1900; } =20 -static QLIST_HEAD(, RTCState) rtc_devices =3D - QLIST_HEAD_INITIALIZER(rtc_devices); - -#ifdef TARGET_I386 -void qmp_rtc_reset_reinjection(Error **errp) -{ - RTCState *s; - - QLIST_FOREACH(s, &rtc_devices, link) { - s->irq_coalesced =3D 0; - } -} -#endif - static void rtc_set_time(RTCState *s) { struct tm tm; @@ -749,22 +754,19 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr= addr, if (ret & (REG_C_UF | REG_C_AF)) { check_update_timer(s); } -#ifdef TARGET_I386 + if(s->irq_coalesced && (s->cmos_data[RTC_REG_B] & REG_B_PIE) && s->irq_reinject_on_ack_count < RTC_REINJECT_ON_ACK_COU= NT) { s->irq_reinject_on_ack_count++; s->cmos_data[RTC_REG_C] |=3D REG_C_IRQF | REG_C_PF; - apic_reset_irq_delivered(); DPRINTF_C("cmos: injecting on ack\n"); - qemu_irq_raise(s->irq); - if (apic_get_irq_delivered()) { + if (rtc_policy_slew_deliver_irq(s)) { s->irq_coalesced--; DPRINTF_C("cmos: coalesced irqs decreased to %d\n", s->irq_coalesced); } } -#endif break; default: ret =3D s->cmos_data[s->cmos_index]; --=20 2.9.3