Skip to content

Commit fb40bd7

Browse files
Mathieu DesnoyersLinus Torvalds
authored andcommitted
Linux Kernel Markers: support multiple probes
RCU style multiple probes support for the Linux Kernel Markers. Common case (one probe) is still fast and does not require dynamic allocation or a supplementary pointer dereference on the fast path. - Move preempt disable from the marker site to the callback. Since we now have an internal callback, move the preempt disable/enable to the callback instead of the marker site. Since the callback change is done asynchronously (passing from a handler that supports arguments to a handler that does not setup the arguments is no arguments are passed), we can safely update it even if it is outside the preempt disable section. - Move probe arm to probe connection. Now, a connected probe is automatically armed. Remove MARK_MAX_FORMAT_LEN, unused. This patch modifies the Linux Kernel Markers API : it removes the probe "arm/disarm" and changes the probe function prototype : it now expects a va_list * instead of a "...". If we want to have more than one probe connected to a marker at a given time (LTTng, or blktrace, ssytemtap) then we need this patch. Without it, connecting a second probe handler to a marker will fail. It allow us, for instance, to do interesting combinations : Do standard tracing with LTTng and, eventually, to compute statistics with SystemTAP, or to have a special trigger on an event that would call a systemtap script which would stop flight recorder tracing. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> Cc: Christoph Hellwig <hch@infradead.org> Cc: Mike Mason <mmlnx@us.ibm.com> Cc: Dipankar Sarma <dipankar@in.ibm.com> Cc: David Smith <dsmith@redhat.com> Cc: "Paul E. McKenney" <paulmck@us.ibm.com> Cc: "Frank Ch. Eigler" <fche@redhat.com> Cc: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9170d2f commit fb40bd7

6 files changed

Lines changed: 565 additions & 236 deletions

File tree

‎arch/powerpc/platforms/cell/spufs/sputrace.c‎

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,34 +146,28 @@ static void sputrace_log_item(const char *name, struct spu_context *ctx,
146146
wake_up(&sputrace_wait);
147147
}
148148

149-
static void spu_context_event(const struct marker *mdata,
150-
void *private, const char *format, ...)
149+
static void spu_context_event(void *probe_private, void *call_data,
150+
const char *format, va_list *args)
151151
{
152-
struct spu_probe *p = mdata->private;
153-
va_list ap;
152+
struct spu_probe *p = probe_private;
154153
struct spu_context *ctx;
155154
struct spu *spu;
156155

157-
va_start(ap, format);
158-
ctx = va_arg(ap, struct spu_context *);
159-
spu = va_arg(ap, struct spu *);
156+
ctx = va_arg(*args, struct spu_context *);
157+
spu = va_arg(*args, struct spu *);
160158

161159
sputrace_log_item(p->name, ctx, spu);
162-
va_end(ap);
163160
}
164161

165-
static void spu_context_nospu_event(const struct marker *mdata,
166-
void *private, const char *format, ...)
162+
static void spu_context_nospu_event(void *probe_private, void *call_data,
163+
const char *format, va_list *args)
167164
{
168-
struct spu_probe *p = mdata->private;
169-
va_list ap;
165+
struct spu_probe *p = probe_private;
170166
struct spu_context *ctx;
171167

172-
va_start(ap, format);
173-
ctx = va_arg(ap, struct spu_context *);
168+
ctx = va_arg(*args, struct spu_context *);
174169

175170
sputrace_log_item(p->name, ctx, NULL);
176-
va_end(ap);
177171
}
178172

179173
struct spu_probe spu_probes[] = {
@@ -219,10 +213,6 @@ static int __init sputrace_init(void)
219213
if (error)
220214
printk(KERN_INFO "Unable to register probe %s\n",
221215
p->name);
222-
223-
error = marker_arm(p->name);
224-
if (error)
225-
printk(KERN_INFO "Unable to arm probe %s\n", p->name);
226216
}
227217

228218
return 0;
@@ -238,7 +228,8 @@ static void __exit sputrace_exit(void)
238228
int i;
239229

240230
for (i = 0; i < ARRAY_SIZE(spu_probes); i++)
241-
marker_probe_unregister(spu_probes[i].name);
231+
marker_probe_unregister(spu_probes[i].name,
232+
spu_probes[i].probe_func, &spu_probes[i]);
242233

243234
remove_proc_entry("sputrace", NULL);
244235
kfree(sputrace_log);

‎include/linux/marker.h‎

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,35 @@ struct marker;
1919

2020
/**
2121
* marker_probe_func - Type of a marker probe function
22-
* @mdata: pointer of type struct marker
23-
* @private_data: caller site private data
22+
* @probe_private: probe private data
23+
* @call_private: call site private data
2424
* @fmt: format string
25-
* @...: variable argument list
25+
* @args: variable argument list pointer. Use a pointer to overcome C's
26+
* inability to pass this around as a pointer in a portable manner in
27+
* the callee otherwise.
2628
*
2729
* Type of marker probe functions. They receive the mdata and need to parse the
2830
* format string to recover the variable argument list.
2931
*/
30-
typedef void marker_probe_func(const struct marker *mdata,
31-
void *private_data, const char *fmt, ...);
32+
typedef void marker_probe_func(void *probe_private, void *call_private,
33+
const char *fmt, va_list *args);
34+
35+
struct marker_probe_closure {
36+
marker_probe_func *func; /* Callback */
37+
void *probe_private; /* Private probe data */
38+
};
3239

