EM-ODP  3.7.0
Event Machine on ODP
em_pool.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Nokia Solutions and Networks
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef EM_POOL_H_
32 #define EM_POOL_H_
33 
34 /**
35  * @file
36  * EM internal event pool functions
37  *
38  */
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #define valid_pool(pool) ((unsigned int)pool_hdl2idx((pool)) < \
45  EM_CONFIG_POOLS)
46 #define invalid_pool(pool) ((unsigned int)pool_hdl2idx((pool)) > \
47  EM_CONFIG_POOLS - 1)
48 
49 int invalid_pool_cfg(const em_pool_cfg_t *pool_cfg,
50  const char **err_str/*out*/);
51 
52 int check_pool_uarea_persistence(const em_pool_cfg_t *pool_cfg,
53  const char **err_str/*out*/);
54 
56 pool_init(mpool_tbl_t *const mpool_tbl, mpool_pool_t *const mpool_pool,
57  const em_pool_cfg_t *default_pool_cfg);
58 
60 pool_term(const mpool_tbl_t *pool_tbl);
61 
62 em_pool_t
63 pool_create(const char *name, em_pool_t req_pool, const em_pool_cfg_t *pool_cfg);
64 
66 pool_delete(em_pool_t pool);
67 
68 em_pool_t
69 pool_find(const char *name);
70 
71 void pool_info_print_hdr(unsigned int num_pools);
72 void pool_info_print(em_pool_t pool);
73 
74 void pool_stats_print(em_pool_t pool);
75 
76 void subpools_stats_print(em_pool_t pool, const int subpools[], int num_subpools);
77 void pool_stats_selected_print(em_pool_t pool, const em_pool_stats_opt_t *opt);
78 void subpools_stats_selected_print(em_pool_t pool, const int subpools[],
79  int num_subpools, const em_pool_stats_opt_t *opt);
80 
81 void print_pool_elem_info(void);
82 
83 /** Convert pool handle to pool index */
84 static inline int
85 pool_hdl2idx(em_pool_t pool)
86 {
87  return (int)(uintptr_t)pool - 1;
88 }
89 
90 /** Convert pool index to pool handle */
91 static inline em_pool_t
92 pool_idx2hdl(int pool_idx)
93 {
94  return (em_pool_t)(uintptr_t)(pool_idx + 1);
95 }
96 
97 /** Returns pool element associated with pool handle */
98 static inline mpool_elem_t *
99 pool_elem_get(em_pool_t pool)
100 {
101  const int pool_idx = pool_hdl2idx(pool);
102  mpool_elem_t *mpool_elem;
103 
104  if (unlikely((unsigned int)pool_idx > EM_CONFIG_POOLS - 1))
105  return NULL;
106 
107  mpool_elem = &em_shm->mpool_tbl.pool[pool_idx];
108 
109  return mpool_elem;
110 }
111 
112 static inline int
113 pool_allocated(const mpool_elem_t *const mpool_elem)
114 {
115  return !objpool_in_pool(&mpool_elem->objpool_elem);
116 }
117 
118 static inline int
119 pool_find_subpool(const mpool_elem_t *const pool_elem, uint32_t size)
120 {
121  int subpool;
122 
123  /* Find the optimal subpool to allocate the event from */
124  for (subpool = 0; subpool < pool_elem->num_subpools &&
125  size > pool_elem->size[subpool]; subpool++)
126  ;
127 
128  if (unlikely(subpool >= pool_elem->num_subpools))
129  return -1;
130 
131  return subpool;
132 }
133 
134 unsigned int
135 pool_count(void);
136 
137 /**
138  * Get the EM event-pool that an odp-pool belongs to.
139  *
140  * An EM event-pool consists of up to EM_MAX_SUBPOOLS subpools (that are
141  * odp-pools) - a table (em_shm->mpool_tbl.pool_subpool_odp2em[]) contains the
142  * mapping and is populated during em_pool_create() calls.
143  */
144 static inline em_pool_t
145 pool_odp2em(odp_pool_t odp_pool)
146 {
147  /*
148  * 'idx' is in the range: 0 to odp_pool_max_index(), which is smaller
149  * than the length of the em_shm->mpool_tbl.pool_subpool_odp2em[] array
150  * (verified at startup in pool_init()).
151  */
152  int idx = odp_pool_index(odp_pool);
153 
154  if (unlikely(idx < 0))
155  return EM_POOL_UNDEF;
156 
157  return (em_pool_t)(uintptr_t)em_shm->mpool_tbl.pool_subpool_odp2em[idx].pool;
158 }
159 
160 /**
161  * Get the EM event-pool and subpool that an odp-pool belongs to.
162  *
163  * An EM event-pool consists of up to EM_MAX_SUBPOOLS subpools (that are
164  * odp-pools) - a table (em_shm->mpool_tbl.pool_subpool_odp2em[]) contains the
165  * mapping and is populated during em_pool_create() calls.
166  */
167 static inline pool_subpool_t
168 pool_subpool_odp2em(odp_pool_t odp_pool)
169 {
170  /*
171  * 'idx' is in the range: 0 to odp_pool_max_index(), which is smaller
172  * than the length of the em_shm->mpool_tbl.pool_subpool_odp2em[] array
173  * (verified at startup in pool_init()).
174  */
175  int idx = odp_pool_index(odp_pool);
176 
177  if (unlikely(idx < 0))
178  return pool_subpool_undef; /* .pool=EM_POOL_UNDEF, .subpool=0 */
179 
180  return em_shm->mpool_tbl.pool_subpool_odp2em[idx];
181 }
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 
187 #endif /* EM_POOL_H_ */
mpool_elem_t::size
uint16_t size
Definition: em_pool_types.h:55
pool_subpool_undef
const pool_subpool_t pool_subpool_undef
Undef value for a pool_subpool_t pool_subpool_undef = {.pool = EM_POOL_UNDEF, .subpool = 0};.
Definition: em_pool.c:59
pool_subpool_t
Definition: em_pool_types.h:100
mpool_elem_t::objpool_elem
objpool_elem_t objpool_elem
Definition: em_pool_types.h:73
em_pool_cfg_t
Definition: event_machine_pool.h:141
mpool_elem_t
Definition: em_pool_types.h:47
mpool_elem_t::num_subpools
int num_subpools
Definition: em_pool_types.h:65
mpool_pool_t
Definition: em_pool_types.h:136
em_status_t
uint32_t em_status_t
Definition: event_machine_types.h:321
mpool_tbl_t
Definition: em_pool_types.h:119
em_shm
em_shm_t * em_shm
Definition: event_machine_init.c:41
em_pool_stats_opt_t
Definition: event_machine_pool.h:98
EM_POOL_UNDEF
#define EM_POOL_UNDEF
Definition: event_machine_hw_types.h:60
EM_CONFIG_POOLS
#define EM_CONFIG_POOLS
Definition: event_machine_config.h:119