All of lore.kernel.org
 help / color / mirror / Atom feed
From: Axel Rasmussen <axelrasmussen@google.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	David Rientjes <rientjes@google.com>,
	 Davidlohr Bueso <dbueso@suse.de>, Ingo Molnar <mingo@kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Jerome Glisse <jglisse@redhat.com>,
	Laurent Dufour <ldufour@linux.ibm.com>,
	 "Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Matthew Wilcox <willy@infradead.org>,
	 Michel Lespinasse <walken@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	 Vlastimil Babka <vbabka@suse.cz>, Will Deacon <will@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org,
	"AKASHI Takahiro" <takahiro.akashi@linaro.org>,
	"Aleksa Sarai" <cyphar@cyphar.com>,
	"Alexander Potapenko" <glider@google.com>,
	"Alexey Dobriyan" <adobriyan@gmail.com>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	"Andrei Vagin" <avagin@gmail.com>,
	"Ard Biesheuvel" <ardb@kernel.org>,
	"Brendan Higgins" <brendanhiggins@google.com>,
	chenqiwu <chenqiwu@xiaomi.com>,
	"Christian Brauner" <christian.brauner@ubuntu.com>,
	"Christian Kellner" <christian@kellner.me>,
	"Corentin Labbe" <clabbe@baylibre.com>,
	"Daniel Jordan" <daniel.m.jordan@oracle.com>,
	"Dan Williams" <dan.j.williams@intel.com>,
	"David Gow" <davidgow@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Dmitry V. Levin" <ldv@altlinux.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	"Eugene Syromiatnikov" <esyr@redhat.com>,
	"Jamie Liu" <jamieliu@google.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"John Garry" <john.garry@huawei.com>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Jonathan Adams" <jwadams@google.com>,
	"Junaid Shahid" <junaids@google.com>,
	"Kees Cook" <keescook@chromium.org>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	"Konstantin Khlebnikov" <khlebnikov@yandex-team.ru>,
	"Krzysztof Kozlowski" <krzk@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Masahiro Yamada" <yamada.masahiro@socionext.com>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	"Michal Hocko" <mhocko@suse.com>,
	"Mikhail Zaslonko" <zaslonko@linux.ibm.com>,
	"Petr Mladek" <pmladek@suse.com>,
	"Ralph Campbell" <rcampbell@nvidia.com>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Roman Gushchin" <guro@fb.com>,
	"Shakeel Butt" <shakeelb@google.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Tal Gilboa" <talgi@mellanox.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Uwe Kleine-König" <uwe@kleine-koenig.org>,
	"Vincenzo Frascino" <vincenzo.frascino@arm.com>,
	"Yang Shi" <yang.shi@linux.alibaba.com>,
	"Yu Zhao" <yuzhao@google.com>,
	"Axel Rasmussen" <axelrasmussen@google.com>
Subject: [PATCH v2 7/7] mmap_lock: add a tracepoint to contended acquisitions
Date: Thu, 28 May 2020 16:53:10 -0700	[thread overview]
Message-ID: <20200528235310.79194-1-axelrasmussen@google.com> (raw)

This allows for the possibiilty of attaching to the tracepoint, to
collect more detailed information than the contention histogram
would otherwise provide.

The tracepoint is called in the same codepath where we increment
the contention histogram (so, it's not really available if the
histogram is disabled). The intent is that this is a more detailed
but more expensive *extension* to the basic data the contention
histogram provides.

Signed-off-by: Axel Rasmussen <axelrasmussen@google.com>
---
 include/linux/mmap_lock.h        |  9 +++++++--
 include/trace/events/mmap_lock.h | 34 ++++++++++++++++++++++++++++++++
 mm/mmap_lock.c                   | 12 +++++++++++
 3 files changed, 53 insertions(+), 2 deletions(-)
 create mode 100644 include/trace/events/mmap_lock.h

diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h
index 1c212a403911..4faed7a5bb49 100644
--- a/include/linux/mmap_lock.h
+++ b/include/linux/mmap_lock.h
@@ -11,6 +11,8 @@
 	.mmap_lock = __RWSEM_INITIALIZER(name.mmap_lock),
 
 #ifdef CONFIG_MMAP_LOCK_HISTOGRAMS
