Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755989AbcDDSVA (ORCPT ); Mon, 4 Apr 2016 14:21:00 -0400 Received: from mail-by2on0142.outbound.protection.outlook.com ([207.46.100.142]:1227 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754687AbcDDSU6 (ORCPT ); Mon, 4 Apr 2016 14:20:58 -0400 Authentication-Results: infradead.org; dkim=none (message not signed) header.d=none;infradead.org; dmarc=none action=none header.from=hpe.com; Message-ID: <5702B082.4080703@hpe.com> Date: Mon, 4 Apr 2016 14:20:50 -0400 From: Waiman Long User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130109 Thunderbird/10.0.12 MIME-Version: 1.0 To: Peter Zijlstra CC: , , , , , , Subject: Re: [RFC][PATCH 1/3] locking: Replace smp_cond_acquire with smp_cond_load_acquire References: <20160404122250.340636238@infradead.org> <20160404123633.348822946@infradead.org> In-Reply-To: <20160404123633.348822946@infradead.org> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [72.71.243.95] X-ClientProxiedBy: CY1PR18CA0024.namprd18.prod.outlook.com (10.163.31.34) To CS1PR84MB0312.NAMPRD84.PROD.OUTLOOK.COM (10.162.190.30) X-MS-Office365-Filtering-Correlation-Id: 35ea8618-7881-4275-ae9b-08d35cb5dd3d X-Microsoft-Exchange-Diagnostics: 1;CS1PR84MB0312;2:uEggqNFKJzKaCwcP0oG5xuOtkl8p4RNzoZX70m45ngE8fy+N80WN1ZWBe5IvG+uWNd9hPqTbA+kRUuPMKrQedQy2N7JbLSO4fUn5OuiDfkxUk88iltSIlG6mR9bisueRAnfmgyzQhs1ev/OTQeCWFX5OjhPwQJt/sF2lRIYgVQG70rsRYKWmStmMKFgtOqPM;3:woCWAu+c698hmDayxFNhe3GUapUd8WpnUC1LHTAy+m6EWRxwUBMB+awQuW1pD8vlQR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UkS2Fwkt/PVrvZOH6zSzqrURGkWtz461TTgNQdLcHREJAmOJMh3/D4HEA+1nyXtDTEcKuM2hd/bnd5XnN+CZ4QC2x8EWkr2fRAYewijEcGW1gKiE6M=;4:9chUv7cZOb3uBeDpf9rvRJLZWoM5t2TFvuClrj2wkd9NuNs7ZrTMaaUDDFeYjDirwcOZt36d847pxlaNZA6qeeobwSDj9i+T25UT71hcd1uiqN49LGSOxCqpdrf6xKC/1fYEefolqu+sziQZa0grOgC0rBlj2sRUyE/plrLloPE5Pwu+17xQkRmZdD0IA4ceEspIhYG701ZypidDDBxq3ivZcqmLwzmEeBxOJLMPRqrrluR3as9Q7sIakgqSaU/yaHqMscqB7MvBB5Uz0kks9IapIQTGcSGkpBB43Osqtxkm/Jvw6F0B4ZaAUR982R5AnhIOzFL58NeEnPnStr/tpICNWV+0c8IRm3Ly9cy5wNkFySXn7v75b9DjrdFwvzQS X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001);SRVR:CS1PR84MB0312;BCL:0;PCL:0;RULEID:;SRVR:CS1PR84MB0312; X-Forefront-PRVS: 0902222726 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6049001)(6009001)(24454002)(377454003)(5004730100002)(1096002)(36756003)(4001350100001)(3846002)(117156001)(50466002)(6116002)(59896002)(586003)(64126003)(230700001)(42186005)(81166005)(110136002)(83506001)(50986999)(189998001)(65806001)(23676002)(5008740100001)(86362001)(2950100001)(65956001)(19580405001)(80316001)(4326007)(19580395003)(47776003)(92566002)(66066001)(54356999)(76176999)(2906002)(87266999)(77096005)(33656002);DIR:OUT;SFP:1102;SCL:1;SRVR:CS1PR84MB0312;H:[192.168.142.150];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDUzFQUjg0TUIwMzEy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-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2016 18:20:55.1577 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR84MB0312 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2837 Lines: 74 On 04/04/2016 08:22 AM, Peter Zijlstra wrote: > This new form allows using hardware assisted waiting. > > Requested-by: Will Deacon > Suggested-by: Linus Torvalds > Signed-off-by: Peter Zijlstra (Intel) > --- > include/linux/compiler.h | 25 +++++++++++++++++++------ > kernel/locking/qspinlock.c | 12 ++++++------ > kernel/sched/core.c | 8 ++++---- > kernel/sched/sched.h | 2 +- > kernel/smp.c | 2 +- > 5 files changed, 31 insertions(+), 18 deletions(-) > > --- a/include/linux/compiler.h > +++ b/include/linux/compiler.h > @@ -305,21 +305,34 @@ static __always_inline void __write_once > }) > > /** > - * smp_cond_acquire() - Spin wait for cond with ACQUIRE ordering > + * smp_cond_load_acquire() - (Spin) wait for cond with ACQUIRE ordering > + * @ptr: pointer to the variable to wait on > * @cond: boolean expression to wait for > * > * Equivalent to using smp_load_acquire() on the condition variable but employs > * the control dependency of the wait to reduce the barrier on many platforms. > * > + * Due to C lacking lambda expressions we load the value of *ptr into a > + * pre-named variable @VAL to be used in @cond. > + * > * The control dependency provides a LOAD->STORE order, the additional RMB > * provides LOAD->LOAD order, together they provide LOAD->{LOAD,STORE} order, > * aka. ACQUIRE. > */ > -#define smp_cond_acquire(cond) do { \ > - while (!(cond)) \ > - cpu_relax(); \ > - smp_rmb(); /* ctrl + rmb := acquire */ \ > -} while (0) > +#ifndef smp_cond_load_acquire > +#define smp_cond_load_acquire(ptr, cond_expr) ({ \ > + typeof(ptr) __PTR = (ptr); \ > + typeof(*ptr) VAL; \ > + for (;;) { \ > + VAL = READ_ONCE(*__PTR); \ > + if (cond_expr) \ > + break; \ > + cpu_relax(); \ > + } \ > + smp_rmb(); /* ctrl + rmb := acquire */ \ > + VAL; \ > +}) > +#endif Using a predefined VAR seems a bit awkward as a reader of the code may not know where VAR comes from. How about passing in a variable to hold the latest value of (*ptr), e.g. #ifndef smp_cond_load_acquire #define smp_cond_load_acquire(ptr, var, cond_expr) do { \ typeof(ptr) __PTR = (ptr); \ for (;;) { \ var = READ_ONCE(*__PTR); \ if (cond_expr) \ break; \ cpu_relax(); \ } \ smp_rmb(); /* ctrl + rmb := acquire */ \ } while (0) #endif Cheers, Longman