52#include <odp/helper/odph_api.h>
73#include "em_libconfig.h"
89 const char *ver_str = odp_version_api_str();
90 unsigned int odp_api_ver = ODP_VERSION_API_NUM(ODP_VERSION_API_GENERATION,
91 ODP_VERSION_API_MAJOR,
92 ODP_VERSION_API_MINOR);
94 unsigned int major = 0;
95 unsigned int minor = 0;
97 if (ver_str == NULL || sscanf(ver_str,
"%u.%u.%u", &gen, &major, &minor) != 3) {
99 "Error: Unable to parse ODP runtime API version: \"%s\"\n",
100 ver_str ? ver_str :
"NULL");
104 unsigned int odp_ver = ODP_VERSION_API_NUM(gen, major, minor);
105 unsigned int min_ver = ODP_VERSION_API_NUM(EM_REQ_ODP_API_GENERATION,
106 EM_REQ_ODP_API_MAJOR,
107 EM_REQ_ODP_API_MINOR);
109 if (odp_ver < min_ver || odp_api_ver < min_ver) {
111 "Error: Unsupported ODP API version:%s%s\n"
112 " EM required ODP API version (min): %u.%u.%u\n"
113 " ODP API version from headers: %u.%u.%u\n"
114 " ODP API version from libodp: %u.%u.%u\n",
115 odp_api_ver < min_ver ?
" headers too old" :
"",
116 odp_ver < min_ver ?
" libodp too old" :
"",
117 EM_REQ_ODP_API_GENERATION,
118 EM_REQ_ODP_API_MAJOR,
119 EM_REQ_ODP_API_MINOR,
120 ODP_VERSION_API_GENERATION,
121 ODP_VERSION_API_MAJOR,
122 ODP_VERSION_API_MINOR,
137 if (unlikely(!conf)) {
139 EM_ESCOPE_CONF_INIT,
"Conf pointer NULL!");
153 "Conf pointer NULL!");
157 "Not initialized: em_conf_init(conf) not called");
161 EM_ESCOPE_INIT,
"User provided log funcs invalid!");
166 "EM shared memory ptr set - already initialized?");
170 "Select EITHER process-per-core OR thread-per-core!");
176 odp_shm_capability_t shm_capa;
178 ret = odp_shm_capability(&shm_capa);
180 "shm capability error:%d", ret);
182 if (shm_capa.flags & ODP_SHM_SINGLE_VA)
183 flags |= ODP_SHM_SINGLE_VA;
185 odp_shm_t shm = odp_shm_reserve(
"em_shm",
sizeof(
em_shm_t),
186 ODP_CACHE_LINE_SIZE, flags);
189 EM_ESCOPE_INIT,
"Shared memory reservation failed!");
191 em_shm = odp_shm_addr(shm);
194 "Shared memory ptr NULL!");
214 stat = check_odp_version();
216 "ODP API version not supported!");
219 ret = em_libconfig_init_global(&
em_shm->libconfig);
221 "libconfig initialization failed:%d", ret);
230 stat = core_map_init(&
em_shm->core_map);
232 "core_map_init() failed:%" PRI_STAT
"", stat);
235 stat = dispatch_init();
237 "dispatch_init() failed:%" PRI_STAT
"", stat);
244 "esv_init() failed:%" PRI_STAT
"", stat);
249 "hooks_init() failed:%" PRI_STAT
"", stat);
256 stat = pool_init(&
em_shm->mpool_tbl, &
em_shm->mpool_pool,
259 "pool_init() failed:%" PRI_STAT
"", stat);
263 "event_init() failed:%" PRI_STAT
"", stat);
265 stat = event_group_init(&
em_shm->event_group_tbl,
266 &
em_shm->event_group_stash);
268 "event_group_init() failed:%" PRI_STAT
"", stat);
270 stat = queue_init(&
em_shm->queue_tbl, &
em_shm->queue_pool,
273 "queue_init() failed:%" PRI_STAT
"", stat);
275 stat = queue_group_init(&
em_shm->queue_group_tbl,
276 &
em_shm->queue_group_pool);
278 "queue_group_init() failed:%" PRI_STAT
"", stat);
280 stat = atomic_group_init(&
em_shm->atomic_group_tbl,
281 &
em_shm->atomic_group_pool);
283 "atomic_group_init() failed:%" PRI_STAT
"", stat);
287 "eo_init() failed:%" PRI_STAT
"", stat);
291 "create_shared_ctrl_queue() failed:%" PRI_STAT
"", stat);
295 stat = timer_init(&
em_shm->timers);
298 "timer_init() failed:%" PRI_STAT
"",
303 stat = chaining_init(&
em_shm->event_chaining);
305 "chaining_init() failed:%" PRI_STAT
"", stat);
310 "emcli_init() failed:%" PRI_STAT
"", stat);
315 print_version_info();
324 "Conf pointer NULL!");
328 "EM not initialized - call em_init() first!");
341 if (unlikely(!conf_local)) {
343 EM_ESCOPE_CONF_LOCAL_INIT,
"conf_local pointer NULL!");
346 memset(conf_local, 0,
sizeof(*conf_local));
355 odp_thread_type_t thrtype_odp = odp_thread_type();
358 EM_ESCOPE_INIT_LOCAL,
359 "Must call em_init() first before %s!", __func__);
362 "conf_local pointer NULL!");
366 "Not initialized: em_conf_local_init(conf_local) not called");
371 "Unsupported core_type=%d", conf_local->
core_type);
374 "Invalid core id: %d!", conf_local->
core_id);
377 "Core already initialized! core_id:%d", locm->
core_id);
383 "ODP thread-type:%d not 'worker' for EM worker core!",
385 status = init_local(conf_local, EM_ESCOPE_INIT_LOCAL);
391 "ODP thread-type:%d not 'control' for EM control core!",
393 status = init_local(conf_local, EM_ESCOPE_INIT_LOCAL);
399 "ODP thread-type:%d not 'control' for EM external thread!",
401 status = init_extthr(conf_local, EM_ESCOPE_INIT_LOCAL);
406 "Unsupported core_type=%d", conf_local->
core_type);
420 EM_ESCOPE_CONF_LOCAL_OPTS,
"Conf pointer NULL!");
423 "Not initialized locally: call em_init_local() or em_init_core() first!");
432 if (!is_core_initialized()) {
434 "Not initialized locally, call em_init_local/core() first!");
438 conf_local_opts_print();
446 odp_thread_type_t thrtype_odp = odp_thread_type();
450 "Must call em_init() first before %s!", __func__);
453 "Core already initialized! core_id:%d", locm->
core_id);
457 "ODP thread-type:%d not 'worker' for EM worker core!",
463 status = init_local(&conf_local, EM_ESCOPE_INIT_CORE);
472 if (unlikely(!term_local)) {
474 EM_ESCOPE_TERM_LOCAL_INIT,
475 "term_local pointer NULL!");
478 memset(term_local, 0,
sizeof(*term_local));
489 EM_ESCOPE_TERM_LOCAL,
"term_local pointer NULL!");
492 EM_ESCOPE_TERM_LOCAL,
493 "EM not initialized - call em_init() first!");
496 "Not initialized: em_init_local() or em_init_core() not called");
500 "Not initialized: em_term_local_init() not called");
505 status = term_core(EM_ESCOPE_TERM_LOCAL);
509 status = term_extthr(EM_ESCOPE_TERM_LOCAL);
514 "Unsupported core_type=%d", conf_local->
core_type);
517 *locm = locm_init_values;
526 odp_thread_type_t thrtype_odp = odp_thread_type();
530 "EM not initialized - call em_init() first!");
533 "Not initialized: em_init_local() or em_init_core() not called");
537 "ODP thread-type:%d not 'worker' for EM worker core!",
540 status = term_core(EM_ESCOPE_TERM_CORE);
541 *locm = locm_init_values;
552 EM_ESCOPE_TERM,
"EM not initialized or already terminated!");
558 queue_group_join_all();
566 odp_schedule_resume();
568 for (
int i = 0; i < 2; i++) {
569 flush_scheduler_events();
571 odp_schedule_pause();
576 "delete_ctrl_queues() failed:%" PRI_STAT
"", stat);
579 timer_term(&
em_shm->timers);
582 if (unlikely(stat !=
EM_OK)) {
584 "emcli_term() failed:%" PRI_STAT
"", stat);
588 stat = chaining_term(&
em_shm->event_chaining);
590 "chaining_term() failed:%" PRI_STAT
"", stat);
592 ret = em_libconfig_term_global(&
em_shm->libconfig);
594 "EM config term failed:%d");
596 stat = pool_term(&
em_shm->mpool_tbl);
598 "pool_term() failed:%" PRI_STAT
"", stat);
600 env_shared_free(
em_shm->queue_tbl.queue_elem);
602 stat = event_group_term();
604 "event_group_term() failed.");
607 stat = queue_group_term();
608 if (unlikely(stat !=
EM_OK)) {
610 "queue_group_term() failed:" PRI_STAT
"", stat);
619 "odp_shm_free() failed:%d", ret);
634 "cfgfile_opts pointer cannot be NULL!");
637 EM_ESCOPE_CFGFILE_OPTS,
638 "EM not initialized - call em_init() first!");
646 cfgfile_opts_print();
#define INTERNAL_ERROR(error, escope, fmt,...)
#define RETURN_ERROR_IF(cond, error, escope, fmt,...)
#define EM_LOCM_INIT_VALUES
#define EM_CHECK_INIT_CALLED
em_status_t delete_ctrl_queues(void)
Delete EM's internal unscheduled control queues at teardown.
em_status_t create_shared_ctrl_queue(void)
Create EM's internal shared unscheduled control queue at startup.
ENV_LOCAL em_locm_t em_locm
#define EM_API_HOOKS_ENABLE
em_status_t emcli_term(void)
Terminate the EM CLI (if enabled)
em_status_t emcli_init(void)
Initialize the EM CLI (if enabled)
@ EM_ERR_OPERATION_FAILED
void em_pool_cfg_init(em_pool_cfg_t *const pool_cfg)
em_status_t em_term(void)
em_status_t em_conf_local_opts(em_conf_local_t *conf_local_opts)
em_status_t em_term_local(const em_term_local_t *term_local)
em_status_t em_conf_opts(em_conf_t *conf_opts)
void em_term_local_init(em_term_local_t *term_local)
void em_cfgfile_opts_print(void)
void em_conf_local_init(em_conf_local_t *conf_local)
em_status_t em_init_local(const em_conf_local_t *conf_local)
em_status_t em_term_core(void)
void em_conf_local_opts_print(void)
void em_conf_init(em_conf_t *conf)
em_status_t em_init(const em_conf_t *conf)
em_status_t em_cfgfile_opts(em_cfgfile_opts_t *cfgfile_opts)
uint16_t em_device_id(void)
void em_conf_opts_print(void)
em_status_t em_init_core(void)
uint32_t __internal_check
em_pool_cfg_t default_pool_cfg
uint32_t __internal_check
em_idle_hooks_t idle_hooks
bool is_core_local_inited
em_conf_local_t conf_local
uint32_t __internal_check