From patchwork Fri Jun 30 04:07:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dou Liyang X-Patchwork-Id: 9818963 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 F185060224 for ; Fri, 30 Jun 2017 09:20:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1B51285FB for ; Fri, 30 Jun 2017 09:20:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4AD12861F; Fri, 30 Jun 2017 09:20:48 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7A069285FB for ; Fri, 30 Jun 2017 09:20:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dQs4B-0005WH-6N; Fri, 30 Jun 2017 09:18:19 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dQnE8-0008K3-Rl for xen-devel@lists.xenproject.org; Fri, 30 Jun 2017 04:08:16 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id A2/0A-02181-0BEC5595; Fri, 30 Jun 2017 04:08:16 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrMIsWRWlGSWpSXmKPExsViPb2gRXf9udB Ig7vLFSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyLvR+ZC76JVFxc1sfewDhTsIuRk0NCwE9i Ves2FhBbSKBW4vO+a+wQ9kpGicPHbbsYuYDs44wSU2ZOYQNJsAnoSJxpfgBWJCIQLrF2bTcbS BGzwDNGiU8/fzCCJIQFgiXOT5rIDGKzCKhKvFu5iBXE5hWIl7gwawkTxGY5iW1b9oDVcwrYSi y58hxqs43Eo13dTBD1ghInZz4Bu45ZQELi4IsXzBC9ShKv1x1ggbB1JZadec8IYWtKbFt9jg3 CNpM4svM/K4QtKLHz+QW2CYwis5CMnYVk7AJGplWMGsWpRWWpRbqG5npJRZnpGSW5iZk5uoYG xnq5qcXFiempOYlJxXrJ+bmbGIGBzgAEOxhfnvY8xCjJwaQkyntuUWikEF9SfkplRmJxRnxRa U5q8SFGGQ4OJQnesLNAOcGi1PTUirTMHGDMwaQlOHiURHgFlgCleYsLEnOLM9MhUqcYLTk2rF 7/hYmjY8bPb0wcx0CkEEtefl6qlDivGsg8AZCGjNI8uHGwtHCJUVZKmJcR6EAhnoLUotzMElT 5V4ziHIxKwrw8IFN4MvNK4La+AjqICegg4RkhIAeVJCKkpBoYd1z15nr+K608oOFP2Kbd+juu xGdtOcFhwhftLvUrUGz/ezeHlt4ZN178lZjG33867NwzMV9nLpumnOsllvELqyXnqbTKG17+9 CQgceoVWTGWgPzcI9afhS50Xpx15NNJpk1rwpsetX50qNYWfOXGNSX39uS0J59C+pS+28eFLz m64uBR5TsMSizFGYmGWsxFxYkA0cYGygYDAAA= X-Env-Sender: douly.fnst@cn.fujitsu.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1498795690!103343455!4 X-Originating-IP: [59.151.112.132] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15731 invoked from network); 30 Jun 2017 04:08:15 -0000 Received: from cn.fujitsu.com (HELO heian.cn.fujitsu.com) (59.151.112.132) by server-8.tower-31.messagelabs.com with SMTP; 30 Jun 2017 04:08:15 -0000 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="20680355" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 30 Jun 2017 12:08:12 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 65BB147F64E0; Fri, 30 Jun 2017 12:08:13 +0800 (CST) Received: from localhost.localdomain.localdomain (10.167.226.106) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 30 Jun 2017 12:08:11 +0800 From: Dou Liyang To: , , Date: Fri, 30 Jun 2017 12:07:36 +0800 Message-ID: <3ce38e2076e32d1e323f0ef9d236937c1c251bc1.1498795030.git.douly.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.226.106] X-yoursite-MailScanner-ID: 65BB147F64E0.A5066 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: douly.fnst@cn.fujitsu.com X-Mailman-Approved-At: Fri, 30 Jun 2017 09:18:16 +0000 Cc: Dou Liyang , bhe@redhat.com, peterz@infradead.org, mingo@kernel.org, ebiederm@xmission.com, hpa@zytor.com, izumi.taku@jp.fujitsu.com, boris.ostrovsky@oracle.com, tglx@linutronix.de Subject: [Xen-devel] [PATCH v5 08/12] x86/ioapic: Refactor the delay logic in timer_irq_works() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Kernel use timer_irq_works() to detects the timer IRQs. It calls mdelay(10) to delay ten ticks and check whether the timer IRQ work or not. The mdelay() depends on the loops_per_jiffy which is set up in calibrate_delay(). Current kernel defaults the IRQ 0 is available when it calibrates delay. But it is wrong in the dump-capture kernel with 'notsc' option inherited from 1st kernel option. dump-capture kernel can't make sure the timer IRQ works well. The correct design is making the interrupt mode setup and checking timer IRQ works in advance of calibrate_delay(). That results in the mdelay() being unusable in timer_irq_works(). Preparatory patch to make the setup in advance. Refactor the delay logic by waiting for some cycles. In the system with X86_FEATURE_TSC feature, Use rdtsc(), others will call __delay() directly. Note: regard 4G as the max CPU frequence of current single CPU. Signed-off-by: Dou Liyang --- arch/x86/kernel/apic/io_apic.c | 45 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index 347bb9f..f710077 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -1607,6 +1607,43 @@ static int __init notimercheck(char *s) } __setup("no_timer_check", notimercheck); +static void __init delay_with_tsc(void) +{ + unsigned long long start, now; + unsigned long ticks = jiffies; + + start = rdtsc(); + + /* + * We don't know the TSC frequency yet, but waiting for + * 40000000000/HZ TSC cycles is safe: + * 4 GHz == 10 jiffies + * 1 GHz == 40 jiffies + */ + do { + rep_nop(); + now = rdtsc(); + } while ((now - start) < 40000000000UL / HZ && + time_before_eq(jiffies, ticks + 4)); +} + +static void __init delay_without_tsc(void) +{ + int band = 1; + unsigned long ticks = jiffies; + + /* + * We don't know any frequency yet, but waiting for + * 40940000000/HZ cycles is safe: + * 4 GHz == 10 jiffies + * 1 GHz == 40 jiffies + * 1 << 1 + 1 << 2 +...+ 1 << 11 = 4094 + */ + do { + __delay(((1 << band++) * 10000000UL) / HZ); + } while (band < 12 && time_before_eq(jiffies, ticks + 4)); +} + /* * There is a nasty bug in some older SMP boards, their mptable lies * about the timer IRQ. We do the following to work around the situation: @@ -1625,8 +1662,12 @@ static int __init timer_irq_works(void) local_save_flags(flags); local_irq_enable(); - /* Let ten ticks pass... */ - mdelay((10 * 1000) / HZ); + + if (boot_cpu_has(X86_FEATURE_TSC)) + delay_with_tsc(); + else + delay_without_tsc(); + local_irq_restore(flags); /*