* [PATCH 1/5] cocci: add script to use RTE_DIM
2024-04-16 15:19 [PATCH 0/5] use RTE_DIM where possible Stephen Hemminger
@ 2024-04-16 15:19 ` Stephen Hemminger
2024-04-16 15:19 ` [PATCH 2/5] app: " Stephen Hemminger
` (3 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Stephen Hemminger @ 2024-04-16 15:19 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
New script to find RTE_DIM should be used.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
devtools/cocci/rte-dim.cocci | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 devtools/cocci/rte-dim.cocci
diff --git a/devtools/cocci/rte-dim.cocci b/devtools/cocci/rte-dim.cocci
new file mode 100644
index 0000000000..e7fcadec98
--- /dev/null
+++ b/devtools/cocci/rte-dim.cocci
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: BSD-3-Clause
+// Use RTE_DIM macro instead of dividing sizeof array with sizeof an elmemnt
+//
+// Based of Linux kernela array_size.cocci
+//
+@@
+type T;
+T[] E;
+@@
+(
+|
+- (sizeof(E)/sizeof(E[...]))
++ RTE_DIM(E)
+|
+- (sizeof(E)/sizeof(*E))
++ RTE_DIM(E)
+|
+- (sizeof(E)/sizeof(T))
++ RTE_DIM(E)
+|
+- RTE_DIM((E))
++ RTE_DIM(E)
+)
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 2/5] app: use RTE_DIM
2024-04-16 15:19 [PATCH 0/5] use RTE_DIM where possible Stephen Hemminger
2024-04-16 15:19 ` [PATCH 1/5] cocci: add script to use RTE_DIM Stephen Hemminger
@ 2024-04-16 15:19 ` Stephen Hemminger
2024-04-16 15:30 ` Tyler Retzlaff
2024-04-17 6:13 ` [EXTERNAL] " Akhil Goyal
2024-04-16 15:19 ` [PATCH 3/5] lib: " Stephen Hemminger
` (2 subsequent siblings)
4 siblings, 2 replies; 13+ messages in thread
From: Stephen Hemminger @ 2024-04-16 15:19 UTC (permalink / raw)
To: dev
Cc: Stephen Hemminger, Wisam Jaddo, Thomas Monjalon, Ferruh Yigit,
Andrew Rybchenko, Akhil Goyal, Anoob Joseph
Use RTE_DIM instead of computing directly with sizeof.
Patch automatically generated via cocci/rte_dim.cocci.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
app/test-flow-perf/main.c | 4 +--
app/test/test_ethdev_link.c | 3 +-
app/test/test_security_inline_macsec.c | 47 +++++++++++++-------------
3 files changed, 25 insertions(+), 29 deletions(-)
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index e224ef6798..e9ef1ae04c 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -965,9 +965,7 @@ args_parse(int argc, char **argv)
"meter-profile") == 0) {
i = 0;
token = strsep(&optarg, ",\0");
- while (token != NULL && i < sizeof(
- meter_profile_values) /
- sizeof(uint64_t)) {
+ while (token != NULL && i < RTE_DIM(meter_profile_values)) {
meter_profile_values[i++] = atol(token);
token = strsep(&optarg, ",\0");
}
diff --git a/app/test/test_ethdev_link.c b/app/test/test_ethdev_link.c
index f063a5fe26..e305df71be 100644
--- a/app/test/test_ethdev_link.c
+++ b/app/test/test_ethdev_link.c
@@ -135,8 +135,7 @@ test_link_speed_all_values(void)
{ "Invalid", 50505 }
};
- for (i = 0; i < sizeof(speed_str_map) / sizeof(struct link_speed_t);
- i++) {
+ for (i = 0; i < RTE_DIM(speed_str_map); i++) {
speed = rte_eth_link_speed_to_str(speed_str_map[i].link_speed);
TEST_ASSERT_BUFFERS_ARE_EQUAL(speed_str_map[i].value,
speed, strlen(speed_str_map[i].value),
diff --git a/app/test/test_security_inline_macsec.c b/app/test/test_security_inline_macsec.c
index f11e9da8c3..26f7504dc2 100644
--- a/app/test/test_security_inline_macsec.c
+++ b/app/test/test_security_inline_macsec.c
@@ -1294,7 +1294,7 @@ test_inline_macsec_encap_all(void)
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
- size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+ size = RTE_DIM(list_mcs_cipher_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_ENCAP, &opts);
@@ -1332,7 +1332,7 @@ test_inline_macsec_decap_all(void)
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
- size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+ size = RTE_DIM(list_mcs_cipher_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_DECAP, &opts);
@@ -1371,7 +1371,7 @@ test_inline_macsec_auth_only_all(void)
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
- size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+ size = RTE_DIM(list_mcs_integrity_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_integrity_vectors[i];
@@ -1410,7 +1410,7 @@ test_inline_macsec_verify_only_all(void)
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
- size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+ size = RTE_DIM(list_mcs_integrity_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_integrity_vectors[i];
@@ -1451,7 +1451,7 @@ test_inline_macsec_encap_decap_all(void)
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
- size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+ size = RTE_DIM(list_mcs_cipher_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
@@ -1492,7 +1492,7 @@ test_inline_macsec_auth_verify_all(void)
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
- size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+ size = RTE_DIM(list_mcs_integrity_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_integrity_vectors[i];
@@ -1578,7 +1578,7 @@ test_inline_macsec_with_vlan(void)
opts.nb_td = 1;
opts.mtu = RTE_ETHER_MTU;
- size = (sizeof(list_mcs_vlan_vectors) / sizeof((list_mcs_vlan_vectors)[0]));
+ size = RTE_DIM(list_mcs_vlan_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_vlan_vectors[i];
@@ -1653,7 +1653,7 @@ test_inline_macsec_pkt_drop(void)
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
- size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0]));
+ size = RTE_DIM(list_mcs_err_cipher_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_err_cipher_vectors[i];
@@ -1693,8 +1693,7 @@ test_inline_macsec_untagged_rx(void)
opts.mtu = RTE_ETHER_MTU;
opts.check_untagged_rx = 1;
- size = (sizeof(list_mcs_untagged_cipher_vectors) /
- sizeof((list_mcs_untagged_cipher_vectors)[0]));
+ size = RTE_DIM(list_mcs_untagged_cipher_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_untagged_cipher_vectors[i];
@@ -1747,7 +1746,7 @@ test_inline_macsec_bad_tag_rx(void)
opts.mtu = RTE_ETHER_MTU;
opts.check_bad_tag_cnt = 1;
- size = (sizeof(list_mcs_bad_tag_vectors) / sizeof((list_mcs_bad_tag_vectors)[0]));
+ size = RTE_DIM(list_mcs_bad_tag_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_bad_tag_vectors[i];
@@ -1786,7 +1785,7 @@ test_inline_macsec_sa_not_in_use(void)
opts.mtu = RTE_ETHER_MTU;
opts.check_sa_not_in_use = 1;
- size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+ size = RTE_DIM(list_mcs_cipher_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
@@ -1825,7 +1824,7 @@ test_inline_macsec_decap_stats(void)
opts.mtu = RTE_ETHER_MTU;
opts.check_decap_stats = 1;
- size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+ size = RTE_DIM(list_mcs_cipher_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
@@ -1866,7 +1865,7 @@ test_inline_macsec_verify_only_stats(void)
opts.mtu = RTE_ETHER_MTU;
opts.check_verify_only_stats = 1;
- size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+ size = RTE_DIM(list_mcs_integrity_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_integrity_vectors[i];
@@ -1906,7 +1905,7 @@ test_inline_macsec_pkts_invalid_stats(void)
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
- size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0]));
+ size = RTE_DIM(list_mcs_err_cipher_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_err_cipher_vectors[i];
@@ -1943,7 +1942,7 @@ test_inline_macsec_pkts_unchecked_stats(void)
opts.mtu = RTE_ETHER_MTU;
opts.check_pkts_unchecked_stats = 1;
- size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+ size = RTE_DIM(list_mcs_integrity_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_integrity_vectors[i];
@@ -1982,7 +1981,7 @@ test_inline_macsec_out_pkts_untagged(void)
opts.mtu = RTE_ETHER_MTU;
opts.check_out_pkts_untagged = 1;
- size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+ size = RTE_DIM(list_mcs_cipher_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_ENCAP, &opts);
@@ -2020,7 +2019,7 @@ test_inline_macsec_out_pkts_toolong(void)
opts.mtu = 50;
opts.check_out_pkts_toolong = 1;
- size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+ size = RTE_DIM(list_mcs_cipher_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_ENCAP, &opts);
@@ -2058,7 +2057,7 @@ test_inline_macsec_encap_stats(void)
opts.mtu = RTE_ETHER_MTU;
opts.check_encap_stats = 1;
- size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+ size = RTE_DIM(list_mcs_cipher_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_ENCAP, &opts);
@@ -2095,7 +2094,7 @@ test_inline_macsec_auth_only_stats(void)
opts.mtu = RTE_ETHER_MTU;
opts.check_auth_only_stats = 1;
- size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+ size = RTE_DIM(list_mcs_integrity_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_integrity_vectors[i];
@@ -2146,7 +2145,7 @@ test_inline_macsec_interrupts_all(void)
rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_MACSEC,
test_macsec_event_callback, &err_vector);
- size = (sizeof(list_mcs_intr_test_vectors) / sizeof((list_mcs_intr_test_vectors)[0]));
+ size = RTE_DIM(list_mcs_intr_test_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_intr_test_vectors[i];
@@ -2194,7 +2193,7 @@ test_inline_macsec_rekey_tx(void)
opts.mtu = RTE_ETHER_MTU;
opts.rekey_en = 1;
- size = (sizeof(list_mcs_rekey_vectors) / sizeof((list_mcs_rekey_vectors)[0]));
+ size = RTE_DIM(list_mcs_rekey_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_rekey_vectors[i];
@@ -2236,7 +2235,7 @@ test_inline_macsec_rekey_rx(void)
opts.mtu = RTE_ETHER_MTU;
opts.rekey_en = 1;
- size = (sizeof(list_mcs_rekey_vectors) / sizeof((list_mcs_rekey_vectors)[0]));
+ size = RTE_DIM(list_mcs_rekey_vectors);
for (i = 0; i < size; i++) {
cur_td = &list_mcs_rekey_vectors[i];
opts.rekey_td = &list_mcs_rekey_vectors[++i];
@@ -2277,7 +2276,7 @@ test_inline_macsec_anti_replay(void)
opts.sectag_insert_mode = 1;
opts.replay_protect = 1;
- size = (sizeof(list_mcs_anti_replay_vectors) / sizeof((list_mcs_anti_replay_vectors)[0]));
+ size = RTE_DIM(list_mcs_anti_replay_vectors);
for (j = 0; j < 2; j++) {
opts.replay_win_sz = replay_win_sz[j];
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/5] app: use RTE_DIM
2024-04-16 15:19 ` [PATCH 2/5] app: " Stephen Hemminger
@ 2024-04-16 15:30 ` Tyler Retzlaff
2024-04-17 6:13 ` [EXTERNAL] " Akhil Goyal
1 sibling, 0 replies; 13+ messages in thread
From: Tyler Retzlaff @ 2024-04-16 15:30 UTC (permalink / raw)
To: Stephen Hemminger
Cc: dev, Wisam Jaddo, Thomas Monjalon, Ferruh Yigit,
Andrew Rybchenko, Akhil Goyal, Anoob Joseph
On Tue, Apr 16, 2024 at 08:19:28AM -0700, Stephen Hemminger wrote:
> Use RTE_DIM instead of computing directly with sizeof.
> Patch automatically generated via cocci/rte_dim.cocci.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: [EXTERNAL] [PATCH 2/5] app: use RTE_DIM
2024-04-16 15:19 ` [PATCH 2/5] app: " Stephen Hemminger
2024-04-16 15:30 ` Tyler Retzlaff
@ 2024-04-17 6:13 ` Akhil Goyal
1 sibling, 0 replies; 13+ messages in thread
From: Akhil Goyal @ 2024-04-17 6:13 UTC (permalink / raw)
To: Stephen Hemminger, dev
Cc: Wisam Jaddo, Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko,
Anoob Joseph
> Use RTE_DIM instead of computing directly with sizeof.
> Patch automatically generated via cocci/rte_dim.cocci.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> app/test-flow-perf/main.c | 4 +--
> app/test/test_ethdev_link.c | 3 +-
> app/test/test_security_inline_macsec.c | 47 +++++++++++++-------------
> 3 files changed, 25 insertions(+), 29 deletions(-)
Acked-by: Akhil Goyal <gakhil@marvell.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 3/5] lib: use RTE_DIM
2024-04-16 15:19 [PATCH 0/5] use RTE_DIM where possible Stephen Hemminger
2024-04-16 15:19 ` [PATCH 1/5] cocci: add script to use RTE_DIM Stephen Hemminger
2024-04-16 15:19 ` [PATCH 2/5] app: " Stephen Hemminger
@ 2024-04-16 15:19 ` Stephen Hemminger
2024-04-16 15:32 ` Tyler Retzlaff
2024-04-16 15:19 ` [PATCH 4/5] examples _use RTE_DIM Stephen Hemminger
2024-04-16 15:19 ` [PATCH 5/5] drivers/net: use RTE_DIM Stephen Hemminger
4 siblings, 1 reply; 13+ messages in thread
From: Stephen Hemminger @ 2024-04-16 15:19 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Reshma Pattan
Use RTE_DIM instead of computing directly with sizeof.
Patch automatically generated via cocci/rte_dim.cocci.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/cmdline/cmdline_vt100.c | 4 +++-
lib/latencystats/rte_latencystats.c | 3 +--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/cmdline/cmdline_vt100.c b/lib/cmdline/cmdline_vt100.c
index 4c9a46c953..61a2ecdd72 100644
--- a/lib/cmdline/cmdline_vt100.c
+++ b/lib/cmdline/cmdline_vt100.c
@@ -8,6 +8,8 @@
#include <stdio.h>
#include <string.h>
+#include <rte_common.h>
+
#include "cmdline_vt100.h"
const char *cmdline_vt100_commands[] = {
@@ -56,7 +58,7 @@ match_command(char *buf, unsigned int size)
size_t cmdlen;
unsigned int i = 0;
- for (i=0 ; i<sizeof(cmdline_vt100_commands)/sizeof(const char *) ; i++) {
+ for (i = 0; i < RTE_DIM(cmdline_vt100_commands); i++) {
cmd = *(cmdline_vt100_commands + i);
cmdlen = strnlen(cmd, CMDLINE_VT100_BUF_SIZE);
diff --git a/lib/latencystats/rte_latencystats.c b/lib/latencystats/rte_latencystats.c
index 4ea9b0d75b..7f8ee19846 100644
--- a/lib/latencystats/rte_latencystats.c
+++ b/lib/latencystats/rte_latencystats.c
@@ -75,8 +75,7 @@ static const struct latency_stats_nameoff lat_stats_strings[] = {
{"jitter_ns", offsetof(struct rte_latency_stats, jitter)},
};
-#define NUM_LATENCY_STATS (sizeof(lat_stats_strings) / \
- sizeof(lat_stats_strings[0]))
+#define NUM_LATENCY_STATS RTE_DIM(lat_stats_strings)
int32_t
rte_latencystats_update(void)
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/5] lib: use RTE_DIM
2024-04-16 15:19 ` [PATCH 3/5] lib: " Stephen Hemminger
@ 2024-04-16 15:32 ` Tyler Retzlaff
0 siblings, 0 replies; 13+ messages in thread
From: Tyler Retzlaff @ 2024-04-16 15:32 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev, Reshma Pattan
On Tue, Apr 16, 2024 at 08:19:29AM -0700, Stephen Hemminger wrote:
> Use RTE_DIM instead of computing directly with sizeof.
> Patch automatically generated via cocci/rte_dim.cocci.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 4/5] examples _use RTE_DIM
2024-04-16 15:19 [PATCH 0/5] use RTE_DIM where possible Stephen Hemminger
` (2 preceding siblings ...)
2024-04-16 15:19 ` [PATCH 3/5] lib: " Stephen Hemminger
@ 2024-04-16 15:19 ` Stephen Hemminger
2024-04-16 15:32 ` Tyler Retzlaff
2024-04-16 15:19 ` [PATCH 5/5] drivers/net: use RTE_DIM Stephen Hemminger
4 siblings, 1 reply; 13+ messages in thread
From: Stephen Hemminger @ 2024-04-16 15:19 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Cristian Dumitrescu
Use RTE_DIM instead of computing directly with sizeof.
Patch automatically generated via cocci/rte_dim.cocci.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
examples/l3fwd/main.c | 3 +--
examples/qos_sched/init.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c
index 8d32ae1dd5..3960d85202 100644
--- a/examples/l3fwd/main.c
+++ b/examples/l3fwd/main.c
@@ -116,8 +116,7 @@ static struct lcore_params lcore_params_array_default[] = {
};
static struct lcore_params * lcore_params = lcore_params_array_default;
-static uint16_t nb_lcore_params = sizeof(lcore_params_array_default) /
- sizeof(lcore_params_array_default[0]);
+static uint16_t nb_lcore_params = RTE_DIM(lcore_params_array_default);
static struct rte_eth_conf port_conf = {
.rxmode = {
diff --git a/examples/qos_sched/init.c b/examples/qos_sched/init.c
index d8abae635a..75629e36ea 100644
--- a/examples/qos_sched/init.c
+++ b/examples/qos_sched/init.c
@@ -206,8 +206,7 @@ struct rte_sched_subport_params subport_params[MAX_SCHED_SUBPORTS] = {
.n_pipes_per_subport_enabled = 4096,
.qsize = {64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},
.pipe_profiles = pipe_profiles,
- .n_pipe_profiles = sizeof(pipe_profiles) /
- sizeof(struct rte_sched_pipe_params),
+ .n_pipe_profiles = RTE_DIM(pipe_profiles),
.n_max_pipe_profiles = MAX_SCHED_PIPE_PROFILES,
.cman_params = NULL,
},
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 5/5] drivers/net: use RTE_DIM
2024-04-16 15:19 [PATCH 0/5] use RTE_DIM where possible Stephen Hemminger
` (3 preceding siblings ...)
2024-04-16 15:19 ` [PATCH 4/5] examples _use RTE_DIM Stephen Hemminger
@ 2024-04-16 15:19 ` Stephen Hemminger
2024-04-16 16:29 ` Ferruh Yigit
4 siblings, 1 reply; 13+ messages in thread
From: Stephen Hemminger @ 2024-04-16 15:19 UTC (permalink / raw)
To: dev
Cc: Stephen Hemminger, Shepard Siegel, Ed Czeck, John Miller,
Ajit Khaparde, Somnath Kotur, Jingjing Wu, Rosen Xu, Jiawen Wu,
Harman Kalra, Jian Wang
Use RTE_DIM instead of computing directly with sizeof.
Patch automatically generated via cocci/rte_dim.cocci.
Code in base/ subdirectory manually excluded.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/ark/ark_pktchkr.c | 2 +-
drivers/net/ark/ark_pktgen.c | 2 +-
drivers/net/bnxt/bnxt_hwrm.c | 12 ++++++------
drivers/net/e1000/em_rxtx.c | 3 +--
drivers/net/iavf/iavf_ipsec_crypto.c | 3 +--
drivers/net/igc/igc_ethdev.c | 3 +--
drivers/net/ipn3ke/ipn3ke_tm.c | 3 +--
drivers/net/ngbe/ngbe_ethdev.c | 6 ++----
drivers/net/octeontx/octeontx_stats.h | 3 +--
drivers/net/txgbe/txgbe_ethdev.c | 9 +++------
drivers/net/txgbe/txgbe_ethdev_vf.c | 3 +--
11 files changed, 19 insertions(+), 30 deletions(-)
diff --git a/drivers/net/ark/ark_pktchkr.c b/drivers/net/ark/ark_pktchkr.c
index e1f336c73c..63c298fca8 100644
--- a/drivers/net/ark/ark_pktchkr.c
+++ b/drivers/net/ark/ark_pktchkr.c
@@ -320,7 +320,7 @@ options(const char *id)
{
unsigned int i;
- for (i = 0; i < sizeof(toptions) / sizeof(struct OPTIONS); i++) {
+ for (i = 0; i < RTE_DIM(toptions); i++) {
if (strcmp(id, toptions[i].opt) == 0)
return &toptions[i];
}
diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c
index 69ff7072b2..98e692c3ad 100644
--- a/drivers/net/ark/ark_pktgen.c
+++ b/drivers/net/ark/ark_pktgen.c
@@ -297,7 +297,7 @@ options(const char *id)
{
unsigned int i;
- for (i = 0; i < sizeof(toptions) / sizeof(struct OPTIONS); i++) {
+ for (i = 0; i < RTE_DIM(toptions); i++) {
if (strcmp(id, toptions[i].opt) == 0)
return &toptions[i];
}
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 6ea7089a3f..68d7382806 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -72,13 +72,13 @@ const char *media_type[] = { "Unknown", "Twisted Pair",
"Direct Attached Copper", "Fiber"
};
-#define MAX_MEDIA_TYPE (sizeof(media_type) / sizeof(const char *))
+#define MAX_MEDIA_TYPE RTE_DIM(media_type)
const char *link_status_str[] = { "Down. No link or cable detected.",
"Down. No link, but a cable has been detected.", "Up.",
};
-#define MAX_LINK_STR (sizeof(link_status_str) / sizeof(const char *))
+#define MAX_LINK_STR RTE_DIM(link_status_str)
const char *fec_mode[] = {
"No active FEC",
@@ -90,13 +90,13 @@ const char *fec_mode[] = {
"FEC RS(272,257)"
};
-#define MAX_FEC_MODE (sizeof(fec_mode) / sizeof(const char *))
+#define MAX_FEC_MODE RTE_DIM(fec_mode)
const char *signal_mode[] = {
"NRZ", "PAM4", "PAM4_112"
};
-#define MAX_SIG_MODE (sizeof(signal_mode) / sizeof(const char *))
+#define MAX_SIG_MODE RTE_DIM(signal_mode)
/* multi-purpose multi-key table container.
* Add a unique entry for a new PHY attribs as per HW CAS.
@@ -226,7 +226,7 @@ struct link_speeds2_tbl {
},
};
-#define BNXT_SPEEDS2_TBL_SZ (sizeof(link_speeds2_tbl) / sizeof(*link_speeds2_tbl))
+#define BNXT_SPEEDS2_TBL_SZ RTE_DIM(link_speeds2_tbl)
/* In hwrm_phy_qcfg reports trained up speeds in link_speed(offset:0x8[31:16]) */
struct link_speeds_tbl {
@@ -269,7 +269,7 @@ struct link_speeds_tbl {
},
};
-#define BNXT_SPEEDS_TBL_SZ (sizeof(link_speeds_tbl) / sizeof(*link_speeds_tbl))
+#define BNXT_SPEEDS_TBL_SZ RTE_DIM(link_speeds_tbl)
static const char *bnxt_get_xcvr_type(uint32_t xcvr_identifier_type_tx_lpi_timer)
{
diff --git a/drivers/net/e1000/em_rxtx.c b/drivers/net/e1000/em_rxtx.c
index df5fbb7823..59d7793787 100644
--- a/drivers/net/e1000/em_rxtx.c
+++ b/drivers/net/e1000/em_rxtx.c
@@ -1666,8 +1666,7 @@ em_rctl_bsize(__rte_unused enum e1000_mac_type hwtyp, uint32_t *bufsz)
* ***************************************************************
*/
- for (i = 0; i != sizeof(bufsz_to_rctl) / sizeof(bufsz_to_rctl[0]);
- i++) {
+ for (i = 0; i != RTE_DIM(bufsz_to_rctl); i++) {
if (rctl_bsize >= bufsz_to_rctl[i].bufsz) {
*bufsz = bufsz_to_rctl[i].bufsz;
return bufsz_to_rctl[i].rctl;
diff --git a/drivers/net/iavf/iavf_ipsec_crypto.c b/drivers/net/iavf/iavf_ipsec_crypto.c
index 6fd45ff45f..d3ce666ef0 100644
--- a/drivers/net/iavf/iavf_ipsec_crypto.c
+++ b/drivers/net/iavf/iavf_ipsec_crypto.c
@@ -1483,8 +1483,7 @@ iavf_ipsec_crypto_capabilities_get(void *device)
* crypto capabilities, except for last element of the array which is
* the null termination
*/
- for (i = 0; i < ((sizeof(iavf_security_capabilities) /
- sizeof(iavf_security_capabilities[0])) - 1); i++) {
+ for (i = 0; i < (RTE_DIM(iavf_security_capabilities) - 1); i++) {
iavf_security_capabilities[i].crypto_capabilities =
iavf_sctx->crypto_capabilities;
}
diff --git a/drivers/net/igc/igc_ethdev.c b/drivers/net/igc/igc_ethdev.c
index 87d7f7caa0..28682c42ae 100644
--- a/drivers/net/igc/igc_ethdev.c
+++ b/drivers/net/igc/igc_ethdev.c
@@ -188,8 +188,7 @@ static const struct rte_igc_xstats_name_off rte_igc_stats_strings[] = {
offsetof(struct igc_hw_stats, icrxdmtc)},
};
-#define IGC_NB_XSTATS (sizeof(rte_igc_stats_strings) / \
- sizeof(rte_igc_stats_strings[0]))
+#define IGC_NB_XSTATS RTE_DIM(rte_igc_stats_strings)
static int eth_igc_configure(struct rte_eth_dev *dev);
static int eth_igc_link_update(struct rte_eth_dev *dev, int wait_to_complete);
diff --git a/drivers/net/ipn3ke/ipn3ke_tm.c b/drivers/net/ipn3ke/ipn3ke_tm.c
index 0260227900..54687ce637 100644
--- a/drivers/net/ipn3ke/ipn3ke_tm.c
+++ b/drivers/net/ipn3ke/ipn3ke_tm.c
@@ -67,8 +67,7 @@ struct ipn3ke_tm_shaper_params_range_type ipn3ke_tm_shaper_params_rang[] = {
{512, 1023, 15, 32768, 67108864, 134086656},
};
-#define IPN3KE_TM_SHAPER_RANGE_NUM (sizeof(ipn3ke_tm_shaper_params_rang) / \
- sizeof(struct ipn3ke_tm_shaper_params_range_type))
+#define IPN3KE_TM_SHAPER_RANGE_NUM RTE_DIM(ipn3ke_tm_shaper_params_rang)
#define IPN3KE_TM_SHAPER_COMMITTED_RATE_MAX \
(ipn3ke_tm_shaper_params_rang[IPN3KE_TM_SHAPER_RANGE_NUM - 1].high)
diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index 4cd07a0030..f10b9647fa 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -238,8 +238,7 @@ static const struct rte_ngbe_xstats_name_off rte_ngbe_stats_strings[] = {
HW_XSTAT_NAME(rx_xoff_packets, "rx_flow_control_xoff_packets"),
};
-#define NGBE_NB_HW_STATS (sizeof(rte_ngbe_stats_strings) / \
- sizeof(rte_ngbe_stats_strings[0]))
+#define NGBE_NB_HW_STATS RTE_DIM(rte_ngbe_stats_strings)
/* Per-queue statistics */
#define QP_XSTAT(m) {#m, offsetof(struct ngbe_hw_stats, qp[0].m)}
@@ -251,8 +250,7 @@ static const struct rte_ngbe_xstats_name_off rte_ngbe_qp_strings[] = {
QP_XSTAT(rx_qp_mc_packets),
};
-#define NGBE_NB_QP_STATS (sizeof(rte_ngbe_qp_strings) / \
- sizeof(rte_ngbe_qp_strings[0]))
+#define NGBE_NB_QP_STATS RTE_DIM(rte_ngbe_qp_strings)
static inline int32_t
ngbe_pf_reset_hw(struct ngbe_hw *hw)
diff --git a/drivers/net/octeontx/octeontx_stats.h b/drivers/net/octeontx/octeontx_stats.h
index 73ef5e93bb..746205bb85 100644
--- a/drivers/net/octeontx/octeontx_stats.h
+++ b/drivers/net/octeontx/octeontx_stats.h
@@ -36,6 +36,5 @@ struct octeontx_xstats octeontx_bgx_xstats[] = {
BGX_XSTAT(tx_pause_packets),
};
-#define NUM_BGX_XSTAT \
- (sizeof(octeontx_bgx_xstats) / sizeof(struct octeontx_xstats))
+#define NUM_BGX_XSTAT RTE_DIM(octeontx_bgx_xstats)
#endif /* __OCTEONTX_STATS_H__ */
diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index b75e8898e2..fbf261bd0b 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -269,8 +269,7 @@ static const struct rte_txgbe_xstats_name_off rte_txgbe_stats_strings[] = {
HW_XSTAT_NAME(rx_xoff_packets, "rx_flow_control_xoff_packets"),
};
-#define TXGBE_NB_HW_STATS (sizeof(rte_txgbe_stats_strings) / \
- sizeof(rte_txgbe_stats_strings[0]))
+#define TXGBE_NB_HW_STATS RTE_DIM(rte_txgbe_stats_strings)
/* Per-priority statistics */
#define UP_XSTAT(m) {#m, offsetof(struct txgbe_hw_stats, up[0].m)}
@@ -290,8 +289,7 @@ static const struct rte_txgbe_xstats_name_off rte_txgbe_up_strings[] = {
UP_XSTAT(tx_up_xon2off_packets),
};
-#define TXGBE_NB_UP_STATS (sizeof(rte_txgbe_up_strings) / \
- sizeof(rte_txgbe_up_strings[0]))
+#define TXGBE_NB_UP_STATS RTE_DIM(rte_txgbe_up_strings)
/* Per-queue statistics */
#define QP_XSTAT(m) {#m, offsetof(struct txgbe_hw_stats, qp[0].m)}
@@ -303,8 +301,7 @@ static const struct rte_txgbe_xstats_name_off rte_txgbe_qp_strings[] = {
QP_XSTAT(rx_qp_mc_packets),
};
-#define TXGBE_NB_QP_STATS (sizeof(rte_txgbe_qp_strings) / \
- sizeof(rte_txgbe_qp_strings[0]))
+#define TXGBE_NB_QP_STATS RTE_DIM(rte_txgbe_qp_strings)
static inline int
txgbe_is_sfp(struct txgbe_hw *hw)
diff --git a/drivers/net/txgbe/txgbe_ethdev_vf.c b/drivers/net/txgbe/txgbe_ethdev_vf.c
index f1341fbf7e..be96519b97 100644
--- a/drivers/net/txgbe/txgbe_ethdev_vf.c
+++ b/drivers/net/txgbe/txgbe_ethdev_vf.c
@@ -112,8 +112,7 @@ static const struct rte_txgbe_xstats_name_off rte_txgbevf_stats_strings[] = {
offsetof(struct txgbevf_hw_stats, qp[7].vfmprc)}
};
-#define TXGBEVF_NB_XSTATS (sizeof(rte_txgbevf_stats_strings) / \
- sizeof(rte_txgbevf_stats_strings[0]))
+#define TXGBEVF_NB_XSTATS RTE_DIM(rte_txgbevf_stats_strings)
/*
* Negotiate mailbox API version with the PF.
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 5/5] drivers/net: use RTE_DIM
2024-04-16 15:19 ` [PATCH 5/5] drivers/net: use RTE_DIM Stephen Hemminger
@ 2024-04-16 16:29 ` Ferruh Yigit
2024-04-16 17:32 ` Stephen Hemminger
0 siblings, 1 reply; 13+ messages in thread
From: Ferruh Yigit @ 2024-04-16 16:29 UTC (permalink / raw)
To: Stephen Hemminger, dev
Cc: Shepard Siegel, Ed Czeck, John Miller, Ajit Khaparde,
Somnath Kotur, Jingjing Wu, Rosen Xu, Jiawen Wu, Harman Kalra,
Jian Wang
On 4/16/2024 4:19 PM, Stephen Hemminger wrote:
> Use RTE_DIM instead of computing directly with sizeof.
> Patch automatically generated via cocci/rte_dim.cocci.
> Code in base/ subdirectory manually excluded.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>
Updated ones looks good to me, but I can see a few more, I don't know if
you excluded base file one intentionally,
searched as `git grep "sizeof.*\[0\]" drivers/net/`
-
drivers/net/bnxt/tf_core/cfa_tcam_mgr.h:28:#define ARRAY_SIZE(_array)
(sizeof(_array) / sizeof(_array[0]))
-
drivers/net/hinic/base/hinic_pmd_nicio.c:449: /
sizeof(hinic_hw_rx_buf_size[0]);
-
drivers/net/ice/ice_ethdev.c:330:#define ICE_NB_MBUF_XSTATS
(sizeof(ice_mbuf_strings) / sizeof(ice_mbuf_strings[0]))
-
drivers/net/i40e/i40e_ethdev.c:554:#define I40E_NB_MBUF_XSTATS
(sizeof(i40e_mbuf_strings) / sizeof(i40e_mbuf_strings[0]))
-
drivers/net/i40e/base/i40e_adminq.h:126: if (!((u32)aq_rc <
(sizeof(aq_to_posix) / sizeof((aq_to_posix)[0]))))
-
drivers/net/ipn3ke/ipn3ke_representor.c:506: /
sizeof(ipn3ke_rpst_hw_port_strings[0]))
drivers/net/ipn3ke/ipn3ke_representor.c:517: /
sizeof(ipn3ke_rpst_rxq_prio_strings[0]))
drivers/net/ipn3ke/ipn3ke_representor.c:530: /
sizeof(ipn3ke_rpst_txq_prio_strings[0]))
-
drivers/net/ixgbe/base/ixgbe_x550.c:443: for (i = 0; i <
sizeof(ixgbe_fw_map) / sizeof(ixgbe_fw_map[0]); ++i) {
drivers/net/ixgbe/base/ixgbe_x550.c:700: for (i = 0; i <
sizeof(ixgbe_fw_map) / sizeof(ixgbe_fw_map[0]); ++i) {
-
drivers/net/ixgbe/base/ixgbe_x550.c:3338: bufsz = sizeof(buf) /
sizeof(buf[0]);
-
drivers/net/mlx5/hws/mlx5dr_internal.h:52:#define ARRAY_SIZE(x)
(sizeof(x) / sizeof((x)[0]))
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 5/5] drivers/net: use RTE_DIM
2024-04-16 16:29 ` Ferruh Yigit
@ 2024-04-16 17:32 ` Stephen Hemminger
2024-04-17 8:00 ` Ferruh Yigit
0 siblings, 1 reply; 13+ messages in thread
From: Stephen Hemminger @ 2024-04-16 17:32 UTC (permalink / raw)
To: Ferruh Yigit
Cc: dev, Shepard Siegel, Ed Czeck, John Miller, Ajit Khaparde,
Somnath Kotur, Jingjing Wu, Rosen Xu, Jiawen Wu, Harman Kalra,
Jian Wang
On Tue, 16 Apr 2024 17:29:25 +0100
Ferruh Yigit <ferruh.yigit@amd.com> wrote:
> On 4/16/2024 4:19 PM, Stephen Hemminger wrote:
> > Use RTE_DIM instead of computing directly with sizeof.
> > Patch automatically generated via cocci/rte_dim.cocci.
> > Code in base/ subdirectory manually excluded.
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> >
>
> Updated ones looks good to me, but I can see a few more, I don't know if
> you excluded base file one intentionally,
> searched as `git grep "sizeof.*\[0\]" drivers/net/`
>
>
> -
> drivers/net/bnxt/tf_core/cfa_tcam_mgr.h:28:#define ARRAY_SIZE(_array)
> (sizeof(_array) / sizeof(_array[0]))
>
> -
For the drivers that choose to define and use ARRAY_SIZE() that is fine.
Since base/ directories often come from other upstream repos, I ignored those.
Something about the Intel drivers was causing warnings and the script would
not automatically change those.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 5/5] drivers/net: use RTE_DIM
2024-04-16 17:32 ` Stephen Hemminger
@ 2024-04-17 8:00 ` Ferruh Yigit
0 siblings, 0 replies; 13+ messages in thread
From: Ferruh Yigit @ 2024-04-17 8:00 UTC (permalink / raw)
To: Stephen Hemminger
Cc: dev, Shepard Siegel, Ed Czeck, John Miller, Ajit Khaparde,
Somnath Kotur, Jingjing Wu, Rosen Xu, Jiawen Wu, Harman Kalra,
Jian Wang
On 4/16/2024 6:32 PM, Stephen Hemminger wrote:
> On Tue, 16 Apr 2024 17:29:25 +0100
> Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>
>> On 4/16/2024 4:19 PM, Stephen Hemminger wrote:
>>> Use RTE_DIM instead of computing directly with sizeof.
>>> Patch automatically generated via cocci/rte_dim.cocci.
>>> Code in base/ subdirectory manually excluded.
>>>
>>> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>>>
>>
>> Updated ones looks good to me, but I can see a few more, I don't know if
>> you excluded base file one intentionally,
>> searched as `git grep "sizeof.*\[0\]" drivers/net/`
>>
>>
>> -
>> drivers/net/bnxt/tf_core/cfa_tcam_mgr.h:28:#define ARRAY_SIZE(_array)
>> (sizeof(_array) / sizeof(_array[0]))
>>
>> -
>
> For the drivers that choose to define and use ARRAY_SIZE() that is fine.
>
ack
Although it can be updated as following, I don't think it differs
`#define ARRAY_SIZE(_array) RTE_DIM(_array)`
> Since base/ directories often come from other upstream repos, I ignored those.
>
ack
> Something about the Intel drivers was causing warnings and the script would
> not automatically change those.
>
ICE_NB_MBUF_XSTATS, I40E_NB_MBUF_XSTATS & ipn3ke_representor.c ones
seems can be updated, manually maybe?
^ permalink raw reply [flat|nested] 13+ messages in thread