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 9D0CEA0562; Fri, 3 Apr 2020 17:38:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9BFFE1C19F; Fri, 3 Apr 2020 17:37:22 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 457581C19A for ; Fri, 3 Apr 2020 17:37:20 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 033FacoE029268; Fri, 3 Apr 2020 08:37: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=MfoXSE1kb64ggW2dyF8wExb3mrtH+xM1iFVVy/gzn3k=; b=DclC3P9VhgHsMUNFxVnCC2Y0jlskS4cjW0DI0HA17qZAwzDmWJCxLIPG+yYthhY1a8Nq 1MwF07JzA2VaPeZgrf46nm1JaRTly/1W/rJT7hvUNa7Ez5u0ulgehbnexd7D1gfMMhHs oyykZuoabAWw/NYO1yrztZWesP2WQa91mex6CahT5wNMdsvskhwe+WVitfgZRpI3mScs EyG4FVaQoYLfS9ZsBHTLqFr25bPe4cvFpVhmJdIW6RmTPFMLLz4knIaMsUVlffxmVjcS vUEbZfBex1gqW35dp1C/clGAFq8DjR6e6VOb9CRiDtQVO/VzDIt0y8PkUx9w/cJji1Aq mg== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0a-0016f401.pphosted.com with ESMTP id 304855y7d3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 03 Apr 2020 08:37:19 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 3 Apr 2020 08:37:17 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 3 Apr 2020 08:37:17 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 658883F7045; Fri, 3 Apr 2020 08:37:15 -0700 (PDT) From: To: Jerin Jacob , Sunil Kumar Kori CC: , , , , Date: Fri, 3 Apr 2020 21:06:41 +0530 Message-ID: <20200403153709.3703448-6-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200403153709.3703448-1-jerinj@marvell.com> References: <20200329144342.1543749-1-jerinj@marvell.com> <20200403153709.3703448-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-03_11:2020-04-03, 2020-04-03 signatures=0 Subject: [dpdk-dev] [PATCH v4 05/33] eal/trace: implement trace operation APIs 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 This patch implements the following public trace APIs. - rte_trace_global_is_enabled() - rte_trace_global_is_disabled() - rte_trace_is_id_invalid() - rte_trace_global_level_set() - rte_trace_global_level_get() - rte_trace_global_mode_set() - rte_trace_global_mode_get() - rte_trace_enable() - rte_trace_disable() - rte_trace_is_enabled() - rte_trace_is_disabled() - rte_trace_level_set() - rte_trace_level_get() - rte_trace_mode_set() - rte_trace_mode_get() - rte_trace_pattern() - rte_trace_regexp() - rte_trace_by_name() Signed-off-by: Jerin Jacob Signed-off-by: Sunil Kumar Kori --- lib/librte_eal/common/eal_common_trace.c | 243 +++++++++++++++++++++++ lib/librte_eal/common/eal_trace.h | 11 + lib/librte_eal/rte_eal_version.map | 18 ++ 3 files changed, 272 insertions(+) diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c index a8890345b..b5d6c842f 100644 --- a/lib/librte_eal/common/eal_common_trace.c +++ b/lib/librte_eal/common/eal_common_trace.c @@ -3,7 +3,9 @@ */ #include +#include #include +#include #include #include @@ -20,6 +22,247 @@ RTE_DEFINE_PER_LCORE(int, ctf_count); static struct trace_point_head tp_list = STAILQ_HEAD_INITIALIZER(tp_list); static struct trace trace; +bool +rte_trace_global_is_enabled(void) +{ + return trace.global_status; +} + +bool +rte_trace_global_is_disabled(void) +{ + return !trace.global_status; +} + +void +rte_trace_global_level_set(uint32_t level) +{ + struct trace_point *tp; + + trace.level = level; + + if (rte_trace_global_is_disabled()) + return; + + STAILQ_FOREACH(tp, &tp_list, next) { + if (level >= rte_trace_level_get(tp->handle)) + rte_trace_enable(tp->handle); + else + rte_trace_disable(tp->handle); + } +} + +uint32_t +rte_trace_global_level_get(void) +{ + return trace.level; +} + +void +rte_trace_global_mode_set(enum rte_trace_mode mode) +{ + struct trace_point *tp; + + if (rte_trace_global_is_disabled()) + return; + + STAILQ_FOREACH(tp, &tp_list, next) + rte_trace_mode_set(tp->handle, mode); + + trace.mode = mode; +} + +enum +rte_trace_mode rte_trace_global_mode_get(void) +{ + return trace.mode; +} + +bool +rte_trace_is_id_invalid(rte_trace_t *t) +{ + if (trace_id_get(t) >= trace.nb_trace_points) + return true; + + return false; +} + +bool +rte_trace_is_enabled(rte_trace_t *trace) +{ + uint64_t val; + + if (rte_trace_is_id_invalid(trace)) + return false; + + val = __atomic_load_n(trace, __ATOMIC_ACQUIRE); + return val & __RTE_TRACE_FIELD_ENABLE_MASK; +} + +bool +rte_trace_is_disabled(rte_trace_t *trace) +{ + uint64_t val; + + if (rte_trace_is_id_invalid(trace)) + return true; + + val = __atomic_load_n(trace, __ATOMIC_ACQUIRE); + return !(val & __RTE_TRACE_FIELD_ENABLE_MASK); +} + +int +rte_trace_enable(rte_trace_t *trace) +{ + if (rte_trace_is_id_invalid(trace)) + return -ERANGE; + + if (rte_trace_level_get(trace) > rte_trace_global_level_get()) + return -EACCES; + + __atomic_or_fetch(trace, __RTE_TRACE_FIELD_ENABLE_MASK, + __ATOMIC_RELEASE); + return 0; +} + +int +rte_trace_disable(rte_trace_t *trace) +{ + if (rte_trace_is_id_invalid(trace)) + return -ERANGE; + + __atomic_and_fetch(trace, ~__RTE_TRACE_FIELD_ENABLE_MASK, + __ATOMIC_RELEASE); + return 0; +} + +uint32_t +rte_trace_level_get(rte_trace_t *trace) +{ + uint64_t val; + + if (rte_trace_is_id_invalid(trace)) + return 0; + + val = __atomic_load_n(trace, __ATOMIC_ACQUIRE); + val &= __RTE_TRACE_FIELD_LEVEL_MASK; + val = val >> __RTE_TRACE_FIELD_LEVEL_SHIFT; + + return val; +} + +int +rte_trace_level_set(rte_trace_t *trace, uint32_t level) +{ + uint64_t val; + + if (rte_trace_is_id_invalid(trace) || level > RTE_LOG_DEBUG) + return -EINVAL; + + val = __atomic_load_n(trace, __ATOMIC_ACQUIRE); + val &= ~__RTE_TRACE_FIELD_LEVEL_MASK; + val |= (uint64_t)level << __RTE_TRACE_FIELD_LEVEL_SHIFT; + __atomic_store_n(trace, val, __ATOMIC_RELEASE); + + if (level <= rte_trace_global_level_get()) + rte_trace_enable(trace); + else + rte_trace_disable(trace); + + return 0; +} + +int +rte_trace_mode_get(rte_trace_t *trace) +{ + uint64_t val; + + if (rte_trace_is_id_invalid(trace)) + return -EINVAL; + + val = __atomic_load_n(trace, __ATOMIC_ACQUIRE); + + return !!(val & __RTE_TRACE_FIELD_ENABLE_DISCARD); +} + +int +rte_trace_mode_set(rte_trace_t *trace, enum rte_trace_mode mode) +{ + if (rte_trace_is_id_invalid(trace) || mode > RTE_TRACE_MODE_DISCARD) + return -EINVAL; + + if (mode == RTE_TRACE_MODE_OVERWRITE) + __atomic_and_fetch(trace, ~__RTE_TRACE_FIELD_ENABLE_DISCARD, + __ATOMIC_RELEASE); + else + __atomic_or_fetch(trace, __RTE_TRACE_FIELD_ENABLE_DISCARD, + __ATOMIC_RELEASE); + + return 0; +} + +int +rte_trace_pattern(const char *pattern, bool enable) +{ + struct trace_point *tp; + int rc = 0, found = 0; + + STAILQ_FOREACH(tp, &tp_list, next) { + if (fnmatch(pattern, tp->name, 0) == 0) { + if (enable) + rc = rte_trace_enable(tp->handle); + else + rc = rte_trace_disable(tp->handle); + found = 1; + } + if (rc < 0) + return rc; + } + + return rc | found; +} + +int +rte_trace_regexp(const char *regex, bool enable) +{ + struct trace_point *tp; + int rc = 0, found = 0; + regex_t r; + + if (regcomp(&r, regex, 0) != 0) + return -EINVAL; + + STAILQ_FOREACH(tp, &tp_list, next) { + if (regexec(&r, tp->name, 0, NULL, 0) == 0) { + if (enable) + rc = rte_trace_enable(tp->handle); + else + rc = rte_trace_disable(tp->handle); + found = 1; + } + if (rc < 0) + return rc; + } + regfree(&r); + + return rc | found; +} + +rte_trace_t * +rte_trace_by_name(const char *name) +{ + struct trace_point *tp; + + if (name == NULL) + return NULL; + + STAILQ_FOREACH(tp, &tp_list, next) + if (strncmp(tp->name, name, TRACE_POINT_NAME_SIZE) == 0) + return tp->handle; + + return NULL; +} + int __rte_trace_point_register(rte_trace_t *handle, const char *name, uint32_t level, void (*register_fn)(void)) diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h index 7665bd6be..e32e0821f 100644 --- a/lib/librte_eal/common/eal_trace.h +++ b/lib/librte_eal/common/eal_trace.h @@ -27,9 +27,20 @@ struct trace_point { struct trace { int register_errno; + bool global_status; + enum rte_trace_mode mode; + uint32_t level; uint32_t nb_trace_points; }; +/* Helper functions */ +static inline uint16_t +trace_id_get(rte_trace_t *trace) +{ + return (*trace & __RTE_TRACE_FIELD_ID_MASK) >> + __RTE_TRACE_FIELD_ID_SHIFT; +} + /* Trace point list functions */ STAILQ_HEAD(trace_point_head, trace_point); diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 3a1be3e3f..cbbb15a08 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -340,4 +340,22 @@ EXPERIMENTAL { rte_log_can_log; rte_thread_getname; __rte_trace_point_register; + rte_trace_global_is_enabled; + rte_trace_global_is_disabled; + rte_trace_is_id_invalid; + rte_trace_global_level_set; + rte_trace_global_level_get; + rte_trace_global_mode_set; + rte_trace_global_mode_get; + rte_trace_enable; + rte_trace_disable; + rte_trace_is_enabled; + rte_trace_is_disabled; + rte_trace_level_set; + rte_trace_level_get; + rte_trace_mode_set; + rte_trace_mode_get; + rte_trace_pattern; + rte_trace_regexp; + rte_trace_by_name; }; -- 2.25.1