app/flow-perf: simplify objects initialization
authorWisam Jaddo <wisamm@nvidia.com>
Thu, 26 Nov 2020 11:15:43 +0000 (13:15 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 7 Jan 2021 14:52:29 +0000 (15:52 +0100)
Since items are static then the default values will be zero,
thus the memset to zero value is just a redundant code.

Also remove the all not needed variables, that can be replaced
with direct set to the structure itself.

Fixes: bf3688f1e816 ("app/flow-perf: add insertion rate calculation")
Cc: stable@dpdk.org
Signed-off-by: Wisam Jaddo <wisamm@nvidia.com>
Reviewed-by: Alexander Kozyrev <akozyrev@nvidia.com>
Reviewed-by: Suanming Mou <suanmingm@nvidia.com>
app/test-flow-perf/actions_gen.c
app/test-flow-perf/items_gen.c

index 1364407..c3545ba 100644 (file)
@@ -143,12 +143,10 @@ add_set_meta(struct rte_flow_action *actions,
        uint8_t actions_counter,
        __rte_unused struct additional_para para)
 {
-       static struct rte_flow_action_set_meta meta_action;
-
-       do {
-               meta_action.data = RTE_BE32(META_DATA);
-               meta_action.mask = RTE_BE32(0xffffffff);
-       } while (0);
+       static struct rte_flow_action_set_meta meta_action = {
+               .data = RTE_BE32(META_DATA),
+               .mask = RTE_BE32(0xffffffff),
+       };
 
        actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_SET_META;
        actions[actions_counter].conf = &meta_action;
@@ -159,13 +157,11 @@ add_set_tag(struct rte_flow_action *actions,
        uint8_t actions_counter,
        __rte_unused struct additional_para para)
 {
-       static struct rte_flow_action_set_tag tag_action;
-
-       do {
-               tag_action.data = RTE_BE32(META_DATA);
-               tag_action.mask = RTE_BE32(0xffffffff);
-               tag_action.index = TAG_INDEX;
-       } while (0);
+       static struct rte_flow_action_set_tag tag_action = {
+               .data = RTE_BE32(META_DATA),
+               .mask = RTE_BE32(0xffffffff),
+               .index = TAG_INDEX,
+       };
 
        actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_SET_TAG;
        actions[actions_counter].conf = &tag_action;
@@ -176,11 +172,9 @@ add_port_id(struct rte_flow_action *actions,
        uint8_t actions_counter,
        __rte_unused struct additional_para para)
 {
-       static struct rte_flow_action_port_id port_id;
-
-       do {
-               port_id.id = PORT_ID_DST;
-       } while (0);
+       static struct rte_flow_action_port_id port_id = {
+               .id = PORT_ID_DST,
+       };
 
        actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_PORT_ID;
        actions[actions_counter].conf = &port_id;
index 0950023..ccebc08 100644 (file)
@@ -26,9 +26,6 @@ add_ether(struct rte_flow_item *items,
        static struct rte_flow_item_eth eth_spec;
        static struct rte_flow_item_eth eth_mask;
 
-       memset(&eth_spec, 0, sizeof(struct rte_flow_item_eth));
-       memset(&eth_mask, 0, sizeof(struct rte_flow_item_eth));
-
        items[items_counter].type = RTE_FLOW_ITEM_TYPE_ETH;
        items[items_counter].spec = &eth_spec;
        items[items_counter].mask = &eth_mask;
@@ -39,16 +36,12 @@ add_vlan(struct rte_flow_item *items,
        uint8_t items_counter,
        __rte_unused struct additional_para para)
 {
-       static struct rte_flow_item_vlan vlan_spec;
-       static struct rte_flow_item_vlan vlan_mask;
-
-       uint16_t vlan_value = VLAN_VALUE;
-
-       memset(&vlan_spec, 0, sizeof(struct rte_flow_item_vlan));
-       memset(&vlan_mask, 0, sizeof(struct rte_flow_item_vlan));
-
-       vlan_spec.tci = RTE_BE16(vlan_value);
-       vlan_mask.tci = RTE_BE16(0xffff);
+       static struct rte_flow_item_vlan vlan_spec = {
+               .tci = RTE_BE16(VLAN_VALUE),
+       };
+       static struct rte_flow_item_vlan vlan_mask = {
+               .tci = RTE_BE16(0xffff),
+       };
 
        items[items_counter].type = RTE_FLOW_ITEM_TYPE_VLAN;
        items[items_counter].spec = &vlan_spec;
@@ -63,9 +56,6 @@ add_ipv4(struct rte_flow_item *items,
        static struct rte_flow_item_ipv4 ipv4_masks[RTE_MAX_LCORE] __rte_cache_aligned;
        uint8_t ti = para.core_idx;
 
-       memset(&ipv4_specs[ti], 0, sizeof(struct rte_flow_item_ipv4));
-       memset(&ipv4_masks[ti], 0, sizeof(struct rte_flow_item_ipv4));
-
        ipv4_specs[ti].hdr.src_addr = RTE_BE32(para.src_ip);
        ipv4_masks[ti].hdr.src_addr = RTE_BE32(0xffffffff);
 
@@ -83,9 +73,6 @@ add_ipv6(struct rte_flow_item *items,
        static struct rte_flow_item_ipv6 ipv6_masks[RTE_MAX_LCORE] __rte_cache_aligned;
        uint8_t ti = para.core_idx;
 
-       memset(&ipv6_specs[ti], 0, sizeof(struct rte_flow_item_ipv6));
-       memset(&ipv6_masks[ti], 0, sizeof(struct rte_flow_item_ipv6));
-
        /** Set ipv6 src **/
        memset(&ipv6_specs[ti].hdr.src_addr, para.src_ip,
                sizeof(ipv6_specs->hdr.src_addr) / 2);
@@ -107,9 +94,6 @@ add_tcp(struct rte_flow_item *items,
        static struct rte_flow_item_tcp tcp_spec;
        static struct rte_flow_item_tcp tcp_mask;
 
-       memset(&tcp_spec, 0, sizeof(struct rte_flow_item_tcp));
-       memset(&tcp_mask, 0, sizeof(struct rte_flow_item_tcp));
-
        items[items_counter].type = RTE_FLOW_ITEM_TYPE_TCP;
        items[items_counter].spec = &tcp_spec;
        items[items_counter].mask = &tcp_mask;
@@ -123,9 +107,6 @@ add_udp(struct rte_flow_item *items,
        static struct rte_flow_item_udp udp_spec;
        static struct rte_flow_item_udp udp_mask;
 
-       memset(&udp_spec, 0, sizeof(struct rte_flow_item_udp));
-       memset(&udp_mask, 0, sizeof(struct rte_flow_item_udp));
-
        items[items_counter].type = RTE_FLOW_ITEM_TYPE_UDP;
        items[items_counter].spec = &udp_spec;
        items[items_counter].mask = &udp_mask;
@@ -144,9 +125,6 @@ add_vxlan(struct rte_flow_item *items,
 
        vni_value = VNI_VALUE;
 
-       memset(&vxlan_specs[ti], 0, sizeof(struct rte_flow_item_vxlan));
-       memset(&vxlan_masks[ti], 0, sizeof(struct rte_flow_item_vxlan));
-
        /* Set standard vxlan vni */
        for (i = 0; i < 3; i++) {
                vxlan_specs[ti].vni[2 - i] = vni_value >> (i * 8);
@@ -174,9 +152,6 @@ add_vxlan_gpe(struct rte_flow_item *items,
 
        vni_value = VNI_VALUE;
 
-       memset(&vxlan_gpe_specs[ti], 0, sizeof(struct rte_flow_item_vxlan_gpe));
-       memset(&vxlan_gpe_masks[ti], 0, sizeof(struct rte_flow_item_vxlan_gpe));
-
        /* Set vxlan-gpe vni */
        for (i = 0; i < 3; i++) {
                vxlan_gpe_specs[ti].vni[2 - i] = vni_value >> (i * 8);
@@ -196,18 +171,12 @@ add_gre(struct rte_flow_item *items,
        uint8_t items_counter,
        __rte_unused struct additional_para para)
 {
-       static struct rte_flow_item_gre gre_spec;
-       static struct rte_flow_item_gre gre_mask;
-
-       uint16_t proto;
-
-       proto = RTE_ETHER_TYPE_TEB;
-
-       memset(&gre_spec, 0, sizeof(struct rte_flow_item_gre));
-       memset(&gre_mask, 0, sizeof(struct rte_flow_item_gre));
-
-       gre_spec.protocol = RTE_BE16(proto);
-       gre_mask.protocol = RTE_BE16(0xffff);
+       static struct rte_flow_item_gre gre_spec = {
+               .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB),
+       };
+       static struct rte_flow_item_gre gre_mask = {
+               .protocol = RTE_BE16(0xffff),
+       };
 
        items[items_counter].type = RTE_FLOW_ITEM_TYPE_GRE;
        items[items_counter].spec = &gre_spec;
@@ -227,9 +196,6 @@ add_geneve(struct rte_flow_item *items,
 
        vni_value = VNI_VALUE;
 
-       memset(&geneve_specs[ti], 0, sizeof(struct rte_flow_item_geneve));
-       memset(&geneve_masks[ti], 0, sizeof(struct rte_flow_item_geneve));
-
        for (i = 0; i < 3; i++) {
                geneve_specs[ti].vni[2 - i] = vni_value >> (i * 8);
                geneve_masks[ti].vni[2 - i] = 0xff;
@@ -245,18 +211,12 @@ add_gtp(struct rte_flow_item *items,
        uint8_t items_counter,
        __rte_unused struct additional_para para)
 {
-       static struct rte_flow_item_gtp gtp_spec;
-       static struct rte_flow_item_gtp gtp_mask;
-
-       uint32_t teid_value;
-
-       teid_value = TEID_VALUE;
-
-       memset(&gtp_spec, 0, sizeof(struct rte_flow_item_gtp));
-       memset(&gtp_mask, 0, sizeof(struct rte_flow_item_gtp));
-
-       gtp_spec.teid = RTE_BE32(teid_value);
-       gtp_mask.teid = RTE_BE32(0xffffffff);
+       static struct rte_flow_item_gtp gtp_spec = {
+               .teid = RTE_BE32(TEID_VALUE),
+       };
+       static struct rte_flow_item_gtp gtp_mask = {
+               .teid = RTE_BE32(0xffffffff),
+       };
 
        items[items_counter].type = RTE_FLOW_ITEM_TYPE_GTP;
        items[items_counter].spec = &gtp_spec;
@@ -268,18 +228,12 @@ add_meta_data(struct rte_flow_item *items,
        uint8_t items_counter,
        __rte_unused struct additional_para para)
 {
-       static struct rte_flow_item_meta meta_spec;
-       static struct rte_flow_item_meta meta_mask;
-
-       uint32_t data;
-
-       data = META_DATA;
-
-       memset(&meta_spec, 0, sizeof(struct rte_flow_item_meta));
-       memset(&meta_mask, 0, sizeof(struct rte_flow_item_meta));
-
-       meta_spec.data = RTE_BE32(data);
-       meta_mask.data = RTE_BE32(0xffffffff);
+       static struct rte_flow_item_meta meta_spec = {
+               .data = RTE_BE32(META_DATA),
+       };
+       static struct rte_flow_item_meta meta_mask = {
+               .data = RTE_BE32(0xffffffff),
+       };
 
        items[items_counter].type = RTE_FLOW_ITEM_TYPE_META;
        items[items_counter].spec = &meta_spec;
@@ -292,21 +246,14 @@ add_meta_tag(struct rte_flow_item *items,
        uint8_t items_counter,
        __rte_unused struct additional_para para)
 {
-       static struct rte_flow_item_tag tag_spec;
-       static struct rte_flow_item_tag tag_mask;
-       uint32_t data;
-       uint8_t index;
-
-       data = META_DATA;
-       index = TAG_INDEX;
-
-       memset(&tag_spec, 0, sizeof(struct rte_flow_item_tag));
-       memset(&tag_mask, 0, sizeof(struct rte_flow_item_tag));
-
-       tag_spec.data = RTE_BE32(data);
-       tag_mask.data = RTE_BE32(0xffffffff);
-       tag_spec.index = index;
-       tag_mask.index = 0xff;
+       static struct rte_flow_item_tag tag_spec = {
+               .data = RTE_BE32(META_DATA),
+               .index = TAG_INDEX,
+       };
+       static struct rte_flow_item_tag tag_mask = {
+               .data = RTE_BE32(0xffffffff),
+               .index = 0xff,
+       };
 
        items[items_counter].type = RTE_FLOW_ITEM_TYPE_TAG;
        items[items_counter].spec = &tag_spec;
@@ -321,9 +268,6 @@ add_icmpv4(struct rte_flow_item *items,
        static struct rte_flow_item_icmp icmpv4_spec;
        static struct rte_flow_item_icmp icmpv4_mask;
 
-       memset(&icmpv4_spec, 0, sizeof(struct rte_flow_item_icmp));
-       memset(&icmpv4_mask, 0, sizeof(struct rte_flow_item_icmp));
-
        items[items_counter].type = RTE_FLOW_ITEM_TYPE_ICMP;
        items[items_counter].spec = &icmpv4_spec;
        items[items_counter].mask = &icmpv4_mask;
@@ -337,9 +281,6 @@ add_icmpv6(struct rte_flow_item *items,
        static struct rte_flow_item_icmp6 icmpv6_spec;
        static struct rte_flow_item_icmp6 icmpv6_mask;
 
-       memset(&icmpv6_spec, 0, sizeof(struct rte_flow_item_icmp6));
-       memset(&icmpv6_mask, 0, sizeof(struct rte_flow_item_icmp6));
-
        items[items_counter].type = RTE_FLOW_ITEM_TYPE_ICMP6;
        items[items_counter].spec = &icmpv6_spec;
        items[items_counter].mask = &icmpv6_mask;