marker.h: change header #define macro name
[lttng-ust.git] / libust / marker.c
... / ...
CommitLineData
1/*
2 * Copyright (C) 2007 Mathieu Desnoyers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18//ust// #include <linux/module.h>
19//ust// #include <linux/mutex.h>
20//ust// #include <linux/types.h>
21//#include "jhash.h"
22//#include "list.h"
23//#include "rcupdate.h"
24//ust// #include <linux/marker.h>
25#include <errno.h>
26//ust// #include <linux/slab.h>
27//ust// #include <linux/immediate.h>
28//ust// #include <linux/sched.h>
29//ust// #include <linux/uaccess.h>
30//ust// #include <linux/user_marker.h>
31//ust// #include <linux/ltt-tracer.h>
32
33#define _LGPL_SOURCE
34#include <urcu-bp.h>
35
36#include <ust/kernelcompat.h>
37
38#include <ust/marker.h>
39#include "usterr.h"
40#include "channels.h"
41#include "tracercore.h"
42#include "tracer.h"
43
44__thread long ust_reg_stack[500];
45volatile __thread long *ust_reg_stack_ptr = (long *) 0;
46
47extern struct marker __start___markers[] __attribute__((visibility("hidden")));
48extern struct marker __stop___markers[] __attribute__((visibility("hidden")));
49extern struct marker_addr __start___marker_addr[] __attribute__((visibility("hidden")));
50extern struct marker_addr __stop___marker_addr[] __attribute__((visibility("hidden")));
51
52/* Set to 1 to enable marker debug output */
53static const int marker_debug;
54
55/*
56 * markers_mutex nests inside module_mutex. Markers mutex protects the builtin
57 * and module markers and the hash table.
58 */
59static DEFINE_MUTEX(markers_mutex);
60
61static LIST_HEAD(libs);
62
63
64void lock_markers(void)
65{
66 mutex_lock(&markers_mutex);
67}
68
69void unlock_markers(void)
70{
71 mutex_unlock(&markers_mutex);
72}
73
74/*
75 * Marker hash table, containing the active markers.
76 * Protected by module_mutex.
77 */
78#define MARKER_HASH_BITS 6
79#define MARKER_TABLE_SIZE (1 << MARKER_HASH_BITS)
80static struct hlist_head marker_table[MARKER_TABLE_SIZE];
81
82/*
83 * Note about RCU :
84 * It is used to make sure every handler has finished using its private data
85 * between two consecutive operation (add or remove) on a given marker. It is
86 * also used to delay the free of multiple probes array until a quiescent state
87 * is reached.
88 * marker entries modifications are protected by the markers_mutex.
89 */
90struct marker_entry {
91 struct hlist_node hlist;
92 char *format;
93 char *name;
94 /* Probe wrapper */
95 void (*call)(const struct marker *mdata, void *call_private, struct registers *regs, ...);
96 struct marker_probe_closure single;
97 struct marker_probe_closure *multi;
98 int refcount; /* Number of times armed. 0 if disarmed. */
99 struct rcu_head rcu;
100 void *oldptr;
101 int rcu_pending;
102 u16 channel_id;
103 u16 event_id;
104 unsigned char ptype:1;
105 unsigned char format_allocated:1;
106 char channel[0]; /* Contains channel'\0'name'\0'format'\0' */
107};
108
109#ifdef CONFIG_MARKERS_USERSPACE
110static void marker_update_processes(void);
111#else
112static void marker_update_processes(void)
113{
114}
115#endif
116
117/**
118 * __mark_empty_function - Empty probe callback
119 * @mdata: marker data
120 * @probe_private: probe private data
121 * @call_private: call site private data
122 * @fmt: format string
123 * @...: variable argument list
124 *
125 * Empty callback provided as a probe to the markers. By providing this to a
126 * disabled marker, we make sure the execution flow is always valid even
127 * though the function pointer change and the marker enabling are two distinct
128 * operations that modifies the execution flow of preemptible code.
129 */
130notrace void __mark_empty_function(const struct marker *mdata,
131 void *probe_private, struct registers *regs, void *call_private, const char *fmt, va_list *args)
132{
133}
134//ust// EXPORT_SYMBOL_GPL(__mark_empty_function);
135
136/*
137 * marker_probe_cb Callback that prepares the variable argument list for probes.
138 * @mdata: pointer of type struct marker
139 * @call_private: caller site private data
140 * @...: Variable argument list.
141 *
142 * Since we do not use "typical" pointer based RCU in the 1 argument case, we
143 * need to put a full smp_rmb() in this branch. This is why we do not use
144 * rcu_dereference() for the pointer read.
145 */
146notrace void marker_probe_cb(const struct marker *mdata,
147 void *call_private, struct registers *regs, ...)
148{
149 va_list args;
150 char ptype;
151
152 /*
153 * rcu_read_lock_sched does two things : disabling preemption to make
154 * sure the teardown of the callbacks can be done correctly when they
155 * are in modules and they insure RCU read coherency.
156 */
157//ust// rcu_read_lock_sched_notrace();
158 ptype = mdata->ptype;
159 if (likely(!ptype)) {
160 marker_probe_func *func;
161 /* Must read the ptype before ptr. They are not data dependant,
162 * so we put an explicit smp_rmb() here. */
163 smp_rmb();
164 func = mdata->single.func;
165 /* Must read the ptr before private data. They are not data
166 * dependant, so we put an explicit smp_rmb() here. */
167 smp_rmb();
168 va_start(args, regs);
169 func(mdata, mdata->single.probe_private, regs, call_private,
170 mdata->format, &args);
171 va_end(args);
172 } else {
173 struct marker_probe_closure *multi;
174 int i;
175 /*
176 * Read mdata->ptype before mdata->multi.
177 */
178 smp_rmb();
179 multi = mdata->multi;
180 /*
181 * multi points to an array, therefore accessing the array
182 * depends on reading multi. However, even in this case,
183 * we must insure that the pointer is read _before_ the array
184 * data. Same as rcu_dereference, but we need a full smp_rmb()
185 * in the fast path, so put the explicit barrier here.
186 */
187 smp_read_barrier_depends();
188 for (i = 0; multi[i].func; i++) {
189 va_start(args, regs);
190 multi[i].func(mdata, multi[i].probe_private,
191 regs, call_private, mdata->format, &args);
192 va_end(args);
193 }
194 }
195//ust// rcu_read_unlock_sched_notrace();
196}
197//ust// EXPORT_SYMBOL_GPL(marker_probe_cb);
198
199/*
200 * marker_probe_cb Callback that does not prepare the variable argument list.
201 * @mdata: pointer of type struct marker
202 * @call_private: caller site private data
203 * @...: Variable argument list.
204 *
205 * Should be connected to markers "MARK_NOARGS".
206 */
207static notrace void marker_probe_cb_noarg(const struct marker *mdata,
208 void *call_private, struct registers *regs, ...)
209{
210 va_list args; /* not initialized */
211 char ptype;
212
213//ust// rcu_read_lock_sched_notrace();
214 ptype = mdata->ptype;
215 if (likely(!ptype)) {
216 marker_probe_func *func;
217 /* Must read the ptype before ptr. They are not data dependant,
218 * so we put an explicit smp_rmb() here. */
219 smp_rmb();
220 func = mdata->single.func;
221 /* Must read the ptr before private data. They are not data
222 * dependant, so we put an explicit smp_rmb() here. */
223 smp_rmb();
224 func(mdata, mdata->single.probe_private, regs, call_private,
225 mdata->format, &args);
226 } else {
227 struct marker_probe_closure *multi;
228 int i;
229 /*
230 * Read mdata->ptype before mdata->multi.
231 */
232 smp_rmb();
233 multi = mdata->multi;
234 /*
235 * multi points to an array, therefore accessing the array
236 * depends on reading multi. However, even in this case,
237 * we must insure that the pointer is read _before_ the array
238 * data. Same as rcu_dereference, but we need a full smp_rmb()
239 * in the fast path, so put the explicit barrier here.
240 */
241 smp_read_barrier_depends();
242 for (i = 0; multi[i].func; i++)
243 multi[i].func(mdata, multi[i].probe_private, regs,
244 call_private, mdata->format, &args);
245 }
246//ust// rcu_read_unlock_sched_notrace();
247}
248
249static void free_old_closure(struct rcu_head *head)
250{
251 struct marker_entry *entry = container_of(head,
252 struct marker_entry, rcu);
253 kfree(entry->oldptr);
254 /* Make sure we free the data before setting the pending flag to 0 */
255 smp_wmb();
256 entry->rcu_pending = 0;
257}
258
259static void debug_print_probes(struct marker_entry *entry)
260{
261 int i;
262
263 if (!marker_debug)
264 return;
265
266 if (!entry->ptype) {
267 printk(KERN_DEBUG "Single probe : %p %p\n",
268 entry->single.func,
269 entry->single.probe_private);
270 } else {
271 for (i = 0; entry->multi[i].func; i++)
272 printk(KERN_DEBUG "Multi probe %d : %p %p\n", i,
273 entry->multi[i].func,
274 entry->multi[i].probe_private);
275 }
276}
277
278static struct marker_probe_closure *
279marker_entry_add_probe(struct marker_entry *entry,
280 marker_probe_func *probe, void *probe_private)
281{
282 int nr_probes = 0;
283 struct marker_probe_closure *old, *new;
284
285 WARN_ON(!probe);
286
287 debug_print_probes(entry);
288 old = entry->multi;
289 if (!entry->ptype) {
290 if (entry->single.func == probe &&
291 entry->single.probe_private == probe_private)
292 return ERR_PTR(-EBUSY);
293 if (entry->single.func == __mark_empty_function) {
294 /* 0 -> 1 probes */
295 entry->single.func = probe;
296 entry->single.probe_private = probe_private;
297 entry->refcount = 1;
298 entry->ptype = 0;
299 debug_print_probes(entry);
300 return NULL;
301 } else {
302 /* 1 -> 2 probes */
303 nr_probes = 1;
304 old = NULL;
305 }
306 } else {
307 /* (N -> N+1), (N != 0, 1) probes */
308 for (nr_probes = 0; old[nr_probes].func; nr_probes++)
309 if (old[nr_probes].func == probe
310 && old[nr_probes].probe_private
311 == probe_private)
312 return ERR_PTR(-EBUSY);
313 }
314 /* + 2 : one for new probe, one for NULL func */
315 new = kzalloc((nr_probes + 2) * sizeof(struct marker_probe_closure),
316 GFP_KERNEL);
317 if (new == NULL)
318 return ERR_PTR(-ENOMEM);
319 if (!old)
320 new[0] = entry->single;
321 else
322 memcpy(new, old,
323 nr_probes * sizeof(struct marker_probe_closure));
324 new[nr_probes].func = probe;
325 new[nr_probes].probe_private = probe_private;
326 entry->refcount = nr_probes + 1;
327 entry->multi = new;
328 entry->ptype = 1;
329 debug_print_probes(entry);
330 return old;
331}
332
333static struct marker_probe_closure *
334marker_entry_remove_probe(struct marker_entry *entry,
335 marker_probe_func *probe, void *probe_private)
336{
337 int nr_probes = 0, nr_del = 0, i;
338 struct marker_probe_closure *old, *new;
339
340 old = entry->multi;
341
342 debug_print_probes(entry);
343 if (!entry->ptype) {
344 /* 0 -> N is an error */
345 WARN_ON(entry->single.func == __mark_empty_function);
346 /* 1 -> 0 probes */
347 WARN_ON(probe && entry->single.func != probe);
348 WARN_ON(entry->single.probe_private != probe_private);
349 entry->single.func = __mark_empty_function;
350 entry->refcount = 0;
351 entry->ptype = 0;
352 debug_print_probes(entry);
353 return NULL;
354 } else {
355 /* (N -> M), (N > 1, M >= 0) probes */
356 for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
357 if ((!probe || old[nr_probes].func == probe)
358 && old[nr_probes].probe_private
359 == probe_private)
360 nr_del++;
361 }
362 }
363
364 if (nr_probes - nr_del == 0) {
365 /* N -> 0, (N > 1) */
366 entry->single.func = __mark_empty_function;
367 entry->refcount = 0;
368 entry->ptype = 0;
369 } else if (nr_probes - nr_del == 1) {
370 /* N -> 1, (N > 1) */
371 for (i = 0; old[i].func; i++)
372 if ((probe && old[i].func != probe) ||
373 old[i].probe_private != probe_private)
374 entry->single = old[i];
375 entry->refcount = 1;
376 entry->ptype = 0;
377 } else {
378 int j = 0;
379 /* N -> M, (N > 1, M > 1) */
380 /* + 1 for NULL */
381 new = kzalloc((nr_probes - nr_del + 1)
382 * sizeof(struct marker_probe_closure), GFP_KERNEL);
383 if (new == NULL)
384 return ERR_PTR(-ENOMEM);
385 for (i = 0; old[i].func; i++)
386 if ((probe && old[i].func != probe) ||
387 old[i].probe_private != probe_private)
388 new[j++] = old[i];
389 entry->refcount = nr_probes - nr_del;
390 entry->ptype = 1;
391 entry->multi = new;
392 }
393 debug_print_probes(entry);
394 return old;
395}
396
397/*
398 * Get marker if the marker is present in the marker hash table.
399 * Must be called with markers_mutex held.
400 * Returns NULL if not present.
401 */
402static struct marker_entry *get_marker(const char *channel, const char *name)
403{
404 struct hlist_head *head;
405 struct hlist_node *node;
406 struct marker_entry *e;
407 size_t channel_len = strlen(channel) + 1;
408 size_t name_len = strlen(name) + 1;
409 u32 hash;
410
411 hash = jhash(channel, channel_len-1, 0) ^ jhash(name, name_len-1, 0);
412 head = &marker_table[hash & ((1 << MARKER_HASH_BITS)-1)];
413 hlist_for_each_entry(e, node, head, hlist) {
414 if (!strcmp(channel, e->channel) && !strcmp(name, e->name))
415 return e;
416 }
417 return NULL;
418}
419
420/*
421 * Add the marker to the marker hash table. Must be called with markers_mutex
422 * held.
423 */
424static struct marker_entry *add_marker(const char *channel, const char *name,
425 const char *format)
426{
427 struct hlist_head *head;
428 struct hlist_node *node;
429 struct marker_entry *e;
430 size_t channel_len = strlen(channel) + 1;
431 size_t name_len = strlen(name) + 1;
432 size_t format_len = 0;
433 u32 hash;
434
435 hash = jhash(channel, channel_len-1, 0) ^ jhash(name, name_len-1, 0);
436 if (format)
437 format_len = strlen(format) + 1;
438 head = &marker_table[hash & ((1 << MARKER_HASH_BITS)-1)];
439 hlist_for_each_entry(e, node, head, hlist) {
440 if (!strcmp(channel, e->channel) && !strcmp(name, e->name)) {
441 printk(KERN_NOTICE
442 "Marker %s.%s busy\n", channel, name);
443 return ERR_PTR(-EBUSY); /* Already there */
444 }
445 }
446 /*
447 * Using kmalloc here to allocate a variable length element. Could
448 * cause some memory fragmentation if overused.
449 */
450 e = kmalloc(sizeof(struct marker_entry)
451 + channel_len + name_len + format_len,
452 GFP_KERNEL);
453 if (!e)
454 return ERR_PTR(-ENOMEM);
455 memcpy(e->channel, channel, channel_len);
456 e->name = &e->channel[channel_len];
457 memcpy(e->name, name, name_len);
458 if (format) {
459 e->format = &e->name[channel_len + name_len];
460 memcpy(e->format, format, format_len);
461 if (strcmp(e->format, MARK_NOARGS) == 0)
462 e->call = marker_probe_cb_noarg;
463 else
464 e->call = marker_probe_cb;
465 trace_mark(metadata, core_marker_format,
466 "channel %s name %s format %s",
467 e->channel, e->name, e->format);
468 } else {
469 e->format = NULL;
470 e->call = marker_probe_cb;
471 }
472 e->single.func = __mark_empty_function;
473 e->single.probe_private = NULL;
474 e->multi = NULL;
475 e->ptype = 0;
476 e->format_allocated = 0;
477 e->refcount = 0;
478 e->rcu_pending = 0;
479 hlist_add_head(&e->hlist, head);
480 return e;
481}
482
483/*
484 * Remove the marker from the marker hash table. Must be called with mutex_lock
485 * held.
486 */
487static int remove_marker(const char *channel, const char *name)
488{
489 struct hlist_head *head;
490 struct hlist_node *node;
491 struct marker_entry *e;
492 int found = 0;
493 size_t channel_len = strlen(channel) + 1;
494 size_t name_len = strlen(name) + 1;
495 u32 hash;
496 int ret;
497
498 hash = jhash(channel, channel_len-1, 0) ^ jhash(name, name_len-1, 0);
499 head = &marker_table[hash & ((1 << MARKER_HASH_BITS)-1)];
500 hlist_for_each_entry(e, node, head, hlist) {
501 if (!strcmp(channel, e->channel) && !strcmp(name, e->name)) {
502 found = 1;
503 break;
504 }
505 }
506 if (!found)
507 return -ENOENT;
508 if (e->single.func != __mark_empty_function)
509 return -EBUSY;
510 hlist_del(&e->hlist);
511 if (e->format_allocated)
512 kfree(e->format);
513 ret = ltt_channels_unregister(e->channel);
514 WARN_ON(ret);
515 /* Make sure the call_rcu has been executed */
516//ust// if (e->rcu_pending)
517//ust// rcu_barrier_sched();
518 kfree(e);
519 return 0;
520}
521
522/*
523 * Set the mark_entry format to the format found in the element.
524 */
525static int marker_set_format(struct marker_entry *entry, const char *format)
526{
527 entry->format = kstrdup(format, GFP_KERNEL);
528 if (!entry->format)
529 return -ENOMEM;
530 entry->format_allocated = 1;
531
532 trace_mark(metadata, core_marker_format,
533 "channel %s name %s format %s",
534 entry->channel, entry->name, entry->format);
535 return 0;
536}
537
538/*
539 * Sets the probe callback corresponding to one marker.
540 */
541static int set_marker(struct marker_entry *entry, struct marker *elem,
542 int active)
543{
544 int ret = 0;
545 WARN_ON(strcmp(entry->name, elem->name) != 0);
546
547 if (entry->format) {
548 if (strcmp(entry->format, elem->format) != 0) {
549 printk(KERN_NOTICE
550 "Format mismatch for probe %s "
551 "(%s), marker (%s)\n",
552 entry->name,
553 entry->format,
554 elem->format);
555 return -EPERM;
556 }
557 } else {
558 ret = marker_set_format(entry, elem->format);
559 if (ret)
560 return ret;
561 }
562
563 /*
564 * probe_cb setup (statically known) is done here. It is
565 * asynchronous with the rest of execution, therefore we only
566 * pass from a "safe" callback (with argument) to an "unsafe"
567 * callback (does not set arguments).
568 */
569 elem->call = entry->call;
570 elem->channel_id = entry->channel_id;
571 elem->event_id = entry->event_id;
572 /*
573 * Sanity check :
574 * We only update the single probe private data when the ptr is
575 * set to a _non_ single probe! (0 -> 1 and N -> 1, N != 1)
576 */
577 WARN_ON(elem->single.func != __mark_empty_function
578 && elem->single.probe_private != entry->single.probe_private
579 && !elem->ptype);
580 elem->single.probe_private = entry->single.probe_private;
581 /*
582 * Make sure the private data is valid when we update the
583 * single probe ptr.
584 */
585 smp_wmb();
586 elem->single.func = entry->single.func;
587 /*
588 * We also make sure that the new probe callbacks array is consistent
589 * before setting a pointer to it.
590 */
591 rcu_assign_pointer(elem->multi, entry->multi);
592 /*
593 * Update the function or multi probe array pointer before setting the
594 * ptype.
595 */
596 smp_wmb();
597 elem->ptype = entry->ptype;
598
599//ust// if (elem->tp_name && (active ^ _imv_read(elem->state))) {
600//ust// WARN_ON(!elem->tp_cb);
601//ust// /*
602//ust// * It is ok to directly call the probe registration because type
603//ust// * checking has been done in the __trace_mark_tp() macro.
604//ust// */
605//ust//
606//ust// if (active) {
607//ust// /*
608//ust// * try_module_get should always succeed because we hold
609//ust// * markers_mutex to get the tp_cb address.
610//ust// */
611//ust// ret = try_module_get(__module_text_address(
612//ust// (unsigned long)elem->tp_cb));
613//ust// BUG_ON(!ret);
614//ust// ret = tracepoint_probe_register_noupdate(
615//ust// elem->tp_name,
616//ust// elem->tp_cb);
617//ust// } else {
618//ust// ret = tracepoint_probe_unregister_noupdate(
619//ust// elem->tp_name,
620//ust// elem->tp_cb);
621//ust// /*
622//ust// * tracepoint_probe_update_all() must be called
623//ust// * before the module containing tp_cb is unloaded.
624//ust// */
625//ust// module_put(__module_text_address(
626//ust// (unsigned long)elem->tp_cb));
627//ust// }
628//ust// }
629 elem->state__imv = active;
630
631 return ret;
632}
633
634/*
635 * Disable a marker and its probe callback.
636 * Note: only waiting an RCU period after setting elem->call to the empty
637 * function insures that the original callback is not used anymore. This insured
638 * by rcu_read_lock_sched around the call site.
639 */
640static void disable_marker(struct marker *elem)
641{
642//ust// int ret;
643//ust//
644//ust// /* leave "call" as is. It is known statically. */
645//ust// if (elem->tp_name && _imv_read(elem->state)) {
646//ust// WARN_ON(!elem->tp_cb);
647//ust// /*
648//ust// * It is ok to directly call the probe registration because type
649//ust// * checking has been done in the __trace_mark_tp() macro.
650//ust// */
651//ust// ret = tracepoint_probe_unregister_noupdate(elem->tp_name,
652//ust// elem->tp_cb);
653//ust// WARN_ON(ret);
654//ust// /*
655//ust// * tracepoint_probe_update_all() must be called
656//ust// * before the module containing tp_cb is unloaded.
657//ust// */
658//ust// module_put(__module_text_address((unsigned long)elem->tp_cb));
659//ust// }
660 elem->state__imv = 0;
661 elem->single.func = __mark_empty_function;
662 /* Update the function before setting the ptype */
663 smp_wmb();
664 elem->ptype = 0; /* single probe */
665 /*
666 * Leave the private data and channel_id/event_id there, because removal
667 * is racy and should be done only after an RCU period. These are never
668 * used until the next initialization anyway.
669 */
670}
671
672/**
673 * marker_update_probe_range - Update a probe range
674 * @begin: beginning of the range
675 * @end: end of the range
676 *
677 * Updates the probe callback corresponding to a range of markers.
678 */
679void marker_update_probe_range(struct marker *begin,
680 struct marker *end)
681{
682 struct marker *iter;
683 struct marker_entry *mark_entry;
684
685 mutex_lock(&markers_mutex);
686 for (iter = begin; iter < end; iter++) {
687 mark_entry = get_marker(iter->channel, iter->name);
688 if (mark_entry) {
689 set_marker(mark_entry, iter, !!mark_entry->refcount);
690 /*
691 * ignore error, continue
692 */
693
694 /* This is added for UST. We emit a core_marker_id event
695 * for markers that are already registered to a probe
696 * upon library load. Otherwise, no core_marker_id will
697 * be generated for these markers. Is this the right thing
698 * to do?
699 */
700 trace_mark(metadata, core_marker_id,
701 "channel %s name %s event_id %hu "
702 "int #1u%zu long #1u%zu pointer #1u%zu "
703 "size_t #1u%zu alignment #1u%u",
704 iter->channel, iter->name, mark_entry->event_id,
705 sizeof(int), sizeof(long), sizeof(void *),
706 sizeof(size_t), ltt_get_alignment());
707 } else {
708 disable_marker(iter);
709 }
710 }
711 mutex_unlock(&markers_mutex);
712}
713
714static void lib_update_markers(void)
715{
716 struct lib *lib;
717
718 /* FIXME: we should probably take a mutex here on libs */
719//ust// mutex_lock(&module_mutex);
720 list_for_each_entry(lib, &libs, list)
721 marker_update_probe_range(lib->markers_start,
722 lib->markers_start + lib->markers_count);
723//ust// mutex_unlock(&module_mutex);
724}
725
726/*
727 * Update probes, removing the faulty probes.
728 *
729 * Internal callback only changed before the first probe is connected to it.
730 * Single probe private data can only be changed on 0 -> 1 and 2 -> 1
731 * transitions. All other transitions will leave the old private data valid.
732 * This makes the non-atomicity of the callback/private data updates valid.
733 *
734 * "special case" updates :
735 * 0 -> 1 callback
736 * 1 -> 0 callback
737 * 1 -> 2 callbacks
738 * 2 -> 1 callbacks
739 * Other updates all behave the same, just like the 2 -> 3 or 3 -> 2 updates.
740 * Site effect : marker_set_format may delete the marker entry (creating a
741 * replacement).
742 */
743static void marker_update_probes(void)
744{
745 /* Core kernel markers */
746//ust// marker_update_probe_range(__start___markers, __stop___markers);
747 /* Markers in modules. */
748//ust// module_update_markers();
749 lib_update_markers();
750//ust// tracepoint_probe_update_all();
751 /* Update immediate values */
752 core_imv_update();
753//ust// module_imv_update(); /* FIXME: need to port for libs? */
754 marker_update_processes();
755}
756
757/**
758 * marker_probe_register - Connect a probe to a marker
759 * @channel: marker channel
760 * @name: marker name
761 * @format: format string
762 * @probe: probe handler
763 * @probe_private: probe private data
764 *
765 * private data must be a valid allocated memory address, or NULL.
766 * Returns 0 if ok, error value on error.
767 * The probe address must at least be aligned on the architecture pointer size.
768 */
769int marker_probe_register(const char *channel, const char *name,
770 const char *format, marker_probe_func *probe,
771 void *probe_private)
772{
773 struct marker_entry *entry;
774 int ret = 0, ret_err;
775 struct marker_probe_closure *old;
776 int first_probe = 0;
777
778 mutex_lock(&markers_mutex);
779 entry = get_marker(channel, name);
780 if (!entry) {
781 first_probe = 1;
782 entry = add_marker(channel, name, format);
783 if (IS_ERR(entry))
784 ret = PTR_ERR(entry);
785 if (ret)
786 goto end;
787 ret = ltt_channels_register(channel);
788 if (ret)
789 goto error_remove_marker;
790 ret = ltt_channels_get_index_from_name(channel);
791 if (ret < 0)
792 goto error_unregister_channel;
793 entry->channel_id = ret;
794 ret = ltt_channels_get_event_id(channel, name);
795 if (ret < 0)
796 goto error_unregister_channel;
797 entry->event_id = ret;
798 ret = 0;
799 trace_mark(metadata, core_marker_id,
800 "channel %s name %s event_id %hu "
801 "int #1u%zu long #1u%zu pointer #1u%zu "
802 "size_t #1u%zu alignment #1u%u",
803 channel, name, entry->event_id,
804 sizeof(int), sizeof(long), sizeof(void *),
805 sizeof(size_t), ltt_get_alignment());
806 } else if (format) {
807 if (!entry->format)
808 ret = marker_set_format(entry, format);
809 else if (strcmp(entry->format, format))
810 ret = -EPERM;
811 if (ret)
812 goto end;
813 }
814
815 /*
816 * If we detect that a call_rcu is pending for this marker,
817 * make sure it's executed now.
818 */
819//ust// if (entry->rcu_pending)
820//ust// rcu_barrier_sched();
821 old = marker_entry_add_probe(entry, probe, probe_private);
822 if (IS_ERR(old)) {
823 ret = PTR_ERR(old);
824 if (first_probe)
825 goto error_unregister_channel;
826 else
827 goto end;
828 }
829 mutex_unlock(&markers_mutex);
830
831 /* Activate marker if necessary */
832 marker_update_probes();
833
834 mutex_lock(&markers_mutex);
835 entry = get_marker(channel, name);
836 if (!entry)
837 goto end;
838//ust// if (entry->rcu_pending)
839//ust// rcu_barrier_sched();
840 entry->oldptr = old;
841 entry->rcu_pending = 1;
842 /* write rcu_pending before calling the RCU callback */
843 smp_wmb();
844//ust// call_rcu_sched(&entry->rcu, free_old_closure);
845 synchronize_rcu(); free_old_closure(&entry->rcu);
846 goto end;
847
848error_unregister_channel:
849 ret_err = ltt_channels_unregister(channel);
850 WARN_ON(ret_err);
851error_remove_marker:
852 ret_err = remove_marker(channel, name);
853 WARN_ON(ret_err);
854end:
855 mutex_unlock(&markers_mutex);
856 return ret;
857}
858//ust// EXPORT_SYMBOL_GPL(marker_probe_register);
859
860/**
861 * marker_probe_unregister - Disconnect a probe from a marker
862 * @channel: marker channel
863 * @name: marker name
864 * @probe: probe function pointer
865 * @probe_private: probe private data
866 *
867 * Returns the private data given to marker_probe_register, or an ERR_PTR().
868 * We do not need to call a synchronize_sched to make sure the probes have
869 * finished running before doing a module unload, because the module unload
870 * itself uses stop_machine(), which insures that every preempt disabled section
871 * have finished.
872 */
873int marker_probe_unregister(const char *channel, const char *name,
874 marker_probe_func *probe, void *probe_private)
875{
876 struct marker_entry *entry;
877 struct marker_probe_closure *old;
878 int ret = -ENOENT;
879
880 mutex_lock(&markers_mutex);
881 entry = get_marker(channel, name);
882 if (!entry)
883 goto end;
884//ust// if (entry->rcu_pending)
885//ust// rcu_barrier_sched();
886 old = marker_entry_remove_probe(entry, probe, probe_private);
887 mutex_unlock(&markers_mutex);
888
889 marker_update_probes();
890
891 mutex_lock(&markers_mutex);
892 entry = get_marker(channel, name);
893 if (!entry)
894 goto end;
895//ust// if (entry->rcu_pending)
896//ust// rcu_barrier_sched();
897 entry->oldptr = old;
898 entry->rcu_pending = 1;
899 /* write rcu_pending before calling the RCU callback */
900 smp_wmb();
901//ust// call_rcu_sched(&entry->rcu, free_old_closure);
902 synchronize_rcu(); free_old_closure(&entry->rcu);
903 remove_marker(channel, name); /* Ignore busy error message */
904 ret = 0;
905end:
906 mutex_unlock(&markers_mutex);
907 return ret;
908}
909//ust// EXPORT_SYMBOL_GPL(marker_probe_unregister);
910
911static struct marker_entry *
912get_marker_from_private_data(marker_probe_func *probe, void *probe_private)
913{
914 struct marker_entry *entry;
915 unsigned int i;
916 struct hlist_head *head;
917 struct hlist_node *node;
918
919 for (i = 0; i < MARKER_TABLE_SIZE; i++) {
920 head = &marker_table[i];
921 hlist_for_each_entry(entry, node, head, hlist) {
922 if (!entry->ptype) {
923 if (entry->single.func == probe
924 && entry->single.probe_private
925 == probe_private)
926 return entry;
927 } else {
928 struct marker_probe_closure *closure;
929 closure = entry->multi;
930 for (i = 0; closure[i].func; i++) {
931 if (closure[i].func == probe &&
932 closure[i].probe_private
933 == probe_private)
934 return entry;
935 }
936 }
937 }
938 }
939 return NULL;
940}
941
942/**
943 * marker_probe_unregister_private_data - Disconnect a probe from a marker
944 * @probe: probe function
945 * @probe_private: probe private data
946 *
947 * Unregister a probe by providing the registered private data.
948 * Only removes the first marker found in hash table.
949 * Return 0 on success or error value.
950 * We do not need to call a synchronize_sched to make sure the probes have
951 * finished running before doing a module unload, because the module unload
952 * itself uses stop_machine(), which insures that every preempt disabled section
953 * have finished.
954 */
955int marker_probe_unregister_private_data(marker_probe_func *probe,
956 void *probe_private)
957{
958 struct marker_entry *entry;
959 int ret = 0;
960 struct marker_probe_closure *old;
961 const char *channel = NULL, *name = NULL;
962
963 mutex_lock(&markers_mutex);
964 entry = get_marker_from_private_data(probe, probe_private);
965 if (!entry) {
966 ret = -ENOENT;
967 goto end;
968 }
969//ust// if (entry->rcu_pending)
970//ust// rcu_barrier_sched();
971 old = marker_entry_remove_probe(entry, NULL, probe_private);
972 channel = kstrdup(entry->channel, GFP_KERNEL);
973 name = kstrdup(entry->name, GFP_KERNEL);
974 mutex_unlock(&markers_mutex);
975
976 marker_update_probes();
977
978 mutex_lock(&markers_mutex);
979 entry = get_marker(channel, name);
980 if (!entry)
981 goto end;
982//ust// if (entry->rcu_pending)
983//ust// rcu_barrier_sched();
984 entry->oldptr = old;
985 entry->rcu_pending = 1;
986 /* write rcu_pending before calling the RCU callback */
987 smp_wmb();
988//ust// call_rcu_sched(&entry->rcu, free_old_closure);
989 synchronize_rcu(); free_old_closure(&entry->rcu);
990 /* Ignore busy error message */
991 remove_marker(channel, name);
992end:
993 mutex_unlock(&markers_mutex);
994 kfree(channel);
995 kfree(name);
996 return ret;
997}
998//ust// EXPORT_SYMBOL_GPL(marker_probe_unregister_private_data);
999
1000/**
1001 * marker_get_private_data - Get a marker's probe private data
1002 * @channel: marker channel
1003 * @name: marker name
1004 * @probe: probe to match
1005 * @num: get the nth matching probe's private data
1006 *
1007 * Returns the nth private data pointer (starting from 0) matching, or an
1008 * ERR_PTR.
1009 * Returns the private data pointer, or an ERR_PTR.
1010 * The private data pointer should _only_ be dereferenced if the caller is the
1011 * owner of the data, or its content could vanish. This is mostly used to
1012 * confirm that a caller is the owner of a registered probe.
1013 */
1014void *marker_get_private_data(const char *channel, const char *name,
1015 marker_probe_func *probe, int num)
1016{
1017 struct hlist_head *head;
1018 struct hlist_node *node;
1019 struct marker_entry *e;
1020 size_t channel_len = strlen(channel) + 1;
1021 size_t name_len = strlen(name) + 1;
1022 int i;
1023 u32 hash;
1024
1025 hash = jhash(channel, channel_len-1, 0) ^ jhash(name, name_len-1, 0);
1026 head = &marker_table[hash & ((1 << MARKER_HASH_BITS)-1)];
1027 hlist_for_each_entry(e, node, head, hlist) {
1028 if (!strcmp(channel, e->channel) && !strcmp(name, e->name)) {
1029 if (!e->ptype) {
1030 if (num == 0 && e->single.func == probe)
1031 return e->single.probe_private;
1032 } else {
1033 struct marker_probe_closure *closure;
1034 int match = 0;
1035 closure = e->multi;
1036 for (i = 0; closure[i].func; i++) {
1037 if (closure[i].func != probe)
1038 continue;
1039 if (match++ == num)
1040 return closure[i].probe_private;
1041 }
1042 }
1043 break;
1044 }
1045 }
1046 return ERR_PTR(-ENOENT);
1047}
1048//ust// EXPORT_SYMBOL_GPL(marker_get_private_data);
1049
1050/**
1051 * markers_compact_event_ids - Compact markers event IDs and reassign channels
1052 *
1053 * Called when no channel users are active by the channel infrastructure.
1054 * Called with lock_markers() and channel mutex held.
1055 */
1056//ust// void markers_compact_event_ids(void)
1057//ust// {
1058//ust// struct marker_entry *entry;
1059//ust// unsigned int i;
1060//ust// struct hlist_head *head;
1061//ust// struct hlist_node *node;
1062//ust// int ret;
1063//ust//
1064//ust// for (i = 0; i < MARKER_TABLE_SIZE; i++) {
1065//ust// head = &marker_table[i];
1066//ust// hlist_for_each_entry(entry, node, head, hlist) {
1067//ust// ret = ltt_channels_get_index_from_name(entry->channel);
1068//ust// WARN_ON(ret < 0);
1069//ust// entry->channel_id = ret;
1070//ust// ret = _ltt_channels_get_event_id(entry->channel,
1071//ust// entry->name);
1072//ust// WARN_ON(ret < 0);
1073//ust// entry->event_id = ret;
1074//ust// }
1075//ust// }
1076//ust// }
1077
1078//ust//#ifdef CONFIG_MODULES
1079
1080/*
1081 * Returns 0 if current not found.
1082 * Returns 1 if current found.
1083 */
1084int lib_get_iter_markers(struct marker_iter *iter)
1085{
1086 struct lib *iter_lib;
1087 int found = 0;
1088
1089//ust// mutex_lock(&module_mutex);
1090 list_for_each_entry(iter_lib, &libs, list) {
1091 if (iter_lib < iter->lib)
1092 continue;
1093 else if (iter_lib > iter->lib)
1094 iter->marker = NULL;
1095 found = marker_get_iter_range(&iter->marker,
1096 iter_lib->markers_start,
1097 iter_lib->markers_start + iter_lib->markers_count);
1098 if (found) {
1099 iter->lib = iter_lib;
1100 break;
1101 }
1102 }
1103//ust// mutex_unlock(&module_mutex);
1104 return found;
1105}
1106
1107/**
1108 * marker_get_iter_range - Get a next marker iterator given a range.
1109 * @marker: current markers (in), next marker (out)
1110 * @begin: beginning of the range
1111 * @end: end of the range
1112 *
1113 * Returns whether a next marker has been found (1) or not (0).
1114 * Will return the first marker in the range if the input marker is NULL.
1115 */
1116int marker_get_iter_range(struct marker **marker, struct marker *begin,
1117 struct marker *end)
1118{
1119 if (!*marker && begin != end) {
1120 *marker = begin;
1121 return 1;
1122 }
1123 if (*marker >= begin && *marker < end)
1124 return 1;
1125 return 0;
1126}
1127//ust// EXPORT_SYMBOL_GPL(marker_get_iter_range);
1128
1129static void marker_get_iter(struct marker_iter *iter)
1130{
1131 int found = 0;
1132
1133 /* Core kernel markers */
1134 if (!iter->lib) {
1135 /* ust FIXME: how come we cannot disable the following line? we shouldn't need core stuff */
1136 found = marker_get_iter_range(&iter->marker,
1137 __start___markers, __stop___markers);
1138 if (found)
1139 goto end;
1140 }
1141 /* Markers in modules. */
1142 found = lib_get_iter_markers(iter);
1143end:
1144 if (!found)
1145 marker_iter_reset(iter);
1146}
1147
1148void marker_iter_start(struct marker_iter *iter)
1149{
1150 marker_get_iter(iter);
1151}
1152//ust// EXPORT_SYMBOL_GPL(marker_iter_start);
1153
1154void marker_iter_next(struct marker_iter *iter)
1155{
1156 iter->marker++;
1157 /*
1158 * iter->marker may be invalid because we blindly incremented it.
1159 * Make sure it is valid by marshalling on the markers, getting the
1160 * markers from following modules if necessary.
1161 */
1162 marker_get_iter(iter);
1163}
1164//ust// EXPORT_SYMBOL_GPL(marker_iter_next);
1165
1166void marker_iter_stop(struct marker_iter *iter)
1167{
1168}
1169//ust// EXPORT_SYMBOL_GPL(marker_iter_stop);
1170
1171void marker_iter_reset(struct marker_iter *iter)
1172{
1173 iter->lib = NULL;
1174 iter->marker = NULL;
1175}
1176//ust// EXPORT_SYMBOL_GPL(marker_iter_reset);
1177
1178#ifdef CONFIG_MARKERS_USERSPACE
1179/*
1180 * must be called with current->user_markers_mutex held
1181 */
1182static void free_user_marker(char __user *state, struct hlist_head *head)
1183{
1184 struct user_marker *umark;
1185 struct hlist_node *pos, *n;
1186
1187 hlist_for_each_entry_safe(umark, pos, n, head, hlist) {
1188 if (umark->state == state) {
1189 hlist_del(&umark->hlist);
1190 kfree(umark);
1191 }
1192 }
1193}
1194
1195//ust// asmlinkage long sys_marker(char __user *name, char __user *format,
1196//ust// char __user *state, int reg)
1197//ust// {
1198//ust// struct user_marker *umark;
1199//ust// long len;
1200//ust// struct marker_entry *entry;
1201//ust// int ret = 0;
1202//ust//
1203//ust// printk(KERN_DEBUG "Program %s %s marker [%p, %p]\n",
1204//ust// current->comm, reg ? "registers" : "unregisters",
1205//ust// name, state);
1206//ust// if (reg) {
1207//ust// umark = kmalloc(sizeof(struct user_marker), GFP_KERNEL);
1208//ust// umark->name[MAX_USER_MARKER_NAME_LEN - 1] = '\0';
1209//ust// umark->format[MAX_USER_MARKER_FORMAT_LEN - 1] = '\0';
1210//ust// umark->state = state;
1211//ust// len = strncpy_from_user(umark->name, name,
1212//ust// MAX_USER_MARKER_NAME_LEN - 1);
1213//ust// if (len < 0) {
1214//ust// ret = -EFAULT;
1215//ust// goto error;
1216//ust// }
1217//ust// len = strncpy_from_user(umark->format, format,
1218//ust// MAX_USER_MARKER_FORMAT_LEN - 1);
1219//ust// if (len < 0) {
1220//ust// ret = -EFAULT;
1221//ust// goto error;
1222//ust// }
1223//ust// printk(KERN_DEBUG "Marker name : %s, format : %s", umark->name,
1224//ust// umark->format);
1225//ust// mutex_lock(&markers_mutex);
1226//ust// entry = get_marker("userspace", umark->name);
1227//ust// if (entry) {
1228//ust// if (entry->format &&
1229//ust// strcmp(entry->format, umark->format) != 0) {
1230//ust// printk(" error, wrong format in process %s",
1231//ust// current->comm);
1232//ust// ret = -EPERM;
1233//ust// goto error_unlock;
1234//ust// }
1235//ust// printk(" %s", !!entry->refcount
1236//ust// ? "enabled" : "disabled");
1237//ust// if (put_user(!!entry->refcount, state)) {
1238//ust// ret = -EFAULT;
1239//ust// goto error_unlock;
1240//ust// }
1241//ust// printk("\n");
1242//ust// } else {
1243//ust// printk(" disabled\n");
1244//ust// if (put_user(0, umark->state)) {
1245//ust// printk(KERN_WARNING
1246//ust// "Marker in %s caused a fault\n",
1247//ust// current->comm);
1248//ust// goto error_unlock;
1249//ust// }
1250//ust// }
1251//ust// mutex_lock(&current->group_leader->user_markers_mutex);
1252//ust// hlist_add_head(&umark->hlist,
1253//ust// &current->group_leader->user_markers);
1254//ust// current->group_leader->user_markers_sequence++;
1255//ust// mutex_unlock(&current->group_leader->user_markers_mutex);
1256//ust// mutex_unlock(&markers_mutex);
1257//ust// } else {
1258//ust// mutex_lock(&current->group_leader->user_markers_mutex);
1259//ust// free_user_marker(state,
1260//ust// &current->group_leader->user_markers);
1261//ust// current->group_leader->user_markers_sequence++;
1262//ust// mutex_unlock(&current->group_leader->user_markers_mutex);
1263//ust// }
1264//ust// goto end;
1265//ust// error_unlock:
1266//ust// mutex_unlock(&markers_mutex);
1267//ust// error:
1268//ust// kfree(umark);
1269//ust// end:
1270//ust// return ret;
1271//ust// }
1272//ust//
1273//ust// /*
1274//ust// * Types :
1275//ust// * string : 0
1276//ust// */
1277//ust// asmlinkage long sys_trace(int type, uint16_t id,
1278//ust// char __user *ubuf)
1279//ust// {
1280//ust// long ret = -EPERM;
1281//ust// char *page;
1282//ust// int len;
1283//ust//
1284//ust// switch (type) {
1285//ust// case 0: /* String */
1286//ust// ret = -ENOMEM;
1287//ust// page = (char *)__get_free_page(GFP_TEMPORARY);
1288//ust// if (!page)
1289//ust// goto string_out;
1290//ust// len = strncpy_from_user(page, ubuf, PAGE_SIZE);
1291//ust// if (len < 0) {
1292//ust// ret = -EFAULT;
1293//ust// goto string_err;
1294//ust// }
1295//ust// trace_mark(userspace, string, "string %s", page);
1296//ust// string_err:
1297//ust// free_page((unsigned long) page);
1298//ust// string_out:
1299//ust// break;
1300//ust// default:
1301//ust// break;
1302//ust// }
1303//ust// return ret;
1304//ust// }
1305
1306//ust// static void marker_update_processes(void)
1307//ust// {
1308//ust// struct task_struct *g, *t;
1309//ust//
1310//ust// /*
1311//ust// * markers_mutex is taken to protect the p->user_markers read.
1312//ust// */
1313//ust// mutex_lock(&markers_mutex);
1314//ust// read_lock(&tasklist_lock);
1315//ust// for_each_process(g) {
1316//ust// WARN_ON(!thread_group_leader(g));
1317//ust// if (hlist_empty(&g->user_markers))
1318//ust// continue;
1319//ust// if (strcmp(g->comm, "testprog") == 0)
1320//ust// printk(KERN_DEBUG "set update pending for testprog\n");
1321//ust// t = g;
1322//ust// do {
1323//ust// /* TODO : implement this thread flag in each arch. */
1324//ust// set_tsk_thread_flag(t, TIF_MARKER_PENDING);
1325//ust// } while ((t = next_thread(t)) != g);
1326//ust// }
1327//ust// read_unlock(&tasklist_lock);
1328//ust// mutex_unlock(&markers_mutex);
1329//ust// }
1330
1331/*
1332 * Update current process.
1333 * Note that we have to wait a whole scheduler period before we are sure that
1334 * every running userspace threads have their markers updated.
1335 * (synchronize_sched() can be used to insure this).
1336 */
1337void marker_update_process(void)
1338{
1339 struct user_marker *umark;
1340 struct hlist_node *pos;
1341 struct marker_entry *entry;
1342
1343 mutex_lock(&markers_mutex);
1344 mutex_lock(&current->group_leader->user_markers_mutex);
1345 if (strcmp(current->comm, "testprog") == 0)
1346 printk(KERN_DEBUG "do update pending for testprog\n");
1347 hlist_for_each_entry(umark, pos,
1348 &current->group_leader->user_markers, hlist) {
1349 printk(KERN_DEBUG "Updating marker %s in %s\n",
1350 umark->name, current->comm);
1351 entry = get_marker("userspace", umark->name);
1352 if (entry) {
1353 if (entry->format &&
1354 strcmp(entry->format, umark->format) != 0) {
1355 printk(KERN_WARNING
1356 " error, wrong format in process %s\n",
1357 current->comm);
1358 break;
1359 }
1360 if (put_user(!!entry->refcount, umark->state)) {
1361 printk(KERN_WARNING
1362 "Marker in %s caused a fault\n",
1363 current->comm);
1364 break;
1365 }
1366 } else {
1367 if (put_user(0, umark->state)) {
1368 printk(KERN_WARNING
1369 "Marker in %s caused a fault\n",
1370 current->comm);
1371 break;
1372 }
1373 }
1374 }
1375 clear_thread_flag(TIF_MARKER_PENDING);
1376 mutex_unlock(&current->group_leader->user_markers_mutex);
1377 mutex_unlock(&markers_mutex);
1378}
1379
1380/*
1381 * Called at process exit and upon do_execve().
1382 * We assume that when the leader exits, no more references can be done to the
1383 * leader structure by the other threads.
1384 */
1385void exit_user_markers(struct task_struct *p)
1386{
1387 struct user_marker *umark;
1388 struct hlist_node *pos, *n;
1389
1390 if (thread_group_leader(p)) {
1391 mutex_lock(&markers_mutex);
1392 mutex_lock(&p->user_markers_mutex);
1393 hlist_for_each_entry_safe(umark, pos, n, &p->user_markers,
1394 hlist)
1395 kfree(umark);
1396 INIT_HLIST_HEAD(&p->user_markers);
1397 p->user_markers_sequence++;
1398 mutex_unlock(&p->user_markers_mutex);
1399 mutex_unlock(&markers_mutex);
1400 }
1401}
1402
1403int is_marker_enabled(const char *channel, const char *name)
1404{
1405 struct marker_entry *entry;
1406
1407 mutex_lock(&markers_mutex);
1408 entry = get_marker(channel, name);
1409 mutex_unlock(&markers_mutex);
1410
1411 return entry && !!entry->refcount;
1412}
1413//ust// #endif
1414
1415int marker_module_notify(struct notifier_block *self,
1416 unsigned long val, void *data)
1417{
1418 struct module *mod = data;
1419
1420 switch (val) {
1421 case MODULE_STATE_COMING:
1422 marker_update_probe_range(mod->markers,
1423 mod->markers + mod->num_markers);
1424 break;
1425 case MODULE_STATE_GOING:
1426 marker_update_probe_range(mod->markers,
1427 mod->markers + mod->num_markers);
1428 break;
1429 }
1430 return 0;
1431}
1432
1433struct notifier_block marker_module_nb = {
1434 .notifier_call = marker_module_notify,
1435 .priority = 0,
1436};
1437
1438//ust// static int init_markers(void)
1439//ust// {
1440//ust// return register_module_notifier(&marker_module_nb);
1441//ust// }
1442//ust// __initcall(init_markers);
1443/* TODO: call marker_module_nb() when a library is linked at runtime (dlopen)? */
1444
1445#endif /* CONFIG_MODULES */
1446
1447void ltt_dump_marker_state(struct ltt_trace_struct *trace)
1448{
1449 struct marker_entry *entry;
1450 struct ltt_probe_private_data call_data;
1451 struct hlist_head *head;
1452 struct hlist_node *node;
1453 unsigned int i;
1454
1455 mutex_lock(&markers_mutex);
1456 call_data.trace = trace;
1457 call_data.serializer = NULL;
1458
1459 for (i = 0; i < MARKER_TABLE_SIZE; i++) {
1460 head = &marker_table[i];
1461 hlist_for_each_entry(entry, node, head, hlist) {
1462 __trace_mark(0, metadata, core_marker_id,
1463 &call_data,
1464 "channel %s name %s event_id %hu "
1465 "int #1u%zu long #1u%zu pointer #1u%zu "
1466 "size_t #1u%zu alignment #1u%u",
1467 entry->channel,
1468 entry->name,
1469 entry->event_id,
1470 sizeof(int), sizeof(long),
1471 sizeof(void *), sizeof(size_t),
1472 ltt_get_alignment());
1473 if (entry->format)
1474 __trace_mark(0, metadata,
1475 core_marker_format,
1476 &call_data,
1477 "channel %s name %s format %s",
1478 entry->channel,
1479 entry->name,
1480 entry->format);
1481 }
1482 }
1483 mutex_unlock(&markers_mutex);
1484}
1485//ust// EXPORT_SYMBOL_GPL(ltt_dump_marker_state);
1486
1487static void (*new_marker_cb)(struct marker *) = NULL;
1488
1489void marker_set_new_marker_cb(void (*cb)(struct marker *))
1490{
1491 new_marker_cb = cb;
1492}
1493
1494static void new_markers(struct marker *start, struct marker *end)
1495{
1496 if(new_marker_cb) {
1497 struct marker *m;
1498 for(m=start; m < end; m++) {
1499 new_marker_cb(m);
1500 }
1501 }
1502}
1503
1504int marker_register_lib(struct marker *markers_start, struct marker_addr *marker_addr_start, int markers_count)
1505{
1506 struct lib *pl;
1507 struct marker_addr *addr;
1508
1509 pl = (struct lib *) malloc(sizeof(struct lib));
1510
1511 pl->markers_start = markers_start;
1512 pl->markers_addr_start = marker_addr_start;
1513 pl->markers_count = markers_count;
1514
1515 lock_markers();
1516 for(addr = marker_addr_start; addr < marker_addr_start + markers_count; addr++)
1517 addr->marker->location = addr->addr;
1518 unlock_markers();
1519
1520 /* FIXME: maybe protect this with its own mutex? */
1521 lock_markers();
1522 list_add(&pl->list, &libs);
1523 unlock_markers();
1524
1525 new_markers(markers_start, markers_start + markers_count);
1526
1527 /* FIXME: update just the loaded lib */
1528 lib_update_markers();
1529
1530 DBG("just registered a markers section from %p and having %d markers", markers_start, markers_count);
1531
1532 return 0;
1533}
1534
1535int marker_unregister_lib(struct marker *markers_start, int markers_count)
1536{
1537 /*FIXME: implement; but before implementing, marker_register_lib must
1538 have appropriate locking. */
1539
1540 return 0;
1541}
1542
1543static int initialized = 0;
1544
1545void __attribute__((constructor)) init_markers(void)
1546{
1547 if(!initialized) {
1548 marker_register_lib(__start___markers, __start___marker_addr, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));
1549 //DBG("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers);
1550 initialized = 1;
1551 }
1552}
This page took 0.027881 seconds and 4 git commands to generate.