From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2C375A0579; Fri, 9 Apr 2021 13:05:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1AB10140F40; Fri, 9 Apr 2021 13:05:21 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 0752D140F47 for ; Fri, 9 Apr 2021 13:05:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617966319; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Hv2QCQV78nM32xDcW1FCrdSzmFNUT6nvZ+siZ/HbVyw=; b=Ux57fTwuEqz9Y+Q+oL4upCBLfjxb+ITexBQcEgcy+fVNLrQzMlYk++bKnvp5a+3raKPw4E SFtcRyU+JGGSyb3Fm3Em8gKPz6e1+acRYQHLOr0zij7s9iiK828eVex95fkQpurCqM00gp rSk0kPxFsS2MGQiooCDblleFUte/TKU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-320-t4trLW-rNSGrwD7NUgbp1Q-1; Fri, 09 Apr 2021 07:05:15 -0400 X-MC-Unique: t4trLW-rNSGrwD7NUgbp1Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8312264149; Fri, 9 Apr 2021 11:05:14 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 574CF690F5; Fri, 9 Apr 2021 11:05:12 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: arybchenko@solarflare.com, l.wojciechow@partner.samsung.com, thomas@monjalon.net, Ilya Maximets Date: Fri, 9 Apr 2021 13:04:52 +0200 Message-Id: <20210409110453.20078-3-david.marchand@redhat.com> In-Reply-To: <20210409110453.20078-1-david.marchand@redhat.com> References: <20200626114751.22523-1-david.marchand@redhat.com> <20210409110453.20078-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH v3 2/3] log: track log level changes X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Add a log message when registering log types and changing log levels. __rte_log_register previous handled both legacy and dynamic logtypes. To simplify the code, __rte_log_register is reworked to only handle dynamic logtypes and takes a log level. Example: $ DPDK_TEST=logs_autotest ./build/app/test/dpdk-test --no-huge -m 512 \ --log-level=lib.eal:debug ... RTE>>logs_autotest == dynamic log types EAL: logtype1 logtype level changed from disabled to info EAL: logtype2 logtype level changed from disabled to info EAL: logtype1 logtype level changed from info to error EAL: logtype3 logtype level changed from error to emerg EAL: logtype2 logtype level changed from info to emerg EAL: logtype3 logtype level changed from emerg to debug EAL: logtype1 logtype level changed from error to debug EAL: logtype2 logtype level changed from emerg to debug error message critical message critical message error message == static log types TESTAPP1: error message TESTAPP1: critical message TESTAPP2: critical message TESTAPP1: error message Test OK Suggested-by: Ilya Maximets Signed-off-by: David Marchand Acked-by: Andrew Rybchenko Acked-by: Lukasz Wojciechowski --- Changes since v2: - rebased on Thomas changes, - updated log level change message, Changes since v1: - updated commitlog, --- lib/librte_eal/common/eal_common_log.c | 79 +++++++++++++------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index 4c1d514770..bed83a402a 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -135,6 +135,21 @@ rte_log_can_log(uint32_t logtype, uint32_t level) return true; } +static void +logtype_set_level(uint32_t type, uint32_t level) +{ + uint32_t current = rte_logs.dynamic_types[type].loglevel; + + if (current != level) { + rte_logs.dynamic_types[type].loglevel = level; + RTE_LOG(DEBUG, EAL, "%s log level changed from %s to %s\n", + rte_logs.dynamic_types[type].name == NULL ? + "" : rte_logs.dynamic_types[type].name, + eal_log_level2str(current), + eal_log_level2str(level)); + } +} + int rte_log_set_level(uint32_t type, uint32_t level) { @@ -143,7 +158,7 @@ rte_log_set_level(uint32_t type, uint32_t level) if (level > RTE_LOG_MAX) return -1; - rte_logs.dynamic_types[type].loglevel = level; + logtype_set_level(type, level); return 0; } @@ -166,7 +181,7 @@ rte_log_set_level_regexp(const char *regex, uint32_t level) continue; if (regexec(&r, rte_logs.dynamic_types[i].name, 0, NULL, 0) == 0) - rte_logs.dynamic_types[i].loglevel = level; + logtype_set_level(i, level); } regfree(&r); @@ -227,7 +242,7 @@ rte_log_set_level_pattern(const char *pattern, uint32_t level) continue; if (fnmatch(pattern, rte_logs.dynamic_types[i].name, 0) == 0) - rte_logs.dynamic_types[i].loglevel = level; + logtype_set_level(i, level); } return 0; @@ -266,29 +281,11 @@ log_lookup(const char *name) return -1; } -/* register an extended log type, assuming table is large enough, and id - * is not yet registered. - */ static int -log_register(const char *name, int id) -{ - char *dup_name = strdup(name); - - if (dup_name == NULL) - return -ENOMEM; - - rte_logs.dynamic_types[id].name = dup_name; - rte_logs.dynamic_types[id].loglevel = RTE_LOG_INFO; - - return id; -} - -/* register an extended log type */ -int -rte_log_register(const char *name) +log_register(const char *name, uint32_t level) { struct rte_log_dynamic_type *new_dynamic_types; - int id, ret; + int id; id = log_lookup(name); if (id >= 0) @@ -301,13 +298,24 @@ rte_log_register(const char *name) return -ENOMEM; rte_logs.dynamic_types = new_dynamic_types; - ret = log_register(name, rte_logs.dynamic_types_len); - if (ret < 0) - return ret; + id = rte_logs.dynamic_types_len; + memset(&rte_logs.dynamic_types[id], 0, + sizeof(rte_logs.dynamic_types[id])); + rte_logs.dynamic_types[id].name = strdup(name); + if (rte_logs.dynamic_types[id].name == NULL) + return -ENOMEM; + logtype_set_level(id, level); rte_logs.dynamic_types_len++; - return ret; + return id; +} + +/* register an extended log type */ +int +rte_log_register(const char *name) +{ + return log_register(name, RTE_LOG_INFO); } /* Register an extended log type and try to pick its level from EAL options */ @@ -316,11 +324,6 @@ rte_log_register_type_and_pick_level(const char *name, uint32_t level_def) { struct rte_eal_opt_loglevel *opt_ll; uint32_t level = level_def; - int type; - - type = rte_log_register(name); - if (type < 0) - return type; TAILQ_FOREACH(opt_ll, &opt_loglevel_list, next) { if (opt_ll->level > RTE_LOG_MAX) @@ -335,9 +338,7 @@ rte_log_register_type_and_pick_level(const char *name, uint32_t level_def) } } - rte_logs.dynamic_types[type].loglevel = level; - - return type; + return log_register(name, level); } struct logtype { @@ -390,9 +391,11 @@ RTE_INIT_PRIO(log_init, LOG) return; /* register legacy log types */ - for (i = 0; i < RTE_DIM(logtype_strings); i++) - log_register(logtype_strings[i].logtype, - logtype_strings[i].log_id); + for (i = 0; i < RTE_DIM(logtype_strings); i++) { + rte_logs.dynamic_types[logtype_strings[i].log_id].name = + strdup(logtype_strings[i].logtype); + logtype_set_level(logtype_strings[i].log_id, RTE_LOG_INFO); + } rte_logs.dynamic_types_len = RTE_LOGTYPE_FIRST_EXT_ID; } -- 2.23.0