Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp273706imj; Fri, 15 Feb 2019 23:39:16 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib6v3/XtA8DvGE6O1baeusCb/sA7Ld6C2OGiyY4CmVGp5mbtWLhgQCmDueBXeoRBEafB0AA X-Received: by 2002:a17:902:10e:: with SMTP id 14mr7832061plb.14.1550302756166; Fri, 15 Feb 2019 23:39:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550302756; cv=none; d=google.com; s=arc-20160816; b=KOnEUilm/uIZB6StZjDszh1E3fTO3F7nkmoxSio7jaDV7UcUyh3Cno+5VBZi2v9kw0 8ws+PzYnLwFbpCltRY29pFOqMGa0IizLGG5Zlbds/hsz0mwjTk4LaDUg0Wn9wlnPyteT XOjj34lwwLY3KkP6bcjTZvaW43bfMZDqnjE3DK+ovO3wFFQzEvONA/Dt9vmSbwmxyZkE KpvetBEf/nleriSB6UpxMYiok/yEcTy7VNcmyEAUtb0wNMTJZm2Jp27/B5+b5GVrZYeh MNLN5JcFNzHiUduRaJ7ZTvUt5iLyf8pX6IAq2wdPNmYVwpQweBgz4Hdl/T55i/608EEi 0Abw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=R9q+9NPxv6RWPwJEG0JZJ+nOTCVUYPN5E6ZnGZtTeM8=; b=yfH4ydzAzEdAzPvIMwGiSnfgeFMf16H6ft7jTiWMyQxrM4C2EjeDeKLKyrgMrgYXlA 5w2P24UMT4CqBy/ngqEF5ownLkAmkdNkIRC/nlmxScwmrsTwvQ5ZxxcN31jePFvF2g7/ x2qosSxPHtqR6g9fsYdYP/AKbMD6Zuon9p4b01G+y29AT+sNK86wzNyTEkmxq4YEmjPY NppvF7ox1vxa48EI0JqaOCJ+IX+8itxfli1TkLIP0IU1gkoCSyK4IaNnMm5OpsE9rj/q xu85kNhf4C3mnlvNFXChtHqBYQClsY2/fYziagEVsGGJlmYkpwWhfTEMJnwXMnker4OB rx8Q== ARC-Authentication-Results: i=1; mx.google.com; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si7341185pfn.180.2019.02.15.23.39.00; Fri, 15 Feb 2019 23:39:16 -0800 (PST) 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; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391774AbfBOUvN (ORCPT + 99 others); Fri, 15 Feb 2019 15:51:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38412 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391321AbfBOUu1 (ORCPT ); Fri, 15 Feb 2019 15:50:27 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A74F325B0; Fri, 15 Feb 2019 20:50:27 +0000 (UTC) Received: from llong.com (dhcp-17-59.bos.redhat.com [10.18.17.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4CF35BBB4; Fri, 15 Feb 2019 20:50:25 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Will Deacon , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Arnd Bergmann , Borislav Petkov , "H. Peter Anvin" , Davidlohr Bueso , Linus Torvalds , Andrew Morton , Tim Chen , Waiman Long Subject: [PATCH-tip v2 04/10] locking/rwsem: Micro-optimize rwsem_try_read_lock_unqueued() Date: Fri, 15 Feb 2019 15:50:04 -0500 Message-Id: <1550263810-31947-5-git-send-email-longman@redhat.com> In-Reply-To: <1550263810-31947-1-git-send-email-longman@redhat.com> References: <1550263810-31947-1-git-send-email-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 15 Feb 2019 20:50:27 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The atomic_long_cmpxchg_acquire() in rwsem_try_read_lock_unqueued() is replaced by atomic_long_try_cmpxchg_acquire() to simpify the code and generate slightly better assembly code. There is no functional change. Signed-off-by: Waiman Long --- kernel/locking/rwsem-xadd.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c index c213869..f6198e1 100644 --- a/kernel/locking/rwsem-xadd.c +++ b/kernel/locking/rwsem-xadd.c @@ -259,21 +259,16 @@ static inline bool rwsem_try_write_lock(long count, struct rw_semaphore *sem) */ static inline bool rwsem_try_write_lock_unqueued(struct rw_semaphore *sem) { - long old, count = atomic_long_read(&sem->count); + long count = atomic_long_read(&sem->count); - while (true) { - if (!(count == 0 || count == RWSEM_WAITING_BIAS)) - return false; - - old = atomic_long_cmpxchg_acquire(&sem->count, count, - count + RWSEM_ACTIVE_WRITE_BIAS); - if (old == count) { + while (!count || count == RWSEM_WAITING_BIAS) { + if (atomic_long_try_cmpxchg_acquire(&sem->count, &count, + count + RWSEM_ACTIVE_WRITE_BIAS)) { rwsem_set_owner(sem); return true; } - - count = old; } + return false; } static inline bool owner_on_cpu(struct task_struct *owner) -- 1.8.3.1