All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>, Will Deacon <will@kernel.org>,
	Waiman Long <longman@redhat.com>,
	Boqun Feng <boqun.feng@gmail.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	rostedt <rostedt@goodmis.org>,
	Byungchul Park <byungchul.park@lge.com>,
	paulmck <paulmck@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
	Radoslaw Burny <rburny@google.com>,
	linux-arch <linux-arch@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH 1/2] locking: Add lock contention tracepoints
Date: Thu, 17 Mar 2022 09:32:55 -0400 (EDT)	[thread overview]
Message-ID: <636955156.156341.1647523975127.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <20220316224548.500123-2-namhyung@kernel.org>

----- On Mar 16, 2022, at 6:45 PM, Namhyung Kim namhyung@kernel.org wrote:

> This adds two new lock contention tracepoints like below:
> 
> * lock:contention_begin
> * lock:contention_end
> 
> The lock:contention_begin takes a flags argument to classify locks.  I
> found it useful to identify what kind of locks it's tracing like if
> it's spinning or sleeping, reader-writer lock, real-time, and per-cpu.
> 
> Move tracepoint definitions into mutex.c so that we can use them
> without lockdep.
> 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> include/trace/events/lock.h | 54 ++++++++++++++++++++++++++++++++++---
> kernel/locking/lockdep.c    |  1 -
> kernel/locking/mutex.c      |  3 +++
> 3 files changed, 54 insertions(+), 4 deletions(-)
> 
> diff --git a/include/trace/events/lock.h b/include/trace/events/lock.h
> index d7512129a324..2a3df36d4fdb 100644
> --- a/include/trace/events/lock.h
> +++ b/include/trace/events/lock.h
> @@ -5,11 +5,21 @@
> #if !defined(_TRACE_LOCK_H) || defined(TRACE_HEADER_MULTI_READ)
> #define _TRACE_LOCK_H
> 
> -#include <linux/lockdep.h>
> +#include <linux/sched.h>
> #include <linux/tracepoint.h>
> 
> +/* flags for lock:contention_begin */
> +#define LCB_F_SPIN	(1U << 0)
> +#define LCB_F_READ	(1U << 1)
> +#define LCB_F_WRITE	(1U << 2)
> +#define LCB_F_RT	(1U << 3)
> +#define LCB_F_PERCPU	(1U << 4)

Unless there is a particular reason for using preprocessor defines here, the
following form is typically better because it does not pollute the preprocessor
defines, e.g.:

enum lock_contention_flags {
        LCB_F_SPIN =   1U << 0;
        LCB_F_READ =   1U << 1;
        LCB_F_WRITE =  1U << 2;
        LCB_F_RT =     1U << 3;
        LCB_F_PERCPU = 1U << 4;
};

Thanks,

Mathieu

