Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp190016ybf; Wed, 26 Feb 2020 11:12:39 -0800 (PST) X-Google-Smtp-Source: APXvYqz1m9yLcfDrTwgLin7ZSUpoAcKYuLw/m+bWHgPdPZACSL9gdFjg+ikosLAuE1XcO7Cznup9 X-Received: by 2002:a54:4006:: with SMTP id x6mr383132oie.145.1582744359323; Wed, 26 Feb 2020 11:12:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582744359; cv=none; d=google.com; s=arc-20160816; b=sO4ejqwDBQ1rSd4IZy6i7lOGzc5F1s9dOYxgw/v6R8c+X+1jkivf+eBBT+wy8KMPk8 gaoFurRquB98TgR4yo4NK6ATnz6oHlWhLT70tounnS99ceyxqZ89EItaGUXNgwRhJGga YkpJIk7X1Y7yBKBgXanIGgpOY8CCGdt3nQlKho9qDIUSYSG9kqK9RgD6fW8uu28jogpP wJTwjxXdEtAJvC0NxIqOcU17LJAiRbpNn+Ecy71EnsQGOqgzo6MjoC21wPeAIYAaqW52 726hXnql10oU19maWKBtemZuax3xiqLqhdRs3gZl3wWedU3rjGoFjRu2V8toe7uLnU/c gx9Q== 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; bh=0W/ZKAhFUKK2CKr/HD94juBN77g94HY7ir8mM0bMd9Q=; b=NeXM2RIgD6S3p+7XMcQb1SWLmMCI0Wmp9UAVDf4qhAn3qMwJjZu2QP6LlvzcsjVdjA R+ZArrYhndh0d2jK56sOfQ4diL8f29vBXMuVu1Q7FxTFiXuS664Swo7BDNIy02+YSmSi 4YXlDeljhH9wcEItYj0JYZe8pnxHaeKvKGU+RVoFktAl9u1pcKQcURwIiKCqikTDEEAn eSMn7k4+SY27SGcAnoeq9lrlyeF26CcI8W+mTo9Ld5MbXMPKqN/3Sd9VshYSLnD8fH4L 7Pfohrd6FfJG02d6sYct+4B1WDPoCSQ7IKi8bsop24alFVp98BN6Fmh3cb0+7vKTVg8c GTow== 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 j8si223309otr.161.2020.02.26.11.12.26; Wed, 26 Feb 2020 11:12:39 -0800 (PST) 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 S1727307AbgBZTLq (ORCPT + 99 others); Wed, 26 Feb 2020 14:11:46 -0500 Received: from mga11.intel.com ([192.55.52.93]:20002 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727146AbgBZTLl (ORCPT ); Wed, 26 Feb 2020 14:11:41 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Feb 2020 11:11:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,489,1574150400"; d="scan'208";a="285072249" Received: from kmp-skylake-client-platform.sc.intel.com ([172.25.112.108]) by FMSMGA003.fm.intel.com with ESMTP; 26 Feb 2020 11:11:40 -0800 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 Subject: [PATCH 1/2] x86/asm: Define a few helpers in delay_waitx() Date: Wed, 26 Feb 2020 11:10:57 -0800 Message-Id: <1582744258-42744-2-git-send-email-kyung.min.park@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1582744258-42744-1-git-send-email-kyung.min.park@intel.com> References: <1582744258-42744-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 Refactor code to make it easier to add a new model specific function to delay for a number of cycles. No functional change. Reviewed-by: Tony Luck Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Kyung Min Park --- arch/x86/lib/delay.c | 58 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c index c126571..6be29cf 100644 --- a/arch/x86/lib/delay.c +++ b/arch/x86/lib/delay.c @@ -90,9 +90,36 @@ static void delay_tsc(unsigned long __loops) * counts with TSC frequency. The input value is the loop of the * counter, it will exit when the timer expires. */ -static void delay_mwaitx(unsigned long __loops) +static void mwaitx(u64 unused, u64 loops) { - u64 start, end, delay, loops = __loops; + u64 delay; + + delay = min_t(u64, MWAITX_MAX_LOOPS, loops); + /* + * Use cpu_tss_rw as a cacheline-aligned, seldomly + * accessed per-cpu variable as the monitor target. + */ + __monitorx(raw_cpu_ptr(&cpu_tss_rw), 0, 0); + + /* + * AMD, like Intel, supports the EAX hint and EAX=0xf + * means, do not enter any deep C-state and we use it + * here in delay() to minimize wakeup latency. + */ + __mwaitx(MWAITX_DISABLE_CSTATES, delay, MWAITX_ECX_TIMER_ENABLE); +} + +static void (*wait_func)(u64, u64); + +/* + * Call a vendor specific function to delay for a given + * amount of time. Because these functions may return + * earlier than requested, check for actual elapsed time + * and call again until done. + */ +static void delay_iterate(unsigned long __loops) +{ + u64 start, end, loops = __loops; /* * Timer value of 0 causes MWAITX to wait indefinitely, unless there @@ -104,20 +131,8 @@ static void delay_mwaitx(unsigned long __loops) start = rdtsc_ordered(); for (;;) { - delay = min_t(u64, MWAITX_MAX_LOOPS, loops); - - /* - * Use cpu_tss_rw as a cacheline-aligned, seldomly - * accessed per-cpu variable as the monitor target. - */ - __monitorx(raw_cpu_ptr(&cpu_tss_rw), 0, 0); - /* - * AMD, like Intel's MWAIT version, supports the EAX hint and - * EAX=0xf0 means, do not enter any deep C-state and we use it - * here in delay() to minimize wakeup latency. - */ - __mwaitx(MWAITX_DISABLE_CSTATES, delay, MWAITX_ECX_TIMER_ENABLE); + wait_func(start, loops); end = rdtsc_ordered(); @@ -134,22 +149,23 @@ static void delay_mwaitx(unsigned long __loops) * 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; +static void (*delay_platform)(unsigned long) = delay_loop; void use_tsc_delay(void) { - if (delay_fn == delay_loop) - delay_fn = delay_tsc; + if (delay_platform == delay_loop) + delay_platform = delay_tsc; } void use_mwaitx_delay(void) { - delay_fn = delay_mwaitx; + wait_func = mwaitx; + delay_platform = delay_iterate; } int read_current_timer(unsigned long *timer_val) { - if (delay_fn == delay_tsc) { + if (delay_platform == delay_tsc) { *timer_val = rdtsc(); return 0; } @@ -158,7 +174,7 @@ int read_current_timer(unsigned long *timer_val) void __delay(unsigned long loops) { - delay_fn(loops); + delay_platform(loops); } EXPORT_SYMBOL(__delay); -- 2.7.4