EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
em_mem.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015-2026, 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#include <stdbool.h>
42#include <stdint.h>
43#include <sys/types.h> /* pid_t */
44
45#include <odp_api.h>
46
47#include <event_machine.h>
50
51/*
52 * Bring in every internal type referenced by em_shm_t / em_locm_t.
53 * Most are embedded by value; even the pointer-typed fields (e.g. hook_tbl_t*,
54 * event_group_elem_t*) require their containing type for sizeof in callers,
55 * so include the full definitions.
56 */
58#include "em_chaining_types.h"
59#include "em_core_types.h"
60#include "em_dispatcher_types.h"
61#include "em_eo_types.h"
62#include "em_error_types.h"
64#include "em_event_types.h"
65#include "em_hook_types.h"
66#include "em_init_types.h"
68#include "em_libconfig_types.h"
69#include "em_pool_types.h"
71#include "em_queue_types.h"
72#include "em_sync_api_types.h"
73#include "em_timer_types.h"
74
75#ifdef __cplusplus
76extern "C" {
77#endif
78
79/**
80 * EM shared memory data
81 *
82 * Struct contains data that is shared between all EM-cores,
83 * i.e. shared between all EM-processes or EM-threads depending on the setup.
84 */
85typedef struct {
86 /** Handle for this shared memory */
87 odp_shm_t this_shm;
88 /** EM internal log function, overridable via em_conf, var args */
90 /** EM internal log function, overridable via em_conf, va_list */
92 /** EM configuration as given to em_init() */
94 /** Indicates if EM has been initialized successfully with em_init() */
95 bool is_init;
96 /** Cache EM config file options */
98 /** EM config file options */
100 /** Mapping between physical core id <-> EM core id */
102 /** Table of buffer/packet/event pools used by EM */
104 /** Pool of free event/mempools */
106 /** EO table */
108 /** EO pool of free/unused EOs */
110 /** Event Chaining resources */
112 /** Queue table */
114 /** Queue pool of free/unused dynamic queues */
116 /** Queue pool of free/unused static queues */
118 /** Queue pool of free/unused aggregator queues */
120 /** Queue group table */
122 /** Queue group pool of free/unused queue groups */
124 /** Atomic group table */
126 /** Dynamic atomic group pool */
128 /** Event group table */
130 /** Event group stash of free/unused queue groups */
131 odp_stash_t event_group_stash ENV_CACHE_LINE_ALIGNED;
132 /** Error handler structure */
134
135 /** Dispatcher enter callback functions currently in use */
136 hook_tbl_t *dispatch_enter_cb_tbl ENV_CACHE_LINE_ALIGNED;
137 /** Dispatcher exit callback functions currently in use */
139 /** Alloc-hook functions currently in use */
141 /** Free-hook functions currently in use */
143 /** Send-hook functions currently in use */
145 /** To_idle hook functions currently in use */
147 /** To_active hook functions currently in use */
149 /** While_idle hook functions currently in use */
151
152 /** Dispatch enter callback storage, many sets of callback-tables */
153 hook_storage_t dispatch_enter_cb_storage ENV_CACHE_LINE_ALIGNED;
154 /** Dispatch exit callback storage, many sets of callback-tables */
155 hook_storage_t dispatch_exit_cb_storage ENV_CACHE_LINE_ALIGNED;
156 /** Alloc-hook function storage, many sets of hook-tables */
158 /** Free-hook function storage, many sets of hook-tables */
160 /** Send-hook function storage, many sets of hook-tables */
162 /** To_idle hook functions storage, many sets of hook-tables */
164 /** To_active hook functions storage, many sets of hook-tables */
166 /** While_idle hook functions storage, many sets of hook-tables */
168
169 /** Timer resources */
171
172 /** Current number of allocated EOs */
173 odp_atomic_u32_t eo_count ENV_CACHE_LINE_ALIGNED;
174 /** Current number of allocated queues */
175 odp_atomic_u32_t queue_count;
176 /** Current number of allocated queue groups */
177 odp_atomic_u32_t queue_group_count;
178 /** Current number of allocated event groups */
179 odp_atomic_u32_t event_group_count;
180 /** Current number of allocated atomic groups */
181 odp_atomic_u32_t atomic_group_count;
182 /** Current number of allocated event pools */
183 odp_atomic_u32_t pool_count;
184
185 /** libconfig setting, default (compiled) and runtime (from file) */
187 /** priority mapping */
188 struct {
189 /** mapping table */
191 int num_runtime;
192 } queue_prio;
193
194 /** Guarantee that size is a multiple of cache line size */
196} em_shm_t;
197
198COMPILE_TIME_ASSERT(sizeof(em_shm_t) % ENV_CACHE_LINE_SIZE == 0,
199 EM_SHM_SIZE_ERROR);
200
201/**
202 * EM core/local current state
203 *
204 * Contains information about the current EO, queue, event group etc. when
205 * running in an EO context (e.g. in an EO-receive function),
206 * undef/NULL otherwise.
207 */
208typedef struct ODP_PACKED {
209 /** Current scheduling context type */
211 /** EO-receive function burst count */
213 /** Current queue element during a receive call */
215 /** Current scheduled queue element that set the sched context*/
217 /** Current event group element (for the current event group) */
219 /** Current event group generation count */
220 uint32_t egrp_gen;
222
223/**
224 * EM core local data
225 */
226typedef struct {
227 /** EM core/local current state */
229
230 /** Idle state of the core, used when calling idle hooks */
232 /** Number of dispatch rounds since previous polling of ctrl queues */
233 unsigned int dispatch_cnt;
234 /** Number of dispatch rounds since previous call of poll/drain functions */
236 /** The number of events from the scheduler to dispatch */
238 /** EM core id for this core */
240 /** Local queues, i.e. storage for events to local queues */
242 /** The number of local queue events dispatched during the em_dispatch...() call */
244 /** Dispatch callback: input_poll_fn() for this core */
246 /** Dispatch callback: output_drain_fn() for this core */
248
249 /** em_atomic_processing_end() called during event dispatch */
251 /** Is the scheduler paused on this core (for odp_sched_pause/resume()) */
253 /** Is this an EM worker or control core? Not an external EM thread */
255 /** Is thread external to EM (doesn't participate in event dispatching) */
257 /** Is thread termination completed? */
259 /** Has core-local initialization completed on this core? */
261
262 /** Time when polling of ctrl queues where last done */
264 /** Ctrl queue poll interval as core-local time (converted per-core) */
266 /** Time when poll and drain functions were last called */
268 /** Poll/drain interval as core-local time (converted per-core) */
270
271 /** PID when TLS was initialized (for detecting forked children) */
272 pid_t init_pid;
273
274 /** EO start-function ongoing, buffer all events and send after start */
276 /** The number of errors on a core */
277 uint64_t error_count;
278
279 /** EM-core local log function */
281
282 /** EM-core local log function with va_list */
284
285 /** Synchronous API */
287
288 /** dispatcher debug timestamps (ns) */
289 uint64_t debug_ts[EM_DEBUG_TSP_LAST];
290
291 /** Track output-queues used during this dispatch round (burst) */
293
294 /** EM local configuration as passed by em_init_local(conf_local) */
296
297 /**
298 * Non-EM events don't have an event header of their own,
299 * use a temporary core-local event header instead.
300 * Initialized to all-zero with .event_type = EM_EVENT_TYPE_ODP to
301 * avoid having ev_hdr == NULL in the code and checks for it.
302 * Using a tmp event header, instead of NULL checks, speeds up the code.
303 *
304 * em_locm_t::evhdr_nonem.event_type = EM_EVENT_TYPE_ODP;
305 */
307
308 /** Guarantee that size is a multiple of cache line size */
310} em_locm_t;
311
312COMPILE_TIME_ASSERT((sizeof(em_locm_t) % ENV_CACHE_LINE_SIZE) == 0,
313 EM_LOCM_SIZE_ERROR);
314
315/** EM shared memory pointer */
316extern em_shm_t *em_shm;
317/** EM core local memory */
318extern ENV_LOCAL em_locm_t em_locm;
319
320#ifdef __cplusplus
321}
322#endif
323
324#endif /* EM_MEM_H_ */
ENV_LOCAL em_locm_t em_locm
em_shm_t * em_shm
struct ODP_PACKED em_locm_current_t
#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
int(* em_input_poll_func_t)(void)
int(* em_output_drain_func_t)(void)
queue_elem_t * q_elem
Definition em_mem.h:214
em_sched_context_type_t sched_context_type
Definition em_mem.h:210
int rcv_multi_cnt
Definition em_mem.h:212
event_group_elem_t * egrp_elem
Definition em_mem.h:218
uint32_t egrp_gen
Definition em_mem.h:220
queue_elem_t * sched_q_elem
Definition em_mem.h:216
bool is_core_local_inited
Definition em_mem.h:260
bool is_em_core
Definition em_mem.h:254
em_locm_current_t current
Definition em_mem.h:228
bool is_term_thread_done
Definition em_mem.h:258
bool is_sched_paused
Definition em_mem.h:252
void *end[0] ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:309
em_output_drain_func_t output_drain_fn
Definition em_mem.h:247
eo_elem_t * start_eo_elem
Definition em_mem.h:275
local_queues_t local_queues
Definition em_mem.h:241
unsigned int dispatch_cnt
Definition em_mem.h:233
unsigned int poll_drain_dispatch_cnt
Definition em_mem.h:235
event_hdr_t evhdr_nonem
Definition em_mem.h:306
uint64_t local_event_cnt
Definition em_mem.h:243
odp_time_t poll_ctrl_interval_time
Definition em_mem.h:265
em_input_poll_func_t input_poll_fn
Definition em_mem.h:245
em_conf_local_t conf_local
Definition em_mem.h:295
em_log_func_t log_fn
Definition em_mem.h:280
em_vlog_func_t vlog_fn
Definition em_mem.h:283
odp_time_t dispatch_last_run
Definition em_mem.h:263
int core_id
Definition em_mem.h:239
sync_api_t sync_api
Definition em_mem.h:286
bool atomic_group_released
Definition em_mem.h:250
pid_t init_pid
Definition em_mem.h:272
int event_burst_cnt
Definition em_mem.h:237
idle_state_t idle_state
Definition em_mem.h:231
bool is_external_thread
Definition em_mem.h:256
output_queue_track_t output_queue_track
Definition em_mem.h:292
odp_time_t poll_drain_dispatch_last_run
Definition em_mem.h:267
uint64_t error_count
Definition em_mem.h:277
odp_time_t poll_drain_interval_time
Definition em_mem.h:269
eo_tbl_t eo_tbl ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:107
queue_group_tbl_t queue_group_tbl ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:121
hook_tbl_t * alloc_hook_tbl
Definition em_mem.h:140
odp_atomic_u32_t event_group_count
Definition em_mem.h:179
hook_storage_t dispatch_exit_cb_storage ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:155
mpool_pool_t mpool_pool ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:105
hook_storage_t while_idle_hook_storage
Definition em_mem.h:167
libconfig_t libconfig ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:186
eo_pool_t eo_pool ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:109
atomic_group_tbl_t atomic_group_tbl ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:125
hook_storage_t send_hook_storage ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:161
odp_atomic_u32_t queue_group_count
Definition em_mem.h:177
hook_storage_t to_active_hook_storage
Definition em_mem.h:165
timer_storage_t timers ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:170
cfgfile_opt_cache_t opt_cache
Definition em_mem.h:97
odp_atomic_u32_t queue_count
Definition em_mem.h:175
em_log_func_t log_fn
Definition em_mem.h:89
queue_group_pool_t queue_group_pool ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:123
event_group_tbl_t event_group_tbl ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:129
queue_pool_t queue_pool_static ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:117
event_chaining_t event_chaining ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:111
hook_storage_t free_hook_storage ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:159
odp_atomic_u32_t eo_count ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:173
hook_tbl_t * to_idle_hook_tbl
Definition em_mem.h:146
hook_tbl_t * to_active_hook_tbl
Definition em_mem.h:148
core_map_t core_map ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:101
hook_storage_t to_idle_hook_storage
Definition em_mem.h:163
atomic_group_pool_t atomic_group_pool ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:127
error_handler_t error_handler ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:133
void *end[0] ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:195
odp_shm_t this_shm
Definition em_mem.h:87
hook_tbl_t * while_idle_hook_tbl
Definition em_mem.h:150
hook_tbl_t * free_hook_tbl
Definition em_mem.h:142
hook_tbl_t * dispatch_exit_cb_tbl
Definition em_mem.h:138
hook_tbl_t * send_hook_tbl
Definition em_mem.h:144
hook_storage_t alloc_hook_storage ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:157
em_conf_t conf
Definition em_mem.h:93
odp_atomic_u32_t atomic_group_count
Definition em_mem.h:181
odp_stash_t event_group_stash ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:131
queue_pool_t queue_pool ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:115
queue_pool_t queue_pool_aggr ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:119
em_vlog_func_t vlog_fn
Definition em_mem.h:91
mpool_tbl_t mpool_tbl ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:103
odp_atomic_u32_t pool_count
Definition em_mem.h:183
hook_tbl_t *dispatch_enter_cb_tbl ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:136
em_cfgfile_opts_t opt
Definition em_mem.h:99
bool is_init
Definition em_mem.h:95
hook_storage_t dispatch_enter_cb_storage ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:153
queue_tbl_t queue_tbl ENV_CACHE_LINE_ALIGNED
Definition em_mem.h:113