trace: save bootup timestamp
authorJerin Jacob <jerinj@marvell.com>
Wed, 22 Apr 2020 19:03:23 +0000 (00:33 +0530)
committerDavid Marchand <david.marchand@redhat.com>
Thu, 23 Apr 2020 13:39:20 +0000 (15:39 +0200)
Find epoch_sec, epoch_nsec and uptime_ticks time information
on eal_trace_init()/bootup to derive the time in the trace.

Signed-off-by: Jerin Jacob <jerinj@marvell.com>
Acked-by: David Marchand <david.marchand@redhat.com>
lib/librte_eal/common/eal_common_trace.c
lib/librte_eal/common/eal_common_trace_utils.c
lib/librte_eal/common/eal_trace.h

index 55d7fa7..d88b2cd 100644 (file)
@@ -61,6 +61,9 @@ eal_trace_init(void)
        if (trace_mkdir())
                goto fail;
 
+       /* Save current epoch timestamp for future use */
+       if (trace_epoch_time_save() < 0)
+               goto fail;
 
        rte_trace_mode_set(trace.mode);
 
index 7fc7022..6b43802 100644 (file)
@@ -98,6 +98,28 @@ fail:
        return -rte_errno;
 }
 
+int
+trace_epoch_time_save(void)
+{
+       struct trace *trace = trace_obj_get();
+       struct timespec epoch = { 0, 0 };
+       uint64_t avg, start, end;
+
+       start = rte_get_tsc_cycles();
+       if (clock_gettime(CLOCK_REALTIME, &epoch) < 0) {
+               trace_err("failed to get the epoch time");
+               return -1;
+       }
+       end = rte_get_tsc_cycles();
+       avg = (start + end) >> 1;
+
+       trace->epoch_sec = (uint64_t) epoch.tv_sec;
+       trace->epoch_nsec = (uint64_t) epoch.tv_nsec;
+       trace->uptime_ticks = avg;
+
+       return 0;
+}
+
 static int
 trace_dir_default_path_get(char *dir_path)
 {
index 4f5da7a..51bb2c3 100644 (file)
@@ -5,6 +5,7 @@
 #ifndef __EAL_TRACE_H
 #define __EAL_TRACE_H
 
+#include <rte_cycles.h>
 #include <rte_spinlock.h>
 #include <rte_trace.h>
 #include <rte_trace_point.h>
@@ -37,6 +38,9 @@ struct trace {
        rte_uuid_t uuid;
        uint32_t buff_len;
        uint32_t nb_trace_points;
+       uint64_t epoch_sec;
+       uint64_t epoch_nsec;
+       uint64_t uptime_ticks;
        rte_spinlock_t lock;
 };
 
@@ -59,6 +63,7 @@ struct trace_point_head *trace_list_head_get(void);
 bool trace_has_duplicate_entry(void);
 void trace_uuid_generate(void);
 int trace_mkdir(void);
+int trace_epoch_time_save(void);
 
 /* EAL interface */
 int eal_trace_init(void);