2 #include <vnet/plugin/plugin.h>
3 #include <vpp/app/version.h>
4 #include <vnet/session/session.h>
5 #include <vnet/session/segment_manager.h>
6 #include <vnet/session/application.h>
8 #define SEG_MGR_TEST_I(_cond, _comment, _args...) \
10 int _evald = (_cond); \
12 fformat(stderr, "FAIL:%d: " _comment "\n", \
15 fformat(stderr, "PASS:%d: " _comment "\n", \
21 #define SEG_MGR_TEST(_cond, _comment, _args...) \
23 if (!SEG_MGR_TEST_I(_cond, _comment, ##_args)) { \
28 #define ST_DBG(_comment, _args...) \
29 fformat(stderr, _comment "\n", ##_args); \
31 #define SEGMENT_MANAGER_GET_INDEX_FROM_HANDLE(x) (x >> 32)
33 /* dummy callback functions */
35 dummy_session_reset_callback (session_t * s)
37 clib_warning ("called...");
41 dummy_session_connected_callback (u32 app_index, u32 api_context,
42 session_t * s, u8 is_fail)
44 clib_warning ("called...");
49 dummy_add_segment_callback (u32 client_index, u64 segment_handle)
51 clib_warning ("called...");
56 dummy_del_segment_callback (u32 client_index, u64 segment_handle)
58 clib_warning ("called...");
63 dummy_session_disconnect_callback (session_t * s)
65 clib_warning ("called...");
69 dummy_session_accept_callback (session_t * s)
71 clib_warning ("called...");
76 dummy_server_rx_callback (session_t * s)
78 clib_warning ("called...");
83 static session_cb_vft_t dummy_session_cbs = {
84 .session_reset_callback = dummy_session_reset_callback,
85 .session_connected_callback = dummy_session_connected_callback,
86 .session_accept_callback = dummy_session_accept_callback,
87 .session_disconnect_callback = dummy_session_disconnect_callback,
88 .builtin_app_rx_callback = dummy_server_rx_callback,
89 .add_segment_callback = dummy_add_segment_callback,
90 .del_segment_callback = dummy_del_segment_callback,
94 static char *states_str[] = {
95 #define _(sym,str) str,
96 foreach_segment_mem_status
100 static u32 size_4KB = 4 << 10;
101 static u32 size_8KB = 8 << 10;
102 static u32 size_12KB = 12 << 10;
103 static u32 size_16KB = 16 << 10;
104 static u32 size_20KB = 20 << 10;
105 static u32 size_32KB = 32 << 10;
106 static u32 size_52KB = 52 << 10;
107 static u32 size_64KB = 64 << 10;
108 static u32 size_128KB = 128 << 10;
109 static u32 size_1MB = 1 << 20;
110 static u32 size_2MB = 2 << 20;
114 segment_manager_test_pressure_1 (vlib_main_t * vm, unformat_input_t * input)
117 segment_manager_t *sm;
118 fifo_segment_t *fs0, *fs;
119 svm_fifo_t *rx_fifo, *tx_fifo;
120 uword app_seg_size = size_2MB;
121 u32 fifo_size = size_128KB;
122 u64 options[APP_OPTIONS_N_OPTIONS];
125 memset (&options, 0, sizeof (options));
127 vnet_app_attach_args_t attach_args = {
128 .api_client_index = ~0,
131 .session_cb_vft = &dummy_session_cbs,
132 .name = format (0, "segment_manager_test_pressure_1"),
135 attach_args.options[APP_OPTIONS_SEGMENT_SIZE] = app_seg_size;
136 attach_args.options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
137 attach_args.options[APP_OPTIONS_RX_FIFO_SIZE] = fifo_size;
138 attach_args.options[APP_OPTIONS_TX_FIFO_SIZE] = fifo_size;
139 rv = vnet_application_attach (&attach_args);
140 SEG_MGR_TEST ((rv == 0), "vnet_application_attach %d", rv);
143 segment_manager_get (SEGMENT_MANAGER_GET_INDEX_FROM_HANDLE
144 (attach_args.segment_handle));
145 SEG_MGR_TEST ((sm != 0), "segment_manager_get %p", sm);
147 /* initial status : (0 / 2MB) */
148 fs0 = segment_manager_get_segment (sm, 0);
149 rv = fifo_segment_get_mem_status (fs0);
150 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_NO_PRESSURE),
151 "fifo_segment_get_mem_status %s", states_str[rv]);
154 /* allocate a fifo : 128KB x2 */
155 rv = segment_manager_alloc_session_fifos (sm,
156 vlib_get_thread_index (),
158 SEG_MGR_TEST ((rv == 0), "segment_manager_alloc_session_fifos %d", rv);
160 svm_fifo_set_size (rx_fifo, size_1MB);
161 svm_fifo_set_size (tx_fifo, size_1MB);
163 fs = segment_manager_get_segment (sm, rx_fifo->segment_index);
164 SEG_MGR_TEST ((fs == fs0), "fs %p", fs);
166 /* fill fifos (but not add chunks) */
167 svm_fifo_enqueue (rx_fifo, fifo_size - 1, data);
168 svm_fifo_enqueue (tx_fifo, fifo_size - 1, data);
170 /* 256KB+ / 2048KB+ => ~12% */
171 fifo_segment_update_free_bytes (fs);
172 rv = fifo_segment_get_mem_status (fs);
173 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_NO_PRESSURE),
174 "fifo_segment_get_mem_status %s", states_str[rv]);
177 svm_fifo_enqueue (rx_fifo, fifo_size, data);
178 svm_fifo_enqueue (rx_fifo, fifo_size, data);
179 svm_fifo_enqueue (rx_fifo, fifo_size, data);
180 svm_fifo_enqueue (tx_fifo, fifo_size, data);
181 svm_fifo_enqueue (tx_fifo, fifo_size, data);
182 svm_fifo_enqueue (tx_fifo, fifo_size, data);
185 fifo_segment_update_free_bytes (fs);
186 rv = fifo_segment_get_mem_status (fs);
187 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_NO_PRESSURE),
188 "fifo_segment_get_mem_status %s", states_str[rv]);
191 svm_fifo_enqueue (rx_fifo, fifo_size, data);
192 svm_fifo_enqueue (tx_fifo, fifo_size, data);
194 /* 10 chunks : 61% */
195 fifo_segment_update_free_bytes (fs);
196 rv = fifo_segment_get_mem_status (fs);
197 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_LOW_PRESSURE),
198 "fifo_segment_get_mem_status %s", states_str[rv]);
201 svm_fifo_enqueue (rx_fifo, fifo_size, data);
202 svm_fifo_enqueue (rx_fifo, fifo_size, data);
203 svm_fifo_enqueue (tx_fifo, fifo_size, data);
204 svm_fifo_enqueue (tx_fifo, fifo_size, data);
206 /* 14 chunks : 85% */
207 fifo_segment_update_free_bytes (fs);
208 rv = fifo_segment_get_mem_status (fs);
209 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_HIGH_PRESSURE),
210 "fifo_segment_get_mem_status %s", states_str[rv]);
214 svm_fifo_dequeue_drop (rx_fifo, fifo_size);
215 svm_fifo_dequeue_drop (rx_fifo, fifo_size);
216 svm_fifo_dequeue_drop (tx_fifo, fifo_size);
217 svm_fifo_dequeue_drop (tx_fifo, fifo_size);
219 /* 10 chunks : 61% */
220 fifo_segment_update_free_bytes (fs);
221 rv = fifo_segment_get_mem_status (fs);
222 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_LOW_PRESSURE),
223 "fifo_segment_get_mem_status %s", states_str[rv]);
227 svm_fifo_enqueue (rx_fifo, fifo_size, data);
228 svm_fifo_enqueue (rx_fifo, fifo_size, data);
229 svm_fifo_enqueue (tx_fifo, fifo_size, data);
230 svm_fifo_enqueue (tx_fifo, fifo_size, data);
232 /* 14 chunks : 85% */
233 fifo_segment_update_free_bytes (fs);
234 rv = fifo_segment_get_mem_status (fs);
235 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_HIGH_PRESSURE),
236 "fifo_segment_get_mem_status %s", states_str[rv]);
238 svm_fifo_dequeue_drop (rx_fifo, fifo_size);
239 svm_fifo_dequeue_drop (rx_fifo, fifo_size);
240 svm_fifo_dequeue_drop (tx_fifo, fifo_size);
241 svm_fifo_dequeue_drop (tx_fifo, fifo_size);
244 /* 10 chunks : 61% */
245 fifo_segment_update_free_bytes (fs);
246 rv = fifo_segment_get_mem_status (fs);
247 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_LOW_PRESSURE),
248 "fifo_segment_get_mem_status %s", states_str[rv]);
251 svm_fifo_dequeue_drop (rx_fifo, fifo_size);
252 svm_fifo_dequeue_drop (rx_fifo, fifo_size);
253 svm_fifo_dequeue_drop (rx_fifo, fifo_size);
254 svm_fifo_dequeue_drop (rx_fifo, fifo_size);
255 svm_fifo_dequeue_drop (tx_fifo, fifo_size);
256 svm_fifo_dequeue_drop (tx_fifo, fifo_size);
257 svm_fifo_dequeue_drop (tx_fifo, fifo_size);
258 svm_fifo_dequeue_drop (tx_fifo, fifo_size);
261 fifo_segment_update_free_bytes (fs);
262 rv = fifo_segment_get_mem_status (fs);
263 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_NO_PRESSURE),
264 "fifo_segment_get_mem_status %s", states_str[rv]);
267 vnet_app_detach_args_t detach_args = {
268 .app_index = attach_args.app_index,
269 .api_client_index = ~0,
271 rv = vnet_application_detach (&detach_args);
272 SEG_MGR_TEST ((rv == 0), "vnet_application_detach %d", rv);
278 segment_manager_test_pressure_2 (vlib_main_t * vm, unformat_input_t * input)
281 segment_manager_t *sm;
282 fifo_segment_t *fs0, *fs;
283 svm_fifo_t *rx_fifo, *tx_fifo;
284 uword app_seg_size = size_2MB;
285 u32 fifo_size = size_4KB;
286 u64 options[APP_OPTIONS_N_OPTIONS];
289 memset (&options, 0, sizeof (options));
291 vnet_app_attach_args_t attach_args = {
292 .api_client_index = ~0,
295 .session_cb_vft = &dummy_session_cbs,
296 .name = format (0, "segment_manager_test_pressure_1"),
299 attach_args.options[APP_OPTIONS_SEGMENT_SIZE] = app_seg_size;
300 attach_args.options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
301 attach_args.options[APP_OPTIONS_RX_FIFO_SIZE] = fifo_size;
302 attach_args.options[APP_OPTIONS_TX_FIFO_SIZE] = fifo_size;
303 rv = vnet_application_attach (&attach_args);
304 SEG_MGR_TEST ((rv == 0), "vnet_application_attach %d", rv);
307 segment_manager_get (SEGMENT_MANAGER_GET_INDEX_FROM_HANDLE
308 (attach_args.segment_handle));
309 SEG_MGR_TEST ((sm != 0), "segment_manager_get %p", sm);
311 /* initial status : (0 / 2MB) */
312 fs0 = segment_manager_get_segment (sm, 0);
313 fifo_segment_update_free_bytes (fs0);
314 rv = fifo_segment_get_mem_status (fs0);
315 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_NO_PRESSURE),
316 "fifo_segment_get_mem_status %s", states_str[rv]);
319 /* allocate fifos : 4KB x2 */
320 rv = segment_manager_alloc_session_fifos (sm,
321 vlib_get_thread_index (),
323 SEG_MGR_TEST ((rv == 0), "segment_manager_alloc_session_fifos %d", rv);
325 svm_fifo_set_size (rx_fifo, size_2MB);
326 svm_fifo_set_size (tx_fifo, size_2MB);
328 /* fill fifos (but not add chunks) */
329 svm_fifo_enqueue (rx_fifo, fifo_size - 1, data);
330 svm_fifo_enqueue (tx_fifo, fifo_size - 1, data);
332 fs = segment_manager_get_segment (sm, rx_fifo->segment_index);
335 for (i = 0; i < 509; ++i)
337 svm_fifo_enqueue (rx_fifo, fifo_size, data);
340 /* 510 chunks : 100% of 2MB */
341 fifo_segment_update_free_bytes (fs);
342 rv = fifo_segment_get_mem_status (fs);
343 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_HIGH_PRESSURE),
344 "fifo_segment_get_mem_status %s", states_str[rv]);
346 /* this fifo growth is expected to fail */
347 rv = svm_fifo_enqueue (rx_fifo, fifo_size, data);
348 SEG_MGR_TEST ((rv == SVM_FIFO_EGROW), "svm_fifo_enqueue %d", rv);
350 /* then, no-memory is detected */
351 fifo_segment_update_free_bytes (fs);
352 rv = fifo_segment_get_mem_status (fs);
353 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_NO_MEMORY),
354 "fifo_segment_get_mem_status %s", states_str[rv]);
357 for (i = 0; i < 20; ++i)
359 svm_fifo_dequeue_drop (rx_fifo, fifo_size);
362 /* 489 chunks : 96%, it is high-pressure level
363 * but the reached-mem-limit record is not reset
364 * so the no-memory state lasts.
366 fifo_segment_update_free_bytes (fs);
367 rv = fifo_segment_get_mem_status (fs);
368 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_NO_MEMORY),
369 "fifo_segment_get_mem_status %s", states_str[rv]);
372 for (i = 0; i < 133; ++i)
374 svm_fifo_dequeue_drop (rx_fifo, fifo_size);
377 /* 356 chunks : 70% of 2MB */
378 fifo_segment_update_free_bytes (fs);
379 rv = fifo_segment_get_mem_status (fs);
380 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_LOW_PRESSURE),
381 "fifo_segment_get_mem_status %s", states_str[rv]);
384 for (i = 0; i < 354; ++i)
386 svm_fifo_dequeue_drop (rx_fifo, fifo_size);
389 /* 2 chunks : 3% of 2MB */
390 fifo_segment_update_free_bytes (fs);
391 rv = fifo_segment_get_mem_status (fs);
392 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_NO_PRESSURE),
393 "fifo_segment_get_mem_status %s", states_str[rv]);
396 vnet_app_detach_args_t detach_args = {
397 .app_index = attach_args.app_index,
398 .api_client_index = ~0,
400 rv = vnet_application_detach (&detach_args);
401 SEG_MGR_TEST ((rv == 0), "vnet_application_detach %d", rv);
407 segment_manager_test_fifo_balanced_alloc (vlib_main_t * vm,
408 unformat_input_t * input)
411 segment_manager_t *sm;
412 fifo_segment_t *fs[4];
413 svm_fifo_t *rx_fifo[4], *tx_fifo[4];
414 uword app_seg_size = size_2MB;
415 u32 fifo_size = size_4KB;
416 u64 options[APP_OPTIONS_N_OPTIONS];
419 memset (&options, 0, sizeof (options));
421 vnet_app_attach_args_t attach_args = {
422 .api_client_index = ~0,
425 .session_cb_vft = &dummy_session_cbs,
426 .name = format (0, "segment_manager_test_pressure_1"),
429 attach_args.options[APP_OPTIONS_SEGMENT_SIZE] = app_seg_size;
430 attach_args.options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
431 attach_args.options[APP_OPTIONS_RX_FIFO_SIZE] = fifo_size;
432 attach_args.options[APP_OPTIONS_TX_FIFO_SIZE] = fifo_size;
433 rv = vnet_application_attach (&attach_args);
434 SEG_MGR_TEST ((rv == 0), "vnet_application_attach %d", rv);
437 segment_manager_get (SEGMENT_MANAGER_GET_INDEX_FROM_HANDLE
438 (attach_args.segment_handle));
439 SEG_MGR_TEST ((sm != 0), "segment_manager_get %p", sm);
441 /* initial status : (0 / 2MB) */
442 fs[0] = segment_manager_get_segment (sm, 0);
443 rv = fifo_segment_get_mem_status (fs[0]);
444 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_NO_PRESSURE),
445 "fifo_segment_get_mem_status %s", states_str[rv]);
447 /* allocate fifos : 4KB x2 */
448 rv = segment_manager_alloc_session_fifos (sm,
449 vlib_get_thread_index (),
450 &rx_fifo[0], &tx_fifo[0]);
451 SEG_MGR_TEST ((rv == 0), "segment_manager_alloc_session_fifos %d", rv);
452 SEG_MGR_TEST ((rx_fifo[0]->segment_index == 0),
453 "segment_index %d", rx_fifo[0]->segment_index);
454 SEG_MGR_TEST ((tx_fifo[0]->segment_index == 0),
455 "segment_index %d", tx_fifo[0]->segment_index);
458 svm_fifo_set_size (rx_fifo[0], size_1MB);
459 for (i = 0; i < 200; ++i)
461 svm_fifo_enqueue (rx_fifo[0], fifo_size, data);
464 /* add another 2MB segment */
465 fs_index = segment_manager_add_segment (sm, size_2MB);
466 SEG_MGR_TEST ((fs_index == 1), "fs_index %d", fs_index);
468 /* allocate fifos : 4KB x2
469 * expected to be allocated on the newer segment,
470 * because the usage of the first segment is high.
472 rv = segment_manager_alloc_session_fifos (sm,
473 vlib_get_thread_index (),
474 &rx_fifo[1], &tx_fifo[1]);
475 SEG_MGR_TEST ((rv == 0), "segment_manager_alloc_session_fifos %d", rv);
476 SEG_MGR_TEST ((rx_fifo[1]->segment_index == 1),
477 "segment_index %d", rx_fifo[1]->segment_index);
478 SEG_MGR_TEST ((tx_fifo[1]->segment_index == 1),
479 "segment_index %d", tx_fifo[1]->segment_index);
481 /* allocate fifos : 4KB x2
482 * expected to be allocated on the newer segment.
484 rv = segment_manager_alloc_session_fifos (sm,
485 vlib_get_thread_index (),
486 &rx_fifo[2], &tx_fifo[2]);
487 SEG_MGR_TEST ((rv == 0), "segment_manager_alloc_session_fifos %d", rv);
488 SEG_MGR_TEST ((rx_fifo[2]->segment_index == 1),
489 "segment_index %d", rx_fifo[2]->segment_index);
490 SEG_MGR_TEST ((tx_fifo[2]->segment_index == 1),
491 "segment_index %d", tx_fifo[2]->segment_index);
493 /* grow fifos, so the usage of the secong segment becomes
494 * higher than the first one.
496 svm_fifo_set_size (rx_fifo[1], size_1MB);
497 for (i = 0; i < 400; ++i)
499 svm_fifo_enqueue (rx_fifo[1], fifo_size, data);
502 /* allocate fifos : 4KB x2
503 * expected to be allocated on the first segment.
505 rv = segment_manager_alloc_session_fifos (sm,
506 vlib_get_thread_index (),
507 &rx_fifo[3], &tx_fifo[3]);
508 SEG_MGR_TEST ((rv == 0), "segment_manager_alloc_session_fifos %d", rv);
509 SEG_MGR_TEST ((rx_fifo[3]->segment_index == 0),
510 "segment_index %d", rx_fifo[3]->segment_index);
511 SEG_MGR_TEST ((tx_fifo[3]->segment_index == 0),
512 "segment_index %d", tx_fifo[3]->segment_index);
516 vnet_app_detach_args_t detach_args = {
517 .app_index = attach_args.app_index,
518 .api_client_index = ~0,
520 rv = vnet_application_detach (&detach_args);
521 SEG_MGR_TEST ((rv == 0), "vnet_application_detach %d", rv);
527 segment_manager_test_fifo_ops (vlib_main_t * vm, unformat_input_t * input)
530 segment_manager_t *sm;
532 svm_fifo_t *rx_fifo, *tx_fifo;
533 uword app_seg_size = size_2MB, most_grown = 0;
534 u32 fifo_size = size_4KB;
536 u64 options[APP_OPTIONS_N_OPTIONS];
539 memset (&options, 0, sizeof (options));
541 vnet_app_attach_args_t attach_args = {
542 .api_client_index = ~0,
545 .session_cb_vft = &dummy_session_cbs,
546 .name = format (0, "segment_manager_test_pressure_1"),
549 attach_args.options[APP_OPTIONS_SEGMENT_SIZE] = app_seg_size;
550 attach_args.options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
551 attach_args.options[APP_OPTIONS_RX_FIFO_SIZE] = fifo_size;
552 attach_args.options[APP_OPTIONS_TX_FIFO_SIZE] = fifo_size;
553 rv = vnet_application_attach (&attach_args);
554 SEG_MGR_TEST ((rv == 0), "vnet_application_attach %d", rv);
557 segment_manager_get (SEGMENT_MANAGER_GET_INDEX_FROM_HANDLE
558 (attach_args.segment_handle));
559 SEG_MGR_TEST ((sm != 0), "segment_manager_get %p", sm);
561 /* initial status : (0 / 2MB) */
562 fs = segment_manager_get_segment (sm, 0);
563 rv = fifo_segment_get_mem_status (fs);
564 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_NO_PRESSURE),
565 "fifo_segment_get_mem_status %s", states_str[rv]);
567 /* allocate fifos : 4KB x2 */
568 rv = segment_manager_alloc_session_fifos (sm,
569 vlib_get_thread_index (),
571 SEG_MGR_TEST ((rv == 0), "segment_manager_alloc_session_fifos %d", rv);
573 /* check the initial fifo size : 4KB */
574 rv = svm_fifo_size (rx_fifo);
575 SEG_MGR_TEST ((rv == size_4KB), "svm_fifo_size %d", rv);
578 rv = svm_fifo_enqueue (rx_fifo, size_4KB, data);
579 SEG_MGR_TEST ((rv == size_4KB), "svm_fifo_enqueue %d", rv);
580 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
581 SEG_MGR_TEST ((max_dequeue == size_4KB), "max_dequeue %u", max_dequeue);
583 /* grow the fifo size : 4KB -> 8KB */
584 svm_fifo_set_size (rx_fifo, size_8KB);
585 rv = svm_fifo_size (rx_fifo);
586 SEG_MGR_TEST ((rv == size_8KB), "svm_fifo_size %d", rv);
588 /* verify that fifo cannot grow larger than the fifo size */
589 /* 4KB + 8KB > 8KB, so only 4KB is queued */
590 rv = svm_fifo_enqueue (rx_fifo, size_8KB, data);
591 SEG_MGR_TEST ((rv == size_4KB), "svm_fifo_enqueue %d", rv);
592 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
593 SEG_MGR_TEST ((max_dequeue == size_8KB), "max_dequeue %u", max_dequeue);
595 /* grow the fifo size : 8KB -> 16KB */
596 svm_fifo_set_size (rx_fifo, size_16KB);
598 /* 8KB + 4KB = 12KB */
599 svm_fifo_enqueue (rx_fifo, size_4KB, data);
600 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
601 SEG_MGR_TEST ((max_dequeue == size_12KB), "max_dequeue %u", max_dequeue);
603 /* grow the fifo size : 16KB -> 32KB */
604 svm_fifo_set_size (rx_fifo, size_32KB);
606 /* 12KB + 8KB = 20KB */
607 svm_fifo_enqueue (rx_fifo, size_8KB, data);
608 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
609 SEG_MGR_TEST ((max_dequeue == size_20KB), "max_dequeue %u", max_dequeue);
611 /* grow the fifo size : 32KB -> 64KB */
612 svm_fifo_set_size (rx_fifo, size_64KB);
614 /* 20KB + 32KB = 52KB */
615 svm_fifo_enqueue (rx_fifo, size_32KB, data);
616 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
617 SEG_MGR_TEST ((max_dequeue == size_52KB), "max_dequeue %u", max_dequeue);
620 for (i = 0; i < 55; ++i)
622 svm_fifo_set_size (rx_fifo, svm_fifo_size (rx_fifo) + size_32KB);
623 svm_fifo_enqueue (rx_fifo, size_32KB, data);
625 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
626 SEG_MGR_TEST ((max_dequeue == (size_52KB + size_32KB * 55)),
627 "max_dequeue %u", max_dequeue);
628 rv = fifo_segment_get_mem_status (fs);
629 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_HIGH_PRESSURE),
630 "fifo_segment_get_mem_status %s", states_str[rv]);
631 most_grown = svm_fifo_size (rx_fifo);
634 svm_fifo_dequeue_drop (rx_fifo, size_20KB);
635 svm_fifo_dequeue_drop (rx_fifo, size_32KB);
638 for (i = 0; i < 20; ++i)
639 svm_fifo_dequeue_drop (rx_fifo, size_32KB);
640 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
641 SEG_MGR_TEST ((max_dequeue == (size_32KB * 35)), "max_dequeue %u",
643 rv = fifo_segment_get_mem_status (fs);
644 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_LOW_PRESSURE),
645 "fifo_segment_get_mem_status %s", states_str[rv]);
648 for (i = 0; i < 10; ++i)
649 svm_fifo_dequeue_drop (rx_fifo, size_32KB);
650 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
651 SEG_MGR_TEST ((max_dequeue == (size_32KB * 25)), "max_dequeue %u",
653 rv = fifo_segment_get_mem_status (fs);
654 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_NO_PRESSURE),
655 "fifo_segment_get_mem_status %s", states_str[rv]);
658 for (i = 0; i < 30; ++i)
659 svm_fifo_enqueue (rx_fifo, size_32KB, data);
660 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
661 SEG_MGR_TEST ((max_dequeue == (size_32KB * 55)), "max_dequeue %u",
663 rv = fifo_segment_get_mem_status (fs);
664 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_HIGH_PRESSURE),
665 "fifo_segment_get_mem_status %s", states_str[rv]);
668 for (i = 0; i < 20; ++i)
669 svm_fifo_dequeue_drop (rx_fifo, size_32KB);
670 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
671 SEG_MGR_TEST ((max_dequeue == (size_32KB * 35)), "max_dequeue %u",
673 rv = fifo_segment_get_mem_status (fs);
674 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_LOW_PRESSURE),
675 "fifo_segment_get_mem_status %s", states_str[rv]);
678 for (i = 0; i < 35; ++i)
679 svm_fifo_dequeue_drop (rx_fifo, size_32KB);
680 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
681 SEG_MGR_TEST ((max_dequeue == 0), "max_dequeue %u", max_dequeue);
682 rv = fifo_segment_get_mem_status (fs);
683 SEG_MGR_TEST ((rv == MEMORY_PRESSURE_NO_PRESSURE),
684 "fifo_segment_get_mem_status %s", states_str[rv]);
686 /* (virtual) fifo size is still large as it is not updated */
687 SEG_MGR_TEST ((rx_fifo->size == most_grown), "rx_fifo->size %u",
690 vnet_app_detach_args_t detach_args = {
691 .app_index = attach_args.app_index,
692 .api_client_index = ~0,
694 rv = vnet_application_detach (&detach_args);
695 SEG_MGR_TEST ((rv == 0), "vnet_application_detach %d", rv);
701 static clib_error_t *
702 segment_manager_test (vlib_main_t * vm,
703 unformat_input_t * input, vlib_cli_command_t * cmd_arg)
707 vnet_session_enable_disable (vm, 1);
709 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
711 if (unformat (input, "pressure_levels_1"))
712 res = segment_manager_test_pressure_1 (vm, input);
713 else if (unformat (input, "pressure_levels_2"))
714 res = segment_manager_test_pressure_2 (vm, input);
715 else if (unformat (input, "alloc"))
716 res = segment_manager_test_fifo_balanced_alloc (vm, input);
717 else if (unformat (input, "fifo_ops"))
718 res = segment_manager_test_fifo_ops (vm, input);
720 else if (unformat (input, "all"))
722 if ((res = segment_manager_test_pressure_1 (vm, input)))
724 if ((res = segment_manager_test_pressure_2 (vm, input)))
726 if ((res = segment_manager_test_fifo_balanced_alloc (vm, input)))
728 if ((res = segment_manager_test_fifo_ops (vm, input)))
737 return clib_error_return (0, "Segment manager unit test failed.");
742 VLIB_CLI_COMMAND (tcp_test_command, static) =
744 .path = "test segment-manager",
745 .short_help = "test segment manager [pressure_levels_1]"
746 "[pressure_level_2][alloc][fifo_ops][all]",
747 .function = segment_manager_test,
751 * fd.io coding-style-patch-verification: ON
754 * eval: (c-set-style "gnu")