ethdev: replace bit shifts with macros
PATCH 1/1 ethdev: replace bit shifts with macros
The macros RTE_BIT32 and RTE_BIT64 are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.
Only bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
--- lib/ethdev/rte_ethdev.c | 16 ++--- lib/ethdev/rte_ethdev.h | 127 ++++++++++++++++++++-------------------- lib/ethdev/rte_flow.c | 4 +- lib/ethdev/rte_flow.h | 6 +- lib/ethdev/rte_mtr.h | 16 ++--- lib/ethdev/rte_tm.h | 36 ++++++------ 6 files changed, 103 insertions(+), 102 deletions(-)
lib/ethdev/rte_ethdev.c +8 -8
@@ -1303,7 +1303,7 @@ eth_dev_validate_offloads(uint16_t port_id, uint64_t req_offloads,while (offloads_diff !=0 ) {/* Check if any offload is requested but not enabled. */ - offload =1ULL <<__builtin_ctzll (offloads_diff); + offload =RTE_BIT64 (__builtin_ctzll (offloads_diff));if (offload & req_offloads) { RTE_ETHDEV_LOG(ERR, "Port %u failed to enable %s offload %s\n",
@@ -1669,7 +1669,7 @@ eth_dev_mac_restore(struct rte_eth_dev *dev, pool_mask = dev->data->mac_pool_sel[i]; do { - if (pool_mask & 1ULL) + if (pool_mask & UINT64_C(1)) (*dev->dev_ops->mac_addr_add)(dev, addr, i, pool); pool_mask >>= 1;
@@ -1945,7 +1945,7 @@ rte_eth_rx_queue_check_split(const struct rte_eth_rxseg_split *rx_seg,* for each segment specified in extended configuration. */ mp_first = rx_seg[0 ].mp; - offset_mask = (1u << seg_capa->offset_align_log2) -1 ; + offset_mask =RTE_BIT32 (seg_capa->offset_align_log2) -1 ;for (seg_idx =0 ; seg_idx < n_seg; seg_idx++) {struct rte_mempool *mpl = rx_seg[seg_idx].mp;uint32_t length = rx_seg[seg_idx].length;
@@ -3686,9 +3686,9 @@ rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on) vbit = vlan_id %64 ;if (on) - vfc->ids[vidx] |=UINT64_C (1 ) << vbit; + vfc->ids[vidx] |=RTE_BIT64 (vbit);else - vfc->ids[vidx] &= ~(UINT64_C (1 ) << vbit); + vfc->ids[vidx] &= ~RTE_BIT64 (vbit); }return eth_err (port_id, ret);
@@ -3960,7 +3960,7 @@ eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,for (i =0 ; i < reta_size; i++) { idx = i /RTE_RETA_GROUP_SIZE ; shift = i %RTE_RETA_GROUP_SIZE ; -if ((reta_conf[idx].mask & (1ULL << shift)) && +if ((reta_conf[idx].mask &RTE_BIT64 (shift)) && (reta_conf[idx].reta[shift] >= max_rxq)) { RTE_ETHDEV_LOG(ERR, "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u\n",
@@ -4299,7 +4299,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr, pool_mask = dev->data->mac_pool_sel[index];/* Check if both MAC address and pool is already there, and do nothing */ -if (pool_mask & (1ULL << pool)) +if (pool_mask &RTE_BIT64 (pool))return 0 ; }
@@ -4311,7 +4311,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,rte_ether_addr_copy (addr, &dev->data->mac_addrs[index]);/* Update pool bitmap in NIC data structure */ - dev->data->mac_pool_sel[index] |= (1ULL << pool); + dev->data->mac_pool_sel[index] |=RTE_BIT64 (pool); }return eth_err (port_id, ret);
lib/ethdev/rte_ethdev.h +64 -63
171 lines not on this page · raw message
lib/ethdev/rte_flow.c +2 -2
@@ -213,12 +213,12 @@ rte_flow_dynf_metadata_register(void)if (flag <0 ) goto error; rte_flow_dynf_metadata_offs = offset; - rte_flow_dynf_metadata_mask = (1ULL << flag); + rte_flow_dynf_metadata_mask =RTE_BIT64 (flag);return 0 ; error: rte_flow_dynf_metadata_offs =-1 ; - rte_flow_dynf_metadata_mask =0ULL ; + rte_flow_dynf_metadata_mask =UINT64_C (0 );return -rte_errno; }
lib/ethdev/rte_flow.h +3 -3
@@ -4131,17 +4131,17 @@ struct rte_flow_tunnel {/** * Indicate that the packet has a tunnel. */ -#define RTE_FLOW_RESTORE_INFO_TUNNEL (1ULL << 0) +#define RTE_FLOW_RESTORE_INFO_TUNNEL RTE_BIT64(0)/** * Indicate that the packet has a non decapsulated tunnel header. */ -#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED (1ULL << 1) +#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED RTE_BIT64(1)/** * Indicate that the packet has a group_id. */ -#define RTE_FLOW_RESTORE_INFO_GROUP_ID (1ULL << 2) +#define RTE_FLOW_RESTORE_INFO_GROUP_ID RTE_BIT64(2)/** * Restore information structure to communicate the current packet processing
lib/ethdev/rte_mtr.h +8 -8
@@ -60,28 +60,28 @@ extern "C" {*/ enum rte_mtr_stats_type {/** Number of packets passed as green by the policer. */ -RTE_MTR_STATS_N_PKTS_GREEN =1 <<0 , +RTE_MTR_STATS_N_PKTS_GREEN =RTE_BIT64 (0 ),/** Number of packets passed as yellow by the policer. */ -RTE_MTR_STATS_N_PKTS_YELLOW =1 <<1 , +RTE_MTR_STATS_N_PKTS_YELLOW =RTE_BIT64 (1 ),/** Number of packets passed as red by the policer. */ -RTE_MTR_STATS_N_PKTS_RED =1 <<2 , +RTE_MTR_STATS_N_PKTS_RED =RTE_BIT64 (2 ),/** Number of packets dropped by the policer. */ -RTE_MTR_STATS_N_PKTS_DROPPED =1 <<3 , +RTE_MTR_STATS_N_PKTS_DROPPED =RTE_BIT64 (3 ),/** Number of bytes passed as green by the policer. */ -RTE_MTR_STATS_N_BYTES_GREEN =1 <<4 , +RTE_MTR_STATS_N_BYTES_GREEN =RTE_BIT64 (4 ),/** Number of bytes passed as yellow by the policer. */ -RTE_MTR_STATS_N_BYTES_YELLOW =1 <<5 , +RTE_MTR_STATS_N_BYTES_YELLOW =RTE_BIT64 (5 ),/** Number of bytes passed as red by the policer. */ -RTE_MTR_STATS_N_BYTES_RED =1 <<6 , +RTE_MTR_STATS_N_BYTES_RED =RTE_BIT64 (6 ),/** Number of bytes dropped by the policer. */ -RTE_MTR_STATS_N_BYTES_DROPPED =1 <<7 , +RTE_MTR_STATS_N_BYTES_DROPPED =RTE_BIT64 (7 ), };/**
lib/ethdev/rte_tm.h +18 -18
@@ -93,38 +93,38 @@ extern "C" {*/ enum rte_tm_stats_type {/** Number of packets scheduled from current node. */ -RTE_TM_STATS_N_PKTS =1 <<0 , +RTE_TM_STATS_N_PKTS =RTE_BIT64 (0 ),/** Number of bytes scheduled from current node. */ -RTE_TM_STATS_N_BYTES =1 <<1 , +RTE_TM_STATS_N_BYTES =RTE_BIT64 (1 ),/** Number of green packets dropped by current leaf node. */ -RTE_TM_STATS_N_PKTS_GREEN_DROPPED =1 <<2 , +RTE_TM_STATS_N_PKTS_GREEN_DROPPED =RTE_BIT64 (2 ),/** Number of yellow packets dropped by current leaf node. */ -RTE_TM_STATS_N_PKTS_YELLOW_DROPPED =1 <<3 , +RTE_TM_STATS_N_PKTS_YELLOW_DROPPED =RTE_BIT64 (3 ),/** Number of red packets dropped by current leaf node. */ -RTE_TM_STATS_N_PKTS_RED_DROPPED =1 <<4 , +RTE_TM_STATS_N_PKTS_RED_DROPPED =RTE_BIT64 (4 ),/** Number of green bytes dropped by current leaf node. */ -RTE_TM_STATS_N_BYTES_GREEN_DROPPED =1 <<5 , +RTE_TM_STATS_N_BYTES_GREEN_DROPPED =RTE_BIT64 (5 ),/** Number of yellow bytes dropped by current leaf node. */ -RTE_TM_STATS_N_BYTES_YELLOW_DROPPED =1 <<6 , +RTE_TM_STATS_N_BYTES_YELLOW_DROPPED =RTE_BIT64 (6 ),/** Number of red bytes dropped by current leaf node. */ -RTE_TM_STATS_N_BYTES_RED_DROPPED =1 <<7 , +RTE_TM_STATS_N_BYTES_RED_DROPPED =RTE_BIT64 (7 ),/** Number of packets currently waiting in the packet queue of current * leaf node. */ -RTE_TM_STATS_N_PKTS_QUEUED =1 <<8 , +RTE_TM_STATS_N_PKTS_QUEUED =RTE_BIT64 (8 ),/** Number of bytes currently waiting in the packet queue of current * leaf node. */ -RTE_TM_STATS_N_BYTES_QUEUED =1 <<9 , +RTE_TM_STATS_N_BYTES_QUEUED =RTE_BIT64 (9 ), };/**
@@ -169,31 +169,31 @@ enum rte_tm_dynamic_update_type {* hierarchy level as the former parent node. Consequently, the node * whose parent is changed preserves its hierarchy level. */ -RTE_TM_UPDATE_NODE_PARENT_KEEP_LEVEL =1 <<0 , +RTE_TM_UPDATE_NODE_PARENT_KEEP_LEVEL =RTE_BIT64 (0 ),/** Dynamic parent node update. The new parent node is located on * different hierarchy level than the former parent node. Consequently, * the node whose parent is changed also changes its hierarchy level. */ -RTE_TM_UPDATE_NODE_PARENT_CHANGE_LEVEL =1 <<1 , +RTE_TM_UPDATE_NODE_PARENT_CHANGE_LEVEL =RTE_BIT64 (1 ),/** Dynamic node add/delete. */ -RTE_TM_UPDATE_NODE_ADD_DELETE =1 <<2 , +RTE_TM_UPDATE_NODE_ADD_DELETE =RTE_BIT64 (2 ),/** Suspend/resume nodes. */ -RTE_TM_UPDATE_NODE_SUSPEND_RESUME =1 <<3 , +RTE_TM_UPDATE_NODE_SUSPEND_RESUME =RTE_BIT64 (3 ),/** Dynamic switch between byte-based and packet-based WFQ weights. */ -RTE_TM_UPDATE_NODE_WFQ_WEIGHT_MODE =1 <<4 , +RTE_TM_UPDATE_NODE_WFQ_WEIGHT_MODE =RTE_BIT64 (4 ),/** Dynamic update on number of SP priorities. */ -RTE_TM_UPDATE_NODE_N_SP_PRIORITIES =1 <<5 , +RTE_TM_UPDATE_NODE_N_SP_PRIORITIES =RTE_BIT64 (5 ),/** Dynamic update of congestion management mode for leaf nodes. */ -RTE_TM_UPDATE_NODE_CMAN =1 <<6 , +RTE_TM_UPDATE_NODE_CMAN =RTE_BIT64 (6 ),/** Dynamic update of the set of enabled stats counter types. */ - RTE_TM_UPDATE_NODE_STATS = 1 << 7, + RTE_TM_UPDATE_NODE_STATS = RTE_BIT64(7), };/**
Signature · 1 line
2.33.0
Quoted 6 lines · Thomas Monjalon
The macros
RTE_BIT32andRTE_BIT64are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.Only bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
Signed-off-by Thomas Monjalon <[email protected]>
Good cleanup, many thanks.
lib/ethdev/rte_mtr.h extern "C" { · line 63
Quoted 10 lines
lib/ethdev/rte_mtr.h +1
-1@@ -60,28 +60,28 @@ extern "C" {*/ enum rte_mtr_stats_type {/** Number of packets passed as green by the policer. */ -RTE_MTR_STATS_N_PKTS_GREEN =1 <<0 , +RTE_MTR_STATS_N_PKTS_GREEN =RTE_BIT64 (0 ),
I think it is a bad idea to initialize enum members to uint64_t value.
16/09/2021 08:52, Andrew Rybchenko:
Quoted 10 lines · Thomas Monjalon
Quoted 6 lines
The macros
RTE_BIT32andRTE_BIT64are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.Only bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
Signed-off-by Thomas Monjalon <[email protected]>Good cleanup, many thanks.
Quoted 13 lines
lib/ethdev/rte_mtr.h extern "C" { · line 63
Quoted 10 lines
lib/ethdev/rte_mtr.h +1
-1@@ -60,28 +60,28 @@ extern "C" {*/ enum rte_mtr_stats_type {/** Number of packets passed as green by the policer. */ -RTE_MTR_STATS_N_PKTS_GREEN =1 <<0 , +RTE_MTR_STATS_N_PKTS_GREEN =RTE_BIT64 (0 ),I think it is a bad idea to initialize enum members to
uint64_tvalue.
Yes probably.
The targets are 64-bit wide so there is an inconsistency in the API I think.
Quoted 25 lines · Thomas Monjalon
16/09/2021 08:52, Andrew Rybchenko:
Quoted 10 lines · Thomas Monjalon
Quoted 6 lines
The macros
RTE_BIT32andRTE_BIT64are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.Only bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
Signed-off-by Thomas Monjalon <[email protected]>Good cleanup, many thanks.
Quoted 13 lines
lib/ethdev/rte_mtr.h extern "C" { · line 63
Quoted 10 lines
lib/ethdev/rte_mtr.h +1
-1@@ -60,28 +60,28 @@ extern "C" {*/ enum rte_mtr_stats_type {/** Number of packets passed as green by the policer. */ -RTE_MTR_STATS_N_PKTS_GREEN =1 <<0 , +RTE_MTR_STATS_N_PKTS_GREEN =RTE_BIT64 (0 ),I think it is a bad idea to initialize enum members to
uint64_tvalue.
Quoted 3 lines
Yes probably.
The targets are 64-bit wide so there is an inconsistency in the API I think.
Yes, I agree. That's why I dislike usage of enums for definition of mask bits.
PATCH v2 1/1 ethdev: replace bit shifts with macros
In reply to Thomas MonjalonThe macros RTE_BIT32 and RTE_BIT64 are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.
Only bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
The API of rte_mtr and rte_tm is using enums for 64-bit variables. As they are enums, RTE_BIT32 is used.
The corresponding struct members should be converted to 32-bit.
---
v2: use RTE_BIT32 in enums
--- lib/ethdev/rte_ethdev.c | 16 ++--- lib/ethdev/rte_ethdev.h | 127 ++++++++++++++++++++-------------------- lib/ethdev/rte_flow.c | 4 +- lib/ethdev/rte_flow.h | 6 +- lib/ethdev/rte_mtr.h | 16 ++--- lib/ethdev/rte_tm.h | 36 ++++++------ 6 files changed, 103 insertions(+), 102 deletions(-)
lib/ethdev/rte_ethdev.c +8 -8
@@ -1303,7 +1303,7 @@ eth_dev_validate_offloads(uint16_t port_id, uint64_t req_offloads,while (offloads_diff !=0 ) {/* Check if any offload is requested but not enabled. */ - offload =1ULL <<__builtin_ctzll (offloads_diff); + offload =RTE_BIT64 (__builtin_ctzll (offloads_diff));if (offload & req_offloads) { RTE_ETHDEV_LOG(ERR, "Port %u failed to enable %s offload %s\n",
@@ -1669,7 +1669,7 @@ eth_dev_mac_restore(struct rte_eth_dev *dev, pool_mask = dev->data->mac_pool_sel[i]; do { - if (pool_mask & 1ULL) + if (pool_mask & UINT64_C(1)) (*dev->dev_ops->mac_addr_add)(dev, addr, i, pool); pool_mask >>= 1;
@@ -1945,7 +1945,7 @@ rte_eth_rx_queue_check_split(const struct rte_eth_rxseg_split *rx_seg,* for each segment specified in extended configuration. */ mp_first = rx_seg[0 ].mp; - offset_mask = (1u << seg_capa->offset_align_log2) -1 ; + offset_mask =RTE_BIT32 (seg_capa->offset_align_log2) -1 ;for (seg_idx =0 ; seg_idx < n_seg; seg_idx++) {struct rte_mempool *mpl = rx_seg[seg_idx].mp;uint32_t length = rx_seg[seg_idx].length;
@@ -3686,9 +3686,9 @@ rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on) vbit = vlan_id %64 ;if (on) - vfc->ids[vidx] |=UINT64_C (1 ) << vbit; + vfc->ids[vidx] |=RTE_BIT64 (vbit);else - vfc->ids[vidx] &= ~(UINT64_C (1 ) << vbit); + vfc->ids[vidx] &= ~RTE_BIT64 (vbit); }return eth_err (port_id, ret);
@@ -3960,7 +3960,7 @@ eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,for (i =0 ; i < reta_size; i++) { idx = i /RTE_RETA_GROUP_SIZE ; shift = i %RTE_RETA_GROUP_SIZE ; -if ((reta_conf[idx].mask & (1ULL << shift)) && +if ((reta_conf[idx].mask &RTE_BIT64 (shift)) && (reta_conf[idx].reta[shift] >= max_rxq)) { RTE_ETHDEV_LOG(ERR, "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u\n",
@@ -4299,7 +4299,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr, pool_mask = dev->data->mac_pool_sel[index];/* Check if both MAC address and pool is already there, and do nothing */ -if (pool_mask & (1ULL << pool)) +if (pool_mask &RTE_BIT64 (pool))return 0 ; }
@@ -4311,7 +4311,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,rte_ether_addr_copy (addr, &dev->data->mac_addrs[index]);/* Update pool bitmap in NIC data structure */ - dev->data->mac_pool_sel[index] |= (1ULL << pool); + dev->data->mac_pool_sel[index] |=RTE_BIT64 (pool); }return eth_err (port_id, ret);
lib/ethdev/rte_ethdev.h +64 -63
171 lines not on this page · raw message
lib/ethdev/rte_flow.c +2 -2
@@ -213,12 +213,12 @@ rte_flow_dynf_metadata_register(void)if (flag <0 ) goto error; rte_flow_dynf_metadata_offs = offset; - rte_flow_dynf_metadata_mask = (1ULL << flag); + rte_flow_dynf_metadata_mask =RTE_BIT64 (flag);return 0 ; error: rte_flow_dynf_metadata_offs =-1 ; - rte_flow_dynf_metadata_mask =0ULL ; + rte_flow_dynf_metadata_mask =UINT64_C (0 );return -rte_errno; }
lib/ethdev/rte_flow.h +3 -3
@@ -4131,17 +4131,17 @@ struct rte_flow_tunnel {/** * Indicate that the packet has a tunnel. */ -#define RTE_FLOW_RESTORE_INFO_TUNNEL (1ULL << 0) +#define RTE_FLOW_RESTORE_INFO_TUNNEL RTE_BIT64(0)/** * Indicate that the packet has a non decapsulated tunnel header. */ -#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED (1ULL << 1) +#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED RTE_BIT64(1)/** * Indicate that the packet has a group_id. */ -#define RTE_FLOW_RESTORE_INFO_GROUP_ID (1ULL << 2) +#define RTE_FLOW_RESTORE_INFO_GROUP_ID RTE_BIT64(2)/** * Restore information structure to communicate the current packet processing
lib/ethdev/rte_mtr.h +8 -8
@@ -60,28 +60,28 @@ extern "C" {*/ enum rte_mtr_stats_type {/** Number of packets passed as green by the policer. */ -RTE_MTR_STATS_N_PKTS_GREEN =1 <<0 , +RTE_MTR_STATS_N_PKTS_GREEN =RTE_BIT32 (0 ),/** Number of packets passed as yellow by the policer. */ -RTE_MTR_STATS_N_PKTS_YELLOW =1 <<1 , +RTE_MTR_STATS_N_PKTS_YELLOW =RTE_BIT32 (1 ),/** Number of packets passed as red by the policer. */ -RTE_MTR_STATS_N_PKTS_RED =1 <<2 , +RTE_MTR_STATS_N_PKTS_RED =RTE_BIT32 (2 ),/** Number of packets dropped by the policer. */ -RTE_MTR_STATS_N_PKTS_DROPPED =1 <<3 , +RTE_MTR_STATS_N_PKTS_DROPPED =RTE_BIT32 (3 ),/** Number of bytes passed as green by the policer. */ -RTE_MTR_STATS_N_BYTES_GREEN =1 <<4 , +RTE_MTR_STATS_N_BYTES_GREEN =RTE_BIT32 (4 ),/** Number of bytes passed as yellow by the policer. */ -RTE_MTR_STATS_N_BYTES_YELLOW =1 <<5 , +RTE_MTR_STATS_N_BYTES_YELLOW =RTE_BIT32 (5 ),/** Number of bytes passed as red by the policer. */ -RTE_MTR_STATS_N_BYTES_RED =1 <<6 , +RTE_MTR_STATS_N_BYTES_RED =RTE_BIT32 (6 ),/** Number of bytes dropped by the policer. */ -RTE_MTR_STATS_N_BYTES_DROPPED =1 <<7 , +RTE_MTR_STATS_N_BYTES_DROPPED =RTE_BIT32 (7 ), };/**
lib/ethdev/rte_tm.h +18 -18
@@ -93,38 +93,38 @@ extern "C" {*/ enum rte_tm_stats_type {/** Number of packets scheduled from current node. */ -RTE_TM_STATS_N_PKTS =1 <<0 , +RTE_TM_STATS_N_PKTS =RTE_BIT32 (0 ),/** Number of bytes scheduled from current node. */ -RTE_TM_STATS_N_BYTES =1 <<1 , +RTE_TM_STATS_N_BYTES =RTE_BIT32 (1 ),/** Number of green packets dropped by current leaf node. */ -RTE_TM_STATS_N_PKTS_GREEN_DROPPED =1 <<2 , +RTE_TM_STATS_N_PKTS_GREEN_DROPPED =RTE_BIT32 (2 ),/** Number of yellow packets dropped by current leaf node. */ -RTE_TM_STATS_N_PKTS_YELLOW_DROPPED =1 <<3 , +RTE_TM_STATS_N_PKTS_YELLOW_DROPPED =RTE_BIT32 (3 ),/** Number of red packets dropped by current leaf node. */ -RTE_TM_STATS_N_PKTS_RED_DROPPED =1 <<4 , +RTE_TM_STATS_N_PKTS_RED_DROPPED =RTE_BIT32 (4 ),/** Number of green bytes dropped by current leaf node. */ -RTE_TM_STATS_N_BYTES_GREEN_DROPPED =1 <<5 , +RTE_TM_STATS_N_BYTES_GREEN_DROPPED =RTE_BIT32 (5 ),/** Number of yellow bytes dropped by current leaf node. */ -RTE_TM_STATS_N_BYTES_YELLOW_DROPPED =1 <<6 , +RTE_TM_STATS_N_BYTES_YELLOW_DROPPED =RTE_BIT32 (6 ),/** Number of red bytes dropped by current leaf node. */ -RTE_TM_STATS_N_BYTES_RED_DROPPED =1 <<7 , +RTE_TM_STATS_N_BYTES_RED_DROPPED =RTE_BIT32 (7 ),/** Number of packets currently waiting in the packet queue of current * leaf node. */ -RTE_TM_STATS_N_PKTS_QUEUED =1 <<8 , +RTE_TM_STATS_N_PKTS_QUEUED =RTE_BIT32 (8 ),/** Number of bytes currently waiting in the packet queue of current * leaf node. */ -RTE_TM_STATS_N_BYTES_QUEUED =1 <<9 , +RTE_TM_STATS_N_BYTES_QUEUED =RTE_BIT32 (9 ), };/**
@@ -169,31 +169,31 @@ enum rte_tm_dynamic_update_type {* hierarchy level as the former parent node. Consequently, the node * whose parent is changed preserves its hierarchy level. */ -RTE_TM_UPDATE_NODE_PARENT_KEEP_LEVEL =1 <<0 , +RTE_TM_UPDATE_NODE_PARENT_KEEP_LEVEL =RTE_BIT32 (0 ),/** Dynamic parent node update. The new parent node is located on * different hierarchy level than the former parent node. Consequently, * the node whose parent is changed also changes its hierarchy level. */ -RTE_TM_UPDATE_NODE_PARENT_CHANGE_LEVEL =1 <<1 , +RTE_TM_UPDATE_NODE_PARENT_CHANGE_LEVEL =RTE_BIT32 (1 ),/** Dynamic node add/delete. */ -RTE_TM_UPDATE_NODE_ADD_DELETE =1 <<2 , +RTE_TM_UPDATE_NODE_ADD_DELETE =RTE_BIT32 (2 ),/** Suspend/resume nodes. */ -RTE_TM_UPDATE_NODE_SUSPEND_RESUME =1 <<3 , +RTE_TM_UPDATE_NODE_SUSPEND_RESUME =RTE_BIT32 (3 ),/** Dynamic switch between byte-based and packet-based WFQ weights. */ -RTE_TM_UPDATE_NODE_WFQ_WEIGHT_MODE =1 <<4 , +RTE_TM_UPDATE_NODE_WFQ_WEIGHT_MODE =RTE_BIT32 (4 ),/** Dynamic update on number of SP priorities. */ -RTE_TM_UPDATE_NODE_N_SP_PRIORITIES =1 <<5 , +RTE_TM_UPDATE_NODE_N_SP_PRIORITIES =RTE_BIT32 (5 ),/** Dynamic update of congestion management mode for leaf nodes. */ -RTE_TM_UPDATE_NODE_CMAN =1 <<6 , +RTE_TM_UPDATE_NODE_CMAN =RTE_BIT32 (6 ),/** Dynamic update of the set of enabled stats counter types. */ - RTE_TM_UPDATE_NODE_STATS = 1 << 7, + RTE_TM_UPDATE_NODE_STATS = RTE_BIT32(7), };/**
Signature · 1 line
2.33.0
23/09/2021 11:39, Thomas Monjalon:
Quoted 5 lines
The macros
RTE_BIT32andRTE_BIT64are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.Only bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
Quoted 7 lines
The API of
rte_mtrandrte_tmis using enums for 64-bit variables. As they are enums,RTE_BIT32is used.
The corresponding struct members should be converted to 32-bit.Signed-off-by Thomas Monjalon <[email protected]>---
v2: useRTE_BIT32in enums
Ping for review.
Earlier it is merged, more patches will adopt the same syntax for their bits.
Quoted 10 lines · Thomas Monjalon
The macros
RTE_BIT32andRTE_BIT64are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.Only bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
The API of
rte_mtrandrte_tmis using enums for 64-bit variables. As they are enums,RTE_BIT32is used.
The corresponding struct members should be converted to 32-bit.Signed-off-by Thomas Monjalon <[email protected]>
Quoted 5 lines · Thomas Monjalon
The macros
RTE_BIT32andRTE_BIT64are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.Only bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
Quoted 7 lines
The API of
rte_mtrandrte_tmis using enums for 64-bit variables. As they are enums,RTE_BIT32is used.
The corresponding struct members should be converted to 32-bit.Signed-off-by Thomas Monjalon <[email protected]>---
v2: useRTE_BIT32in enums
Hi Thomas,
Can you rebase on top of latest main, this conflict with adding doxygen group comment patch:
Commit 0ce56b057b5c ("ethdev: group constant definitions in Doxygen")
PATCH v3 1/1 ethdev: replace bit shifts with macros
In reply to Thomas MonjalonThe macros RTE_BIT32 and RTE_BIT64 are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.
Only bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
The API of rte_mtr and rte_tm is using enums for 64-bit variables. As they are enums, RTE_BIT32 is used.
The corresponding struct members should be converted to 32-bit.
---
v2: use RTE_BIT32 in enums
v3: rebase on main
--- lib/ethdev/rte_ethdev.c | 16 ++--- lib/ethdev/rte_ethdev.h | 129 ++++++++++++++++++++-------------------- lib/ethdev/rte_flow.c | 4 +- lib/ethdev/rte_flow.h | 6 +- lib/ethdev/rte_mtr.h | 16 ++--- lib/ethdev/rte_tm.h | 36 +++++------ 6 files changed, 104 insertions(+), 103 deletions(-)
lib/ethdev/rte_ethdev.c +8 -8
@@ -1303,7 +1303,7 @@ eth_dev_validate_offloads(uint16_t port_id, uint64_t req_offloads,while (offloads_diff !=0 ) {/* Check if any offload is requested but not enabled. */ - offload =1ULL <<__builtin_ctzll (offloads_diff); + offload =RTE_BIT64 (__builtin_ctzll (offloads_diff));if (offload & req_offloads) { RTE_ETHDEV_LOG(ERR, "Port %u failed to enable %s offload %s\n",
@@ -1669,7 +1669,7 @@ eth_dev_mac_restore(struct rte_eth_dev *dev, pool_mask = dev->data->mac_pool_sel[i]; do { - if (pool_mask & 1ULL) + if (pool_mask & UINT64_C(1)) (*dev->dev_ops->mac_addr_add)(dev, addr, i, pool); pool_mask >>= 1;
@@ -1945,7 +1945,7 @@ rte_eth_rx_queue_check_split(const struct rte_eth_rxseg_split *rx_seg,* for each segment specified in extended configuration. */ mp_first = rx_seg[0 ].mp; - offset_mask = (1u << seg_capa->offset_align_log2) -1 ; + offset_mask =RTE_BIT32 (seg_capa->offset_align_log2) -1 ;for (seg_idx =0 ; seg_idx < n_seg; seg_idx++) {struct rte_mempool *mpl = rx_seg[seg_idx].mp;uint32_t length = rx_seg[seg_idx].length;
@@ -3686,9 +3686,9 @@ rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on) vbit = vlan_id %64 ;if (on) - vfc->ids[vidx] |=UINT64_C (1 ) << vbit; + vfc->ids[vidx] |=RTE_BIT64 (vbit);else - vfc->ids[vidx] &= ~(UINT64_C (1 ) << vbit); + vfc->ids[vidx] &= ~RTE_BIT64 (vbit); }return eth_err (port_id, ret);
@@ -3960,7 +3960,7 @@ eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,for (i =0 ; i < reta_size; i++) { idx = i /RTE_RETA_GROUP_SIZE ; shift = i %RTE_RETA_GROUP_SIZE ; -if ((reta_conf[idx].mask & (1ULL << shift)) && +if ((reta_conf[idx].mask &RTE_BIT64 (shift)) && (reta_conf[idx].reta[shift] >= max_rxq)) { RTE_ETHDEV_LOG(ERR, "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u\n",
@@ -4299,7 +4299,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr, pool_mask = dev->data->mac_pool_sel[index];/* Check if both MAC address and pool is already there, and do nothing */ -if (pool_mask & (1ULL << pool)) +if (pool_mask &RTE_BIT64 (pool))return 0 ; }
@@ -4311,7 +4311,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,rte_ether_addr_copy (addr, &dev->data->mac_addrs[index]);/* Update pool bitmap in NIC data structure */ - dev->data->mac_pool_sel[index] |= (1ULL << pool); + dev->data->mac_pool_sel[index] |=RTE_BIT64 (pool); }return eth_err (port_id, ret);
lib/ethdev/rte_ethdev.h +65 -64
173 lines not on this page · raw message
lib/ethdev/rte_flow.c +2 -2
@@ -213,12 +213,12 @@ rte_flow_dynf_metadata_register(void)if (flag <0 ) goto error; rte_flow_dynf_metadata_offs = offset; - rte_flow_dynf_metadata_mask = (1ULL << flag); + rte_flow_dynf_metadata_mask =RTE_BIT64 (flag);return 0 ; error: rte_flow_dynf_metadata_offs =-1 ; - rte_flow_dynf_metadata_mask =0ULL ; + rte_flow_dynf_metadata_mask =UINT64_C (0 );return -rte_errno; }
lib/ethdev/rte_flow.h +3 -3
@@ -4131,17 +4131,17 @@ struct rte_flow_tunnel {/** * Indicate that the packet has a tunnel. */ -#define RTE_FLOW_RESTORE_INFO_TUNNEL (1ULL << 0) +#define RTE_FLOW_RESTORE_INFO_TUNNEL RTE_BIT64(0)/** * Indicate that the packet has a non decapsulated tunnel header. */ -#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED (1ULL << 1) +#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED RTE_BIT64(1)/** * Indicate that the packet has a group_id. */ -#define RTE_FLOW_RESTORE_INFO_GROUP_ID (1ULL << 2) +#define RTE_FLOW_RESTORE_INFO_GROUP_ID RTE_BIT64(2)/** * Restore information structure to communicate the current packet processing
lib/ethdev/rte_mtr.h +8 -8
@@ -60,28 +60,28 @@ extern "C" {*/ enum rte_mtr_stats_type {/** Number of packets passed as green by the policer. */ -RTE_MTR_STATS_N_PKTS_GREEN =1 <<0 , +RTE_MTR_STATS_N_PKTS_GREEN =RTE_BIT32 (0 ),/** Number of packets passed as yellow by the policer. */ -RTE_MTR_STATS_N_PKTS_YELLOW =1 <<1 , +RTE_MTR_STATS_N_PKTS_YELLOW =RTE_BIT32 (1 ),/** Number of packets passed as red by the policer. */ -RTE_MTR_STATS_N_PKTS_RED =1 <<2 , +RTE_MTR_STATS_N_PKTS_RED =RTE_BIT32 (2 ),/** Number of packets dropped by the policer. */ -RTE_MTR_STATS_N_PKTS_DROPPED =1 <<3 , +RTE_MTR_STATS_N_PKTS_DROPPED =RTE_BIT32 (3 ),/** Number of bytes passed as green by the policer. */ -RTE_MTR_STATS_N_BYTES_GREEN =1 <<4 , +RTE_MTR_STATS_N_BYTES_GREEN =RTE_BIT32 (4 ),/** Number of bytes passed as yellow by the policer. */ -RTE_MTR_STATS_N_BYTES_YELLOW =1 <<5 , +RTE_MTR_STATS_N_BYTES_YELLOW =RTE_BIT32 (5 ),/** Number of bytes passed as red by the policer. */ -RTE_MTR_STATS_N_BYTES_RED =1 <<6 , +RTE_MTR_STATS_N_BYTES_RED =RTE_BIT32 (6 ),/** Number of bytes dropped by the policer. */ -RTE_MTR_STATS_N_BYTES_DROPPED =1 <<7 , +RTE_MTR_STATS_N_BYTES_DROPPED =RTE_BIT32 (7 ), };/**
lib/ethdev/rte_tm.h +18 -18
@@ -93,38 +93,38 @@ extern "C" {*/ enum rte_tm_stats_type {/** Number of packets scheduled from current node. */ -RTE_TM_STATS_N_PKTS =1 <<0 , +RTE_TM_STATS_N_PKTS =RTE_BIT32 (0 ),/** Number of bytes scheduled from current node. */ -RTE_TM_STATS_N_BYTES =1 <<1 , +RTE_TM_STATS_N_BYTES =RTE_BIT32 (1 ),/** Number of green packets dropped by current leaf node. */ -RTE_TM_STATS_N_PKTS_GREEN_DROPPED =1 <<2 , +RTE_TM_STATS_N_PKTS_GREEN_DROPPED =RTE_BIT32 (2 ),/** Number of yellow packets dropped by current leaf node. */ -RTE_TM_STATS_N_PKTS_YELLOW_DROPPED =1 <<3 , +RTE_TM_STATS_N_PKTS_YELLOW_DROPPED =RTE_BIT32 (3 ),/** Number of red packets dropped by current leaf node. */ -RTE_TM_STATS_N_PKTS_RED_DROPPED =1 <<4 , +RTE_TM_STATS_N_PKTS_RED_DROPPED =RTE_BIT32 (4 ),/** Number of green bytes dropped by current leaf node. */ -RTE_TM_STATS_N_BYTES_GREEN_DROPPED =1 <<5 , +RTE_TM_STATS_N_BYTES_GREEN_DROPPED =RTE_BIT32 (5 ),/** Number of yellow bytes dropped by current leaf node. */ -RTE_TM_STATS_N_BYTES_YELLOW_DROPPED =1 <<6 , +RTE_TM_STATS_N_BYTES_YELLOW_DROPPED =RTE_BIT32 (6 ),/** Number of red bytes dropped by current leaf node. */ -RTE_TM_STATS_N_BYTES_RED_DROPPED =1 <<7 , +RTE_TM_STATS_N_BYTES_RED_DROPPED =RTE_BIT32 (7 ),/** Number of packets currently waiting in the packet queue of current * leaf node. */ -RTE_TM_STATS_N_PKTS_QUEUED =1 <<8 , +RTE_TM_STATS_N_PKTS_QUEUED =RTE_BIT32 (8 ),/** Number of bytes currently waiting in the packet queue of current * leaf node. */ -RTE_TM_STATS_N_BYTES_QUEUED =1 <<9 , +RTE_TM_STATS_N_BYTES_QUEUED =RTE_BIT32 (9 ), };/**
@@ -169,31 +169,31 @@ enum rte_tm_dynamic_update_type {* hierarchy level as the former parent node. Consequently, the node * whose parent is changed preserves its hierarchy level. */ -RTE_TM_UPDATE_NODE_PARENT_KEEP_LEVEL =1 <<0 , +RTE_TM_UPDATE_NODE_PARENT_KEEP_LEVEL =RTE_BIT32 (0 ),/** Dynamic parent node update. The new parent node is located on * different hierarchy level than the former parent node. Consequently, * the node whose parent is changed also changes its hierarchy level. */ -RTE_TM_UPDATE_NODE_PARENT_CHANGE_LEVEL =1 <<1 , +RTE_TM_UPDATE_NODE_PARENT_CHANGE_LEVEL =RTE_BIT32 (1 ),/** Dynamic node add/delete. */ -RTE_TM_UPDATE_NODE_ADD_DELETE =1 <<2 , +RTE_TM_UPDATE_NODE_ADD_DELETE =RTE_BIT32 (2 ),/** Suspend/resume nodes. */ -RTE_TM_UPDATE_NODE_SUSPEND_RESUME =1 <<3 , +RTE_TM_UPDATE_NODE_SUSPEND_RESUME =RTE_BIT32 (3 ),/** Dynamic switch between byte-based and packet-based WFQ weights. */ -RTE_TM_UPDATE_NODE_WFQ_WEIGHT_MODE =1 <<4 , +RTE_TM_UPDATE_NODE_WFQ_WEIGHT_MODE =RTE_BIT32 (4 ),/** Dynamic update on number of SP priorities. */ -RTE_TM_UPDATE_NODE_N_SP_PRIORITIES =1 <<5 , +RTE_TM_UPDATE_NODE_N_SP_PRIORITIES =RTE_BIT32 (5 ),/** Dynamic update of congestion management mode for leaf nodes. */ -RTE_TM_UPDATE_NODE_CMAN =1 <<6 , +RTE_TM_UPDATE_NODE_CMAN =RTE_BIT32 (6 ),/** Dynamic update of the set of enabled stats counter types. */ - RTE_TM_UPDATE_NODE_STATS = 1 << 7, + RTE_TM_UPDATE_NODE_STATS = RTE_BIT32(7), };/**
Signature · 1 line
2.33.0
07/10/2021 15:26, Thomas Monjalon:
Quoted 8 lines
The macros
RTE_BIT32andRTE_BIT64are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.Only bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
The API of
rte_mtrandrte_tmis using enums for 64-bit variables. As they are enums,RTE_BIT32is used.
The corresponding struct members should be converted to 32-bit.
According to this report:
http://mails.dpdk.org/archives/test-report/2021-October/224792.html
Ubuntu 18.04 does not accept this change:
rte_tm.h:181:2: error: enumerator value for ‘RTE_TM_UPDATE_NODE_ADD_DELETE’ is not an integer constant
RTE_TM_UPDATE_NODE_ADD_DELETE = RTE_BIT32(2),
Anybody understands why?
PATCH v4 1/1 ethdev: replace bit shifts with macros
In reply to Thomas MonjalonThe macros RTE_BIT32 and RTE_BIT64 are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.
The bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
The API of rte_mtr and rte_tm is using enums for 64-bit variables. As they are enums, unsigned bit cannot be used.
---
v2: use RTE_BIT32 in enums
v3: rebase on main
v4: keep enums untouched
--- lib/ethdev/rte_ethdev.c | 16 ++--- lib/ethdev/rte_ethdev.h | 129 ++++++++++++++++++++-------------------- lib/ethdev/rte_flow.c | 4 +- lib/ethdev/rte_flow.h | 6 +- 4 files changed, 78 insertions(+), 77 deletions(-)
lib/ethdev/rte_ethdev.c +8 -8
@@ -1303,7 +1303,7 @@ eth_dev_validate_offloads(uint16_t port_id, uint64_t req_offloads,while (offloads_diff !=0 ) {/* Check if any offload is requested but not enabled. */ - offload =1ULL <<__builtin_ctzll (offloads_diff); + offload =RTE_BIT64 (__builtin_ctzll (offloads_diff));if (offload & req_offloads) { RTE_ETHDEV_LOG(ERR, "Port %u failed to enable %s offload %s\n",
@@ -1669,7 +1669,7 @@ eth_dev_mac_restore(struct rte_eth_dev *dev, pool_mask = dev->data->mac_pool_sel[i]; do { - if (pool_mask & 1ULL) + if (pool_mask & UINT64_C(1)) (*dev->dev_ops->mac_addr_add)(dev, addr, i, pool); pool_mask >>= 1;
@@ -1945,7 +1945,7 @@ rte_eth_rx_queue_check_split(const struct rte_eth_rxseg_split *rx_seg,* for each segment specified in extended configuration. */ mp_first = rx_seg[0 ].mp; - offset_mask = (1u << seg_capa->offset_align_log2) -1 ; + offset_mask =RTE_BIT32 (seg_capa->offset_align_log2) -1 ;for (seg_idx =0 ; seg_idx < n_seg; seg_idx++) {struct rte_mempool *mpl = rx_seg[seg_idx].mp;uint32_t length = rx_seg[seg_idx].length;
@@ -3686,9 +3686,9 @@ rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on) vbit = vlan_id %64 ;if (on) - vfc->ids[vidx] |=UINT64_C (1 ) << vbit; + vfc->ids[vidx] |=RTE_BIT64 (vbit);else - vfc->ids[vidx] &= ~(UINT64_C (1 ) << vbit); + vfc->ids[vidx] &= ~RTE_BIT64 (vbit); }return eth_err (port_id, ret);
@@ -3960,7 +3960,7 @@ eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,for (i =0 ; i < reta_size; i++) { idx = i /RTE_RETA_GROUP_SIZE ; shift = i %RTE_RETA_GROUP_SIZE ; -if ((reta_conf[idx].mask & (1ULL << shift)) && +if ((reta_conf[idx].mask &RTE_BIT64 (shift)) && (reta_conf[idx].reta[shift] >= max_rxq)) { RTE_ETHDEV_LOG(ERR, "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u\n",
@@ -4299,7 +4299,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr, pool_mask = dev->data->mac_pool_sel[index];/* Check if both MAC address and pool is already there, and do nothing */ -if (pool_mask & (1ULL << pool)) +if (pool_mask &RTE_BIT64 (pool))return 0 ; }
@@ -4311,7 +4311,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,rte_ether_addr_copy (addr, &dev->data->mac_addrs[index]);/* Update pool bitmap in NIC data structure */ - dev->data->mac_pool_sel[index] |= (1ULL << pool); + dev->data->mac_pool_sel[index] |=RTE_BIT64 (pool); }return eth_err (port_id, ret);
lib/ethdev/rte_ethdev.h +65 -64
173 lines not on this page · raw message
lib/ethdev/rte_flow.c +2 -2
@@ -213,12 +213,12 @@ rte_flow_dynf_metadata_register(void)if (flag <0 ) goto error; rte_flow_dynf_metadata_offs = offset; - rte_flow_dynf_metadata_mask = (1ULL << flag); + rte_flow_dynf_metadata_mask =RTE_BIT64 (flag);return 0 ; error: rte_flow_dynf_metadata_offs =-1 ; - rte_flow_dynf_metadata_mask =0ULL ; + rte_flow_dynf_metadata_mask =UINT64_C (0 );return -rte_errno; }
lib/ethdev/rte_flow.h +3 -3
@@ -4131,17 +4131,17 @@ struct rte_flow_tunnel {/** * Indicate that the packet has a tunnel. */ -#define RTE_FLOW_RESTORE_INFO_TUNNEL (1ULL << 0) +#define RTE_FLOW_RESTORE_INFO_TUNNEL RTE_BIT64(0)/** * Indicate that the packet has a non decapsulated tunnel header. */ -#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED (1ULL << 1) +#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED RTE_BIT64(1)/** * Indicate that the packet has a group_id. */ -#define RTE_FLOW_RESTORE_INFO_GROUP_ID (1ULL << 2) +#define RTE_FLOW_RESTORE_INFO_GROUP_ID RTE_BIT64(2)/** * Restore information structure to communicate the current packet processing
Signature · 1 line
2.33.0
Quoted 14 lines · Thomas Monjalon
The macros
RTE_BIT32andRTE_BIT64are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.The bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
The API of
rte_mtrandrte_tmis using enums for 64-bit variables. As they are enums, unsigned bit cannot be used.Signed-off-by Thomas Monjalon <[email protected]>Reviewed-by Andrew Rybchenko <[email protected]>---
v2: useRTE_BIT32in enums
v3: rebase on main
v4: keep enums untouched
Quoted 7 lines
--- lib/ethdev/rte_ethdev.c | 16 ++--- lib/ethdev/rte_ethdev.h | 129 ++++++++++++++++++++-------------------- lib/ethdev/rte_flow.c | 4 +- lib/ethdev/rte_flow.h | 6 +- 4 files changed, 78 insertions(+), 77 deletions(-)
Is 'ETH_RSS_L4_CHKSUM' left unchanged intentionally?
#define ETH_RSS_L4_CHKSUM (1ULL << 35)
07/10/2021 19:32, Ferruh Yigit:
Quoted 3 lines
Is '
ETH_RSS_L4_CHKSUM' left unchanged intentionally?#define
ETH_RSS_L4_CHKSUM(1ULL << 35)
No, I missed it when rebasing.
PATCH v5 1/1 ethdev: replace bit shifts with macros
In reply to Thomas MonjalonThe macros RTE_BIT32 and RTE_BIT64 are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.
The bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
The API of rte_mtr and rte_tm is using enums for 64-bit variables. As they are enums, unsigned bit cannot be used.
---
v2: use RTE_BIT32 in enums
v3: rebase on main
v4: keep enums untouched
v5: convert new flag ETH_RSS_L4_CHKSUM
--- lib/ethdev/rte_ethdev.c | 16 ++--- lib/ethdev/rte_ethdev.h | 131 ++++++++++++++++++++-------------------- lib/ethdev/rte_flow.c | 4 +- lib/ethdev/rte_flow.h | 6 +- 4 files changed, 79 insertions(+), 78 deletions(-)
lib/ethdev/rte_ethdev.c +8 -8
@@ -1317,7 +1317,7 @@ eth_dev_validate_offloads(uint16_t port_id, uint64_t req_offloads,while (offloads_diff !=0 ) {/* Check if any offload is requested but not enabled. */ - offload =1ULL <<__builtin_ctzll (offloads_diff); + offload =RTE_BIT64 (__builtin_ctzll (offloads_diff));if (offload & req_offloads) { RTE_ETHDEV_LOG(ERR, "Port %u failed to enable %s offload %s\n",
@@ -1683,7 +1683,7 @@ eth_dev_mac_restore(struct rte_eth_dev *dev, pool_mask = dev->data->mac_pool_sel[i]; do { - if (pool_mask & 1ULL) + if (pool_mask & UINT64_C(1)) (*dev->dev_ops->mac_addr_add)(dev, addr, i, pool); pool_mask >>= 1;
@@ -1959,7 +1959,7 @@ rte_eth_rx_queue_check_split(const struct rte_eth_rxseg_split *rx_seg,* for each segment specified in extended configuration. */ mp_first = rx_seg[0 ].mp; - offset_mask = (1u << seg_capa->offset_align_log2) -1 ; + offset_mask =RTE_BIT32 (seg_capa->offset_align_log2) -1 ;for (seg_idx =0 ; seg_idx < n_seg; seg_idx++) {struct rte_mempool *mpl = rx_seg[seg_idx].mp;uint32_t length = rx_seg[seg_idx].length;
@@ -3666,9 +3666,9 @@ rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on) vbit = vlan_id %64 ;if (on) - vfc->ids[vidx] |=UINT64_C (1 ) << vbit; + vfc->ids[vidx] |=RTE_BIT64 (vbit);else - vfc->ids[vidx] &= ~(UINT64_C (1 ) << vbit); + vfc->ids[vidx] &= ~RTE_BIT64 (vbit); }return eth_err (port_id, ret);
@@ -3940,7 +3940,7 @@ eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,for (i =0 ; i < reta_size; i++) { idx = i /RTE_RETA_GROUP_SIZE ; shift = i %RTE_RETA_GROUP_SIZE ; -if ((reta_conf[idx].mask & (1ULL << shift)) && +if ((reta_conf[idx].mask &RTE_BIT64 (shift)) && (reta_conf[idx].reta[shift] >= max_rxq)) { RTE_ETHDEV_LOG(ERR, "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u\n",
@@ -4279,7 +4279,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr, pool_mask = dev->data->mac_pool_sel[index];/* Check if both MAC address and pool is already there, and do nothing */ -if (pool_mask & (1ULL << pool)) +if (pool_mask &RTE_BIT64 (pool))return 0 ; }
@@ -4291,7 +4291,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,rte_ether_addr_copy (addr, &dev->data->mac_addrs[index]);/* Update pool bitmap in NIC data structure */ - dev->data->mac_pool_sel[index] |= (1ULL << pool); + dev->data->mac_pool_sel[index] |=RTE_BIT64 (pool); }return eth_err (port_id, ret);
lib/ethdev/rte_ethdev.h +66 -65
181 lines not on this page · raw message
lib/ethdev/rte_flow.c +2 -2
@@ -213,12 +213,12 @@ rte_flow_dynf_metadata_register(void)if (flag <0 ) goto error; rte_flow_dynf_metadata_offs = offset; - rte_flow_dynf_metadata_mask = (1ULL << flag); + rte_flow_dynf_metadata_mask =RTE_BIT64 (flag);return 0 ; error: rte_flow_dynf_metadata_offs =-1 ; - rte_flow_dynf_metadata_mask =0ULL ; + rte_flow_dynf_metadata_mask =UINT64_C (0 );return -rte_errno; }
lib/ethdev/rte_flow.h +3 -3
@@ -4131,17 +4131,17 @@ struct rte_flow_tunnel {/** * Indicate that the packet has a tunnel. */ -#define RTE_FLOW_RESTORE_INFO_TUNNEL (1ULL << 0) +#define RTE_FLOW_RESTORE_INFO_TUNNEL RTE_BIT64(0)/** * Indicate that the packet has a non decapsulated tunnel header. */ -#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED (1ULL << 1) +#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED RTE_BIT64(1)/** * Indicate that the packet has a group_id. */ -#define RTE_FLOW_RESTORE_INFO_GROUP_ID (1ULL << 2) +#define RTE_FLOW_RESTORE_INFO_GROUP_ID RTE_BIT64(2)/** * Restore information structure to communicate the current packet processing
Signature · 1 line
2.33.0
Quoted 8 lines · Thomas Monjalon
The macros
RTE_BIT32andRTE_BIT64are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.The bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
The API of
rte_mtrandrte_tmis using enums for 64-bit variables. As they are enums, unsigned bit cannot be used.
Quoted 7 lines
Signed-off-by Thomas Monjalon<[email protected]>Reviewed-by Andrew Rybchenko<[email protected]>---
v2: useRTE_BIT32in enums
v3: rebase on main
v4: keep enums untouched
v5: convert new flagETH_RSS_L4_CHKSUM
Hi Thomas,
Thanks for the update, but a recent commit [1] in ethdev is added a few more '<<', can you please rebase on the latest next-net.
[1]
Commit c4f4884b654b ("ethdev: negotiate delivery of packet metadata from HW to PMD")
PATCH v6 1/1 ethdev: replace bit shifts with macros
In reply to Thomas MonjalonFrom: Thomas Monjalon <[email protected]>
The macros RTE_BIT32 and RTE_BIT64 are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.
The bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
The API of rte_mtr and rte_tm is using enums for 64-bit variables. As they are enums, unsigned bit cannot be used.
---
v6:
* Rebased on top of latest next-net
--- lib/ethdev/rte_ethdev.c | 16 ++--- lib/ethdev/rte_ethdev.h | 137 ++++++++++++++++++++-------------------- lib/ethdev/rte_flow.c | 4 +- lib/ethdev/rte_flow.h | 6 +- 4 files changed, 82 insertions(+), 81 deletions(-)
lib/ethdev/rte_ethdev.c +8 -8
@@ -1293,7 +1293,7 @@ eth_dev_validate_offloads(uint16_t port_id, uint64_t req_offloads,while (offloads_diff !=0 ) {/* Check if any offload is requested but not enabled. */ - offload =1ULL <<__builtin_ctzll (offloads_diff); + offload =RTE_BIT64 (__builtin_ctzll (offloads_diff));if (offload & req_offloads) { RTE_ETHDEV_LOG(ERR, "Port %u failed to enable %s offload %s\n",
@@ -1687,7 +1687,7 @@ eth_dev_mac_restore(struct rte_eth_dev *dev, pool_mask = dev->data->mac_pool_sel[i]; do { - if (pool_mask & 1ULL) + if (pool_mask & UINT64_C(1)) (*dev->dev_ops->mac_addr_add)(dev, addr, i, pool); pool_mask >>= 1;
@@ -1969,7 +1969,7 @@ rte_eth_rx_queue_check_split(const struct rte_eth_rxseg_split *rx_seg,* for each segment specified in extended configuration. */ mp_first = rx_seg[0 ].mp; - offset_mask = (1u << seg_capa->offset_align_log2) -1 ; + offset_mask =RTE_BIT32 (seg_capa->offset_align_log2) -1 ;for (seg_idx =0 ; seg_idx < n_seg; seg_idx++) {struct rte_mempool *mpl = rx_seg[seg_idx].mp;uint32_t length = rx_seg[seg_idx].length;
@@ -3730,9 +3730,9 @@ rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on) vbit = vlan_id %64 ;if (on) - vfc->ids[vidx] |=UINT64_C (1 ) << vbit; + vfc->ids[vidx] |=RTE_BIT64 (vbit);else - vfc->ids[vidx] &= ~(UINT64_C (1 ) << vbit); + vfc->ids[vidx] &= ~RTE_BIT64 (vbit); }return eth_err (port_id, ret);
@@ -4004,7 +4004,7 @@ eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,for (i =0 ; i < reta_size; i++) { idx = i /RTE_RETA_GROUP_SIZE ; shift = i %RTE_RETA_GROUP_SIZE ; -if ((reta_conf[idx].mask & (1ULL << shift)) && +if ((reta_conf[idx].mask &RTE_BIT64 (shift)) && (reta_conf[idx].reta[shift] >= max_rxq)) { RTE_ETHDEV_LOG(ERR, "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u\n",
@@ -4343,7 +4343,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr, pool_mask = dev->data->mac_pool_sel[index];/* Check if both MAC address and pool is already there, and do nothing */ -if (pool_mask & (1ULL << pool)) +if (pool_mask &RTE_BIT64 (pool))return 0 ; }
@@ -4355,7 +4355,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,rte_ether_addr_copy (addr, &dev->data->mac_addrs[index]);/* Update pool bitmap in NIC data structure */ - dev->data->mac_pool_sel[index] |= (1ULL << pool); + dev->data->mac_pool_sel[index] |=RTE_BIT64 (pool); }return eth_err (port_id, ret);
lib/ethdev/rte_ethdev.h +69 -68
197 lines not on this page · raw message
lib/ethdev/rte_flow.c +2 -2
@@ -217,12 +217,12 @@ rte_flow_dynf_metadata_register(void)if (flag <0 ) goto error; rte_flow_dynf_metadata_offs = offset; - rte_flow_dynf_metadata_mask = (1ULL << flag); + rte_flow_dynf_metadata_mask =RTE_BIT64 (flag);return 0 ; error: rte_flow_dynf_metadata_offs =-1 ; - rte_flow_dynf_metadata_mask =0ULL ; + rte_flow_dynf_metadata_mask =UINT64_C (0 );return -rte_errno; }
lib/ethdev/rte_flow.h +3 -3
@@ -4283,17 +4283,17 @@ struct rte_flow_tunnel {/** * Indicate that the packet has a tunnel. */ -#define RTE_FLOW_RESTORE_INFO_TUNNEL (1ULL << 0) +#define RTE_FLOW_RESTORE_INFO_TUNNEL RTE_BIT64(0)/** * Indicate that the packet has a non decapsulated tunnel header. */ -#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED (1ULL << 1) +#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED RTE_BIT64(1)/** * Indicate that the packet has a group_id. */ -#define RTE_FLOW_RESTORE_INFO_GROUP_ID (1ULL << 2) +#define RTE_FLOW_RESTORE_INFO_GROUP_ID RTE_BIT64(2)/** * Restore information structure to communicate the current packet processing
Signature · 1 line
2.31.1
Ferruh Yigit
AppliedQuoted 5 lines · Ferruh Yigit
From: Thomas Monjalon <[email protected]>
The macros
RTE_BIT32andRTE_BIT64are used to replace bit shifts. The macro UINT64C is also used to replace remaining occurrences of ULL.
Quoted 7 lines
The bit shifts of ETH_RSS_LEVEL_* are kept for aesthetic reason.
The API of
rte_mtrandrte_tmis using enums for 64-bit variables. As they are enums, unsigned bit cannot be used.Signed-off-by Thomas Monjalon <[email protected]>Reviewed-by Andrew Rybchenko <[email protected]>
Applied to dpdk-next-net/main, thanks.