Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3887965pxy; Mon, 26 Apr 2021 12:09:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSUwe7KUyRl8VbIsOiXQjwoaqNVbOnjV29XcLVZe+PeM2VRE7Jx6LRR+mhiHf38PG2flfa X-Received: by 2002:a17:90a:df08:: with SMTP id gp8mr3286866pjb.199.1619464191242; Mon, 26 Apr 2021 12:09:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619464191; cv=none; d=google.com; s=arc-20160816; b=RD9ucpdlBZev0VkXUuI+O6ON9lSR4ClWMgdS3se8bivVRlIdW0suOD4NgUKnxc3RXg as/IOvcUt7e9CbLfZBdQUHSQWr+D3HX4pjt8nAJNPiVybG9Sz9JWfEPyivMbuxixw6jf duV71aCleM7LRRYMeMW2ksblDUu92idSG5nWSkHTPeAj+74SxJEqGtPw/Eek/E5G9vmC s8LGogNA74EGFST1WU23YgbruJGCC9S4kqeFWFfSv0WRKydd7sxIxMC1cNjJSVp1gRmA 12P+pan5SgZgjbc8NAS5lhm1IsFJNCj4ABPO2RrV1hXlRjMNWogMCJBlmM3TMbhMDP1R bTdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=yD6J++tFGN2JroTP2/fJSOvNTeeHAc+T/Yq8Saih9NQ=; b=j0ftmI8GHp6/i2r8elCwx62xUZ4Bl1v90sT84BRTeV6KGatwIOsIlyc5xcASO9zjOc pnW0gQTm1lPsNJb72HtMHzJhs1tqk+XLCrmmBSKUTMNuGRNxKCKlChQIR6/aQDfEt0TA CjQ8pFJzdTHtQA+0y9vg7jWGaxp9IF7bxpBm2xSXcMbQL54Z/ZMpg5MmBvkGwFW60XiK IrxRo1fQ7e4JrfbjEo02EzkHOZfIO/S5aQ+L94K1GFZ2RvtpyCr5Op1r6LOY3lJdu8NF UQ/xezmo3/fh9QL0+0KCUt66uo74mdsazdUFVsD8Qzy/58GZ6Z25tXjD8Vf9ypuNBRdN x7Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=H4SdH27d; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x13si442528pjh.49.2021.04.26.12.09.32; Mon, 26 Apr 2021 12:09:51 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=H4SdH27d; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239018AbhDZSvS (ORCPT + 99 others); Mon, 26 Apr 2021 14:51:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20530 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239008AbhDZSvQ (ORCPT ); Mon, 26 Apr 2021 14:51:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619463033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=yD6J++tFGN2JroTP2/fJSOvNTeeHAc+T/Yq8Saih9NQ=; b=H4SdH27d3v/z1BtdgW/HQ2LvSQ/6NcfJla5XBnEf/MWKUbAIvNU7zR8sIr985lBn9d8Dii L0un4F3LxsutiVdFcioUz+sNNCJraZFnuVRab9LYdv7xzHHsEApsUk2MIbW+af6vhwD8Gc BTkbpisWGvjpQoD9avspzQV3zByCzZk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-543-VX1-4-GwPm2Gz4imiOJ4hQ-1; Mon, 26 Apr 2021 14:50:31 -0400 X-MC-Unique: VX1-4-GwPm2Gz4imiOJ4hQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 19661107ACCA; Mon, 26 Apr 2021 18:50:30 +0000 (UTC) Received: from llong.com (ovpn-118-134.rdu2.redhat.com [10.10.118.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1E015D6A1; Mon, 26 Apr 2021 18:50:25 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng Cc: linux-kernel@vger.kernel.org, Borislav Petkov , Ali Saidi , Steve Capper , Waiman Long Subject: [PATCH] locking/qrwlock: queued_write_lock_slowpath() cleanup Date: Mon, 26 Apr 2021 14:50:17 -0400 Message-Id: <20210426185017.19815-1-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make the code more readable by replacing the atomic_cmpxchg_acquire() by an equivalent atomic_try_cmpxchg_acquire() and change atomic_add() to atomic_or(). For architectures that use qrwlock, I do not find one that has an atomic_add() defined but not an atomic_or(). I guess it should be fine by changing atomic_add() to atomic_or(). Note that the previous use of atomic_add() isn't wrong as only one writer that is the wait_lock owner can set the waiting flag and the flag will be cleared later on when acquiring the write lock. Suggested-by: Linus Torvalds Signed-off-by: Waiman Long --- kernel/locking/qrwlock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/locking/qrwlock.c b/kernel/locking/qrwlock.c index b94f3831e963..ec36b73f4733 100644 --- a/kernel/locking/qrwlock.c +++ b/kernel/locking/qrwlock.c @@ -66,12 +66,12 @@ void queued_write_lock_slowpath(struct qrwlock *lock) arch_spin_lock(&lock->wait_lock); /* Try to acquire the lock directly if no reader is present */ - if (!atomic_read(&lock->cnts) && - (atomic_cmpxchg_acquire(&lock->cnts, 0, _QW_LOCKED) == 0)) + if (!(cnts = atomic_read(&lock->cnts)) && + atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED)) goto unlock; /* Set the waiting flag to notify readers that a writer is pending */ - atomic_add(_QW_WAITING, &lock->cnts); + atomic_or(_QW_WAITING, &lock->cnts); /* When no more readers or writers, set the locked flag */ do { -- 2.18.1