From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932852AbbFILBd (ORCPT ); Tue, 9 Jun 2015 07:01:33 -0400 Received: from mail-bl2on0134.outbound.protection.outlook.com ([65.55.169.134]:21226 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753721AbbFILBY (ORCPT ); Tue, 9 Jun 2015 07:01:24 -0400 Authentication-Results: spf=none (sender IP is 165.204.84.221) smtp.mailfrom=amd.com; amacapital.net; dkim=none (message not signed) header.d=none; X-WSS-ID: 0NPOBY7-07-514-02 X-M-MSG: Date: Tue, 9 Jun 2015 18:59:36 +0800 From: Huang Rui To: Peter Zijlstra CC: Borislav Petkov , Andy Lutomirski , Thomas Gleixner , "Rafael J. Wysocki" , Len Brown , John Stultz , =?iso-8859-1?Q?Fr=E9d=E9ric?= Weisbecker , "linux-kernel@vger.kernel.org" , "x86@kernel.org" , "Fengguang Wu" , Aaron Lu , "Suthikulpanit, Suravee" , "Li, Tony" , "Xue, Ken" Subject: Re: [PATCH v2 3/4] x86, mwaitt: introduce mwaix delay with a configurable timer Message-ID: <20150609105935.GE17030@hr-slim.amd.com> References: <1433819621-15093-1-git-send-email-ray.huang@amd.com> <1433819621-15093-4-git-send-email-ray.huang@amd.com> <20150609092952.GR3644@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20150609092952.GR3644@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD034;1:DWgCSxI9pSQhATTLVYmjTg2O8smIj7ItZiBhyjm9MbHl4fdg92TC2I7pkC5D0VBuYlQJHd7NPsYocpCx3MfTdRBFzaeMr1JsLa5z3fHlIOPl2m+yrpVtNABvdI988vhOo6ZTJ8b2fKCCS0JpcZGfTYqoEwKy+kXQxNiPIDgM7/S1yQY6MiDBF8PDwaR9SOSBE0b3GnFWODOc737mBh3iOs4fYEGeOJyoGkkCnCNkgl8zc/iy/D9dNslQ8TtiHQPN/dQ3HpKoTZgvtkKHvmIopGx+l0scMyPcs0EvpmYmrtiaaGZZxA75DA+ghOo07zS1C6KajD1tTOVyKhJlaczpIg== X-Forefront-Antispam-Report: CIP:165.204.84.221;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(428002)(199003)(189002)(51704005)(164054003)(46406003)(54356999)(53416004)(23726002)(105586002)(92566002)(83506001)(50986999)(47776003)(4001350100001)(46102003)(50466002)(77096005)(87936001)(2950100001)(77156002)(76176999)(33656002)(5001920100001)(189998001)(110136002)(97756001)(86362001)(106466001)(62966003)(101416001);DIR:OUT;SFP:1102;SCL:1;SRVR:BN3PR02MB1112;H:atltwp01.amd.com;FPR:;SPF:None;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR02MB1112; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(520003)(3002001);SRVR:BN3PR02MB1112;BCL:0;PCL:0;RULEID:;SRVR:BN3PR02MB1112; X-Forefront-PRVS: 06022AA85F X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2015 11:01:21.2157 (UTC) X-MS-Exchange-CrossTenant-Id: fde4dada-be84-483f-92cc-e026cbee8e96 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fde4dada-be84-483f-92cc-e026cbee8e96;Ip=[165.204.84.221];Helo=[atltwp01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR02MB1112 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 09, 2015 at 05:29:52PM +0800, Peter Zijlstra wrote: > On Tue, Jun 09, 2015 at 11:13:40AM +0800, Huang Rui wrote: > > +static void delay_mwaitx(unsigned long __loops) > > +{ > > + u32 end, now, delay, addr; > > + > > + delay = __loops; > > + rdtsc_barrier(); > > + rdtscl(end); > > + end += delay; > > + > > + while (1) { > > + __monitorx(&addr, 0, 0); > > + mwaitx(delay, true); > > + > > + rdtsc_barrier(); > > + rdtscl(now); > > + if (end <= now) > > + break; > > + delay = end - now; > > + } > > How about you think instead and do something like: > > rdtsc(start); > rdtsc_barrier(); > > for (;;) { > delay = min(MWAIT_MAX_LOOPS, loops); > > __monitorx(&addr, 0, 0); > mwaitx(delay, true); > > rdtsc_barrier(); > rdtsc(end); > rdtsc_barrier(); > > loops -= end - start; > if (loops <= 0) > break; > > start = end; > } > It looks better, thanks. :) > > +} > > + > > +/* > > * Since we calibrate only once at boot, this > > * function should be set once at boot and not changed > > */ > > @@ -118,7 +145,12 @@ int read_current_timer(unsigned long *timer_val) > > > > void __delay(unsigned long loops) > > { > > - delay_fn(loops); > > + if (loops > MWAITX_MAX_LOOPS || > > + !static_cpu_has_safe(X86_FEATURE_MWAITT) || > > + boot_option_delay != DELAY_MWAITX) > > + delay_fn(loops); > > + else > > + delay_mwaitx(loops); > > } > > Then you can do away with that fallback entirely. OK, I will submit V3 to remove kernel parameter and with the change of delay method. Thanks, Rui