Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932139AbbLDWFz (ORCPT ); Fri, 4 Dec 2015 17:05:55 -0500 Received: from mail-ig0-f177.google.com ([209.85.213.177]:36329 "EHLO mail-ig0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756653AbbLDWFu (ORCPT ); Fri, 4 Dec 2015 17:05:50 -0500 MIME-Version: 1.0 In-Reply-To: <5661FCD0.60909@hpe.com> References: <20151203124010.627312076@infradead.org> <20151203124339.552838970@infradead.org> <20151203163725.GJ11337@arm.com> <20151203202627.GV17308@twins.programming.kicks-ass.net> <5661FCD0.60909@hpe.com> Date: Fri, 4 Dec 2015 14:05:49 -0800 X-Google-Sender-Auth: TMY58KGnpQ3R86c5OisRZ7Q_cmI Message-ID: Subject: Re: [PATCH 3/4] locking: Introduce smp_cond_acquire() From: Linus Torvalds To: Waiman Long Cc: Peter Zijlstra , Will Deacon , Ingo Molnar , Oleg Nesterov , Linux Kernel Mailing List , Paul McKenney , Boqun Feng , Jonathan Corbet , Michal Hocko , David Howells , Paul Turner Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1365 Lines: 42 On Fri, Dec 4, 2015 at 12:51 PM, Waiman Long wrote: > > Will the following work? Are we trying to win some obfuscated C contest here? Just make it do something like (skipping backslashes to make it easier to type and read) #define smp_cond_load_acquire(ptr, cond_expr) ({ typeof(*ptr) VAL; for (;;) { VAL = READ_ONCE(*ptr); if (cond_expr) break; cpu_relax(); } smp_rmb(); VAL; }) and then you'd have it be val = smp_cond_load_acquire(&lock->val.counter, !(VAL & _Q_LOCKED_PENDING_MASK)); which is at least halfway legible. Not some odd "fragments of expressions" interfaces unless absolutely required, please. Of course, I suspect we should not use READ_ONCE(), but some architecture-overridable version that just defaults to READ_ONCE(). Same goes for that "smp_rmb()". Because maybe some architectures will just prefer an explicit acquire, and I suspect we do *not* want architectures having to recreate and override that crazy loop. How much does this all actually end up mattering, btw? Linus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/