Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1065205ybb; Fri, 10 Apr 2020 16:30:53 -0700 (PDT) X-Google-Smtp-Source: APiQypJbIDtnUuZlyjKVUce74zTogwFm/tTNncKe6sv62uZBMuBGi40Slv5FI9SP+wtg+vz5Sx4C X-Received: by 2002:a0c:f548:: with SMTP id p8mr4011188qvm.199.1586561453296; Fri, 10 Apr 2020 16:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586561453; cv=none; d=google.com; s=arc-20160816; b=XR85HAQB2D/TtQupJzXRkSYBWOXTZ+UaNjE/OlVish+L94ntGaZGgYZcUX83uB14iU VENZ/TgWeTDGW2KmwmzfGG0y6b4nW/osy/ogba9YdDqV9mjqw5Tt9md+cJHvsdH9X3rH +C1JZXLKJ+He6q0v3PpcsVaxNOvFGLqeCqMaQeGBW2PRA75GFMVGsW4gRQbiLcXFgvs3 E9e8GgVtyslEDlZk/OskRxWuhbOeFXX2lnz53vjaE62jsyis7yRT2rv3CvhoRH6utu2j rCdgYkjNk7srncAWR3OlUKF+m1oO6qODdTR7OMHSZM/By6CRQeVpyqjV2vm7PbO7leXi Ualw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=soEB9+Z93gSBd5yqpuUr+BwRs62e0bn46hEc0qTGw50=; b=pgU2FSDMw+Ltg8CObUmWl5AJW8+idNT5/h+cZAIhHirs/z7u4MlM+BwQ1dnS4RrJq3 uYtmMVsWnQqBoamIQa1Yq0n+s7m6NdKXgKm+qiZoStG+XsPRVV/+vVF/ayGGMKITAABF C5JFQiK7KX1rt0hp8pEc8a8+/YGZ8h7GQ+U3a1m7oLHju9JvFGrAuso73/Y7BCvIiNMO g3EduRrya8EzMmyNWby34Bj3aSgyw+xnXpd3VoTGOg/PtGoGw0WNQq7tdyTyslZ6J+V9 46zOPurSsY/Zeu0N1ptbHHYwtgz2vdk2M8sWP1NVjKdN8KIHJ2Fw4YrZB3JTnm2tDA0n 4+cA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb13si1958635qvb.136.2020.04.10.16.30.36; Fri, 10 Apr 2020 16:30:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726783AbgDJX3n (ORCPT + 99 others); Fri, 10 Apr 2020 19:29:43 -0400 Received: from mga18.intel.com ([134.134.136.126]:5049 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726678AbgDJX3k (ORCPT ); Fri, 10 Apr 2020 19:29:40 -0400 IronPort-SDR: yGiWCFyBymcTfybOAn4bxya6fKnbzy9rEauBOIiBzJACIpnpgIxT2X0KwtDVJtyECXpC6QD+sb FYB2Gh27UOqw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2020 16:29:40 -0700 IronPort-SDR: +MCgeTjluZ7adXp+74ZEdFbObWadOf6uRxamiy2iHK7qJbMICaKxc4NU6G21nAAE7X+sIVlBUT yJuygeZjLx4g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,368,1580803200"; d="scan'208";a="399057318" Received: from kmp-skylake-client-platform.sc.intel.com ([172.25.112.108]) by orsmga004.jf.intel.com with ESMTP; 10 Apr 2020 16:29:40 -0700 From: Kyung Min Park To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, gregkh@linuxfoundation.org, ak@linux.intel.com, tony.luck@intel.com, ashok.raj@intel.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, kyung.min.park@intel.com Subject: [PATCH v3 1/3] x86/delay: Preparatory code cleanup Date: Fri, 10 Apr 2020 16:29:53 -0700 Message-Id: <1586561395-50914-2-git-send-email-kyung.min.park@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1586561395-50914-1-git-send-email-kyung.min.park@intel.com> References: <1586561395-50914-1-git-send-email-kyung.min.park@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner From: Thomas Gleixner 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 --- arch/x86/include/asm/delay.h | 2 +- arch/x86/include/asm/mwait.h | 2 +- arch/x86/lib/delay.c | 45 +++++++++++++++++++++++--------------------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/arch/x86/include/asm/delay.h b/arch/x86/include/asm/delay.h index de9e784..bb91d7c 100644 --- a/arch/x86/include/asm/delay.h +++ b/arch/x86/include/asm/delay.h @@ -4,7 +4,7 @@ #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; -- 2.7.4