Received: by 10.192.165.148 with SMTP id m20csp998947imm; Sat, 5 May 2018 02:40:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrBkprboKkrAcBGOBI/henfVTOs5KnWF8+aPT0llXODaKlkZ7oDuPMQ/VX6XYR7uFOxk3zG X-Received: by 2002:a63:af4b:: with SMTP id s11-v6mr9118097pgo.346.1525513209660; Sat, 05 May 2018 02:40:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525513209; cv=none; d=google.com; s=arc-20160816; b=hRjDutp/BQTU7D9gII82nmz9hXwEqRLEGz/6XGSvauR61FYqYHghasf69MWrJToClO jXGLOycGNnV2gSCDM5kdV1Cz+1D2vEHf2R65EV26YfKVfnrlxQ8iC+QRXWxlzkFysSNH S1LCVpBRf4mfu1oMwxmfQafzqTioUFd0EwL/uc8QNtg4s+k2IE7kb12RX0MH7zVjoQLg 5c7+1nYIhlA4wfOozKj7I2ITbfNZB0a8l1hPKt6uzYL2upWof65cpZgpuADC9FIXImzD Fd9olF2bYRUbH08VEi+/OYqi2nRft+Mj5pEDugNoeOHX/RWc/tAa/W2lHha4sdbT/lxi 3HPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=zael+NF24l72eFAYKEV1JZ6jsioW8uXzrmbyDhfOLDc=; b=Y9tJWfMnkqhKCP00H32JOiFmxVfB+jevz1ivU0ltaXSm2+HQ4e5a2sJt1hd9pM/9ay Uef23QROUsGWnnH20VR4CA/KND8ILFHILx4cdzzpCpe7SIqUXMRbHW08SUA3KigeyPdL tWONcSf9koKpVqMDDU4cNmKrzrxhYaajTNClqTPEUmmpNk3nO66xqDuySyiSAoSLlF9Y rWWgu7d8cWpNoMXudfg8VAcLUBO92jApJ4jDkXxQpibVUeeXD8ISr7zC5Z6kL0LfOk85 Hkcis+Dq+Iudp4tbkFjzQ17t6OFiVrGToQQb57hvp/+F7SHMU1hr2J5Ch89dt2MiydTX YSvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=BFj029/R; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e21-v6si3453582pgv.522.2018.05.05.02.39.55; Sat, 05 May 2018 02:40:09 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=BFj029/R; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751200AbeEEJif (ORCPT + 99 others); Sat, 5 May 2018 05:38:35 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:54864 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750821AbeEEJie (ORCPT ); Sat, 5 May 2018 05:38:34 -0400 Received: by mail-wm0-f67.google.com with SMTP id f6so7264936wmc.4 for ; Sat, 05 May 2018 02:38:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zael+NF24l72eFAYKEV1JZ6jsioW8uXzrmbyDhfOLDc=; b=BFj029/Rtb23qCzK15FZFfhuUdz9gMHKOOugsla9eIY5Q6cZ6yITZj4ZsPlPC01gaP 1ZSegGFoM+V3jLNmOiCzQoz4/NJtQ33n5jVn5Mxo4iBbisY01RZBWMDG1Csg96B5/l3d 0BtBDRjt4657tmiSI9BQsct16/MJ/bHg+jHrwJoG4l2eVODMrr0piRf0cSkqkI0vMemk erPvtNf78hZku55EHRuzx/BfPiftKo1cN3i/Kl1qKInbrNFYlmlsvPhD/x4xI65z4/9X wmTDyYUmVklLuYLFVq42HrBShHe1I/fWH4lGbFp7Ey02XXJXS3UtrWvz6yFLHHwNfql2 sZIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=zael+NF24l72eFAYKEV1JZ6jsioW8uXzrmbyDhfOLDc=; b=puozFGnyv/CgwydOCsDEv3UHFdWvkPsqgBTHoRMunp/aF3BNCTda0tnHsltBDy/pj3 m6y0qKmYpPUOt2uLylhyo+2L0OhBgNKxt37v6pXAskzS2zE0XuIuHZncfeRJwLyciH05 D/XrVDucGU/SClB9NdUfgs1XLCYOX30jb8HtjpOYecqpZns39S2M2tz6pCv4m4Dat6Xm V3/mIYZ4FEVsk/pC5jCmd39rThFSBDaytyskT96DJcIJkZ8PxLMl/2jHBa0crgL//KEe ZXaAW7vVxr9/IyuPXUkE0Rc/xPxqoOEJkqu91Smoa0hxrMeEYxY6r3zveWWDI2zKOaLv v67A== X-Gm-Message-State: ALQs6tB1L34ykSqtongdo0XaZt7qeX300MzN6lCNlD8Dtu+m7MqANdcD YkRCI50JGBqGCXe0B6yBxbM= X-Received: by 10.28.184.132 with SMTP id i126mr18214337wmf.30.1525513112695; Sat, 05 May 2018 02:38:32 -0700 (PDT) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id h133sm3756045wmf.47.2018.05.05.02.38.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 May 2018 02:38:32 -0700 (PDT) Date: Sat, 5 May 2018 11:38:29 +0200 From: Ingo Molnar To: Peter Zijlstra Cc: Mark Rutland , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, aryabinin@virtuozzo.com, boqun.feng@gmail.com, catalin.marinas@arm.com, dvyukov@google.com, will.deacon@arm.com Subject: Re: [PATCH] locking/atomics: Clean up the atomic.h maze of #defines Message-ID: <20180505093829.xfylnedwd5nonhae@gmail.com> References: <20180504173937.25300-1-mark.rutland@arm.com> <20180504173937.25300-2-mark.rutland@arm.com> <20180504180105.GS12217@hirez.programming.kicks-ass.net> <20180504180909.dnhfflibjwywnm4l@lakrids.cambridge.arm.com> <20180505081100.nsyrqrpzq2vd27bk@gmail.com> <20180505084721.GA32344@noisy.programming.kicks-ass.net> <20180505090403.p2ywuen42rnlwizq@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180505090403.p2ywuen42rnlwizq@gmail.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Ingo Molnar wrote: > * Peter Zijlstra wrote: > > > > So we could do the following simplification on top of that: > > > > > > #ifndef atomic_fetch_dec_relaxed > > > # ifndef atomic_fetch_dec > > > # define atomic_fetch_dec(v) atomic_fetch_sub(1, (v)) > > > # define atomic_fetch_dec_relaxed(v) atomic_fetch_sub_relaxed(1, (v)) > > > # define atomic_fetch_dec_acquire(v) atomic_fetch_sub_acquire(1, (v)) > > > # define atomic_fetch_dec_release(v) atomic_fetch_sub_release(1, (v)) > > > # else > > > # define atomic_fetch_dec_relaxed atomic_fetch_dec > > > # define atomic_fetch_dec_acquire atomic_fetch_dec > > > # define atomic_fetch_dec_release atomic_fetch_dec > > > # endif > > > #else > > > # ifndef atomic_fetch_dec > > > # define atomic_fetch_dec(...) __atomic_op_fence(atomic_fetch_dec, __VA_ARGS__) > > > # define atomic_fetch_dec_acquire(...) __atomic_op_acquire(atomic_fetch_dec, __VA_ARGS__) > > > # define atomic_fetch_dec_release(...) __atomic_op_release(atomic_fetch_dec, __VA_ARGS__) > > > # endif > > > #endif > > > > This would disallow an architecture to override just fetch_dec_release for > > instance. > > Couldn't such a crazy arch just define _all_ the 3 APIs in this group? > That's really a small price and makes the place pay the complexity > price that does the weirdness... > > > I don't think there currently is any architecture that does that, but the > > intent was to allow it to override anything and only provide defaults where it > > does not. > > I'd argue that if a new arch only defines one of these APIs that's probably a bug. > If they absolutely want to do it, they still can - by defining all 3 APIs. > > So there's no loss in arch flexibility. BTW., PowerPC for example is already in such a situation, it does not define atomic_cmpxchg_release(), only the other APIs: #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n))) #define atomic_cmpxchg_relaxed(v, o, n) \ cmpxchg_relaxed(&((v)->counter), (o), (n)) #define atomic_cmpxchg_acquire(v, o, n) \ cmpxchg_acquire(&((v)->counter), (o), (n)) Was it really the intention on the PowerPC side that the generic code falls back to cmpxchg(), i.e.: # define atomic_cmpxchg_release(...) __atomic_op_release(atomic_cmpxchg, __VA_ARGS__) Which after macro expansion becomes: smp_mb__before_atomic(); atomic_cmpxchg_relaxed(v, o, n); smp_mb__before_atomic() on PowerPC falls back to the generic __smp_mb(), which falls back to mb(), which on PowerPC is the 'sync' instruction. Isn't this a inefficiency bug? While I'm pretty clueless about PowerPC low level cmpxchg atomics, they appear to have the following basic structure: full cmpxchg(): PPC_ATOMIC_ENTRY_BARRIER # sync ldarx + stdcx PPC_ATOMIC_EXIT_BARRIER # sync cmpxchg_relaxed(): ldarx + stdcx cmpxchg_acquire(): ldarx + stdcx PPC_ACQUIRE_BARRIER # lwsync The logical extension for cmpxchg_release() would be: cmpxchg_release(): PPC_RELEASE_BARRIER # lwsync ldarx + stdcx But instead we silently get the generic fallback, which does: smp_mb__before_atomic(); atomic_cmpxchg_relaxed(v, o, n); Which maps to: sync ldarx + stdcx Note that it uses a full barrier instead of lwsync (does that stand for 'lightweight sync'?). Even if it turns out we need the full barrier, with the overly finegrained structure of the atomics this detail is totally undocumented and non-obvious. Thanks, Ingo