Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1755977pxb; Mon, 20 Sep 2021 04:43:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhm0SoSQO33y2w9lhxZulFyrxn8YQFo/zeCIOz5vYxleG7V+s2XbyIp2eECoc4VQSB8KjT X-Received: by 2002:a05:6e02:152b:: with SMTP id i11mr17659208ilu.65.1632138236367; Mon, 20 Sep 2021 04:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632138236; cv=none; d=google.com; s=arc-20160816; b=gaaN3i+2JQcoHSuhoVD6kJL5tAVi5vc/0P0NVAs0c+umUhzxevEcIQFQnkIZ//ImwO lRPFsk0gDiGr1Wl4Vs7RHsoXrMsR7wGeNZ0Yjg7Q15ConLViduhZhzdXcoXmxg54GtJx gwcnsrl/PsGjwfap1qov/cZ4ge+CmpySSSdYsjSUELICEyJ0gRGLPAld/eIXnisT96RQ qbrhVKTxC1+IhZnYuZzo63zf0PX5Fp+usfFkmAEe7+a/cIcEWsOD79dfP4P+WcR+J0V6 0Clg9CMABJGvUpaNGUjEL+tye8oKocGVJKh6JnU9aZiCjxAw4zT5tz2SVcxFxTX89meY 714g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JES4q+WRhJCfGBiYCiPrre75MlDvZJyjx/xKnaOl4yE=; b=HNuRy7H7+J/pwt0ulcIXpVaIMQpTYgMAFnE7s9P3G4WgnGff1PXZlOUsPrSqTPJTOu ECmEU2nnBiqOsPtztfyijAn4VkjHVtWG28fmY15YrUmSrYQNjiChNPWbNjF4XFn+7A9k YX2xweej34hd4PgOdxFDgOLgsu2IS3DOW0wunRe9uDTXTNI/urDlUMxxKUOchA5msl0f FDiQOGd0ADcaTba/fQtyb5tOulnpwS0j896PwyX1AvphziNMDaVcZJbDx9rzb6mSLz7E TtoeBkrd/kkMsDOUZOVE25KG9cS4d4megr7NR/mG3gwFLrcnp+LsIgOMLn+Bb/GLdA14 N0uA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t13si13745627jam.123.2021.09.20.04.43.45; Mon, 20 Sep 2021 04:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232397AbhITFWQ (ORCPT + 99 others); Mon, 20 Sep 2021 01:22:16 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:50588 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231443AbhITFWK (ORCPT ); Mon, 20 Sep 2021 01:22:10 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E7DC820000; Mon, 20 Sep 2021 05:20:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5565D13AC7; Mon, 20 Sep 2021 05:20:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8GmdCCgaSGFsSwAAMHmgww (envelope-from ); Mon, 20 Sep 2021 05:20:40 +0000 From: Davidlohr Bueso To: tglx@linutronix.de Cc: peterz@infradead.org, mingo@kernel.org, rostedt@goodmis.org, longman@redhat.com, bigeasy@linutronix.de, boqun.feng@gmail.com, dave@stgolabs.net, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: [PATCH 1/2] locking/rwbase: Optimize rwbase_read_trylock Date: Sun, 19 Sep 2021 22:20:30 -0700 Message-Id: <20210920052031.54220-2-dave@stgolabs.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210920052031.54220-1-dave@stgolabs.net> References: <20210920052031.54220-1-dave@stgolabs.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of a full barrier around the Rmw insn, micro-optimize for weakly ordered archs such that we only provide the required ACQUIRE semantics when taking the read lock. Signed-off-by: Davidlohr Bueso --- kernel/locking/rwbase_rt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/locking/rwbase_rt.c b/kernel/locking/rwbase_rt.c index 88191f6e252c..a9034784a5a0 100644 --- a/kernel/locking/rwbase_rt.c +++ b/kernel/locking/rwbase_rt.c @@ -59,8 +59,7 @@ static __always_inline int rwbase_read_trylock(struct rwbase_rt *rwb) * set. */ for (r = atomic_read(&rwb->readers); r < 0;) { - /* Fully-ordered if cmpxchg() succeeds, provides ACQUIRE */ - if (likely(atomic_try_cmpxchg(&rwb->readers, &r, r + 1))) + if (likely(atomic_try_cmpxchg_acquire(&rwb->readers, &r, r + 1))) return 1; } return 0; @@ -183,7 +182,7 @@ static inline void __rwbase_write_unlock(struct rwbase_rt *rwb, int bias, /* * _release() is needed in case that reader is in fast path, pairing - * with atomic_try_cmpxchg() in rwbase_read_trylock(), provides RELEASE + * with atomic_try_cmpxchg_acquire() in rwbase_read_trylock(). */ (void)atomic_add_return_release(READER_BIAS - bias, &rwb->readers); raw_spin_unlock_irqrestore(&rtm->wait_lock, flags); -- 2.26.2