3340
struct marker {
3441
const char *name; /* Marker name */
3542
const char *format; /* Marker format string, describing the
3643
* variable argument list.
3744
*/
3845
char state; /* Marker state. */
39-
marker_probe_func *call;/* Probe handler function pointer */
40-
void *private; /* Private probe data */
46+
char ptype; /* probe type : 0 : single, 1 : multi */
47+
void (*call)(const struct marker *mdata, /* Probe wrapper */
48+
void *call_private, const char *fmt, ...);
49+
struct marker_probe_closure single;
50+
struct marker_probe_closure *multi;
4151
} __attribute__((aligned(8)));
4252

4353
#ifdef CONFIG_MARKERS
@@ -49,7 +59,7 @@ struct marker {
4959
* not add unwanted padding between the beginning of the section and the
5060
* structure. Force alignment to the same alignment as the section start.
5161
*/
52-
#define __trace_mark(name, call_data, format, args...) \
62+
#define __trace_mark(name, call_private, format, args...) \
5363
do { \
5464
static const char __mstrtab_name_##name[] \
5565
__attribute__((section("__markers_strings"))) \
@@ -60,24 +70,23 @@ struct marker {
6070
static struct marker __mark_##name \
6171
__attribute__((section("__markers"), aligned(8))) = \
6272
{ __mstrtab_name_##name, __mstrtab_format_##name, \
63-
0, __mark_empty_function, NULL }; \
73+
0, 0, marker_probe_cb, \
74+
{ __mark_empty_function, NULL}, NULL }; \
6475
__mark_check_format(format, ## args); \
6576
if (unlikely(__mark_##name.state)) { \
66-
preempt_disable(); \
6777
(*__mark_##name.call) \
68-
(&__mark_##name, call_data, \
78+
(&__mark_##name, call_private, \
6979
format, ## args); \
70-
preempt_enable(); \
7180
} \
7281
} while (0)
7382

7483
extern void marker_update_probe_range(struct marker *begin,
75-
struct marker *end, struct module *probe_module, int *refcount);
84+
struct marker *end);
7685
#else /* !CONFIG_MARKERS */
77-
#define __trace_mark(name, call_data, format, args...) \
86+
#define __trace_mark(name, call_private, format, args...) \
7887
__mark_check_format(format, ## args)
7988
static inline void marker_update_probe_range(struct marker *begin,
80-
struct marker *end, struct module *probe_module, int *refcount)
89+
struct marker *end)
8190
{ }
8291
#endif /* CONFIG_MARKERS */
8392

@@ -92,8 +101,6 @@ static inline void marker_update_probe_range(struct marker *begin,
92101
#define trace_mark(name, format, args...) \
93102
__trace_mark(name, NULL, format, ## args)
94103

95-
#define MARK_MAX_FORMAT_LEN 1024
96-
97104
/**
98105
* MARK_NOARGS - Format string for a marker with no argument.
99106
*/
@@ -106,24 +113,30 @@ static inline void __printf(1, 2) __mark_check_format(const char *fmt, ...)
106113

107114
extern marker_probe_func __mark_empty_function;
108115

116+
extern void marker_probe_cb(const struct marker *mdata,
117+
void *call_private, const char *fmt, ...);
118+
extern void marker_probe_cb_noarg(const struct marker *mdata,
119+
void *call_private, const char *fmt, ...);
120+
109121
/*
110122
* Connect a probe to a marker.
111123
* private data pointer must be a valid allocated memory address, or NULL.
112124
*/
113125
extern int marker_probe_register(const char *name, const char *format,
114-
marker_probe_func *probe, void *private);
126+
marker_probe_func *probe, void *probe_private);
115127

116128
/*
117129
* Returns the private data given to marker_probe_register.
118130
*/
119-
extern void *marker_probe_unregister(const char *name);
131+
extern int marker_probe_unregister(const char *name,
132+
marker_probe_func *probe, void *probe_private);
120133
/*
121134
* Unregister a marker by providing the registered private data.
122135
*/
123-
extern void *marker_probe_unregister_private_data(void *private);
136+
extern int marker_probe_unregister_private_data(marker_probe_func *probe,
137+
void *probe_private);
124138

125-
extern int marker_arm(const char *name);
126-
extern int marker_disarm(const char *name);
127-
extern void *marker_get_private_data(const char *name);
139+
extern void *marker_get_private_data(const char *name, marker_probe_func *probe,
140+
int num);
128141

129142
#endif

‎include/linux/module.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ int unregister_module_notifier(struct notifier_block * nb);
465465

466466
extern void print_modules(void);
467467

468-
extern void module_update_markers(struct module *probe_module, int *refcount);
468+
extern void module_update_markers(void);
469469

470470
#else /* !CONFIG_MODULES... */
471471
#define EXPORT_SYMBOL(sym)

0 commit comments

Comments
 (0)