From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 1D8116CA9 for ; Mon, 9 May 2016 18:14:13 +0200 (CEST) Received: from glumotte.dev.6wind.com (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id 34FF924EC9; Mon, 9 May 2016 18:12:36 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org, david.marchand@6wind.com Cc: Maxime Leroy Date: Mon, 9 May 2016 18:13:36 +0200 Message-Id: <1462810416-6183-1-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.8.0.rc3 Subject: [dpdk-dev] [PATCH] eal: fix log level/type retrieving on a standard pthread X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2016 16:14:13 -0000 From: Maxime Leroy The functions rte_log_cur_msg_loglevel() and rte_log_cur_msg_logtype() return the current log level/type for the message being processed. They are used when implementing a user-defined logging stream. The current log levels and types were stored in a table indexed by the lcore_id, only returning a valid value for dataplane threads. Setting and getting these values in a non dataplane thread was ignored, using the global value instead. To fix this issue, a per-thread variable could be used (with RTE_DEFINE_PER_LCORE), allowing any pthread to set and retrieve its current log level or type. Signed-off-by: Maxime Leroy Signed-off-by: Olivier Matz --- lib/librte_eal/common/eal_common_log.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index 64aa79f..9526095 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -98,9 +98,10 @@ static int history_enabled = 1; struct log_cur_msg { uint32_t loglevel; /**< log level - see rte_log.h */ uint32_t logtype; /**< log type - see rte_log.h */ -} __rte_cache_aligned; -static struct log_cur_msg log_cur_msg[RTE_MAX_LCORE]; /**< per core log */ +}; + /* per core log */ +static RTE_DEFINE_PER_LCORE(struct log_cur_msg, log_cur_msg); /* default logs */ @@ -205,21 +206,13 @@ rte_get_log_type(void) /* get the current loglevel for the message beeing processed */ int rte_log_cur_msg_loglevel(void) { - unsigned lcore_id; - lcore_id = rte_lcore_id(); - if (lcore_id >= RTE_MAX_LCORE) - return rte_get_log_level(); - return log_cur_msg[lcore_id].loglevel; + return RTE_PER_LCORE(log_cur_msg).loglevel; } /* get the current logtype for the message beeing processed */ int rte_log_cur_msg_logtype(void) { - unsigned lcore_id; - lcore_id = rte_lcore_id(); - if (lcore_id >= RTE_MAX_LCORE) - return rte_get_log_type(); - return log_cur_msg[lcore_id].logtype; + return RTE_PER_LCORE(log_cur_msg).logtype; } /* Dump log history to file */ @@ -273,17 +266,13 @@ rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap) { int ret; FILE *f = rte_logs.file; - unsigned lcore_id; if ((level > rte_logs.level) || !(logtype & rte_logs.type)) return 0; /* save loglevel and logtype in a global per-lcore variable */ - lcore_id = rte_lcore_id(); - if (lcore_id < RTE_MAX_LCORE) { - log_cur_msg[lcore_id].loglevel = level; - log_cur_msg[lcore_id].logtype = logtype; - } + RTE_PER_LCORE(log_cur_msg).loglevel = level; + RTE_PER_LCORE(log_cur_msg).logtype = logtype; ret = vfprintf(f, format, ap); fflush(f); -- 2.8.0.rc3