@@ -136,8 +136,6 @@ struct fpm_nl_ctx {
136136
137137 /* Amount of data plane context processed. */
138138 _Atomic uint32_t dplane_contexts ;
139- /* Amount of data plane contexts enqueued. */
140- _Atomic uint32_t ctxqueue_len ;
141139 /* Peak amount of data plane contexts enqueued. */
142140 _Atomic uint32_t ctxqueue_len_peak ;
143141
@@ -399,6 +397,12 @@ DEFUN(fpm_show_counters, fpm_show_counters_cmd,
399397 FPM_STR
400398 "FPM statistic counters\n" )
401399{
400+ uint32_t curr_queue_len ;
401+
402+ frr_with_mutex (& gfnc -> ctxqueue_mutex ) {
403+ curr_queue_len = dplane_ctx_queue_count (& gfnc -> ctxqueue );
404+ }
405+
402406 vty_out (vty , "%30s\n%30s\n" , "FPM counters" , "============" );
403407
404408#define SHOW_COUNTER (label , counter ) \
@@ -412,8 +416,7 @@ DEFUN(fpm_show_counters, fpm_show_counters_cmd,
412416 SHOW_COUNTER ("Connection errors" , gfnc -> counters .connection_errors );
413417 SHOW_COUNTER ("Data plane items processed" ,
414418 gfnc -> counters .dplane_contexts );
415- SHOW_COUNTER ("Data plane items enqueued" ,
416- gfnc -> counters .ctxqueue_len );
419+ SHOW_COUNTER ("Data plane items enqueued" , curr_queue_len );
417420 SHOW_COUNTER ("Data plane items queue peak" ,
418421 gfnc -> counters .ctxqueue_len_peak );
419422 SHOW_COUNTER ("Buffer full hits" , gfnc -> counters .buffer_full );
@@ -432,6 +435,12 @@ DEFUN(fpm_show_counters_json, fpm_show_counters_json_cmd,
432435 "FPM statistic counters\n"
433436 JSON_STR )
434437{
438+ uint32_t curr_queue_len ;
439+
440+ frr_with_mutex (& gfnc -> ctxqueue_mutex ) {
441+ curr_queue_len = dplane_ctx_queue_count (& gfnc -> ctxqueue );
442+ }
443+
435444 struct json_object * jo ;
436445
437446 jo = json_object_new_object ();
@@ -445,8 +454,7 @@ DEFUN(fpm_show_counters_json, fpm_show_counters_json_cmd,
445454 gfnc -> counters .connection_errors );
446455 json_object_int_add (jo , "data-plane-contexts" ,
447456 gfnc -> counters .dplane_contexts );
448- json_object_int_add (jo , "data-plane-contexts-queue" ,
449- gfnc -> counters .ctxqueue_len );
457+ json_object_int_add (jo , "data-plane-contexts-queue" , curr_queue_len );
450458 json_object_int_add (jo , "data-plane-contexts-queue-peak" ,
451459 gfnc -> counters .ctxqueue_len_peak );
452460 json_object_int_add (jo , "buffer-full-hits" , gfnc -> counters .buffer_full );
@@ -1495,8 +1503,6 @@ static void fpm_process_queue(struct event *t)
14951503
14961504 /* Account the processed entries. */
14971505 processed_contexts ++ ;
1498- atomic_fetch_sub_explicit (& fnc -> counters .ctxqueue_len , 1 ,
1499- memory_order_relaxed );
15001506
15011507 dplane_ctx_set_status (ctx , ZEBRA_DPLANE_REQUEST_SUCCESS );
15021508 dplane_provider_enqueue_out_ctx (fnc -> prov , ctx );
@@ -1670,7 +1676,7 @@ static int fpm_nl_process(struct zebra_dplane_provider *prov)
16701676 struct zebra_dplane_ctx * ctx ;
16711677 struct fpm_nl_ctx * fnc ;
16721678 int counter , limit ;
1673- uint64_t cur_queue , peak_queue = 0 , stored_peak_queue ;
1679+ uint64_t cur_queue = 0 , peak_queue = 0 , stored_peak_queue ;
16741680
16751681 fnc = dplane_provider_get_data (prov );
16761682 limit = dplane_provider_get_work_limit (prov );
@@ -1684,20 +1690,12 @@ static int fpm_nl_process(struct zebra_dplane_provider *prov)
16841690 * anyway.
16851691 */
16861692 if (fnc -> socket != -1 && fnc -> connecting == false) {
1687- /*
1688- * Update the number of queued contexts *before*
1689- * enqueueing, to ensure counter consistency.
1690- */
1691- atomic_fetch_add_explicit (& fnc -> counters .ctxqueue_len ,
1692- 1 , memory_order_relaxed );
1693-
16941693 frr_with_mutex (& fnc -> ctxqueue_mutex ) {
16951694 dplane_ctx_enqueue_tail (& fnc -> ctxqueue , ctx );
1695+ cur_queue =
1696+ dplane_ctx_queue_count (& fnc -> ctxqueue );
16961697 }
16971698
1698- cur_queue = atomic_load_explicit (
1699- & fnc -> counters .ctxqueue_len ,
1700- memory_order_relaxed );
17011699 if (peak_queue < cur_queue )
17021700 peak_queue = cur_queue ;
17031701 continue ;
@@ -1714,9 +1712,7 @@ static int fpm_nl_process(struct zebra_dplane_provider *prov)
17141712 atomic_store_explicit (& fnc -> counters .ctxqueue_len_peak ,
17151713 peak_queue , memory_order_relaxed );
17161714
1717- if (atomic_load_explicit (& fnc -> counters .ctxqueue_len ,
1718- memory_order_relaxed )
1719- > 0 )
1715+ if (cur_queue > 0 )
17201716 event_add_event (fnc -> fthread -> master , fpm_process_queue , fnc , 0 ,
17211717 & fnc -> t_dequeue );
17221718
0 commit comments