[v1,06/32] eal/trace: get bootup timestamp for trace
Checks
Commit Message
From: Jerin Jacob <jerinj@marvell.com>
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>
---
lib/librte_eal/common/eal_common_trace.c | 3 +++
.../common/eal_common_trace_utils.c | 22 +++++++++++++++++++
lib/librte_eal/common/eal_trace.h | 5 +++++
3 files changed, 30 insertions(+)
Comments
On 2020-03-18 20:02, jerinj@marvell.com wrote:
> From: Jerin Jacob <jerinj@marvell.com>
>
> 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>
> ---
> lib/librte_eal/common/eal_common_trace.c | 3 +++
> .../common/eal_common_trace_utils.c | 22 +++++++++++++++++++
> lib/librte_eal/common/eal_trace.h | 5 +++++
> 3 files changed, 30 insertions(+)
>
> diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c
> index abb221cf3..51c4dd550 100644
> --- a/lib/librte_eal/common/eal_common_trace.c
> +++ b/lib/librte_eal/common/eal_common_trace.c
> @@ -59,6 +59,9 @@ eal_trace_init(void)
> if (trace_mkdir())
> goto fail;
>
> + /* Save current epoch timestamp for future use */
> + if (trace_epoch_time_save())
> + goto fail;
< 0 looks cleaner.
>
> rte_trace_global_mode_set(trace.mode);
>
> diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
> index f7d59774c..340ab62e4 100644
> --- a/lib/librte_eal/common/eal_common_trace_utils.c
> +++ b/lib/librte_eal/common/eal_common_trace_utils.c
> @@ -98,6 +98,28 @@ trace_session_name_generate(char *trace_dir)
> return -rte_errno;
> }
>
> +int
> +trace_epoch_time_save(void)
> +{
> + struct trace *trace = trace_obj_get();
> + struct timespec epoch = { 0, 0 };
= {} also works.
> + 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;
If you would settle with keeping the time offset in microseconds, you
would only need "epoch_offset_usec".
> + trace->uptime_ticks = avg;
> +
> + return 0;
> +}
> +
> static int
> trace_dir_default_path_get(char *dir_path)
> {
> diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h
> index 10c2f03ac..9807613d2 100644
> --- a/lib/librte_eal/common/eal_trace.h
> +++ b/lib/librte_eal/common/eal_trace.h
> @@ -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_uuid.h>
> @@ -38,6 +39,9 @@ struct trace {
> rte_uuid_t uuid;
> uint32_t level;
> uint32_t nb_trace_points;
> + uint64_t epoch_sec;
> + uint64_t epoch_nsec;
> + uint64_t uptime_ticks;
> rte_spinlock_t lock;
> };
>
> @@ -60,6 +64,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);
On Thu, Mar 19, 2020 at 4:13 PM Mattias Rönnblom
<mattias.ronnblom@ericsson.com> wrote:
>
> On 2020-03-18 20:02, jerinj@marvell.com wrote:
> > From: Jerin Jacob <jerinj@marvell.com>
> >
> > 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>
> > ---
> > lib/librte_eal/common/eal_common_trace.c | 3 +++
> > .../common/eal_common_trace_utils.c | 22 +++++++++++++++++++
> > lib/librte_eal/common/eal_trace.h | 5 +++++
> > 3 files changed, 30 insertions(+)
> >
> > diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c
> > index abb221cf3..51c4dd550 100644
> > --- a/lib/librte_eal/common/eal_common_trace.c
> > +++ b/lib/librte_eal/common/eal_common_trace.c
> > @@ -59,6 +59,9 @@ eal_trace_init(void)
> > if (trace_mkdir())
> > goto fail;
> >
> > + /* Save current epoch timestamp for future use */
> > + if (trace_epoch_time_save())
> > + goto fail;
> < 0 looks cleaner.
OK. I will change it in v2.
> >
> > rte_trace_global_mode_set(trace.mode);
> >
> > diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
> > index f7d59774c..340ab62e4 100644
> > --- a/lib/librte_eal/common/eal_common_trace_utils.c
> > +++ b/lib/librte_eal/common/eal_common_trace_utils.c
> > @@ -98,6 +98,28 @@ trace_session_name_generate(char *trace_dir)
> > return -rte_errno;
> > }
> >
> > +int
> > +trace_epoch_time_save(void)
> > +{
> > + struct trace *trace = trace_obj_get();
> > + struct timespec epoch = { 0, 0 };
> = {} also works.
> > + 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;
> If you would settle with keeping the time offset in microseconds, you
> would only need "epoch_offset_usec".
ctf spec[1] uses offset_s and offset in clock definition. Storing both
to avoid conversion in the future.
[1]
https://diamon.org/ctf/#spec8
@@ -59,6 +59,9 @@ eal_trace_init(void)
if (trace_mkdir())
goto fail;
+ /* Save current epoch timestamp for future use */
+ if (trace_epoch_time_save())
+ goto fail;
rte_trace_global_mode_set(trace.mode);
@@ -98,6 +98,28 @@ trace_session_name_generate(char *trace_dir)
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)
{
@@ -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_uuid.h>
@@ -38,6 +39,9 @@ struct trace {
rte_uuid_t uuid;
uint32_t level;
uint32_t nb_trace_points;
+ uint64_t epoch_sec;
+ uint64_t epoch_nsec;
+ uint64_t uptime_ticks;
rte_spinlock_t lock;
};
@@ -60,6 +64,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);