Skip to content

Commit a8d154b

Browse files
Steven Rostedtrostedt
authored andcommitted
tracing: create automated trace defines
This patch lowers the number of places a developer must modify to add new tracepoints. The current method to add a new tracepoint into an existing system is to write the trace point macro in the trace header with one of the macros TRACE_EVENT, TRACE_FORMAT or DECLARE_TRACE, then they must add the same named item into the C file with the macro DEFINE_TRACE(name) and then add the trace point. This change cuts out the needing to add the DEFINE_TRACE(name). Every file that uses the tracepoint must still include the trace/<type>.h file, but the one C file must also add a define before the including of that file. #define CREATE_TRACE_POINTS #include <trace/mytrace.h> This will cause the trace/mytrace.h file to also produce the C code necessary to implement the trace point. Note, if more than one trace/<type>.h is used to create the C code it is best to list them all together. #define CREATE_TRACE_POINTS #include <trace/foo.h> #include <trace/bar.h> #include <trace/fido.h> Thanks to Mathieu Desnoyers and Christoph Hellwig for coming up with the cleaner solution of the define above the includes over my first design to have the C code include a "special" header. This patch converts sched, irq and lockdep and skb to use this new method. Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Neil Horman <nhorman@tuxdriver.com> Cc: Zhao Lei <zhaolei@cn.fujitsu.com> Cc: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> Cc: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent ea20d92 commit a8d154b

16 files changed

Lines changed: 105 additions & 46 deletions

File tree

‎include/trace/define_trace.h‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Trace files that want to automate creationg of all tracepoints defined
3+
* in their file should include this file. The following are macros that the
4+
* trace file may define:
5+
*
6+
* TRACE_SYSTEM defines the system the tracepoint is for
7+
*
8+
* TRACE_INCLUDE_FILE if the file name is something other than TRACE_SYSTEM.h
9+
* This macro may be defined to tell define_trace.h what file to include.
10+
* Note, leave off the ".h".
11+
*
12+
* TRACE_INCLUDE_PATH if the path is something other than core kernel include/trace
13+
* then this macro can define the path to use. Note, the path is relative to
14+
* define_trace.h, not the file including it. Full path names for out of tree
15+
* modules must be used.
16+
*/
17+
18+
#ifdef CREATE_TRACE_POINTS
19+
20+
/* Prevent recursion */
21+
#undef CREATE_TRACE_POINTS
22+
23+
#include <linux/stringify.h>
24+
25+
#undef TRACE_EVENT
26+
#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
27+
DEFINE_TRACE(name)
28+
29+
#undef TRACE_FORMAT
30+
#define TRACE_FORMAT(name, proto, args, print) \
31+
DEFINE_TRACE(name)
32+
33+
#undef DECLARE_TRACE
34+
#define DECLARE_TRACE(name, proto, args) \
35+
DEFINE_TRACE(name)
36+
37+
#undef TRACE_INCLUDE
38+
#undef __TRACE_INCLUDE
39+
40+
#ifndef TRACE_INCLUDE_FILE
41+
# define TRACE_INCLUDE_FILE TRACE_SYSTEM
42+
# define UNDEF_TRACE_INCLUDE_FILE
43+
#endif
44+
45+
#ifndef TRACE_INCLUDE_PATH
46+
# define __TRACE_INCLUDE(system) <trace/system.h>
47+
# define UNDEF_TRACE_INCLUDE_FILE
48+
#else
49+
# define __TRACE_INCLUDE(system) __stringify(TRACE_INCLUDE_PATH/system.h)
50+
#endif
51+
52+
# define TRACE_INCLUDE(system) __TRACE_INCLUDE(system)
53+
54+
/* Let the trace headers be reread */
55+
#define TRACE_HEADER_MULTI_READ
56+
57+
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
58+
59+
#undef TRACE_HEADER_MULTI_READ
60+
61+
/* Only undef what we defined in this file */
62+
#ifdef UNDEF_TRACE_INCLUDE_FILE
63+
# undef TRACE_INCLUDE_PATH
64+
# undef UNDEF_TRACE_INCLUDE_FILE
65+
#endif
66+
67+
#ifdef UNDEF_TRACE_INCLUDE_FILE
68+
# undef TRACE_INCLUDE_PATH
69+
# undef UNDEF_TRACE_INCLUDE_FILE
70+
#endif
71+
72+
/* We may be processing more files */
73+
#define CREATE_TRACE_POINTS
74+
75+
#endif /* CREATE_TRACE_POINTS */

