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 0ABC6A00C4; Thu, 31 Oct 2019 10:21:16 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D27CD1C1FC; Thu, 31 Oct 2019 10:21:15 +0100 (CET) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 01C461C1E6 for ; Thu, 31 Oct 2019 10:21:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572513674; 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=yqSGwlOyQt+mKAKoKRU6+lD5ykfGm0uTk43WyIb7aZY=; b=XLXdbyuR8dqZ5UXivu54PMH0S2HKp1JLhe7NSQ2Y5Q4pCo43lBu6cNFaR60Wd2F3HUS4j2 81goCz2HwkPL3gESveQsf49Tomxu6/Wx4tSsE5XpwGgXrcLhp+QtwyhoF9aZ70NEGvcXt8 ZPEMPOBOBm5HRI1WjmA0GnKgE23Uwfg= Received: from mail-ua1-f72.google.com (mail-ua1-f72.google.com [209.85.222.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-144-gOpwChzEPnKFg_gE8l6ogQ-1; Thu, 31 Oct 2019 05:21:08 -0400 Received: by mail-ua1-f72.google.com with SMTP id n21so455050uaq.14 for ; Thu, 31 Oct 2019 02:21:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZrN8JofSRRpeVlUKtU4HTHERumQ2KR3G3qj7jD85dj4=; b=GUxhM2XaJPqLEywJFpMUSrlOwmsTZcvI6H7re16md+/8iA7V6GisJpsIUive9O0Uj7 y3/9jT3lkjIF0nzUW7XjmRSUdZtHbSWK8ETsHJ2SqYFCBohpsKRQs4OsrGhP3E6siw18 dg0yhVGZtxpWtSDdJjWKbpU3Gz/bcNOvC4JE67oPaS256RG9Jn9soiDwVRjQ+oyt4kD/ iCSVyBy6zNKZsSBwBaBRrbsHQlvhyDmQRFKF6eXgInXqfLOVWl0uFpSQx1ku7LKrHzpd 5a6n8TCtE4t+1ipxn4WpbZalcyLLwGi9VzatN6i6Uk4Fs4OUYEn/y5NL9jVMdFvqhWbi 35aQ== X-Gm-Message-State: APjAAAVzV6wPYe/stzxGdXb0YyvRpBTa4udE/L954oY6KgVbcn8ZuUZL wc/GoImlOlP8f5QFrc2heIh2ukhaMaMV6X0lQQGUCoOYMxe9yv8WCKGLV3WzngyEShh4J7CXnnr Cu7bk+UcFeKNL/24MtR8= X-Received: by 2002:a67:7d95:: with SMTP id y143mr2262334vsc.39.1572513667607; Thu, 31 Oct 2019 02:21:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8+C3E7DLExZkum1bP3eG52EbsPBOGAmmCnWfkQJFdv3kpVImrdNOdFYHNCdvcmejBisuxxtsNcCmEFRtn2UA= X-Received: by 2002:a67:7d95:: with SMTP id y143mr2262307vsc.39.1572513667227; Thu, 31 Oct 2019 02:21:07 -0700 (PDT) MIME-Version: 1.0 References: <20191028090907.824-1-pbhagavatula@marvell.com> In-Reply-To: <20191028090907.824-1-pbhagavatula@marvell.com> From: David Marchand Date: Thu, 31 Oct 2019 10:20:55 +0100 Message-ID: To: Pavan Nikhilesh Cc: Wenzhuo Lu , Jingjing Wu , Bernard Iremonger , Olivier Matz , Bruce Richardson , Vladimir Medvedkin , Anatoly Burakov , Reshma Pattan , Robert Sanford , Erik Gabriel Carrillo , dev X-MC-Unique: gOpwChzEPnKFg_gE8l6ogQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [dpdk-dev] [PATCH 1/3] app: use RTE_DIM to calculate array size 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" On Mon, Oct 28, 2019 at 10:09 AM wrote: > > From: Pavan Nikhilesh > > Use RTE_DIM macro to calculate array size > > Suggested-by: David Marchand > Signed-off-by: Pavan Nikhilesh Ah, I was not expecting this soon. Thanks for looking at it. > --- > app/test-pmd/cmdline.c | 2 +- > app/test-pmd/icmpecho.c | 2 +- > app/test-pmd/testpmd.c | 2 +- > app/test/test.c | 2 +- > app/test/test_cmdline_etheraddr.c | 10 +++------- > app/test/test_cmdline_ipaddr.c | 18 ++++++------------ > app/test/test_cmdline_num.c | 16 +++++----------- > app/test/test_cmdline_portlist.c | 12 ++++-------- > app/test/test_cmdline_string.c | 15 +++++---------- > app/test/test_debug.c | 2 +- > app/test/test_eal_flags.c | 9 ++++----- > app/test/test_errno.c | 4 ++-- > app/test/test_lpm.c | 2 +- > app/test/test_lpm6.c | 2 +- > app/test/test_lpm6_data.h | 3 +-- > app/test/test_malloc.c | 2 +- > app/test/test_memcpy.c | 2 +- > app/test/test_memcpy_perf.c | 4 ++-- > app/test/test_mp_secondary.c | 3 +-- > app/test/test_pdump.c | 3 +-- > app/test/test_pmd_ring_perf.c | 2 +- > app/test/test_ring_perf.c | 6 +++--- > app/test/test_timer_secondary.c | 3 +-- > 23 files changed, 48 insertions(+), 78 deletions(-) > > diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c > index 447806991..c6b4e44a2 100644 > --- a/app/test-pmd/cmdline.c > +++ b/app/test-pmd/cmdline.c > @@ -5490,7 +5490,7 @@ cmd_show_bypass_config_parsed(void *parsed_result, > "OS/board off", > "power supply off", > "timeout"}; > - int num_events =3D (sizeof events) / (sizeof events[0]); > + int num_events =3D RTE_DIM(events); > > /* Display the bypass mode.*/ > if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) !=3D 0= ) { > diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c > index 2d359c943..65aece16c 100644 > --- a/app/test-pmd/icmpecho.c > +++ b/app/test-pmd/icmpecho.c > @@ -188,7 +188,7 @@ ip_proto_name(uint16_t ip_proto) > "PIM", /**< Protocol Independent Mcast */ > }; > > - if (ip_proto < sizeof(ip_proto_names) / sizeof(ip_proto_names[0])= ) > + if (ip_proto < RTE_DIM(ip_proto_names)) > return ip_proto_names[ip_proto]; > switch (ip_proto) { > #ifdef IPPROTO_PGM > diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c > index 38acbc58a..1103db629 100644 > --- a/app/test-pmd/testpmd.c > +++ b/app/test-pmd/testpmd.c > @@ -2584,7 +2584,7 @@ struct pmd_test_command { > cmd_func_t cmd_func; > }; > > -#define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]= )) > +#define PMD_TEST_CMD_NB RTE_DIM(pmd_test_menu) This macro is just unused and can be shot. > > /* Check the link status of all ports in up to 9s, and print them finall= y */ > static void > diff --git a/app/test/test.c b/app/test/test.c > index cd7aaf645..784535095 100644 > --- a/app/test/test.c > +++ b/app/test/test.c > @@ -74,7 +74,7 @@ do_recursive_call(void) > > if (recursive_call =3D=3D NULL) > return -1; > - for (i =3D 0; i < sizeof(actions)/sizeof(actions[0]); i++) { > + for (i =3D 0; i < RTE_DIM(actions); i++) { > if (strcmp(actions[i].env_var, recursive_call) =3D=3D 0) > return (actions[i].action_fn)(); > } > diff --git a/app/test/test_cmdline_etheraddr.c b/app/test/test_cmdline_et= heraddr.c > index 9a32fd7ec..dc7fa944b 100644 > --- a/app/test/test_cmdline_etheraddr.c > +++ b/app/test/test_cmdline_etheraddr.c > @@ -72,13 +72,9 @@ const char * ether_addr_invalid_strs[] =3D { > " ", > }; > > -#define ETHERADDR_VALID_STRS_SIZE \ > - (sizeof(ether_addr_valid_strs) / sizeof(ether_addr_valid_strs[0])= ) > -#define ETHERADDR_GARBAGE_STRS_SIZE \ > - (sizeof(ether_addr_garbage_strs) / sizeof(ether_addr_garbage_strs= [0])) > -#define ETHERADDR_INVALID_STRS_SIZE \ > - (sizeof(ether_addr_invalid_strs) / sizeof(ether_addr_invalid_strs= [0])) > - > +#define ETHERADDR_VALID_STRS_SIZE RTE_DIM(ether_addr_valid_strs) > +#define ETHERADDR_GARBAGE_STRS_SIZE RTE_DIM(ether_addr_garbage_strs) > +#define ETHERADDR_INVALID_STRS_SIZE RTE_DIM(ether_addr_invalid_strs) Those macros are just used once, in loops enumerating the array entries. Let's remove them and replace inline: /* test full strings */ - for (i =3D 0; i < ETHERADDR_VALID_STRS_SIZE; i++) { + for (i =3D 0; i < RTE_DIM(ether_addr_valid_strs); i++) { etc... > > > static int > diff --git a/app/test/test_cmdline_ipaddr.c b/app/test/test_cmdline_ipadd= r.c > index 2d11ce936..0c90162e8 100644 > --- a/app/test/test_cmdline_ipaddr.c > +++ b/app/test/test_cmdline_ipaddr.c > @@ -264,18 +264,12 @@ const char * ipaddr_invalid_strs[] =3D { > " ", > }; > > -#define IPADDR_VALID_STRS_SIZE \ > - (sizeof(ipaddr_valid_strs) / sizeof(ipaddr_valid_strs[0])) > -#define IPADDR_GARBAGE_ADDR4_STRS_SIZE \ > - (sizeof(ipaddr_garbage_addr4_strs) / sizeof(ipaddr_garbage_addr4_= strs[0])) > -#define IPADDR_GARBAGE_ADDR6_STRS_SIZE \ > - (sizeof(ipaddr_garbage_addr6_strs) / sizeof(ipaddr_garbage_addr6_= strs[0])) > -#define IPADDR_GARBAGE_NETWORK4_STRS_SIZE \ > - (sizeof(ipaddr_garbage_network4_strs) / sizeof(ipaddr_garbage_net= work4_strs[0])) > -#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE \ > - (sizeof(ipaddr_garbage_network6_strs) / sizeof(ipaddr_garbage_net= work6_strs[0])) > -#define IPADDR_INVALID_STRS_SIZE \ > - (sizeof(ipaddr_invalid_strs) / sizeof(ipaddr_invalid_strs[0])) > +#define IPADDR_VALID_STRS_SIZE RTE_DIM(ipaddr_valid_strs) > +#define IPADDR_GARBAGE_ADDR4_STRS_SIZE RTE_DIM(ipaddr_garbage_addr4_strs= ) > +#define IPADDR_GARBAGE_ADDR6_STRS_SIZE RTE_DIM(ipaddr_garbage_addr6_strs= ) > +#define IPADDR_GARBAGE_NETWORK4_STRS_SIZE RTE_DIM(ipaddr_garbage_network= 4_strs) > +#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE RTE_DIM(ipaddr_garbage_network= 6_strs) > +#define IPADDR_INVALID_STRS_SIZE RTE_DIM(ipaddr_invalid_strs) Idem. > > static void > dump_addr(cmdline_ipaddr_t addr) > diff --git a/app/test/test_cmdline_num.c b/app/test/test_cmdline_num.c > index 4c97caf3d..1daeaf840 100644 > --- a/app/test/test_cmdline_num.c > +++ b/app/test/test_cmdline_num.c > @@ -216,17 +216,11 @@ const char * num_invalid_strs[] =3D { > "\0", > }; > > -#define NUM_POSITIVE_STRS_SIZE \ > - (sizeof(num_valid_positive_strs) / sizeof(num_valid_positive_strs= [0])) > -#define NUM_NEGATIVE_STRS_SIZE \ > - (sizeof(num_valid_negative_strs) / sizeof(num_valid_negative_strs= [0])) > -#define NUM_POSITIVE_GARBAGE_STRS_SIZE \ > - (sizeof(num_garbage_positive_strs) / sizeof(num_garbage_positive_= strs[0])) > -#define NUM_NEGATIVE_GARBAGE_STRS_SIZE \ > - (sizeof(num_garbage_negative_strs) / sizeof(num_garbage_negative_= strs[0])) > -#define NUM_INVALID_STRS_SIZE \ > - (sizeof(num_invalid_strs) / sizeof(num_invalid_strs[0])) > - > +#define NUM_POSITIVE_STRS_SIZE RTE_DIM(num_valid_positive_strs) > +#define NUM_NEGATIVE_STRS_SIZE RTE_DIM(num_valid_negative_strs) > +#define NUM_POSITIVE_GARBAGE_STRS_SIZE RTE_DIM(num_garbage_positive_strs= ) > +#define NUM_NEGATIVE_GARBAGE_STRS_SIZE RTE_DIM(num_garbage_negative_strs= ) > +#define NUM_INVALID_STRS_SIZE RTE_DIM(num_invalid_strs) Idem. Stopping at this, I suppose you get the idea for the rest of the changes. Thanks. --=20 David Marchand