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