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: 9711751 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5675360362 for ; Thu, 4 May 2017 12:00:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A3DA2623C for ; Thu, 4 May 2017 12:00:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EE4528686; Thu, 4 May 2017 12:00:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F9B92623C for ; Thu, 4 May 2017 12:00:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753523AbdEDMA0 (ORCPT ); Thu, 4 May 2017 08:00:26 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36817 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753299AbdEDMAV (ORCPT ); Thu, 4 May 2017 08:00:21 -0400 Received: by mail-pg0-f67.google.com with SMTP id v1so2012612pgv.3 for ; Thu, 04 May 2017 05:00:20 -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=fSNmvwGaYhedcTpqE2U3/H0aM6OGkv69myQk2bZV2WUr0f37+jKSa3PE/RCZSRHKxA pERZlQ+lktV0zLTBdy8FRMngbu7iE+cXmoI7fspfi+ly86Ql0heBlogAsIEKZa9WMi/U OBQtvXQ+DO4rnJPBdfyuDFhln8TYy8mXUu6LmHQyd3daIk8SSvn123WSvSnOr1tTOCYn yfS04SxLNKndZcXEEFaxqLFyq9YHXEL9lRb3R53Vlk5xoltsO6BHGTdwEQec7PfRNQhA zlwKmZr0angN/nt2OjgdmzSVK32lZZNwWxOAyyENgghMwMddrKBf+mStv6BXy5skA7iB J/tw== X-Gm-Message-State: AN3rC/6+UIRz8DXs20nMXUC5fWZBXtz853m7F0+J3KSoJciP1TkK/pv4 E2arcHJxQZTEQQ== 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 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, yunfangtai@tencent.com, Xiao Guangrong Subject: [PATCH v2 5/5] mc146818rtc: embrace all x86 specific code 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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];