linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 7/7] mmap_lock: add a tracepoint to contended acquisitions
@ 2020-05-28 23:53 Axel Rasmussen
  0 siblings, 0 replies; only message in thread
From: Axel Rasmussen @ 2020-05-28 23:53 UTC (permalink / raw)
  To: Andrew Morton, David Rientjes, Davidlohr Bueso, Ingo Molnar,
	Ingo Molnar, Jerome Glisse, Laurent Dufour, Liam R . Howlett,
	Matthew Wilcox, Michel Lespinasse, Peter Zijlstra,
	Vlastimil Babka, Will Deacon
  Cc: linux-fsdevel, linux-kernel, linux-mm, AKASHI Takahiro,
	Aleksa Sarai, Alexander Potapenko, Alexey Dobriyan, Al Viro,
	Andrei Vagin, Ard Biesheuvel, Brendan Higgins, chenqiwu,
	Christian Brauner, Christian Kellner, Corentin Labbe,
	Daniel Jordan, Dan Williams, David Gow, David S. Miller,
	Dmitry V. Levin, Eric W. Biederman, Eugene Syromiatnikov,
	Jamie Liu, Jason Gunthorpe, John Garry, John Hubbard,
	Jonathan Adams, Junaid Shahid, Kees Cook, Kirill A. Shutemov,
	Konstantin Khlebnikov, Krzysztof Kozlowski, Mark Rutland,
	Masahiro Yamada, Masami Hiramatsu, Mathieu Desnoyers,
	Michal Hocko, Mikhail Zaslonko, Petr Mladek, Ralph Campbell,
	Randy Dunlap, Roman Gushchin, Shakeel Butt, Steven Rostedt,
	Tal Gilboa, Thomas Gleixner, Uwe Kleine-König,
	Vincenzo Frascino, Yang Shi, Yu Zhao, Axel Rasmussen

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



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-05-28 23:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-28 23:53 [PATCH v2 7/7] mmap_lock: add a tracepoint to contended acquisitions Axel Rasmussen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).