> +
> +
> #ifdef CONFIG_LOCKDEP
> 
> +#include <linux/lockdep.h>
> +
> TRACE_EVENT(lock_acquire,
> 
> 	TP_PROTO(struct lockdep_map *lock, unsigned int subclass,
> @@ -78,8 +88,46 @@ DEFINE_EVENT(lock, lock_acquired,
> 	TP_ARGS(lock, ip)
> );
> 
> -#endif
> -#endif
> +#endif /* CONFIG_LOCK_STAT */
> +#endif /* CONFIG_LOCKDEP */
> +
> +TRACE_EVENT(contention_begin,
> +
> +	TP_PROTO(void *lock, unsigned int flags),
> +
> +	TP_ARGS(lock, flags),
> +
> +	TP_STRUCT__entry(
> +		__field(void *, lock_addr)
> +		__field(unsigned int, flags)
> +	),
> +
> +	TP_fast_assign(
> +		__entry->lock_addr = lock;
> +		__entry->flags = flags;
> +	),
> +
> +	TP_printk("%p (flags=%x)", __entry->lock_addr, __entry->flags)
> +);
> +
> +TRACE_EVENT(contention_end,
> +
> +	TP_PROTO(void *lock, int ret),
> +
> +	TP_ARGS(lock, ret),
> +
> +	TP_STRUCT__entry(
> +		__field(void *, lock_addr)
> +		__field(int, ret)
> +	),
> +
> +	TP_fast_assign(
> +		__entry->lock_addr = lock;
> +		__entry->ret = ret;
> +	),
> +
> +	TP_printk("%p (ret=%d)", __entry->lock_addr, __entry->ret)
> +);
> 
> #endif /* _TRACE_LOCK_H */
> 
> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> index 50036c10b518..08f8fb6a2d1e 100644
> --- a/kernel/locking/lockdep.c
> +++ b/kernel/locking/lockdep.c
> @@ -60,7 +60,6 @@
> 
> #include "lockdep_internals.h"
> 
> -#define CREATE_TRACE_POINTS
> #include <trace/events/lock.h>
> 
> #ifdef CONFIG_PROVE_LOCKING
> diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
> index 5e3585950ec8..ee2fd7614a93 100644
> --- a/kernel/locking/mutex.c
> +++ b/kernel/locking/mutex.c
> @@ -30,6 +30,9 @@
> #include <linux/debug_locks.h>
> #include <linux/osq_lock.h>
> 
> +#define CREATE_TRACE_POINTS
> +#include <trace/events/lock.h>
> +
> #ifndef CONFIG_PREEMPT_RT
> #include "mutex.h"
> 
> --
> 2.35.1.894.gb6a874cedc-goog

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

  parent reply	other threads:[~2022-03-17 13:33 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16 22:45 [PATCH 0/2] locking: Add new lock contention tracepoints (v3) Namhyung Kim
2022-03-16 22:45 ` [PATCH 1/2] locking: Add lock contention tracepoints Namhyung Kim
2022-03-17  2:31   ` Steven Rostedt
2022-03-17 13:32   ` Mathieu Desnoyers [this message]
2022-03-17 16:07     ` Steven Rostedt
2022-03-17 16:37       ` Mathieu Desnoyers
2022-03-18 20:58         ` Namhyung Kim
2022-03-16 22:45 ` [PATCH 2/2] locking: Apply contention tracepoints in the slow path Namhyung Kim
2022-03-17 13:45   ` Mathieu Desnoyers
2022-03-17 16:10     ` Steven Rostedt
2022-03-17 16:43       ` Mathieu Desnoyers
2022-03-18 21:34     ` Namhyung Kim
2022-03-17 18:19   ` Hyeonggon Yoo
2022-03-18 21:43     ` Namhyung Kim
2022-03-18 12:55   ` Boqun Feng
2022-03-18 13:24     ` Hyeonggon Yoo
2022-03-18 13:28       ` Hyeonggon Yoo
2022-03-18 16:43     ` Peter Zijlstra
2022-03-18 21:55       ` Namhyung Kim
2022-03-18 22:07         ` Steven Rostedt
2022-03-19  0:11           ` Namhyung Kim
2022-03-22  5:31             ` Namhyung Kim
2022-03-22 12:59               ` Steven Rostedt
2022-03-22 16:39                 ` Namhyung Kim
2022-03-17 17:32 ` [PATCH 0/2] locking: Add new lock contention tracepoints (v3) Hyeonggon Yoo
2022-03-18 21:12   ` Namhyung Kim
  -- strict thread matches above, loose matches on Subject: below --
2022-03-22 18:57 [PATCH 0/2] locking: Add new lock contention tracepoints (v4) Namhyung Kim
2022-03-22 18:57 ` [PATCH 1/2] locking: Add lock contention tracepoints Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=636955156.156341.1647523975127.JavaMail.zimbra@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=arnd@arndb.de \
    --cc=boqun.feng@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=byungchul.park@lge.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rburny@google.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.