blob: 43007ad76ed293d7e3231a6b3d7122e765c06f75 [file] [log] [blame]
Florin Coras623eb562019-02-03 19:28:34 -08001/*
2 * Copyright (c) 2019 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include <vnet/session/application.h>
17#include <vnet/session/application_interface.h>
Florin Coras54a51fd2019-02-07 15:34:52 -080018#include <vnet/session/session.h>
Florin Coras623eb562019-02-03 19:28:34 -080019
20/**
21 * Pool of workers associated to apps
22 */
23static app_worker_t *app_workers;
24
Florin Coras623eb562019-02-03 19:28:34 -080025app_worker_t *
26app_worker_alloc (application_t * app)
27{
28 app_worker_t *app_wrk;
Florin Coras0242d302022-12-22 15:03:44 -080029
Florin Coras623eb562019-02-03 19:28:34 -080030 pool_get (app_workers, app_wrk);
31 clib_memset (app_wrk, 0, sizeof (*app_wrk));
32 app_wrk->wrk_index = app_wrk - app_workers;
33 app_wrk->app_index = app->app_index;
34 app_wrk->wrk_map_index = ~0;
35 app_wrk->connects_seg_manager = APP_INVALID_SEGMENT_MANAGER_INDEX;
Florin Corasc8e812f2020-05-14 05:32:18 +000036 clib_spinlock_init (&app_wrk->detached_seg_managers_lock);
Florin Coras0242d302022-12-22 15:03:44 -080037 vec_validate (app_wrk->wrk_evts, vlib_num_workers ());
38 vec_validate (app_wrk->wrk_mq_congested, vlib_num_workers ());
Nathan Skrzypczakba65ca42019-05-16 16:35:40 +020039 APP_DBG ("New app %v worker %u", app->name, app_wrk->wrk_index);
Florin Coras623eb562019-02-03 19:28:34 -080040 return app_wrk;
41}
42
43app_worker_t *
44app_worker_get (u32 wrk_index)
45{
46 return pool_elt_at_index (app_workers, wrk_index);
47}
48
49app_worker_t *
50app_worker_get_if_valid (u32 wrk_index)
51{
52 if (pool_is_free_index (app_workers, wrk_index))
53 return 0;
54 return pool_elt_at_index (app_workers, wrk_index);
55}
56
57void
58app_worker_free (app_worker_t * app_wrk)
59{
60 application_t *app = application_get (app_wrk->app_index);
Florin Coras980ee742023-08-04 16:14:01 -070061 session_handle_t handle, *handles = 0, *sh;
Florin Corasc1a42652019-02-08 18:27:29 -080062 vnet_unlisten_args_t _a, *a = &_a;
Florin Coras623eb562019-02-03 19:28:34 -080063 segment_manager_t *sm;
Florin Coras980ee742023-08-04 16:14:01 -070064 u64 *sm_indices = 0;
Florin Coras87d66332019-06-11 12:31:31 -070065 session_t *ls;
Florin Coras623eb562019-02-03 19:28:34 -080066 u32 sm_index;
Florin Corasea727642021-05-07 19:39:43 -070067 int i;
Florin Coras623eb562019-02-03 19:28:34 -080068
69 /*
Florin Coras0242d302022-12-22 15:03:44 -080070 * Cleanup vpp wrk events
71 */
72 app_worker_del_all_events (app_wrk);
73 for (i = 0; i < vec_len (app_wrk->wrk_evts); i++)
74 clib_fifo_free (app_wrk->wrk_evts[i]);
75
76 vec_free (app_wrk->wrk_evts);
77 vec_free (app_wrk->wrk_mq_congested);
78
79 /*
Florin Coras623eb562019-02-03 19:28:34 -080080 * Listener cleanup
81 */
82
Florin Corasc9940fc2019-02-05 20:55:11 -080083 hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
84 ls = listen_session_get_from_handle (handle);
Florin Coras87d66332019-06-11 12:31:31 -070085 vec_add1 (handles, app_listen_session_handle (ls));
Florin Corasbf395972020-04-30 15:05:24 +000086 vec_add1 (sm_indices, sm_index);
Florin Coras623eb562019-02-03 19:28:34 -080087 sm = segment_manager_get (sm_index);
Florin Coras623eb562019-02-03 19:28:34 -080088 }));
Florin Coras623eb562019-02-03 19:28:34 -080089
90 for (i = 0; i < vec_len (handles); i++)
91 {
Florin Corasbf395972020-04-30 15:05:24 +000092 /* Cleanup listener */
Florin Coras623eb562019-02-03 19:28:34 -080093 a->app_index = app->app_index;
94 a->wrk_map_index = app_wrk->wrk_map_index;
95 a->handle = handles[i];
Florin Corasc1a42652019-02-08 18:27:29 -080096 (void) vnet_unlisten (a);
Florin Corasbf395972020-04-30 15:05:24 +000097
98 sm = segment_manager_get_if_valid (sm_indices[i]);
99 if (sm && !segment_manager_app_detached (sm))
100 {
101 sm->first_is_protected = 0;
102 segment_manager_init_free (sm);
103 }
Florin Coras623eb562019-02-03 19:28:34 -0800104 }
Florin Corased4e6122024-01-12 13:10:17 -0500105 vec_free (handles);
Florin Corasbf395972020-04-30 15:05:24 +0000106 vec_free (sm_indices);
107 hash_free (app_wrk->listeners_table);
Florin Coras623eb562019-02-03 19:28:34 -0800108
109 /*
110 * Connects segment manager cleanup
111 */
112
113 if (app_wrk->connects_seg_manager != APP_INVALID_SEGMENT_MANAGER_INDEX)
114 {
115 sm = segment_manager_get (app_wrk->connects_seg_manager);
116 sm->app_wrk_index = SEGMENT_MANAGER_INVALID_APP_INDEX;
Florin Coras565115e2019-02-20 19:48:31 -0800117 sm->first_is_protected = 0;
Florin Coras88001c62019-04-24 14:44:46 -0700118 segment_manager_init_free (sm);
Florin Coras623eb562019-02-03 19:28:34 -0800119 }
120
Florin Corasd50ff7f2020-04-16 04:30:22 +0000121 /*
122 * Half-open cleanup
123 */
124
Florin Corasea727642021-05-07 19:39:43 -0700125 pool_foreach (sh, app_wrk->half_open_table)
126 session_cleanup_half_open (*sh);
Florin Corasd50ff7f2020-04-16 04:30:22 +0000127
Florin Corasea727642021-05-07 19:39:43 -0700128 pool_free (app_wrk->half_open_table);
Florin Corasd50ff7f2020-04-16 04:30:22 +0000129
Florin Corasc8e812f2020-05-14 05:32:18 +0000130 /*
131 * Detached listener segment managers cleanup
132 */
133 for (i = 0; i < vec_len (app_wrk->detached_seg_managers); i++)
134 {
135 sm = segment_manager_get (app_wrk->detached_seg_managers[i]);
136 segment_manager_init_free (sm);
137 }
138 vec_free (app_wrk->detached_seg_managers);
139 clib_spinlock_free (&app_wrk->detached_seg_managers_lock);
140
Florin Coras623eb562019-02-03 19:28:34 -0800141 if (CLIB_DEBUG)
142 clib_memset (app_wrk, 0xfe, sizeof (*app_wrk));
Benoît Ganned4aeb842019-07-18 18:38:42 +0200143 pool_put (app_workers, app_wrk);
Florin Coras623eb562019-02-03 19:28:34 -0800144}
145
146application_t *
147app_worker_get_app (u32 wrk_index)
148{
149 app_worker_t *app_wrk;
150 app_wrk = app_worker_get_if_valid (wrk_index);
151 if (!app_wrk)
152 return 0;
153 return application_get_if_valid (app_wrk->app_index);
154}
155
156static segment_manager_t *
157app_worker_alloc_segment_manager (app_worker_t * app_wrk)
158{
Florin Coras94a6df02021-05-06 15:32:14 -0700159 segment_manager_t *sm;
Florin Coras623eb562019-02-03 19:28:34 -0800160
Florin Coras94a6df02021-05-06 15:32:14 -0700161 sm = segment_manager_alloc ();
Florin Coras623eb562019-02-03 19:28:34 -0800162 sm->app_wrk_index = app_wrk->wrk_index;
Florin Corasa107f402020-09-29 19:18:46 -0700163 segment_manager_init (sm);
Florin Coras623eb562019-02-03 19:28:34 -0800164 return sm;
165}
166
Florin Corasa27a46e2019-02-18 13:02:28 -0800167static int
168app_worker_alloc_session_fifos (segment_manager_t * sm, session_t * s)
169{
170 svm_fifo_t *rx_fifo = 0, *tx_fifo = 0;
Florin Corasa27a46e2019-02-18 13:02:28 -0800171 int rv;
172
Florin Coras62ddc032019-12-08 18:30:42 -0800173 if ((rv = segment_manager_alloc_session_fifos (sm, s->thread_index,
174 &rx_fifo, &tx_fifo)))
Florin Corasa27a46e2019-02-18 13:02:28 -0800175 return rv;
176
Florin Corasc547e912020-12-08 17:50:45 -0800177 rx_fifo->shr->master_session_index = s->session_index;
Florin Corasa27a46e2019-02-18 13:02:28 -0800178 rx_fifo->master_thread_index = s->thread_index;
179
Florin Corasc547e912020-12-08 17:50:45 -0800180 tx_fifo->shr->master_session_index = s->session_index;
Florin Corasa27a46e2019-02-18 13:02:28 -0800181 tx_fifo->master_thread_index = s->thread_index;
182
183 s->rx_fifo = rx_fifo;
184 s->tx_fifo = tx_fifo;
Florin Corasa27a46e2019-02-18 13:02:28 -0800185 return 0;
186}
187
Florin Coras623eb562019-02-03 19:28:34 -0800188int
Florin Coras7428eaa2023-12-11 16:04:57 -0800189app_worker_alloc_wrk_cl_session (app_worker_t *app_wrk, session_t *ls)
190{
191 svm_fifo_t *rx_fifo = 0, *tx_fifo = 0;
192 segment_manager_t *sm;
193 session_handle_t lsh;
194 app_listener_t *al;
195 session_t *s;
196
Florin Coras97fef282023-12-21 19:41:12 -0800197 al = app_listener_get (ls->al_index);
Florin Coras7428eaa2023-12-11 16:04:57 -0800198 sm = app_worker_get_listen_segment_manager (app_wrk, ls);
199 lsh = session_handle (ls);
200
201 s = session_alloc (0 /* listener on main worker */);
202 session_set_state (s, SESSION_STATE_LISTENING);
203 s->flags |= SESSION_F_IS_CLESS;
204 s->app_wrk_index = app_wrk->wrk_index;
205 ls = session_get_from_handle (lsh);
206 s->session_type = ls->session_type;
207 s->connection_index = ls->connection_index;
208
209 segment_manager_alloc_session_fifos (sm, s->thread_index, &rx_fifo,
210 &tx_fifo);
211
212 rx_fifo->shr->master_session_index = s->session_index;
213 rx_fifo->master_thread_index = s->thread_index;
214
215 tx_fifo->shr->master_session_index = s->session_index;
216 tx_fifo->master_thread_index = s->thread_index;
217
218 s->rx_fifo = rx_fifo;
219 s->tx_fifo = tx_fifo;
220
221 vec_validate (al->cl_listeners, app_wrk->wrk_map_index);
222 al->cl_listeners[app_wrk->wrk_map_index] = s->session_index;
223
224 return 0;
225}
226
227void
228app_worker_free_wrk_cl_session (app_worker_t *app_wrk, session_t *ls)
229{
230 app_listener_t *al;
231 session_t *s;
232
Florin Coras97fef282023-12-21 19:41:12 -0800233 al = app_listener_get (ls->al_index);
Florin Coras7428eaa2023-12-11 16:04:57 -0800234
235 s = app_listener_get_wrk_cl_session (al, app_wrk->wrk_map_index);
236 segment_manager_dealloc_fifos (s->rx_fifo, s->tx_fifo);
237 session_free (s);
238
239 al->cl_listeners[app_wrk->wrk_map_index] = SESSION_INVALID_INDEX;
240}
241
242int
Florin Corasd4295e62019-02-22 13:11:38 -0800243app_worker_init_listener (app_worker_t * app_wrk, session_t * ls)
Florin Coras623eb562019-02-03 19:28:34 -0800244{
245 segment_manager_t *sm;
246
247 /* Allocate segment manager. All sessions derived out of a listen session
Florin Coras7428eaa2023-12-11 16:04:57 -0800248 * have fifos allocated by the same segment manager.
249 * TODO(fcoras): limit memory consumption by cless listeners */
Florin Coras623eb562019-02-03 19:28:34 -0800250 if (!(sm = app_worker_alloc_segment_manager (app_wrk)))
Florin Coras00e01d32019-10-21 16:07:46 -0700251 return SESSION_E_ALLOC;
Florin Coras623eb562019-02-03 19:28:34 -0800252
Florin Coras1a4aaf12021-11-27 10:30:03 -0800253 /* Once the first segment is mapped, don't remove it until unlisten */
254 sm->first_is_protected = 1;
255
Florin Corasc9940fc2019-02-05 20:55:11 -0800256 /* Keep track of the segment manager for the listener or this worker */
Florin Coras623eb562019-02-03 19:28:34 -0800257 hash_set (app_wrk->listeners_table, listen_session_get_handle (ls),
258 segment_manager_index (sm));
259
Florin Coras7428eaa2023-12-11 16:04:57 -0800260 if (ls->flags & SESSION_F_IS_CLESS)
261 return app_worker_alloc_wrk_cl_session (app_wrk, ls);
262
Florin Coras623eb562019-02-03 19:28:34 -0800263 return 0;
264}
265
Filip Tehlar0028e6f2023-06-28 10:47:32 +0200266session_error_t
267app_worker_start_listen (app_worker_t *app_wrk, app_listener_t *app_listener)
Florin Corasd4295e62019-02-22 13:11:38 -0800268{
269 session_t *ls;
Florin Coras00e01d32019-10-21 16:07:46 -0700270 int rv;
Florin Corasd4295e62019-02-22 13:11:38 -0800271
272 if (clib_bitmap_get (app_listener->workers, app_wrk->wrk_map_index))
Florin Coras00e01d32019-10-21 16:07:46 -0700273 return SESSION_E_ALREADY_LISTENING;
Florin Corasd4295e62019-02-22 13:11:38 -0800274
275 app_listener->workers = clib_bitmap_set (app_listener->workers,
276 app_wrk->wrk_map_index, 1);
277
278 if (app_listener->session_index != SESSION_INVALID_INDEX)
279 {
280 ls = session_get (app_listener->session_index, 0);
Florin Coras00e01d32019-10-21 16:07:46 -0700281 if ((rv = app_worker_init_listener (app_wrk, ls)))
282 return rv;
Florin Corasd4295e62019-02-22 13:11:38 -0800283 }
284
285 if (app_listener->local_index != SESSION_INVALID_INDEX)
286 {
287 ls = session_get (app_listener->local_index, 0);
Florin Coras00e01d32019-10-21 16:07:46 -0700288 if ((rv = app_worker_init_listener (app_wrk, ls)))
289 return rv;
Florin Corasd4295e62019-02-22 13:11:38 -0800290 }
291
292 return 0;
293}
294
Florin Coras2b81e3c2019-02-27 07:55:46 -0800295static void
Florin Corasc8e812f2020-05-14 05:32:18 +0000296app_worker_add_detached_sm (app_worker_t * app_wrk, u32 sm_index)
297{
298 vec_add1 (app_wrk->detached_seg_managers, sm_index);
299}
300
301void
302app_worker_del_detached_sm (app_worker_t * app_wrk, u32 sm_index)
303{
304 u32 i;
305
306 clib_spinlock_lock (&app_wrk->detached_seg_managers_lock);
307 for (i = 0; i < vec_len (app_wrk->detached_seg_managers); i++)
308 {
309 if (app_wrk->detached_seg_managers[i] == sm_index)
310 {
311 vec_del1 (app_wrk->detached_seg_managers, i);
312 break;
313 }
314 }
315 clib_spinlock_unlock (&app_wrk->detached_seg_managers_lock);
316}
317
318static void
Florin Coras2b81e3c2019-02-27 07:55:46 -0800319app_worker_stop_listen_session (app_worker_t * app_wrk, session_t * ls)
Florin Coras623eb562019-02-03 19:28:34 -0800320{
Florin Corasc9940fc2019-02-05 20:55:11 -0800321 session_handle_t handle;
Florin Coras623eb562019-02-03 19:28:34 -0800322 segment_manager_t *sm;
323 uword *sm_indexp;
liuyacan87d48ad2021-04-28 11:34:03 +0000324 session_state_t *states = 0;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800325
326 handle = listen_session_get_handle (ls);
327 sm_indexp = hash_get (app_wrk->listeners_table, handle);
328 if (PREDICT_FALSE (!sm_indexp))
329 return;
330
Florin Coras7428eaa2023-12-11 16:04:57 -0800331 if (ls->flags & SESSION_F_IS_CLESS)
332 app_worker_free_wrk_cl_session (app_wrk, ls);
Florin Coras87b7e3d2020-03-27 15:06:07 +0000333
Florin Coras1bd46162020-04-13 23:35:55 +0000334 /* Try to cleanup segment manager */
Florin Coras2b81e3c2019-02-27 07:55:46 -0800335 sm = segment_manager_get (*sm_indexp);
Florin Coras94a6df02021-05-06 15:32:14 -0700336 if (sm)
Florin Coras2b81e3c2019-02-27 07:55:46 -0800337 {
Florin Coras1a4aaf12021-11-27 10:30:03 -0800338 sm->first_is_protected = 0;
Florin Coras1bd46162020-04-13 23:35:55 +0000339 segment_manager_app_detach (sm);
340 if (!segment_manager_has_fifos (sm))
Florin Coras94a6df02021-05-06 15:32:14 -0700341 {
342 /* Empty segment manager, cleanup it up */
343 segment_manager_free (sm);
344 }
Florin Corasc8e812f2020-05-14 05:32:18 +0000345 else
346 {
Florin Coras94a6df02021-05-06 15:32:14 -0700347 /* Delete sessions in CREATED state */
348 vec_add1 (states, SESSION_STATE_CREATED);
349 segment_manager_del_sessions_filter (sm, states);
350 vec_free (states);
351
Florin Corasc8e812f2020-05-14 05:32:18 +0000352 /* Track segment manager in case app detaches and all the
353 * outstanding sessions need to be closed */
354 app_worker_add_detached_sm (app_wrk, *sm_indexp);
355 sm->flags |= SEG_MANAGER_F_DETACHED_LISTENER;
356 }
Florin Coras2b81e3c2019-02-27 07:55:46 -0800357 }
Florin Coras1bd46162020-04-13 23:35:55 +0000358
Florin Coras2b81e3c2019-02-27 07:55:46 -0800359 hash_unset (app_wrk->listeners_table, handle);
360}
361
362int
363app_worker_stop_listen (app_worker_t * app_wrk, app_listener_t * al)
364{
Florin Corasd4295e62019-02-22 13:11:38 -0800365 session_t *ls;
Florin Coras623eb562019-02-03 19:28:34 -0800366
Florin Corasc9940fc2019-02-05 20:55:11 -0800367 if (!clib_bitmap_get (al->workers, app_wrk->wrk_map_index))
368 return 0;
369
370 if (al->session_index != SESSION_INVALID_INDEX)
Florin Coras623eb562019-02-03 19:28:34 -0800371 {
Florin Corasc9940fc2019-02-05 20:55:11 -0800372 ls = listen_session_get (al->session_index);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800373 app_worker_stop_listen_session (app_wrk, ls);
Florin Coras623eb562019-02-03 19:28:34 -0800374 }
375
Florin Corasc9940fc2019-02-05 20:55:11 -0800376 if (al->local_index != SESSION_INVALID_INDEX)
Florin Coras623eb562019-02-03 19:28:34 -0800377 {
Florin Corasd4295e62019-02-22 13:11:38 -0800378 ls = listen_session_get (al->local_index);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800379 app_worker_stop_listen_session (app_wrk, ls);
Florin Coras623eb562019-02-03 19:28:34 -0800380 }
Florin Corasc9940fc2019-02-05 20:55:11 -0800381
382 clib_bitmap_set_no_check (al->workers, app_wrk->wrk_map_index, 0);
383 if (clib_bitmap_is_zero (al->workers))
384 app_listener_cleanup (al);
Florin Coras623eb562019-02-03 19:28:34 -0800385
386 return 0;
387}
388
389int
Florin Corasa27a46e2019-02-18 13:02:28 -0800390app_worker_init_accepted (session_t * s)
391{
392 app_worker_t *app_wrk;
393 segment_manager_t *sm;
394 session_t *listener;
Ryujiro Shibuyad8f48e22020-01-22 12:11:42 +0000395 application_t *app;
Florin Corasa27a46e2019-02-18 13:02:28 -0800396
Nathan Skrzypczak2f0f96b2019-06-13 10:14:28 +0200397 listener = listen_session_get_from_handle (s->listener_handle);
Florin Corasa27a46e2019-02-18 13:02:28 -0800398 app_wrk = application_listener_select_worker (listener);
Florin Coras0242d302022-12-22 15:03:44 -0800399 if (PREDICT_FALSE (app_worker_mq_is_congested (app_wrk)))
Florin Coras20c24232021-11-22 21:19:01 -0800400 return -1;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800401
Florin Coras20c24232021-11-22 21:19:01 -0800402 s->app_wrk_index = app_wrk->wrk_index;
Ryujiro Shibuyad8f48e22020-01-22 12:11:42 +0000403 app = application_get (app_wrk->app_index);
404 if (app->cb_fns.fifo_tuning_callback)
405 s->flags |= SESSION_F_CUSTOM_FIFO_TUNING;
406
Florin Corasa27a46e2019-02-18 13:02:28 -0800407 sm = app_worker_get_listen_segment_manager (app_wrk, listener);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800408 if (app_worker_alloc_session_fifos (sm, s))
409 return -1;
410
411 return 0;
Florin Corasa27a46e2019-02-18 13:02:28 -0800412}
413
414int
Florin Coras0242d302022-12-22 15:03:44 -0800415app_worker_listened_notify (app_worker_t *app_wrk, session_handle_t alsh,
416 u32 opaque, session_error_t err)
417{
Florin Coras09c0e8f2023-08-11 14:40:13 -0700418 session_event_t evt = { .event_type = SESSION_CTRL_EVT_BOUND,
419 .as_u64[0] = alsh,
Florin Coras4197fb92023-10-27 09:21:50 -0700420 .as_u64[1] = (u64) opaque << 32 | (u32) err };
Florin Coras0242d302022-12-22 15:03:44 -0800421
422 app_worker_add_event_custom (app_wrk, 0 /* thread index */, &evt);
423
424 return 0;
425}
426
427int
428app_worker_unlisten_reply (app_worker_t *app_wrk, session_handle_t sh,
429 u32 opaque, session_error_t err)
430{
Florin Coras09c0e8f2023-08-11 14:40:13 -0700431 session_event_t evt = { .event_type = SESSION_CTRL_EVT_UNLISTEN_REPLY,
432 .as_u64[0] = sh,
433 .as_u64[1] = (u64) opaque << 32 | (u32) err };
Florin Coras0242d302022-12-22 15:03:44 -0800434
435 app_worker_add_event_custom (app_wrk, 0 /* thread index */, &evt);
436 return 0;
437}
438
439int
Florin Corasa27a46e2019-02-18 13:02:28 -0800440app_worker_accept_notify (app_worker_t * app_wrk, session_t * s)
441{
Florin Coras0242d302022-12-22 15:03:44 -0800442 app_worker_add_event (app_wrk, s, SESSION_CTRL_EVT_ACCEPTED);
443 return 0;
Florin Corasa27a46e2019-02-18 13:02:28 -0800444}
445
446int
447app_worker_init_connected (app_worker_t * app_wrk, session_t * s)
448{
449 application_t *app = application_get (app_wrk->app_index);
450 segment_manager_t *sm;
451
Ryujiro Shibuyad8f48e22020-01-22 12:11:42 +0000452 if (app->cb_fns.fifo_tuning_callback)
453 s->flags |= SESSION_F_CUSTOM_FIFO_TUNING;
454
Florin Corase6552402020-11-11 13:25:53 -0800455 /* Allocate fifos for session, unless the app is a builtin proxy */
456 if (application_is_builtin_proxy (app))
Florin Coras2ceb8182023-08-31 17:33:47 -0700457 return app->cb_fns.proxy_alloc_session_fifos (s);
Florin Corase6552402020-11-11 13:25:53 -0800458
459 sm = app_worker_get_connect_segment_manager (app_wrk);
460 return app_worker_alloc_session_fifos (sm, s);
Florin Corasa27a46e2019-02-18 13:02:28 -0800461}
462
463int
Florin Coras00e01d32019-10-21 16:07:46 -0700464app_worker_connect_notify (app_worker_t * app_wrk, session_t * s,
465 session_error_t err, u32 opaque)
Florin Corasa27a46e2019-02-18 13:02:28 -0800466{
Florin Coras09c0e8f2023-08-11 14:40:13 -0700467 session_event_t evt = { .event_type = SESSION_CTRL_EVT_CONNECTED,
468 .as_u64[0] = s ? s->session_index : ~0,
469 .as_u64[1] = (u64) opaque << 32 | (u32) err };
470 u32 thread_index = s ? s->thread_index : vlib_get_thread_index ();
Florin Coras0242d302022-12-22 15:03:44 -0800471
472 app_worker_add_event_custom (app_wrk, thread_index, &evt);
473 return 0;
Florin Corasa27a46e2019-02-18 13:02:28 -0800474}
475
476int
Florin Corasea727642021-05-07 19:39:43 -0700477app_worker_add_half_open (app_worker_t *app_wrk, session_handle_t sh)
Florin Corasd50ff7f2020-04-16 04:30:22 +0000478{
Florin Corasea727642021-05-07 19:39:43 -0700479 session_handle_t *shp;
480
Florin Coras309f7aa2022-03-18 08:33:08 -0700481 ASSERT (session_vlib_thread_is_cl_thread ());
Florin Corasea727642021-05-07 19:39:43 -0700482 pool_get (app_wrk->half_open_table, shp);
483 *shp = sh;
484
485 return (shp - app_wrk->half_open_table);
Florin Corasd50ff7f2020-04-16 04:30:22 +0000486}
487
488int
Florin Coras2c876f92021-05-10 21:12:27 -0700489app_worker_del_half_open (app_worker_t *app_wrk, session_t *s)
Florin Corasd50ff7f2020-04-16 04:30:22 +0000490{
Florin Coras0242d302022-12-22 15:03:44 -0800491 app_worker_add_event (app_wrk, s, SESSION_CTRL_EVT_HALF_CLEANUP);
Florin Corasd50ff7f2020-04-16 04:30:22 +0000492 return 0;
493}
494
Florin Corasd50ff7f2020-04-16 04:30:22 +0000495int
Florin Corasbf7ce2c2019-03-06 14:44:42 -0800496app_worker_close_notify (app_worker_t * app_wrk, session_t * s)
497{
Florin Coras0242d302022-12-22 15:03:44 -0800498 app_worker_add_event (app_wrk, s, SESSION_CTRL_EVT_DISCONNECTED);
Florin Corasbf7ce2c2019-03-06 14:44:42 -0800499 return 0;
500}
501
502int
Florin Coras692b9492019-07-12 15:01:53 -0700503app_worker_transport_closed_notify (app_worker_t * app_wrk, session_t * s)
504{
Florin Coras0242d302022-12-22 15:03:44 -0800505 app_worker_add_event (app_wrk, s, SESSION_CTRL_EVT_TRANSPORT_CLOSED);
Florin Coras692b9492019-07-12 15:01:53 -0700506 return 0;
507}
508
509int
Florin Coras69b68ef2019-04-02 11:38:51 -0700510app_worker_reset_notify (app_worker_t * app_wrk, session_t * s)
511{
Florin Coras0242d302022-12-22 15:03:44 -0800512 app_worker_add_event (app_wrk, s, SESSION_CTRL_EVT_RESET);
Florin Coras69b68ef2019-04-02 11:38:51 -0700513 return 0;
514}
515
516int
Florin Coras70f26d52019-07-08 11:47:18 -0700517app_worker_cleanup_notify (app_worker_t * app_wrk, session_t * s,
518 session_cleanup_ntf_t ntf)
519{
Florin Coras09c0e8f2023-08-11 14:40:13 -0700520 session_event_t evt = { .event_type = SESSION_CTRL_EVT_CLEANUP,
521 .as_u64[0] = (u64) ntf << 32 | s->session_index,
522 .as_u64[1] = pointer_to_uword (session_cleanup) };
Florin Coras0242d302022-12-22 15:03:44 -0800523
524 app_worker_add_event_custom (app_wrk, s->thread_index, &evt);
525
Florin Coras70f26d52019-07-08 11:47:18 -0700526 return 0;
527}
528
529int
Florin Coras0242d302022-12-22 15:03:44 -0800530app_worker_cleanup_notify_custom (app_worker_t *app_wrk, session_t *s,
531 session_cleanup_ntf_t ntf,
532 void (*cleanup_cb) (session_t *s))
Florin Corasbf7ce2c2019-03-06 14:44:42 -0800533{
Florin Coras09c0e8f2023-08-11 14:40:13 -0700534 session_event_t evt = { .event_type = SESSION_CTRL_EVT_CLEANUP,
535 .as_u64[0] = (u64) ntf << 32 | s->session_index,
536 .as_u64[1] = pointer_to_uword (cleanup_cb) };
Florin Coras0242d302022-12-22 15:03:44 -0800537
538 app_worker_add_event_custom (app_wrk, s->thread_index, &evt);
539
Florin Corasbf7ce2c2019-03-06 14:44:42 -0800540 return 0;
541}
542
543int
Florin Coras0242d302022-12-22 15:03:44 -0800544app_worker_rx_notify (app_worker_t *app_wrk, session_t *s)
Florin Coras0e573f52019-05-07 16:28:16 -0700545{
Florin Coras0242d302022-12-22 15:03:44 -0800546 app_worker_add_event (app_wrk, s, SESSION_IO_EVT_RX);
Florin Coras0e573f52019-05-07 16:28:16 -0700547 return 0;
548}
549
550int
Florin Coras49568af2019-07-31 16:46:24 -0700551app_worker_migrate_notify (app_worker_t * app_wrk, session_t * s,
552 session_handle_t new_sh)
553{
Florin Coras09c0e8f2023-08-11 14:40:13 -0700554 session_event_t evt = { .event_type = SESSION_CTRL_EVT_MIGRATED,
555 .as_u64[0] = s->session_index,
556 .as_u64[1] = new_sh };
Florin Coras0242d302022-12-22 15:03:44 -0800557
558 app_worker_add_event_custom (app_wrk, s->thread_index, &evt);
Florin Coras49568af2019-07-31 16:46:24 -0700559 return 0;
560}
561
562int
Florin Coras623eb562019-02-03 19:28:34 -0800563app_worker_own_session (app_worker_t * app_wrk, session_t * s)
564{
565 segment_manager_t *sm;
566 svm_fifo_t *rxf, *txf;
Filip Tehlarac3c8dc2023-03-14 08:50:28 +0100567 int rv;
Florin Coras623eb562019-02-03 19:28:34 -0800568
569 if (s->session_state == SESSION_STATE_LISTENING)
570 return application_change_listener_owner (s, app_wrk);
571
572 s->app_wrk_index = app_wrk->wrk_index;
573
574 rxf = s->rx_fifo;
575 txf = s->tx_fifo;
576
577 if (!rxf || !txf)
578 return 0;
579
580 s->rx_fifo = 0;
581 s->tx_fifo = 0;
582
Florin Coras94a6df02021-05-06 15:32:14 -0700583 sm = app_worker_get_connect_segment_manager (app_wrk);
Filip Tehlarac3c8dc2023-03-14 08:50:28 +0100584 if ((rv = app_worker_alloc_session_fifos (sm, s)))
585 return rv;
Florin Coras623eb562019-02-03 19:28:34 -0800586
Sirshak Das28aa5392019-02-05 01:33:33 -0600587 if (!svm_fifo_is_empty_cons (rxf))
588 svm_fifo_clone (s->rx_fifo, rxf);
Florin Coras623eb562019-02-03 19:28:34 -0800589
Sirshak Das28aa5392019-02-05 01:33:33 -0600590 if (!svm_fifo_is_empty_cons (txf))
591 svm_fifo_clone (s->tx_fifo, txf);
592
Florin Coras19223e02019-03-03 14:56:05 -0800593 segment_manager_dealloc_fifos (rxf, txf);
Florin Coras623eb562019-02-03 19:28:34 -0800594
595 return 0;
596}
597
598int
Florin Coras89a9f612021-05-11 11:55:07 -0700599app_worker_connect_session (app_worker_t *app_wrk, session_endpoint_cfg_t *sep,
600 session_handle_t *rsh)
Florin Coras623eb562019-02-03 19:28:34 -0800601{
Florin Coras0242d302022-12-22 15:03:44 -0800602 if (PREDICT_FALSE (app_worker_mq_is_congested (app_wrk)))
Florin Coras20c24232021-11-22 21:19:01 -0800603 return SESSION_E_REFUSED;
604
Florin Coras89a9f612021-05-11 11:55:07 -0700605 sep->app_wrk_index = app_wrk->wrk_index;
Florin Coras623eb562019-02-03 19:28:34 -0800606
Florin Coras89a9f612021-05-11 11:55:07 -0700607 return session_open (sep, rsh);
Florin Coras623eb562019-02-03 19:28:34 -0800608}
609
610int
Ryujiro Shibuyad8f48e22020-01-22 12:11:42 +0000611app_worker_session_fifo_tuning (app_worker_t * app_wrk, session_t * s,
612 svm_fifo_t * f,
613 session_ft_action_t act, u32 len)
614{
615 application_t *app = application_get (app_wrk->app_index);
616 return app->cb_fns.fifo_tuning_callback (s, f, act, len);
617}
618
Florin Coras623eb562019-02-03 19:28:34 -0800619segment_manager_t *
620app_worker_get_connect_segment_manager (app_worker_t * app)
621{
622 ASSERT (app->connects_seg_manager != (u32) ~ 0);
623 return segment_manager_get (app->connects_seg_manager);
624}
625
626segment_manager_t *
Florin Coras623eb562019-02-03 19:28:34 -0800627app_worker_get_listen_segment_manager (app_worker_t * app,
628 session_t * listener)
629{
630 uword *smp;
631 smp = hash_get (app->listeners_table, listen_session_get_handle (listener));
Dave Barach47d41ad2020-02-17 09:13:26 -0500632 ALWAYS_ASSERT (smp != 0);
Florin Coras623eb562019-02-03 19:28:34 -0800633 return segment_manager_get (*smp);
634}
635
636session_t *
Florin Corasc9940fc2019-02-05 20:55:11 -0800637app_worker_first_listener (app_worker_t * app_wrk, u8 fib_proto,
Florin Coras623eb562019-02-03 19:28:34 -0800638 u8 transport_proto)
639{
640 session_t *listener;
641 u64 handle;
642 u32 sm_index;
643 u8 sst;
644
645 sst = session_type_from_proto_and_ip (transport_proto,
646 fib_proto == FIB_PROTOCOL_IP4);
647
Florin Corasc9940fc2019-02-05 20:55:11 -0800648 hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
Florin Coras623eb562019-02-03 19:28:34 -0800649 listener = listen_session_get_from_handle (handle);
650 if (listener->session_type == sst
Florin Corasd5c604d2019-03-18 09:06:35 -0700651 && !(listener->flags & SESSION_F_PROXY))
Florin Coras623eb562019-02-03 19:28:34 -0800652 return listener;
653 }));
Florin Coras623eb562019-02-03 19:28:34 -0800654
655 return 0;
656}
657
658session_t *
Florin Corasc9940fc2019-02-05 20:55:11 -0800659app_worker_proxy_listener (app_worker_t * app_wrk, u8 fib_proto,
Florin Coras623eb562019-02-03 19:28:34 -0800660 u8 transport_proto)
661{
662 session_t *listener;
663 u64 handle;
664 u32 sm_index;
665 u8 sst;
666
667 sst = session_type_from_proto_and_ip (transport_proto,
668 fib_proto == FIB_PROTOCOL_IP4);
669
Florin Corasc9940fc2019-02-05 20:55:11 -0800670 hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
Florin Coras623eb562019-02-03 19:28:34 -0800671 listener = listen_session_get_from_handle (handle);
Florin Corasd5c604d2019-03-18 09:06:35 -0700672 if (listener->session_type == sst && (listener->flags & SESSION_F_PROXY))
Florin Coras623eb562019-02-03 19:28:34 -0800673 return listener;
674 }));
Florin Coras623eb562019-02-03 19:28:34 -0800675
676 return 0;
677}
678
679/**
680 * Send an API message to the external app, to map new segment
681 */
682int
Florin Coras2b81e3c2019-02-27 07:55:46 -0800683app_worker_add_segment_notify (app_worker_t * app_wrk, u64 segment_handle)
Florin Coras623eb562019-02-03 19:28:34 -0800684{
Florin Coras09c0e8f2023-08-11 14:40:13 -0700685 session_event_t evt = { .event_type = SESSION_CTRL_EVT_APP_ADD_SEGMENT,
686 .as_u64[1] = segment_handle };
Florin Coras0242d302022-12-22 15:03:44 -0800687
688 app_worker_add_event_custom (app_wrk, vlib_get_thread_index (), &evt);
689
690 return 0;
Florin Coras623eb562019-02-03 19:28:34 -0800691}
692
Florin Coras2b81e3c2019-02-27 07:55:46 -0800693int
694app_worker_del_segment_notify (app_worker_t * app_wrk, u64 segment_handle)
695{
Florin Coras09c0e8f2023-08-11 14:40:13 -0700696 session_event_t evt = { .event_type = SESSION_CTRL_EVT_APP_DEL_SEGMENT,
697 .as_u64[1] = segment_handle };
Florin Coras0242d302022-12-22 15:03:44 -0800698
699 app_worker_add_event_custom (app_wrk, vlib_get_thread_index (), &evt);
700
701 return 0;
Florin Coras623eb562019-02-03 19:28:34 -0800702}
703
Florin Coras20c24232021-11-22 21:19:01 -0800704static int
705app_wrk_send_fd (app_worker_t *app_wrk, int fd)
706{
707 if (!appns_sapi_enabled ())
708 {
709 vl_api_registration_t *reg;
710 clib_error_t *error;
711
712 reg =
713 vl_mem_api_client_index_to_registration (app_wrk->api_client_index);
714 if (!reg)
715 {
716 clib_warning ("no api registration for client: %u",
717 app_wrk->api_client_index);
718 return -1;
719 }
720
721 if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
722 return -1;
723
724 error = vl_api_send_fd_msg (reg, &fd, 1);
725 if (error)
726 {
727 clib_error_report (error);
728 return -1;
729 }
730
731 return 0;
732 }
733
734 app_sapi_msg_t smsg = { 0 };
735 app_namespace_t *app_ns;
736 clib_error_t *error;
737 application_t *app;
738 clib_socket_t *cs;
739 u32 cs_index;
740
741 app = application_get (app_wrk->app_index);
742 app_ns = app_namespace_get (app->ns_index);
743 cs_index = appns_sapi_handle_sock_index (app_wrk->api_client_index);
744 cs = appns_sapi_get_socket (app_ns, cs_index);
745 if (PREDICT_FALSE (!cs))
746 return -1;
747
748 /* There's no payload for the message only the type */
749 smsg.type = APP_SAPI_MSG_TYPE_SEND_FDS;
750 error = clib_socket_sendmsg (cs, &smsg, sizeof (smsg), &fd, 1);
751 if (error)
752 {
753 clib_error_report (error);
754 return -1;
755 }
756
757 return 0;
758}
759
Florin Coras0242d302022-12-22 15:03:44 -0800760void
761app_worker_add_event (app_worker_t *app_wrk, session_t *s,
762 session_evt_type_t evt_type)
Florin Coras20c24232021-11-22 21:19:01 -0800763{
Florin Coras20c24232021-11-22 21:19:01 -0800764 session_event_t *evt;
Florin Coras20c24232021-11-22 21:19:01 -0800765
Florin Coras0242d302022-12-22 15:03:44 -0800766 ASSERT (s->thread_index == vlib_get_thread_index ());
767 clib_fifo_add2 (app_wrk->wrk_evts[s->thread_index], evt);
768 evt->session_index = s->session_index;
769 evt->event_type = evt_type;
770 evt->postponed = 0;
Florin Coras20c24232021-11-22 21:19:01 -0800771
Florin Coras0242d302022-12-22 15:03:44 -0800772 /* First event for this app_wrk. Schedule it for handling in session input */
773 if (clib_fifo_elts (app_wrk->wrk_evts[s->thread_index]) == 1)
Florin Coras20c24232021-11-22 21:19:01 -0800774 {
Florin Coras0242d302022-12-22 15:03:44 -0800775 session_worker_t *wrk = session_main_get_worker (s->thread_index);
776 session_wrk_program_app_wrk_evts (wrk, app_wrk->wrk_index);
Florin Coras20c24232021-11-22 21:19:01 -0800777 }
Florin Coras20c24232021-11-22 21:19:01 -0800778}
779
Florin Coras0242d302022-12-22 15:03:44 -0800780void
781app_worker_add_event_custom (app_worker_t *app_wrk, u32 thread_index,
782 session_event_t *evt)
Florin Coras20c24232021-11-22 21:19:01 -0800783{
Florin Coras0242d302022-12-22 15:03:44 -0800784 clib_fifo_add1 (app_wrk->wrk_evts[thread_index], *evt);
Florin Coras20c24232021-11-22 21:19:01 -0800785
Florin Coras0242d302022-12-22 15:03:44 -0800786 /* First event for this app_wrk. Schedule it for handling in session input */
787 if (clib_fifo_elts (app_wrk->wrk_evts[thread_index]) == 1)
Florin Coras20c24232021-11-22 21:19:01 -0800788 {
Florin Coras0242d302022-12-22 15:03:44 -0800789 session_worker_t *wrk = session_main_get_worker (thread_index);
790 session_wrk_program_app_wrk_evts (wrk, app_wrk->wrk_index);
Florin Coras20c24232021-11-22 21:19:01 -0800791 }
Florin Coras20c24232021-11-22 21:19:01 -0800792}
793
794always_inline void
795app_wrk_send_ctrl_evt_inline (app_worker_t *app_wrk, u8 evt_type, void *msg,
796 u32 msg_len, int fd)
797{
798 svm_msg_q_msg_t _mq_msg, *mq_msg = &_mq_msg;
799 svm_msg_q_t *mq = app_wrk->event_queue;
800 session_event_t *evt;
Florin Coras20c24232021-11-22 21:19:01 -0800801
Florin Coras0242d302022-12-22 15:03:44 -0800802 ASSERT (!svm_msg_q_or_ring_is_full (mq, SESSION_MQ_CTRL_EVT_RING));
803 *mq_msg = svm_msg_q_alloc_msg_w_ring (mq, SESSION_MQ_CTRL_EVT_RING);
Florin Coras20c24232021-11-22 21:19:01 -0800804
805 evt = svm_msg_q_msg_data (mq, mq_msg);
806 clib_memset (evt, 0, sizeof (*evt));
807 evt->event_type = evt_type;
808 clib_memcpy_fast (evt->data, msg, msg_len);
809
810 if (fd != -1)
811 app_wrk_send_fd (app_wrk, fd);
812
Florin Coras0242d302022-12-22 15:03:44 -0800813 svm_msg_q_add_raw (mq, mq_msg);
Florin Coras20c24232021-11-22 21:19:01 -0800814}
815
816void
817app_wrk_send_ctrl_evt_fd (app_worker_t *app_wrk, u8 evt_type, void *msg,
818 u32 msg_len, int fd)
819{
820 app_wrk_send_ctrl_evt_inline (app_wrk, evt_type, msg, msg_len, fd);
821}
822
823void
824app_wrk_send_ctrl_evt (app_worker_t *app_wrk, u8 evt_type, void *msg,
825 u32 msg_len)
826{
827 app_wrk_send_ctrl_evt_inline (app_wrk, evt_type, msg, msg_len, -1);
828}
829
Florin Coras0242d302022-12-22 15:03:44 -0800830u8
831app_worker_mq_wrk_is_congested (app_worker_t *app_wrk, u32 thread_index)
Florin Coras623eb562019-02-03 19:28:34 -0800832{
Florin Coras0242d302022-12-22 15:03:44 -0800833 return app_wrk->wrk_mq_congested[thread_index] > 0;
Florin Coras623eb562019-02-03 19:28:34 -0800834}
835
Florin Coras0242d302022-12-22 15:03:44 -0800836void
837app_worker_set_mq_wrk_congested (app_worker_t *app_wrk, u32 thread_index)
Florin Coras623eb562019-02-03 19:28:34 -0800838{
Florin Coras0242d302022-12-22 15:03:44 -0800839 ASSERT (thread_index == vlib_get_thread_index ());
Florin Coras6df9f442024-07-02 01:38:47 -0700840 if (!app_wrk->wrk_mq_congested[thread_index])
841 {
842 clib_atomic_fetch_add_relax (&app_wrk->mq_congested, 1);
843 app_wrk->wrk_mq_congested[thread_index] = 1;
844 }
Florin Coras623eb562019-02-03 19:28:34 -0800845}
846
Florin Coras0242d302022-12-22 15:03:44 -0800847void
848app_worker_unset_wrk_mq_congested (app_worker_t *app_wrk, u32 thread_index)
Florin Coras623eb562019-02-03 19:28:34 -0800849{
Florin Coras0242d302022-12-22 15:03:44 -0800850 clib_atomic_fetch_sub_relax (&app_wrk->mq_congested, 1);
851 ASSERT (thread_index == vlib_get_thread_index ());
852 app_wrk->wrk_mq_congested[thread_index] = 0;
Florin Coras623eb562019-02-03 19:28:34 -0800853}
854
Florin Coras623eb562019-02-03 19:28:34 -0800855u8 *
856format_app_worker_listener (u8 * s, va_list * args)
857{
858 app_worker_t *app_wrk = va_arg (*args, app_worker_t *);
Florin Coras980ee742023-08-04 16:14:01 -0700859 session_handle_t handle = va_arg (*args, u64);
Florin Coras623eb562019-02-03 19:28:34 -0800860 u32 sm_index = va_arg (*args, u32);
861 int verbose = va_arg (*args, int);
862 session_t *listener;
863 const u8 *app_name;
864 u8 *str;
865
866 if (!app_wrk)
867 {
868 if (verbose)
Xiaoming Jiang806709f2021-06-23 09:07:57 +0000869 s = format (s, "%-" SESSION_CLI_ID_LEN "s%-25s%-10s%-15s%-15s%-10s",
870 "Connection", "App", "Wrk", "API Client", "ListenerID",
871 "SegManager");
Florin Coras623eb562019-02-03 19:28:34 -0800872 else
Xiaoming Jiang806709f2021-06-23 09:07:57 +0000873 s = format (s, "%-" SESSION_CLI_ID_LEN "s%-25s%-10s", "Connection",
874 "App", "Wrk");
Florin Coras623eb562019-02-03 19:28:34 -0800875
876 return s;
877 }
878
879 app_name = application_name_from_index (app_wrk->app_index);
880 listener = listen_session_get_from_handle (handle);
Florin Coras31c99552019-03-01 13:00:58 -0800881 str = format (0, "%U", format_session, listener, verbose);
Florin Coras623eb562019-02-03 19:28:34 -0800882
883 if (verbose)
884 {
Dave Barach3e07a4a2020-04-04 10:05:48 -0400885 u8 *buf;
886 buf = format (0, "%u(%u)", app_wrk->wrk_map_index, app_wrk->wrk_index);
Xiaoming Jiang806709f2021-06-23 09:07:57 +0000887 s = format (s, "%-" SESSION_CLI_ID_LEN "v%-25v%-10v%-15u%-15u%-10u", str,
888 app_name, buf, app_wrk->api_client_index, handle, sm_index);
Dave Barach3e07a4a2020-04-04 10:05:48 -0400889 vec_free (buf);
Florin Coras623eb562019-02-03 19:28:34 -0800890 }
891 else
Xiaoming Jiang806709f2021-06-23 09:07:57 +0000892 s = format (s, "%-" SESSION_CLI_ID_LEN "v%-25v%=10u", str, app_name,
893 app_wrk->wrk_map_index);
jiangxiaoming6b410e62020-10-10 15:23:54 +0800894
895 vec_free (str);
Florin Coras623eb562019-02-03 19:28:34 -0800896
897 return s;
898}
899
900u8 *
901format_app_worker (u8 * s, va_list * args)
902{
903 app_worker_t *app_wrk = va_arg (*args, app_worker_t *);
904 u32 indent = 1;
905
Florin Coras20c24232021-11-22 21:19:01 -0800906 s = format (s,
907 "%U wrk-index %u app-index %u map-index %u "
908 "api-client-index %d mq-cong %u\n",
909 format_white_space, indent, app_wrk->wrk_index,
910 app_wrk->app_index, app_wrk->wrk_map_index,
911 app_wrk->api_client_index, app_wrk->mq_congested);
Florin Coras623eb562019-02-03 19:28:34 -0800912 return s;
913}
914
915void
916app_worker_format_connects (app_worker_t * app_wrk, int verbose)
917{
Florin Coras623eb562019-02-03 19:28:34 -0800918 segment_manager_t *sm;
Florin Coras623eb562019-02-03 19:28:34 -0800919
920 /* Header */
921 if (!app_wrk)
922 {
Florin Coras88001c62019-04-24 14:44:46 -0700923 segment_manager_format_sessions (0, verbose);
Florin Coras623eb562019-02-03 19:28:34 -0800924 return;
925 }
926
927 if (app_wrk->connects_seg_manager == (u32) ~ 0)
928 return;
929
Florin Coras623eb562019-02-03 19:28:34 -0800930 sm = segment_manager_get (app_wrk->connects_seg_manager);
Florin Coras88001c62019-04-24 14:44:46 -0700931 segment_manager_format_sessions (sm, verbose);
Florin Coras623eb562019-02-03 19:28:34 -0800932}
933
Florin Coras623eb562019-02-03 19:28:34 -0800934/*
935 * fd.io coding-style-patch-verification: ON
936 *
937 * Local Variables:
938 * eval: (c-set-style "gnu")
939 * End:
940 */