4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/queue.h>
43 #include <rte_common.h>
45 #include <rte_debug.h>
46 #include <rte_memory.h>
47 #include <rte_memzone.h>
48 #include <rte_atomic.h>
49 #include <rte_launch.h>
50 #include <rte_tailq.h>
52 #include <rte_eal_memconfig.h>
53 #include <rte_per_lcore.h>
54 #include <rte_lcore.h>
55 #include <rte_branch_prediction.h>
57 #include <rte_errno.h>
58 #include <rte_string_fns.h>
59 #include <rte_spinlock.h>
61 #include "rte_mempool.h"
63 TAILQ_HEAD(rte_mempool_list, rte_mempool);
65 #define CACHE_FLUSHTHRESH_MULTIPLIER 1.5
68 * return the greatest common divisor between a and b (fast algorithm)
71 static unsigned get_gcd(unsigned a, unsigned b)
96 * Depending on memory configuration, objects addresses are spread
97 * between channels and ranks in RAM: the pool allocator will add
98 * padding between objects. This function return the new size of the
101 static unsigned optimize_object_size(unsigned obj_size)
103 unsigned nrank, nchan;
104 unsigned new_obj_size;
106 /* get number of channels */
107 nchan = rte_memory_get_nchannel();
111 nrank = rte_memory_get_nrank();
115 /* process new object size */
116 new_obj_size = (obj_size + CACHE_LINE_MASK) / CACHE_LINE_SIZE;
117 while (get_gcd(new_obj_size, nrank * nchan) != 1)
119 return new_obj_size * CACHE_LINE_SIZE;
123 mempool_add_elem(struct rte_mempool *mp, void *obj, uint32_t obj_idx,
124 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg)
126 struct rte_mempool **mpp;
128 obj = (char *)obj + mp->header_size;
130 /* set mempool ptr in header */
131 mpp = __mempool_from_obj(obj);
134 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
135 __mempool_write_header_cookie(obj, 1);
136 __mempool_write_trailer_cookie(obj);
138 /* call the initializer */
140 obj_init(mp, obj_init_arg, obj, obj_idx);
142 /* enqueue in ring */
143 rte_ring_sp_enqueue(mp->ring, obj);
147 rte_mempool_obj_iter(void *vaddr, uint32_t elt_num, size_t elt_sz, size_t align,
148 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift,
149 rte_mempool_obj_iter_t obj_iter, void *obj_iter_arg)
153 uintptr_t end, start, va;
156 pg_sz = (uintptr_t)1 << pg_shift;
157 va = (uintptr_t)vaddr;
162 while (i != elt_num && j != pg_num) {
164 start = RTE_ALIGN_CEIL(va, align);
165 end = start + elt_sz;
167 pgn = (end >> pg_shift) - (start >> pg_shift);
170 /* do we have enough space left for the next element. */
176 paddr[k] + pg_sz == paddr[k + 1];
181 * if next pgn chunks of memory physically continuous,
182 * use it to create next element.
183 * otherwise, just skip that chunk unused.
186 if (obj_iter != NULL)
187 obj_iter(obj_iter_arg, (void *)start,
193 va = RTE_ALIGN_CEIL((va + 1), pg_sz);
202 * Populate mempool with the objects.
205 struct mempool_populate_arg {
206 struct rte_mempool *mp;
207 rte_mempool_obj_ctor_t *obj_init;
212 mempool_obj_populate(void *arg, void *start, void *end, uint32_t idx)
214 struct mempool_populate_arg *pa = arg;
216 mempool_add_elem(pa->mp, start, idx, pa->obj_init, pa->obj_init_arg);
217 pa->mp->elt_va_end = (uintptr_t)end;
221 mempool_populate(struct rte_mempool *mp, size_t num, size_t align,
222 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg)
225 struct mempool_populate_arg arg;
227 elt_sz = mp->elt_size + mp->header_size + mp->trailer_size;
229 arg.obj_init = obj_init;
230 arg.obj_init_arg = obj_init_arg;
232 mp->size = rte_mempool_obj_iter((void *)mp->elt_va_start,
234 mp->elt_pa, mp->pg_num, mp->pg_shift,
235 mempool_obj_populate, &arg);
239 rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
240 struct rte_mempool_objsz *sz)
242 struct rte_mempool_objsz lsz;
244 sz = (sz != NULL) ? sz : &lsz;
247 * In header, we have at least the pointer to the pool, and
248 * optionaly a 64 bits cookie.
251 sz->header_size += sizeof(struct rte_mempool *); /* ptr to pool */
252 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
253 sz->header_size += sizeof(uint64_t); /* cookie */
255 if ((flags & MEMPOOL_F_NO_CACHE_ALIGN) == 0)
256 sz->header_size = RTE_ALIGN_CEIL(sz->header_size,
259 /* trailer contains the cookie in debug mode */
260 sz->trailer_size = 0;
261 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
262 sz->trailer_size += sizeof(uint64_t); /* cookie */
264 /* element size is 8 bytes-aligned at least */
265 sz->elt_size = RTE_ALIGN_CEIL(elt_size, sizeof(uint64_t));
267 /* expand trailer to next cache line */
268 if ((flags & MEMPOOL_F_NO_CACHE_ALIGN) == 0) {
269 sz->total_size = sz->header_size + sz->elt_size +
271 sz->trailer_size += ((CACHE_LINE_SIZE -
272 (sz->total_size & CACHE_LINE_MASK)) &
277 * increase trailer to add padding between objects in order to
278 * spread them across memory channels/ranks
280 if ((flags & MEMPOOL_F_NO_SPREAD) == 0) {
282 new_size = optimize_object_size(sz->header_size + sz->elt_size +
284 sz->trailer_size = new_size - sz->header_size - sz->elt_size;
287 if (! rte_eal_has_hugepages()) {
289 * compute trailer size so that pool elements fit exactly in
292 int page_size = getpagesize();
293 int new_size = page_size - sz->header_size - sz->elt_size;
294 if (new_size < 0 || (unsigned int)new_size < sz->trailer_size) {
295 printf("When hugepages are disabled, pool objects "
296 "can't exceed PAGE_SIZE: %d + %d + %d > %d\n",
297 sz->header_size, sz->elt_size, sz->trailer_size,
301 sz->trailer_size = new_size;
304 /* this is the size of an object, including header and trailer */
305 sz->total_size = sz->header_size + sz->elt_size + sz->trailer_size;
307 return (sz->total_size);
312 * Calculate maximum amount of memory required to store given number of objects.
315 rte_mempool_xmem_size(uint32_t elt_num, size_t elt_sz, uint32_t pg_shift)
317 size_t n, pg_num, pg_sz, sz;
319 pg_sz = (size_t)1 << pg_shift;
321 if ((n = pg_sz / elt_sz) > 0) {
322 pg_num = (elt_num + n - 1) / n;
323 sz = pg_num << pg_shift;
325 sz = RTE_ALIGN_CEIL(elt_sz, pg_sz) * elt_num;
332 * Calculate how much memory would be actually required with the
333 * given memory footprint to store required number of elements.
336 mempool_lelem_iter(void *arg, __rte_unused void *start, void *end,
337 __rte_unused uint32_t idx)
339 *(uintptr_t *)arg = (uintptr_t)end;
343 rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num, size_t elt_sz,
344 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift)
350 pg_sz = (size_t)1 << pg_shift;
351 va = (uintptr_t)vaddr;
354 if ((n = rte_mempool_obj_iter(vaddr, elt_num, elt_sz, 1,
355 paddr, pg_num, pg_shift, mempool_lelem_iter,
360 uv = RTE_ALIGN_CEIL(uv, pg_sz);
365 /* create the mempool */
367 rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
368 unsigned cache_size, unsigned private_data_size,
369 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
370 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg,
371 int socket_id, unsigned flags)
373 #ifdef RTE_LIBRTE_XEN_DOM0
374 return (rte_dom0_mempool_create(name, n, elt_size,
375 cache_size, private_data_size,
376 mp_init, mp_init_arg,
377 obj_init, obj_init_arg,
380 return (rte_mempool_xmem_create(name, n, elt_size,
381 cache_size, private_data_size,
382 mp_init, mp_init_arg,
383 obj_init, obj_init_arg,
385 NULL, NULL, MEMPOOL_PG_NUM_DEFAULT, MEMPOOL_PG_SHIFT_MAX));
390 * Create the mempool over already allocated chunk of memory.
391 * That external memory buffer can consists of physically disjoint pages.
392 * Setting vaddr to NULL, makes mempool to fallback to original behaviour
393 * and allocate space for mempool and it's elements as one big chunk of
394 * physically continuos memory.
397 rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
398 unsigned cache_size, unsigned private_data_size,
399 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
400 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg,
401 int socket_id, unsigned flags, void *vaddr,
402 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift)
404 char mz_name[RTE_MEMZONE_NAMESIZE];
405 char rg_name[RTE_RING_NAMESIZE];
406 struct rte_mempool *mp = NULL;
408 const struct rte_memzone *mz;
410 int mz_flags = RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY;
413 struct rte_mempool_objsz objsz;
415 int page_size = getpagesize();
417 /* compilation-time checks */
418 RTE_BUILD_BUG_ON((sizeof(struct rte_mempool) &
419 CACHE_LINE_MASK) != 0);
420 #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0
421 RTE_BUILD_BUG_ON((sizeof(struct rte_mempool_cache) &
422 CACHE_LINE_MASK) != 0);
423 RTE_BUILD_BUG_ON((offsetof(struct rte_mempool, local_cache) &
424 CACHE_LINE_MASK) != 0);
426 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
427 RTE_BUILD_BUG_ON((sizeof(struct rte_mempool_debug_stats) &
428 CACHE_LINE_MASK) != 0);
429 RTE_BUILD_BUG_ON((offsetof(struct rte_mempool, stats) &
430 CACHE_LINE_MASK) != 0);
433 /* check that we have an initialised tail queue */
434 if (RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL,
435 rte_mempool_list) == NULL) {
436 rte_errno = E_RTE_NO_TAILQ;
440 /* asked cache too big */
441 if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE) {
446 /* check that we have both VA and PA */
447 if (vaddr != NULL && paddr == NULL) {
452 /* Check that pg_num and pg_shift parameters are valid. */
453 if (pg_num < RTE_DIM(mp->elt_pa) || pg_shift > MEMPOOL_PG_SHIFT_MAX) {
458 /* "no cache align" imply "no spread" */
459 if (flags & MEMPOOL_F_NO_CACHE_ALIGN)
460 flags |= MEMPOOL_F_NO_SPREAD;
463 if (flags & MEMPOOL_F_SP_PUT)
464 rg_flags |= RING_F_SP_ENQ;
465 if (flags & MEMPOOL_F_SC_GET)
466 rg_flags |= RING_F_SC_DEQ;
468 /* calculate mempool object sizes. */
469 if (!rte_mempool_calc_obj_size(elt_size, flags, &objsz)) {
474 rte_rwlock_write_lock(RTE_EAL_MEMPOOL_RWLOCK);
476 /* allocate the ring that will be used to store objects */
477 /* Ring functions will return appropriate errors if we are
478 * running as a secondary process etc., so no checks made
479 * in this function for that condition */
480 snprintf(rg_name, sizeof(rg_name), RTE_MEMPOOL_MZ_FORMAT, name);
481 r = rte_ring_create(rg_name, rte_align32pow2(n+1), socket_id, rg_flags);
486 * reserve a memory zone for this mempool: private data is
489 private_data_size = (private_data_size +
490 CACHE_LINE_MASK) & (~CACHE_LINE_MASK);
492 if (! rte_eal_has_hugepages()) {
494 * expand private data size to a whole page, so that the
495 * first pool element will start on a new standard page
497 int head = sizeof(struct rte_mempool);
498 int new_size = (private_data_size + head) % page_size;
500 private_data_size += page_size - new_size;
505 * If user provided an external memory buffer, then use it to
506 * store mempool objects. Otherwise reserve memzone big enough to
507 * hold mempool header and metadata plus mempool objects.
509 mempool_size = MEMPOOL_HEADER_SIZE(mp, pg_num) + private_data_size;
511 mempool_size += (size_t)objsz.total_size * n;
513 if (! rte_eal_has_hugepages()) {
515 * we want the memory pool to start on a page boundary,
516 * because pool elements crossing page boundaries would
517 * result in discontiguous physical addresses
519 mempool_size += page_size;
522 snprintf(mz_name, sizeof(mz_name), RTE_MEMPOOL_MZ_FORMAT, name);
524 mz = rte_memzone_reserve(mz_name, mempool_size, socket_id, mz_flags);
527 * no more memory: in this case we loose previously reserved
528 * space for the as we cannot free it
533 if (rte_eal_has_hugepages()) {
534 startaddr = (void*)mz->addr;
536 /* align memory pool start address on a page boundary */
537 unsigned long addr = (unsigned long)mz->addr;
538 if (addr & (page_size - 1)) {
540 addr &= ~(page_size - 1);
542 startaddr = (void*)addr;
545 /* init the mempool structure */
547 memset(mp, 0, sizeof(*mp));
548 snprintf(mp->name, sizeof(mp->name), "%s", name);
549 mp->phys_addr = mz->phys_addr;
553 mp->elt_size = objsz.elt_size;
554 mp->header_size = objsz.header_size;
555 mp->trailer_size = objsz.trailer_size;
556 mp->cache_size = cache_size;
557 mp->cache_flushthresh = (uint32_t)
558 (cache_size * CACHE_FLUSHTHRESH_MULTIPLIER);
559 mp->private_data_size = private_data_size;
561 /* calculate address of the first element for continuous mempool. */
562 obj = (char *)mp + MEMPOOL_HEADER_SIZE(mp, pg_num) +
565 /* populate address translation fields. */
567 mp->pg_shift = pg_shift;
568 mp->pg_mask = RTE_LEN2MASK(mp->pg_shift, typeof(mp->pg_mask));
570 /* mempool elements allocated together with mempool */
572 mp->elt_va_start = (uintptr_t)obj;
573 mp->elt_pa[0] = mp->phys_addr +
574 (mp->elt_va_start - (uintptr_t)mp);
576 /* mempool elements in a separate chunk of memory. */
578 mp->elt_va_start = (uintptr_t)vaddr;
579 memcpy(mp->elt_pa, paddr, sizeof (mp->elt_pa[0]) * pg_num);
582 mp->elt_va_end = mp->elt_va_start;
584 /* call the initializer */
586 mp_init(mp, mp_init_arg);
588 mempool_populate(mp, n, 1, obj_init, obj_init_arg);
590 RTE_EAL_TAILQ_INSERT_TAIL(RTE_TAILQ_MEMPOOL, rte_mempool_list, mp);
593 rte_rwlock_write_unlock(RTE_EAL_MEMPOOL_RWLOCK);
598 /* Return the number of entries in the mempool */
600 rte_mempool_count(const struct rte_mempool *mp)
604 count = rte_ring_count(mp->ring);
606 #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0
609 if (mp->cache_size == 0)
612 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
613 count += mp->local_cache[lcore_id].len;
618 * due to race condition (access to len is not locked), the
619 * total can be greater than size... so fix the result
621 if (count > mp->size)
626 /* dump the cache status */
628 rte_mempool_dump_cache(FILE *f, const struct rte_mempool *mp)
630 #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0
633 unsigned cache_count;
635 fprintf(f, " cache infos:\n");
636 fprintf(f, " cache_size=%"PRIu32"\n", mp->cache_size);
637 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
638 cache_count = mp->local_cache[lcore_id].len;
639 fprintf(f, " cache_count[%u]=%u\n", lcore_id, cache_count);
640 count += cache_count;
642 fprintf(f, " total_cache_count=%u\n", count);
646 fprintf(f, " cache disabled\n");
651 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
652 /* check cookies before and after objects */
653 #ifndef __INTEL_COMPILER
654 #pragma GCC diagnostic ignored "-Wcast-qual"
657 struct mempool_audit_arg {
658 const struct rte_mempool *mp;
664 mempool_obj_audit(void *arg, void *start, void *end, uint32_t idx)
666 struct mempool_audit_arg *pa = arg;
669 obj = (char *)start + pa->mp->header_size;
670 pa->obj_end = (uintptr_t)end;
671 pa->obj_num = idx + 1;
672 __mempool_check_cookies(pa->mp, &obj, 1, 2);
676 mempool_audit_cookies(const struct rte_mempool *mp)
678 uint32_t elt_sz, num;
679 struct mempool_audit_arg arg;
681 elt_sz = mp->elt_size + mp->header_size + mp->trailer_size;
684 arg.obj_end = mp->elt_va_start;
687 num = rte_mempool_obj_iter((void *)mp->elt_va_start,
689 mp->elt_pa, mp->pg_num, mp->pg_shift,
690 mempool_obj_audit, &arg);
692 if (num != mp->size) {
693 rte_panic("rte_mempool_obj_iter(mempool=%p, size=%u) "
694 "iterated only over %u elements\n",
696 } else if (arg.obj_end != mp->elt_va_end || arg.obj_num != mp->size) {
697 rte_panic("rte_mempool_obj_iter(mempool=%p, size=%u) "
698 "last callback va_end: %#tx (%#tx expeceted), "
699 "num of objects: %u (%u expected)\n",
701 arg.obj_end, mp->elt_va_end,
702 arg.obj_num, mp->size);
706 #ifndef __INTEL_COMPILER
707 #pragma GCC diagnostic error "-Wcast-qual"
710 #define mempool_audit_cookies(mp) do {} while(0)
713 #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0
714 /* check cookies before and after objects */
716 mempool_audit_cache(const struct rte_mempool *mp)
718 /* check cache size consistency */
720 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
721 if (mp->local_cache[lcore_id].len > mp->cache_flushthresh) {
722 RTE_LOG(CRIT, MEMPOOL, "badness on cache[%u]\n",
724 rte_panic("MEMPOOL: invalid cache len\n");
729 #define mempool_audit_cache(mp) do {} while(0)
733 /* check the consistency of mempool (size, cookies, ...) */
735 rte_mempool_audit(const struct rte_mempool *mp)
737 mempool_audit_cache(mp);
738 mempool_audit_cookies(mp);
740 /* For case where mempool DEBUG is not set, and cache size is 0 */
744 /* dump the status of the mempool on the console */
746 rte_mempool_dump(FILE *f, const struct rte_mempool *mp)
748 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
749 struct rte_mempool_debug_stats sum;
752 unsigned common_count;
753 unsigned cache_count;
755 fprintf(f, "mempool <%s>@%p\n", mp->name, mp);
756 fprintf(f, " flags=%x\n", mp->flags);
757 fprintf(f, " ring=<%s>@%p\n", mp->ring->name, mp->ring);
758 fprintf(f, " phys_addr=0x%" PRIx64 "\n", mp->phys_addr);
759 fprintf(f, " size=%"PRIu32"\n", mp->size);
760 fprintf(f, " header_size=%"PRIu32"\n", mp->header_size);
761 fprintf(f, " elt_size=%"PRIu32"\n", mp->elt_size);
762 fprintf(f, " trailer_size=%"PRIu32"\n", mp->trailer_size);
763 fprintf(f, " total_obj_size=%"PRIu32"\n",
764 mp->header_size + mp->elt_size + mp->trailer_size);
766 fprintf(f, " private_data_size=%"PRIu32"\n", mp->private_data_size);
767 fprintf(f, " pg_num=%"PRIu32"\n", mp->pg_num);
768 fprintf(f, " pg_shift=%"PRIu32"\n", mp->pg_shift);
769 fprintf(f, " pg_mask=%#tx\n", mp->pg_mask);
770 fprintf(f, " elt_va_start=%#tx\n", mp->elt_va_start);
771 fprintf(f, " elt_va_end=%#tx\n", mp->elt_va_end);
772 fprintf(f, " elt_pa[0]=0x%" PRIx64 "\n", mp->elt_pa[0]);
775 fprintf(f, " avg bytes/object=%#Lf\n",
776 (long double)(mp->elt_va_end - mp->elt_va_start) /
779 cache_count = rte_mempool_dump_cache(f, mp);
780 common_count = rte_ring_count(mp->ring);
781 if ((cache_count + common_count) > mp->size)
782 common_count = mp->size - cache_count;
783 fprintf(f, " common_pool_count=%u\n", common_count);
785 /* sum and dump statistics */
786 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
787 memset(&sum, 0, sizeof(sum));
788 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
789 sum.put_bulk += mp->stats[lcore_id].put_bulk;
790 sum.put_objs += mp->stats[lcore_id].put_objs;
791 sum.get_success_bulk += mp->stats[lcore_id].get_success_bulk;
792 sum.get_success_objs += mp->stats[lcore_id].get_success_objs;
793 sum.get_fail_bulk += mp->stats[lcore_id].get_fail_bulk;
794 sum.get_fail_objs += mp->stats[lcore_id].get_fail_objs;
796 fprintf(f, " stats:\n");
797 fprintf(f, " put_bulk=%"PRIu64"\n", sum.put_bulk);
798 fprintf(f, " put_objs=%"PRIu64"\n", sum.put_objs);
799 fprintf(f, " get_success_bulk=%"PRIu64"\n", sum.get_success_bulk);
800 fprintf(f, " get_success_objs=%"PRIu64"\n", sum.get_success_objs);
801 fprintf(f, " get_fail_bulk=%"PRIu64"\n", sum.get_fail_bulk);
802 fprintf(f, " get_fail_objs=%"PRIu64"\n", sum.get_fail_objs);
804 fprintf(f, " no statistics available\n");
807 rte_mempool_audit(mp);
810 /* dump the status of all mempools on the console */
812 rte_mempool_list_dump(FILE *f)
814 const struct rte_mempool *mp = NULL;
815 struct rte_mempool_list *mempool_list;
818 RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL, rte_mempool_list)) == NULL) {
819 rte_errno = E_RTE_NO_TAILQ;
823 rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK);
825 TAILQ_FOREACH(mp, mempool_list, next) {
826 rte_mempool_dump(f, mp);
829 rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK);
832 /* search a mempool from its name */
834 rte_mempool_lookup(const char *name)
836 struct rte_mempool *mp = NULL;
837 struct rte_mempool_list *mempool_list;
840 RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL, rte_mempool_list)) == NULL) {
841 rte_errno = E_RTE_NO_TAILQ;
845 rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK);
847 TAILQ_FOREACH(mp, mempool_list, next) {
848 if (strncmp(name, mp->name, RTE_MEMPOOL_NAMESIZE) == 0)
852 rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK);
860 void rte_mempool_walk(void (*func)(const struct rte_mempool *, void *),
863 struct rte_mempool *mp = NULL;
864 struct rte_mempool_list *mempool_list;
867 RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL, rte_mempool_list)) == NULL) {
868 rte_errno = E_RTE_NO_TAILQ;
872 rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK);
874 TAILQ_FOREACH(mp, mempool_list, next) {
878 rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK);