Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp566768imu; Thu, 20 Dec 2018 01:29:53 -0800 (PST) X-Google-Smtp-Source: AFSGD/V8TcDXYw0pwI9aYX60dL7vBtYfJ9dl1Il7x4u70ncvBPmVsqWpSnTiQLmV5cpSCm5R9kGZ X-Received: by 2002:a17:902:27e6:: with SMTP id i35mr22924698plg.222.1545298193820; Thu, 20 Dec 2018 01:29:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545298193; cv=none; d=google.com; s=arc-20160816; b=KB1u8Tp4rcyXZbjbLI8LgtuoOMGlnJSFDna1P7OQLE6W7953Wv++ZeDqQM9WDH6wMA xU93kJ0xZ0il4YWtaHWifB9n9d1AVMSq4fFkcanS81L9AHBJ+XUwNvCUuQtsZRomxj5s RRoYq/s4B8bNgu77nvXmutZVBy27PB8xjyheZjqs6c0Ir7Ti/YWYXMLxtrnLzrJRXNdW B3hnaAJGLUsNVFh0mlIaYprFR6+HXzRjyLEgoCE/rQR2S6Z9+AUC9l2eed0WjKtEV9WO aIsu73/WVjUy9SOFITdlsPM2R5tE1UeB3YNv8p5+CURVjzQBnq7WQ+xZ3vV0+qxod5yr GMjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kxMIrKhCfCWH4u9IofSLeiNo8mETt2QmPaMVeR8s4uo=; b=hL5Mpi0inDyrU2VHWBsCZ3vatjQYhdw8wpmKsu0INnWSzRS5B4Dpftbg2z4W1CVBDf OG0F/m8zMFtRem7zxBIHNXHrEppWf2lqw4hpF+WtpWBmeefQF1ZEg5ZX2y0FITd6nqrv 8vPBDcb7Dr6r374JF0nP20OJm5iPI/S81yLu5V2L0qzHrIf/q38VhnuvNKqJhCUx8qPo 8OdiY61inTQx4a2mLJJ0q1xw8FU0eBLx3aHAh8ynFMxCJn+fc3zaOaoHszWZwVhCKYDZ 9GQUTDm9LYqGt6G1yYD0UAEN4M3oDqN1QUQahtIulTPznU5tjoKRbBej85G9DGPL7t6b MgJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b043WTT3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b28si17837994pgm.409.2018.12.20.01.29.38; Thu, 20 Dec 2018 01:29:53 -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; dkim=pass header.i=@kernel.org header.s=default header.b=b043WTT3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732152AbeLTJ0o (ORCPT + 99 others); Thu, 20 Dec 2018 04:26:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:57418 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732140AbeLTJ0m (ORCPT ); Thu, 20 Dec 2018 04:26:42 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EFB9620656; Thu, 20 Dec 2018 09:26:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545298001; bh=Dp781QzXBoae/xoPg/n69YM5KGJBNViX5dW6DJA8xSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b043WTT3XyBLKx3Q1+FRYpJ9UkdIKUgEO+ZH5HXWEU60vX3d+FMW4xmnUQReO7kIt aDfc2YPlc+9Y2y2/9fhs5DSvuEWsZAs3zYl2cSfHQtoOhOlG1uItIkw0m2eggaW5mY sUvbQ3c6R6QIJV/46I7pwXbd2dZj6Rtikov0UlW0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Will Deacon , Linus Torvalds , Thomas Gleixner , andrea.parri@amarulasolutions.com, longman@redhat.com, Ingo Molnar , Sebastian Andrzej Siewior , Sasha Levin Subject: [PATCH 4.14 27/72] locking/qspinlock: Re-order code Date: Thu, 20 Dec 2018 10:18:26 +0100 Message-Id: <20181220085923.406505183@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181220085922.332225035@linuxfoundation.org> References: <20181220085922.332225035@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ commit 53bf57fab7321fb42b703056a4c80fc9d986d170 upstream. Flip the branch condition after atomic_fetch_or_acquire(_Q_PENDING_VAL) such that we loose the indent. This also result in a more natural code flow IMO. Signed-off-by: Peter Zijlstra (Intel) Acked-by: Will Deacon Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: andrea.parri@amarulasolutions.com Cc: longman@redhat.com Link: https://lkml.kernel.org/r/20181003130257.156322446@infradead.org Signed-off-by: Ingo Molnar Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Sasha Levin --- kernel/locking/qspinlock.c | 54 ++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c index 841550dfb7b8..9ffc2f9af8b8 100644 --- a/kernel/locking/qspinlock.c +++ b/kernel/locking/qspinlock.c @@ -324,38 +324,36 @@ void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val) * 0,0,1 -> 0,1,1 ; pending */ val = atomic_fetch_or_acquire(_Q_PENDING_VAL, &lock->val); - if (!(val & ~_Q_LOCKED_MASK)) { - /* - * We're pending, wait for the owner to go away. - * - * *,1,1 -> *,1,0 - * - * this wait loop must be a load-acquire such that we match the - * store-release that clears the locked bit and create lock - * sequentiality; this is because not all - * clear_pending_set_locked() implementations imply full - * barriers. - */ - if (val & _Q_LOCKED_MASK) { - smp_cond_load_acquire(&lock->val.counter, - !(VAL & _Q_LOCKED_MASK)); - } - - /* - * take ownership and clear the pending bit. - * - * *,1,0 -> *,0,1 - */ - clear_pending_set_locked(lock); - return; + /* + * If we observe any contention; undo and queue. + */ + if (unlikely(val & ~_Q_LOCKED_MASK)) { + if (!(val & _Q_PENDING_MASK)) + clear_pending(lock); + goto queue; } /* - * If pending was clear but there are waiters in the queue, then - * we need to undo our setting of pending before we queue ourselves. + * We're pending, wait for the owner to go away. + * + * 0,1,1 -> 0,1,0 + * + * this wait loop must be a load-acquire such that we match the + * store-release that clears the locked bit and create lock + * sequentiality; this is because not all + * clear_pending_set_locked() implementations imply full + * barriers. + */ + if (val & _Q_LOCKED_MASK) + smp_cond_load_acquire(&lock->val.counter, !(VAL & _Q_LOCKED_MASK)); + + /* + * take ownership and clear the pending bit. + * + * 0,1,0 -> 0,0,1 */ - if (!(val & _Q_PENDING_MASK)) - clear_pending(lock); + clear_pending_set_locked(lock); + return; /* * End of pending bit optimistic spinning and beginning of MCS -- 2.19.1