[v2,7/7] mmap_lock: add a tracepoint to contended acquisitions
diff mbox series

Message ID 20200528235310.79194-1-axelrasmussen@google.com
State New
Headers show
Series
  • Add histogram measuring mmap_lock contention latency
Related show

Commit Message

Axel Rasmussen May 28, 2020, 11:53 p.m. UTC
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

Patch
diff mbox series

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)) {                                 \