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