Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3399989rwl; Mon, 27 Mar 2023 13:31:16 -0700 (PDT) X-Google-Smtp-Source: AKy350Yv7dne028ao0TMbTM+0gZci+elpSi9B/HL/ClhS0CWQaO5SYFTNSE7QeBRTJ5BnOsgjAB1 X-Received: by 2002:a05:6402:cd:b0:502:26b7:7a44 with SMTP id i13-20020a05640200cd00b0050226b77a44mr9809541edu.1.1679949076589; Mon, 27 Mar 2023 13:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679949076; cv=none; d=google.com; s=arc-20160816; b=HnM0fJm42Kr5HIsHaI3niynpIot8+VGaCNuswwGxBZHqx0kbEHU+x+xoaIBha2wDhT xHfAIWDYYC2m3Ohtj/F41rH0rWxXjGqfCyj4xTrf6batrSlYZVo5UA3wEudTwMwKyxw3 7pxJApC6G3ZgLBmNQJtq0EGyN0fw9l1cjMW5cCA0D3BWuMXtnCS6QY35wAm5auAFfJjv ZJ8Sc6H/ZMmLhZCHi+/rTNTHl1K4JSRa+5Iw3xBBuZYL8Trt8IX5dofbi5rB8XnDtk4Y WZZ6O0d2MW0yUFQ/GaBzaW01M07ZE1mdMtVOarOWfFwd5qLyZKqkWXSNCK19HP67pw/S 1u3A== 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 :dkim-signature; bh=uKqJMijs13Jukpid8KMMuGMpFDV4xKY3d7eMa9951QU=; b=ws5eOk7ydQJkhSW8iogJx6lSRi4T5PTsM21XDqcQVb6ejbO9Jt+JFCuEw6P+xNvo0n 2fS/pnyy/e7qPL4DM6ah1slSlIWNqGeV/cNjA4S/nvG90Vn70meXoXYqGfr7KvEK5c4M QqBTzVSyT/bA+9ZNY7CkyUfLnDS+hzyxMUKLWPNF505GFKGiZsHWMFfCfqKG/4k3Tv4+ hbP0oj7cXr9zriWePIaKlh808Kbyn7LqjkdHExwNb1euw71wklCR+sFpX2OgJxhtPPPq ydeZ+JYxVJ1IWAj522lAUdFJB0tJrTaboGhO1kF0N8fVorw0tvvSOv0OVz3HP++Jj9k2 O/0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CnHnHRny; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m25-20020a056402051900b00501d48232ecsi19560480edv.404.2023.03.27.13.30.51; Mon, 27 Mar 2023 13:31:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CnHnHRny; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbjC0U0H (ORCPT + 99 others); Mon, 27 Mar 2023 16:26:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232400AbjC0UZx (ORCPT ); Mon, 27 Mar 2023 16:25:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB1A43ABD for ; Mon, 27 Mar 2023 13:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679948667; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uKqJMijs13Jukpid8KMMuGMpFDV4xKY3d7eMa9951QU=; b=CnHnHRnyr6Z8V+8gidl0UnwYDvhNfbSfmeacSWVy00QUWxGHGCk1J56XSwbHQ1IrxyeTp+ SC1sipXSgBVFe+KKkE8Pe4zz50zCDBRVOG9Rl3mt9pTuqT7OxtGxKeMnR1x/fd1zVjeAJ4 ZBQ3j/mhGaGFHpqCELkSl3sAOyka4P4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-445-uW3x49_LPuSP5n5_MrxFaw-1; Mon, 27 Mar 2023 16:24:24 -0400 X-MC-Unique: uW3x49_LPuSP5n5_MrxFaw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E156185A588; Mon, 27 Mar 2023 20:24:23 +0000 (UTC) Received: from llong.com (unknown [10.22.17.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D2712027040; Mon, 27 Mar 2023 20:24:23 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng Cc: linux-kernel@vger.kernel.org, Waiman Long Subject: [PATCH v2 4/8] locking/rwsem: Simplify rwsem_writer_wake() Date: Mon, 27 Mar 2023 16:24:09 -0400 Message-Id: <20230327202413.1955856-5-longman@redhat.com> In-Reply-To: <20230327202413.1955856-1-longman@redhat.com> References: <20230327202413.1955856-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra Since @waiter := rwsem_first_waiter() simplify things. Suggested-by: Waiman Long Signed-off-by: Peter Zijlstra (Intel) --- kernel/locking/rwsem.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index 0cc0aa566a6b..225e86326ea4 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -426,26 +426,12 @@ rwsem_waiter_wake(struct rwsem_waiter *waiter, struct wake_q_head *wake_q) static inline bool rwsem_try_write_lock(struct rw_semaphore *sem, struct rwsem_waiter *waiter) { - - struct rwsem_waiter *first = rwsem_first_waiter(sem); long count, new; lockdep_assert_held(&sem->wait_lock); count = atomic_long_read(&sem->count); do { - bool has_handoff = !!(count & RWSEM_FLAG_HANDOFF); - - if (has_handoff) { - /* - * Honor handoff bit and yield only when the first - * waiter is the one that set it. Otherwisee, we - * still try to acquire the rwsem. - */ - if (first->handoff_set && (waiter != first)) - return false; - } - new = count; if (count & RWSEM_LOCK_MASK) { @@ -454,8 +440,9 @@ static inline bool rwsem_try_write_lock(struct rw_semaphore *sem, * if it is an RT task or wait in the wait queue * for too long. */ - if (has_handoff || (!rt_task(waiter->task) && - !time_after(jiffies, waiter->timeout))) + if ((count & RWSEM_FLAG_HANDOFF) || + (!rt_task(waiter->task) && + !time_after(jiffies, waiter->timeout))) return false; new |= RWSEM_FLAG_HANDOFF; @@ -474,7 +461,7 @@ static inline bool rwsem_try_write_lock(struct rw_semaphore *sem, * set here to enable optimistic spinning in slowpath loop. */ if (new & RWSEM_FLAG_HANDOFF) { - first->handoff_set = true; + waiter->handoff_set = true; lockevent_inc(rwsem_wlock_handoff); return false; } -- 2.31.1