@@ -222,14 +222,16 @@ static void zserv_write(struct thread *thread)
222222 struct stream * msg ;
223223 uint32_t wcmd = 0 ;
224224 struct stream_fifo * cache ;
225+ uint64_t time_now = monotime (NULL );
225226
226227 /* If we have any data pending, try to flush it first */
227228 switch (buffer_flush_all (client -> wb , client -> sock )) {
228229 case BUFFER_ERROR :
229230 goto zwrite_fail ;
230231 case BUFFER_PENDING :
231- atomic_store_explicit (& client -> last_write_time , monotime (NULL ),
232- memory_order_relaxed );
232+ frr_with_mutex (& client -> stats_mtx ) {
233+ client -> last_write_time = time_now ;
234+ }
233235 zserv_client_event (client , ZSERV_CLIENT_WRITE );
234236 return ;
235237 case BUFFER_EMPTY :
@@ -263,20 +265,19 @@ static void zserv_write(struct thread *thread)
263265 case BUFFER_ERROR :
264266 goto zwrite_fail ;
265267 case BUFFER_PENDING :
266- atomic_store_explicit (& client -> last_write_time , monotime (NULL ),
267- memory_order_relaxed );
268+ frr_with_mutex (& client -> stats_mtx ) {
269+ client -> last_write_time = time_now ;
270+ }
268271 zserv_client_event (client , ZSERV_CLIENT_WRITE );
269272 return ;
270273 case BUFFER_EMPTY :
271274 break ;
272275 }
273276
274- atomic_store_explicit (& client -> last_write_cmd , wcmd ,
275- memory_order_relaxed );
276-
277- atomic_store_explicit (& client -> last_write_time , monotime (NULL ),
278- memory_order_relaxed );
279-
277+ frr_with_mutex (& client -> stats_mtx ) {
278+ client -> last_write_cmd = wcmd ;
279+ client -> last_write_time = time_now ;
280+ }
280281 return ;
281282
282283zwrite_fail :
@@ -423,11 +424,13 @@ static void zserv_read(struct thread *thread)
423424 }
424425
425426 if (p2p < p2p_orig ) {
427+ uint64_t time_now = monotime (NULL );
428+
426429 /* update session statistics */
427- atomic_store_explicit (& client -> last_read_time , monotime ( NULL ),
428- memory_order_relaxed ) ;
429- atomic_store_explicit ( & client -> last_read_cmd , hdr .command ,
430- memory_order_relaxed );
430+ frr_with_mutex (& client -> stats_mtx ) {
431+ client -> last_read_time = time_now ;
432+ client -> last_read_cmd = hdr .command ;
433+ }
431434
432435 /* publish read packets on client's input queue */
433436 frr_with_mutex (& client -> ibuf_mtx ) {
@@ -621,6 +624,7 @@ static void zserv_client_free(struct zserv *client)
621624 buffer_free (client -> wb );
622625
623626 /* Free buffer mutexes */
627+ pthread_mutex_destroy (& client -> stats_mtx );
624628 pthread_mutex_destroy (& client -> obuf_mtx );
625629 pthread_mutex_destroy (& client -> ibuf_mtx );
626630
@@ -741,14 +745,13 @@ static struct zserv *zserv_client_create(int sock)
741745 client -> obuf_fifo = stream_fifo_new ();
742746 client -> ibuf_work = stream_new (stream_size );
743747 client -> obuf_work = stream_new (stream_size );
748+ client -> connect_time = monotime (NULL );
744749 pthread_mutex_init (& client -> ibuf_mtx , NULL );
745750 pthread_mutex_init (& client -> obuf_mtx , NULL );
751+ pthread_mutex_init (& client -> stats_mtx , NULL );
746752 client -> wb = buffer_new (0 );
747753 TAILQ_INIT (& (client -> gr_info_queue ));
748754
749- atomic_store_explicit (& client -> connect_time , monotime (NULL ),
750- memory_order_relaxed );
751-
752755 /* Initialize flags */
753756 for (afi = AFI_IP ; afi < AFI_MAX ; afi ++ ) {
754757 for (i = 0 ; i < ZEBRA_ROUTE_MAX ; i ++ )
@@ -1009,8 +1012,14 @@ static void zebra_show_client_detail(struct vty *vty, struct zserv *client)
10091012 vty_out (vty , "------------------------ \n" );
10101013 vty_out (vty , "FD: %d \n" , client -> sock );
10111014
1012- connect_time = (time_t ) atomic_load_explicit (& client -> connect_time ,
1013- memory_order_relaxed );
1015+ frr_with_mutex (& client -> stats_mtx ) {
1016+ connect_time = client -> connect_time ;
1017+ last_read_time = client -> last_read_time ;
1018+ last_write_time = client -> last_write_time ;
1019+
1020+ last_read_cmd = client -> last_read_cmd ;
1021+ last_write_cmd = client -> last_write_cmd ;
1022+ }
10141023
10151024 vty_out (vty , "Connect Time: %s \n" ,
10161025 zserv_time_buf (& connect_time , cbuf , ZEBRA_TIME_BUF ));
@@ -1030,16 +1039,6 @@ static void zebra_show_client_detail(struct vty *vty, struct zserv *client)
10301039 vty_out (vty , "Client will %sbe notified about it's routes status\n" ,
10311040 client -> notify_owner ? "" : "Not " );
10321041
1033- last_read_time = (time_t )atomic_load_explicit (& client -> last_read_time ,
1034- memory_order_relaxed );
1035- last_write_time = (time_t )atomic_load_explicit (& client -> last_write_time ,
1036- memory_order_relaxed );
1037-
1038- last_read_cmd = atomic_load_explicit (& client -> last_read_cmd ,
1039- memory_order_relaxed );
1040- last_write_cmd = atomic_load_explicit (& client -> last_write_cmd ,
1041- memory_order_relaxed );
1042-
10431042 vty_out (vty , "Last Msg Rx Time: %s \n" ,
10441043 zserv_time_buf (& last_read_time , rbuf , ZEBRA_TIME_BUF ));
10451044 vty_out (vty , "Last Msg Tx Time: %s \n" ,
@@ -1173,12 +1172,11 @@ static void zebra_show_client_brief(struct vty *vty, struct zserv *client)
11731172 char wbuf [ZEBRA_TIME_BUF ];
11741173 time_t connect_time , last_read_time , last_write_time ;
11751174
1176- connect_time = (time_t )atomic_load_explicit (& client -> connect_time ,
1177- memory_order_relaxed );
1178- last_read_time = (time_t )atomic_load_explicit (& client -> last_read_time ,
1179- memory_order_relaxed );
1180- last_write_time = (time_t )atomic_load_explicit (& client -> last_write_time ,
1181- memory_order_relaxed );
1175+ frr_with_mutex (& client -> stats_mtx ) {
1176+ connect_time = client -> connect_time ;
1177+ last_read_time = client -> last_read_time ;
1178+ last_write_time = client -> last_write_time ;
1179+ }
11821180
11831181 if (client -> instance || client -> session_id )
11841182 snprintfrr (client_string , sizeof (client_string ), "%s[%u:%u]" ,
0 commit comments