EM-ODP  3.8.0-1
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 stash of free/unused queue groups */
93  odp_stash_t event_group_stash ENV_CACHE_LINE_ALIGNED;
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_ */
idle_state_t
ENV_LOCAL em_locm_t em_locm
em_shm_t * em_shm
struct ODP_PACKED em_locm_current_t
#define ENV_CACHE_LINE_ALIGNED
Definition: environment.h:76
#define ENV_LOCAL
Definition: environment.h:57
#define ENV_CACHE_LINE_SIZE
Definition: environment.h:62
#define EM_QUEUE_PRIO_NUM
int(* em_log_func_t)(em_log_level_t level, const char *fmt,...) __attribute__((format(printf
int(*) typedef int(* em_vlog_func_t)(em_log_level_t level, const char *fmt, va_list args)
em_sched_context_type_t
queue_elem_t * q_elem
Definition: em_mem.h:174
em_sched_context_type_t sched_context_type
Definition: em_mem.h:170
int rcv_multi_cnt
Definition: em_mem.h:172
event_group_elem_t * egrp_elem
Definition: em_mem.h:180
queue_elem_t * sched_q_elem
Definition: em_mem.h:176
int32_t egrp_gen
Definition: em_mem.h:182
em_event_group_t egrp
Definition: em_mem.h:178
em_locm_current_t current
Definition: em_mem.h:190
bool is_sched_paused
Definition: em_mem.h:209
void *end[0] ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:245
eo_elem_t * start_eo_elem
Definition: em_mem.h:225
bool do_input_poll
Definition: em_mem.h:203
local_queues_t local_queues
Definition: em_mem.h:222
unsigned int dispatch_cnt
Definition: em_mem.h:212
unsigned int poll_drain_dispatch_cnt
Definition: em_mem.h:217
em_log_func_t log_fn
Definition: em_mem.h:230
em_vlog_func_t vlog_fn
Definition: em_mem.h:233
odp_time_t dispatch_last_run
Definition: em_mem.h:214
int core_id
Definition: em_mem.h:196
sync_api_t sync_api
Definition: em_mem.h:236
bool atomic_group_released
Definition: em_mem.h:201
int event_burst_cnt
Definition: em_mem.h:198
bool is_external_thr
Definition: em_mem.h:207
idle_state_t idle_state
Definition: em_mem.h:193
bool do_output_drain
Definition: em_mem.h:205
output_queue_track_t output_queue_track
Definition: em_mem.h:242
odp_time_t poll_drain_dispatch_last_run
Definition: em_mem.h:219
uint64_t error_count
Definition: em_mem.h:227
env_atomic32_t queue_group_count
Definition: em_mem.h:138
eo_tbl_t eo_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:71
queue_group_tbl_t queue_group_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:83
hook_tbl_t * alloc_hook_tbl
Definition: em_mem.h:102
hook_storage_t dispatch_exit_cb_storage ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:117
libconfig_t libconfig
Definition: em_mem.h:146
mpool_pool_t mpool_pool ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:69
hook_storage_t while_idle_hook_storage
Definition: em_mem.h:129
eo_pool_t eo_pool ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:73
atomic_group_tbl_t atomic_group_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:87
hook_storage_t send_hook_storage ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:123
hook_storage_t to_active_hook_storage
Definition: em_mem.h:127
timer_storage_t timers ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:134
em_log_func_t log_fn
Definition: em_mem.h:57
queue_group_pool_t queue_group_pool ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:85
event_group_tbl_t event_group_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:91
queue_pool_t queue_pool_static ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:81
event_chaining_t event_chaining ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:75
hook_storage_t free_hook_storage ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:121
hook_tbl_t * to_idle_hook_tbl
Definition: em_mem.h:108
opt_t opt ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:63
hook_tbl_t * to_active_hook_tbl
Definition: em_mem.h:110
core_map_t core_map ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:65
hook_storage_t to_idle_hook_storage
Definition: em_mem.h:125
atomic_group_pool_t atomic_group_pool ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:89
error_handler_t error_handler ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:95
env_atomic32_t event_group_count
Definition: em_mem.h:140
void *end[0] ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:155
odp_shm_t this_shm
Definition: em_mem.h:55
hook_tbl_t * while_idle_hook_tbl
Definition: em_mem.h:112
hook_tbl_t * free_hook_tbl
Definition: em_mem.h:104
hook_tbl_t * dispatch_exit_cb_tbl
Definition: em_mem.h:100
env_atomic32_t atomic_group_count
Definition: em_mem.h:142
hook_tbl_t * send_hook_tbl
Definition: em_mem.h:106
hook_storage_t alloc_hook_storage ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:119
odp_stash_t event_group_stash ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:93
queue_pool_t queue_pool ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:79
em_vlog_func_t vlog_fn
Definition: em_mem.h:59
mpool_tbl_t mpool_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:67
em_conf_t conf ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:61
hook_tbl_t *dispatch_enter_cb_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:98
env_atomic32_t pool_count
Definition: em_mem.h:144
hook_storage_t dispatch_enter_cb_storage ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:115
queue_tbl_t queue_tbl ENV_CACHE_LINE_ALIGNED
Definition: em_mem.h:77
Definition: em_init.h:58