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 DCD6545CA4; Thu, 7 Nov 2024 21:52:29 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9D15743314; Thu, 7 Nov 2024 21:52:21 +0100 (CET) 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 CA4E2432FC for ; Thu, 7 Nov 2024 21:52:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731012740; 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=2x20pMKVqmOWhkAEddILA+qyC45SRmBVgrFnfHZd88M=; b=R9MJXOcYx44XW8GNhp7B4CkmjKO/I4aFcKUarA/pOtesCFr/0jqpjpXqFIIl6Je4bDfTJ7 Dlp1cDJhE2eDyKldiGI5mJSYVUP9eT4rD7vRT1W//K15cF5Wh9gogs/p8U55f5Qu2WS/Tk zh3+LsATgBiJDlpZh+9RhYzyZNnIB98= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-330-0RLXB17gNcWxXiIDPLGPxw-1; Thu, 07 Nov 2024 15:52:18 -0500 X-MC-Unique: 0RLXB17gNcWxXiIDPLGPxw-1 X-Mimecast-MFC-AGG-ID: 0RLXB17gNcWxXiIDPLGPxw Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 41FF01955F79; Thu, 7 Nov 2024 20:52:17 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.57]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7D05A300019E; Thu, 7 Nov 2024 20:52:15 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Tyler Retzlaff , Bruce Richardson , Dmitry Kozlyuk Subject: [PATCH v31 03/12] eal: introduce log options parser Date: Thu, 7 Nov 2024 21:51:35 +0100 Message-ID: <20241107205145.2424871-4-david.marchand@redhat.com> In-Reply-To: <20241107205145.2424871-1-david.marchand@redhat.com> References: <20200814173441.23086-1-stephen@networkplumber.org> <20241107205145.2424871-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: fbLiQBiH6zZlQW4oieIWneeALHpye5FosYK2NT3Zh5Q_1731012737 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 Rename existing log level option parser and add a little helper tracking all options related to logs. This will make it easier to add more log options in the next commits. Signed-off-by: David Marchand --- lib/eal/common/eal_common_options.c | 26 ++++++++++++++++++-------- lib/eal/common/eal_options.h | 3 ++- lib/eal/freebsd/eal.c | 8 ++++---- lib/eal/linux/eal.c | 8 ++++---- lib/eal/windows/eal.c | 7 ++++--- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 17c378f0c7..ab6cf8bebf 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -1640,9 +1640,20 @@ eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out) return -1; } -/* Parse the arguments for --log-level only */ +bool +eal_option_is_log(int opt) +{ + switch (opt) { + case OPT_LOG_LEVEL_NUM: + return true; + default: + return false; + } +} + +/* Parse all arguments looking for log related ones */ int -eal_log_level_parse(int argc, char * const argv[]) +eal_parse_log_options(int argc, char * const argv[]) { struct internal_config *internal_conf = eal_get_internal_configuration(); int option_index, opt; @@ -1661,12 +1672,11 @@ eal_log_level_parse(int argc, char * const argv[]) while ((opt = getopt_long(argc, argv, eal_short_options, eal_long_options, &option_index)) != EOF) { - switch (opt) { - case OPT_LOG_LEVEL_NUM: - if (eal_parse_common_option(opt, optarg, internal_conf) < 0) - return -1; - break; - } + if (!eal_option_is_log(opt)) + continue; + + if (eal_parse_common_option(opt, optarg, internal_conf) < 0) + return -1; } /* restore getopt lib */ diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index f3f2e104f6..06ba023c5a 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -96,7 +96,8 @@ enum { extern const char eal_short_options[]; extern const struct option eal_long_options[]; -int eal_log_level_parse(int argc, char * const argv[]); +bool eal_option_is_log(int opt); +int eal_parse_log_options(int argc, char * const argv[]); int eal_parse_common_option(int opt, const char *argv, struct internal_config *conf); int eal_option_device_parse(void); diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index d3b40e81d8..8563ef1156 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -392,8 +392,8 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_parse_log_options() already handled this option */ + if (eal_option_is_log(opt)) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -574,8 +574,8 @@ rte_eal_init(int argc, char **argv) /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); - /* set log level as early as possible */ - eal_log_level_parse(argc, argv); + /* parse log options as early as possible */ + eal_parse_log_options(argc, argv); if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 40d750ed0d..9ac52ea500 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -610,8 +610,8 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_parse_log_options() already handled this option */ + if (eal_option_is_log(opt)) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -950,8 +950,8 @@ rte_eal_init(int argc, char **argv) eal_reset_internal_config(internal_conf); - /* set log level as early as possible */ - eal_log_level_parse(argc, argv); + /* parse log options as early as possible */ + eal_parse_log_options(argc, argv); /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index a77e590a72..69d367fb8e 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -120,8 +120,8 @@ eal_parse_args(int argc, char **argv) return -1; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_parse_log_options() already handled this option */ + if (eal_option_is_log(opt)) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -252,7 +252,8 @@ rte_eal_init(int argc, char **argv) eal_log_init(NULL, 0); - eal_log_level_parse(argc, argv); + /* parse log options as early as possible */ + eal_parse_log_options(argc, argv); if (eal_create_cpu_map() < 0) { rte_eal_init_alert("Cannot discover CPU and NUMA."); -- 2.47.0