From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 78FA3A00C2;
	Wed, 22 Apr 2020 21:04:58 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 7EAA81D526;
	Wed, 22 Apr 2020 21:04:32 +0200 (CEST)
Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com
 [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 9A3E61D442
 for <dev@dpdk.org>; Wed, 22 Apr 2020 21:04:19 +0200 (CEST)
Received: from pps.filterd (m0045851.ppops.net [127.0.0.1])
 by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id
 03MJ1blG005895; Wed, 22 Apr 2020 12:04:19 -0700
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com;
 h=from : to : cc :
 subject : date : message-id : in-reply-to : references : mime-version :
 content-transfer-encoding : content-type; s=pfpt0818;
 bh=dwbDkFPvSPD7J2imicb7c0sAe7sdXFacTyKvMCid1Fk=;
 b=s/uCU+RpTpzL8DFPepdMyo57/O+CJffW4Szsg71k1aQfqUNVTbhPbEN9T/5lNNZPDwoo
 AENv0tYR3YG/OlKFaTE6hqvn+zSXL8EdGKTG/ihrRwGtXj4lH+5Ql+5L6ooiFEmjft1P
 ESFsqa/sTOKMAcQGC/G/LMzPYILW4rz6bXs5nGSX14Z6GwFOuTAmalFbhD0487C0PazX
 k25Seeb15GCQ0la6I3RcIh/ebcn27UopFW5iR7Xn321B2OiC4Kdjl+8B4VO5U88H0R/C
 tOoLKh+xfqs12LclTYaW2/Wo2LXqceh925fm6+hH1XMoGkirzINo+s2sZPJNpVXzf7eU lQ== 
Received: from sc-exch02.marvell.com ([199.233.58.182])
 by mx0b-0016f401.pphosted.com with ESMTP id 30jd013jds-1
 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT);
 Wed, 22 Apr 2020 12:04:19 -0700
Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH02.marvell.com
 (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2;
 Wed, 22 Apr 2020 12:04:16 -0700
Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com
 (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2;
 Wed, 22 Apr 2020 12:04:16 -0700
Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com
 (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.2 via Frontend
 Transport; Wed, 22 Apr 2020 12:04:16 -0700
Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14])
 by maili.marvell.com (Postfix) with ESMTP id B1BB63F704F;
 Wed, 22 Apr 2020 12:04:13 -0700 (PDT)
From: <jerinj@marvell.com>
To: Jerin Jacob <jerinj@marvell.com>, Sunil Kumar Kori <skori@marvell.com>
CC: <dev@dpdk.org>, <thomas@monjalon.net>, <bruce.richardson@intel.com>,
 <david.marchand@redhat.com>, <mattias.ronnblom@ericsson.com>
Date: Thu, 23 Apr 2020 00:33:23 +0530
Message-ID: <20200422190349.3768487-7-jerinj@marvell.com>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20200422190349.3768487-1-jerinj@marvell.com>
References: <20200419100133.3232316-1-jerinj@marvell.com>
 <20200422190349.3768487-1-jerinj@marvell.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676
 definitions=2020-04-22_06:2020-04-22,
 2020-04-22 signatures=0
Subject: [dpdk-dev] [PATCH v7 06/32] eal/trace: get bootup timestamp for
	trace
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

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 e270808d2..c02be897a 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() < 0)
+		goto fail;
 
 	rte_trace_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 d2ab8f845..f7700934b 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 };
+	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)
 {
diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h
index deb57dd4c..493163c1c 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_trace_point.h>
@@ -39,6 +40,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;
 };
 
@@ -61,6 +65,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);
-- 
2.25.1