Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

context_tracking: User/kernel broundary cross trace events

This can be useful to track all kernel/user round trips.
And it's also helpful to debug the context tracking subsystem.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Li Zhong <zhong@linux.vnet.ibm.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Kevin Hilman <khilman@linaro.org>

+63
+58
include/trace/events/context_tracking.h
··· 1 + #undef TRACE_SYSTEM 2 + #define TRACE_SYSTEM context_tracking 3 + 4 + #if !defined(_TRACE_CONTEXT_TRACKING_H) || defined(TRACE_HEADER_MULTI_READ) 5 + #define _TRACE_CONTEXT_TRACKING_H 6 + 7 + #include <linux/tracepoint.h> 8 + 9 + DECLARE_EVENT_CLASS(context_tracking_user, 10 + 11 + TP_PROTO(int dummy), 12 + 13 + TP_ARGS(dummy), 14 + 15 + TP_STRUCT__entry( 16 + __field( int, dummy ) 17 + ), 18 + 19 + TP_fast_assign( 20 + __entry->dummy = dummy; 21 + ), 22 + 23 + TP_printk("%s", "") 24 + ); 25 + 26 + /** 27 + * user_enter - called when the kernel resumes to userspace 28 + * @dummy: dummy arg to make trace event macro happy 29 + * 30 + * This event occurs when the kernel resumes to userspace after 31 + * an exception or a syscall. 32 + */ 33 + DEFINE_EVENT(context_tracking_user, user_enter, 34 + 35 + TP_PROTO(int dummy), 36 + 37 + TP_ARGS(dummy) 38 + ); 39 + 40 + /** 41 + * user_exit - called when userspace enters the kernel 42 + * @dummy: dummy arg to make trace event macro happy 43 + * 44 + * This event occurs when userspace enters the kernel through 45 + * an exception or a syscall. 46 + */ 47 + DEFINE_EVENT(context_tracking_user, user_exit, 48 + 49 + TP_PROTO(int dummy), 50 + 51 + TP_ARGS(dummy) 52 + ); 53 + 54 + 55 + #endif /* _TRACE_CONTEXT_TRACKING_H */ 56 + 57 + /* This part must be outside protection */ 58 + #include <trace/define_trace.h>
+5
kernel/context_tracking.c
··· 20 20 #include <linux/hardirq.h> 21 21 #include <linux/export.h> 22 22 23 + #define CREATE_TRACE_POINTS 24 + #include <trace/events/context_tracking.h> 25 + 23 26 struct static_key context_tracking_enabled = STATIC_KEY_INIT_FALSE; 24 27 EXPORT_SYMBOL_GPL(context_tracking_enabled); 25 28 ··· 67 64 local_irq_save(flags); 68 65 if ( __this_cpu_read(context_tracking.state) != IN_USER) { 69 66 if (__this_cpu_read(context_tracking.active)) { 67 + trace_user_enter(0); 70 68 /* 71 69 * At this stage, only low level arch entry code remains and 72 70 * then we'll run in userspace. We can assume there won't be ··· 163 159 */ 164 160 rcu_user_exit(); 165 161 vtime_user_exit(current); 162 + trace_user_exit(0); 166 163 } 167 164 __this_cpu_write(context_tracking.state, IN_KERNEL); 168 165 }