‎include/trace/irq.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ TRACE_FORMAT(softirq_exit,
5151
TP_FMT("softirq=%d action=%s", (int)(h - vec), softirq_to_name[h-vec])
5252
);
5353

54-
#endif
54+
#endif /* _TRACE_IRQ_H */
55+
56+
/* This part must be outside protection */
57+
#include <trace/define_trace.h>

‎include/trace/kmem.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,7 @@ TRACE_EVENT(kmem_cache_free,
188188

189189
TP_printk("call_site=%lx ptr=%p", __entry->call_site, __entry->ptr)
190190
);
191+
#endif /* _TRACE_KMEM_H */
191192

192-
#endif
193+
/* This part must be outside protection */
194+
#include <trace/define_trace.h>

‎include/trace/lockdep.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ TRACE_EVENT(lock_acquired,
5555
#endif
5656

5757
#endif /* _TRACE_LOCKDEP_H */
58+
59+
/* This part must be outside protection */
60+
#include <trace/define_trace.h>

‎include/trace/sched.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,6 @@ TRACE_EVENT(sched_signal_send,
334334
);
335335

336336
#endif /* _TRACE_SCHED_H */
337+
338+
/* This part must be outside protection */
339+
#include <trace/define_trace.h>

‎include/trace/skb.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ TRACE_EVENT(kfree_skb,
3535
);
3636

3737
#endif /* _TRACE_SKB_H */
38+
39+
/* This part must be outside protection */
40+
#include <trace/define_trace.h>

‎kernel/exit.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@
5656
#include <asm/mmu_context.h>
5757
#include "cred-internals.h"
5858

59-
DEFINE_TRACE(sched_process_free);
60-
DEFINE_TRACE(sched_process_exit);
61-
DEFINE_TRACE(sched_process_wait);
62-
6359
static void exit_mm(struct task_struct * tsk);
6460

6561
static void __unhash_process(struct task_struct *p)

‎kernel/fork.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ DEFINE_PER_CPU(unsigned long, process_counts) = 0;
8383

8484
__cacheline_aligned DEFINE_RWLOCK(tasklist_lock); /* outer */
8585

86-
DEFINE_TRACE(sched_process_fork);
87-
8886
int nr_processes(void)
8987
{
9088
int cpu;

‎kernel/irq/handle.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
#include <linux/kernel_stat.h>
1818
#include <linux/rculist.h>
1919
#include <linux/hash.h>
20-
#include <trace/irq.h>
2120
#include <linux/bootmem.h>
2221

22+
#define CREATE_TRACE_POINTS
23+
#include <trace/irq.h>
24+
2325
#include "internals.h"
2426

2527
/*
@@ -348,9 +350,6 @@ static void warn_no_thread(unsigned int irq, struct irqaction *action)
348350
"but no thread function available.", irq, action->name);
349351
}
350352

351-
DEFINE_TRACE(irq_handler_entry);
352-
DEFINE_TRACE(irq_handler_exit);
353-
354353
/**
355354
* handle_IRQ_event - irq action chain handler
356355
* @irq: the interrupt number

‎kernel/kthread.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ static DEFINE_SPINLOCK(kthread_create_lock);
2121
static LIST_HEAD(kthread_create_list);
2222
struct task_struct *kthreadd_task;
2323

24-
DEFINE_TRACE(sched_kthread_stop);
25-
DEFINE_TRACE(sched_kthread_stop_ret);
26-
2724
struct kthread_create_info
2825
{
2926
/* Information passed to kthread() from kthreadd. */

0 commit comments

Comments
 (0)