CNDP  22.08.0
mempool_private.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2019-2022 Intel Corporation.
3  * Copyright (c) 2016 6WIND S.A.
4  */
5 
6 #ifndef _MEMPOOL_PRIVATE_H_
7 #define _MEMPOOL_PRIVATE_H_
8 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <stdint.h>
19 #include <inttypes.h>
20 
21 #include <cne_branch_prediction.h>
22 #include <cne_common.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define MEMPOOL_PG_SHIFT_MAX (sizeof(uintptr_t) * CHAR_BIT - 1)
29 
30 #ifndef CNE_MEMPOOL_ALIGN
31 #define CNE_MEMPOOL_ALIGN CNE_CACHE_LINE_SIZE
32 #endif
33 
34 #define CNE_MEMPOOL_ALIGN_MASK (CNE_MEMPOOL_ALIGN - 1)
35 
39 struct mempool_stats {
40  uint64_t put_bulk;
41  uint64_t put_objs;
42  uint64_t get_success_bulk;
43  uint64_t get_success_objs;
44  uint64_t get_fail_bulk;
45  uint64_t get_fail_objs;
46 } __cne_cache_aligned;
47 
53 struct mempool_cache {
54  uint32_t size;
55  uint32_t flushthresh;
56  uint32_t len;
57  /*
58  * Cache is allocated to this size to allow it to overflow in certain
59  * cases to avoid needless emptying of cache.
60  */
61  void *objs[MEMPOOL_CACHE_MAX_SIZE * 3];
62 } __cne_cache_aligned;
63 
64 struct cne_mempool {
65  void *objring;
66  void *objmem;
67  ssize_t objmem_sz;
68  uint32_t obj_cnt;
69  uint32_t obj_sz;
70  uint32_t cache_sz;
71  uint32_t populated_sz;
72  uint32_t free_objmem;
73  struct mempool_cache *cache;
74  struct mempool_stats *stats;
75 } __cne_cache_aligned;
76 
77 // clang-format off
78 #define __MEMPOOL_STAT_ADD(mp, name, n) do { \
79  int __uid = cne_id(); \
80  mp->stats[__uid].name##_objs += n; \
81  mp->stats[__uid].name##_bulk += 1; \
82  } while(0)
83 // clang-format on
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 #endif /* _MEMPOOL_PRIVATE_H_ */
uint32_t flushthresh
void * objs[MEMPOOL_CACHE_MAX_SIZE *3]
uint64_t get_success_objs
uint64_t put_objs
uint64_t get_success_bulk
uint64_t put_bulk
uint64_t get_fail_objs
uint64_t get_fail_bulk