DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev]  [PATCH 1/3] app: use RTE_DIM to calculate array size
@ 2019-10-28  9:09 pbhagavatula
  2019-10-28  9:09 ` [dpdk-dev] [PATCH 2/3] examples: " pbhagavatula
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: pbhagavatula @ 2019-10-28  9:09 UTC (permalink / raw)
  To: Wenzhuo Lu, Jingjing Wu, Bernard Iremonger, Olivier Matz,
	Bruce Richardson, Vladimir Medvedkin, Anatoly Burakov,
	Reshma Pattan, Robert Sanford, Erik Gabriel Carrillo
  Cc: dev, Pavan Nikhilesh

From: Pavan Nikhilesh <pbhagavatula@marvell.com>

Use RTE_DIM macro to calculate array size

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 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 = (sizeof events) / (sizeof events[0]);
+	int num_events = RTE_DIM(events);

 	/* Display the bypass mode.*/
 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 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)

 /* Check the link status of all ports in up to 9s, and print them finally */
 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 == NULL)
 		return -1;
-	for (i = 0; i < sizeof(actions)/sizeof(actions[0]); i++) {
+	for (i = 0; i < RTE_DIM(actions); i++) {
 		if (strcmp(actions[i].env_var, recursive_call) == 0)
 			return (actions[i].action_fn)();
 	}
diff --git a/app/test/test_cmdline_etheraddr.c b/app/test/test_cmdline_etheraddr.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[] = {
 		" ",
 };

-#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)


 static int
diff --git a/app/test/test_cmdline_ipaddr.c b/app/test/test_cmdline_ipaddr.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[] = {
 		" ",
 };

-#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_network4_strs[0]))
-#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE \
-	(sizeof(ipaddr_garbage_network6_strs) / sizeof(ipaddr_garbage_network6_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_network4_strs)
+#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE RTE_DIM(ipaddr_garbage_network6_strs)
+#define IPADDR_INVALID_STRS_SIZE RTE_DIM(ipaddr_invalid_strs)

 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[] = {
 		"\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)


 static int
diff --git a/app/test/test_cmdline_portlist.c b/app/test/test_cmdline_portlist.c
index 0dc6d0030..851215377 100644
--- a/app/test/test_cmdline_portlist.c
+++ b/app/test/test_cmdline_portlist.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <inttypes.h>

+#include <rte_common.h>
 #include <cmdline_parse.h>
 #include <cmdline_parse_portlist.h>

@@ -88,14 +89,9 @@ const char * portlist_invalid_strs[] = {
 		"0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,2",
 };

-#define PORTLIST_VALID_STRS_SIZE \
-	(sizeof(portlist_valid_strs) / sizeof(portlist_valid_strs[0]))
-#define PORTLIST_GARBAGE_STRS_SIZE \
-	(sizeof(portlist_garbage_strs) / sizeof(portlist_garbage_strs[0]))
-#define PORTLIST_INVALID_STRS_SIZE \
-	(sizeof(portlist_invalid_strs) / sizeof(portlist_invalid_strs[0]))
-
-
+#define PORTLIST_VALID_STRS_SIZE RTE_DIM(portlist_valid_strs)
+#define PORTLIST_GARBAGE_STRS_SIZE RTE_DIM(portlist_garbage_strs)
+#define PORTLIST_INVALID_STRS_SIZE RTE_DIM(portlist_invalid_strs)


 /* test invalid parameters */
diff --git a/app/test/test_cmdline_string.c b/app/test/test_cmdline_string.c
index 0461a85bb..f6ac76fc9 100644
--- a/app/test/test_cmdline_string.c
+++ b/app/test/test_cmdline_string.c
@@ -115,16 +115,11 @@ const char * string_help_strs[] = {



-#define STRING_PARSE_STRS_SIZE \
-	(sizeof(string_parse_strs) / sizeof(string_parse_strs[0]))
-#define STRING_HELP_STRS_SIZE \
-	(sizeof(string_help_strs) / sizeof(string_help_strs[0]))
-#define STRING_ELT_STRS_SIZE \
-	(sizeof(string_elt_strs) / sizeof(string_elt_strs[0]))
-#define STRING_NB_STRS_SIZE \
-	(sizeof(string_nb_strs) / sizeof(string_nb_strs[0]))
-#define STRING_INVALID_STRS_SIZE \
-	(sizeof(string_invalid_strs) / sizeof(string_invalid_strs[0]))
+#define STRING_PARSE_STRS_SIZE RTE_DIM(string_parse_strs)
+#define STRING_HELP_STRS_SIZE RTE_DIM(string_help_strs)
+#define STRING_ELT_STRS_SIZE RTE_DIM(string_elt_strs)
+#define STRING_NB_STRS_SIZE RTE_DIM(string_nb_strs)
+#define STRING_INVALID_STRS_SIZE RTE_DIM(string_invalid_strs)

 #define SMALL_BUF 8

diff --git a/app/test/test_debug.c b/app/test/test_debug.c
index faf2cf557..25eab97e2 100644
--- a/app/test/test_debug.c
+++ b/app/test/test_debug.c
@@ -81,7 +81,7 @@ test_exit(void)
 {
 	int test_vals[] = { 0, 1, 2, 255, -1 };
 	unsigned i;
-	for (i = 0; i < sizeof(test_vals) / sizeof(test_vals[0]); i++){
+	for (i = 0; i < RTE_DIM(test_vals); i++) {
 		if (test_exit_val(test_vals[i]) < 0)
 			return -1;
 	}
diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c
index 5b2c0f5cd..4ee809e3d 100644
--- a/app/test/test_eal_flags.c
+++ b/app/test/test_eal_flags.c
@@ -36,8 +36,7 @@
 #define memtest1 "memtest1"
 #define memtest2 "memtest2"
 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
-#define launch_proc(ARGV) process_dup(ARGV, \
-		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 enum hugepage_action {
 	HUGEPAGE_CHECK_EXISTS = 0,
@@ -268,7 +267,7 @@ test_whitelist_flag(void)
 			pci_whitelist, "08:00.1,type=normal",
 	};

-	for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
+	for (i = 0; i < RTE_DIM(wlinval); i++) {
 		if (launch_proc(wlinval[i]) == 0) {
 			printf("Error - process did run ok with invalid "
 			    "whitelist parameter\n");
@@ -324,7 +323,7 @@ test_invalid_b_flag(void)

 	int i;

-	for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
+	for (i = 0; i != RTE_DIM(blinval); i++) {
 		if (launch_proc(blinval[i]) == 0) {
 			printf("Error - process did run ok with invalid "
 			    "blacklist parameter\n");
@@ -425,7 +424,7 @@ test_invalid_r_flag(void)

 	int i;

-	for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
+	for (i = 0; i != RTE_DIM(rinval); i++) {
 		if (launch_proc(rinval[i]) == 0) {
 			printf("Error - process did run ok with invalid "
 			    "-r (rank) parameter\n");
diff --git a/app/test/test_errno.c b/app/test/test_errno.c
index 7df8192d5..3ff0456a5 100644
--- a/app/test/test_errno.c
+++ b/app/test/test_errno.c
@@ -36,7 +36,7 @@ test_errno(void)
 	if (rte_errno != 0)
 		return -1;
 	/* check for standard errors we return the same as libc */
-	for (i = 0; i < sizeof(std_errs)/sizeof(std_errs[0]); i++){
+	for (i = 0; i < RTE_DIM(std_errs); i++) {
 		rte_retval = rte_strerror(std_errs[i]);
 		libc_retval = strerror(std_errs[i]);
 		printf("rte_strerror: '%s', strerror: '%s'\n",
@@ -47,7 +47,7 @@ test_errno(void)
 	/* for rte-specific errors ensure we return a different string
 	 * and that the string for libc is for an unknown error
 	 */
-	for (i = 0; i < sizeof(rte_errs)/sizeof(rte_errs[0]); i++){
+	for (i = 0; i < RTE_DIM(rte_errs); i++) {
 		rte_retval = rte_strerror(rte_errs[i]);
 		libc_retval = strerror(rte_errs[i]);
 		printf("rte_strerror: '%s', strerror: '%s'\n",
diff --git a/app/test/test_lpm.c b/app/test/test_lpm.c
index e969fe051..68f000c1b 100644
--- a/app/test/test_lpm.c
+++ b/app/test/test_lpm.c
@@ -64,7 +64,7 @@ rte_lpm_test tests[] = {
 	test18
 };

-#define NUM_LPM_TESTS (sizeof(tests)/sizeof(tests[0]))
+#define NUM_LPM_TESTS RTE_DIM(tests)
 #define MAX_DEPTH 32
 #define MAX_RULES 256
 #define NUMBER_TBL8S 256
diff --git a/app/test/test_lpm6.c b/app/test/test_lpm6.c
index 670aadb40..1df4af257 100644
--- a/app/test/test_lpm6.c
+++ b/app/test/test_lpm6.c
@@ -85,7 +85,7 @@ rte_lpm6_test tests6[] = {
 	test28,
 };

-#define NUM_LPM6_TESTS                (sizeof(tests6)/sizeof(tests6[0]))
+#define NUM_LPM6_TESTS                                   RTE_DIM(tests6)
 #define MAX_DEPTH                                                    128
 #define MAX_RULES                                                1000000
 #define NUMBER_TBL8S                                           (1 << 16)
diff --git a/app/test/test_lpm6_data.h b/app/test/test_lpm6_data.h
index 565138a31..c3894f730 100644
--- a/app/test/test_lpm6_data.h
+++ b/app/test/test_lpm6_data.h
@@ -1029,8 +1029,7 @@ static struct rules_tbl_entry large_route_table[] = {
 	{{234, 149, 220, 106, 0, 144, 214, 128, 35, 102, 0, 0, 0, 0, 0, 0}, 79, 106},
 };

-#define  NUM_ROUTE_ENTRIES \
-	(sizeof(large_route_table) / sizeof(large_route_table[0]))
+#define  NUM_ROUTE_ENTRIES RTE_DIM(large_route_table)

 #define  NUM_IPS_ENTRIES (NUM_ROUTE_ENTRIES * 100)

diff --git a/app/test/test_malloc.c b/app/test/test_malloc.c
index a16e28cc3..67a48ba38 100644
--- a/app/test/test_malloc.c
+++ b/app/test/test_malloc.c
@@ -255,7 +255,7 @@ test_str_to_size(void)
 			{"18446744073709551616", 0} /* ULLONG_MAX + 1 == out of range*/
 	};
 	unsigned i;
-	for (i = 0; i < sizeof(test_values)/sizeof(test_values[0]); i++)
+	for (i = 0; i < RTE_DIM(test_values); i++)
 		if (rte_str_to_size(test_values[i].str) != test_values[i].value)
 			return -1;
 	return 0;
diff --git a/app/test/test_memcpy.c b/app/test/test_memcpy.c
index 2c69ad964..53eb8433a 100644
--- a/app/test/test_memcpy.c
+++ b/app/test/test_memcpy.c
@@ -103,7 +103,7 @@ static int
 func_test(void)
 {
 	unsigned int off_src, off_dst, i;
-	unsigned int num_buf_sizes = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
+	unsigned int num_buf_sizes = RTE_DIM(buf_sizes);
 	int ret;

 	for (off_src = 0; off_src < ALIGNMENT_UNIT; off_src++) {
diff --git a/app/test/test_memcpy_perf.c b/app/test/test_memcpy_perf.c
index 6f436f3ef..8f06b0f1e 100644
--- a/app/test/test_memcpy_perf.c
+++ b/app/test/test_memcpy_perf.c
@@ -250,7 +250,7 @@ perf_test_constant_unaligned(void)
 static inline void
 perf_test_variable_aligned(void)
 {
-	unsigned n = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
+	unsigned n = RTE_DIM(buf_sizes);
 	unsigned i;
 	for (i = 0; i < n; i++) {
 		ALL_PERF_TESTS_FOR_SIZE((size_t)buf_sizes[i]);
@@ -261,7 +261,7 @@ perf_test_variable_aligned(void)
 static inline void
 perf_test_variable_unaligned(void)
 {
-	unsigned n = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
+	unsigned n = RTE_DIM(buf_sizes);
 	unsigned i;
 	for (i = 0; i < n; i++) {
 		ALL_PERF_TESTS_FOR_SIZE_UNALIGNED((size_t)buf_sizes[i]);
diff --git a/app/test/test_mp_secondary.c b/app/test/test_mp_secondary.c
index 2ac33f781..ac15ddbf2 100644
--- a/app/test/test_mp_secondary.c
+++ b/app/test/test_mp_secondary.c
@@ -47,8 +47,7 @@

 #include "process.h"

-#define launch_proc(ARGV) process_dup(ARGV, \
-		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 /*
  * This function is called in the primary i.e. main test, to spawn off secondary
diff --git a/app/test/test_pdump.c b/app/test/test_pdump.c
index af206968b..ad183184c 100644
--- a/app/test/test_pdump.c
+++ b/app/test/test_pdump.c
@@ -18,8 +18,7 @@
 #include "process.h"
 #include "test_pdump.h"

-#define launch_p(ARGV) process_dup(ARGV, \
-		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_p(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 struct rte_ring *ring_server;
 uint16_t portid;
diff --git a/app/test/test_pmd_ring_perf.c b/app/test/test_pmd_ring_perf.c
index 6318da18f..3b2ff9cb4 100644
--- a/app/test/test_pmd_ring_perf.c
+++ b/app/test/test_pmd_ring_perf.c
@@ -100,7 +100,7 @@ test_bulk_enqueue_dequeue(void)
 	unsigned sz, i = 0;
 	struct rte_mbuf *burst[MAX_BURST] = {0};

-	for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
+	for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
 		const uint64_t sc_start = rte_rdtsc();
 		for (i = 0; i < iterations; i++) {
 			rte_ring_sp_enqueue_bulk(r, (void *)burst,
diff --git a/app/test/test_ring_perf.c b/app/test/test_ring_perf.c
index 70ee46ffe..f2accb8a0 100644
--- a/app/test/test_ring_perf.c
+++ b/app/test/test_ring_perf.c
@@ -240,7 +240,7 @@ run_on_core_pair(struct lcore_pair *cores, struct rte_ring *r,
 {
 	struct thread_params param1 = {0}, param2 = {0};
 	unsigned i;
-	for (i = 0; i < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); i++) {
+	for (i = 0; i < RTE_DIM(bulk_sizes); i++) {
 		lcore_count = 0;
 		param1.size = param2.size = bulk_sizes[i];
 		param1.r = param2.r = r;
@@ -376,7 +376,7 @@ test_burst_enqueue_dequeue(struct rte_ring *r)
 	unsigned sz, i = 0;
 	void *burst[MAX_BURST] = {0};

-	for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
+	for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
 		const uint64_t sc_start = rte_rdtsc();
 		for (i = 0; i < iterations; i++) {
 			rte_ring_sp_enqueue_burst(r, burst,
@@ -414,7 +414,7 @@ test_bulk_enqueue_dequeue(struct rte_ring *r)
 	unsigned sz, i = 0;
 	void *burst[MAX_BURST] = {0};

-	for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
+	for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
 		const uint64_t sc_start = rte_rdtsc();
 		for (i = 0; i < iterations; i++) {
 			rte_ring_sp_enqueue_bulk(r, burst,
diff --git a/app/test/test_timer_secondary.c b/app/test/test_timer_secondary.c
index 790f18052..7a3bc873b 100644
--- a/app/test/test_timer_secondary.c
+++ b/app/test/test_timer_secondary.c
@@ -23,8 +23,7 @@
 #define TEST_INFO_MZ_NAME	"test_timer_info_mz"
 #define MSECPERSEC		1E3

-#define launch_proc(ARGV) \
-	process_dup(ARGV, sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 struct test_info {
 	unsigned int mstr_lcore;
--
2.23.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH 2/3] examples: use RTE_DIM to calculate array size
  2019-10-28  9:09 [dpdk-dev] [PATCH 1/3] app: use RTE_DIM to calculate array size pbhagavatula
@ 2019-10-28  9:09 ` pbhagavatula
  2019-10-28  9:09 ` [dpdk-dev] [PATCH 3/3] lib: " pbhagavatula
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: pbhagavatula @ 2019-10-28  9:09 UTC (permalink / raw)
  To: Cristian Dumitrescu, Marko Kovacevic, Ori Kam, Bruce Richardson,
	Radu Nicolau, Akhil Goyal, Tomasz Kantecki, David Hunt,
	John McNamara, Harry van Haaren, Xiaoyun Li
  Cc: dev, Pavan Nikhilesh

From: Pavan Nikhilesh <pbhagavatula@marvell.com>

use RTE_DIM macro to calculate array size.

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 examples/ip_pipeline/parser.c  |  2 +-
 examples/ipv4_multicast/main.c |  3 +--
 examples/l3fwd-power/main.c    | 12 ++++--------
 examples/l3fwd/l3fwd_em.c      |  6 ++----
 examples/l3fwd/l3fwd_lpm.c     |  6 ++----
 examples/vmdq/main.c           |  2 +-
 examples/vmdq_dcb/main.c       |  2 +-
 7 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/examples/ip_pipeline/parser.c b/examples/ip_pipeline/parser.c
index 3fffeb586..fb0769fe3 100644
--- a/examples/ip_pipeline/parser.c
+++ b/examples/ip_pipeline/parser.c
@@ -528,7 +528,7 @@ my_ether_aton(const char *a)
 		if (errno != 0 || end == a || (end[0] != ':' && end[0] != 0))
 			return NULL;
 		a = end + 1;
-	} while (++i != sizeof(o) / sizeof(o[0]) && end[0] != 0);
+	} while (++i != RTE_DIM(o) && end[0] != 0);

 	/* Junk at the end of line */
 	if (end[0] != 0)
diff --git a/examples/ipv4_multicast/main.c b/examples/ipv4_multicast/main.c
index 63333b5b6..cd2851c1c 100644
--- a/examples/ipv4_multicast/main.c
+++ b/examples/ipv4_multicast/main.c
@@ -155,8 +155,7 @@ static struct mcast_group_params mcast_group_table[] = {
 		{RTE_IPV4(224,0,0,115), 0xF},
 };

-#define N_MCAST_GROUPS \
-	(sizeof (mcast_group_table) / sizeof (mcast_group_table[0]))
+#define N_MCAST_GROUPS RTE_DIM(mcast_group_table)


 /* Send burst of packets on an output interface */
diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index d049d8a5d..2a56bfa8c 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -238,8 +238,7 @@ static struct lcore_params lcore_params_array_default[] = {
 };

 struct lcore_params *lcore_params = lcore_params_array_default;
-uint16_t nb_lcore_params = sizeof(lcore_params_array_default) /
-				sizeof(lcore_params_array_default[0]);
+uint16_t nb_lcore_params = RTE_DIM(lcore_params_array_default);

 static struct rte_eth_conf port_conf = {
 	.rxmode = {
@@ -326,11 +325,9 @@ static lookup_struct_t *ipv6_l3fwd_lookup_struct[NB_SOCKETS];

 #define L3FWD_HASH_ENTRIES	1024

-#define IPV4_L3FWD_NUM_ROUTES \
-	(sizeof(ipv4_l3fwd_route_array) / sizeof(ipv4_l3fwd_route_array[0]))
+#define IPV4_L3FWD_NUM_ROUTES RTE_DIM(ipv4_l3fwd_route_array)

-#define IPV6_L3FWD_NUM_ROUTES \
-	(sizeof(ipv6_l3fwd_route_array) / sizeof(ipv6_l3fwd_route_array[0]))
+#define IPV6_L3FWD_NUM_ROUTES RTE_DIM(ipv6_l3fwd_route_array)

 static uint16_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
 static uint16_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
@@ -354,8 +351,7 @@ static struct ipv4_l3fwd_route ipv4_l3fwd_route_array[] = {
 	{RTE_IPV4(8,1,1,0), 24, 7},
 };

-#define IPV4_L3FWD_NUM_ROUTES \
-	(sizeof(ipv4_l3fwd_route_array) / sizeof(ipv4_l3fwd_route_array[0]))
+#define IPV4_L3FWD_NUM_ROUTES RTE_DIM(ipv4_l3fwd_route_array)

 #define IPV4_L3FWD_LPM_MAX_RULES     1024

diff --git a/examples/l3fwd/l3fwd_em.c b/examples/l3fwd/l3fwd_em.c
index 74a7c8fa4..1b1cce47d 100644
--- a/examples/l3fwd/l3fwd_em.c
+++ b/examples/l3fwd/l3fwd_em.c
@@ -203,11 +203,9 @@ ipv6_hash_crc(const void *data, __rte_unused uint32_t data_len,
 	return init_val;
 }

-#define IPV4_L3FWD_EM_NUM_ROUTES \
-	(sizeof(ipv4_l3fwd_em_route_array) / sizeof(ipv4_l3fwd_em_route_array[0]))
+#define IPV4_L3FWD_EM_NUM_ROUTES RTE_DIM(ipv4_l3fwd_em_route_array)

-#define IPV6_L3FWD_EM_NUM_ROUTES \
-	(sizeof(ipv6_l3fwd_em_route_array) / sizeof(ipv6_l3fwd_em_route_array[0]))
+#define IPV6_L3FWD_EM_NUM_ROUTES RTE_DIM(ipv6_l3fwd_em_route_array)

 static uint8_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
 static uint8_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
diff --git a/examples/l3fwd/l3fwd_lpm.c b/examples/l3fwd/l3fwd_lpm.c
index a3a65f7fc..848b8135b 100644
--- a/examples/l3fwd/l3fwd_lpm.c
+++ b/examples/l3fwd/l3fwd_lpm.c
@@ -65,10 +65,8 @@ static struct ipv6_l3fwd_lpm_route ipv6_l3fwd_lpm_route_array[] = {
 	{{32, 1, 2, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0}, 48, 7},
 };

-#define IPV4_L3FWD_LPM_NUM_ROUTES \
-	(sizeof(ipv4_l3fwd_lpm_route_array) / sizeof(ipv4_l3fwd_lpm_route_array[0]))
-#define IPV6_L3FWD_LPM_NUM_ROUTES \
-	(sizeof(ipv6_l3fwd_lpm_route_array) / sizeof(ipv6_l3fwd_lpm_route_array[0]))
+#define IPV4_L3FWD_LPM_NUM_ROUTES RTE_DIM(ipv4_l3fwd_lpm_route_array)
+#define IPV6_L3FWD_LPM_NUM_ROUTES RTE_DIM(ipv6_l3fwd_lpm_route_array)

 #define IPV4_L3FWD_LPM_MAX_RULES         1024
 #define IPV4_L3FWD_LPM_NUMBER_TBL8S (1 << 8)
diff --git a/examples/vmdq/main.c b/examples/vmdq/main.c
index 6e6fc91ec..011110920 100644
--- a/examples/vmdq/main.c
+++ b/examples/vmdq/main.c
@@ -503,7 +503,7 @@ lcore_main(__attribute__((__unused__)) void *dummy)

 	for (;;) {
 		struct rte_mbuf *buf[MAX_PKT_BURST];
-		const uint16_t buf_size = sizeof(buf) / sizeof(buf[0]);
+		const uint16_t buf_size = RTE_DIM(buf);

 		for (p = 0; p < num_ports; p++) {
 			const uint8_t sport = ports[p];
diff --git a/examples/vmdq_dcb/main.c b/examples/vmdq_dcb/main.c
index 594c4f195..f417b2fd9 100644
--- a/examples/vmdq_dcb/main.c
+++ b/examples/vmdq_dcb/main.c
@@ -582,7 +582,7 @@ lcore_main(void *arg)

 	for (;;) {
 		struct rte_mbuf *buf[MAX_PKT_BURST];
-		const uint16_t buf_size = sizeof(buf) / sizeof(buf[0]);
+		const uint16_t buf_size = RTE_DIM(buf);
 		for (p = 0; p < num_ports; p++) {
 			const uint8_t src = ports[p];
 			const uint8_t dst = ports[p ^ 1]; /* 0 <-> 1, 2 <-> 3 etc */
--
2.23.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev]  [PATCH 3/3] lib: use RTE_DIM to calculate array size
  2019-10-28  9:09 [dpdk-dev] [PATCH 1/3] app: use RTE_DIM to calculate array size pbhagavatula
  2019-10-28  9:09 ` [dpdk-dev] [PATCH 2/3] examples: " pbhagavatula
