EM-ODP  3.7.0
Event Machine on ODP
em_mem.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 /**
32  * @file
33  *
34  * EM Shared & Local Memory data
35  *
36  */
37 
38 #ifndef EM_MEM_H_
39 #define EM_MEM_H_
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
46 
47 /**
48  * EM shared memory data
49  *
50  * Struct contains data that is shared between all EM-cores,
51  * i.e. shared between all EM-processes or EM-threads depending on the setup.
52  */
53 typedef struct {
54  /** Handle for this shared memory */
55  odp_shm_t this_shm;
56  /** EM internal log function, overridable via em_conf, var args */
58  /** EM internal log function, overridable via em_conf, va_list */
60  /** EM configuration as given to em_init() */
62  /** EM config file options */
64  /** Mapping between physical core id <-> EM core id */
66  /** Table of buffer/packet/event pools used by EM */
68  /** Pool of free event/mempools */
70  /** EO table */
72  /** EO pool of free/unused EOs */
74  /** Event Chaining resources */
76  /** Queue table */
78  /** Queue pool of free/unused dynamic queues */
80  /** Queue pool of free/unused static queues */
82  /** Queue group table */
84  /** Queue group pool of free/unused queue groups */
86  /** Atomic group table */
88  /** Dynamic atomic group pool */
90  /** Event group table */
92  /** Event group pool of free/unused queue groups */
94  /** Error handler structure */
96 
97  /** Dispatcher enter callback functions currently in use */
98  hook_tbl_t *dispatch_enter_cb_tbl ENV_CACHE_LINE_ALIGNED;
99  /** Dispatcher exit callback functions currently in use */
101  /** Alloc-hook functions currently in use */
103  /** Free-hook functions currently in use */
105  /** Send-hook functions currently in use */
107  /** To_idle hook functions currently in use */
109  /** To_active hook functions currently in use */
111  /** While_idle hook functions currently in use */
113 
114  /** Dispatch enter callback storage, many sets of callback-tables */
115  hook_storage_t dispatch_enter_cb_storage ENV_CACHE_LINE_ALIGNED;
116  /** Dispatch exit callback storage, many sets of callback-tables */
117  hook_storage_t dispatch_exit_cb_storage ENV_CACHE_LINE_ALIGNED;
118  /** Alloc-hook function storage, many sets of hook-tables */
120  /** Free-hook function storage, many sets of hook-tables */
122  /** Send-hook function storage, many sets of hook-tables */
124  /** To_idle hook functions storage, many sets of hook-tables */
126  /** To_active hook functions storage, many sets of hook-tables */
128  /** While_idle hook functions storage, many sets of hook-tables */
130 
131  /** Current number of allocated EOs */
133  /** Timer resources */
135  /** Current number of allocated queues */
137  /** Current number of allocated queue groups */
139  /** Current number of allocated event groups */
141  /** Current number of allocated atomic groups */
143  /** Current number of allocated event pools */
145  /** libconfig setting, default (compiled) and runtime (from file) */
147  /** priority mapping */
148  struct {
149  /** mapping table */
151  int num_runtime;
152  } queue_prio;
153 
154  /** Guarantee that size is a multiple of cache line size */
156 } em_shm_t;
157 
158 COMPILE_TIME_ASSERT(sizeof(em_shm_t) % ENV_CACHE_LINE_SIZE == 0,
159  EM_SHM_SIZE_ERROR);
160 
161 /**
162  * EM core/local current state
163  *
164  * Contains information about the current EO, queue, event group etc. when
165  * running in an EO context (e.g. in an EO-receive function),
166  * undef/NULL otherwise.
167  */
168 typedef struct ODP_PACKED {
169  /** Current scheduling context type */
171  /** EO-receive function burst count */
173  /** Current queue element during a receive call */
175  /** Current scheduled queue element that set the sched context*/
177  /** Current event group */
178  em_event_group_t egrp;
179  /** Current event group element */
181  /** Current event group generation count*/
182  int32_t egrp_gen;
184 
185 /**
186  * EM core local data
187  */
188 typedef struct {
189  /** EM core/local current state */
191 
192  /** Idle state of the core, used when calling idle hooks */
194 
195  /** EM core id for this core */
196  int core_id;
197  /** The number of events from the scheduler to dispatch */
199 
200  /** em_atomic_processing_end() called during event dispatch */
202  /** Is input_poll_fn executed on this core */
204  /** Is output_drain_fn executed on this core */
206  /** Is thread external to EM (doesn't participate in event dispatching) */
208  /** Is the scheduler paused on this core (for odp_sched_pause/resume()) */
210 
211  /** Number of dispatch rounds since previous polling of ctrl queues */
212  unsigned int dispatch_cnt;
213  /** Time when polling of ctrl queues where last done */
214  odp_time_t dispatch_last_run;
215 
216  /** Number of dispatch rounds since previous call of poll/drain functions */
218  /** Time when poll and drain functions were last called */
220 
221  /** Local queues, i.e. storage for events to local queues */
223 
224  /** EO start-function ongoing, buffer all events and send after start */
226  /** The number of errors on a core */
227  uint64_t error_count;
228 
229  /** EM-core local log function */
231 
232  /** EM-core local log function with va_list */
234 
235  /** Synchronous API */
237 
238  /** dispatcher debug timestamps (ns) */
239  uint64_t debug_ts[EM_DEBUG_TSP_LAST];
240 
241  /** Track output-queues used during this dispatch round (burst) */
243 
244  /** Guarantee that size is a multiple of cache line size */
246 } em_locm_t;
247 
248 COMPILE_TIME_ASSERT((sizeof(em_locm_t) % ENV_CACHE_LINE_SIZE) == 0,
249  EM_LOCM_SIZE_ERROR);
250 
251 /** EM shared memory pointer */
252 extern em_shm_t *em_shm;
253 /** EM core local memory */
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 
260 #endif /* EM_MEM_H_ */
error_handler_t
Definition: em_error_types.h:48
em_shm_t::while_idle_hook_tbl
hook_tbl_t * while_idle_hook_tbl
Definition: em_mem.h:112
eo_pool_t
Definition: em_eo_types.h:94
em_shm_t::ENV_CACHE_LINE_ALIGNED
hook_storage_t free_hook_storage ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:121
em_shm_t::pool_count
env_atomic32_t pool_count
Definition: em_mem.h:144
ODP_PACKED::sched_context_type
em_sched_context_type_t sched_context_type
Definition: em_mem.h:170
em_locm_t::local_queues
local_queues_t local_queues
Definition: em_mem.h:222
em_locm_t::output_queue_track
output_queue_track_t output_queue_track
Definition: em_mem.h:242
EM_QUEUE_PRIO_NUM
#define EM_QUEUE_PRIO_NUM
Definition: event_machine_hw_config.h:103
em_shm_t::event_group_count
env_atomic32_t event_group_count
Definition: em_mem.h:140
queue_pool_t
Definition: em_queue_types.h:298
em_locm_t::do_output_drain
bool do_output_drain
Definition: em_mem.h:205
ODP_PACKED
Definition: em_event_types.h:129
ENV_CACHE_LINE_SIZE
#define ENV_CACHE_LINE_SIZE
Definition: environment.h:62
em_locm_t::dispatch_cnt
unsigned int dispatch_cnt
Definition: em_mem.h:212
event_group_pool_t
Definition: em_event_group_types.h:111
idle_state_t
idle_state_t
Definition: em_dispatcher_types.h:47
em_log_func_t
int(* em_log_func_t)(em_log_level_t level, const char *fmt,...) __attribute__((format(printf
Definition: event_machine_hw_types.h:329
em_shm_t::log_fn
em_log_func_t log_fn
Definition: em_mem.h:57
em_locm
ENV_LOCAL em_locm_t em_locm
em_locm_t::dispatch_last_run
odp_time_t dispatch_last_run
Definition: em_mem.h:214
em_locm_t::is_sched_paused
bool is_sched_paused
Definition: em_mem.h:209
ODP_PACKED::sched_q_elem
queue_elem_t * sched_q_elem
Definition: em_mem.h:176
em_locm_t::current
em_locm_current_t current
Definition: em_mem.h:190
queue_group_tbl_t
Definition: em_queue_group_types.h:86
em_shm_t::send_hook_tbl
hook_tbl_t * send_hook_tbl
Definition: em_mem.h:106
timer_storage_t
Definition: em_timer_types.h:50
em_locm_t::sync_api
sync_api_t sync_api
Definition: em_mem.h:236
em_shm_t::ENV_CACHE_LINE_ALIGNED
eo_pool_t eo_pool ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:73
em_shm_t::ENV_CACHE_LINE_ALIGNED
queue_pool_t queue_pool_static ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:81
em_shm_t::ENV_CACHE_LINE_ALIGNED
mpool_pool_t mpool_pool ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:69
em_shm_t::free_hook_tbl
hook_tbl_t * free_hook_tbl
Definition: em_mem.h:104
output_queue_track_t
Definition: em_queue_types.h:316
em_shm_t::ENV_CACHE_LINE_ALIGNED
error_handler_t error_handler ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:95
em_locm_t::log_fn
em_log_func_t log_fn
Definition: em_mem.h:230
ODP_PACKED::egrp_elem
event_group_elem_t * egrp_elem
Definition: em_mem.h:180
core_map_t
Definition: em_core_types.h:47
em_shm_t::ENV_CACHE_LINE_ALIGNED
queue_tbl_t queue_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:77
eo_elem_t
Definition: em_eo_types.h:47
sync_api_t
Definition: em_sync_api_types.h:48
em_locm_t::event_burst_cnt
int event_burst_cnt
Definition: em_mem.h:198
em_shm_t::ENV_CACHE_LINE_ALIGNED
atomic_group_pool_t atomic_group_pool ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:89
em_shm_t
Definition: em_mem.h:53
em_shm_t::libconfig
libconfig_t libconfig
Definition: em_mem.h:146
em_shm_t::to_active_hook_tbl
hook_tbl_t * to_active_hook_tbl
Definition: em_mem.h:110
em_locm_t::poll_drain_dispatch_last_run
odp_time_t poll_drain_dispatch_last_run
Definition: em_mem.h:219
em_shm_t::ENV_CACHE_LINE_ALIGNED
hook_storage_t dispatch_exit_cb_storage ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:117
ENV_CACHE_LINE_ALIGNED
#define ENV_CACHE_LINE_ALIGNED
Definition: environment.h:76
em_locm_t::idle_state
idle_state_t idle_state
Definition: em_mem.h:193
em_shm_t::ENV_CACHE_LINE_ALIGNED
hook_storage_t send_hook_storage ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:123
opt_t
Definition: em_init.h:58
em_shm_t::ENV_CACHE_LINE_ALIGNED
core_map_t core_map ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:65
em_shm_t::ENV_CACHE_LINE_ALIGNED
event_group_tbl_t event_group_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:91
em_locm_t::do_input_poll
bool do_input_poll
Definition: em_mem.h:203
em_shm_t::ENV_CACHE_LINE_ALIGNED
timer_storage_t timers ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:134
em_shm_t::ENV_CACHE_LINE_ALIGNED
queue_group_tbl_t queue_group_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:83
ODP_PACKED::egrp
em_event_group_t egrp
Definition: em_mem.h:178
em_shm_t::ENV_CACHE_LINE_ALIGNED
atomic_group_tbl_t atomic_group_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:87
em_shm_t::ENV_CACHE_LINE_ALIGNED
void *end[0] ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:155
queue_tbl_t
Definition: em_queue_types.h:271
em_shm_t::ENV_CACHE_LINE_ALIGNED
queue_group_pool_t queue_group_pool ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:85
em_locm_current_t
struct ODP_PACKED em_locm_current_t
mpool_pool_t
Definition: em_pool_types.h:136
atomic_group_pool_t
Definition: em_atomic_group_types.h:85
em_locm_t::core_id
int core_id
Definition: em_mem.h:196
em_locm_t::ENV_CACHE_LINE_ALIGNED
void *end[0] ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:245
em_shm_t::ENV_CACHE_LINE_ALIGNED
opt_t opt ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:63
ODP_PACKED::q_elem
queue_elem_t * q_elem
Definition: em_mem.h:174
mpool_tbl_t
Definition: em_pool_types.h:119
em_shm_t::ENV_CACHE_LINE_ALIGNED
queue_pool_t queue_pool ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:79
em_locm_t::atomic_group_released
bool atomic_group_released
Definition: em_mem.h:201
event_machine_debug.h
_env_atomic32
Definition: env_atomic.h:44
em_shm_t::queue_group_count
env_atomic32_t queue_group_count
Definition: em_mem.h:138
em_shm
em_shm_t * em_shm
Definition: event_machine_init.c:41
em_shm_t::ENV_CACHE_LINE_ALIGNED
hook_storage_t alloc_hook_storage ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:119
libconfig
Definition: em_libconfig_types.h:50
em_shm_t::ENV_CACHE_LINE_ALIGNED
hook_storage_t dispatch_enter_cb_storage ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:115
ODP_PACKED::egrp_gen
int32_t egrp_gen
Definition: em_mem.h:182
event_group_tbl_t
Definition: em_event_group_types.h:103
em_shm_t::ENV_CACHE_LINE_ALIGNED
hook_tbl_t *dispatch_enter_cb_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:98
em_shm_t::this_shm
odp_shm_t this_shm
Definition: em_mem.h:55
local_queues_t
Definition: em_queue_types.h:305
atomic_group_tbl_t
Definition: em_atomic_group_types.h:77
hook_tbl_t
Definition: em_hook_types.h:76
em_shm_t::dispatch_exit_cb_tbl
hook_tbl_t * dispatch_exit_cb_tbl
Definition: em_mem.h:100
em_shm_t::alloc_hook_tbl
hook_tbl_t * alloc_hook_tbl
Definition: em_mem.h:102
em_locm_t::poll_drain_dispatch_cnt
unsigned int poll_drain_dispatch_cnt
Definition: em_mem.h:217
em_shm_t::to_idle_hook_storage
hook_storage_t to_idle_hook_storage
Definition: em_mem.h:125
em_vlog_func_t
int(*) typedef int(* em_vlog_func_t)(em_log_level_t level, const char *fmt, va_list args)
Definition: event_machine_hw_types.h:337
em_shm_t::atomic_group_count
env_atomic32_t atomic_group_count
Definition: em_mem.h:142
em_shm_t::ENV_CACHE_LINE_ALIGNED
eo_tbl_t eo_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:71
eo_tbl_t
Definition: em_eo_types.h:89
em_locm_t::vlog_fn
em_vlog_func_t vlog_fn
Definition: em_mem.h:233
event_group_elem_t
Definition: em_event_group_types.h:64
em_locm_t
Definition: em_mem.h:188
em_shm_t::ENV_CACHE_LINE_ALIGNED
em_conf_t conf ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:61
ENV_LOCAL
#define ENV_LOCAL
Definition: environment.h:57
queue_group_pool_t
Definition: em_queue_group_types.h:94
em_shm_t::ENV_CACHE_LINE_ALIGNED
event_chaining_t event_chaining ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:75
em_locm_t::is_external_thr
bool is_external_thr
Definition: em_mem.h:207
event_chaining_t
Definition: em_chaining_types.h:45
em_shm_t::to_active_hook_storage
hook_storage_t to_active_hook_storage
Definition: em_mem.h:127
em_shm_t::ENV_CACHE_LINE_ALIGNED
event_group_pool_t event_group_pool ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:93
em_shm_t::while_idle_hook_storage
hook_storage_t while_idle_hook_storage
Definition: em_mem.h:129
em_shm_t::ENV_CACHE_LINE_ALIGNED
mpool_tbl_t mpool_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:67
hook_storage_t
Definition: em_hook_types.h:89
em_shm_t::vlog_fn
em_vlog_func_t vlog_fn
Definition: em_mem.h:59
queue_elem_t
Definition: em_queue_types.h:180
em_locm_t::start_eo_elem
eo_elem_t * start_eo_elem
Definition: em_mem.h:225
em_sched_context_type_t
em_sched_context_type_t
Definition: event_machine_types.h:277
em_locm_t::error_count
uint64_t error_count
Definition: em_mem.h:227
em_shm_t::to_idle_hook_tbl
hook_tbl_t * to_idle_hook_tbl
Definition: em_mem.h:108
ODP_PACKED::rcv_multi_cnt
int rcv_multi_cnt
Definition: em_mem.h:172
em_conf_t
Definition: event_machine_init.h:93