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_malloc.h>
49 #include <rte_atomic.h>
50 #include <rte_launch.h>
51 #include <rte_tailq.h>
53 #include <rte_eal_memconfig.h>
54 #include <rte_per_lcore.h>
55 #include <rte_lcore.h>
56 #include <rte_branch_prediction.h>
58 #include <rte_errno.h>
59 #include <rte_string_fns.h>
60 #include <rte_spinlock.h>
62 #include "rte_mempool.h"
64 TAILQ_HEAD(rte_mempool_list, rte_tailq_entry);
66 #define CACHE_FLUSHTHRESH_MULTIPLIER 1.5
69 * return the greatest common divisor between a and b (fast algorithm)
72 static unsigned get_gcd(unsigned a, unsigned b)
97 * Depending on memory configuration, objects addresses are spread
98 * between channels and ranks in RAM: the pool allocator will add
99 * padding between objects. This function return the new size of the
102 static unsigned optimize_object_size(unsigned obj_size)
104 unsigned nrank, nchan;
105 unsigned new_obj_size;
107 /* get number of channels */
108 nchan = rte_memory_get_nchannel();
112 nrank = rte_memory_get_nrank();
116 /* process new object size */
117 new_obj_size = (obj_size + CACHE_LINE_MASK) / CACHE_LINE_SIZE;
118 while (get_gcd(new_obj_size, nrank * nchan) != 1)
120 return new_obj_size * CACHE_LINE_SIZE;
124 mempool_add_elem(struct rte_mempool *mp, void *obj, uint32_t obj_idx,
125 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg)
127 struct rte_mempool **mpp;
129 obj = (char *)obj + mp->header_size;
131 /* set mempool ptr in header */
132 mpp = __mempool_from_obj(obj);
135 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
136 __mempool_write_header_cookie(obj, 1);
137 __mempool_write_trailer_cookie(obj);
139 /* call the initializer */
141 obj_init(mp, obj_init_arg, obj, obj_idx);
143 /* enqueue in ring */
144 rte_ring_sp_enqueue(mp->ring, obj);
148 rte_mempool_obj_iter(void *vaddr, uint32_t elt_num, size_t elt_sz, size_t align,
149 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift,
150 rte_mempool_obj_iter_t obj_iter, void *obj_iter_arg)
154 uintptr_t end, start, va;
157 pg_sz = (uintptr_t)1 << pg_shift;
158 va = (uintptr_t)vaddr;
163 while (i != elt_num && j != pg_num) {
165 start = RTE_ALIGN_CEIL(va, align);
166 end = start + elt_sz;
168 pgn = (end >> pg_shift) - (start >> pg_shift);
171 /* do we have enough space left for the next element. */
177 paddr[k] + pg_sz == paddr[k + 1];
182 * if next pgn chunks of memory physically continuous,
183 * use it to create next element.
184 * otherwise, just skip that chunk unused.
187 if (obj_iter != NULL)
188 obj_iter(obj_iter_arg, (void *)start,
194 va = RTE_ALIGN_CEIL((va + 1), pg_sz);
203 * Populate mempool with the objects.
206 struct mempool_populate_arg {
207 struct rte_mempool *mp;
208 rte_mempool_obj_ctor_t *obj_init;
213 mempool_obj_populate(void *arg, void *start, void *end, uint32_t idx)
215 struct mempool_populate_arg *pa = arg;
217 mempool_add_elem(pa->mp, start, idx, pa->obj_init, pa->obj_init_arg);
218 pa->mp->elt_va_end = (uintptr_t)end;
222 mempool_populate(struct rte_mempool *mp, size_t num, size_t align,
223 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg)
226 struct mempool_populate_arg arg;
228 elt_sz = mp->elt_size + mp->header_size + mp->trailer_size;
230 arg.obj_init = obj_init;
231 arg.obj_init_arg = obj_init_arg;
233 mp->size = rte_mempool_obj_iter((void *)mp->elt_va_start,
235 mp->elt_pa, mp->pg_num, mp->pg_shift,
236 mempool_obj_populate, &arg);
240 rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
241 struct rte_mempool_objsz *sz)
243 struct rte_mempool_objsz lsz;
245 sz = (sz != NULL) ? sz : &lsz;
248 * In header, we have at least the pointer to the pool, and
249 * optionaly a 64 bits cookie.
252 sz->header_size += sizeof(struct rte_mempool *); /* ptr to pool */
253 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
254 sz->header_size += sizeof(uint64_t); /* cookie */
256 if ((flags & MEMPOOL_F_NO_CACHE_ALIGN) == 0)
257 sz->header_size = RTE_ALIGN_CEIL(sz->header_size,
260 /* trailer contains the cookie in debug mode */
261 sz->trailer_size = 0;
262 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
263 sz->trailer_size += sizeof(uint64_t); /* cookie */
265 /* element size is 8 bytes-aligned at least */
266 sz->elt_size = RTE_ALIGN_CEIL(elt_size, sizeof(uint64_t));
268 /* expand trailer to next cache line */
269 if ((flags & MEMPOOL_F_NO_CACHE_ALIGN) == 0) {
270 sz->total_size = sz->header_size + sz->elt_size +
272 sz->trailer_size += ((CACHE_LINE_SIZE -
273 (sz->total_size & CACHE_LINE_MASK)) &
278 * increase trailer to add padding between objects in order to
279 * spread them across memory channels/ranks
281 if ((flags & MEMPOOL_F_NO_SPREAD) == 0) {
283 new_size = optimize_object_size(sz->header_size + sz->elt_size +
285 sz->trailer_size = new_size - sz->header_size - sz->elt_size;
288 if (! rte_eal_has_hugepages()) {
290 * compute trailer size so that pool elements fit exactly in
293 int page_size = getpagesize();
294 int new_size = page_size - sz->header_size - sz->elt_size;
295 if (new_size < 0 || (unsigned int)new_size < sz->trailer_size) {
296 printf("When hugepages are disabled, pool objects "
297 "can't exceed PAGE_SIZE: %d + %d + %d > %d\n",
298 sz->header_size, sz->elt_size, sz->trailer_size,
302 sz->trailer_size = new_size;
305 /* this is the size of an object, including header and trailer */
306 sz->total_size = sz->header_size + sz->elt_size + sz->trailer_size;
308 return (sz->total_size);
313 * Calculate maximum amount of memory required to store given number of objects.
316 rte_mempool_xmem_size(uint32_t elt_num, size_t elt_sz, uint32_t pg_shift)
318 size_t n, pg_num, pg_sz, sz;
320 pg_sz = (size_t)1 << pg_shift;
322 if ((n = pg_sz / elt_sz) > 0) {
323 pg_num = (elt_num + n - 1) / n;
324 sz = pg_num << pg_shift;
326 sz = RTE_ALIGN_CEIL(elt_sz, pg_sz) * elt_num;
333 * Calculate how much memory would be actually required with the
334 * given memory footprint to store required number of elements.
337 mempool_lelem_iter(void *arg, __rte_unused void *start, void *end,
338 __rte_unused uint32_t idx)
340 *(uintptr_t *)arg = (uintptr_t)end;
344 rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num, size_t elt_sz,
345 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift)
351 pg_sz = (size_t)1 << pg_shift;
352 va = (uintptr_t)vaddr;
355 if ((n = rte_mempool_obj_iter(vaddr, elt_num, elt_sz, 1,
356 paddr, pg_num, pg_shift, mempool_lelem_iter,
361 uv = RTE_ALIGN_CEIL(uv, pg_sz);
366 /* create the mempool */
368 rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
369 unsigned cache_size, unsigned private_data_size,
370 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
371 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg,
372 int socket_id, unsigned flags)
374 #ifdef RTE_LIBRTE_XEN_DOM0
375 return (rte_dom0_mempool_create(name, n, elt_size,
376 cache_size, private_data_size,
377 mp_init, mp_init_arg,
378 obj_init, obj_init_arg,
381 return (rte_mempool_xmem_create(name, n, elt_size,
382 cache_size, private_data_size,
383 mp_init, mp_init_arg,
384 obj_init, obj_init_arg,
386 NULL, NULL, MEMPOOL_PG_NUM_DEFAULT, MEMPOOL_PG_SHIFT_MAX));
391 * Create the mempool over already allocated chunk of memory.
392 * That external memory buffer can consists of physically disjoint pages.
393 * Setting vaddr to NULL, makes mempool to fallback to original behaviour
394 * and allocate space for mempool and it's elements as one big chunk of
395 * physically continuos memory.
398 rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
399 unsigned cache_size, unsigned private_data_size,
400 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
401 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg,
402 int socket_id, unsigned flags, void *vaddr,
403 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift)
405 char mz_name[RTE_MEMZONE_NAMESIZE];
406 char rg_name[RTE_RING_NAMESIZE];
407 struct rte_mempool *mp = NULL;
408 struct rte_tailq_entry *te;
410 const struct rte_memzone *mz;
412 int mz_flags = RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY;
415 struct rte_mempool_objsz objsz;
417 int page_size = getpagesize();
419 /* compilation-time checks */
420 RTE_BUILD_BUG_ON((sizeof(struct rte_mempool) &
421 CACHE_LINE_MASK) != 0);
422 #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0
423 RTE_BUILD_BUG_ON((sizeof(struct rte_mempool_cache) &
424 CACHE_LINE_MASK) != 0);
425 RTE_BUILD_BUG_ON((offsetof(struct rte_mempool, local_cache) &
426 CACHE_LINE_MASK) != 0);
428 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
429 RTE_BUILD_BUG_ON((sizeof(struct rte_mempool_debug_stats) &
430 CACHE_LINE_MASK) != 0);
431 RTE_BUILD_BUG_ON((offsetof(struct rte_mempool, stats) &
432 CACHE_LINE_MASK) != 0);
435 /* check that we have an initialised tail queue */
436 if (RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL,
437 rte_mempool_list) == NULL) {
438 rte_errno = E_RTE_NO_TAILQ;
442 /* asked cache too big */
443 if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE) {
448 /* check that we have both VA and PA */
449 if (vaddr != NULL && paddr == NULL) {
454 /* Check that pg_num and pg_shift parameters are valid. */
455 if (pg_num < RTE_DIM(mp->elt_pa) || pg_shift > MEMPOOL_PG_SHIFT_MAX) {
460 /* "no cache align" imply "no spread" */
461 if (flags & MEMPOOL_F_NO_CACHE_ALIGN)
462 flags |= MEMPOOL_F_NO_SPREAD;
465 if (flags & MEMPOOL_F_SP_PUT)
466 rg_flags |= RING_F_SP_ENQ;
467 if (flags & MEMPOOL_F_SC_GET)
468 rg_flags |= RING_F_SC_DEQ;
470 /* calculate mempool object sizes. */
471 if (!rte_mempool_calc_obj_size(elt_size, flags, &objsz)) {
476 rte_rwlock_write_lock(RTE_EAL_MEMPOOL_RWLOCK);
478 /* allocate the ring that will be used to store objects */
479 /* Ring functions will return appropriate errors if we are
480 * running as a secondary process etc., so no checks made
481 * in this function for that condition */
482 snprintf(rg_name, sizeof(rg_name), RTE_MEMPOOL_MZ_FORMAT, name);
483 r = rte_ring_create(rg_name, rte_align32pow2(n+1), socket_id, rg_flags);
488 * reserve a memory zone for this mempool: private data is
491 private_data_size = (private_data_size +
492 CACHE_LINE_MASK) & (~CACHE_LINE_MASK);
494 if (! rte_eal_has_hugepages()) {
496 * expand private data size to a whole page, so that the
497 * first pool element will start on a new standard page
499 int head = sizeof(struct rte_mempool);
500 int new_size = (private_data_size + head) % page_size;
502 private_data_size += page_size - new_size;
506 /* try to allocate tailq entry */
507 te = rte_zmalloc("MEMPOOL_TAILQ_ENTRY", sizeof(*te), 0);
509 RTE_LOG(ERR, MEMPOOL, "Cannot allocate tailq entry!\n");
514 * If user provided an external memory buffer, then use it to
515 * store mempool objects. Otherwise reserve memzone big enough to
516 * hold mempool header and metadata plus mempool objects.
518 mempool_size = MEMPOOL_HEADER_SIZE(mp, pg_num) + private_data_size;
520 mempool_size += (size_t)objsz.total_size * n;
522 if (! rte_eal_has_hugepages()) {
524 * we want the memory pool to start on a page boundary,
525 * because pool elements crossing page boundaries would
526 * result in discontiguous physical addresses
528 mempool_size += page_size;
531 snprintf(mz_name, sizeof(mz_name), RTE_MEMPOOL_MZ_FORMAT, name);
533 mz = rte_memzone_reserve(mz_name, mempool_size, socket_id, mz_flags);
536 * no more memory: in this case we loose previously reserved
537 * space for the as we cannot free it
544 if (rte_eal_has_hugepages()) {
545 startaddr = (void*)mz->addr;
547 /* align memory pool start address on a page boundary */
548 unsigned long addr = (unsigned long)mz->addr;
549 if (addr & (page_size - 1)) {
551 addr &= ~(page_size - 1);
553 startaddr = (void*)addr;
556 /* init the mempool structure */
558 memset(mp, 0, sizeof(*mp));
559 snprintf(mp->name, sizeof(mp->name), "%s", name);
560 mp->phys_addr = mz->phys_addr;
564 mp->elt_size = objsz.elt_size;
565 mp->header_size = objsz.header_size;
566 mp->trailer_size = objsz.trailer_size;
567 mp->cache_size = cache_size;
568 mp->cache_flushthresh = (uint32_t)
569 (cache_size * CACHE_FLUSHTHRESH_MULTIPLIER);
570 mp->private_data_size = private_data_size;
572 /* calculate address of the first element for continuous mempool. */
573 obj = (char *)mp + MEMPOOL_HEADER_SIZE(mp, pg_num) +
576 /* populate address translation fields. */
578 mp->pg_shift = pg_shift;
579 mp->pg_mask = RTE_LEN2MASK(mp->pg_shift, typeof(mp->pg_mask));
581 /* mempool elements allocated together with mempool */
583 mp->elt_va_start = (uintptr_t)obj;
584 mp->elt_pa[0] = mp->phys_addr +
585 (mp->elt_va_start - (uintptr_t)mp);
587 /* mempool elements in a separate chunk of memory. */
589 mp->elt_va_start = (uintptr_t)vaddr;
590 memcpy(mp->elt_pa, paddr, sizeof (mp->elt_pa[0]) * pg_num);
593 mp->elt_va_end = mp->elt_va_start;
595 /* call the initializer */
597 mp_init(mp, mp_init_arg);
599 mempool_populate(mp, n, 1, obj_init, obj_init_arg);
601 te->data = (void *) mp;
603 RTE_EAL_TAILQ_INSERT_TAIL(RTE_TAILQ_MEMPOOL, rte_mempool_list, te);
606 rte_rwlock_write_unlock(RTE_EAL_MEMPOOL_RWLOCK);
611 /* Return the number of entries in the mempool */
613 rte_mempool_count(const struct rte_mempool *mp)
617 count = rte_ring_count(mp->ring);
619 #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0
622 if (mp->cache_size == 0)
625 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
626 count += mp->local_cache[lcore_id].len;
631 * due to race condition (access to len is not locked), the
632 * total can be greater than size... so fix the result
634 if (count > mp->size)
639 /* dump the cache status */
641 rte_mempool_dump_cache(FILE *f, const struct rte_mempool *mp)
643 #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0
646 unsigned cache_count;
648 fprintf(f, " cache infos:\n");
649 fprintf(f, " cache_size=%"PRIu32"\n", mp->cache_size);
650 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
651 cache_count = mp->local_cache[lcore_id].len;
652 fprintf(f, " cache_count[%u]=%u\n", lcore_id, cache_count);
653 count += cache_count;
655 fprintf(f, " total_cache_count=%u\n", count);
659 fprintf(f, " cache disabled\n");
664 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
665 /* check cookies before and after objects */
666 #ifndef __INTEL_COMPILER
667 #pragma GCC diagnostic ignored "-Wcast-qual"
670 struct mempool_audit_arg {
671 const struct rte_mempool *mp;
677 mempool_obj_audit(void *arg, void *start, void *end, uint32_t idx)
679 struct mempool_audit_arg *pa = arg;
682 obj = (char *)start + pa->mp->header_size;
683 pa->obj_end = (uintptr_t)end;
684 pa->obj_num = idx + 1;
685 __mempool_check_cookies(pa->mp, &obj, 1, 2);
689 mempool_audit_cookies(const struct rte_mempool *mp)
691 uint32_t elt_sz, num;
692 struct mempool_audit_arg arg;
694 elt_sz = mp->elt_size + mp->header_size + mp->trailer_size;
697 arg.obj_end = mp->elt_va_start;
700 num = rte_mempool_obj_iter((void *)mp->elt_va_start,
702 mp->elt_pa, mp->pg_num, mp->pg_shift,
703 mempool_obj_audit, &arg);
705 if (num != mp->size) {
706 rte_panic("rte_mempool_obj_iter(mempool=%p, size=%u) "
707 "iterated only over %u elements\n",
709 } else if (arg.obj_end != mp->elt_va_end || arg.obj_num != mp->size) {
710 rte_panic("rte_mempool_obj_iter(mempool=%p, size=%u) "
711 "last callback va_end: %#tx (%#tx expeceted), "
712 "num of objects: %u (%u expected)\n",
714 arg.obj_end, mp->elt_va_end,
715 arg.obj_num, mp->size);
719 #ifndef __INTEL_COMPILER
720 #pragma GCC diagnostic error "-Wcast-qual"
723 #define mempool_audit_cookies(mp) do {} while(0)
726 #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0
727 /* check cookies before and after objects */
729 mempool_audit_cache(const struct rte_mempool *mp)
731 /* check cache size consistency */
733 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
734 if (mp->local_cache[lcore_id].len > mp->cache_flushthresh) {
735 RTE_LOG(CRIT, MEMPOOL, "badness on cache[%u]\n",
737 rte_panic("MEMPOOL: invalid cache len\n");
742 #define mempool_audit_cache(mp) do {} while(0)
746 /* check the consistency of mempool (size, cookies, ...) */
748 rte_mempool_audit(const struct rte_mempool *mp)
750 mempool_audit_cache(mp);
751 mempool_audit_cookies(mp);
753 /* For case where mempool DEBUG is not set, and cache size is 0 */
757 /* dump the status of the mempool on the console */
759 rte_mempool_dump(FILE *f, const struct rte_mempool *mp)
761 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
762 struct rte_mempool_debug_stats sum;
765 unsigned common_count;
766 unsigned cache_count;
768 fprintf(f, "mempool <%s>@%p\n", mp->name, mp);
769 fprintf(f, " flags=%x\n", mp->flags);
770 fprintf(f, " ring=<%s>@%p\n", mp->ring->name, mp->ring);
771 fprintf(f, " phys_addr=0x%" PRIx64 "\n", mp->phys_addr);
772 fprintf(f, " size=%"PRIu32"\n", mp->size);
773 fprintf(f, " header_size=%"PRIu32"\n", mp->header_size);
774 fprintf(f, " elt_size=%"PRIu32"\n", mp->elt_size);
775 fprintf(f, " trailer_size=%"PRIu32"\n", mp->trailer_size);
776 fprintf(f, " total_obj_size=%"PRIu32"\n",
777 mp->header_size + mp->elt_size + mp->trailer_size);
779 fprintf(f, " private_data_size=%"PRIu32"\n", mp->private_data_size);
780 fprintf(f, " pg_num=%"PRIu32"\n", mp->pg_num);
781 fprintf(f, " pg_shift=%"PRIu32"\n", mp->pg_shift);
782 fprintf(f, " pg_mask=%#tx\n", mp->pg_mask);
783 fprintf(f, " elt_va_start=%#tx\n", mp->elt_va_start);
784 fprintf(f, " elt_va_end=%#tx\n", mp->elt_va_end);
785 fprintf(f, " elt_pa[0]=0x%" PRIx64 "\n", mp->elt_pa[0]);
788 fprintf(f, " avg bytes/object=%#Lf\n",
789 (long double)(mp->elt_va_end - mp->elt_va_start) /
792 cache_count = rte_mempool_dump_cache(f, mp);
793 common_count = rte_ring_count(mp->ring);
794 if ((cache_count + common_count) > mp->size)
795 common_count = mp->size - cache_count;
796 fprintf(f, " common_pool_count=%u\n", common_count);
798 /* sum and dump statistics */
799 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
800 memset(&sum, 0, sizeof(sum));
801 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
802 sum.put_bulk += mp->stats[lcore_id].put_bulk;
803 sum.put_objs += mp->stats[lcore_id].put_objs;
804 sum.get_success_bulk += mp->stats[lcore_id].get_success_bulk;
805 sum.get_success_objs += mp->stats[lcore_id].get_success_objs;
806 sum.get_fail_bulk += mp->stats[lcore_id].get_fail_bulk;
807 sum.get_fail_objs += mp->stats[lcore_id].get_fail_objs;
809 fprintf(f, " stats:\n");
810 fprintf(f, " put_bulk=%"PRIu64"\n", sum.put_bulk);
811 fprintf(f, " put_objs=%"PRIu64"\n", sum.put_objs);
812 fprintf(f, " get_success_bulk=%"PRIu64"\n", sum.get_success_bulk);
813 fprintf(f, " get_success_objs=%"PRIu64"\n", sum.get_success_objs);
814 fprintf(f, " get_fail_bulk=%"PRIu64"\n", sum.get_fail_bulk);
815 fprintf(f, " get_fail_objs=%"PRIu64"\n", sum.get_fail_objs);
817 fprintf(f, " no statistics available\n");
820 rte_mempool_audit(mp);
823 /* dump the status of all mempools on the console */
825 rte_mempool_list_dump(FILE *f)
827 const struct rte_mempool *mp = NULL;
828 struct rte_tailq_entry *te;
829 struct rte_mempool_list *mempool_list;
832 RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL, rte_mempool_list)) == NULL) {
833 rte_errno = E_RTE_NO_TAILQ;
837 rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK);
839 TAILQ_FOREACH(te, mempool_list, next) {
840 mp = (struct rte_mempool *) te->data;
841 rte_mempool_dump(f, mp);
844 rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK);
847 /* search a mempool from its name */
849 rte_mempool_lookup(const char *name)
851 struct rte_mempool *mp = NULL;
852 struct rte_tailq_entry *te;
853 struct rte_mempool_list *mempool_list;
856 RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL, rte_mempool_list)) == NULL) {
857 rte_errno = E_RTE_NO_TAILQ;
861 rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK);
863 TAILQ_FOREACH(te, mempool_list, next) {
864 mp = (struct rte_mempool *) te->data;
865 if (strncmp(name, mp->name, RTE_MEMPOOL_NAMESIZE) == 0)
869 rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK);
879 void rte_mempool_walk(void (*func)(const struct rte_mempool *, void *),
882 struct rte_tailq_entry *te = NULL;
883 struct rte_mempool_list *mempool_list;
886 RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL, rte_mempool_list)) == NULL) {
887 rte_errno = E_RTE_NO_TAILQ;
891 rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK);
893 TAILQ_FOREACH(te, mempool_list, next) {
894 (*func)((struct rte_mempool *) te->data, arg);
897 rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK);