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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0289C433EF for ; Wed, 11 May 2022 08:31:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243729AbiEKIbc (ORCPT ); Wed, 11 May 2022 04:31:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243732AbiEKIau (ORCPT ); Wed, 11 May 2022 04:30:50 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00777AE59 for ; Wed, 11 May 2022 01:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Z5e65L0M41Gs6gcibvNCWhoVMZX63kJooFCukdv86e0=; b=cC5m+FXs3pQOted/Fo/m8h5tmY MEN2YGzsI/VpSjyAa6MS24IIDOd1qWs6Cea7KeF+u465ZQBXMAPudbzUYnPGMuUFhb43mnAJKZNYz Ao35McZcy9IbGAvfB/A2+MKq2Tk+HeO5xj1u5+dX5R6qlcIZQFLGDG10rO7SbXqqdQqZJnjm0g6XN wzmUgjGqLPwvC7GUJvSaDJ2IzBL6VV8Hs/SttaLW4VTvIFCyy3He6GuURAmNxjYqGDgWkctxsIdYz qJYpRbJ73gk/kLRZD9kv27O8tfn0iOQJCLJBHvk1VHfB2Jz+lU4axJqJ/oVSiqhfPYQjYy74xB3qC rh9kIkMw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nohjy-005HDw-Dz; Wed, 11 May 2022 08:30:38 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 44F0E980E3A; Wed, 11 May 2022 10:30:36 +0200 (CEST) Date: Wed, 11 May 2022 10:30:36 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , Will Deacon , Boqun Feng , Arnd Bergmann , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] locking/qrwlock: Reduce cacheline contention for rwlocks used in interrupt context Message-ID: <20220511083036.GY76023@worktop.programming.kicks-ass.net> References: <20220510192134.434753-1-longman@redhat.com> <20220510192134.434753-2-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220510192134.434753-2-longman@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 10, 2022 at 03:21:34PM -0400, Waiman Long wrote: > Even though qrwlock is supposed to be a fair lock, it does allow readers > from interrupt context to spin on the lock until it can acquire it making > it not as fair. This exception was added due to the requirement to allow > recursive read lock in interrupt context. This can also be achieved by > just ignoring the writer waiting bit without spinning on the lock. > > By making this change, we make qrwlock a bit more fair and eliminating > the problem of cacheline bouncing for rwlocks that are used heavily in > interrupt context, like the networking stack. This should also reduce > the chance of lock starvation for those interrupt context rwlocks. > diff --git a/kernel/locking/qrwlock.c b/kernel/locking/qrwlock.c > index 2e1600906c9f..d52d13e95600 100644 > --- a/kernel/locking/qrwlock.c > +++ b/kernel/locking/qrwlock.c > @@ -18,21 +18,16 @@ > * queued_read_lock_slowpath - acquire read lock of a queued rwlock > * @lock: Pointer to queued rwlock structure > */ > -void queued_read_lock_slowpath(struct qrwlock *lock) > +void queued_read_lock_slowpath(struct qrwlock *lock, int cnts) > { > /* > - * Readers come here when they cannot get the lock without waiting > + * Readers come here when they cannot get the lock without waiting. > + * Readers in interrupt context can steal the lock immediately > + * if the writer is just waiting (not holding the lock yet). > */ > - if (unlikely(in_interrupt())) { > - /* > - * Readers in interrupt context will get the lock immediately > - * if the writer is just waiting (not holding the lock yet), > - * so spin with ACQUIRE semantics until the lock is available > - * without waiting in the queue. > - */ > - atomic_cond_read_acquire(&lock->cnts, !(VAL & _QW_LOCKED)); > + if (unlikely(!(cnts & _QW_LOCKED) && in_interrupt())) > return; > - } > + > atomic_sub(_QR_BIAS, &lock->cnts); > > trace_contention_begin(lock, LCB_F_SPIN | LCB_F_READ); I'm confused; prior to this change: CPU0 CPU1 write_lock_irq(&l) read_lock(&l) read_lock(&l) ... was not deadlock, but now it would AFAICT.