#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;
/*
* 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);
}
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// }
//ust// }
-#ifdef CONFIG_MODULES
+//ust//#ifdef CONFIG_MODULES
/**
* marker_get_iter_range - Get a next marker iterator given a range.
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);
void marker_iter_reset(struct marker_iter *iter)
{
- iter->module = NULL;
+ iter->lib = NULL;
iter->marker = NULL;
}
//ust// EXPORT_SYMBOL_GPL(marker_iter_reset);
return entry && !!entry->refcount;
}
-#endif
+//ust// #endif
int marker_module_notify(struct notifier_block *self,
unsigned long val, void *data)
#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);
+}
+
+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;
+
+ list_add(&pl->list, &libs);
+
+ /* FIXME: update just the loaded lib */
+ lib_update_markers();
+
+ printf("just registered a markers section from %p and having %d markers\n", markers_start, markers_count);
+
+ 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;
+ }
+}