From: Mathieu Desnoyers Date: Mon, 30 Jan 2012 15:30:05 +0000 (-0500) Subject: clock: read bootid as clock monotonic ID X-Git-Tag: v2.0-pre12~7 X-Git-Url: http://git.lttng.org/?p=lttng-modules.git;a=commitdiff_plain;h=a82c63f10514ca43282498ea4fdee3908576528a clock: read bootid as clock monotonic ID Signed-off-by: Mathieu Desnoyers --- diff --git a/Makefile b/Makefile index ad2ff5a7..2cfc6901 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,8 @@ lttng-tracer-objs := lttng-events.o lttng-abi.o \ lttng-context-prio.o lttng-context-nice.o \ lttng-context-vpid.o lttng-context-tid.o \ lttng-context-vtid.o lttng-context-ppid.o \ - lttng-context-vppid.o lttng-calibrate.o + lttng-context-vppid.o lttng-calibrate.o \ + wrapper/random.o ifneq ($(CONFIG_HAVE_SYSCALL_TRACEPOINTS),) lttng-tracer-objs += lttng-syscalls.o diff --git a/lttng-events.c b/lttng-events.c index 6dd3ba4e..c25d4449 100644 --- a/lttng-events.c +++ b/lttng-events.c @@ -16,6 +16,7 @@ #include #include "wrapper/uuid.h" #include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */ +#include "wrapper/random.h" #include "lttng-events.h" #include "lttng-tracer.h" @@ -881,7 +882,7 @@ static int _lttng_session_metadata_statedump(struct lttng_session *session) { unsigned char *uuid_c = session->uuid.b; - unsigned char uuid_s[37]; + unsigned char uuid_s[37], clock_uuid_s[BOOT_ID_LEN]; struct lttng_channel *chan; struct lttng_event *event; int ret = 0; @@ -939,15 +940,27 @@ int _lttng_session_metadata_statedump(struct lttng_session *session) ret = lttng_metadata_printf(session, "clock {\n" - " name = %s;\n" - " uuid = %s;\n" + " name = %s;\n", + "monotonic" + ); + if (ret) + goto end; + + if (!trace_clock_uuid(clock_uuid_s)) { + ret = lttng_metadata_printf(session, + " uuid = %s;\n", + clock_uuid_s + ); + if (ret) + goto end; + } + + ret = lttng_metadata_printf(session, " description = \"Monotonic Clock\";\n" " freq = %llu; /* Frequency, in Hz */\n" " /* clock value offset from Epoch is: offset * (1/freq) */\n" " offset = %llu;\n" "};\n\n", - "monotonic", - trace_clock_uuid(), (unsigned long long) trace_clock_freq(), (unsigned long long) measure_clock_offset() ); diff --git a/wrapper/random.c b/wrapper/random.c new file mode 100644 index 00000000..da8cb176 --- /dev/null +++ b/wrapper/random.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) + * + * wrapper around bootid read. Using KALLSYMS to get its address when + * available, else we need to have a kernel that exports this function to GPL + * modules. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +/* boot_id depends on sysctl */ +#if defined(CONFIG_SYSCTL) + +#include +#include +#include +#include +#include "random.h" + +/* + * Returns string boot id. + */ +int wrapper_get_bootid(char *bootid) +{ + struct file *file; + int ret; + ssize_t len; + mm_segment_t old_fs; + + file = filp_open("/proc/sys/kernel/random/boot_id", O_RDONLY, 0); + if (IS_ERR(file)) + return PTR_ERR(file); + + old_fs = get_fs(); + set_fs(KERNEL_DS); + + if (!file->f_op || !file->f_op->read) { + ret = -EINVAL; + goto end; + } + + len = file->f_op->read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos); + if (len != BOOT_ID_LEN - 1) { + ret = -EINVAL; + goto end; + } + + bootid[BOOT_ID_LEN - 1] = '\0'; + ret = 0; +end: + set_fs(old_fs); + filp_close(file, current->files); + return ret; +} + +#else + +int wrapper_get_bootid(char *bootid) +{ + return -ENOSYS; +} + +#endif diff --git a/wrapper/random.h b/wrapper/random.h new file mode 100644 index 00000000..30a14d18 --- /dev/null +++ b/wrapper/random.h @@ -0,0 +1,18 @@ +#ifndef _LTTNG_WRAPPER_RANDOM_H +#define _LTTNG_WRAPPER_RANDOM_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) + * + * wrapper around bootid read. Using KALLSYMS to get its address when + * available, else we need to have a kernel that exports this function to GPL + * modules. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#define BOOT_ID_LEN 37 + +int wrapper_get_bootid(char *bootid); + +#endif /* _LTTNG_WRAPPER_RANDOM_H */ diff --git a/wrapper/trace-clock.h b/wrapper/trace-clock.h index 1140b94b..801e640e 100644 --- a/wrapper/trace-clock.h +++ b/wrapper/trace-clock.h @@ -18,6 +18,7 @@ #include #include #include +#include "random.h" static inline u64 trace_clock_monotonic_wrapper(void) { @@ -49,9 +50,9 @@ static inline u64 trace_clock_freq(void) return (u64) NSEC_PER_SEC; } -static inline const char *trace_clock_uuid(void) +static inline int trace_clock_uuid(char *uuid) { - return "CLOCK_MONOTONIC"; + return wrapper_get_bootid(uuid); } static inline int get_trace_clock(void)