@ 2019-10-28  9:09 ` pbhagavatula
  2019-10-31  9:20 ` [dpdk-dev] [PATCH 1/3] app: " David Marchand
  2019-11-07  2:58 ` [dpdk-dev] [PATCH v2 " pbhagavatula
  3 siblings, 0 replies; 16+ messages in thread
From: pbhagavatula @ 2019-10-28  9:09 UTC (permalink / raw)
  To: Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko,
	Konstantin Ananyev, Cristian Dumitrescu
  Cc: dev, Pavan Nikhilesh

From: Pavan Nikhilesh <pbhagavatula@marvell.com>

use RTE_DIM to calculate array size.

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 lib/librte_ethdev/rte_ethdev.c        | 8 +++-----
 lib/librte_ip_frag/ip_frag_internal.c | 5 ++---
 lib/librte_port/rte_port_eventdev.c   | 4 ++--
 lib/librte_port/rte_port_eventdev.h   | 4 ----
 4 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 7743205d3..721ee694b 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -86,7 +86,7 @@ static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
 		rx_nombuf)},
 };

-#define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
+#define RTE_NB_STATS RTE_DIM(rte_stats_strings)

 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
 	{"packets", offsetof(struct rte_eth_stats, q_ipackets)},
@@ -94,15 +94,13 @@ static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
 	{"errors", offsetof(struct rte_eth_stats, q_errors)},
 };

-#define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) /	\
-		sizeof(rte_rxq_stats_strings[0]))
+#define RTE_NB_RXQ_STATS RTE_DIM(rte_rxq_stats_strings)

 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
 	{"packets", offsetof(struct rte_eth_stats, q_opackets)},
 	{"bytes", offsetof(struct rte_eth_stats, q_obytes)},
 };
-#define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) /	\
-		sizeof(rte_txq_stats_strings[0]))
+#define RTE_NB_TXQ_STATS RTE_DIM(rte_txq_stats_strings)

 #define RTE_RX_OFFLOAD_BIT2STR(_name)	\
 	{ DEV_RX_OFFLOAD_##_name, #_name }
diff --git a/lib/librte_ip_frag/ip_frag_internal.c b/lib/librte_ip_frag/ip_frag_internal.c
index 97470a872..b436a4c93 100644
--- a/lib/librte_ip_frag/ip_frag_internal.c
+++ b/lib/librte_ip_frag/ip_frag_internal.c
@@ -107,8 +107,7 @@ ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr,
 				IP_LAST_FRAG_IDX : UINT32_MAX;

 	/* this is the intermediate fragment. */
-	} else if ((idx = fp->last_idx) <
-		sizeof (fp->frags) / sizeof (fp->frags[0])) {
+	} else if ((idx = fp->last_idx) < RTE_DIM(fp->frags)) {
 		fp->last_idx++;
 	}

@@ -116,7 +115,7 @@ ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr,
 	 * erroneous packet: either exceed max allowed number of fragments,
 	 * or duplicate first/last fragment encountered.
 	 */
-	if (idx >= sizeof (fp->frags) / sizeof (fp->frags[0])) {
+	if (idx >= RTE_DIM(fp->frags)) {

 		/* report an error. */
 		if (fp->key.key_len == IPV4_KEYLEN)
diff --git a/lib/librte_port/rte_port_eventdev.c b/lib/librte_port/rte_port_eventdev.c
index aa93bd3a2..fd7dac9a5 100644
--- a/lib/librte_port/rte_port_eventdev.c
+++ b/lib/librte_port/rte_port_eventdev.c
@@ -179,7 +179,7 @@ rte_port_eventdev_writer_create(void *params, int socket_id)
 	port->evt_op = conf->evt_op;
 	memset(&port->ev, 0, sizeof(port->ev));

-	for (i = 0; i < ARRAY_SIZE(port->ev); i++) {
+	for (i = 0; i < RTE_DIM(port->ev); i++) {
 		port->ev[i].queue_id = port->queue_id;
 		port->ev[i].sched_type = port->sched_type;
 		port->ev[i].op = port->evt_op;
@@ -386,7 +386,7 @@ rte_port_eventdev_writer_nodrop_create(void *params, int socket_id)
 	port->evt_op = conf->evt_op;
 	memset(&port->ev, 0, sizeof(port->ev));

-	for (i = 0; i < ARRAY_SIZE(port->ev); i++) {
+	for (i = 0; i < RTE_DIM(port->ev); i++) {
 		port->ev[i].queue_id = port->queue_id;
 		port->ev[i].sched_type = port->sched_type;
 		port->ev[i].op = port->evt_op;
diff --git a/lib/librte_port/rte_port_eventdev.h b/lib/librte_port/rte_port_eventdev.h
index acf88f4e9..966e9cdaf 100644
--- a/lib/librte_port/rte_port_eventdev.h
+++ b/lib/librte_port/rte_port_eventdev.h
@@ -9,10 +9,6 @@
 extern "C" {
 #endif

-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 /**
  * @file
  * RTE Port Eventdev Interface
--
2.23.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH 1/3] app: use RTE_DIM to calculate array size
  2019-10-28  9:09 [dpdk-dev] [PATCH 1/3] app: use RTE_DIM to calculate array size pbhagavatula
  2019-10-28  9:09 ` [dpdk-dev] [PATCH 2/3] examples: " pbhagavatula
  2019-10-28  9:09 ` [dpdk-dev] [PATCH 3/3] lib: " pbhagavatula
@ 2019-10-31  9:20 ` David Marchand
  2019-11-07  2:12   ` [dpdk-dev] [EXT] " Pavan Nikhilesh Bhagavatula
  2019-11-07  2:58 ` [dpdk-dev] [PATCH v2 " pbhagavatula
  3 siblings, 1 reply; 16+ messages in thread
From: David Marchand @ 2019-10-31  9:20 UTC (permalink / raw)
  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

On Mon, Oct 28, 2019 at 10:09 AM <pbhagavatula@marvell.com> wrote:
>
> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
>
> Use RTE_DIM macro to calculate array size
>
> Suggested-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>

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 = (sizeof events) / (sizeof events[0]);
> +       int num_events = RTE_DIM(events);
>
>         /* Display the bypass mode.*/
>         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 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 finally */
>  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 == NULL)
>                 return -1;
> -       for (i = 0; i < sizeof(actions)/sizeof(actions[0]); i++) {
> +       for (i = 0; i < RTE_DIM(actions); i++) {
>                 if (strcmp(actions[i].env_var, recursive_call) == 0)
>                         return (actions[i].action_fn)();
>         }
> diff --git a/app/test/test_cmdline_etheraddr.c b/app/test/test_cmdline_etheraddr.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[] = {
>                 " ",
>  };
>
> -#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 = 0; i < ETHERADDR_VALID_STRS_SIZE; i++) {
+       for (i = 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_ipaddr.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[] = {
>                 " ",
>  };
>
> -#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_network4_strs[0]))
> -#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE \
> -       (sizeof(ipaddr_garbage_network6_strs) / sizeof(ipaddr_garbage_network6_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_network4_strs)
> +#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE RTE_DIM(ipaddr_garbage_network6_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[] = {
>                 "\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.

-- 
David Marchand


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [EXT] Re: [PATCH 1/3] app: use RTE_DIM to calculate array size
  2019-10-31  9:20 ` [dpdk-dev] [PATCH 1/3] app: " David Marchand
@ 2019-11-07  2:12   ` Pavan Nikhilesh Bhagavatula
  0 siblings, 0 replies; 16+ messages in thread
From: Pavan Nikhilesh Bhagavatula @ 2019-11-07  2:12 UTC (permalink / raw)
  To: David Marchand
  Cc: Wenzhuo Lu, Jingjing Wu, Bernard Iremonger, Olivier Matz,
	Bruce Richardson, Vladimir Medvedkin, Anatoly Burakov,
	Reshma Pattan, Robert Sanford, Erik Gabriel Carrillo, dev

>On Mon, Oct 28, 2019 at 10:09 AM <pbhagavatula@marvell.com> wrote:
>>
>> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
>>
>> Use RTE_DIM macro to calculate array size
>>
>> Suggested-by: David Marchand <david.marchand@redhat.com>
>> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
>
>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 = (sizeof events) / (sizeof events[0]);
>> +       int num_events = RTE_DIM(events);
>>
>>         /* Display the bypass mode.*/
>>         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode)
>!= 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.

Ill send v2 removing the macros. 

Thanks.
>
>
>>
>>  /* Check the link status of all ports in up to 9s, and print them finally
>*/
>>  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 == NULL)
>>                 return -1;
>> -       for (i = 0; i < sizeof(actions)/sizeof(actions[0]); i++) {
>> +       for (i = 0; i < RTE_DIM(actions); i++) {
>>                 if (strcmp(actions[i].env_var, recursive_call) == 0)
>>                         return (actions[i].action_fn)();
>>         }
>> diff --git a/app/test/test_cmdline_etheraddr.c
>b/app/test/test_cmdline_etheraddr.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[] = {
>>                 " ",
>>  };
>>
>> -#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 = 0; i < ETHERADDR_VALID_STRS_SIZE; i++) {
>+       for (i = 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_ipaddr.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[] = {
>>                 " ",
>>  };
>>
>> -#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_network4_strs[0]))
>> -#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE \
>> -       (sizeof(ipaddr_garbage_network6_strs) /
>sizeof(ipaddr_garbage_network6_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_network4_strs)
>> +#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE
>RTE_DIM(ipaddr_garbage_network6_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[] = {
>>                 "\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.
>
>--
>David Marchand


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH v2 1/3] app: use RTE_DIM to calculate array size
  2019-10-28  9:09 [dpdk-dev] [PATCH 1/3] app: use RTE_DIM to calculate array size pbhagavatula
                   ` (2 preceding siblings ...)
  2019-10-31  9:20 ` [dpdk-dev] [PATCH 1/3] app: " David Marchand
@ 2019-11-07  2:58 ` pbhagavatula
  2019-11-07  2:58   ` [dpdk-dev] [PATCH v2 2/3] examples: " pbhagavatula
                     ` (3 more replies)
  3 siblings, 4 replies; 16+ messages in thread
From: pbhagavatula @ 2019-11-07  2:58 UTC (permalink / raw)
  To: david.marchand, Wenzhuo Lu, Jingjing Wu, Bernard Iremonger,
	Olivier Matz, Bruce Richardson, Vladimir Medvedkin,
	Anatoly Burakov, Reshma Pattan, Robert Sanford,
	Erik Gabriel Carrillo
  Cc: dev, Pavan Nikhilesh

From: Pavan Nikhilesh <pbhagavatula@marvell.com>

Use RTE_DIM macro to calculate array size

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 v2 Changes:
 ----------
 - remove macros that are used only once.(David)

 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 | 15 +++------------
 app/test/test_cmdline_ipaddr.c    | 25 ++++++-------------------
 app/test/test_cmdline_num.c       | 23 +++++------------------
 app/test/test_cmdline_portlist.c  | 17 ++++-------------
 app/test/test_cmdline_string.c    | 23 +++++------------------
 app/test/test_debug.c             |  2 +-
 app/test/test_eal_flags.c         |  9 ++++-----
 app/test/test_errno.c             |  4 ++--
 app/test/test_lpm.c               |  3 +--
 app/test/test_lpm6.c              |  3 +--
 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, 47 insertions(+), 113 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 = (sizeof events) / (sizeof events[0]);
+	int num_events = RTE_DIM(events);

 	/* Display the bypass mode.*/
 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 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..f7746b481 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2584,8 +2584,6 @@ struct pmd_test_command {
 	cmd_func_t cmd_func;
 };

-#define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]))
-
 /* Check the link status of all ports in up to 9s, and print them finally */
 static void
 check_all_ports_link_status(uint32_t port_mask)
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 == NULL)
 		return -1;
-	for (i = 0; i < sizeof(actions)/sizeof(actions[0]); i++) {
+	for (i = 0; i < RTE_DIM(actions); i++) {
 		if (strcmp(actions[i].env_var, recursive_call) == 0)
 			return (actions[i].action_fn)();
 	}
diff --git a/app/test/test_cmdline_etheraddr.c b/app/test/test_cmdline_etheraddr.c
index 9a32fd7ec..9691c32ba 100644
--- a/app/test/test_cmdline_etheraddr.c
+++ b/app/test/test_cmdline_etheraddr.c
@@ -72,15 +72,6 @@ const char * ether_addr_invalid_strs[] = {
 		" ",
 };

-#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]))
-
-
-
 static int
 is_addr_different(const struct rte_ether_addr addr, uint64_t num)
 {
@@ -151,7 +142,7 @@ test_parse_etheraddr_invalid_data(void)
 	struct rte_ether_addr result;

 	/* test full strings */
-	for (i = 0; i < ETHERADDR_INVALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ether_addr_invalid_strs); i++) {

 		memset(&result, 0, sizeof(struct rte_ether_addr));

@@ -176,7 +167,7 @@ test_parse_etheraddr_valid(void)
 	struct rte_ether_addr result;

 	/* test full strings */
-	for (i = 0; i < ETHERADDR_VALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ether_addr_valid_strs); i++) {

 		memset(&result, 0, sizeof(struct rte_ether_addr));

@@ -195,7 +186,7 @@ test_parse_etheraddr_valid(void)
 	}

 	/* test garbage strings */
-	for (i = 0; i < ETHERADDR_GARBAGE_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ether_addr_garbage_strs); i++) {

 		memset(&result, 0, sizeof(struct rte_ether_addr));

diff --git a/app/test/test_cmdline_ipaddr.c b/app/test/test_cmdline_ipaddr.c
index 2d11ce936..875fe9b01 100644
--- a/app/test/test_cmdline_ipaddr.c
+++ b/app/test/test_cmdline_ipaddr.c
@@ -264,19 +264,6 @@ const char * ipaddr_invalid_strs[] = {
 		" ",
 };

-#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_network4_strs[0]))
-#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE \
-	(sizeof(ipaddr_garbage_network6_strs) / sizeof(ipaddr_garbage_network6_strs[0]))
-#define IPADDR_INVALID_STRS_SIZE \
-	(sizeof(ipaddr_invalid_strs) / sizeof(ipaddr_invalid_strs[0]))
-
 static void
 dump_addr(cmdline_ipaddr_t addr)
 {
@@ -369,7 +356,7 @@ test_parse_ipaddr_valid(void)
 	}

 	/* test valid strings */
-	for (i = 0; i < IPADDR_VALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ipaddr_valid_strs); i++) {

 		/* test each valid string against different flags */
 		for (flags = 1; flags < 0x8; flags++) {
@@ -417,7 +404,7 @@ test_parse_ipaddr_valid(void)
 	}

 	/* test garbage ipv4 address strings */
-	for (i = 0; i < IPADDR_GARBAGE_ADDR4_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ipaddr_garbage_addr4_strs); i++) {

 		struct in_addr tmp = IPv4_GARBAGE_ADDR;

@@ -459,7 +446,7 @@ test_parse_ipaddr_valid(void)
 	}

 	/* test garbage ipv6 address strings */
-	for (i = 0; i < IPADDR_GARBAGE_ADDR6_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ipaddr_garbage_addr6_strs); i++) {

 		cmdline_ipaddr_t tmp = {.addr = IPv6_GARBAGE_ADDR};

@@ -502,7 +489,7 @@ test_parse_ipaddr_valid(void)


 	/* test garbage ipv4 network strings */
-	for (i = 0; i < IPADDR_GARBAGE_NETWORK4_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ipaddr_garbage_network4_strs); i++) {

 		struct in_addr tmp = IPv4_GARBAGE_ADDR;

@@ -544,7 +531,7 @@ test_parse_ipaddr_valid(void)
 	}

 	/* test garbage ipv6 address strings */
-	for (i = 0; i < IPADDR_GARBAGE_NETWORK6_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ipaddr_garbage_network6_strs); i++) {

 		cmdline_ipaddr_t tmp = {.addr = IPv6_GARBAGE_ADDR};

@@ -601,7 +588,7 @@ test_parse_ipaddr_invalid_data(void)
 	memset(&result, 0, sizeof(result));

 	/* test invalid strings */
-	for (i = 0; i < IPADDR_INVALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ipaddr_invalid_strs); i++) {

 		/* test each valid string against different flags */
 		for (flags = 1; flags < 0x8; flags++) {
diff --git a/app/test/test_cmdline_num.c b/app/test/test_cmdline_num.c
index 4c97caf3d..f6af58a27 100644
--- a/app/test/test_cmdline_num.c
+++ b/app/test/test_cmdline_num.c
@@ -216,19 +216,6 @@ const char * num_invalid_strs[] = {
 		"\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]))
-
-
-
 static int
 can_parse_unsigned(uint64_t expected_result, enum cmdline_numtype type)
 {
@@ -392,7 +379,7 @@ test_parse_num_invalid_data(void)
 		token.num_data.type = type;

 		/* test full strings */
-		for (i = 0; i < NUM_INVALID_STRS_SIZE; i++) {
+		for (i = 0; i < RTE_DIM(num_invalid_strs); i++) {

 			memset(&result, 0, sizeof(uint64_t));
 			memset(&buf, 0, sizeof(buf));
@@ -431,7 +418,7 @@ test_parse_num_valid(void)
 		token.num_data.type = type;

 		/* test positive strings */
-		for (i = 0; i < NUM_POSITIVE_STRS_SIZE; i++) {
+		for (i = 0; i <  RTE_DIM(num_valid_positive_strs); i++) {
 			result = 0;
 			memset(&buf, 0, sizeof(buf));

@@ -459,7 +446,7 @@ test_parse_num_valid(void)
 		}

 		/* test negative strings */
-		for (i = 0; i < NUM_NEGATIVE_STRS_SIZE; i++) {
+		for (i = 0; i < RTE_DIM(num_valid_negative_strs); i++) {
 			result = 0;
 			memset(&buf, 0, sizeof(buf));

@@ -509,7 +496,7 @@ test_parse_num_valid(void)
 		token.num_data.type = type;

 		/* test positive garbage strings */
-		for (i = 0; i < NUM_POSITIVE_GARBAGE_STRS_SIZE; i++) {
+		for (i = 0; i < RTE_DIM(num_garbage_positive_strs); i++) {
 			result = 0;
 			memset(&buf, 0, sizeof(buf));

@@ -537,7 +524,7 @@ test_parse_num_valid(void)
 		}

 		/* test negative strings */
-		for (i = 0; i < NUM_NEGATIVE_GARBAGE_STRS_SIZE; i++) {
+		for (i = 0; i < RTE_DIM(num_garbage_negative_strs); i++) {
 			result = 0;
 			memset(&buf, 0, sizeof(buf));

diff --git a/app/test/test_cmdline_portlist.c b/app/test/test_cmdline_portlist.c
index 0dc6d0030..cbfdfcf54 100644
--- a/app/test/test_cmdline_portlist.c
+++ b/app/test/test_cmdline_portlist.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <inttypes.h>

+#include <rte_common.h>
 #include <cmdline_parse.h>
 #include <cmdline_parse_portlist.h>

@@ -88,16 +89,6 @@ const char * portlist_invalid_strs[] = {
 		"0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,2",
 };

-#define PORTLIST_VALID_STRS_SIZE \
-	(sizeof(portlist_valid_strs) / sizeof(portlist_valid_strs[0]))
-#define PORTLIST_GARBAGE_STRS_SIZE \
-	(sizeof(portlist_garbage_strs) / sizeof(portlist_garbage_strs[0]))
-#define PORTLIST_INVALID_STRS_SIZE \
-	(sizeof(portlist_invalid_strs) / sizeof(portlist_invalid_strs[0]))
-
-
-
-
 /* test invalid parameters */
 int
 test_parse_portlist_invalid_param(void)
@@ -155,7 +146,7 @@ test_parse_portlist_invalid_data(void)
 	cmdline_portlist_t result;

 	/* test invalid strings */
-	for (i = 0; i < PORTLIST_INVALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(portlist_invalid_strs); i++) {

 		memset(&result, 0, sizeof(cmdline_portlist_t));

@@ -180,7 +171,7 @@ test_parse_portlist_valid(void)
 	cmdline_portlist_t result;

 	/* test full strings */
-	for (i = 0; i < PORTLIST_VALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(portlist_valid_strs); i++) {

 		memset(&result, 0, sizeof(cmdline_portlist_t));

@@ -199,7 +190,7 @@ test_parse_portlist_valid(void)
 	}

 	/* test garbage strings */
-	for (i = 0; i < PORTLIST_GARBAGE_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(portlist_garbage_strs); i++) {

 		memset(&result, 0, sizeof(cmdline_portlist_t));

diff --git a/app/test/test_cmdline_string.c b/app/test/test_cmdline_string.c
index 0461a85bb..97516c940 100644
--- a/app/test/test_cmdline_string.c
+++ b/app/test/test_cmdline_string.c
@@ -113,19 +113,6 @@ const char * string_help_strs[] = {
 		"multi#str",
 };

-
-
-#define STRING_PARSE_STRS_SIZE \
-	(sizeof(string_parse_strs) / sizeof(string_parse_strs[0]))
-#define STRING_HELP_STRS_SIZE \
-	(sizeof(string_help_strs) / sizeof(string_help_strs[0]))
-#define STRING_ELT_STRS_SIZE \
-	(sizeof(string_elt_strs) / sizeof(string_elt_strs[0]))
-#define STRING_NB_STRS_SIZE \
-	(sizeof(string_nb_strs) / sizeof(string_nb_strs[0]))
-#define STRING_INVALID_STRS_SIZE \
-	(sizeof(string_invalid_strs) / sizeof(string_invalid_strs[0]))
-
 #define SMALL_BUF 8

 /* test invalid parameters */
@@ -203,7 +190,7 @@ test_parse_string_invalid_data(void)
 	unsigned i;

 	/* test parsing invalid strings */
-	for (i = 0; i < STRING_INVALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(string_invalid_strs); i++) {
 		memset(&token, 0, sizeof(token));
 		memset(buf, 0, sizeof(buf));

@@ -302,7 +289,7 @@ test_parse_string_valid(void)
 	unsigned i;

 	/* test parsing strings */
-	for (i = 0; i < STRING_PARSE_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(string_parse_strs); i++) {
 		memset(&token, 0, sizeof(token));
 		memset(buf, 0, sizeof(buf));

@@ -334,7 +321,7 @@ test_parse_string_valid(void)
 	}

 	/* get number of string tokens and verify it's correct */
-	for (i = 0; i < STRING_NB_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(string_nb_strs); i++) {
 		memset(&token, 0, sizeof(token));

 		token.string_data.str = string_nb_strs[i].str;
@@ -348,7 +335,7 @@ test_parse_string_valid(void)
 	}

 	/* get token at specified position and verify it's correct */
-	for (i = 0; i < STRING_ELT_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(string_elt_strs); i++) {
 		memset(&token, 0, sizeof(token));
 		memset(buf, 0, sizeof(buf));

@@ -368,7 +355,7 @@ test_parse_string_valid(void)
 	}

 	/* cover all cases with help strings */
-	for (i = 0; i < STRING_HELP_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(string_help_strs); i++) {
 		memset(&help_token, 0, sizeof(help_token));
 		memset(help_str, 0, sizeof(help_str));
 		help_token.string_data.str = string_help_strs[i];
diff --git a/app/test/test_debug.c b/app/test/test_debug.c
index faf2cf557..25eab97e2 100644
--- a/app/test/test_debug.c
+++ b/app/test/test_debug.c
@@ -81,7 +81,7 @@ test_exit(void)
 {
 	int test_vals[] = { 0, 1, 2, 255, -1 };
 	unsigned i;
-	for (i = 0; i < sizeof(test_vals) / sizeof(test_vals[0]); i++){
+	for (i = 0; i < RTE_DIM(test_vals); i++) {
 		if (test_exit_val(test_vals[i]) < 0)
 			return -1;
 	}
diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c
index 5b2c0f5cd..4ee809e3d 100644
--- a/app/test/test_eal_flags.c
+++ b/app/test/test_eal_flags.c
@@ -36,8 +36,7 @@
 #define memtest1 "memtest1"
 #define memtest2 "memtest2"
 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
-#define launch_proc(ARGV) process_dup(ARGV, \
-		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 enum hugepage_action {
 	HUGEPAGE_CHECK_EXISTS = 0,
@@ -268,7 +267,7 @@ test_whitelist_flag(void)
 			pci_whitelist, "08:00.1,type=normal",
 	};

-	for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
+	for (i = 0; i < RTE_DIM(wlinval); i++) {
 		if (launch_proc(wlinval[i]) == 0) {
 			printf("Error - process did run ok with invalid "
 			    "whitelist parameter\n");
@@ -324,7 +323,7 @@ test_invalid_b_flag(void)

 	int i;

-	for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
+	for (i = 0; i != RTE_DIM(blinval); i++) {
 		if (launch_proc(blinval[i]) == 0) {
 			printf("Error - process did run ok with invalid "
 			    "blacklist parameter\n");
@@ -425,7 +424,7 @@ test_invalid_r_flag(void)

 	int i;

-	for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
+	for (i = 0; i != RTE_DIM(rinval); i++) {
 		if (launch_proc(rinval[i]) == 0) {
 			printf("Error - process did run ok with invalid "
 			    "-r (rank) parameter\n");
diff --git a/app/test/test_errno.c b/app/test/test_errno.c
index 7df8192d5..3ff0456a5 100644
--- a/app/test/test_errno.c
+++ b/app/test/test_errno.c
@@ -36,7 +36,7 @@ test_errno(void)
 	if (rte_errno != 0)
 		return -1;
 	/* check for standard errors we return the same as libc */
-	for (i = 0; i < sizeof(std_errs)/sizeof(std_errs[0]); i++){
+	for (i = 0; i < RTE_DIM(std_errs); i++) {
 		rte_retval = rte_strerror(std_errs[i]);
 		libc_retval = strerror(std_errs[i]);
 		printf("rte_strerror: '%s', strerror: '%s'\n",
@@ -47,7 +47,7 @@ test_errno(void)
 	/* for rte-specific errors ensure we return a different string
 	 * and that the string for libc is for an unknown error
 	 */
-	for (i = 0; i < sizeof(rte_errs)/sizeof(rte_errs[0]); i++){
+	for (i = 0; i < RTE_DIM(rte_errs); i++) {
 		rte_retval = rte_strerror(rte_errs[i]);
 		libc_retval = strerror(rte_errs[i]);
 		printf("rte_strerror: '%s', strerror: '%s'\n",
diff --git a/app/test/test_lpm.c b/app/test/test_lpm.c
index e969fe051..3a3fd097f 100644
--- a/app/test/test_lpm.c
+++ b/app/test/test_lpm.c
@@ -64,7 +64,6 @@ rte_lpm_test tests[] = {
 	test18
 };

-#define NUM_LPM_TESTS (sizeof(tests)/sizeof(tests[0]))
 #define MAX_DEPTH 32
 #define MAX_RULES 256
 #define NUMBER_TBL8S 256
@@ -1276,7 +1275,7 @@ test_lpm(void)
 	unsigned i;
 	int status, global_status = 0;

-	for (i = 0; i < NUM_LPM_TESTS; i++) {
+	for (i = 0; i < RTE_DIM(tests); i++) {
 		status = tests[i]();
 		if (status < 0) {
 			printf("ERROR: LPM Test %u: FAIL\n", i);
diff --git a/app/test/test_lpm6.c b/app/test/test_lpm6.c
index 670aadb40..0d664546f 100644
--- a/app/test/test_lpm6.c
+++ b/app/test/test_lpm6.c
@@ -85,7 +85,6 @@ rte_lpm6_test tests6[] = {
 	test28,
 };

-#define NUM_LPM6_TESTS                (sizeof(tests6)/sizeof(tests6[0]))
 #define MAX_DEPTH                                                    128
 #define MAX_RULES                                                1000000
 #define NUMBER_TBL8S                                           (1 << 16)
@@ -1780,7 +1779,7 @@ test_lpm6(void)
 	unsigned i;
 	int status = -1, global_status = 0;

-	for (i = 0; i < NUM_LPM6_TESTS; i++) {
+	for (i = 0; i < RTE_DIM(tests6); i++) {
 		printf("# test %02d\n", i);
 		status = tests6[i]();

diff --git a/app/test/test_lpm6_data.h b/app/test/test_lpm6_data.h
index 565138a31..c3894f730 100644
--- a/app/test/test_lpm6_data.h
+++ b/app/test/test_lpm6_data.h
@@ -1029,8 +1029,7 @@ static struct rules_tbl_entry large_route_table[] = {
 	{{234, 149, 220, 106, 0, 144, 214, 128, 35, 102, 0, 0, 0, 0, 0, 0}, 79, 106},
 };

-#define  NUM_ROUTE_ENTRIES \
-	(sizeof(large_route_table) / sizeof(large_route_table[0]))
+#define  NUM_ROUTE_ENTRIES RTE_DIM(large_route_table)

 #define  NUM_IPS_ENTRIES (NUM_ROUTE_ENTRIES * 100)

diff --git a/app/test/test_malloc.c b/app/test/test_malloc.c
index a16e28cc3..67a48ba38 100644
--- a/app/test/test_malloc.c
+++ b/app/test/test_malloc.c
@@ -255,7 +255,7 @@ test_str_to_size(void)
 			{"18446744073709551616", 0} /* ULLONG_MAX + 1 == out of range*/
 	};
 	unsigned i;
-	for (i = 0; i < sizeof(test_values)/sizeof(test_values[0]); i++)
+	for (i = 0; i < RTE_DIM(test_values); i++)
 		if (rte_str_to_size(test_values[i].str) != test_values[i].value)
 			return -1;
 	return 0;
diff --git a/app/test/test_memcpy.c b/app/test/test_memcpy.c
index 2c69ad964..53eb8433a 100644
--- a/app/test/test_memcpy.c
+++ b/app/test/test_memcpy.c
@@ -103,7 +103,7 @@ static int
 func_test(void)
 {
 	unsigned int off_src, off_dst, i;
-	unsigned int num_buf_sizes = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
+	unsigned int num_buf_sizes = RTE_DIM(buf_sizes);
 	int ret;

 	for (off_src = 0; off_src < ALIGNMENT_UNIT; off_src++) {
diff --git a/app/test/test_memcpy_perf.c b/app/test/test_memcpy_perf.c
index 6f436f3ef..8f06b0f1e 100644
--- a/app/test/test_memcpy_perf.c
+++ b/app/test/test_memcpy_perf.c
@@ -250,7 +250,7 @@ perf_test_constant_unaligned(void)
 static inline void
 perf_test_variable_aligned(void)
 {
-	unsigned n = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
+	unsigned n = RTE_DIM(buf_sizes);
 	unsigned i;
 	for (i = 0; i < n; i++) {
 		ALL_PERF_TESTS_FOR_SIZE((size_t)buf_sizes[i]);
@@ -261,7 +261,7 @@ perf_test_variable_aligned(void)
 static inline void
 perf_test_variable_unaligned(void)
 {
-	unsigned n = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
+	unsigned n = RTE_DIM(buf_sizes);
 	unsigned i;
 	for (i = 0; i < n; i++) {
 		ALL_PERF_TESTS_FOR_SIZE_UNALIGNED((size_t)buf_sizes[i]);
diff --git a/app/test/test_mp_secondary.c b/app/test/test_mp_secondary.c
index 2ac33f781..ac15ddbf2 100644
--- a/app/test/test_mp_secondary.c
+++ b/app/test/test_mp_secondary.c
@@ -47,8 +47,7 @@

 #include "process.h"

-#define launch_proc(ARGV) process_dup(ARGV, \
-		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 /*
  * This function is called in the primary i.e. main test, to spawn off secondary
diff --git a/app/test/test_pdump.c b/app/test/test_pdump.c
index af206968b..ad183184c 100644
--- a/app/test/test_pdump.c
+++ b/app/test/test_pdump.c
@@ -18,8 +18,7 @@
 #include "process.h"
 #include "test_pdump.h"

-#define launch_p(ARGV) process_dup(ARGV, \
-		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_p(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 struct rte_ring *ring_server;
 uint16_t portid;
diff --git a/app/test/test_pmd_ring_perf.c b/app/test/test_pmd_ring_perf.c
index 6318da18f..3b2ff9cb4 100644
--- a/app/test/test_pmd_ring_perf.c
+++ b/app/test/test_pmd_ring_perf.c
@@ -100,7 +100,7 @@ test_bulk_enqueue_dequeue(void)
 	unsigned sz, i = 0;
 	struct rte_mbuf *burst[MAX_BURST] = {0};

-	for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
+	for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
 		const uint64_t sc_start = rte_rdtsc();
 		for (i = 0; i < iterations; i++) {
 			rte_ring_sp_enqueue_bulk(r, (void *)burst,
diff --git a/app/test/test_ring_perf.c b/app/test/test_ring_perf.c
index 70ee46ffe..f2accb8a0 100644
--- a/app/test/test_ring_perf.c
+++ b/app/test/test_ring_perf.c
@@ -240,7 +240,7 @@ run_on_core_pair(struct lcore_pair *cores, struct rte_ring *r,
 {
 	struct thread_params param1 = {0}, param2 = {0};
 	unsigned i;
-	for (i = 0; i < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); i++) {
+	for (i = 0; i < RTE_DIM(bulk_sizes); i++) {
 		lcore_count = 0;
 		param1.size = param2.size = bulk_sizes[i];
 		param1.r = param2.r = r;
@@ -376,7 +376,7 @@ test_burst_enqueue_dequeue(struct rte_ring *r)
 	unsigned sz, i = 0;
 	void *burst[MAX_BURST] = {0};

-	for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
+	for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
 		const uint64_t sc_start = rte_rdtsc();
 		for (i = 0; i < iterations; i++) {
 			rte_ring_sp_enqueue_burst(r, burst,
@@ -414,7 +414,7 @@ test_bulk_enqueue_dequeue(struct rte_ring *r)
 	unsigned sz, i = 0;
 	void *burst[MAX_BURST] = {0};

-	for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
+	for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
 		const uint64_t sc_start = rte_rdtsc();
 		for (i = 0; i < iterations; i++) {
 			rte_ring_sp_enqueue_bulk(r, burst,
diff --git a/app/test/test_timer_secondary.c b/app/test/test_timer_secondary.c
index 790f18052..7a3bc873b 100644
--- a/app/test/test_timer_secondary.c
+++ b/app/test/test_timer_secondary.c
@@ -23,8 +23,7 @@
 #define TEST_INFO_MZ_NAME	"test_timer_info_mz"
 #define MSECPERSEC		1E3

-#define launch_proc(ARGV) \
-	process_dup(ARGV, sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 struct test_info {
 	unsigned int mstr_lcore;
--
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH v2 2/3] examples: use RTE_DIM to calculate array size
  2019-11-07  2:58 ` [dpdk-dev] [PATCH v2 " pbhagavatula
@ 2019-11-07  2:58   ` pbhagavatula
  2019-11-07  2:58   ` [dpdk-dev] [PATCH v2 3/3] lib: " pbhagavatula
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: pbhagavatula @ 2019-11-07  2:58 UTC (permalink / raw)
  To: david.marchand, Cristian Dumitrescu, Marko Kovacevic, Ori Kam,
	Bruce Richardson, Radu Nicolau, Akhil Goyal, Tomasz Kantecki,
	David Hunt, John McNamara, Harry van Haaren, Xiaoyun Li
  Cc: dev, Pavan Nikhilesh

From: Pavan Nikhilesh <pbhagavatula@marvell.com>

use RTE_DIM macro to calculate array size.

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 examples/ip_pipeline/parser.c  |  2 +-
 examples/ipv4_multicast/main.c |  6 +-----
 examples/l3fwd-power/main.c    | 18 ++++--------------
 examples/l3fwd/l3fwd_em.c      |  6 ++----
 examples/l3fwd/l3fwd_lpm.c     |  9 ++-------
 examples/vmdq/main.c           |  2 +-
 examples/vmdq_dcb/main.c       |  2 +-
 7 files changed, 12 insertions(+), 33 deletions(-)

diff --git a/examples/ip_pipeline/parser.c b/examples/ip_pipeline/parser.c
index 3fffeb586..fb0769fe3 100644
--- a/examples/ip_pipeline/parser.c
+++ b/examples/ip_pipeline/parser.c
@@ -528,7 +528,7 @@ my_ether_aton(const char *a)
 		if (errno != 0 || end == a || (end[0] != ':' && end[0] != 0))
 			return NULL;
 		a = end + 1;
-	} while (++i != sizeof(o) / sizeof(o[0]) && end[0] != 0);
+	} while (++i != RTE_DIM(o) && end[0] != 0);

 	/* Junk at the end of line */
 	if (end[0] != 0)
diff --git a/examples/ipv4_multicast/main.c b/examples/ipv4_multicast/main.c
index 63333b5b6..e65caa025 100644
--- a/examples/ipv4_multicast/main.c
+++ b/examples/ipv4_multicast/main.c
@@ -155,10 +155,6 @@ static struct mcast_group_params mcast_group_table[] = {
 		{RTE_IPV4(224,0,0,115), 0xF},
 };

-#define N_MCAST_GROUPS \
-	(sizeof (mcast_group_table) / sizeof (mcast_group_table[0]))
-
-
 /* Send burst of packets on an output interface */
 static void
 send_burst(struct lcore_queue_conf *qconf, uint16_t port)
@@ -555,7 +551,7 @@ init_mcast_hash(void)
 		return -1;
 	}

-	for (i = 0; i < N_MCAST_GROUPS; i ++){
+	for (i = 0; i < RTE_DIM(mcast_group_table); i++) {
 		if (rte_fbk_hash_add_key(mcast_hash,
 			mcast_group_table[i].ip,
 			mcast_group_table[i].port_mask) < 0) {
diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index d049d8a5d..e90d18b24 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -238,8 +238,7 @@ static struct lcore_params lcore_params_array_default[] = {
 };

 struct lcore_params *lcore_params = lcore_params_array_default;
-uint16_t nb_lcore_params = sizeof(lcore_params_array_default) /
-				sizeof(lcore_params_array_default[0]);
+uint16_t nb_lcore_params = RTE_DIM(lcore_params_array_default);

 static struct rte_eth_conf port_conf = {
 	.rxmode = {
@@ -326,12 +325,6 @@ static lookup_struct_t *ipv6_l3fwd_lookup_struct[NB_SOCKETS];

 #define L3FWD_HASH_ENTRIES	1024

-#define IPV4_L3FWD_NUM_ROUTES \
-	(sizeof(ipv4_l3fwd_route_array) / sizeof(ipv4_l3fwd_route_array[0]))
-
-#define IPV6_L3FWD_NUM_ROUTES \
-	(sizeof(ipv6_l3fwd_route_array) / sizeof(ipv6_l3fwd_route_array[0]))
-
 static uint16_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
 static uint16_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
 #endif
@@ -354,9 +347,6 @@ static struct ipv4_l3fwd_route ipv4_l3fwd_route_array[] = {
 	{RTE_IPV4(8,1,1,0), 24, 7},
 };

-#define IPV4_L3FWD_NUM_ROUTES \
-	(sizeof(ipv4_l3fwd_route_array) / sizeof(ipv4_l3fwd_route_array[0]))
-
 #define IPV4_L3FWD_LPM_MAX_RULES     1024

 typedef struct rte_lpm lookup_struct_t;
@@ -1841,7 +1831,7 @@ setup_hash(int socketid)


 	/* populate the ipv4 hash */
-	for (i = 0; i < IPV4_L3FWD_NUM_ROUTES; i++) {
+	for (i = 0; i < RTE_DIM(ipv4_l3fwd_route_array); i++) {
 		ret = rte_hash_add_key (ipv4_l3fwd_lookup_struct[socketid],
 				(void *) &ipv4_l3fwd_route_array[i].key);
 		if (ret < 0) {
@@ -1854,7 +1844,7 @@ setup_hash(int socketid)
 	}

 	/* populate the ipv6 hash */
-	for (i = 0; i < IPV6_L3FWD_NUM_ROUTES; i++) {
+	for (i = 0; i < RTE_DIM(ipv6_l3fwd_route_array); i++) {
 		ret = rte_hash_add_key (ipv6_l3fwd_lookup_struct[socketid],
 				(void *) &ipv6_l3fwd_route_array[i].key);
 		if (ret < 0) {
@@ -1891,7 +1881,7 @@ setup_lpm(int socketid)
 				" on socket %d\n", socketid);

 	/* populate the LPM table */
-	for (i = 0; i < IPV4_L3FWD_NUM_ROUTES; i++) {
+	for (i = 0; i < RTE_DIM(ipv4_l3fwd_route_array); i++) {
 		ret = rte_lpm_add(ipv4_l3fwd_lookup_struct[socketid],
 			ipv4_l3fwd_route_array[i].ip,
 			ipv4_l3fwd_route_array[i].depth,
diff --git a/examples/l3fwd/l3fwd_em.c b/examples/l3fwd/l3fwd_em.c
index 74a7c8fa4..1b1cce47d 100644
--- a/examples/l3fwd/l3fwd_em.c
+++ b/examples/l3fwd/l3fwd_em.c
@@ -203,11 +203,9 @@ ipv6_hash_crc(const void *data, __rte_unused uint32_t data_len,
 	return init_val;
 }

-#define IPV4_L3FWD_EM_NUM_ROUTES \
-	(sizeof(ipv4_l3fwd_em_route_array) / sizeof(ipv4_l3fwd_em_route_array[0]))
+#define IPV4_L3FWD_EM_NUM_ROUTES RTE_DIM(ipv4_l3fwd_em_route_array)

-#define IPV6_L3FWD_EM_NUM_ROUTES \
-	(sizeof(ipv6_l3fwd_em_route_array) / sizeof(ipv6_l3fwd_em_route_array[0]))
+#define IPV6_L3FWD_EM_NUM_ROUTES RTE_DIM(ipv6_l3fwd_em_route_array)

 static uint8_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
 static uint8_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
diff --git a/examples/l3fwd/l3fwd_lpm.c b/examples/l3fwd/l3fwd_lpm.c
index a3a65f7fc..6671da4f2 100644
--- a/examples/l3fwd/l3fwd_lpm.c
+++ b/examples/l3fwd/l3fwd_lpm.c
@@ -65,11 +65,6 @@ static struct ipv6_l3fwd_lpm_route ipv6_l3fwd_lpm_route_array[] = {
 	{{32, 1, 2, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0}, 48, 7},
 };

-#define IPV4_L3FWD_LPM_NUM_ROUTES \
-	(sizeof(ipv4_l3fwd_lpm_route_array) / sizeof(ipv4_l3fwd_lpm_route_array[0]))
-#define IPV6_L3FWD_LPM_NUM_ROUTES \
-	(sizeof(ipv6_l3fwd_lpm_route_array) / sizeof(ipv6_l3fwd_lpm_route_array[0]))
-
 #define IPV4_L3FWD_LPM_MAX_RULES         1024
 #define IPV4_L3FWD_LPM_NUMBER_TBL8S (1 << 8)
 #define IPV6_L3FWD_LPM_MAX_RULES         1024
@@ -277,7 +272,7 @@ setup_lpm(const int socketid)
 			socketid);

 	/* populate the LPM table */
-	for (i = 0; i < IPV4_L3FWD_LPM_NUM_ROUTES; i++) {
+	for (i = 0; i < RTE_DIM(ipv4_l3fwd_lpm_route_array); i++) {
 		struct in_addr in;

 		/* skip unused ports */
@@ -317,7 +312,7 @@ setup_lpm(const int socketid)
 			socketid);

 	/* populate the LPM table */
-	for (i = 0; i < IPV6_L3FWD_LPM_NUM_ROUTES; i++) {
+	for (i = 0; i < RTE_DIM(ipv6_l3fwd_lpm_route_array); i++) {

 		/* skip unused ports */
 		if ((1 << ipv6_l3fwd_lpm_route_array[i].if_out &
diff --git a/examples/vmdq/main.c b/examples/vmdq/main.c
index 6e6fc91ec..011110920 100644
--- a/examples/vmdq/main.c
+++ b/examples/vmdq/main.c
@@ -503,7 +503,7 @@ lcore_main(__attribute__((__unused__)) void *dummy)

 	for (;;) {
 		struct rte_mbuf *buf[MAX_PKT_BURST];
-		const uint16_t buf_size = sizeof(buf) / sizeof(buf[0]);
+		const uint16_t buf_size = RTE_DIM(buf);

 		for (p = 0; p < num_ports; p++) {
 			const uint8_t sport = ports[p];
diff --git a/examples/vmdq_dcb/main.c b/examples/vmdq_dcb/main.c
index 594c4f195..f417b2fd9 100644
--- a/examples/vmdq_dcb/main.c
+++ b/examples/vmdq_dcb/main.c
@@ -582,7 +582,7 @@ lcore_main(void *arg)

 	for (;;) {
 		struct rte_mbuf *buf[MAX_PKT_BURST];
-		const uint16_t buf_size = sizeof(buf) / sizeof(buf[0]);
+		const uint16_t buf_size = RTE_DIM(buf);
 		for (p = 0; p < num_ports; p++) {
 			const uint8_t src = ports[p];
 			const uint8_t dst = ports[p ^ 1]; /* 0 <-> 1, 2 <-> 3 etc */
--
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH v2 3/3] lib: use RTE_DIM to calculate array size
  2019-11-07  2:58 ` [dpdk-dev] [PATCH v2 " pbhagavatula
  2019-11-07  2:58   ` [dpdk-dev] [PATCH v2 2/3] examples: " pbhagavatula
@ 2019-11-07  2:58   ` pbhagavatula
  2019-11-07  9:08     ` Dumitrescu, Cristian
  2019-12-10 13:10   ` [dpdk-dev] [PATCH v2 1/3] app: " David Marchand
  2020-01-24  4:55   ` [dpdk-dev] [PATCH v3 " pbhagavatula
  3 siblings, 1 reply; 16+ messages in thread
From: pbhagavatula @ 2019-11-07  2:58 UTC (permalink / raw)
  To: david.marchand, Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko,
	Konstantin Ananyev, Cristian Dumitrescu
  Cc: dev, Pavan Nikhilesh

From: Pavan Nikhilesh <pbhagavatula@marvell.com>

use RTE_DIM to calculate array size.

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 lib/librte_ethdev/rte_ethdev.c        | 8 +++-----
 lib/librte_ip_frag/ip_frag_internal.c | 5 ++---
 lib/librte_port/rte_port_eventdev.c   | 4 ++--
 lib/librte_port/rte_port_eventdev.h   | 4 ----
 4 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 7743205d3..721ee694b 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -86,7 +86,7 @@ static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
 		rx_nombuf)},
 };
 
-#define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
+#define RTE_NB_STATS RTE_DIM(rte_stats_strings)
 
 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
 	{"packets", offsetof(struct rte_eth_stats, q_ipackets)},
@@ -94,15 +94,13 @@ static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
 	{"errors", offsetof(struct rte_eth_stats, q_errors)},
 };
 
-#define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) /	\
-		sizeof(rte_rxq_stats_strings[0]))
+#define RTE_NB_RXQ_STATS RTE_DIM(rte_rxq_stats_strings)
 
 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
 	{"packets", offsetof(struct rte_eth_stats, q_opackets)},
 	{"bytes", offsetof(struct rte_eth_stats, q_obytes)},
 };
-#define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) /	\
-		sizeof(rte_txq_stats_strings[0]))
+#define RTE_NB_TXQ_STATS RTE_DIM(rte_txq_stats_strings)
 
 #define RTE_RX_OFFLOAD_BIT2STR(_name)	\
 	{ DEV_RX_OFFLOAD_##_name, #_name }
diff --git a/lib/librte_ip_frag/ip_frag_internal.c b/lib/librte_ip_frag/ip_frag_internal.c
index 97470a872..b436a4c93 100644
--- a/lib/librte_ip_frag/ip_frag_internal.c
+++ b/lib/librte_ip_frag/ip_frag_internal.c
@@ -107,8 +107,7 @@ ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr,
 				IP_LAST_FRAG_IDX : UINT32_MAX;
 
 	/* this is the intermediate fragment. */
-	} else if ((idx = fp->last_idx) <
-		sizeof (fp->frags) / sizeof (fp->frags[0])) {
+	} else if ((idx = fp->last_idx) < RTE_DIM(fp->frags)) {
 		fp->last_idx++;
 	}
 
@@ -116,7 +115,7 @@ ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr,
 	 * erroneous packet: either exceed max allowed number of fragments,
 	 * or duplicate first/last fragment encountered.
 	 */
-	if (idx >= sizeof (fp->frags) / sizeof (fp->frags[0])) {
+	if (idx >= RTE_DIM(fp->frags)) {
 
 		/* report an error. */
 		if (fp->key.key_len == IPV4_KEYLEN)
diff --git a/lib/librte_port/rte_port_eventdev.c b/lib/librte_port/rte_port_eventdev.c
index aa93bd3a2..fd7dac9a5 100644
--- a/lib/librte_port/rte_port_eventdev.c
+++ b/lib/librte_port/rte_port_eventdev.c
@@ -179,7 +179,7 @@ rte_port_eventdev_writer_create(void *params, int socket_id)
 	port->evt_op = conf->evt_op;
 	memset(&port->ev, 0, sizeof(port->ev));
 
-	for (i = 0; i < ARRAY_SIZE(port->ev); i++) {
+	for (i = 0; i < RTE_DIM(port->ev); i++) {
 		port->ev[i].queue_id = port->queue_id;
 		port->ev[i].sched_type = port->sched_type;
 		port->ev[i].op = port->evt_op;
@@ -386,7 +386,7 @@ rte_port_eventdev_writer_nodrop_create(void *params, int socket_id)
 	port->evt_op = conf->evt_op;
 	memset(&port->ev, 0, sizeof(port->ev));
 
-	for (i = 0; i < ARRAY_SIZE(port->ev); i++) {
+	for (i = 0; i < RTE_DIM(port->ev); i++) {
 		port->ev[i].queue_id = port->queue_id;
 		port->ev[i].sched_type = port->sched_type;
 		port->ev[i].op = port->evt_op;
diff --git a/lib/librte_port/rte_port_eventdev.h b/lib/librte_port/rte_port_eventdev.h
index acf88f4e9..966e9cdaf 100644
--- a/lib/librte_port/rte_port_eventdev.h
+++ b/lib/librte_port/rte_port_eventdev.h
@@ -9,10 +9,6 @@
 extern "C" {
 #endif
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 /**
  * @file
  * RTE Port Eventdev Interface
-- 
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v2 3/3] lib: use RTE_DIM to calculate array size
  2019-11-07  2:58   ` [dpdk-dev] [PATCH v2 3/3] lib: " pbhagavatula
@ 2019-11-07  9:08     ` Dumitrescu, Cristian
  0 siblings, 0 replies; 16+ messages in thread
From: Dumitrescu, Cristian @ 2019-11-07  9:08 UTC (permalink / raw)
  To: pbhagavatula, david.marchand, Thomas Monjalon, Yigit, Ferruh,
	Andrew Rybchenko, Ananyev, Konstantin
  Cc: dev



> -----Original Message-----
> From: pbhagavatula@marvell.com <pbhagavatula@marvell.com>
> Sent: Thursday, November 7, 2019 2:58 AM
> To: david.marchand@redhat.com; Thomas Monjalon
> <thomas@monjalon.net>; Yigit, Ferruh <ferruh.yigit@intel.com>; Andrew
> Rybchenko <arybchenko@solarflare.com>; Ananyev, Konstantin
> <konstantin.ananyev@intel.com>; Dumitrescu, Cristian
> <cristian.dumitrescu@intel.com>
> Cc: dev@dpdk.org; Pavan Nikhilesh <pbhagavatula@marvell.com>
> Subject: [dpdk-dev] [PATCH v2 3/3] lib: use RTE_DIM to calculate array size
> 
> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
> 
> use RTE_DIM to calculate array size.
> 
> Suggested-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
> ---
>  lib/librte_ethdev/rte_ethdev.c        | 8 +++-----
>  lib/librte_ip_frag/ip_frag_internal.c | 5 ++---
>  lib/librte_port/rte_port_eventdev.c   | 4 ++--
>  lib/librte_port/rte_port_eventdev.h   | 4 ----
>  4 files changed, 7 insertions(+), 14 deletions(-)
> 

Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/3] app: use RTE_DIM to calculate array size
  2019-11-07  2:58 ` [dpdk-dev] [PATCH v2 " pbhagavatula
  2019-11-07  2:58   ` [dpdk-dev] [PATCH v2 2/3] examples: " pbhagavatula
  2019-11-07  2:58   ` [dpdk-dev] [PATCH v2 3/3] lib: " pbhagavatula
@ 2019-12-10 13:10   ` David Marchand
  2020-01-24  4:55   ` [dpdk-dev] [PATCH v3 " pbhagavatula
  3 siblings, 0 replies; 16+ messages in thread
From: David Marchand @ 2019-12-10 13:10 UTC (permalink / raw)
  To: Pavan Nikhilesh; +Cc: dev

On Thu, Nov 7, 2019 at 3:59 AM <pbhagavatula@marvell.com> wrote:
>
> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
>
> Use RTE_DIM macro to calculate array size
>
> Suggested-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
> ---
>  v2 Changes:
>  ----------
>  - remove macros that are used only once.(David)
>
>  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 | 15 +++------------
>  app/test/test_cmdline_ipaddr.c    | 25 ++++++-------------------
>  app/test/test_cmdline_num.c       | 23 +++++------------------
>  app/test/test_cmdline_portlist.c  | 17 ++++-------------
>  app/test/test_cmdline_string.c    | 23 +++++------------------
>  app/test/test_debug.c             |  2 +-
>  app/test/test_eal_flags.c         |  9 ++++-----
>  app/test/test_errno.c             |  4 ++--
>  app/test/test_lpm.c               |  3 +--
>  app/test/test_lpm6.c              |  3 +--
>  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, 47 insertions(+), 113 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 = (sizeof events) / (sizeof events[0]);
> +       int num_events = RTE_DIM(events);

num_events is used only once.

>
>         /* Display the bypass mode.*/
>         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {

[snip]

> diff --git a/app/test/test_cmdline_num.c b/app/test/test_cmdline_num.c
> index 4c97caf3d..f6af58a27 100644
> --- a/app/test/test_cmdline_num.c
> +++ b/app/test/test_cmdline_num.c
[snip]
> @@ -431,7 +418,7 @@ test_parse_num_valid(void)
>                 token.num_data.type = type;
>
>                 /* test positive strings */
> -               for (i = 0; i < NUM_POSITIVE_STRS_SIZE; i++) {
> +               for (i = 0; i <  RTE_DIM(num_valid_positive_strs); i++) {

Unneeded space.

>                         result = 0;
>                         memset(&buf, 0, sizeof(buf));
>

[snip]

> diff --git a/app/test/test_cmdline_portlist.c b/app/test/test_cmdline_portlist.c
> index 0dc6d0030..cbfdfcf54 100644
> --- a/app/test/test_cmdline_portlist.c
> +++ b/app/test/test_cmdline_portlist.c
> @@ -6,6 +6,7 @@
>  #include <string.h>
>  #include <inttypes.h>
>
> +#include <rte_common.h>

We separate the includes in 3 groups, standard system headers, dpdk
headers and finally application headers.
Add a line here.

>  #include <cmdline_parse.h>
>  #include <cmdline_parse_portlist.h>
>

[snip]

> diff --git a/app/test/test_memcpy.c b/app/test/test_memcpy.c
> index 2c69ad964..53eb8433a 100644
> --- a/app/test/test_memcpy.c
> +++ b/app/test/test_memcpy.c
> @@ -103,7 +103,7 @@ static int
>  func_test(void)
>  {
>         unsigned int off_src, off_dst, i;
> -       unsigned int num_buf_sizes = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
> +       unsigned int num_buf_sizes = RTE_DIM(buf_sizes);

num_buf_sizes is used only once.

>         int ret;
>
>         for (off_src = 0; off_src < ALIGNMENT_UNIT; off_src++) {
> diff --git a/app/test/test_memcpy_perf.c b/app/test/test_memcpy_perf.c
> index 6f436f3ef..8f06b0f1e 100644
> --- a/app/test/test_memcpy_perf.c
> +++ b/app/test/test_memcpy_perf.c
> @@ -250,7 +250,7 @@ perf_test_constant_unaligned(void)
>  static inline void
>  perf_test_variable_aligned(void)
>  {
> -       unsigned n = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
> +       unsigned n = RTE_DIM(buf_sizes);

n is used only once.

>         unsigned i;
>         for (i = 0; i < n; i++) {
>                 ALL_PERF_TESTS_FOR_SIZE((size_t)buf_sizes[i]);
> @@ -261,7 +261,7 @@ perf_test_variable_aligned(void)
>  static inline void
>  perf_test_variable_unaligned(void)
>  {
> -       unsigned n = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
> +       unsigned n = RTE_DIM(buf_sizes);

idem.

>         unsigned i;
>         for (i = 0; i < n; i++) {
>                 ALL_PERF_TESTS_FOR_SIZE_UNALIGNED((size_t)buf_sizes[i]);

The rest looks good.

If you still have some available cycles, can you handle those too?

$ git grep 'sizeof(.*) */ *sizeof(.*)' -- app/test
app/test/test_func_reentrancy.c:   for (case_id = 0; case_id <
sizeof(test_cases)/sizeof(struct test_case); case_id ++) {
app/test/test_hash.c:           i < sizeof(hashtest_funcs) /
sizeof(rte_hash_function);
app/test/test_hash.c:                   j < sizeof(hashtest_initvals)
/ sizeof(uint32_t);
app/test/test_hash.c:                           k <
sizeof(hashtest_key_lens) / sizeof(uint32_t);
app/test/test_hash_functions.c:    for (i = 0; i <
sizeof(hashtest_key_lens) / sizeof(uint32_t); i++) {
app/test/test_hash_functions.c:            for (j = 0; j <
sizeof(hashtest_initvals) / sizeof(uint32_t); j++) {
app/test/test_hash_functions.c:    for (i = 0; i <
sizeof(hashtest_key_lens) / sizeof(uint32_t); i++) {
app/test/test_hash_functions.c:            for (j = 0; j <
sizeof(hashtest_initvals) / sizeof(uint32_t); j++) {
app/test/test_power.c:     const int envs_size =
sizeof(envs)/sizeof(enum power_management_env);


Thanks for working on cleanups.


--
David Marchand


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH v3 1/3] app: use RTE_DIM to calculate array size
  2019-11-07  2:58 ` [dpdk-dev] [PATCH v2 " pbhagavatula
                     ` (2 preceding siblings ...)
  2019-12-10 13:10   ` [dpdk-dev] [PATCH v2 1/3] app: " David Marchand
@ 2020-01-24  4:55   ` pbhagavatula
  2020-01-24  4:55     ` [dpdk-dev] [PATCH v3 2/3] examples: " pbhagavatula
                       ` (2 more replies)
  3 siblings, 3 replies; 16+ messages in thread
From: pbhagavatula @ 2020-01-24  4:55 UTC (permalink / raw)
  To: Wenzhuo Lu, Jingjing Wu, Bernard Iremonger, Olivier Matz,
	Yipeng Wang, Sameh Gobriel, Bruce Richardson, Vladimir Medvedkin,
	Anatoly Burakov, Andrew Rybchenko, Reshma Pattan, David Hunt,
	Robert Sanford, Erik Gabriel Carrillo
  Cc: dev, Pavan Nikhilesh

From: Pavan Nikhilesh <pbhagavatula@marvell.com>

Use RTE_DIM macro to calculate array size

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 v3 Changes:
 ----------
 - remove variables that are used only once.(David)
 - rebase on ToT.
 - flush out rest of instances not using RTE_DIM.

 v2 Changes:
 ----------
 - remove macros that are used only once.(David)

 app/test-pmd/cmdline.c            |  3 +--
 app/test-pmd/icmpecho.c           |  2 +-
 app/test-pmd/testpmd.c            |  2 --
 app/test/test.c                   |  2 +-
 app/test/test_cmdline_etheraddr.c | 15 +++------------
 app/test/test_cmdline_ipaddr.c    | 25 ++++++-------------------
 app/test/test_cmdline_num.c       | 23 +++++------------------
 app/test/test_cmdline_portlist.c  | 18 +++++-------------
 app/test/test_cmdline_string.c    | 23 +++++------------------
 app/test/test_debug.c             |  2 +-
 app/test/test_eal_flags.c         |  9 ++++-----
 app/test/test_errno.c             |  4 ++--
 app/test/test_func_reentrancy.c   |  2 +-
 app/test/test_hash.c              | 12 +++---------
 app/test/test_hash_functions.c    | 10 +++++-----
 app/test/test_lpm.c               |  3 +--
 app/test/test_lpm6.c              |  3 +--
 app/test/test_lpm6_data.h         |  3 +--
 app/test/test_malloc.c            |  2 +-
 app/test/test_memcpy.c            |  3 +--
 app/test/test_memcpy_perf.c       |  6 ++----
 app/test/test_mp_secondary.c      |  3 +--
 app/test/test_pdump.c             |  3 +--
 app/test/test_pmd_ring_perf.c     |  2 +-
 app/test/test_power.c             |  4 +---
 app/test/test_ring_perf.c         |  2 +-
 app/test/test_timer_secondary.c   |  3 +--
 27 files changed, 56 insertions(+), 133 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index dab22bc4d..969ed8596 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -5578,7 +5578,6 @@ cmd_show_bypass_config_parsed(void *parsed_result,
 		"OS/board off",
 		"power supply off",
 		"timeout"};
-	int num_events = (sizeof events) / (sizeof events[0]);

 	/* Display the bypass mode.*/
 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
@@ -5599,7 +5598,7 @@ cmd_show_bypass_config_parsed(void *parsed_result,
 	printf("\tbypass timeout = %s\n", timeouts[timeout]);

 	/* Display the bypass events and associated modes. */
-	for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
+	for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {

 		if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
 			printf("\tFailed to get bypass mode for event = %s\n",
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 f9f4cd1d3..a1dd4043e 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2796,8 +2796,6 @@ struct pmd_test_command {
 	cmd_func_t cmd_func;
 };

-#define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]))
-
 /* Check the link status of all ports in up to 9s, and print them finally */
 static void
 check_all_ports_link_status(uint32_t port_mask)
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 == NULL)
 		return -1;
-	for (i = 0; i < sizeof(actions)/sizeof(actions[0]); i++) {
+	for (i = 0; i < RTE_DIM(actions); i++) {
 		if (strcmp(actions[i].env_var, recursive_call) == 0)
 			return (actions[i].action_fn)();
 	}
diff --git a/app/test/test_cmdline_etheraddr.c b/app/test/test_cmdline_etheraddr.c
index 9a32fd7ec..9691c32ba 100644
--- a/app/test/test_cmdline_etheraddr.c
+++ b/app/test/test_cmdline_etheraddr.c
@@ -72,15 +72,6 @@ const char * ether_addr_invalid_strs[] = {
 		" ",
 };

-#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]))
-
-
-
 static int
 is_addr_different(const struct rte_ether_addr addr, uint64_t num)
 {
@@ -151,7 +142,7 @@ test_parse_etheraddr_invalid_data(void)
 	struct rte_ether_addr result;

 	/* test full strings */
-	for (i = 0; i < ETHERADDR_INVALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ether_addr_invalid_strs); i++) {

 		memset(&result, 0, sizeof(struct rte_ether_addr));

@@ -176,7 +167,7 @@ test_parse_etheraddr_valid(void)
 	struct rte_ether_addr result;

 	/* test full strings */
-	for (i = 0; i < ETHERADDR_VALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ether_addr_valid_strs); i++) {

 		memset(&result, 0, sizeof(struct rte_ether_addr));

@@ -195,7 +186,7 @@ test_parse_etheraddr_valid(void)
 	}

 	/* test garbage strings */
-	for (i = 0; i < ETHERADDR_GARBAGE_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ether_addr_garbage_strs); i++) {

 		memset(&result, 0, sizeof(struct rte_ether_addr));

diff --git a/app/test/test_cmdline_ipaddr.c b/app/test/test_cmdline_ipaddr.c
index 088cd5afc..b3f50d80d 100644
--- a/app/test/test_cmdline_ipaddr.c
+++ b/app/test/test_cmdline_ipaddr.c
@@ -262,19 +262,6 @@ const char * ipaddr_invalid_strs[] = {
 		" ",
 };

-#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_network4_strs[0]))
-#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE \
-	(sizeof(ipaddr_garbage_network6_strs) / sizeof(ipaddr_garbage_network6_strs[0]))
-#define IPADDR_INVALID_STRS_SIZE \
-	(sizeof(ipaddr_invalid_strs) / sizeof(ipaddr_invalid_strs[0]))
-
 static void
 dump_addr(cmdline_ipaddr_t addr)
 {
@@ -367,7 +354,7 @@ test_parse_ipaddr_valid(void)
 	}

 	/* test valid strings */
-	for (i = 0; i < IPADDR_VALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ipaddr_valid_strs); i++) {

 		/* test each valid string against different flags */
 		for (flags = 1; flags < 0x8; flags++) {
@@ -415,7 +402,7 @@ test_parse_ipaddr_valid(void)
 	}

 	/* test garbage ipv4 address strings */
-	for (i = 0; i < IPADDR_GARBAGE_ADDR4_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ipaddr_garbage_addr4_strs); i++) {

 		struct in_addr tmp = IPv4_GARBAGE_ADDR;

@@ -457,7 +444,7 @@ test_parse_ipaddr_valid(void)
 	}

 	/* test garbage ipv6 address strings */
-	for (i = 0; i < IPADDR_GARBAGE_ADDR6_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ipaddr_garbage_addr6_strs); i++) {

 		cmdline_ipaddr_t tmp = {.addr = IPv6_GARBAGE_ADDR};

@@ -500,7 +487,7 @@ test_parse_ipaddr_valid(void)


 	/* test garbage ipv4 network strings */
-	for (i = 0; i < IPADDR_GARBAGE_NETWORK4_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ipaddr_garbage_network4_strs); i++) {

 		struct in_addr tmp = IPv4_GARBAGE_ADDR;

@@ -542,7 +529,7 @@ test_parse_ipaddr_valid(void)
 	}

 	/* test garbage ipv6 address strings */
-	for (i = 0; i < IPADDR_GARBAGE_NETWORK6_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ipaddr_garbage_network6_strs); i++) {

 		cmdline_ipaddr_t tmp = {.addr = IPv6_GARBAGE_ADDR};

@@ -599,7 +586,7 @@ test_parse_ipaddr_invalid_data(void)
 	memset(&result, 0, sizeof(result));

 	/* test invalid strings */
-	for (i = 0; i < IPADDR_INVALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(ipaddr_invalid_strs); i++) {

 		/* test each valid string against different flags */
 		for (flags = 1; flags < 0x8; flags++) {
diff --git a/app/test/test_cmdline_num.c b/app/test/test_cmdline_num.c
index 4c97caf3d..a6ad95507 100644
--- a/app/test/test_cmdline_num.c
+++ b/app/test/test_cmdline_num.c
@@ -216,19 +216,6 @@ const char * num_invalid_strs[] = {
 		"\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]))
-
-
-
 static int
 can_parse_unsigned(uint64_t expected_result, enum cmdline_numtype type)
 {
@@ -392,7 +379,7 @@ test_parse_num_invalid_data(void)
 		token.num_data.type = type;

 		/* test full strings */
-		for (i = 0; i < NUM_INVALID_STRS_SIZE; i++) {
+		for (i = 0; i < RTE_DIM(num_invalid_strs); i++) {

 			memset(&result, 0, sizeof(uint64_t));
 			memset(&buf, 0, sizeof(buf));
@@ -431,7 +418,7 @@ test_parse_num_valid(void)
 		token.num_data.type = type;

 		/* test positive strings */
-		for (i = 0; i < NUM_POSITIVE_STRS_SIZE; i++) {
+		for (i = 0; i < RTE_DIM(num_valid_positive_strs); i++) {
 			result = 0;
 			memset(&buf, 0, sizeof(buf));

@@ -459,7 +446,7 @@ test_parse_num_valid(void)
 		}

 		/* test negative strings */
-		for (i = 0; i < NUM_NEGATIVE_STRS_SIZE; i++) {
+		for (i = 0; i < RTE_DIM(num_valid_negative_strs); i++) {
 			result = 0;
 			memset(&buf, 0, sizeof(buf));

@@ -509,7 +496,7 @@ test_parse_num_valid(void)
 		token.num_data.type = type;

 		/* test positive garbage strings */
-		for (i = 0; i < NUM_POSITIVE_GARBAGE_STRS_SIZE; i++) {
+		for (i = 0; i < RTE_DIM(num_garbage_positive_strs); i++) {
 			result = 0;
 			memset(&buf, 0, sizeof(buf));

@@ -537,7 +524,7 @@ test_parse_num_valid(void)
 		}

 		/* test negative strings */
-		for (i = 0; i < NUM_NEGATIVE_GARBAGE_STRS_SIZE; i++) {
+		for (i = 0; i < RTE_DIM(num_garbage_negative_strs); i++) {
 			result = 0;
 			memset(&buf, 0, sizeof(buf));

diff --git a/app/test/test_cmdline_portlist.c b/app/test/test_cmdline_portlist.c
index 0dc6d0030..fd354214a 100644
--- a/app/test/test_cmdline_portlist.c
+++ b/app/test/test_cmdline_portlist.c
@@ -6,6 +6,8 @@
 #include <string.h>
 #include <inttypes.h>

+#include <rte_common.h>
+
 #include <cmdline_parse.h>
 #include <cmdline_parse_portlist.h>

@@ -88,16 +90,6 @@ const char * portlist_invalid_strs[] = {
 		"0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,2",
 };

-#define PORTLIST_VALID_STRS_SIZE \
-	(sizeof(portlist_valid_strs) / sizeof(portlist_valid_strs[0]))
-#define PORTLIST_GARBAGE_STRS_SIZE \
-	(sizeof(portlist_garbage_strs) / sizeof(portlist_garbage_strs[0]))
-#define PORTLIST_INVALID_STRS_SIZE \
-	(sizeof(portlist_invalid_strs) / sizeof(portlist_invalid_strs[0]))
-
-
-
-
 /* test invalid parameters */
 int
 test_parse_portlist_invalid_param(void)
@@ -155,7 +147,7 @@ test_parse_portlist_invalid_data(void)
 	cmdline_portlist_t result;

 	/* test invalid strings */
-	for (i = 0; i < PORTLIST_INVALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(portlist_invalid_strs); i++) {

 		memset(&result, 0, sizeof(cmdline_portlist_t));

@@ -180,7 +172,7 @@ test_parse_portlist_valid(void)
 	cmdline_portlist_t result;

 	/* test full strings */
-	for (i = 0; i < PORTLIST_VALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(portlist_valid_strs); i++) {

 		memset(&result, 0, sizeof(cmdline_portlist_t));

@@ -199,7 +191,7 @@ test_parse_portlist_valid(void)
 	}

 	/* test garbage strings */
-	for (i = 0; i < PORTLIST_GARBAGE_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(portlist_garbage_strs); i++) {

 		memset(&result, 0, sizeof(cmdline_portlist_t));

diff --git a/app/test/test_cmdline_string.c b/app/test/test_cmdline_string.c
index 0461a85bb..97516c940 100644
--- a/app/test/test_cmdline_string.c
+++ b/app/test/test_cmdline_string.c
@@ -113,19 +113,6 @@ const char * string_help_strs[] = {
 		"multi#str",
 };

-
-
-#define STRING_PARSE_STRS_SIZE \
-	(sizeof(string_parse_strs) / sizeof(string_parse_strs[0]))
-#define STRING_HELP_STRS_SIZE \
-	(sizeof(string_help_strs) / sizeof(string_help_strs[0]))
-#define STRING_ELT_STRS_SIZE \
-	(sizeof(string_elt_strs) / sizeof(string_elt_strs[0]))
-#define STRING_NB_STRS_SIZE \
-	(sizeof(string_nb_strs) / sizeof(string_nb_strs[0]))
-#define STRING_INVALID_STRS_SIZE \
-	(sizeof(string_invalid_strs) / sizeof(string_invalid_strs[0]))
-
 #define SMALL_BUF 8

 /* test invalid parameters */
@@ -203,7 +190,7 @@ test_parse_string_invalid_data(void)
 	unsigned i;

 	/* test parsing invalid strings */
-	for (i = 0; i < STRING_INVALID_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(string_invalid_strs); i++) {
 		memset(&token, 0, sizeof(token));
 		memset(buf, 0, sizeof(buf));

@@ -302,7 +289,7 @@ test_parse_string_valid(void)
 	unsigned i;

 	/* test parsing strings */
-	for (i = 0; i < STRING_PARSE_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(string_parse_strs); i++) {
 		memset(&token, 0, sizeof(token));
 		memset(buf, 0, sizeof(buf));

@@ -334,7 +321,7 @@ test_parse_string_valid(void)
 	}

 	/* get number of string tokens and verify it's correct */
-	for (i = 0; i < STRING_NB_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(string_nb_strs); i++) {
 		memset(&token, 0, sizeof(token));

 		token.string_data.str = string_nb_strs[i].str;
@@ -348,7 +335,7 @@ test_parse_string_valid(void)
 	}

 	/* get token at specified position and verify it's correct */
-	for (i = 0; i < STRING_ELT_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(string_elt_strs); i++) {
 		memset(&token, 0, sizeof(token));
 		memset(buf, 0, sizeof(buf));

@@ -368,7 +355,7 @@ test_parse_string_valid(void)
 	}

 	/* cover all cases with help strings */
-	for (i = 0; i < STRING_HELP_STRS_SIZE; i++) {
+	for (i = 0; i < RTE_DIM(string_help_strs); i++) {
 		memset(&help_token, 0, sizeof(help_token));
 		memset(help_str, 0, sizeof(help_str));
 		help_token.string_data.str = string_help_strs[i];
diff --git a/app/test/test_debug.c b/app/test/test_debug.c
index faf2cf557..25eab97e2 100644
--- a/app/test/test_debug.c
+++ b/app/test/test_debug.c
@@ -81,7 +81,7 @@ test_exit(void)
 {
 	int test_vals[] = { 0, 1, 2, 255, -1 };
 	unsigned i;
-	for (i = 0; i < sizeof(test_vals) / sizeof(test_vals[0]); i++){
+	for (i = 0; i < RTE_DIM(test_vals); i++) {
 		if (test_exit_val(test_vals[i]) < 0)
 			return -1;
 	}
diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c
index 5b2c0f5cd..4ee809e3d 100644
--- a/app/test/test_eal_flags.c
+++ b/app/test/test_eal_flags.c
@@ -36,8 +36,7 @@
 #define memtest1 "memtest1"
 #define memtest2 "memtest2"
 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
-#define launch_proc(ARGV) process_dup(ARGV, \
-		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 enum hugepage_action {
 	HUGEPAGE_CHECK_EXISTS = 0,
@@ -268,7 +267,7 @@ test_whitelist_flag(void)
 			pci_whitelist, "08:00.1,type=normal",
 	};

-	for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
+	for (i = 0; i < RTE_DIM(wlinval); i++) {
 		if (launch_proc(wlinval[i]) == 0) {
 			printf("Error - process did run ok with invalid "
 			    "whitelist parameter\n");
@@ -324,7 +323,7 @@ test_invalid_b_flag(void)

 	int i;

-	for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
+	for (i = 0; i != RTE_DIM(blinval); i++) {
 		if (launch_proc(blinval[i]) == 0) {
 			printf("Error - process did run ok with invalid "
 			    "blacklist parameter\n");
@@ -425,7 +424,7 @@ test_invalid_r_flag(void)

 	int i;

-	for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
+	for (i = 0; i != RTE_DIM(rinval); i++) {
 		if (launch_proc(rinval[i]) == 0) {
 			printf("Error - process did run ok with invalid "
 			    "-r (rank) parameter\n");
diff --git a/app/test/test_errno.c b/app/test/test_errno.c
index 7df8192d5..3ff0456a5 100644
--- a/app/test/test_errno.c
+++ b/app/test/test_errno.c
@@ -36,7 +36,7 @@ test_errno(void)
 	if (rte_errno != 0)
 		return -1;
 	/* check for standard errors we return the same as libc */
-	for (i = 0; i < sizeof(std_errs)/sizeof(std_errs[0]); i++){
+	for (i = 0; i < RTE_DIM(std_errs); i++) {
 		rte_retval = rte_strerror(std_errs[i]);
 		libc_retval = strerror(std_errs[i]);
 		printf("rte_strerror: '%s', strerror: '%s'\n",
@@ -47,7 +47,7 @@ test_errno(void)
 	/* for rte-specific errors ensure we return a different string
 	 * and that the string for libc is for an unknown error
 	 */
-	for (i = 0; i < sizeof(rte_errs)/sizeof(rte_errs[0]); i++){
+	for (i = 0; i < RTE_DIM(rte_errs); i++) {
 		rte_retval = rte_strerror(rte_errs[i]);
 		libc_retval = strerror(rte_errs[i]);
 		printf("rte_strerror: '%s', strerror: '%s'\n",
diff --git a/app/test/test_func_reentrancy.c b/app/test/test_func_reentrancy.c
index 99ad902a2..78c6d6bd1 100644
--- a/app/test/test_func_reentrancy.c
+++ b/app/test/test_func_reentrancy.c
@@ -480,7 +480,7 @@ test_func_reentrancy(void)
 	else if (rte_lcore_count() > MAX_LCORES)
 		printf("Too many lcores, some cores will be disabled\n");

-	for (case_id = 0; case_id < sizeof(test_cases)/sizeof(struct test_case); case_id ++) {
+	for (case_id = 0; case_id < RTE_DIM(test_cases); case_id ++) {
 		pt_case = &test_cases[case_id];
 		if (pt_case->func == NULL)
 			continue;
diff --git a/app/test/test_hash.c b/app/test/test_hash.c
index 0052dce2d..fbd5725c6 100644
--- a/app/test/test_hash.c
+++ b/app/test/test_hash.c
@@ -235,15 +235,9 @@ static void run_hash_func_tests(void)
 {
 	unsigned i, j, k;

-	for (i = 0;
-	     i < sizeof(hashtest_funcs) / sizeof(rte_hash_function);
-	     i++) {
-		for (j = 0;
-		     j < sizeof(hashtest_initvals) / sizeof(uint32_t);
-		     j++) {
-			for (k = 0;
-			     k < sizeof(hashtest_key_lens) / sizeof(uint32_t);
-			     k++) {
+	for (i = 0; i < RTE_DIM(hashtest_funcs); i++) {
+		for (j = 0; j < RTE_DIM(hashtest_initvals); j++) {
+			for (k = 0; k < RTE_DIM(hashtest_key_lens); k++) {
 				run_hash_func_test(hashtest_funcs[i],
 						hashtest_initvals[j],
 						hashtest_key_lens[k]);
diff --git a/app/test/test_hash_functions.c b/app/test/test_hash_functions.c
index c1fc9492d..76d51b6e7 100644
--- a/app/test/test_hash_functions.c
+++ b/app/test/test_hash_functions.c
@@ -152,10 +152,10 @@ verify_precalculated_hash_func_tests(void)
 	for (i = 0; i < 64; i++)
 		key[i] = (uint8_t) i;

-	for (i = 0; i < sizeof(hashtest_key_lens) / sizeof(uint32_t); i++) {
-		for (j = 0; j < sizeof(hashtest_initvals) / sizeof(uint32_t); j++) {
+	for (i = 0; i < RTE_DIM(hashtest_key_lens); i++) {
+		for (j = 0; j < RTE_DIM(hashtest_initvals); j++) {
 			hash = rte_jhash(key, hashtest_key_lens[i],
-					hashtest_initvals[j]);
+					 hashtest_initvals[j]);
 			if (hash != hash_values_jhash[j][i]) {
 				printf("jhash for %u bytes with initial value 0x%x."
 				       "Expected 0x%x, but got 0x%x\n",
@@ -192,8 +192,8 @@ verify_jhash_32bits(void)
 	for (i = 0; i < 64; i++)
 		key[i] = rand() & 0xff;

-	for (i = 0; i < sizeof(hashtest_key_lens) / sizeof(uint32_t); i++) {
-		for (j = 0; j < sizeof(hashtest_initvals) / sizeof(uint32_t); j++) {
+	for (i = 0; i < RTE_DIM(hashtest_key_lens); i++) {
+		for (j = 0; j < RTE_DIM(hashtest_initvals); j++) {
 			/* Key size must be multiple of 4 (32 bits) */
 			if ((hashtest_key_lens[i] & 0x3) == 0) {
 				hash = rte_jhash(key, hashtest_key_lens[i],
diff --git a/app/test/test_lpm.c b/app/test/test_lpm.c
index e969fe051..3a3fd097f 100644
--- a/app/test/test_lpm.c
+++ b/app/test/test_lpm.c
@@ -64,7 +64,6 @@ rte_lpm_test tests[] = {
 	test18
 };

-#define NUM_LPM_TESTS (sizeof(tests)/sizeof(tests[0]))
 #define MAX_DEPTH 32
 #define MAX_RULES 256
 #define NUMBER_TBL8S 256
@@ -1276,7 +1275,7 @@ test_lpm(void)
 	unsigned i;
 	int status, global_status = 0;

-	for (i = 0; i < NUM_LPM_TESTS; i++) {
+	for (i = 0; i < RTE_DIM(tests); i++) {
 		status = tests[i]();
 		if (status < 0) {
 			printf("ERROR: LPM Test %u: FAIL\n", i);
diff --git a/app/test/test_lpm6.c b/app/test/test_lpm6.c
index 670aadb40..0d664546f 100644
--- a/app/test/test_lpm6.c
+++ b/app/test/test_lpm6.c
@@ -85,7 +85,6 @@ rte_lpm6_test tests6[] = {
 	test28,
 };

-#define NUM_LPM6_TESTS                (sizeof(tests6)/sizeof(tests6[0]))
 #define MAX_DEPTH                                                    128
 #define MAX_RULES                                                1000000
 #define NUMBER_TBL8S                                           (1 << 16)
@@ -1780,7 +1779,7 @@ test_lpm6(void)
 	unsigned i;
 	int status = -1, global_status = 0;

-	for (i = 0; i < NUM_LPM6_TESTS; i++) {
+	for (i = 0; i < RTE_DIM(tests6); i++) {
 		printf("# test %02d\n", i);
 		status = tests6[i]();

diff --git a/app/test/test_lpm6_data.h b/app/test/test_lpm6_data.h
index 565138a31..c3894f730 100644
--- a/app/test/test_lpm6_data.h
+++ b/app/test/test_lpm6_data.h
@@ -1029,8 +1029,7 @@ static struct rules_tbl_entry large_route_table[] = {
 	{{234, 149, 220, 106, 0, 144, 214, 128, 35, 102, 0, 0, 0, 0, 0, 0}, 79, 106},
 };

-#define  NUM_ROUTE_ENTRIES \
-	(sizeof(large_route_table) / sizeof(large_route_table[0]))
+#define  NUM_ROUTE_ENTRIES RTE_DIM(large_route_table)

 #define  NUM_IPS_ENTRIES (NUM_ROUTE_ENTRIES * 100)

diff --git a/app/test/test_malloc.c b/app/test/test_malloc.c
index a16e28cc3..67a48ba38 100644
--- a/app/test/test_malloc.c
+++ b/app/test/test_malloc.c
@@ -255,7 +255,7 @@ test_str_to_size(void)
 			{"18446744073709551616", 0} /* ULLONG_MAX + 1 == out of range*/
 	};
 	unsigned i;
-	for (i = 0; i < sizeof(test_values)/sizeof(test_values[0]); i++)
+	for (i = 0; i < RTE_DIM(test_values); i++)
 		if (rte_str_to_size(test_values[i].str) != test_values[i].value)
 			return -1;
 	return 0;
diff --git a/app/test/test_memcpy.c b/app/test/test_memcpy.c
index 2c69ad964..1ab86f496 100644
--- a/app/test/test_memcpy.c
+++ b/app/test/test_memcpy.c
@@ -103,12 +103,11 @@ static int
 func_test(void)
 {
 	unsigned int off_src, off_dst, i;
-	unsigned int num_buf_sizes = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
 	int ret;

 	for (off_src = 0; off_src < ALIGNMENT_UNIT; off_src++) {
 		for (off_dst = 0; off_dst < ALIGNMENT_UNIT; off_dst++) {
-			for (i = 0; i < num_buf_sizes; i++) {
+			for (i = 0; i < RTE_DIM(buf_sizes); i++) {
 				ret = test_single_memcpy(off_src, off_dst,
 				                         buf_sizes[i]);
 				if (ret != 0)
diff --git a/app/test/test_memcpy_perf.c b/app/test/test_memcpy_perf.c
index 6f436f3ef..00a2092b4 100644
--- a/app/test/test_memcpy_perf.c
+++ b/app/test/test_memcpy_perf.c
@@ -250,9 +250,8 @@ perf_test_constant_unaligned(void)
 static inline void
 perf_test_variable_aligned(void)
 {
-	unsigned n = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
 	unsigned i;
-	for (i = 0; i < n; i++) {
+	for (i = 0; i < RTE_DIM(buf_sizes); i++) {
 		ALL_PERF_TESTS_FOR_SIZE((size_t)buf_sizes[i]);
 	}
 }
@@ -261,9 +260,8 @@ perf_test_variable_aligned(void)
 static inline void
 perf_test_variable_unaligned(void)
 {
-	unsigned n = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
 	unsigned i;
-	for (i = 0; i < n; i++) {
+	for (i = 0; i < RTE_DIM(buf_sizes); i++) {
 		ALL_PERF_TESTS_FOR_SIZE_UNALIGNED((size_t)buf_sizes[i]);
 	}
 }
diff --git a/app/test/test_mp_secondary.c b/app/test/test_mp_secondary.c
index 2ac33f781..ac15ddbf2 100644
--- a/app/test/test_mp_secondary.c
+++ b/app/test/test_mp_secondary.c
@@ -47,8 +47,7 @@

 #include "process.h"

-#define launch_proc(ARGV) process_dup(ARGV, \
-		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 /*
  * This function is called in the primary i.e. main test, to spawn off secondary
diff --git a/app/test/test_pdump.c b/app/test/test_pdump.c
index af206968b..ad183184c 100644
--- a/app/test/test_pdump.c
+++ b/app/test/test_pdump.c
@@ -18,8 +18,7 @@
 #include "process.h"
 #include "test_pdump.h"

-#define launch_p(ARGV) process_dup(ARGV, \
-		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_p(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 struct rte_ring *ring_server;
 uint16_t portid;
diff --git a/app/test/test_pmd_ring_perf.c b/app/test/test_pmd_ring_perf.c
index 6318da18f..3b2ff9cb4 100644
--- a/app/test/test_pmd_ring_perf.c
+++ b/app/test/test_pmd_ring_perf.c
@@ -100,7 +100,7 @@ test_bulk_enqueue_dequeue(void)
 	unsigned sz, i = 0;
 	struct rte_mbuf *burst[MAX_BURST] = {0};

-	for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
+	for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
 		const uint64_t sc_start = rte_rdtsc();
 		for (i = 0; i < iterations; i++) {
 			rte_ring_sp_enqueue_bulk(r, (void *)burst,
diff --git a/app/test/test_power.c b/app/test/test_power.c
index 0ff2aa0d1..c82b35a60 100644
--- a/app/test/test_power.c
+++ b/app/test/test_power.c
@@ -135,10 +135,8 @@ test_power(void)
 			PM_ENV_KVM_VM,
 			PM_ENV_PSTATE_CPUFREQ};

-	const int envs_size = sizeof(envs)/sizeof(enum power_management_env);
-
 	int i;
-	for (i = 0; i < envs_size; ++i) {
+	for (i = 0; i < (int)RTE_DIM(envs); ++i) {

 		/* Test setting a valid environment */
 		ret = rte_power_set_env(envs[i]);
diff --git a/app/test/test_ring_perf.c b/app/test/test_ring_perf.c
index ce23ee737..ee21faf71 100644
--- a/app/test/test_ring_perf.c
+++ b/app/test/test_ring_perf.c
@@ -293,7 +293,7 @@ run_on_core_pair(struct lcore_pair *cores, struct rte_ring *r, const int esize)
 		f2 = dequeue_bulk_16B;
 	}

-	for (i = 0; i < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); i++) {
+	for (i = 0; i < RTE_DIM(bulk_sizes); i++) {
 		lcore_count = 0;
 		param1.size = param2.size = bulk_sizes[i];
 		param1.r = param2.r = r;
diff --git a/app/test/test_timer_secondary.c b/app/test/test_timer_secondary.c
index 790f18052..7a3bc873b 100644
--- a/app/test/test_timer_secondary.c
+++ b/app/test/test_timer_secondary.c
@@ -23,8 +23,7 @@
 #define TEST_INFO_MZ_NAME	"test_timer_info_mz"
 #define MSECPERSEC		1E3

-#define launch_proc(ARGV) \
-	process_dup(ARGV, sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 struct test_info {
 	unsigned int mstr_lcore;
--
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH v3 2/3] examples: use RTE_DIM to calculate array size
  2020-01-24  4:55   ` [dpdk-dev] [PATCH v3 " pbhagavatula
@ 2020-01-24  4:55     ` pbhagavatula
  2020-01-24  4:55     ` [dpdk-dev] [PATCH v3 3/3] lib: " pbhagavatula
  2020-02-05 10:22     ` [dpdk-dev] [PATCH v3 1/3] app: " David Marchand
  2 siblings, 0 replies; 16+ messages in thread
From: pbhagavatula @ 2020-01-24  4:55 UTC (permalink / raw)
  To: Cristian Dumitrescu, Marko Kovacevic, Ori Kam, Bruce Richardson,
	Radu Nicolau, Akhil Goyal, Tomasz Kantecki, Sunil Kumar Kori,
	Pavan Nikhilesh, David Hunt, John McNamara, Kirill Rybalchenko,
	Harry van Haaren, Xiaoyun Li
  Cc: dev

From: Pavan Nikhilesh <pbhagavatula@marvell.com>

use RTE_DIM macro to calculate array size.

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 examples/ip_pipeline/parser.c  |  2 +-
 examples/ipv4_multicast/main.c |  6 +-----
 examples/l3fwd-power/main.c    | 18 ++++--------------
 examples/l3fwd/l3fwd_em.c      |  6 ++----
 examples/l3fwd/l3fwd_lpm.c     |  9 ++-------
 examples/vmdq/main.c           |  2 +-
 examples/vmdq_dcb/main.c       |  2 +-
 7 files changed, 12 insertions(+), 33 deletions(-)

diff --git a/examples/ip_pipeline/parser.c b/examples/ip_pipeline/parser.c
index 3fffeb586..fb0769fe3 100644
--- a/examples/ip_pipeline/parser.c
+++ b/examples/ip_pipeline/parser.c
@@ -528,7 +528,7 @@ my_ether_aton(const char *a)
 		if (errno != 0 || end == a || (end[0] != ':' && end[0] != 0))
 			return NULL;
 		a = end + 1;
-	} while (++i != sizeof(o) / sizeof(o[0]) && end[0] != 0);
+	} while (++i != RTE_DIM(o) && end[0] != 0);
 
 	/* Junk at the end of line */
 	if (end[0] != 0)
diff --git a/examples/ipv4_multicast/main.c b/examples/ipv4_multicast/main.c
index 63333b5b6..1fb28513b 100644
--- a/examples/ipv4_multicast/main.c
+++ b/examples/ipv4_multicast/main.c
@@ -155,10 +155,6 @@ static struct mcast_group_params mcast_group_table[] = {
 		{RTE_IPV4(224,0,0,115), 0xF},
 };
 
-#define N_MCAST_GROUPS \
-	(sizeof (mcast_group_table) / sizeof (mcast_group_table[0]))
-
-
 /* Send burst of packets on an output interface */
 static void
 send_burst(struct lcore_queue_conf *qconf, uint16_t port)
@@ -555,7 +551,7 @@ init_mcast_hash(void)
 		return -1;
 	}
 
-	for (i = 0; i < N_MCAST_GROUPS; i ++){
+	for (i = 0; i < RTE_DIM(mcast_group_table); i++) {
 		if (rte_fbk_hash_add_key(mcast_hash,
 			mcast_group_table[i].ip,
 			mcast_group_table[i].port_mask) < 0) {
diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index d049d8a5d..e90d18b24 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -238,8 +238,7 @@ static struct lcore_params lcore_params_array_default[] = {
 };
 
 struct lcore_params *lcore_params = lcore_params_array_default;
-uint16_t nb_lcore_params = sizeof(lcore_params_array_default) /
-				sizeof(lcore_params_array_default[0]);
+uint16_t nb_lcore_params = RTE_DIM(lcore_params_array_default);
 
 static struct rte_eth_conf port_conf = {
 	.rxmode = {
@@ -326,12 +325,6 @@ static lookup_struct_t *ipv6_l3fwd_lookup_struct[NB_SOCKETS];
 
 #define L3FWD_HASH_ENTRIES	1024
 
-#define IPV4_L3FWD_NUM_ROUTES \
-	(sizeof(ipv4_l3fwd_route_array) / sizeof(ipv4_l3fwd_route_array[0]))
-
-#define IPV6_L3FWD_NUM_ROUTES \
-	(sizeof(ipv6_l3fwd_route_array) / sizeof(ipv6_l3fwd_route_array[0]))
-
 static uint16_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
 static uint16_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
 #endif
@@ -354,9 +347,6 @@ static struct ipv4_l3fwd_route ipv4_l3fwd_route_array[] = {
 	{RTE_IPV4(8,1,1,0), 24, 7},
 };
 
-#define IPV4_L3FWD_NUM_ROUTES \
-	(sizeof(ipv4_l3fwd_route_array) / sizeof(ipv4_l3fwd_route_array[0]))
-
 #define IPV4_L3FWD_LPM_MAX_RULES     1024
 
 typedef struct rte_lpm lookup_struct_t;
@@ -1841,7 +1831,7 @@ setup_hash(int socketid)
 
 
 	/* populate the ipv4 hash */
-	for (i = 0; i < IPV4_L3FWD_NUM_ROUTES; i++) {
+	for (i = 0; i < RTE_DIM(ipv4_l3fwd_route_array); i++) {
 		ret = rte_hash_add_key (ipv4_l3fwd_lookup_struct[socketid],
 				(void *) &ipv4_l3fwd_route_array[i].key);
 		if (ret < 0) {
@@ -1854,7 +1844,7 @@ setup_hash(int socketid)
 	}
 
 	/* populate the ipv6 hash */
-	for (i = 0; i < IPV6_L3FWD_NUM_ROUTES; i++) {
+	for (i = 0; i < RTE_DIM(ipv6_l3fwd_route_array); i++) {
 		ret = rte_hash_add_key (ipv6_l3fwd_lookup_struct[socketid],
 				(void *) &ipv6_l3fwd_route_array[i].key);
 		if (ret < 0) {
@@ -1891,7 +1881,7 @@ setup_lpm(int socketid)
 				" on socket %d\n", socketid);
 
 	/* populate the LPM table */
-	for (i = 0; i < IPV4_L3FWD_NUM_ROUTES; i++) {
+	for (i = 0; i < RTE_DIM(ipv4_l3fwd_route_array); i++) {
 		ret = rte_lpm_add(ipv4_l3fwd_lookup_struct[socketid],
 			ipv4_l3fwd_route_array[i].ip,
 			ipv4_l3fwd_route_array[i].depth,
diff --git a/examples/l3fwd/l3fwd_em.c b/examples/l3fwd/l3fwd_em.c
index 74a7c8fa4..1b1cce47d 100644
--- a/examples/l3fwd/l3fwd_em.c
+++ b/examples/l3fwd/l3fwd_em.c
@@ -203,11 +203,9 @@ ipv6_hash_crc(const void *data, __rte_unused uint32_t data_len,
 	return init_val;
 }
 
-#define IPV4_L3FWD_EM_NUM_ROUTES \
-	(sizeof(ipv4_l3fwd_em_route_array) / sizeof(ipv4_l3fwd_em_route_array[0]))
+#define IPV4_L3FWD_EM_NUM_ROUTES RTE_DIM(ipv4_l3fwd_em_route_array)
 
-#define IPV6_L3FWD_EM_NUM_ROUTES \
-	(sizeof(ipv6_l3fwd_em_route_array) / sizeof(ipv6_l3fwd_em_route_array[0]))
+#define IPV6_L3FWD_EM_NUM_ROUTES RTE_DIM(ipv6_l3fwd_em_route_array)
 
 static uint8_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
 static uint8_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
diff --git a/examples/l3fwd/l3fwd_lpm.c b/examples/l3fwd/l3fwd_lpm.c
index 349de2703..1b3950d91 100644
--- a/examples/l3fwd/l3fwd_lpm.c
+++ b/examples/l3fwd/l3fwd_lpm.c
@@ -65,11 +65,6 @@ static struct ipv6_l3fwd_lpm_route ipv6_l3fwd_lpm_route_array[] = {
 	{{32, 1, 2, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0}, 48, 7},
 };
 
-#define IPV4_L3FWD_LPM_NUM_ROUTES \
-	(sizeof(ipv4_l3fwd_lpm_route_array) / sizeof(ipv4_l3fwd_lpm_route_array[0]))
-#define IPV6_L3FWD_LPM_NUM_ROUTES \
-	(sizeof(ipv6_l3fwd_lpm_route_array) / sizeof(ipv6_l3fwd_lpm_route_array[0]))
-
 #define IPV4_L3FWD_LPM_MAX_RULES         1024
 #define IPV4_L3FWD_LPM_NUMBER_TBL8S (1 << 8)
 #define IPV6_L3FWD_LPM_MAX_RULES         1024
@@ -277,7 +272,7 @@ setup_lpm(const int socketid)
 			socketid);
 
 	/* populate the LPM table */
-	for (i = 0; i < IPV4_L3FWD_LPM_NUM_ROUTES; i++) {
+	for (i = 0; i < RTE_DIM(ipv4_l3fwd_lpm_route_array); i++) {
 		struct in_addr in;
 
 		/* skip unused ports */
@@ -317,7 +312,7 @@ setup_lpm(const int socketid)
 			socketid);
 
 	/* populate the LPM table */
-	for (i = 0; i < IPV6_L3FWD_LPM_NUM_ROUTES; i++) {
+	for (i = 0; i < RTE_DIM(ipv6_l3fwd_lpm_route_array); i++) {
 
 		/* skip unused ports */
 		if ((1 << ipv6_l3fwd_lpm_route_array[i].if_out &
diff --git a/examples/vmdq/main.c b/examples/vmdq/main.c
index 6e6fc91ec..011110920 100644
--- a/examples/vmdq/main.c
+++ b/examples/vmdq/main.c
@@ -503,7 +503,7 @@ lcore_main(__attribute__((__unused__)) void *dummy)
 
 	for (;;) {
 		struct rte_mbuf *buf[MAX_PKT_BURST];
-		const uint16_t buf_size = sizeof(buf) / sizeof(buf[0]);
+		const uint16_t buf_size = RTE_DIM(buf);
 
 		for (p = 0; p < num_ports; p++) {
 			const uint8_t sport = ports[p];
diff --git a/examples/vmdq_dcb/main.c b/examples/vmdq_dcb/main.c
index 594c4f195..f417b2fd9 100644
--- a/examples/vmdq_dcb/main.c
+++ b/examples/vmdq_dcb/main.c
@@ -582,7 +582,7 @@ lcore_main(void *arg)
 
 	for (;;) {
 		struct rte_mbuf *buf[MAX_PKT_BURST];
-		const uint16_t buf_size = sizeof(buf) / sizeof(buf[0]);
+		const uint16_t buf_size = RTE_DIM(buf);
 		for (p = 0; p < num_ports; p++) {
 			const uint8_t src = ports[p];
 			const uint8_t dst = ports[p ^ 1]; /* 0 <-> 1, 2 <-> 3 etc */
-- 
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH v3 3/3] lib: use RTE_DIM to calculate array size
  2020-01-24  4:55   ` [dpdk-dev] [PATCH v3 " pbhagavatula
  2020-01-24  4:55     ` [dpdk-dev] [PATCH v3 2/3] examples: " pbhagavatula
@ 2020-01-24  4:55     ` pbhagavatula
  2020-01-24 10:37       ` Laatz, Kevin
  2020-02-05 10:22     ` [dpdk-dev] [PATCH v3 1/3] app: " David Marchand
  2 siblings, 1 reply; 16+ messages in thread
From: pbhagavatula @ 2020-01-24  4:55 UTC (permalink / raw)
  To: Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko,
	Konstantin Ananyev, Cristian Dumitrescu, Kevin Laatz
  Cc: dev, Pavan Nikhilesh

From: Pavan Nikhilesh <pbhagavatula@marvell.com>

use RTE_DIM to calculate array size.

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/librte_ethdev/rte_ethdev.c                   | 8 +++-----
 lib/librte_ip_frag/ip_frag_internal.c            | 5 ++---
 lib/librte_port/rte_port_eventdev.c              | 4 ++--
 lib/librte_port/rte_port_eventdev.h              | 4 ----
 lib/librte_telemetry/rte_telemetry_parser_test.c | 4 +---
 5 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 9d62dc436..774c721b3 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -86,7 +86,7 @@ static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
 		rx_nombuf)},
 };
 
-#define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
+#define RTE_NB_STATS RTE_DIM(rte_stats_strings)
 
 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
 	{"packets", offsetof(struct rte_eth_stats, q_ipackets)},
@@ -94,15 +94,13 @@ static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
 	{"errors", offsetof(struct rte_eth_stats, q_errors)},
 };
 
-#define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) /	\
-		sizeof(rte_rxq_stats_strings[0]))
+#define RTE_NB_RXQ_STATS RTE_DIM(rte_rxq_stats_strings)
 
 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
 	{"packets", offsetof(struct rte_eth_stats, q_opackets)},
 	{"bytes", offsetof(struct rte_eth_stats, q_obytes)},
 };
-#define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) /	\
-		sizeof(rte_txq_stats_strings[0]))
+#define RTE_NB_TXQ_STATS RTE_DIM(rte_txq_stats_strings)
 
 #define RTE_RX_OFFLOAD_BIT2STR(_name)	\
 	{ DEV_RX_OFFLOAD_##_name, #_name }
diff --git a/lib/librte_ip_frag/ip_frag_internal.c b/lib/librte_ip_frag/ip_frag_internal.c
index 97470a872..b436a4c93 100644
--- a/lib/librte_ip_frag/ip_frag_internal.c
+++ b/lib/librte_ip_frag/ip_frag_internal.c
@@ -107,8 +107,7 @@ ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr,
 				IP_LAST_FRAG_IDX : UINT32_MAX;
 
 	/* this is the intermediate fragment. */
-	} else if ((idx = fp->last_idx) <
-		sizeof (fp->frags) / sizeof (fp->frags[0])) {
+	} else if ((idx = fp->last_idx) < RTE_DIM(fp->frags)) {
 		fp->last_idx++;
 	}
 
@@ -116,7 +115,7 @@ ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr,
 	 * erroneous packet: either exceed max allowed number of fragments,
 	 * or duplicate first/last fragment encountered.
 	 */
-	if (idx >= sizeof (fp->frags) / sizeof (fp->frags[0])) {
+	if (idx >= RTE_DIM(fp->frags)) {
 
 		/* report an error. */
 		if (fp->key.key_len == IPV4_KEYLEN)
diff --git a/lib/librte_port/rte_port_eventdev.c b/lib/librte_port/rte_port_eventdev.c
index aa93bd3a2..fd7dac9a5 100644
--- a/lib/librte_port/rte_port_eventdev.c
+++ b/lib/librte_port/rte_port_eventdev.c
@@ -179,7 +179,7 @@ rte_port_eventdev_writer_create(void *params, int socket_id)
 	port->evt_op = conf->evt_op;
 	memset(&port->ev, 0, sizeof(port->ev));
 
-	for (i = 0; i < ARRAY_SIZE(port->ev); i++) {
+	for (i = 0; i < RTE_DIM(port->ev); i++) {
 		port->ev[i].queue_id = port->queue_id;
 		port->ev[i].sched_type = port->sched_type;
 		port->ev[i].op = port->evt_op;
@@ -386,7 +386,7 @@ rte_port_eventdev_writer_nodrop_create(void *params, int socket_id)
 	port->evt_op = conf->evt_op;
 	memset(&port->ev, 0, sizeof(port->ev));
 
-	for (i = 0; i < ARRAY_SIZE(port->ev); i++) {
+	for (i = 0; i < RTE_DIM(port->ev); i++) {
 		port->ev[i].queue_id = port->queue_id;
 		port->ev[i].sched_type = port->sched_type;
 		port->ev[i].op = port->evt_op;
diff --git a/lib/librte_port/rte_port_eventdev.h b/lib/librte_port/rte_port_eventdev.h
index acf88f4e9..966e9cdaf 100644
--- a/lib/librte_port/rte_port_eventdev.h
+++ b/lib/librte_port/rte_port_eventdev.h
@@ -9,10 +9,6 @@
 extern "C" {
 #endif
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 /**
  * @file
  * RTE Port Eventdev Interface
diff --git a/lib/librte_telemetry/rte_telemetry_parser_test.c b/lib/librte_telemetry/rte_telemetry_parser_test.c
index 23ec7a77c..6164ef83e 100644
--- a/lib/librte_telemetry/rte_telemetry_parser_test.c
+++ b/lib/librte_telemetry/rte_telemetry_parser_test.c
@@ -463,10 +463,8 @@ rte_telemetry_parser_test(struct telemetry_impl *telemetry)
 	};
 
 
-#define NUM_TEST_TYPES (sizeof(test_types)/sizeof(const char * const))
-
 	uint32_t i;
-	for (i = 0; i < NUM_TEST_TYPES; i++) {
+	for (i = 0; i < RTE_DIM(test_types); i++) {
 		TELEMETRY_LOG_INFO("%s", test_types[i]);
 
 		ret = rte_telemetry_send_get_ports_and_stats_request(telemetry,
-- 
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v3 3/3] lib: use RTE_DIM to calculate array size
  2020-01-24  4:55     ` [dpdk-dev] [PATCH v3 3/3] lib: " pbhagavatula
@ 2020-01-24 10:37       ` Laatz, Kevin
  0 siblings, 0 replies; 16+ messages in thread
From: Laatz, Kevin @ 2020-01-24 10:37 UTC (permalink / raw)
  To: pbhagavatula, Thomas Monjalon, Yigit, Ferruh, Andrew Rybchenko,
	Ananyev, Konstantin, Dumitrescu, Cristian
  Cc: dev

> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
> 
> use RTE_DIM to calculate array size.
> 
> Suggested-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
> Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
> ---
>  lib/librte_ethdev/rte_ethdev.c                   | 8 +++-----
>  lib/librte_ip_frag/ip_frag_internal.c            | 5 ++---
>  lib/librte_port/rte_port_eventdev.c              | 4 ++--
>  lib/librte_port/rte_port_eventdev.h              | 4 ----
>  lib/librte_telemetry/rte_telemetry_parser_test.c | 4 +---
>  5 files changed, 8 insertions(+), 17 deletions(-)

<...>

Acked-by: Kevin Laatz <kevin.laatz@intel.com>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v3 1/3] app: use RTE_DIM to calculate array size
  2020-01-24  4:55   ` [dpdk-dev] [PATCH v3 " pbhagavatula
  2020-01-24  4:55     ` [dpdk-dev] [PATCH v3 2/3] examples: " pbhagavatula
  2020-01-24  4:55     ` [dpdk-dev] [PATCH v3 3/3] lib: " pbhagavatula
@ 2020-02-05 10:22     ` David Marchand
  2020-02-05 13:40       ` David Marchand
  2 siblings, 1 reply; 16+ messages in thread
From: David Marchand @ 2020-02-05 10:22 UTC (permalink / raw)
  To: Pavan Nikhilesh
  Cc: Wenzhuo Lu, Jingjing Wu, Bernard Iremonger, Olivier Matz,
	Yipeng Wang, Sameh Gobriel, Bruce Richardson, Vladimir Medvedkin,
	Anatoly Burakov, Andrew Rybchenko, Reshma Pattan, David Hunt,
	Robert Sanford, Erik Gabriel Carrillo, dev

On Fri, Jan 24, 2020 at 5:56 AM <pbhagavatula@marvell.com> wrote:
>
> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
>
> Use RTE_DIM macro to calculate array size
>
> Suggested-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>

I caught some integer type issue with bypass feature in test-pmd.
Will fix when applying.

For the series,
Acked-by: David Marchand <david.marchand@redhat.com>


--
David Marchand


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH v3 1/3] app: use RTE_DIM to calculate array size
  2020-02-05 10:22     ` [dpdk-dev] [PATCH v3 1/3] app: " David Marchand
@ 2020-02-05 13:40       ` David Marchand
  0 siblings, 0 replies; 16+ messages in thread
From: David Marchand @ 2020-02-05 13:40 UTC (permalink / raw)
  To: Pavan Nikhilesh
  Cc: Wenzhuo Lu, Jingjing Wu, Bernard Iremonger, Olivier Matz,
	Yipeng Wang, Sameh Gobriel, Bruce Richardson, Vladimir Medvedkin,
	Anatoly Burakov, Andrew Rybchenko, Reshma Pattan, David Hunt,
	Robert Sanford, Erik Gabriel Carrillo, dev

On Wed, Feb 5, 2020 at 11:22 AM David Marchand
<david.marchand@redhat.com> wrote:
>
> On Fri, Jan 24, 2020 at 5:56 AM <pbhagavatula@marvell.com> wrote:
> >
> > From: Pavan Nikhilesh <pbhagavatula@marvell.com>
> >
> > Use RTE_DIM macro to calculate array size
> >
> > Suggested-by: David Marchand <david.marchand@redhat.com>
> > Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
>
> I caught some integer type issue with bypass feature in test-pmd.
> Will fix when applying.
>
> For the series,
> Acked-by: David Marchand <david.marchand@redhat.com>

Series applied, thanks Pavan.

-- 
David Marchand


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2020-02-05 13:41 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-28  9:09 [dpdk-dev] [PATCH 1/3] app: use RTE_DIM to calculate array size pbhagavatula
2019-10-28  9:09 ` [dpdk-dev] [PATCH 2/3] examples: " pbhagavatula
2019-10-28  9:09 ` [dpdk-dev] [PATCH 3/3] lib: " pbhagavatula
2019-10-31  9:20 ` [dpdk-dev] [PATCH 1/3] app: " David Marchand
2019-11-07  2:12   ` [dpdk-dev] [EXT] " Pavan Nikhilesh Bhagavatula
2019-11-07  2:58 ` [dpdk-dev] [PATCH v2 " pbhagavatula
2019-11-07  2:58   ` [dpdk-dev] [PATCH v2 2/3] examples: " pbhagavatula
2019-11-07  2:58   ` [dpdk-dev] [PATCH v2 3/3] lib: " pbhagavatula
2019-11-07  9:08     ` Dumitrescu, Cristian
2019-12-10 13:10   ` [dpdk-dev] [PATCH v2 1/3] app: " David Marchand
2020-01-24  4:55   ` [dpdk-dev] [PATCH v3 " pbhagavatula
2020-01-24  4:55     ` [dpdk-dev] [PATCH v3 2/3] examples: " pbhagavatula
2020-01-24  4:55     ` [dpdk-dev] [PATCH v3 3/3] lib: " pbhagavatula
2020-01-24 10:37       ` Laatz, Kevin
2020-02-05 10:22     ` [dpdk-dev] [PATCH v3 1/3] app: " David Marchand
2020-02-05 13:40       ` David Marchand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).