Lines Matching refs:buffer
59 static void drop(const struct mpsc_pbuf_buffer *buffer, const union mpsc_pbuf_generic *item) in drop() argument
90 static void init(struct mpsc_pbuf_buffer *buffer, uint32_t wlen, bool overwrite) in init() argument
96 mpsc_pbuf_init(buffer, &mpsc_buf_cfg); in init()
116 struct mpsc_pbuf_buffer buffer; in item_put_no_overwrite() local
118 init(&buffer, 4 - !pow2, false); in item_put_no_overwrite()
120 int repeat = buffer.size*2; in item_put_no_overwrite()
127 mpsc_pbuf_put_word(&buffer, test_1word.item); in item_put_no_overwrite()
129 t = (union test_item *)mpsc_pbuf_claim(&buffer); in item_put_no_overwrite()
132 mpsc_pbuf_free(&buffer, &t->item); in item_put_no_overwrite()
136 zassert_is_null(mpsc_pbuf_claim(&buffer)); in item_put_no_overwrite()
147 struct mpsc_pbuf_buffer buffer; in item_put_overwrite() local
149 init(&buffer, 4 - !pow2, true); in item_put_overwrite()
157 for (int i = 0; i < buffer.size + 1; i++) { in item_put_overwrite()
159 mpsc_pbuf_put_word(&buffer, test_1word.item); in item_put_overwrite()
174 struct mpsc_pbuf_buffer buffer; in item_put_saturate() local
176 init(&buffer, 4 - !pow2, false); in item_put_saturate()
178 int repeat = buffer.size; in item_put_saturate()
182 zassert_false(mpsc_pbuf_is_pending(&buffer)); in item_put_saturate()
186 mpsc_pbuf_put_word(&buffer, test_1word.item); in item_put_saturate()
188 zassert_true(mpsc_pbuf_is_pending(&buffer)); in item_put_saturate()
190 t = (union test_item *)mpsc_pbuf_claim(&buffer); in item_put_saturate()
193 mpsc_pbuf_free(&buffer, &t->item); in item_put_saturate()
198 mpsc_pbuf_put_word(&buffer, test_1word.item); in item_put_saturate()
202 t = (union test_item *)mpsc_pbuf_claim(&buffer); in item_put_saturate()
205 mpsc_pbuf_free(&buffer, &t->item); in item_put_saturate()
208 zassert_is_null(mpsc_pbuf_claim(&buffer)); in item_put_saturate()
219 struct mpsc_pbuf_buffer buffer; in benchmark_item_put() local
221 init(&buffer, ARRAY_SIZE(buf32) - !pow2, true); in benchmark_item_put()
223 int repeat = buffer.size - 1; in benchmark_item_put()
229 mpsc_pbuf_put_word(&buffer, test_1word.item); in benchmark_item_put()
240 ti = (union test_item *)mpsc_pbuf_claim(&buffer); in benchmark_item_put()
243 mpsc_pbuf_free(&buffer, &ti->item); in benchmark_item_put()
249 zassert_is_null(mpsc_pbuf_claim(&buffer)); in benchmark_item_put()
260 struct mpsc_pbuf_buffer buffer; in item_put_ext_no_overwrite() local
262 init(&buffer, 8 - !pow2, false); in item_put_ext_no_overwrite()
264 int repeat = buffer.size * 2; in item_put_ext_no_overwrite()
278 mpsc_pbuf_put_word_ext(&buffer, test_ext_item.item, data); in item_put_ext_no_overwrite()
280 t = (union test_item *)mpsc_pbuf_claim(&buffer); in item_put_ext_no_overwrite()
284 mpsc_pbuf_free(&buffer, &t->item); in item_put_ext_no_overwrite()
287 zassert_is_null(mpsc_pbuf_claim(&buffer)); in item_put_ext_no_overwrite()
298 struct mpsc_pbuf_buffer buffer; in item_put_word_ext_overwrite() local
300 init(&buffer, 8 - !pow2, true); in item_put_word_ext_overwrite()
303 int repeat = 1 + buffer.size / w; in item_put_word_ext_overwrite()
317 mpsc_pbuf_put_word_ext(&buffer, test_ext_item.item, (void *)i); in item_put_word_ext_overwrite()
333 struct mpsc_pbuf_buffer buffer; in item_put_ext_saturate() local
335 init(&buffer, 8 - !pow2, false); in item_put_ext_saturate()
337 int repeat = buffer.size / PUT_EXT_LEN; in item_put_ext_saturate()
350 mpsc_pbuf_put_word_ext(&buffer, test_ext_item.item, data); in item_put_ext_saturate()
352 t = (union test_item *)mpsc_pbuf_claim(&buffer); in item_put_ext_saturate()
355 mpsc_pbuf_free(&buffer, &t->item); in item_put_ext_saturate()
361 mpsc_pbuf_put_word_ext(&buffer, test_ext_item.item, data); in item_put_ext_saturate()
365 t = (union test_item *)mpsc_pbuf_claim(&buffer); in item_put_ext_saturate()
369 mpsc_pbuf_free(&buffer, &t->item); in item_put_ext_saturate()
372 zassert_is_null(mpsc_pbuf_claim(&buffer)); in item_put_ext_saturate()
383 struct mpsc_pbuf_buffer buffer; in benchmark_item_put_ext() local
385 init(&buffer, ARRAY_SIZE(buf32) - !pow2, false); in benchmark_item_put_ext()
387 int repeat = (buffer.size - 1) / PUT_EXT_LEN; in benchmark_item_put_ext()
399 mpsc_pbuf_put_word_ext(&buffer, test_ext_item.item, data); in benchmark_item_put_ext()
410 ti = (union test_item *)mpsc_pbuf_claim(&buffer); in benchmark_item_put_ext()
413 mpsc_pbuf_free(&buffer, &ti->item); in benchmark_item_put_ext()
419 zassert_is_null(mpsc_pbuf_claim(&buffer)); in benchmark_item_put_ext()
430 struct mpsc_pbuf_buffer buffer; in benchmark_item_put_data() local
432 init(&buffer, ARRAY_SIZE(buf32) - !pow2, false); in benchmark_item_put_data()
434 int repeat = (buffer.size - 1) / PUT_EXT_LEN; in benchmark_item_put_data()
449 mpsc_pbuf_put_data(&buffer, (uint32_t *)&test_ext_item, in benchmark_item_put_data()
461 ti = (union test_item *)mpsc_pbuf_claim(&buffer); in benchmark_item_put_data()
464 mpsc_pbuf_free(&buffer, &ti->item); in benchmark_item_put_data()
470 zassert_is_null(mpsc_pbuf_claim(&buffer)); in benchmark_item_put_data()
481 struct mpsc_pbuf_buffer buffer; in item_put_data_overwrite() local
483 init(&buffer, 8 - !pow2, true); in item_put_data_overwrite()
486 int repeat = 1 + buffer.size / w; in item_put_data_overwrite()
505 mpsc_pbuf_put_data(&buffer, (uint32_t *)vitem, len); in item_put_data_overwrite()
520 struct mpsc_pbuf_buffer buffer; in item_alloc_commit() local
522 init(&buffer, 16 - !pow2, false); in item_alloc_commit()
529 packet = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, len, in item_alloc_commit()
536 mpsc_pbuf_commit(&buffer, (union mpsc_pbuf_generic *)packet); in item_alloc_commit()
538 packet = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in item_alloc_commit()
546 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)packet); in item_alloc_commit()
558 struct mpsc_pbuf_buffer buffer; in item_max_alloc() local
561 init(&buffer, 8, overwrite); in item_max_alloc()
565 packet = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, in item_max_alloc()
566 buffer.size, in item_max_alloc()
569 packet->hdr.len = buffer.size; in item_max_alloc()
570 mpsc_pbuf_commit(&buffer, (union mpsc_pbuf_generic *)packet); in item_max_alloc()
572 packet = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in item_max_alloc()
573 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)packet); in item_max_alloc()
577 packet = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, in item_max_alloc()
578 buffer.size + 1, in item_max_alloc()
589 static uint32_t saturate_buffer_uneven(struct mpsc_pbuf_buffer *buffer, in saturate_buffer_uneven() argument
596 uneven + ((buffer->size - (uneven * len)) / len); in saturate_buffer_uneven()
600 packet = (struct test_data_var *)mpsc_pbuf_alloc(buffer, len, in saturate_buffer_uneven()
603 mpsc_pbuf_commit(buffer, (union mpsc_pbuf_generic *)packet); in saturate_buffer_uneven()
605 packet = (struct test_data_var *)mpsc_pbuf_claim(buffer); in saturate_buffer_uneven()
607 mpsc_pbuf_free(buffer, (union mpsc_pbuf_generic *)packet); in saturate_buffer_uneven()
611 packet = (struct test_data_var *)mpsc_pbuf_alloc(buffer, len, in saturate_buffer_uneven()
620 mpsc_pbuf_commit(buffer, (union mpsc_pbuf_generic *)packet); in saturate_buffer_uneven()
629 struct mpsc_pbuf_buffer buffer; in item_alloc_commit_saturate() local
631 init(&buffer, 32 - !pow2, false); in item_alloc_commit_saturate()
633 saturate_buffer_uneven(&buffer, 5); in item_alloc_commit_saturate()
638 packet = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, len, in item_alloc_commit_saturate()
643 packet = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in item_alloc_commit_saturate()
645 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)packet); in item_alloc_commit_saturate()
648 packet = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, len, in item_alloc_commit_saturate()
661 struct mpsc_pbuf_buffer buffer; in item_alloc_preemption() local
663 init(&buffer, ARRAY_SIZE(buf32) - !pow2, false); in item_alloc_preemption()
669 p0 = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, 10, K_NO_WAIT); in item_alloc_preemption()
674 p = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in item_alloc_preemption()
677 p1 = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, 20, K_NO_WAIT); in item_alloc_preemption()
684 mpsc_pbuf_commit(&buffer, (union mpsc_pbuf_generic *)p1); in item_alloc_preemption()
687 p = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in item_alloc_preemption()
690 mpsc_pbuf_commit(&buffer, (union mpsc_pbuf_generic *)p0); in item_alloc_preemption()
693 p = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in item_alloc_preemption()
696 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)p); in item_alloc_preemption()
699 p = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in item_alloc_preemption()
702 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)p); in item_alloc_preemption()
705 p = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in item_alloc_preemption()
720 struct mpsc_pbuf_buffer buffer; in overwrite() local
722 init(&buffer, 32 - !pow2, true); in overwrite()
723 uint32_t packet_cnt = saturate_buffer_uneven(&buffer, fill_len); in overwrite()
735 p = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, len0, K_NO_WAIT); in overwrite()
738 mpsc_pbuf_commit(&buffer, (union mpsc_pbuf_generic *)p); in overwrite()
749 p = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, len1, K_NO_WAIT); in overwrite()
752 mpsc_pbuf_commit(&buffer, (union mpsc_pbuf_generic *)p); in overwrite()
756 p = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in overwrite()
764 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)p); in overwrite()
767 p = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in overwrite()
770 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)p); in overwrite()
772 p = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in overwrite()
775 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)p); in overwrite()
777 p = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in overwrite()
791 struct mpsc_pbuf_buffer buffer; in overwrite_while_claimed() local
793 init(&buffer, 32 - !pow2, true); in overwrite_while_claimed()
797 uint32_t packet_cnt = saturate_buffer_uneven(&buffer, fill_len); in overwrite_while_claimed()
802 p0 = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in overwrite_while_claimed()
811 p1 = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, 6, K_NO_WAIT); in overwrite_while_claimed()
814 mpsc_pbuf_commit(&buffer, (union mpsc_pbuf_generic *)p1); in overwrite_while_claimed()
816 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)p0); in overwrite_while_claimed()
819 p0 = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in overwrite_while_claimed()
823 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)p0); in overwrite_while_claimed()
826 p0 = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in overwrite_while_claimed()
830 p0 = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in overwrite_while_claimed()
844 struct mpsc_pbuf_buffer buffer; in overwrite_while_claimed2() local
846 init(&buffer, 32 - !pow2, true); in overwrite_while_claimed2()
850 uint32_t packet_cnt = saturate_buffer_uneven(&buffer, fill_len); in overwrite_while_claimed2()
855 p0 = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in overwrite_while_claimed2()
866 p1 = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, len, K_NO_WAIT); in overwrite_while_claimed2()
870 mpsc_pbuf_commit(&buffer, (union mpsc_pbuf_generic *)p1); in overwrite_while_claimed2()
872 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)p0); in overwrite_while_claimed2()
875 p0 = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in overwrite_while_claimed2()
879 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)p0); in overwrite_while_claimed2()
882 p0 = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in overwrite_while_claimed2()
886 p0 = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in overwrite_while_claimed2()
906 static void consistent_drop(const struct mpsc_pbuf_buffer *buffer, in consistent_drop() argument
919 struct mpsc_pbuf_buffer buffer; in ZTEST() local
928 mpsc_pbuf_init(&buffer, &cfg); in ZTEST()
940 tdv = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in ZTEST()
952 tdv2 = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, in ZTEST()
957 mpsc_pbuf_commit(&buffer, (union mpsc_pbuf_generic *)tdv2); in ZTEST()
962 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)tdv); in ZTEST()
970 tdv2 = (struct test_data_var *)mpsc_pbuf_claim(&buffer); in ZTEST()
976 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)tdv2); in ZTEST()
990 struct mpsc_pbuf_buffer *buffer = p0; in t_entry() local
995 t = (struct test_data_ext *)mpsc_pbuf_alloc(buffer, in t_entry()
1000 t = (struct test_data_ext *)mpsc_pbuf_alloc(buffer, in t_entry()
1008 mpsc_pbuf_commit(buffer, (union mpsc_pbuf_generic *)vt); in t_entry()
1014 void start_threads(struct mpsc_pbuf_buffer *buffer) in start_threads() argument
1021 buffer, (void *)wait_ms, NULL, in start_threads()
1044 struct mpsc_pbuf_buffer buffer; in ZTEST() local
1049 init(&buffer, ARRAY_SIZE(buf32) - 1, true); in ZTEST()
1052 uint32_t packet_cnt = saturate_buffer_uneven(&buffer, fill_len); in ZTEST()
1054 start_threads(&buffer); in ZTEST()
1059 union test_item *t = (union test_item *)mpsc_pbuf_claim(&buffer); in ZTEST()
1061 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)t); in ZTEST()
1067 (struct test_data_ext *)mpsc_pbuf_claim(&buffer); in ZTEST()
1073 mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)vt); in ZTEST()
1076 zassert_equal(mpsc_pbuf_claim(&buffer), NULL, "No more packets."); in ZTEST()
1080 static void check_packet(struct mpsc_pbuf_buffer *buffer, char exp_c) in check_packet() argument
1085 claimed = mpsc_pbuf_claim(buffer); in check_packet()
1090 mpsc_pbuf_free(buffer, claimed); in check_packet()
1095 struct mpsc_pbuf_buffer buffer; in ZTEST() local
1117 mpsc_pbuf_init(&buffer, &buffer_config); in ZTEST()
1120 for (int i = 0; i < buffer.size; ++i) { in ZTEST()
1121 mpsc_pbuf_put_word(&buffer, item.item); in ZTEST()
1131 mpsc_pbuf_put_word(&buffer, item.item); in ZTEST()
1135 claimed = mpsc_pbuf_claim(&buffer); in ZTEST()
1146 mpsc_pbuf_put_word(&buffer, item.item); in ZTEST()
1154 mpsc_pbuf_put_word(&buffer, item.item); in ZTEST()
1158 mpsc_pbuf_free(&buffer, claimed); in ZTEST()
1161 check_packet(&buffer, 'e'); in ZTEST()
1164 check_packet(&buffer, 'f'); in ZTEST()
1167 check_packet(&buffer, 'g'); in ZTEST()
1170 claimed = mpsc_pbuf_claim(&buffer); in ZTEST()
1174 static void check_usage(struct mpsc_pbuf_buffer *buffer, in check_usage() argument
1181 mpsc_pbuf_get_utilization(buffer, &size, &usage); in check_usage()
1182 zassert_equal(size / sizeof(int), buffer->size - 1, "%d: got:%d, exp:%d", in check_usage()
1183 line, size / sizeof(int), buffer->size - 1); in check_usage()
1186 err = mpsc_pbuf_get_max_utilization(buffer, &usage); in check_usage()
1193 #define CHECK_USAGE(buffer, now, max) \ argument
1194 check_usage(buffer, (now) * sizeof(int), 0, (max) * sizeof(int), __LINE__)
1196 static void ignore_drop(const struct mpsc_pbuf_buffer *buffer, in ignore_drop() argument
1199 ARG_UNUSED(buffer); in ignore_drop()
1205 struct mpsc_pbuf_buffer buffer; in ZTEST() local
1214 mpsc_pbuf_init(&buffer, &config); in ZTEST()
1216 check_usage(&buffer, 0, -ENOTSUP, 0, __LINE__); in ZTEST()
1220 mpsc_pbuf_init(&buffer, &config); in ZTEST()
1222 CHECK_USAGE(&buffer, 0, 0); in ZTEST()
1233 mpsc_pbuf_put_word(&buffer, test_1word.item); in ZTEST()
1235 CHECK_USAGE(&buffer, 1, 1); in ZTEST()
1237 mpsc_pbuf_put_word_ext(&buffer, test_ext_item.item, NULL); in ZTEST()
1239 CHECK_USAGE(&buffer, 1 + PUT_EXT_LEN, 1 + PUT_EXT_LEN); in ZTEST()
1241 t = (union test_item *)mpsc_pbuf_claim(&buffer); in ZTEST()
1244 CHECK_USAGE(&buffer, 1 + PUT_EXT_LEN, 1 + PUT_EXT_LEN); in ZTEST()
1245 mpsc_pbuf_free(&buffer, &t->item); in ZTEST()
1247 t = (union test_item *)mpsc_pbuf_claim(&buffer); in ZTEST()
1250 CHECK_USAGE(&buffer, PUT_EXT_LEN, 1 + PUT_EXT_LEN); in ZTEST()
1252 mpsc_pbuf_free(&buffer, &t->item); in ZTEST()
1254 CHECK_USAGE(&buffer, 0, 1 + PUT_EXT_LEN); in ZTEST()
1266 mpsc_pbuf_put_data(&buffer, (uint32_t *)&test_ext_item2, PUT_EXT_LEN); in ZTEST()
1268 CHECK_USAGE(&buffer, PUT_EXT_LEN, 1 + PUT_EXT_LEN); in ZTEST()
1270 t = (union test_item *)mpsc_pbuf_claim(&buffer); in ZTEST()
1272 mpsc_pbuf_free(&buffer, &t->item); in ZTEST()
1274 CHECK_USAGE(&buffer, 0, 1 + PUT_EXT_LEN); in ZTEST()
1276 memset(&buffer, 0, sizeof(buffer)); in ZTEST()
1278 mpsc_pbuf_init(&buffer, &config); in ZTEST()
1284 for (i = 0; i < (buffer.size - 1) / len; i++) { in ZTEST()
1285 packet = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, len, K_NO_WAIT); in ZTEST()
1288 mpsc_pbuf_commit(&buffer, (union mpsc_pbuf_generic *)packet); in ZTEST()
1289 CHECK_USAGE(&buffer, len * (i + 1), len * (i + 1)); in ZTEST()
1292 packet = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, len, K_NO_WAIT); in ZTEST()