Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp768902ybj; Thu, 7 May 2020 07:15:28 -0700 (PDT) X-Google-Smtp-Source: APiQypJ6RG3mIaStPczH1EnoUf2zwC/UGEMtHKv5syDP+/p+8k5Lkxt5yAPudqDzvVBHQHXDzR4b X-Received: by 2002:a17:906:f90d:: with SMTP id lc13mr11603803ejb.367.1588860928061; Thu, 07 May 2020 07:15:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588860928; cv=none; d=google.com; s=arc-20160816; b=C4SLwjbUuzjr52SK2GZbUM1MWqw161Vbnsk2OsDKalZUjIm5yVAoM3QDuvcHT+QwYf 85hrC7FMotnn8MJbSxv9sW5js4wRNDTWKPQObq4iqlRv2wzSjdkMOiCRI0u5tPd9eaWc GEInS1J+FPrnU+kJwMiPaNIpPsTsMWYOwFMFHuTM+R/5PbLGjZAaYi+SSHER23sMxx5I dtlmUFwCJEIAmE3eBvNrLqN9UizYVKZGs0lui3wRd1DUeqN35qaM9whDZUpAnxlLmia7 teyxONtAkCPQKY7XRkhcQFGGnASptYxJxRF9b1oLtCDS6ohYs9uGO/Mr4Fd7jXZ1TuIE uLkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=vhrI+bjJ0BYmfUpIDIPQgOtxlPBenVX/4znksncd+m8=; b=bd83l2rlbFOPRG50oUPBBjL2iX8fsfFgblkeKoln7OGpMzDN3JUrOz08WzJMczuN9D GEGO5k00ciByltbaIdpmNiSpSMha6RqUkuSmHg6I2LTQ7ALWkBaimtXa2dg22WVzisZG ECp+0m/2B6YIs2BvIDsw9VwQLqSkh0OQ7m+h9l8JDVB4hPFfLfm0rFn2+jS2OS1Gs9Kv yLef/BEym8G+sHa+rTogln9YGrIH4w/2DOQ8/yeAPOk+Li+PqabQjrIDST4hbMkiuBZI Ip/rIom+iDBqn948rrX+3BB1bDNDaMR+PrH5Vw5n9oQ8xg/miCTidbsD1I3+t0q73bVI b9Uw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cx2si3113064edb.452.2020.05.07.07.15.03; Thu, 07 May 2020 07:15:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727982AbgEGONd (ORCPT + 99 others); Thu, 7 May 2020 10:13:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727788AbgEGONb (ORCPT ); Thu, 7 May 2020 10:13:31 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A67FC05BD43; Thu, 7 May 2020 07:13:31 -0700 (PDT) Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jWhHD-0002c5-RK; Thu, 07 May 2020 16:13:28 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 476A11C0451; Thu, 7 May 2020 16:13:27 +0200 (CEST) Date: Thu, 07 May 2020 14:13:27 -0000 From: "tip-bot2 for Thomas Gleixner" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/timers] x86/delay: Preparatory code cleanup Cc: Thomas Gleixner , Kyung Min Park , x86 , LKML In-Reply-To: <1587757076-30337-2-git-send-email-kyung.min.park@intel.com> References: <1587757076-30337-2-git-send-email-kyung.min.park@intel.com> MIME-Version: 1.0 Message-ID: <158886080725.8414.13575285074483659672.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/timers branch of tip: Commit-ID: e8824890249355656968d8846908a313fe231f11 Gitweb: https://git.kernel.org/tip/e8824890249355656968d8846908a313fe231f11 Author: Thomas Gleixner AuthorDate: Fri, 24 Apr 2020 12:37:54 -07:00 Committer: Thomas Gleixner CommitterDate: Thu, 07 May 2020 16:06:19 +02:00 x86/delay: Preparatory code cleanup The naming conventions in the delay code are confusing at best. All delay variants use a loops argument and or variable which originates from the original delay_loop() implementation. But all variants except delay_loop() are based on TSC cycles. Rename the argument to cycles and make it type u64 to avoid these weird expansions to u64 in the functions. Rename MWAITX_MAX_LOOPS to MWAITX_MAX_WAIT_CYCLES for the same reason and fixup the comment of delay_mwaitx() as well. Mark the delay_fn function pointer __ro_after_init and fixup the comment for it. No functional change and preparation for the upcoming TPAUSE based delay variant. [ Kyung Min Park: Added __init to use_tsc_delay() ] Signed-off-by: Thomas Gleixner Signed-off-by: Kyung Min Park Signed-off-by: Thomas Gleixner Link: https://lkml.kernel.org/r/1587757076-30337-2-git-send-email-kyung.min.park@intel.com --- arch/x86/include/asm/delay.h | 3 +- arch/x86/include/asm/mwait.h | 2 +- arch/x86/lib/delay.c | 45 ++++++++++++++++++----------------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/arch/x86/include/asm/delay.h b/arch/x86/include/asm/delay.h index de9e784..9aa38de 100644 --- a/arch/x86/include/asm/delay.h +++ b/arch/x86/include/asm/delay.h @@ -3,8 +3,9 @@ #define _ASM_X86_DELAY_H #include +#include -void use_tsc_delay(void); +void __init use_tsc_delay(void); void use_mwaitx_delay(void); #endif /* _ASM_X86_DELAY_H */ diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h index b809f11..a43b35b 100644 --- a/arch/x86/include/asm/mwait.h +++ b/arch/x86/include/asm/mwait.h @@ -20,7 +20,7 @@ #define MWAIT_ECX_INTERRUPT_BREAK 0x1 #define MWAITX_ECX_TIMER_ENABLE BIT(1) -#define MWAITX_MAX_LOOPS ((u32)-1) +#define MWAITX_MAX_WAIT_CYCLES UINT_MAX #define MWAITX_DISABLE_CSTATES 0xf0 u32 get_umwait_control_msr(void); diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c index c126571..887d52d 100644 --- a/arch/x86/lib/delay.c +++ b/arch/x86/lib/delay.c @@ -27,9 +27,19 @@ # include #endif +static void delay_loop(u64 __loops); + +/* + * Calibration and selection of the delay mechanism happens only once + * during boot. + */ +static void (*delay_fn)(u64) __ro_after_init = delay_loop; + /* simple loop based delay: */ -static void delay_loop(unsigned long loops) +static void delay_loop(u64 __loops) { + unsigned long loops = (unsigned long)__loops; + asm volatile( " test %0,%0 \n" " jz 3f \n" @@ -49,9 +59,9 @@ static void delay_loop(unsigned long loops) } /* TSC based delay: */ -static void delay_tsc(unsigned long __loops) +static void delay_tsc(u64 cycles) { - u64 bclock, now, loops = __loops; + u64 bclock, now; int cpu; preempt_disable(); @@ -59,7 +69,7 @@ static void delay_tsc(unsigned long __loops) bclock = rdtsc_ordered(); for (;;) { now = rdtsc_ordered(); - if ((now - bclock) >= loops) + if ((now - bclock) >= cycles) break; /* Allow RT tasks to run */ @@ -77,7 +87,7 @@ static void delay_tsc(unsigned long __loops) * counter for this CPU. */ if (unlikely(cpu != smp_processor_id())) { - loops -= (now - bclock); + cycles -= (now - bclock); cpu = smp_processor_id(); bclock = rdtsc_ordered(); } @@ -87,24 +97,24 @@ static void delay_tsc(unsigned long __loops) /* * On some AMD platforms, MWAITX has a configurable 32-bit timer, that - * counts with TSC frequency. The input value is the loop of the - * counter, it will exit when the timer expires. + * counts with TSC frequency. The input value is the number of TSC cycles + * to wait. MWAITX will also exit when the timer expires. */ -static void delay_mwaitx(unsigned long __loops) +static void delay_mwaitx(u64 cycles) { - u64 start, end, delay, loops = __loops; + u64 start, end, delay; /* * Timer value of 0 causes MWAITX to wait indefinitely, unless there * is a store on the memory monitored by MONITORX. */ - if (loops == 0) + if (!cycles) return; start = rdtsc_ordered(); for (;;) { - delay = min_t(u64, MWAITX_MAX_LOOPS, loops); + delay = min_t(u64, MWAITX_MAX_WAIT_CYCLES, cycles); /* * Use cpu_tss_rw as a cacheline-aligned, seldomly @@ -121,22 +131,15 @@ static void delay_mwaitx(unsigned long __loops) end = rdtsc_ordered(); - if (loops <= end - start) + if (cycles <= end - start) break; - loops -= end - start; - + cycles -= end - start; start = end; } } -/* - * Since we calibrate only once at boot, this - * function should be set once at boot and not changed - */ -static void (*delay_fn)(unsigned long) = delay_loop; - -void use_tsc_delay(void) +void __init use_tsc_delay(void) { if (delay_fn == delay_loop) delay_fn = delay_tsc;