+void __trace_mmap_lock_contended(struct mm_struct *mm, u64 duration);
+
 static inline void __mmap_lock_histogram_record_duration(struct mm_struct *mm,
 							 u64 duration)
 {
@@ -21,8 +23,11 @@ static inline void __mmap_lock_histogram_record_duration(struct mm_struct *mm,
 static inline void mmap_lock_histogram_record(struct mm_struct *mm,
 					      u64 start_time_ns)
 {
-	__mmap_lock_histogram_record_duration(mm,
-					      sched_clock() - start_time_ns);
+	u64 duration = sched_clock() - start_time_ns;
+
+	/* This function is only used in the contended case, so trace here. */
+	__trace_mmap_lock_contended(mm, duration);
+	__mmap_lock_histogram_record_duration(mm, duration);
 }
 #endif
 
diff --git a/include/trace/events/mmap_lock.h b/include/trace/events/mmap_lock.h
new file mode 100644
index 000000000000..afd581f5fbdb
--- /dev/null
+++ b/include/trace/events/mmap_lock.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM mmap_lock
+
+#if !defined(_TRACE_MMAP_LOCK_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_MMAP_LOCK_H
+
+#include <linux/tracepoint.h>
+#include <linux/types.h>
+
+struct mm_struct;
+
+TRACE_EVENT(mmap_lock_contended,
+
+	TP_PROTO(struct mm_struct *mm, u64 duration),
+
+	TP_ARGS(mm, duration),
+
+	TP_STRUCT__entry(
+		__field(struct mm_struct *, mm)
+		__field(u64, duration)
+	),
+
+	TP_fast_assign(
+		__entry->mm = mm;
+		__entry->duration = duration;
+	),
+
+	TP_printk("mm=%p duration=%llu\n", __entry->mm, __entry->duration));
+
+#endif /* _TRACE_MMAP_LOCK_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c
index f166cf40c60a..406c43039b0b 100644
--- a/mm/mmap_lock.c
+++ b/mm/mmap_lock.c
@@ -1,8 +1,20 @@
 // SPDX-License-Identifier: GPL-2.0
+#define CREATE_TRACE_POINTS
+#include <trace/events/mmap_lock.h>
+
 #include <linux/kernel.h>
 #include <linux/lockdep.h>
 #include <linux/mmap_lock.h>
 
+void __trace_mmap_lock_contended(struct mm_struct *mm, u64 duration)
+{
+	/* This must be in a separate file, as otherwise there's a circular
+	 * dependency between linux/mmap_lock.h and trace/events/mmap_lock.h.
+	 */
+	trace_mmap_lock_contended(mm, duration);
+}
+EXPORT_SYMBOL_GPL(__trace_mmap_lock_contended);
+
 #define MMAP_LOCK_CONTENDED(_mm, try, lock)                                    \
 	do {                                                                   \
 		if (!try(&(_mm)->mmap_lock)) {                                 \
-- 
2.27.0.rc0.183.gde8f92d652-goog



                 reply	other threads:[~2020-05-28 23:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200528235310.79194-1-axelrasmussen@google.com \
    --to=axelrasmussen@google.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=avagin@gmail.com \
    --cc=brendanhiggins@google.com \
    --cc=chenqiwu@xiaomi.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=christian@kellner.me \
    --cc=clabbe@baylibre.com \
    --cc=cyphar@cyphar.com \
    --cc=dan.j.williams@intel.com \
    --cc=daniel.m.jordan@oracle.com \
    --cc=davem@davemloft.net \
    --cc=davidgow@google.com \
    --cc=dbueso@suse.de \
    --cc=ebiederm@xmission.com \
    --cc=esyr@redhat.com \
    --cc=glider@google.com \
    --cc=guro@fb.com \
    --cc=jamieliu@google.com \
    --cc=jgg@ziepe.ca \
    --cc=jglisse@redhat.com \
    --cc=jhubbard@nvidia.com \
    --cc=john.garry@huawei.com \
    --cc=junaids@google.com \
    --cc=jwadams@google.com \
    --cc=keescook@chromium.org \
    --cc=khlebnikov@yandex-team.ru \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=krzk@kernel.org \
    --cc=ldufour@linux.ibm.com \
    --cc=ldv@altlinux.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=mhocko@suse.com \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rcampbell@nvidia.com \
    --cc=rdunlap@infradead.org \
    --cc=rientjes@google.com \
    --cc=rostedt@goodmis.org \
    --cc=shakeelb@google.com \
    --cc=takahiro.akashi@linaro.org \
    --cc=talgi@mellanox.com \
    --cc=tglx@linutronix.de \
    --cc=uwe@kleine-koenig.org \
    --cc=vbabka@suse.cz \
    --cc=vincenzo.frascino@arm.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=walken@google.com \
    --cc=will@kernel.org \
    --cc=willy@infradead.org \
    --cc=yamada.masahiro@socionext.com \
    --cc=yang.shi@linux.alibaba.com \
    --cc=yuzhao@google.com \
    --cc=zaslonko@linux.ibm.com \
    /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.