From patchwork Thu May 4 11:59:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 758549 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wJYd86Th9z9s0m for ; Thu, 4 May 2017 22:05:32 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gsRasEwy"; dkim-atps=neutral Received: from localhost ([::1]:41469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FVi-0006qw-Bv for incoming@patchwork.ozlabs.org; Thu, 04 May 2017 08:05:30 -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) 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) 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) 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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) } } +static QLIST_HEAD(, RTCState) rtc_devices = + 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 = 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 = opaque; if (s->irq_coalesced != 0) { - apic_reset_irq_delivered(); s->cmos_data[RTC_REG_C] |= 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) rtc_coalesced_timer_update(s); } +#else +static bool rtc_policy_slew_deliver_irq(RTCState *s) +{ + assert(0); + return false; +} #endif 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] |= REG_C_PF; if (s->cmos_data[RTC_REG_B] & REG_B_PIE) { s->cmos_data[RTC_REG_C] |= REG_C_IRQF; -#ifdef TARGET_I386 if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) { if (s->irq_reinject_on_ack_count >= RTC_REINJECT_ON_ACK_COUNT) - s->irq_reinject_on_ack_count = 0; - apic_reset_irq_delivered(); - qemu_irq_raise(s->irq); - if (!apic_get_irq_delivered()) { + s->irq_reinject_on_ack_count = 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); } } @@ -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; } -static QLIST_HEAD(, RTCState) rtc_devices = - 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 = 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_COUNT) { s->irq_reinject_on_ack_count++; s->cmos_data[RTC_REG_C] |= 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 = s->cmos_data[s->cmos_index];