From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D395EC874B for ; Thu, 7 Sep 2023 18:06:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7A028D0006; Thu, 7 Sep 2023 14:06:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B2A788D0001; Thu, 7 Sep 2023 14:06:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F2008D0006; Thu, 7 Sep 2023 14:06:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8F2758D0001 for ; Thu, 7 Sep 2023 14:06:01 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5C8A314012E for ; Thu, 7 Sep 2023 18:06:01 +0000 (UTC) X-FDA: 81210580122.01.14340E4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 74546C0021 for ; Thu, 7 Sep 2023 18:05:59 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JBDNUpYK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of longman@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694109959; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=A17IvpynFGjRTpzvVbSGwFNvsNOOnGzpHwVnCuCCR08=; b=nAJczQJvfx0Lb6KgzjRY8CAtlXVnr9i2LS18nAvjYtjpN91c5wLcHwZZ0SCa/X8XwS7Dou vxsH1mTOB+oEulgTKrZTWB4uHvgbitj5IjqkUZTj5rYif5e9SiH/yQ4A/5HOP9LjVyBFCP wLqSzqQi4t+Jy1IYNuWqJT7uNILUDks= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JBDNUpYK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of longman@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694109959; a=rsa-sha256; cv=none; b=jy6SRDThmXpQ14BkDzu8Vwj73Y/L1RZPOrb8pDl0Wo9U5h76OgKxalktICj+0fFV2SbwAo D10oDGo2TWgyt+4hkxh3pkiOrRfLfeRHDwRQ1rgZmmrdkv0Wj10yH5Szuoy2lbBlNENIjY 1gG4rv4H/ZrgF+iL0OSdtiflXFDCfR4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694109958; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A17IvpynFGjRTpzvVbSGwFNvsNOOnGzpHwVnCuCCR08=; b=JBDNUpYK2b1sfcRub0wmNjQ/14ngAwdjAt3YQLlYxtMZkUmamLisfyQfYk+NHBnpmlY8na rQ7IYNo+Xnt/7++ktwEF++IEogR0/eGFW5nmLD90Uhryfx8ahKhulcD5XjxqI7k9fpHh+V 91FHD3XMyAzOFkWYZxGj4BknWwo2miM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-421-ddqwgDxDN9-rV5Fnng-Qpw-1; Thu, 07 Sep 2023 14:05:56 -0400 X-MC-Unique: ddqwgDxDN9-rV5Fnng-Qpw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 98FCA3C19385; Thu, 7 Sep 2023 18:05:55 +0000 (UTC) Received: from [10.22.16.164] (unknown [10.22.16.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34BA2493112; Thu, 7 Sep 2023 18:05:55 +0000 (UTC) Message-ID: <2cd975ec-f868-f180-350f-b1b704118777@redhat.com> Date: Thu, 7 Sep 2023 14:05:54 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH 1/5] locking: Add rwsem_is_write_locked() Content-Language: en-US To: "Matthew Wilcox (Oracle)" , Peter Zijlstra , Ingo Molnar , Will Deacon Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chandan Babu R , "Darrick J . Wong" , linux-xfs@vger.kernel.org References: <20230907174705.2976191-1-willy@infradead.org> <20230907174705.2976191-2-willy@infradead.org> From: Waiman Long In-Reply-To: <20230907174705.2976191-2-willy@infradead.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Queue-Id: 74546C0021 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: wfbu4ugx5bb5ddsbfcto64ix6ndzj3w8 X-HE-Tag: 1694109959-61971 X-HE-Meta: U2F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4nw7Eft1eHDReFCR0FYpGxF+p42Vwv9as/zJtaT4fIXhkMsEfl4yEI/zJHjrbKjtxuWZrJ8EUdiLWWtjaMLN7rm59R08hpYg7qfSH2m14u2Lb+84SbFxF6IjLwoG1UnzGd9wMqFyRsxcI8mJl7LlgmLL/hayj/R9a79D7d85OYxIM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 9/7/23 13:47, Matthew Wilcox (Oracle) wrote: > Several places want to know whether the lock is held by a writer, instead > of just whether it's held. We can implement this for both normal and > rt rwsems. RWSEM_WRITER_LOCKED is declared in rwsem.c and exposing > it outside that file might tempt other people to use it, so just use > a comment to note that's what the 1 means, and help anybody find it if > they're looking to change the implementation. > > Signed-off-by: Matthew Wilcox (Oracle) > --- > include/linux/rwbase_rt.h | 5 +++++ > include/linux/rwsem.h | 10 ++++++++++ > 2 files changed, 15 insertions(+) > > diff --git a/include/linux/rwbase_rt.h b/include/linux/rwbase_rt.h > index 1d264dd08625..3c25b14edc05 100644 > --- a/include/linux/rwbase_rt.h > +++ b/include/linux/rwbase_rt.h > @@ -31,6 +31,11 @@ static __always_inline bool rw_base_is_locked(struct rwbase_rt *rwb) > return atomic_read(&rwb->readers) != READER_BIAS; > } > > +static __always_inline bool rw_base_is_write_locked(struct rwbase_rt *rwb) > +{ > + return atomic_read(&rwb->readers) == WRITER_BIAS; > +} > + > static __always_inline bool rw_base_is_contended(struct rwbase_rt *rwb) > { > return atomic_read(&rwb->readers) > 0; > diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h > index 1dd530ce8b45..0f78b8d2e653 100644 > --- a/include/linux/rwsem.h > +++ b/include/linux/rwsem.h > @@ -72,6 +72,11 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem) > return atomic_long_read(&sem->count) != 0; > } > > +static inline int rwsem_is_write_locked(struct rw_semaphore *sem) > +{ > + return atomic_long_read(&sem->count) & 1 /* RWSEM_WRITER_LOCKED */; > +} I would prefer you move the various RWSEM_* count bit macros from kernel/locking/rwsem.c to under the !PREEMPT_RT block and directly use RWSEM_WRITER_LOCKED instead of hardcoding a value of 1. Cheers, Longman