@@ -42,33 +42,36 @@ struct mlx5_hws_cnt_dcs_mng {
4242 struct mlx5_hws_cnt_dcs dcs [MLX5_HWS_CNT_DCS_NUM ];
4343};
4444
45- struct mlx5_hws_cnt {
46- struct flow_counter_stats reset ;
47- bool in_used ; /* Indicator whether this counter in used or in pool. */
48- union {
49- struct {
50- uint32_t share :1 ;
51- /*
52- * share will be set to 1 when this counter is used as
53- * indirect action.
54- */
55- uint32_t age_idx :24 ;
56- /*
57- * When this counter uses for aging, it save the index
58- * of AGE parameter. For pure counter (without aging)
59- * this index is zero.
60- */
61- };
62- /* This struct is only meaningful when user own this counter. */
63- uint32_t query_gen_when_free ;
45+ union mlx5_hws_cnt_state {
46+ uint32_t data ;
47+ struct {
48+ uint32_t in_used :1 ;
49+ /* Indicator whether this counter in used or in pool. */
50+ uint32_t share :1 ;
51+ /*
52+ * share will be set to 1 when this counter is used as
53+ * indirect action.
54+ */
55+ uint32_t age_idx :24 ;
6456 /*
65- * When PMD own this counter (user put back counter to PMD
66- * counter pool, i.e), this field recorded value of counter
67- * pools query generation at time user release the counter.
57+ * When this counter uses for aging, it stores the index
58+ * of AGE parameter. Otherwise, this index is zero.
6859 */
6960 };
7061};
7162
63+ struct mlx5_hws_cnt {
64+ struct flow_counter_stats reset ;
65+ union mlx5_hws_cnt_state cnt_state ;
66+ /* This struct is only meaningful when user own this counter. */
67+ uint32_t query_gen_when_free ;
68+ /*
69+ * When PMD own this counter (user put back counter to PMD
70+ * counter pool, i.e), this field recorded value of counter
71+ * pools query generation at time user release the counter.
72+ */
73+ };
74+
7275struct mlx5_hws_cnt_raw_data_mng {
7376 struct flow_counter_stats * raw ;
7477 struct mlx5_pmd_mr mr ;
@@ -179,6 +182,42 @@ mlx5_hws_cnt_id_valid(cnt_id_t cnt_id)
179182 MLX5_INDIRECT_ACTION_TYPE_COUNT ? true : false;
180183}
181184
185+ static __rte_always_inline void
186+ mlx5_hws_cnt_set_age_idx (struct mlx5_hws_cnt * cnt , uint32_t value )
187+ {
188+ union mlx5_hws_cnt_state cnt_state ;
189+
190+ cnt_state .data = __atomic_load_n (& cnt -> cnt_state .data , __ATOMIC_ACQUIRE );
191+ cnt_state .age_idx = value ;
192+ __atomic_store_n (& cnt -> cnt_state .data , cnt_state .data , __ATOMIC_RELEASE );
193+ }
194+
195+ static __rte_always_inline void
196+ mlx5_hws_cnt_set_all (struct mlx5_hws_cnt * cnt , uint32_t in_used , uint32_t share , uint32_t age_idx )
197+ {
198+ union mlx5_hws_cnt_state cnt_state ;
199+
200+ cnt_state .in_used = !!in_used ;
201+ cnt_state .share = !!share ;
202+ cnt_state .age_idx = age_idx ;
203+ __atomic_store_n (& cnt -> cnt_state .data , cnt_state .data , __ATOMIC_RELAXED );
204+ }
205+
206+ static __rte_always_inline void
207+ mlx5_hws_cnt_get_all (struct mlx5_hws_cnt * cnt , uint32_t * in_used , uint32_t * share ,
208+ uint32_t * age_idx )
209+ {
210+ union mlx5_hws_cnt_state cnt_state ;
211+
212+ cnt_state .data = __atomic_load_n (& cnt -> cnt_state .data , __ATOMIC_ACQUIRE );
213+ if (in_used != NULL )
214+ * in_used = cnt_state .in_used ;
215+ if (share != NULL )
216+ * share = cnt_state .share ;
217+ if (age_idx != NULL )
218+ * age_idx = cnt_state .age_idx ;
219+ }
220+
182221/**
183222 * Generate Counter id from internal index.
184223 *
@@ -402,8 +441,7 @@ mlx5_hws_cnt_pool_put(struct mlx5_hws_cnt_pool *cpool, uint32_t *queue,
402441 uint32_t iidx ;
403442
404443 iidx = mlx5_hws_cnt_iidx (cpool , * cnt_id );
405- MLX5_ASSERT (cpool -> pool [iidx ].in_used );
406- cpool -> pool [iidx ].in_used = false;
444+ mlx5_hws_cnt_set_all (& cpool -> pool [iidx ], 0 , 0 , 0 );
407445 cpool -> pool [iidx ].query_gen_when_free =
408446 __atomic_load_n (& cpool -> query_gen , __ATOMIC_RELAXED );
409447 if (likely (queue != NULL ))
@@ -459,7 +497,7 @@ mlx5_hws_cnt_pool_put(struct mlx5_hws_cnt_pool *cpool, uint32_t *queue,
459497 */
460498static __rte_always_inline int
461499mlx5_hws_cnt_pool_get (struct mlx5_hws_cnt_pool * cpool , uint32_t * queue ,
462- cnt_id_t * cnt_id , uint32_t age_idx )
500+ cnt_id_t * cnt_id , uint32_t age_idx , uint32_t shared )
463501{
464502 unsigned int ret ;
465503 struct rte_ring_zc_data zcdc = {0 };
@@ -486,9 +524,7 @@ mlx5_hws_cnt_pool_get(struct mlx5_hws_cnt_pool *cpool, uint32_t *queue,
486524 __hws_cnt_query_raw (cpool , * cnt_id ,
487525 & cpool -> pool [iidx ].reset .hits ,
488526 & cpool -> pool [iidx ].reset .bytes );
489- MLX5_ASSERT (!cpool -> pool [iidx ].in_used );
490- cpool -> pool [iidx ].in_used = true;
491- cpool -> pool [iidx ].age_idx = age_idx ;
527+ mlx5_hws_cnt_set_all (& cpool -> pool [iidx ], 1 , shared , age_idx );
492528 return 0 ;
493529 }
494530 ret = rte_ring_dequeue_zc_burst_elem_start (qcache , sizeof (cnt_id_t ), 1 ,
@@ -526,10 +562,7 @@ mlx5_hws_cnt_pool_get(struct mlx5_hws_cnt_pool *cpool, uint32_t *queue,
526562 __hws_cnt_query_raw (cpool , * cnt_id , & cpool -> pool [iidx ].reset .hits ,
527563 & cpool -> pool [iidx ].reset .bytes );
528564 rte_ring_dequeue_zc_elem_finish (qcache , 1 );
529- cpool -> pool [iidx ].share = 0 ;
530- MLX5_ASSERT (!cpool -> pool [iidx ].in_used );
531- cpool -> pool [iidx ].in_used = true;
532- cpool -> pool [iidx ].age_idx = age_idx ;
565+ mlx5_hws_cnt_set_all (& cpool -> pool [iidx ], 1 , shared , age_idx );
533566 return 0 ;
534567}
535568
@@ -582,32 +615,23 @@ static __rte_always_inline int
582615mlx5_hws_cnt_shared_get (struct mlx5_hws_cnt_pool * cpool , cnt_id_t * cnt_id ,
583616 uint32_t age_idx )
584617{
585- int ret ;
586- uint32_t iidx ;
587-
588- ret = mlx5_hws_cnt_pool_get (cpool , NULL , cnt_id , age_idx );
589- if (ret != 0 )
590- return ret ;
591- iidx = mlx5_hws_cnt_iidx (cpool , * cnt_id );
592- cpool -> pool [iidx ].share = 1 ;
593- return 0 ;
618+ return mlx5_hws_cnt_pool_get (cpool , NULL , cnt_id , age_idx , 1 );
594619}
595620
596621static __rte_always_inline void
597622mlx5_hws_cnt_shared_put (struct mlx5_hws_cnt_pool * cpool , cnt_id_t * cnt_id )
598623{
599- uint32_t iidx = mlx5_hws_cnt_iidx (cpool , * cnt_id );
600-
601- cpool -> pool [iidx ].share = 0 ;
602624 mlx5_hws_cnt_pool_put (cpool , NULL , cnt_id );
603625}
604626
605627static __rte_always_inline bool
606628mlx5_hws_cnt_is_shared (struct mlx5_hws_cnt_pool * cpool , cnt_id_t cnt_id )
607629{
608630 uint32_t iidx = mlx5_hws_cnt_iidx (cpool , cnt_id );
631+ uint32_t share ;
609632
610- return cpool -> pool [iidx ].share ? true : false;
633+ mlx5_hws_cnt_get_all (& cpool -> pool [iidx ], NULL , & share , NULL );
634+ return !!share ;
611635}
612636
613637static __rte_always_inline void
@@ -616,17 +640,19 @@ mlx5_hws_cnt_age_set(struct mlx5_hws_cnt_pool *cpool, cnt_id_t cnt_id,
616640{
617641 uint32_t iidx = mlx5_hws_cnt_iidx (cpool , cnt_id );
618642
619- MLX5_ASSERT (cpool -> pool [iidx ].share );
620- cpool -> pool [iidx ]. age_idx = age_idx ;
643+ MLX5_ASSERT (cpool -> pool [iidx ].cnt_state . share );
644+ mlx5_hws_cnt_set_age_idx ( & cpool -> pool [iidx ], age_idx ) ;
621645}
622646
623647static __rte_always_inline uint32_t
624648mlx5_hws_cnt_age_get (struct mlx5_hws_cnt_pool * cpool , cnt_id_t cnt_id )
625649{
626650 uint32_t iidx = mlx5_hws_cnt_iidx (cpool , cnt_id );
651+ uint32_t age_idx , share ;
627652
628- MLX5_ASSERT (cpool -> pool [iidx ].share );
629- return cpool -> pool [iidx ].age_idx ;
653+ mlx5_hws_cnt_get_all (& cpool -> pool [iidx ], NULL , & share , & age_idx );
654+ MLX5_ASSERT (share );
655+ return age_idx ;
630656}
631657
632658static __rte_always_inline cnt_id_t
0 commit comments