From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22A8B645 for ; Wed, 8 Jan 2025 02:19:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736302785; cv=none; b=i4KueKw2Djy3K+H7Zp1n078j2W10dA/IM9zJqjqgo0hibcFMMyDAbX+z4TiqZQV3avwl/ncOAM7FqaPHvVtOuMzgu8h2bfzWWvb1DXlYsbO+7iI/9gta7pvtYofNOw2+2p8126MqyzPpHqvkXEEVf9co3EobPS3sPKKPDCsG0tE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736302785; c=relaxed/simple; bh=Qj+hLD0gEGnHb8JH0qSYU8eyFpcK4ftOZb4vC7NlWsk=; h=From:Message-ID:Date:MIME-Version:Subject:To:Cc:References: In-Reply-To:Content-Type; b=TRnFPgIrDcPESly2hvVIVVS0oDFvKL56w8fHzygeQ9uwsU0ryZwAINRa9pwBCpbW96qhjdQx0mKYfe6F/IOPvEkj5CJXslc3AcPZz3oDW6xRhVxmyXvD8tmHPiImZkdpaRWd2sUbVVXjgQOOgQ+O8o64khoKc12c61dymBLyiNE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=enoEtplH; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="enoEtplH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736302782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8LJU0czswQQdicouhFkuEn3K0tQUHiRMIxjJx5nDcxI=; b=enoEtplHSUMB1z3U+/K1q+dwWMSkTXE480Zfeu9VLopAAv6mx0QdOZigr9Nj/cz0owz4Fv PGyswmf9zZ2gbRxY0+E66CzQ55dSnrkEPyHg+ThRs140sdXuhfxxPfacA7Fszm5Im9cFY3 6Dv/JKdaK7WAbGL2DotDUXGuQqw8sow= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-i2CerDhQPOarQ_xKy5_JkQ-1; Tue, 07 Jan 2025 21:19:41 -0500 X-MC-Unique: i2CerDhQPOarQ_xKy5_JkQ-1 X-Mimecast-MFC-AGG-ID: i2CerDhQPOarQ_xKy5_JkQ Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6d8f78fdad0so245706696d6.2 for ; Tue, 07 Jan 2025 18:19:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736302781; x=1736907581; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:user-agent:mime-version:date:message-id:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8LJU0czswQQdicouhFkuEn3K0tQUHiRMIxjJx5nDcxI=; b=w0Wp42jYwogi9c1Qd6rt0NoZRRMFPsdMjeLpUkE6wtAVlLkRXe0UBuyLf+/jXfPXrM JxhEWg7PYQmv6Fl0o6UUbcPFdjVhO/hvPs00gWWmNvBBWhxMpSXO9NGlr4KQy+5ekSVo 0WGRgrz4fK+5lxM6gMPzvqoVvM76j89IW3ERaDu18sma/NhCVzpkP8nelfY5erO0Hf4N yPIrnH3WoXQgj8BMdmkvZ2Xd3cXvugT/EehwpC53VDXQwOg/Unr77IYUtqL6QlDwW0vA mF/lF7BeMMPc5RmdjA91V7wdXBI2uauta8v00Z6hRAe5G2EkBpl3+cLCJYqw61wqR626 Ljbw== X-Forwarded-Encrypted: i=1; AJvYcCXZEJutGPlWWqNRHRuimqOR747XH6Dx8mx8Fl5fN37vkDdV+rK1R/n5Kw7+jzUCpk0UO+Hb9OAau9Tl20M=@vger.kernel.org X-Gm-Message-State: AOJu0Yzj6uif1UJc1hyIqObS0tYJ6xDVPgsVqRYWEtmcSPAIMHcM7zah 2GzI6GuPvpeJfE2yJajedW/Mf5ph2quLinrMnHb95cZknxY3f3Ml660pasdyLaaeemVzMDhUR3X pgI5Ky+fv83bIZDurEwZRuwICd27uoGmehoq31O6JeIxyG7roU+rm7kPfr8jayw== X-Gm-Gg: ASbGnct8AOXXwSlTMD9iTPPK8r7sRQ1JVEaWWo86zJvzTql7FGDA7hecpChJnkaR4TS TcOFwKi2R2x8MssQyjfdcnuuwXkyXCb+0Sre9+3lr7gAFXGEKCsiY51BWYtpK2FvUDA7+Hjm0aH AddSBcc7hlIxuudNxjjZnDHSKgHulKwx58v8frEv5G4EGUhKCcnSXTjvlHOudR/mazRy393Q41n pK0awoMtTRC5LEI7OQy80hmJ7yPA/ihYu0JZWeYl2PpCKu7ivGfxxZsGo9wLCUjMD9Pb/pdpKNH y4SAyEkwFIZobmeL8gQqJuZk X-Received: by 2002:a05:6214:21eb:b0:6d8:850a:4d69 with SMTP id 6a1803df08f44-6df9b1c9d3emr22539536d6.1.1736302780789; Tue, 07 Jan 2025 18:19:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMT0AZpQ96TehcTrjNxJCuvyQJtut5soZJJgcQFg5JSircrYlrtBGZhzNe7YbnASHCikeEeA== X-Received: by 2002:a05:6214:21eb:b0:6d8:850a:4d69 with SMTP id 6a1803df08f44-6df9b1c9d3emr22539296d6.1.1736302780493; Tue, 07 Jan 2025 18:19:40 -0800 (PST) Received: from ?IPV6:2601:188:ca00:a00:f844:fad5:7984:7bd7? ([2601:188:ca00:a00:f844:fad5:7984:7bd7]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd180ebe59sm186114706d6.27.2025.01.07.18.19.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Jan 2025 18:19:39 -0800 (PST) From: Waiman Long X-Google-Original-From: Waiman Long Message-ID: <593abb4c-12d6-4d61-a41e-f258cb8f22c6@redhat.com> Date: Tue, 7 Jan 2025 21:19:31 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH bpf-next v1 08/22] rqspinlock: Protect pending bit owners from stalls To: Kumar Kartikeya Dwivedi , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Barret Rhoden , Linus Torvalds , Peter Zijlstra , Waiman Long , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Eduard Zingerman , "Paul E. McKenney" , Tejun Heo , Josh Don , Dohyun Kim , kernel-team@meta.com References: <20250107140004.2732830-1-memxor@gmail.com> <20250107140004.2732830-9-memxor@gmail.com> Content-Language: en-US In-Reply-To: <20250107140004.2732830-9-memxor@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/7/25 8:59 AM, Kumar Kartikeya Dwivedi wrote: > The pending bit is used to avoid queueing in case the lock is > uncontended, and has demonstrated benefits for the 2 contender scenario, > esp. on x86. In case the pending bit is acquired and we wait for the > locked bit to disappear, we may get stuck due to the lock owner not > making progress. Hence, this waiting loop must be protected with a > timeout check. > > To perform a graceful recovery once we decide to abort our lock > acquisition attempt in this case, we must unset the pending bit since we > own it. All waiters undoing their changes and exiting gracefully allows > the lock word to be restored to the unlocked state once all participants > (owner, waiters) have been recovered, and the lock remains usable. > Hence, set the pending bit back to zero before returning to the caller. > > Introduce a lockevent (rqspinlock_lock_timeout) to capture timeout > event statistics. > > Reviewed-by: Barret Rhoden > Signed-off-by: Kumar Kartikeya Dwivedi > --- > include/asm-generic/rqspinlock.h | 2 +- > kernel/locking/lock_events_list.h | 5 +++++ > kernel/locking/rqspinlock.c | 28 +++++++++++++++++++++++----- > 3 files changed, 29 insertions(+), 6 deletions(-) > > diff --git a/include/asm-generic/rqspinlock.h b/include/asm-generic/rqspinlock.h > index 8ed266f4e70b..5c996a82e75f 100644 > --- a/include/asm-generic/rqspinlock.h > +++ b/include/asm-generic/rqspinlock.h > @@ -19,6 +19,6 @@ struct qspinlock; > */ > #define RES_DEF_TIMEOUT (NSEC_PER_SEC / 2) > > -extern void resilient_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val, u64 timeout); > +extern int resilient_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val, u64 timeout); > > #endif /* __ASM_GENERIC_RQSPINLOCK_H */ > diff --git a/kernel/locking/lock_events_list.h b/kernel/locking/lock_events_list.h > index 97fb6f3f840a..c5286249994d 100644 > --- a/kernel/locking/lock_events_list.h > +++ b/kernel/locking/lock_events_list.h > @@ -49,6 +49,11 @@ LOCK_EVENT(lock_use_node4) /* # of locking ops that use 4th percpu node */ > LOCK_EVENT(lock_no_node) /* # of locking ops w/o using percpu node */ > #endif /* CONFIG_QUEUED_SPINLOCKS */ > > +/* > + * Locking events for Resilient Queued Spin Lock > + */ > +LOCK_EVENT(rqspinlock_lock_timeout) /* # of locking ops that timeout */ > + > /* > * Locking events for rwsem > */ Since the build of rqspinlock.c is conditional on CONFIG_QUEUED_SPINLOCKS, this lock event should be inside the CONFIG_QUEUED_SPINLOCKS block. Cheers, Longman