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>
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_tailq_entry);
65 static struct rte_tailq_elem rte_mempool_tailq = {
66 .name = "RTE_MEMPOOL",
68 EAL_REGISTER_TAILQ(rte_mempool_tailq)
70 #define CACHE_FLUSHTHRESH_MULTIPLIER 1.5
71 #define CALC_CACHE_FLUSHTHRESH(c) \
72 ((typeof(c))((c) * CACHE_FLUSHTHRESH_MULTIPLIER))
75 * return the greatest common divisor between a and b (fast algorithm)
78 static unsigned get_gcd(unsigned a, unsigned b)
103 * Depending on memory configuration, objects addresses are spread
104 * between channels and ranks in RAM: the pool allocator will add
105 * padding between objects. This function return the new size of the
108 static unsigned optimize_object_size(unsigned obj_size)
110 unsigned nrank, nchan;
111 unsigned new_obj_size;
113 /* get number of channels */
114 nchan = rte_memory_get_nchannel();
118 nrank = rte_memory_get_nrank();
122 /* process new object size */
123 new_obj_size = (obj_size + RTE_CACHE_LINE_MASK) / RTE_CACHE_LINE_SIZE;
124 while (get_gcd(new_obj_size, nrank * nchan) != 1)
126 return new_obj_size * RTE_CACHE_LINE_SIZE;
130 mempool_add_elem(struct rte_mempool *mp, void *obj, uint32_t obj_idx,
131 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg)
133 struct rte_mempool **mpp;
135 obj = (char *)obj + mp->header_size;
137 /* set mempool ptr in header */
138 mpp = __mempool_from_obj(obj);
141 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
142 __mempool_write_header_cookie(obj, 1);
143 __mempool_write_trailer_cookie(obj);
145 /* call the initializer */
147 obj_init(mp, obj_init_arg, obj, obj_idx);
149 /* enqueue in ring */
150 rte_ring_sp_enqueue(mp->ring, obj);
154 rte_mempool_obj_iter(void *vaddr, uint32_t elt_num, size_t elt_sz, size_t align,
155 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift,
156 rte_mempool_obj_iter_t obj_iter, void *obj_iter_arg)
160 uintptr_t end, start, va;
163 pg_sz = (uintptr_t)1 << pg_shift;
164 va = (uintptr_t)vaddr;
169 while (i != elt_num && j != pg_num) {
171 start = RTE_ALIGN_CEIL(va, align);
172 end = start + elt_sz;
174 pgn = (end >> pg_shift) - (start >> pg_shift);
177 /* do we have enough space left for the next element. */
183 paddr[k] + pg_sz == paddr[k + 1];
188 * if next pgn chunks of memory physically continuous,
189 * use it to create next element.
190 * otherwise, just skip that chunk unused.
193 if (obj_iter != NULL)
194 obj_iter(obj_iter_arg, (void *)start,
200 va = RTE_ALIGN_CEIL((va + 1), pg_sz);
209 * Populate mempool with the objects.
212 struct mempool_populate_arg {
213 struct rte_mempool *mp;
214 rte_mempool_obj_ctor_t *obj_init;
219 mempool_obj_populate(void *arg, void *start, void *end, uint32_t idx)
221 struct mempool_populate_arg *pa = arg;
223 mempool_add_elem(pa->mp, start, idx, pa->obj_init, pa->obj_init_arg);
224 pa->mp->elt_va_end = (uintptr_t)end;
228 mempool_populate(struct rte_mempool *mp, size_t num, size_t align,
229 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg)
232 struct mempool_populate_arg arg;
234 elt_sz = mp->elt_size + mp->header_size + mp->trailer_size;
236 arg.obj_init = obj_init;
237 arg.obj_init_arg = obj_init_arg;
239 mp->size = rte_mempool_obj_iter((void *)mp->elt_va_start,
241 mp->elt_pa, mp->pg_num, mp->pg_shift,
242 mempool_obj_populate, &arg);
246 rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
247 struct rte_mempool_objsz *sz)
249 struct rte_mempool_objsz lsz;
251 sz = (sz != NULL) ? sz : &lsz;
254 * In header, we have at least the pointer to the pool, and
255 * optionaly a 64 bits cookie.
258 sz->header_size += sizeof(struct rte_mempool *); /* ptr to pool */
259 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
260 sz->header_size += sizeof(uint64_t); /* cookie */
262 if ((flags & MEMPOOL_F_NO_CACHE_ALIGN) == 0)
263 sz->header_size = RTE_ALIGN_CEIL(sz->header_size,
264 RTE_CACHE_LINE_SIZE);
266 /* trailer contains the cookie in debug mode */
267 sz->trailer_size = 0;
268 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
269 sz->trailer_size += sizeof(uint64_t); /* cookie */
271 /* element size is 8 bytes-aligned at least */
272 sz->elt_size = RTE_ALIGN_CEIL(elt_size, sizeof(uint64_t));
274 /* expand trailer to next cache line */
275 if ((flags & MEMPOOL_F_NO_CACHE_ALIGN) == 0) {
276 sz->total_size = sz->header_size + sz->elt_size +
278 sz->trailer_size += ((RTE_CACHE_LINE_SIZE -
279 (sz->total_size & RTE_CACHE_LINE_MASK)) &
280 RTE_CACHE_LINE_MASK);
284 * increase trailer to add padding between objects in order to
285 * spread them across memory channels/ranks
287 if ((flags & MEMPOOL_F_NO_SPREAD) == 0) {
289 new_size = optimize_object_size(sz->header_size + sz->elt_size +
291 sz->trailer_size = new_size - sz->header_size - sz->elt_size;
294 if (! rte_eal_has_hugepages()) {
296 * compute trailer size so that pool elements fit exactly in
299 int page_size = getpagesize();
300 int new_size = page_size - sz->header_size - sz->elt_size;
301 if (new_size < 0 || (unsigned int)new_size < sz->trailer_size) {
302 printf("When hugepages are disabled, pool objects "
303 "can't exceed PAGE_SIZE: %d + %d + %d > %d\n",
304 sz->header_size, sz->elt_size, sz->trailer_size,
308 sz->trailer_size = new_size;
311 /* this is the size of an object, including header and trailer */
312 sz->total_size = sz->header_size + sz->elt_size + sz->trailer_size;
314 return (sz->total_size);
319 * Calculate maximum amount of memory required to store given number of objects.
322 rte_mempool_xmem_size(uint32_t elt_num, size_t elt_sz, uint32_t pg_shift)
324 size_t n, pg_num, pg_sz, sz;
326 pg_sz = (size_t)1 << pg_shift;
328 if ((n = pg_sz / elt_sz) > 0) {
329 pg_num = (elt_num + n - 1) / n;
330 sz = pg_num << pg_shift;
332 sz = RTE_ALIGN_CEIL(elt_sz, pg_sz) * elt_num;
339 * Calculate how much memory would be actually required with the
340 * given memory footprint to store required number of elements.
343 mempool_lelem_iter(void *arg, __rte_unused void *start, void *end,
344 __rte_unused uint32_t idx)
346 *(uintptr_t *)arg = (uintptr_t)end;
350 rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num, size_t elt_sz,
351 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift)
357 pg_sz = (size_t)1 << pg_shift;
358 va = (uintptr_t)vaddr;
361 if ((n = rte_mempool_obj_iter(vaddr, elt_num, elt_sz, 1,
362 paddr, pg_num, pg_shift, mempool_lelem_iter,
364 return (-(ssize_t)n);
367 uv = RTE_ALIGN_CEIL(uv, pg_sz);
372 /* create the mempool */
374 rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
375 unsigned cache_size, unsigned private_data_size,
376 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
377 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg,
378 int socket_id, unsigned flags)
380 #ifdef RTE_LIBRTE_XEN_DOM0
381 return (rte_dom0_mempool_create(name, n, elt_size,
382 cache_size, private_data_size,
383 mp_init, mp_init_arg,
384 obj_init, obj_init_arg,
387 return (rte_mempool_xmem_create(name, n, elt_size,
388 cache_size, private_data_size,
389 mp_init, mp_init_arg,
390 obj_init, obj_init_arg,
392 NULL, NULL, MEMPOOL_PG_NUM_DEFAULT, MEMPOOL_PG_SHIFT_MAX));
397 * Create the mempool over already allocated chunk of memory.
398 * That external memory buffer can consists of physically disjoint pages.
399 * Setting vaddr to NULL, makes mempool to fallback to original behaviour
400 * and allocate space for mempool and it's elements as one big chunk of
401 * physically continuos memory.
404 rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
405 unsigned cache_size, unsigned private_data_size,
406 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
407 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg,
408 int socket_id, unsigned flags, void *vaddr,
409 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift)
411 char mz_name[RTE_MEMZONE_NAMESIZE];
412 char rg_name[RTE_RING_NAMESIZE];
413 struct rte_mempool_list *mempool_list;
414 struct rte_mempool *mp = NULL;
415 struct rte_tailq_entry *te;
417 const struct rte_memzone *mz;
419 int mz_flags = RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY;
422 struct rte_mempool_objsz objsz;
424 int page_size = getpagesize();
426 /* compilation-time checks */
427 RTE_BUILD_BUG_ON((sizeof(struct rte_mempool) &
428 RTE_CACHE_LINE_MASK) != 0);
429 #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0
430 RTE_BUILD_BUG_ON((sizeof(struct rte_mempool_cache) &
431 RTE_CACHE_LINE_MASK) != 0);
432 RTE_BUILD_BUG_ON((offsetof(struct rte_mempool, local_cache) &
433 RTE_CACHE_LINE_MASK) != 0);
435 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
436 RTE_BUILD_BUG_ON((sizeof(struct rte_mempool_debug_stats) &
437 RTE_CACHE_LINE_MASK) != 0);
438 RTE_BUILD_BUG_ON((offsetof(struct rte_mempool, stats) &
439 RTE_CACHE_LINE_MASK) != 0);
442 mempool_list = RTE_TAILQ_CAST(rte_mempool_tailq.head, rte_mempool_list);
444 /* asked cache too big */
445 if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE ||
446 CALC_CACHE_FLUSHTHRESH(cache_size) > n) {
451 /* check that we have both VA and PA */
452 if (vaddr != NULL && paddr == NULL) {
457 /* Check that pg_num and pg_shift parameters are valid. */
458 if (pg_num < RTE_DIM(mp->elt_pa) || pg_shift > MEMPOOL_PG_SHIFT_MAX) {
463 /* "no cache align" imply "no spread" */
464 if (flags & MEMPOOL_F_NO_CACHE_ALIGN)
465 flags |= MEMPOOL_F_NO_SPREAD;
468 if (flags & MEMPOOL_F_SP_PUT)
469 rg_flags |= RING_F_SP_ENQ;
470 if (flags & MEMPOOL_F_SC_GET)
471 rg_flags |= RING_F_SC_DEQ;
473 /* calculate mempool object sizes. */
474 if (!rte_mempool_calc_obj_size(elt_size, flags, &objsz)) {
479 rte_rwlock_write_lock(RTE_EAL_MEMPOOL_RWLOCK);
481 /* allocate the ring that will be used to store objects */
482 /* Ring functions will return appropriate errors if we are
483 * running as a secondary process etc., so no checks made
484 * in this function for that condition */
485 snprintf(rg_name, sizeof(rg_name), RTE_MEMPOOL_MZ_FORMAT, name);
486 r = rte_ring_create(rg_name, rte_align32pow2(n+1), socket_id, rg_flags);
491 * reserve a memory zone for this mempool: private data is
494 private_data_size = (private_data_size +
495 RTE_CACHE_LINE_MASK) & (~RTE_CACHE_LINE_MASK);
497 if (! rte_eal_has_hugepages()) {
499 * expand private data size to a whole page, so that the
500 * first pool element will start on a new standard page
502 int head = sizeof(struct rte_mempool);
503 int new_size = (private_data_size + head) % page_size;
505 private_data_size += page_size - new_size;
509 /* try to allocate tailq entry */
510 te = rte_zmalloc("MEMPOOL_TAILQ_ENTRY", sizeof(*te), 0);
512 RTE_LOG(ERR, MEMPOOL, "Cannot allocate tailq entry!\n");
517 * If user provided an external memory buffer, then use it to
518 * store mempool objects. Otherwise reserve memzone big enough to
519 * hold mempool header and metadata plus mempool objects.
521 mempool_size = MEMPOOL_HEADER_SIZE(mp, pg_num) + private_data_size;
523 mempool_size += (size_t)objsz.total_size * n;
525 if (! rte_eal_has_hugepages()) {
527 * we want the memory pool to start on a page boundary,
528 * because pool elements crossing page boundaries would
529 * result in discontiguous physical addresses
531 mempool_size += page_size;
534 snprintf(mz_name, sizeof(mz_name), RTE_MEMPOOL_MZ_FORMAT, name);
536 mz = rte_memzone_reserve(mz_name, mempool_size, socket_id, mz_flags);
539 * no more memory: in this case we loose previously reserved
540 * space for the as we cannot free it
547 if (rte_eal_has_hugepages()) {
548 startaddr = (void*)mz->addr;
550 /* align memory pool start address on a page boundary */
551 unsigned long addr = (unsigned long)mz->addr;
552 if (addr & (page_size - 1)) {
554 addr &= ~(page_size - 1);
556 startaddr = (void*)addr;
559 /* init the mempool structure */
561 memset(mp, 0, sizeof(*mp));
562 snprintf(mp->name, sizeof(mp->name), "%s", name);
563 mp->phys_addr = mz->phys_addr;
567 mp->elt_size = objsz.elt_size;
568 mp->header_size = objsz.header_size;
569 mp->trailer_size = objsz.trailer_size;
570 mp->cache_size = cache_size;
571 mp->cache_flushthresh = CALC_CACHE_FLUSHTHRESH(cache_size);
572 mp->private_data_size = private_data_size;
574 /* calculate address of the first element for continuous mempool. */
575 obj = (char *)mp + MEMPOOL_HEADER_SIZE(mp, pg_num) +
578 /* populate address translation fields. */
580 mp->pg_shift = pg_shift;
581 mp->pg_mask = RTE_LEN2MASK(mp->pg_shift, typeof(mp->pg_mask));
583 /* mempool elements allocated together with mempool */
585 mp->elt_va_start = (uintptr_t)obj;
586 mp->elt_pa[0] = mp->phys_addr +
587 (mp->elt_va_start - (uintptr_t)mp);
589 /* mempool elements in a separate chunk of memory. */
591 mp->elt_va_start = (uintptr_t)vaddr;
592 memcpy(mp->elt_pa, paddr, sizeof (mp->elt_pa[0]) * pg_num);
595 mp->elt_va_end = mp->elt_va_start;
597 /* call the initializer */
599 mp_init(mp, mp_init_arg);
601 mempool_populate(mp, n, 1, obj_init, obj_init_arg);
603 te->data = (void *) mp;
605 rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
606 TAILQ_INSERT_TAIL(mempool_list, te, next);
607 rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
610 rte_rwlock_write_unlock(RTE_EAL_MEMPOOL_RWLOCK);
615 /* Return the number of entries in the mempool */
617 rte_mempool_count(const struct rte_mempool *mp)
621 count = rte_ring_count(mp->ring);
623 #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0
626 if (mp->cache_size == 0)
629 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
630 count += mp->local_cache[lcore_id].len;
635 * due to race condition (access to len is not locked), the
636 * total can be greater than size... so fix the result
638 if (count > mp->size)
643 /* dump the cache status */
645 rte_mempool_dump_cache(FILE *f, const struct rte_mempool *mp)
647 #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0
650 unsigned cache_count;
652 fprintf(f, " cache infos:\n");
653 fprintf(f, " cache_size=%"PRIu32"\n", mp->cache_size);
654 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
655 cache_count = mp->local_cache[lcore_id].len;
656 fprintf(f, " cache_count[%u]=%u\n", lcore_id, cache_count);
657 count += cache_count;
659 fprintf(f, " total_cache_count=%u\n", count);
663 fprintf(f, " cache disabled\n");
668 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
669 /* check cookies before and after objects */
670 #ifndef __INTEL_COMPILER
671 #pragma GCC diagnostic ignored "-Wcast-qual"
674 struct mempool_audit_arg {
675 const struct rte_mempool *mp;
681 mempool_obj_audit(void *arg, void *start, void *end, uint32_t idx)
683 struct mempool_audit_arg *pa = arg;
686 obj = (char *)start + pa->mp->header_size;
687 pa->obj_end = (uintptr_t)end;
688 pa->obj_num = idx + 1;
689 __mempool_check_cookies(pa->mp, &obj, 1, 2);
693 mempool_audit_cookies(const struct rte_mempool *mp)
695 uint32_t elt_sz, num;
696 struct mempool_audit_arg arg;
698 elt_sz = mp->elt_size + mp->header_size + mp->trailer_size;
701 arg.obj_end = mp->elt_va_start;
704 num = rte_mempool_obj_iter((void *)mp->elt_va_start,
706 mp->elt_pa, mp->pg_num, mp->pg_shift,
707 mempool_obj_audit, &arg);
709 if (num != mp->size) {
710 rte_panic("rte_mempool_obj_iter(mempool=%p, size=%u) "
711 "iterated only over %u elements\n",
713 } else if (arg.obj_end != mp->elt_va_end || arg.obj_num != mp->size) {
714 rte_panic("rte_mempool_obj_iter(mempool=%p, size=%u) "
715 "last callback va_end: %#tx (%#tx expeceted), "
716 "num of objects: %u (%u expected)\n",
718 arg.obj_end, mp->elt_va_end,
719 arg.obj_num, mp->size);
723 #ifndef __INTEL_COMPILER
724 #pragma GCC diagnostic error "-Wcast-qual"
727 #define mempool_audit_cookies(mp) do {} while(0)
730 #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0
731 /* check cookies before and after objects */
733 mempool_audit_cache(const struct rte_mempool *mp)
735 /* check cache size consistency */
737 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
738 if (mp->local_cache[lcore_id].len > mp->cache_flushthresh) {
739 RTE_LOG(CRIT, MEMPOOL, "badness on cache[%u]\n",
741 rte_panic("MEMPOOL: invalid cache len\n");
746 #define mempool_audit_cache(mp) do {} while(0)
750 /* check the consistency of mempool (size, cookies, ...) */
752 rte_mempool_audit(const struct rte_mempool *mp)
754 mempool_audit_cache(mp);
755 mempool_audit_cookies(mp);
757 /* For case where mempool DEBUG is not set, and cache size is 0 */
761 /* dump the status of the mempool on the console */
763 rte_mempool_dump(FILE *f, const struct rte_mempool *mp)
765 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
766 struct rte_mempool_debug_stats sum;
769 unsigned common_count;
770 unsigned cache_count;
772 RTE_VERIFY(f != NULL);
773 RTE_VERIFY(mp != NULL);
775 fprintf(f, "mempool <%s>@%p\n", mp->name, mp);
776 fprintf(f, " flags=%x\n", mp->flags);
777 fprintf(f, " ring=<%s>@%p\n", mp->ring->name, mp->ring);
778 fprintf(f, " phys_addr=0x%" PRIx64 "\n", mp->phys_addr);
779 fprintf(f, " size=%"PRIu32"\n", mp->size);
780 fprintf(f, " header_size=%"PRIu32"\n", mp->header_size);
781 fprintf(f, " elt_size=%"PRIu32"\n", mp->elt_size);
782 fprintf(f, " trailer_size=%"PRIu32"\n", mp->trailer_size);
783 fprintf(f, " total_obj_size=%"PRIu32"\n",
784 mp->header_size + mp->elt_size + mp->trailer_size);
786 fprintf(f, " private_data_size=%"PRIu32"\n", mp->private_data_size);
787 fprintf(f, " pg_num=%"PRIu32"\n", mp->pg_num);
788 fprintf(f, " pg_shift=%"PRIu32"\n", mp->pg_shift);
789 fprintf(f, " pg_mask=%#tx\n", mp->pg_mask);
790 fprintf(f, " elt_va_start=%#tx\n", mp->elt_va_start);
791 fprintf(f, " elt_va_end=%#tx\n", mp->elt_va_end);
792 fprintf(f, " elt_pa[0]=0x%" PRIx64 "\n", mp->elt_pa[0]);
795 fprintf(f, " avg bytes/object=%#Lf\n",
796 (long double)(mp->elt_va_end - mp->elt_va_start) /
799 cache_count = rte_mempool_dump_cache(f, mp);
800 common_count = rte_ring_count(mp->ring);
801 if ((cache_count + common_count) > mp->size)
802 common_count = mp->size - cache_count;
803 fprintf(f, " common_pool_count=%u\n", common_count);
805 /* sum and dump statistics */
806 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
807 memset(&sum, 0, sizeof(sum));
808 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
809 sum.put_bulk += mp->stats[lcore_id].put_bulk;
810 sum.put_objs += mp->stats[lcore_id].put_objs;
811 sum.get_success_bulk += mp->stats[lcore_id].get_success_bulk;
812 sum.get_success_objs += mp->stats[lcore_id].get_success_objs;
813 sum.get_fail_bulk += mp->stats[lcore_id].get_fail_bulk;
814 sum.get_fail_objs += mp->stats[lcore_id].get_fail_objs;
816 fprintf(f, " stats:\n");
817 fprintf(f, " put_bulk=%"PRIu64"\n", sum.put_bulk);
818 fprintf(f, " put_objs=%"PRIu64"\n", sum.put_objs);
819 fprintf(f, " get_success_bulk=%"PRIu64"\n", sum.get_success_bulk);
820 fprintf(f, " get_success_objs=%"PRIu64"\n", sum.get_success_objs);
821 fprintf(f, " get_fail_bulk=%"PRIu64"\n", sum.get_fail_bulk);
822 fprintf(f, " get_fail_objs=%"PRIu64"\n", sum.get_fail_objs);
824 fprintf(f, " no statistics available\n");
827 rte_mempool_audit(mp);
830 /* dump the status of all mempools on the console */
832 rte_mempool_list_dump(FILE *f)
834 const struct rte_mempool *mp = NULL;
835 struct rte_tailq_entry *te;
836 struct rte_mempool_list *mempool_list;
838 mempool_list = RTE_TAILQ_CAST(rte_mempool_tailq.head, rte_mempool_list);
840 rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK);
842 TAILQ_FOREACH(te, mempool_list, next) {
843 mp = (struct rte_mempool *) te->data;
844 rte_mempool_dump(f, mp);
847 rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK);
850 /* search a mempool from its name */
852 rte_mempool_lookup(const char *name)
854 struct rte_mempool *mp = NULL;
855 struct rte_tailq_entry *te;
856 struct rte_mempool_list *mempool_list;
858 mempool_list = RTE_TAILQ_CAST(rte_mempool_tailq.head, rte_mempool_list);
860 rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK);
862 TAILQ_FOREACH(te, mempool_list, next) {
863 mp = (struct rte_mempool *) te->data;
864 if (strncmp(name, mp->name, RTE_MEMPOOL_NAMESIZE) == 0)
868 rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK);
878 void rte_mempool_walk(void (*func)(const struct rte_mempool *, void *),
881 struct rte_tailq_entry *te = NULL;
882 struct rte_mempool_list *mempool_list;
884 mempool_list = RTE_TAILQ_CAST(rte_mempool_tailq.head, rte_mempool_list);
886 rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK);
888 TAILQ_FOREACH(te, mempool_list, next) {
889 (*func)((struct rte_mempool *) te->data, arg);
892 rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK);