]> git.droids-corp.org - dpdk.git/commitdiff
net/ice: fix race condition in Rx timestamp
authorSimei Su <simei.su@intel.com>
Wed, 8 Jun 2022 02:46:01 +0000 (10:46 +0800)
committerQi Zhang <qi.z.zhang@intel.com>
Thu, 23 Jun 2022 05:49:38 +0000 (07:49 +0200)
In multi-cores cases for Rx timestamp offload, to avoid phc time being
frequently overwritten, move related variables from ice_adapter to
ice_rx_queue structure, and each queue will handle timestamp calculation
by itself.

Fixes: 953e74e6b73a ("net/ice: enable Rx timestamp on flex descriptor")
Fixes: 5543827fc6df ("net/ice: improve performance of Rx timestamp offload")
Cc: stable@dpdk.org
Signed-off-by: Simei Su <simei.su@intel.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
drivers/net/ice/ice_ethdev.h
drivers/net/ice/ice_rxtx.c
drivers/net/ice/ice_rxtx.h

index f9f4a1c71b1f6499f9675179c0c5e4c24c051f4f..c257bb23d39ef4040c1d224d601f6f3c0a42202e 100644 (file)
@@ -606,9 +606,6 @@ struct ice_adapter {
        struct rte_timecounter tx_tstamp_tc;
        bool ptp_ena;
        uint64_t time_hw;
-       uint32_t hw_time_high; /* high 32 bits of timestamp */
-       uint32_t hw_time_low; /* low 32 bits of timestamp */
-       uint64_t hw_time_update; /* SW time of HW record updating */
        struct ice_fdir_prof_info fdir_prof_info[ICE_MAX_PTGS];
        struct ice_rss_prof_info rss_prof_info[ICE_MAX_PTGS];
        /* True if DCF state of the associated PF is on */
index 975ab5574998c7f48918fafb620b170f83949d3e..bfb3a16ae222e7435699b261cba1f9ad16a4b3cd 100644 (file)
@@ -1595,7 +1595,7 @@ ice_rx_scan_hw_ring(struct ice_rx_queue *rxq)
        if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
                uint64_t sw_cur_time = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
 
-               if (unlikely(sw_cur_time - ad->hw_time_update > 4))
+               if (unlikely(sw_cur_time - rxq->hw_time_update > 4))
                        is_tsinit = 1;
        }
 #endif
@@ -1639,16 +1639,16 @@ ice_rx_scan_hw_ring(struct ice_rx_queue *rxq)
                                if (unlikely(is_tsinit)) {
                                        ts_ns = ice_tstamp_convert_32b_64b(hw, ad, 1,
                                                                           rxq->time_high);
-                                       ad->hw_time_low = (uint32_t)ts_ns;
-                                       ad->hw_time_high = (uint32_t)(ts_ns >> 32);
+                                       rxq->hw_time_low = (uint32_t)ts_ns;
+                                       rxq->hw_time_high = (uint32_t)(ts_ns >> 32);
                                        is_tsinit = false;
                                } else {
-                                       if (rxq->time_high < ad->hw_time_low)
-                                               ad->hw_time_high += 1;
-                                       ts_ns = (uint64_t)ad->hw_time_high << 32 | rxq->time_high;
-                                       ad->hw_time_low = rxq->time_high;
+                                       if (rxq->time_high < rxq->hw_time_low)
+                                               rxq->hw_time_high += 1;
+                                       ts_ns = (uint64_t)rxq->hw_time_high << 32 | rxq->time_high;
+                                       rxq->hw_time_low = rxq->time_high;
                                }
-                               ad->hw_time_update = rte_get_timer_cycles() /
+                               rxq->hw_time_update = rte_get_timer_cycles() /
                                                     (rte_get_timer_hz() / 1000);
                                *RTE_MBUF_DYNFIELD(mb,
                                                   ice_timestamp_dynfield_offset,
@@ -1861,7 +1861,7 @@ ice_recv_scattered_pkts(void *rx_queue,
        if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
                uint64_t sw_cur_time = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
 
-               if (unlikely(sw_cur_time - ad->hw_time_update > 4))
+               if (unlikely(sw_cur_time - rxq->hw_time_update > 4))
                        is_tsinit = true;
        }
 #endif
@@ -1981,16 +1981,16 @@ ice_recv_scattered_pkts(void *rx_queue,
                           rte_le_to_cpu_32(rxd.wb.flex_ts.ts_high);
                        if (unlikely(is_tsinit)) {
                                ts_ns = ice_tstamp_convert_32b_64b(hw, ad, 1, rxq->time_high);
-                               ad->hw_time_low = (uint32_t)ts_ns;
-                               ad->hw_time_high = (uint32_t)(ts_ns >> 32);
+                               rxq->hw_time_low = (uint32_t)ts_ns;
+                               rxq->hw_time_high = (uint32_t)(ts_ns >> 32);
                                is_tsinit = false;
                        } else {
-                               if (rxq->time_high < ad->hw_time_low)
-                                       ad->hw_time_high += 1;
-                               ts_ns = (uint64_t)ad->hw_time_high << 32 | rxq->time_high;
-                               ad->hw_time_low = rxq->time_high;
+                               if (rxq->time_high < rxq->hw_time_low)
+                                       rxq->hw_time_high += 1;
+                               ts_ns = (uint64_t)rxq->hw_time_high << 32 | rxq->time_high;
+                               rxq->hw_time_low = rxq->time_high;
                        }
-                       ad->hw_time_update = rte_get_timer_cycles() /
+                       rxq->hw_time_update = rte_get_timer_cycles() /
                                             (rte_get_timer_hz() / 1000);
                        *RTE_MBUF_DYNFIELD(rxm,
                                           (ice_timestamp_dynfield_offset),
@@ -2371,7 +2371,7 @@ ice_recv_pkts(void *rx_queue,
        if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
                uint64_t sw_cur_time = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
 
-               if (unlikely(sw_cur_time - ad->hw_time_update > 4))
+               if (unlikely(sw_cur_time - rxq->hw_time_update > 4))
                        is_tsinit = 1;
        }
 #endif
@@ -2432,16 +2432,16 @@ ice_recv_pkts(void *rx_queue,
                           rte_le_to_cpu_32(rxd.wb.flex_ts.ts_high);
                        if (unlikely(is_tsinit)) {
                                ts_ns = ice_tstamp_convert_32b_64b(hw, ad, 1, rxq->time_high);
-                               ad->hw_time_low = (uint32_t)ts_ns;
-                               ad->hw_time_high = (uint32_t)(ts_ns >> 32);
+                               rxq->hw_time_low = (uint32_t)ts_ns;
+                               rxq->hw_time_high = (uint32_t)(ts_ns >> 32);
                                is_tsinit = false;
                        } else {
-                               if (rxq->time_high < ad->hw_time_low)
-                                       ad->hw_time_high += 1;
-                               ts_ns = (uint64_t)ad->hw_time_high << 32 | rxq->time_high;
-                               ad->hw_time_low = rxq->time_high;
+                               if (rxq->time_high < rxq->hw_time_low)
+                                       rxq->hw_time_high += 1;
+                               ts_ns = (uint64_t)rxq->hw_time_high << 32 | rxq->time_high;
+                               rxq->hw_time_low = rxq->time_high;
                        }
-                       ad->hw_time_update = rte_get_timer_cycles() /
+                       rxq->hw_time_update = rte_get_timer_cycles() /
                                             (rte_get_timer_hz() / 1000);
                        *RTE_MBUF_DYNFIELD(rxm,
                                           (ice_timestamp_dynfield_offset),
index bb18a0195149105b5362c3b5e206676b22fc39ea..f5337d52846936eb9feb32d4eabda3e1e53feea9 100644 (file)
@@ -95,6 +95,9 @@ struct ice_rx_queue {
        uint32_t time_high;
        uint32_t hw_register_set;
        const struct rte_memzone *mz;
+       uint32_t hw_time_high; /* high 32 bits of timestamp */
+       uint32_t hw_time_low; /* low 32 bits of timestamp */
+       uint64_t hw_time_update; /* SW time of HW record updating */
 };
 
 struct ice_tx_entry {