From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ilvokhin.com (mail.ilvokhin.com [178.62.254.231]) (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 12826379996; Tue, 31 Mar 2026 12:16:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.62.254.231 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774959411; cv=none; b=NkG5PTtjNUH9buVwWYTgi+L8NVc/H9WF+pWlLXH8HFM6JaLFSNqsaNNOK8NYJPFDtjRyjbZB01R61k9EdJLFL8od0xv8y12V7/rZI4zQNlRzOAk4t3mButIBLN/67Bwn7B7i9PJ6Bd88qJw8DZBOtpyM8reJVc4pCYs/V6PgQOw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774959411; c=relaxed/simple; bh=TakF1Zagv1YgZI7pZAW/GTp7AUkWn9mqkH1+3mQgg+0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dNYQF9+8fzkn6uaCzH7l6nGpZ/R9dCtETEREX4SDJBsCQHOhYytOJZ1Q55Lb9eXWs0bqy/o2ntyGy7tEeWsyoFF8ykc0pG3mq+Kf09oG47tIj3t9tAfIHFsPAOGLzP/7AxDDR3l9xyzQkTls0MUAUFnuLyU+4f4HT1qAfnnLyg4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com; spf=pass smtp.mailfrom=ilvokhin.com; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b=E9ChVItp; arc=none smtp.client-ip=178.62.254.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b="E9ChVItp" Received: from shell.ilvokhin.com (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id C7DD3BE242; Tue, 31 Mar 2026 12:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1774959407; bh=fmOnVSldgMRg/8pGDKo6wUzrYFaZS5iOwP+Hm7ivSzc=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=E9ChVItphVkjUtNNOlIsaXKqbJIKHVd05tZl9VjsTincvkl4+6OIMtozfMyTd9khm wG63Wu+eCzPfC9aBKGIUFKss7uZL7kLRRjZxL80a35fei1ME7K/m2xG6Ft5zImKYdQ nXNrJwdEjYs6yNqfZ5evrY6xy632+Hfb5anmMfN0= Date: Tue, 31 Mar 2026 12:16:45 +0000 From: Dmitry Ilvokhin To: Usama Arif Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Waiman Long , Thomas Bogendoerfer , Juergen Gross , Ajay Kaher , Alexey Makhalov , Broadcom internal kernel review list , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Arnd Bergmann , Dennis Zhou , Tejun Heo , Christoph Lameter , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, virtualization@lists.linux.dev, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH v4 3/5] locking: Add contended_release tracepoint to sleepable locks Message-ID: References: <20260331103451.1070175-1-usama.arif@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260331103451.1070175-1-usama.arif@linux.dev> On Tue, Mar 31, 2026 at 03:34:50AM -0700, Usama Arif wrote: > On Thu, 26 Mar 2026 15:10:02 +0000 Dmitry Ilvokhin wrote: > > > Add the contended_release trace event. This tracepoint fires on the > > holder side when a contended lock is released, complementing the > > existing contention_begin/contention_end tracepoints which fire on the > > waiter side. > > > > This enables correlating lock hold time under contention with waiter > > events by lock address. > > > > Add trace_contended_release() calls to the slowpath unlock paths of > > sleepable locks: mutex, rtmutex, semaphore, rwsem, percpu-rwsem, and > > RT-specific rwbase locks. > > > > Where possible, trace_contended_release() fires before the lock is > > released and before the waiter is woken. For some lock types, the > > tracepoint fires after the release but before the wake. Making the > > placement consistent across all lock types is not worth the added > > complexity. > > > > For reader/writer locks, the tracepoint fires for every reader releasing > > while a writer is waiting, not only for the last reader. > > > > Signed-off-by: Dmitry Ilvokhin > > --- > > include/trace/events/lock.h | 17 +++++++++++++++++ > > kernel/locking/mutex.c | 4 ++++ > > kernel/locking/percpu-rwsem.c | 11 +++++++++++ > > kernel/locking/rtmutex.c | 1 + > > kernel/locking/rwbase_rt.c | 6 ++++++ > > kernel/locking/rwsem.c | 10 ++++++++-- > > kernel/locking/semaphore.c | 4 ++++ > > 7 files changed, 51 insertions(+), 2 deletions(-) > > > > diff --git a/include/trace/events/lock.h b/include/trace/events/lock.h > > index da978f2afb45..1ded869cd619 100644 > > --- a/include/trace/events/lock.h > > +++ b/include/trace/events/lock.h > > @@ -137,6 +137,23 @@ TRACE_EVENT(contention_end, > > TP_printk("%p (ret=%d)", __entry->lock_addr, __entry->ret) > > ); > > > > +TRACE_EVENT(contended_release, > > + > > + TP_PROTO(void *lock), > > + > > + TP_ARGS(lock), > > + > > + TP_STRUCT__entry( > > + __field(void *, lock_addr) > > + ), > > + > > + TP_fast_assign( > > + __entry->lock_addr = lock; > > + ), > > + > > + TP_printk("%p", __entry->lock_addr) > > +); > > + > > #endif /* _TRACE_LOCK_H */ > > > > /* This part must be outside protection */ > > diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c > > index 427187ff02db..6c2c9312eb8f 100644 > > --- a/kernel/locking/mutex.c > > +++ b/kernel/locking/mutex.c > > @@ -997,6 +997,9 @@ static noinline void __sched __mutex_unlock_slowpath(struct mutex *lock, unsigne > > wake_q_add(&wake_q, next); > > } > > > > + if (trace_contended_release_enabled() && waiter) > > + trace_contended_release(lock); > > + > > This won't compile? waiter is declared in the if block, so you are using > it outside scope here. > Thanks for the feedback, Usama. waiter is declared at function scope, right on top. It's also assigned before the if block, so it's still in scope at the tracepoint.