X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=libmarkers%2Fmarker.c;h=ab0fc775adc422ba651a06e4430cfae1d589e19d;hb=474d745fffdcb195beae194471c63947aa03249a;hp=f9f82fb0f90dce294113e5dea3e0f1ee6d0cdb55;hpb=b6bf28ecd4c07e7865d340f1600a35d6edc05ec8;p=ust.git diff --git a/libmarkers/marker.c b/libmarkers/marker.c index f9f82fb..ab0fc77 100644 --- a/libmarkers/marker.c +++ b/libmarkers/marker.c @@ -35,9 +35,10 @@ #include "usterr.h" #include "channels.h" #include "tracercore.h" +#include "tracer.h" -extern struct marker __start___markers[]; -extern struct marker __stop___markers[]; +extern struct marker __start___markers[] __attribute__((visibility("hidden"))); +extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); /* Set to 1 to enable marker debug output */ static const int marker_debug; @@ -677,6 +678,20 @@ void marker_update_probe_range(struct marker *begin, /* * ignore error, continue */ + + /* This is added for UST. We emit a core_marker_id event + * for markers that are already registered to a probe + * upon library load. Otherwise, no core_marker_id will + * be generated for these markers. Is this the right thing + * to do? + */ + trace_mark(metadata, core_marker_id, + "channel %s name %s event_id %hu " + "int #1u%zu long #1u%zu pointer #1u%zu " + "size_t #1u%zu alignment #1u%u", + iter->channel, iter->name, mark_entry->event_id, + sizeof(int), sizeof(long), sizeof(void *), + sizeof(size_t), ltt_get_alignment()); } else { disable_marker(iter); } @@ -704,13 +719,14 @@ void marker_update_probe_range(struct marker *begin, static void marker_update_probes(void) { /* Core kernel markers */ - marker_update_probe_range(__start___markers, __stop___markers); +//ust// marker_update_probe_range(__start___markers, __stop___markers); /* Markers in modules. */ //ust// module_update_markers(); + lib_update_markers(); //ust// tracepoint_probe_update_all(); /* Update immediate values */ core_imv_update(); -//ust// module_imv_update(); +//ust// module_imv_update(); /* FIXME: need to port for libs? */ marker_update_processes(); } @@ -801,6 +817,7 @@ int marker_probe_register(const char *channel, const char *name, /* write rcu_pending before calling the RCU callback */ smp_wmb(); call_rcu_sched(&entry->rcu, free_old_closure); + /*synchronize_rcu(); free_old_closure();*/ goto end; error_unregister_channel: @@ -1031,7 +1048,7 @@ void *marker_get_private_data(const char *channel, const char *name, //ust// } //ust// } -#ifdef CONFIG_MODULES +//ust//#ifdef CONFIG_MODULES /** * marker_get_iter_range - Get a next marker iterator given a range. @@ -1060,14 +1077,15 @@ static void marker_get_iter(struct marker_iter *iter) int found = 0; /* Core kernel markers */ - if (!iter->module) { + if (!iter->lib) { + /* ust FIXME: how come we cannot disable the following line? we shouldn't need core stuff */ found = marker_get_iter_range(&iter->marker, __start___markers, __stop___markers); if (found) goto end; } /* Markers in modules. */ - found = module_get_iter_markers(iter); + found = lib_get_iter_markers(iter); end: if (!found) marker_iter_reset(iter); @@ -1098,7 +1116,7 @@ void marker_iter_stop(struct marker_iter *iter) void marker_iter_reset(struct marker_iter *iter) { - iter->module = NULL; + iter->lib = NULL; iter->marker = NULL; } //ust// EXPORT_SYMBOL_GPL(marker_iter_reset); @@ -1338,7 +1356,7 @@ int is_marker_enabled(const char *channel, const char *name) return entry && !!entry->refcount; } -#endif +//ust// #endif int marker_module_notify(struct notifier_block *self, unsigned long val, void *data) @@ -1372,42 +1390,143 @@ struct notifier_block marker_module_nb = { #endif /* CONFIG_MODULES */ -//ust// void ltt_dump_marker_state(struct ltt_trace_struct *trace) -//ust// { -//ust// struct marker_iter iter; -//ust// struct ltt_probe_private_data call_data; -//ust// const char *channel; -//ust// -//ust// call_data.trace = trace; -//ust// call_data.serializer = NULL; -//ust// -//ust// marker_iter_reset(&iter); -//ust// marker_iter_start(&iter); -//ust// for (; iter.marker != NULL; marker_iter_next(&iter)) { -//ust// if (!_imv_read(iter.marker->state)) -//ust// continue; -//ust// channel = ltt_channels_get_name_from_index( -//ust// iter.marker->channel_id); -//ust// __trace_mark(0, metadata, core_marker_id, -//ust// &call_data, -//ust// "channel %s name %s event_id %hu " -//ust// "int #1u%zu long #1u%zu pointer #1u%zu " -//ust// "size_t #1u%zu alignment #1u%u", -//ust// channel, -//ust// iter.marker->name, -//ust// iter.marker->event_id, -//ust// sizeof(int), sizeof(long), -//ust// sizeof(void *), sizeof(size_t), -//ust// ltt_get_alignment()); -//ust// if (iter.marker->format) -//ust// __trace_mark(0, metadata, -//ust// core_marker_format, -//ust// &call_data, -//ust// "channel %s name %s format %s", -//ust// channel, -//ust// iter.marker->name, -//ust// iter.marker->format); -//ust// } -//ust// marker_iter_stop(&iter); -//ust// } +void ltt_dump_marker_state(struct ltt_trace_struct *trace) +{ + struct marker_iter iter; + struct ltt_probe_private_data call_data; + const char *channel; + + call_data.trace = trace; + call_data.serializer = NULL; + + marker_iter_reset(&iter); + marker_iter_start(&iter); + for (; iter.marker != NULL; marker_iter_next(&iter)) { + if (!_imv_read(iter.marker->state)) + continue; + channel = ltt_channels_get_name_from_index( + iter.marker->channel_id); + __trace_mark(0, metadata, core_marker_id, + &call_data, + "channel %s name %s event_id %hu " + "int #1u%zu long #1u%zu pointer #1u%zu " + "size_t #1u%zu alignment #1u%u", + channel, + iter.marker->name, + iter.marker->event_id, + sizeof(int), sizeof(long), + sizeof(void *), sizeof(size_t), + ltt_get_alignment()); + if (iter.marker->format) + __trace_mark(0, metadata, + core_marker_format, + &call_data, + "channel %s name %s format %s", + channel, + iter.marker->name, + iter.marker->format); + } + marker_iter_stop(&iter); +} //ust// EXPORT_SYMBOL_GPL(ltt_dump_marker_state); + + +static LIST_HEAD(libs); + +/* + * Returns 0 if current not found. + * Returns 1 if current found. + */ +int lib_get_iter_markers(struct marker_iter *iter) +{ + struct lib *iter_lib; + int found = 0; + +//ust// mutex_lock(&module_mutex); + list_for_each_entry(iter_lib, &libs, list) { + if (iter_lib < iter->lib) + continue; + else if (iter_lib > iter->lib) + iter->marker = NULL; + found = marker_get_iter_range(&iter->marker, + iter_lib->markers_start, + iter_lib->markers_start + iter_lib->markers_count); + if (found) { + iter->lib = iter_lib; + break; + } + } +//ust// mutex_unlock(&module_mutex); + return found; +} + +void lib_update_markers(void) +{ + struct lib *lib; + +//ust// mutex_lock(&module_mutex); + list_for_each_entry(lib, &libs, list) + marker_update_probe_range(lib->markers_start, + lib->markers_start + lib->markers_count); +//ust// mutex_unlock(&module_mutex); +} + +static void (*new_marker_cb)(struct marker *) = NULL; + +void marker_set_new_marker_cb(void (*cb)(struct marker *)) +{ + new_marker_cb = cb; +} + +static void new_markers(struct marker *start, struct marker *end) +{ + if(new_marker_cb) { + struct marker *m; + for(m=start; m < end; m++) { + new_marker_cb(m); + } + } +} + +int marker_register_lib(struct marker *markers_start, int markers_count) +{ + struct lib *pl; + + pl = (struct lib *) malloc(sizeof(struct lib)); + + pl->markers_start = markers_start; + pl->markers_count = markers_count; + + /* FIXME: maybe protect this with its own mutex? */ + lock_markers(); + list_add(&pl->list, &libs); + unlock_markers(); + + new_markers(markers_start, markers_start + markers_count); + + /* FIXME: update just the loaded lib */ + lib_update_markers(); + + DBG("just registered a markers section from %p and having %d markers", markers_start, markers_count); + + return 0; +} + +int marker_unregister_lib(struct marker *markers_start, int markers_count) +{ + /*FIXME: implement; but before implementing, marker_register_lib must + have appropriate locking. */ + + return 0; +} + +static int initialized = 0; + +void __attribute__((constructor)) init_markers(void) +{ + if(!initialized) { + marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); + printf("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers); + initialized = 1; + } +}