net/iavf: fix race condition for multi-cores
PATCH 1/1 net/iavf: fix race condition for multi-cores
In multi-cores cases for RX timestamp offload, if packets arrive too fast, aq command to get phc time will be pended.
This patch adds spinlock to fix this issue. To avoid phc time being frequently overwritten, move related variables to iavf_rx_queue structure, and each queue will handle timestamp calculation by itself.
--- drivers/net/iavf/iavf.h | 5 ++- drivers/net/iavf/iavf_ethdev.c | 9 ++---- drivers/net/iavf/iavf_rxtx.c | 56 ++++++++++++++++++++-------------- drivers/net/iavf/iavf_rxtx.h | 2 ++ drivers/net/iavf/iavf_vchnl.c | 17 ++++++----- 5 files changed, 49 insertions(+), 40 deletions(-)
drivers/net/iavf/iavf.h +2 -3
@@ -270,6 +270,7 @@ struct iavf_info {struct rte_eth_dev *eth_dev;uint32_t ptp_caps; +rte_spinlock_t phc_time_aq_lock; };#define IAVF_MAX_PKT_TYPE 1024
@@ -314,8 +315,6 @@ struct iavf_adapter {bool stopped;uint16_t fdir_ref_cnt;struct iavf_devargs devargs; -uint64_t phc_time; -uint64_t hw_time_update; };/* IAVF_DEV_PRIVATE_TO */
@@ -481,5 +480,5 @@ int iavf_ipsec_crypto_request(struct iavf_adapter *adapter, uint8_t *resp_msg, size_t resp_msg_len);extern const struct rte_tm_ops iavf_tm_ops;int iavf_get_ptp_cap (struct iavf_adapter *adapter); -int iavf_get_phc_time (struct iavf_adapter *adapter); +int iavf_get_phc_time (struct iavf_rx_queue *rxq);#endif /* _IAVF_ETHDEV_H_ */
drivers/net/iavf/iavf_ethdev.c +2 -7
@@ -1020,13 +1020,8 @@ iavf_dev_start(struct rte_eth_dev *dev) }if (dev->data->dev_conf.rxmode.offloads & -RTE_ETH_RX_OFFLOAD_TIMESTAMP ) { -if (iavf_get_phc_time (adapter)) { -PMD_DRV_LOG (ERR ,"get physical time failed" ); - goto err_mac; - } - adapter->hw_time_update =rte_get_timer_cycles () / (rte_get_timer_hz () /1000 ); - } +RTE_ETH_RX_OFFLOAD_TIMESTAMP ) +rte_spinlock_init (&vf->phc_time_aq_lock);return 0 ;
drivers/net/iavf/iavf_rxtx.c +33 -23
127 lines not on this page · raw message
drivers/net/iavf/iavf_rxtx.h +2 -0
@@ -222,6 +222,8 @@ struct iavf_rx_queue {/* flexible descriptor metadata extraction offload flag */ struct iavf_rx_queue_stats stats;uint64_t offloads; +uint64_t phc_time; +uint64_t hw_time_update; };struct iavf_tx_entry {
drivers/net/iavf/iavf_vchnl.c +10 -7
@@ -1896,12 +1896,13 @@ iavf_get_ptp_cap(struct iavf_adapter *adapter) }int -iavf_get_phc_time (struct iavf_adapter *adapter) +iavf_get_phc_time (struct iavf_rx_queue *rxq) { +struct iavf_adapter *adapter = rxq->vsi->adapter;struct iavf_info *vf =IAVF_DEV_PRIVATE_TO_VF (adapter);struct virtchnl_phc_time phc_time;struct iavf_cmd_info args; -int err; +int err =0 ; args.ops =VIRTCHNL_OP_1588_PTP_GET_TIME ; args.in_args = (uint8_t *)&phc_time;
@@ -1909,14 +1910,16 @@ iavf_get_phc_time(struct iavf_adapter *adapter) args.out_buffer = vf->aq_resp; args.out_size =IAVF_AQ_BUF_SZ ; +rte_spinlock_lock (&vf->phc_time_aq_lock); err =iavf_execute_vf_cmd (adapter, &args,0 );if (err) {PMD_DRV_LOG (ERR , -"Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME" ); -return err; +"Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME" ); + goto out; } + rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time; - adapter->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time; - -return 0 ; +out: +rte_spinlock_unlock (&vf->phc_time_aq_lock); +return err; }
Signature · 1 line
2.25.1
drivers/net/iavf/iavf_ethdev.c iavf_dev_start(struct rte_eth_dev *dev) · line 1024
Quoted 10 lines · On Thu, 19 May 2022 09:19:59 +0800 Wenjun Wu <[email protected]> wrote:
drivers/net/iavf/iavf_ethdev.c +2
-7if (dev->data->dev_conf.rxmode.offloads & -RTE_ETH_RX_OFFLOAD_TIMESTAMP ) { -if (iavf_get_phc_time (adapter)) { -PMD_DRV_LOG (ERR ,"get physical time failed" ); - goto err_mac; - } - adapter->hw_time_update =rte_get_timer_cycles () / (rte_get_timer_hz () /1000 ); - } +RTE_ETH_RX_OFFLOAD_TIMESTAMP ) +rte_spinlock_init (&vf->phc_time_aq_lock);
Be safe just always init the spin_lock. It is just a simple assignment.
PATCH v2 1/1 net/iavf: fix race condition for multi-cores
In reply to Wenjun WuIn multi-cores cases for RX timestamp offload, if packets arrive too fast, aq command to get phc time will be pended.
This patch adds spinlock to fix this issue. To avoid phc time being frequently overwritten, move related variables to iavf_rx_queue structure, and each queue will handle timestamp calculation by itself.
---
v2: move duplicated spinlock initialization.
--- drivers/net/iavf/iavf.h | 5 ++-- drivers/net/iavf/iavf_ethdev.c | 13 +++----- drivers/net/iavf/iavf_rxtx.c | 55 ++++++++++++++++++++-------------- drivers/net/iavf/iavf_rxtx.h | 2 ++ drivers/net/iavf/iavf_vchnl.c | 17 ++++++----- 5 files changed, 50 insertions(+), 42 deletions(-)
drivers/net/iavf/iavf.h +2 -3
@@ -270,6 +270,7 @@ struct iavf_info {struct rte_eth_dev *eth_dev;uint32_t ptp_caps; +rte_spinlock_t phc_time_aq_lock; };#define IAVF_MAX_PKT_TYPE 1024
@@ -314,8 +315,6 @@ struct iavf_adapter {bool stopped;uint16_t fdir_ref_cnt;struct iavf_devargs devargs; -uint64_t phc_time; -uint64_t hw_time_update; };/* IAVF_DEV_PRIVATE_TO */
@@ -481,5 +480,5 @@ int iavf_ipsec_crypto_request(struct iavf_adapter *adapter, uint8_t *resp_msg, size_t resp_msg_len);extern const struct rte_tm_ops iavf_tm_ops;int iavf_get_ptp_cap (struct iavf_adapter *adapter); -int iavf_get_phc_time (struct iavf_adapter *adapter); +int iavf_get_phc_time (struct iavf_rx_queue *rxq);#endif /* _IAVF_ETHDEV_H_ */
drivers/net/iavf/iavf_ethdev.c +4 -9
@@ -1014,20 +1014,15 @@ iavf_dev_start(struct rte_eth_dev *dev)iavf_add_del_mc_addr_list (adapter, vf->mc_addrs, vf->mc_addrs_num, true); +if (dev->data->dev_conf.rxmode.offloads & +RTE_ETH_RX_OFFLOAD_TIMESTAMP ) +rte_spinlock_init (&vf->phc_time_aq_lock); +if (iavf_start_queues (dev) !=0 ) {PMD_DRV_LOG (ERR ,"enable queues failed" ); goto err_mac; } -if (dev->data->dev_conf.rxmode.offloads & -RTE_ETH_RX_OFFLOAD_TIMESTAMP ) { -if (iavf_get_phc_time (adapter)) { -PMD_DRV_LOG (ERR ,"get physical time failed" ); - goto err_mac; - } - adapter->hw_time_update =rte_get_timer_cycles () / (rte_get_timer_hz () /1000 ); - } -return 0 ; err_mac:
drivers/net/iavf/iavf_rxtx.c +32 -23
126 lines not on this page · raw message
drivers/net/iavf/iavf_rxtx.h +2 -0
@@ -222,6 +222,8 @@ struct iavf_rx_queue {/* flexible descriptor metadata extraction offload flag */ struct iavf_rx_queue_stats stats;uint64_t offloads; +uint64_t phc_time; +uint64_t hw_time_update; };struct iavf_tx_entry {
drivers/net/iavf/iavf_vchnl.c +10 -7
@@ -1896,12 +1896,13 @@ iavf_get_ptp_cap(struct iavf_adapter *adapter) }int -iavf_get_phc_time (struct iavf_adapter *adapter) +iavf_get_phc_time (struct iavf_rx_queue *rxq) { +struct iavf_adapter *adapter = rxq->vsi->adapter;struct iavf_info *vf =IAVF_DEV_PRIVATE_TO_VF (adapter);struct virtchnl_phc_time phc_time;struct iavf_cmd_info args; -int err; +int err =0 ; args.ops =VIRTCHNL_OP_1588_PTP_GET_TIME ; args.in_args = (uint8_t *)&phc_time;
@@ -1909,14 +1910,16 @@ iavf_get_phc_time(struct iavf_adapter *adapter) args.out_buffer = vf->aq_resp; args.out_size =IAVF_AQ_BUF_SZ ; +rte_spinlock_lock (&vf->phc_time_aq_lock); err =iavf_execute_vf_cmd (adapter, &args,0 );if (err) {PMD_DRV_LOG (ERR , -"Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME" ); -return err; +"Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME" ); + goto out; } + rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time; - adapter->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time; - -return 0 ; +out: +rte_spinlock_unlock (&vf->phc_time_aq_lock); +return err; }
Signature · 1 line
2.25.1
drivers/net/iavf/iavf_ethdev.c iavf_dev_start(struct rte_eth_dev *dev) · line 1020
Quoted 5 lines · On Thu, 19 May 2022 15:33:34 +0800 Wenjun Wu <[email protected]> wrote:
drivers/net/iavf/iavf_ethdev.c +4
-0+if (dev->data->dev_conf.rxmode.offloads & +RTE_ETH_RX_OFFLOAD_TIMESTAMP ) +rte_spinlock_init (&vf->phc_time_aq_lock); +
There is no reason this init needs to be only true with some flags. Just always do it.
PATCH v3 1/1 net/iavf: fix race condition for multi-cores
In reply to Wenjun WuIn multi-cores cases for RX timestamp offload, if packets arrive too fast, aq command to get phc time will be pended.
This patch adds spinlock to fix this issue. To avoid phc time being frequently overwritten, move related variables to iavf_rx_queue structure, and each queue will handle timestamp calculation by itself.
---
v3: remove restrictions on initialization.
v2: move duplicated spinlock initialization.
--- drivers/net/iavf/iavf.h | 5 ++-- drivers/net/iavf/iavf_ethdev.c | 11 ++----- drivers/net/iavf/iavf_rxtx.c | 55 ++++++++++++++++++++-------------- drivers/net/iavf/iavf_rxtx.h | 2 ++ drivers/net/iavf/iavf_vchnl.c | 15 ++++++---- 5 files changed, 47 insertions(+), 41 deletions(-)
drivers/net/iavf/iavf.h +2 -3
@@ -270,6 +270,7 @@ struct iavf_info {struct rte_eth_dev *eth_dev;uint32_t ptp_caps; +rte_spinlock_t phc_time_aq_lock; };#define IAVF_MAX_PKT_TYPE 1024
@@ -314,8 +315,6 @@ struct iavf_adapter {bool stopped;uint16_t fdir_ref_cnt;struct iavf_devargs devargs; -uint64_t phc_time; -uint64_t hw_time_update; };/* IAVF_DEV_PRIVATE_TO */
@@ -481,5 +480,5 @@ int iavf_ipsec_crypto_request(struct iavf_adapter *adapter, uint8_t *resp_msg, size_t resp_msg_len);extern const struct rte_tm_ops iavf_tm_ops;int iavf_get_ptp_cap (struct iavf_adapter *adapter); -int iavf_get_phc_time (struct iavf_adapter *adapter); +int iavf_get_phc_time (struct iavf_rx_queue *rxq);#endif /* _IAVF_ETHDEV_H_ */
drivers/net/iavf/iavf_ethdev.c +2 -9
@@ -1014,20 +1014,13 @@ iavf_dev_start(struct rte_eth_dev *dev)iavf_add_del_mc_addr_list (adapter, vf->mc_addrs, vf->mc_addrs_num, true); +rte_spinlock_init (&vf->phc_time_aq_lock); +if (iavf_start_queues (dev) !=0 ) {PMD_DRV_LOG (ERR ,"enable queues failed" ); goto err_mac; } -if (dev->data->dev_conf.rxmode.offloads & -RTE_ETH_RX_OFFLOAD_TIMESTAMP ) { -if (iavf_get_phc_time (adapter)) { -PMD_DRV_LOG (ERR ,"get physical time failed" ); - goto err_mac; - } - adapter->hw_time_update =rte_get_timer_cycles () / (rte_get_timer_hz () /1000 ); - } -return 0 ; err_mac:
drivers/net/iavf/iavf_rxtx.c +32 -23
126 lines not on this page · raw message
drivers/net/iavf/iavf_rxtx.h +2 -0
@@ -222,6 +222,8 @@ struct iavf_rx_queue {/* flexible descriptor metadata extraction offload flag */ struct iavf_rx_queue_stats stats;uint64_t offloads; +uint64_t phc_time; +uint64_t hw_time_update; };struct iavf_tx_entry {
drivers/net/iavf/iavf_vchnl.c +9 -6
@@ -1896,12 +1896,13 @@ iavf_get_ptp_cap(struct iavf_adapter *adapter) }int -iavf_get_phc_time (struct iavf_adapter *adapter) +iavf_get_phc_time (struct iavf_rx_queue *rxq) { +struct iavf_adapter *adapter = rxq->vsi->adapter;struct iavf_info *vf =IAVF_DEV_PRIVATE_TO_VF (adapter);struct virtchnl_phc_time phc_time;struct iavf_cmd_info args; -int err; +int err =0 ; args.ops =VIRTCHNL_OP_1588_PTP_GET_TIME ; args.in_args = (uint8_t *)&phc_time;
@@ -1909,14 +1910,16 @@ iavf_get_phc_time(struct iavf_adapter *adapter) args.out_buffer = vf->aq_resp; args.out_size =IAVF_AQ_BUF_SZ ; +rte_spinlock_lock (&vf->phc_time_aq_lock); err =iavf_execute_vf_cmd (adapter, &args,0 );if (err) {PMD_DRV_LOG (ERR ,"Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME" ); -return err; + goto out; } + rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time; - adapter->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time; - -return 0 ; +out: +rte_spinlock_unlock (&vf->phc_time_aq_lock); +return err; }
Signature · 1 line
2.25.1
PATCH v4 1/1 net/iavf: fix race condition for multi-cores
In reply to Wenjun WuIn multi-cores cases for RX timestamp offload, if packets arrive too fast, aq command to get phc time will be pended.
This patch adds spinlock to fix this issue. To avoid phc time being frequently overwritten, move related variables to iavf_rx_queue structure, and each queue will handle timestamp calculation by itself.
---
v4: rebase to the latest commit.
v3: remove restrictions on initialization.
v2: move duplicated spinlock initialization.
--- drivers/net/iavf/iavf.h | 5 ++-- drivers/net/iavf/iavf_ethdev.c | 11 ++----- drivers/net/iavf/iavf_rxtx.c | 55 ++++++++++++++++++++-------------- drivers/net/iavf/iavf_rxtx.h | 2 ++ drivers/net/iavf/iavf_vchnl.c | 15 ++++++---- 5 files changed, 47 insertions(+), 41 deletions(-)
drivers/net/iavf/iavf.h +2 -3
@@ -270,6 +270,7 @@ struct iavf_info {struct rte_eth_dev *eth_dev;uint32_t ptp_caps; +rte_spinlock_t phc_time_aq_lock; };#define IAVF_MAX_PKT_TYPE 1024
@@ -315,8 +316,6 @@ struct iavf_adapter {bool closed;uint16_t fdir_ref_cnt;struct iavf_devargs devargs; -uint64_t phc_time; -uint64_t hw_time_update; };/* IAVF_DEV_PRIVATE_TO */
@@ -482,5 +481,5 @@ int iavf_ipsec_crypto_request(struct iavf_adapter *adapter, uint8_t *resp_msg, size_t resp_msg_len);extern const struct rte_tm_ops iavf_tm_ops;int iavf_get_ptp_cap (struct iavf_adapter *adapter); -int iavf_get_phc_time (struct iavf_adapter *adapter); +int iavf_get_phc_time (struct iavf_rx_queue *rxq);#endif /* _IAVF_ETHDEV_H_ */
drivers/net/iavf/iavf_ethdev.c +2 -9
@@ -1039,20 +1039,13 @@ iavf_dev_start(struct rte_eth_dev *dev)iavf_add_del_mc_addr_list (adapter, vf->mc_addrs, vf->mc_addrs_num, true); +rte_spinlock_init (&vf->phc_time_aq_lock); +if (iavf_start_queues (dev) !=0 ) {PMD_DRV_LOG (ERR ,"enable queues failed" ); goto err_mac; } -if (dev->data->dev_conf.rxmode.offloads & -RTE_ETH_RX_OFFLOAD_TIMESTAMP ) { -if (iavf_get_phc_time (adapter)) { -PMD_DRV_LOG (ERR ,"get physical time failed" ); - goto err_mac; - } - adapter->hw_time_update =rte_get_timer_cycles () / (rte_get_timer_hz () /1000 ); - } -return 0 ; err_mac:
drivers/net/iavf/iavf_rxtx.c +32 -23
126 lines not on this page · raw message
drivers/net/iavf/iavf_rxtx.h +2 -0
@@ -223,6 +223,8 @@ struct iavf_rx_queue {/* flexible descriptor metadata extraction offload flag */ struct iavf_rx_queue_stats stats;uint64_t offloads; +uint64_t phc_time; +uint64_t hw_time_update; };struct iavf_tx_entry {
drivers/net/iavf/iavf_vchnl.c +9 -6
@@ -1913,12 +1913,13 @@ iavf_get_ptp_cap(struct iavf_adapter *adapter) }int -iavf_get_phc_time (struct iavf_adapter *adapter) +iavf_get_phc_time (struct iavf_rx_queue *rxq) { +struct iavf_adapter *adapter = rxq->vsi->adapter;struct iavf_info *vf =IAVF_DEV_PRIVATE_TO_VF (adapter);struct virtchnl_phc_time phc_time;struct iavf_cmd_info args; -int err; +int err =0 ; args.ops =VIRTCHNL_OP_1588_PTP_GET_TIME ; args.in_args = (uint8_t *)&phc_time;
@@ -1926,14 +1927,16 @@ iavf_get_phc_time(struct iavf_adapter *adapter) args.out_buffer = vf->aq_resp; args.out_size =IAVF_AQ_BUF_SZ ; +rte_spinlock_lock (&vf->phc_time_aq_lock); err =iavf_execute_vf_cmd (adapter, &args,0 );if (err) {PMD_DRV_LOG (ERR ,"Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME" ); -return err; + goto out; } + rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time; - adapter->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time; - -return 0 ; +out: +rte_spinlock_unlock (&vf->phc_time_aq_lock); +return err; }
Signature · 1 line
2.25.1
Quoted 18 lines
-----Original Message-----
From: Wu, Wenjun1 <[email protected]>
Sent: Monday, May 23, 2022 12:49 PM
To: [email protected]; Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>; Zhang, Qi Z <[email protected]>; Su, Simei <[email protected]>
Cc: [email protected]; Wu, Wenjun1 <[email protected]>
Subject: [PATCH v4] net/iavf: fix race condition for multi-coresIn multi-cores cases for RX timestamp offload, if packets arrive too fast, aq command to get phc time will be pended.
This patch adds spinlock to fix this issue. To avoid phc time being frequently overwritten, move related variables to
iavf_rx_queuestructure, and each queue will handle timestamp calculation by itself.
Quoted 5 lines
Fixes 2a0a62f40af5 ("net/iavf: enable Rx timestamp on Flex Descriptor")Fixes 33db16136e55 ("net/iavf: improve performance of Rx timestampoffload")
Signed-off-by Wenjun Wu <[email protected]>
Applied to dpdk-next-net-intel.
Thanks
Qi