clock: read bootid as clock monotonic ID
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 Jan 2012 15:30:05 +0000 (10:30 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 Jan 2012 15:30:05 +0000 (10:30 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Makefile
lttng-events.c
wrapper/random.c [new file with mode: 0644]
wrapper/random.h [new file with mode: 0644]
wrapper/trace-clock.h

index ad2ff5a73d91f0c2c4de1b6da9a9f21d4e846b09..2cfc69012509d2c931b18291e8cbb399011aa39b 100644 (file)
--- 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
index 6dd3ba4ed19ef1bfb77002c50c1ab90f3714375a..c25d4449ebec3e72985dee8ce246caed33655c08 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/jiffies.h>
 #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 (file)
index 0000000..da8cb17
--- /dev/null
@@ -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 <linux/fs.h>
+#include <linux/file.h>
+#include <linux/sched.h>
+#include <linux/uaccess.h>
+#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 (file)
index 0000000..30a14d1
--- /dev/null
@@ -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 */
index 1140b94bcd1de2ae292a5dc9c4f9ffd4653271aa..801e640eda894346554cb6fa2fa9e9324de6b256 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/ktime.h>
 #include <linux/time.h>
 #include <linux/hrtimer.h>
+#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)
This page took 0.029383 seconds and 4 git commands to generate.