examples: use common macro RTE_DIM

Use RTE_DIM macro to calculate array size.

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
Acked-by: David Marchand <david.marchand@redhat.com>
This commit is contained in:
Pavan Nikhilesh 2020-01-24 10:25:43 +05:30 committed by David Marchand
parent 71bdd8a178
commit 7efe28bd07
7 changed files with 12 additions and 33 deletions

View file

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

View file

@ -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) {

View file

@ -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,

View file

@ -204,11 +204,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;

View file

@ -66,11 +66,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
@ -480,7 +475,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 */
@ -520,7 +515,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 &

View file

@ -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];

View file

@ -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 */