From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3D173A0562; Sun, 29 Mar 2020 16:46:01 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8B6AA1C10C; Sun, 29 Mar 2020 16:43:59 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 702171C0B7 for ; Sun, 29 Mar 2020 16:43:55 +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 02TEfJ4J013739; Sun, 29 Mar 2020 07:43:54 -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=XyWOA+rF9f0W2YRWJwZaaVgrUODa+OQLdTVE2/tRyfg=; b=kppuYcieoKUApTBkWwI6NGhNd1zKl7psPilfB/Ydf0xd4tH3Vz9kzKFpon8FcN4woxdc Tz5njyNgHCR+RIWGSxhcc/u3jVwW0NyoSzzeYUoHBnYR1beoVFBOuVGoLqi/v/RcA6Ei Pj5n0Ax988NtJa6XZyImkvZ1sd/5CKPaI9k6zVcDzVcPcLaRY2pgQZzZgpAYHPcfRfzr jloXfyX08LmbximW89cEkUlcEgZd93WCeZiX6qyedH0c/KtMpzbPgCDhJULc+wXc+W+o jrXBEIHzzbbAeVpCvHPaXEQDhE6JxYvgVWVWorofw8b0qwogwMGA63I7dCAOJn7oyMnQ Sg== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 30263kb5h2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 29 Mar 2020 07:43:54 -0700 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 29 Mar 2020 07:43:52 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sun, 29 Mar 2020 07:43:52 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id AA7223F703F; Sun, 29 Mar 2020 07:43:50 -0700 (PDT) From: To: Jerin Jacob , Sunil Kumar Kori , Bruce Richardson CC: , , , Date: Sun, 29 Mar 2020 20:13:15 +0530 Message-ID: <20200329144342.1543749-7-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200329144342.1543749-1-jerinj@marvell.com> References: <20200325211603.240288-1-jerinj@marvell.com> <20200329144342.1543749-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.645 definitions=2020-03-29_05:2020-03-27, 2020-03-29 signatures=0 Subject: [dpdk-dev] [PATCH v3 06/33] eal/trace: add internal trace init and fini interface X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jerin Jacob Define eal_trace_init() and eal_trace_fini() EAL interface functions that rte_eal_init() and rte_eal_cleanup() function can be use to initialize and finalize the trace subsystem. eal_trace_init() function will add the following functionality if trace is enabled through EAL command line param. - Test for trace registration failure. - Test for duplicate trace name registration - Generate UUID ver 4. - Create a trace directory Signed-off-by: Jerin Jacob Signed-off-by: Sunil Kumar Kori --- lib/librte_eal/common/eal_common_trace.c | 54 ++++++ .../common/eal_common_trace_utils.c | 173 ++++++++++++++++++ lib/librte_eal/common/eal_trace.h | 21 +++ lib/librte_eal/common/meson.build | 1 + lib/librte_eal/freebsd/eal/Makefile | 1 + lib/librte_eal/linux/eal/Makefile | 1 + 6 files changed, 251 insertions(+) create mode 100644 lib/librte_eal/common/eal_common_trace_utils.c diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c index b5d6c842f..50890fb5b 100644 --- a/lib/librte_eal/common/eal_common_trace.c +++ b/lib/librte_eal/common/eal_common_trace.c @@ -22,6 +22,60 @@ RTE_DEFINE_PER_LCORE(int, ctf_count); static struct trace_point_head tp_list = STAILQ_HEAD_INITIALIZER(tp_list); static struct trace trace; +struct trace* +trace_obj_get(void) +{ + return &trace; +} + +struct trace_point_head * +trace_list_head_get(void) +{ + return &tp_list; +} + +int +eal_trace_init(void) +{ + /* One of the Trace registration failed */ + if (trace.register_errno) { + rte_errno = trace.register_errno; + goto fail; + } + + if (rte_trace_global_is_disabled()) + return 0; + + rte_spinlock_init(&trace.lock); + + /* Is duplicate trace name registered */ + if (trace_has_duplicate_entry()) + goto fail; + + /* Generate UUID ver 4 with total size of events and number of events */ + trace_uuid_generate(); + + /* Create trace directory */ + if (trace_mkdir()) + goto fail; + + + rte_trace_global_mode_set(trace.mode); + + return 0; + +fail: + trace_err("failed to initialize trace [%s]", rte_strerror(rte_errno)); + return -rte_errno; +} + +void +eal_trace_fini(void) +{ + if (rte_trace_global_is_disabled()) + return; +} + bool rte_trace_global_is_enabled(void) { diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c new file mode 100644 index 000000000..8df7b5c33 --- /dev/null +++ b/lib/librte_eal/common/eal_common_trace_utils.c @@ -0,0 +1,173 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ + +#include +#include +#include +#include + +#include +#include +#include + +#include "eal_filesystem.h" +#include "eal_trace.h" + +static bool +trace_entry_compare(const char *name) +{ + struct trace_point_head *tp_list = trace_list_head_get(); + struct trace_point *tp; + int count = 0; + + STAILQ_FOREACH(tp, tp_list, next) { + if (strncmp(tp->name, name, TRACE_POINT_NAME_SIZE) == 0) + count++; + if (count > 1) { + trace_err("found duplicate entry %s", name); + rte_errno = EEXIST; + return true; + } + } + return false; +} + +bool +trace_has_duplicate_entry(void) +{ + struct trace_point_head *tp_list = trace_list_head_get(); + struct trace_point *tp; + + /* Is duplicate trace name registered */ + STAILQ_FOREACH(tp, tp_list, next) + if (trace_entry_compare(tp->name)) + return true; + + return false; +} + +void +trace_uuid_generate(void) +{ + struct trace_point_head *tp_list = trace_list_head_get(); + struct trace *trace = trace_obj_get(); + struct trace_point *tp; + uint64_t sz_total = 0; + + /* Go over the registered trace points to get total size of events */ + STAILQ_FOREACH(tp, tp_list, next) { + const uint16_t sz = *tp->handle & __RTE_TRACE_FIELD_SIZE_MASK; + sz_total += sz; + } + + rte_uuid_t uuid = RTE_UUID_INIT(sz_total, trace->nb_trace_points, + 0x4370, 0x8f50, 0x222ddd514176ULL); + rte_uuid_copy(trace->uuid, uuid); +} + +static int +trace_session_name_generate(char *trace_dir) +{ + struct tm *tm_result; + time_t tm; + int rc; + + tm = time(NULL); + if ((int)tm == -1) + goto fail; + + tm_result = localtime(&tm); + if (tm_result == NULL) + goto fail; + + rc = rte_strscpy(trace_dir, + eal_get_hugefile_prefix(), TRACE_PREFIX_LEN); + if (rc == -E2BIG) + rc = TRACE_PREFIX_LEN; + trace_dir[rc++] = '-'; + + rc = strftime(trace_dir + rc, TRACE_DIR_STR_LEN - rc, + "%Y-%m-%d-%p-%I-%M-%S", tm_result); + if (rc == 0) + goto fail; + + return rc; +fail: + rte_errno = errno; + return -rte_errno; +} + +static int +trace_dir_default_path_get(char *dir_path) +{ + struct trace *trace = trace_obj_get(); + uint32_t size = sizeof(trace->dir); + struct passwd *pwd; + char *home_dir; + + /* First check for shell environment variable */ + home_dir = getenv("HOME"); + if (home_dir == NULL) { + /* Fallback to password file entry */ + pwd = getpwuid(getuid()); + if (pwd == NULL) + return -EINVAL; + + home_dir = pwd->pw_dir; + } + + /* Append dpdk-traces to directory */ + if (snprintf(dir_path, size, "%s/dpdk-traces/", home_dir) < 0) + return -ENAMETOOLONG; + + return 0; +} + +int +trace_mkdir(void) +{ + struct trace *trace = trace_obj_get(); + char session[TRACE_DIR_STR_LEN]; + char *dir_path; + int rc; + + if (!trace->dir_offset) { + dir_path = calloc(1, sizeof(trace->dir)); + if (dir_path == NULL) { + trace_err("fail to allocate memory\n"); + return -ENOMEM; + } + + rc = trace_dir_default_path_get(dir_path); + if (rc < 0) { + trace_err("fail to get default path\n"); + free(dir_path); + return rc; + } + + } + + /* Create the path if it t exist, no "mkdir -p" available here */ + rc = mkdir(trace->dir, 0700); + if (rc < 0 && errno != EEXIST) { + trace_err("mkdir %s failed [%s]", trace->dir, strerror(errno)); + rte_errno = errno; + return -rte_errno; + } + + rc = trace_session_name_generate(session); + if (rc < 0) + return rc; + + rc = mkdir(trace->dir, 0700); + if (rc < 0) { + trace_err("mkdir %s failed [%s]", trace->dir, strerror(errno)); + rte_errno = errno; + return -rte_errno; + } + + RTE_LOG(INFO, EAL, "Trace dir: %s\n", trace->dir); + return 0; +} + diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h index e32e0821f..9354f2456 100644 --- a/lib/librte_eal/common/eal_trace.h +++ b/lib/librte_eal/common/eal_trace.h @@ -5,7 +5,9 @@ #ifndef __EAL_TRACE_H #define __EAL_TRACE_H +#include #include +#include #define trace_err(fmt, args...)\ RTE_LOG(ERR, EAL, "%s():%u " fmt "\n",\ @@ -15,6 +17,8 @@ RTE_LOG(CRIT, EAL, "%s():%u " fmt "\n",\ __func__, __LINE__, ## args) +#define TRACE_PREFIX_LEN 12 +#define TRACE_DIR_STR_LEN (sizeof("YYYY-mm-dd-AM-HH-MM-SS") + TRACE_PREFIX_LEN) #define TRACE_CTF_FIELD_SIZE 384 #define TRACE_POINT_NAME_SIZE 64 @@ -26,11 +30,15 @@ struct trace_point { }; struct trace { + char dir[PATH_MAX]; + int dir_offset; int register_errno; bool global_status; enum rte_trace_mode mode; + rte_uuid_t uuid; uint32_t level; uint32_t nb_trace_points; + rte_spinlock_t lock; }; /* Helper functions */ @@ -41,7 +49,20 @@ trace_id_get(rte_trace_t *trace) __RTE_TRACE_FIELD_ID_SHIFT; } +/* Trace object functions */ +struct trace *trace_obj_get(void); + /* Trace point list functions */ STAILQ_HEAD(trace_point_head, trace_point); +struct trace_point_head *trace_list_head_get(void); + +/* Util functions */ +bool trace_has_duplicate_entry(void); +void trace_uuid_generate(void); +int trace_mkdir(void); + +/* EAL interface */ +int eal_trace_init(void); +void eal_trace_fini(void); #endif /* __EAL_TRACE_H */ diff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build index 88c14ebe5..716a255d2 100644 --- a/lib/librte_eal/common/meson.build +++ b/lib/librte_eal/common/meson.build @@ -29,6 +29,7 @@ common_sources = files( 'eal_common_thread.c', 'eal_common_timer.c', 'eal_common_trace.c', + 'eal_common_trace_utils.c', 'eal_common_uuid.c', 'hotplug_mp.c', 'malloc_elem.c', diff --git a/lib/librte_eal/freebsd/eal/Makefile b/lib/librte_eal/freebsd/eal/Makefile index b2fcc4212..8c444da02 100644 --- a/lib/librte_eal/freebsd/eal/Makefile +++ b/lib/librte_eal/freebsd/eal/Makefile @@ -61,6 +61,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_proc.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_uuid.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_trace.c +SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_trace_utils.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += hotplug_mp.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += malloc_elem.c diff --git a/lib/librte_eal/linux/eal/Makefile b/lib/librte_eal/linux/eal/Makefile index 95470d3bb..bd9993e58 100644 --- a/lib/librte_eal/linux/eal/Makefile +++ b/lib/librte_eal/linux/eal/Makefile @@ -69,6 +69,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_proc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_uuid.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_trace.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_trace_utils.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += hotplug_mp.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += malloc_elem.c -- 2.25.1