MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_refcnt_iter

Function test_refcnt_iter

dpdk/app/test/test_mbuf.c:1013–1069  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1011}
1012
1013static void
1014test_refcnt_iter(unsigned int lcore, unsigned int iter,
1015 struct rte_mempool *refcnt_pool,
1016 struct rte_ring *refcnt_mbuf_ring)
1017{
1018 uint16_t ref;
1019 unsigned i, n, tref, wn;
1020 struct rte_mbuf *m;
1021
1022 tref = 0;
1023
1024 /* For each mbuf in the pool:
1025 * - allocate mbuf,
1026 * - increment it's reference up to N+1,
1027 * - enqueue it N times into the ring for worker cores to free.
1028 */
1029 for (i = 0, n = rte_mempool_avail_count(refcnt_pool);
1030 i != n && (m = rte_pktmbuf_alloc(refcnt_pool)) != NULL;
1031 i++) {
1032 ref = RTE_MAX(rte_rand() % REFCNT_MAX_REF, 1UL);
1033 tref += ref;
1034 if ((ref & 1) != 0) {
1035 rte_pktmbuf_refcnt_update(m, ref);
1036 while (ref-- != 0)
1037 rte_ring_enqueue(refcnt_mbuf_ring, m);
1038 } else {
1039 while (ref-- != 0) {
1040 rte_pktmbuf_refcnt_update(m, 1);
1041 rte_ring_enqueue(refcnt_mbuf_ring, m);
1042 }
1043 }
1044 rte_pktmbuf_free(m);
1045 }
1046
1047 if (i != n)
1048 rte_panic("(lcore=%u, iter=%u): was able to allocate only "
1049 "%u from %u mbufs\n", lcore, iter, i, n);
1050
1051 /* wait till worker lcores will consume all mbufs */
1052 while (!rte_ring_empty(refcnt_mbuf_ring))
1053 ;
1054
1055 /* check that all mbufs are back into mempool by now */
1056 for (wn = 0; wn != REFCNT_MAX_TIMEOUT; wn++) {
1057 if ((i = rte_mempool_avail_count(refcnt_pool)) == n) {
1058 refcnt_lcore[lcore] += tref;
1059 printf("%s(lcore=%u, iter=%u) completed, "
1060 "%u references processed\n",
1061 __func__, lcore, iter, tref);
1062 return;
1063 }
1064 rte_delay_ms(100);
1065 }
1066
1067 rte_panic("(lcore=%u, iter=%u): after %us only "
1068 "%u of %u mbufs left free\n", lcore, iter, wn, i, n);
1069}
1070

Callers 1

test_refcnt_mainFunction · 0.85

Calls 9

rte_mempool_avail_countFunction · 0.85
rte_pktmbuf_allocFunction · 0.85
rte_randFunction · 0.85
rte_ring_enqueueFunction · 0.85
rte_pktmbuf_freeFunction · 0.85
rte_ring_emptyFunction · 0.85
rte_delay_msFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected