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 E221545CB1; Fri, 8 Nov 2024 09:57:40 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 10F7F43300; Fri, 8 Nov 2024 09:57:37 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 76AA343267 for ; Fri, 8 Nov 2024 09:57:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731056255; 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=BfJh3kYoxmCVVo8b4DBZ0nypuDo2Cmzb2RdyC5qmw4Q=; b=c3MlXWIpvdVh0f/zxRdD9OYcpZvxExNhh1OA4sQGjO5GBCcimS0xdNGLnNeQtTNV3jdFIz 2J007nJxkjRdkq9oUxcri7IwMbRJMHBtUKRgJnSDjz0pyQU5a0jQIxJWhaRYvDFuahO7BJ 2HRYIYOFEpnWvOvD0U73kYMuJhMqTec= 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-333-TTqWpbVfPIarFT4UIZewNw-1; Fri, 08 Nov 2024 03:57:34 -0500 X-MC-Unique: TTqWpbVfPIarFT4UIZewNw-1 X-Mimecast-MFC-AGG-ID: TTqWpbVfPIarFT4UIZewNw Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 0443B1956088; Fri, 8 Nov 2024 08:57:33 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.57]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3D4311955F43; Fri, 8 Nov 2024 08:57:30 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Tyler Retzlaff , Bruce Richardson , Dmitry Kozlyuk Subject: [PATCH v32 03/12] eal: introduce log options parser Date: Fri, 8 Nov 2024 09:57:00 +0100 Message-ID: <20241108085710.2943741-4-david.marchand@redhat.com> In-Reply-To: <20241108085710.2943741-1-david.marchand@redhat.com> References: <20200814173441.23086-1-stephen@networkplumber.org> <20241108085710.2943741-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: xGUymjUbAl7YVXzCMRVZYIjllk05q_HxNhRLecPmLUA_1731056253 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 89dfc540f2..16b1c67cca 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -393,8 +393,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); @@ -575,8 +575,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 f82a398d4b..49a88cfbd5 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -611,8 +611,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); @@ -951,8 +951,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 25e69a429b..f77053eb7e 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -121,8 +121,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); @@ -254,7 +254,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