64static ENV_LOCAL
unsigned int _eo_tbl_iter_idx;
66static ENV_LOCAL
unsigned int _eo_q_iter_idx;
67static ENV_LOCAL em_eo_t _eo_q_iter_eo;
74 "Invalid param ptr: Use em_eo_param_init() before create");
78 "Mandatory EO function pointer(s) NULL!");
95static em_eo_t eo_create(
const char *name,
const em_eo_param_t *param,
102 status = check_eo_create_params(param, escope);
103 if (unlikely(status !=
EM_OK)) {
114 eo_elem = eo_elem_get(eo);
115 if (unlikely(!eo_elem)) {
118 "Invalid EO:%" PRI_EO "", eo);
122 odp_ticketlock_lock(&eo_elem->
lock);
126 strncpy(eo_elem->name, name,
sizeof(eo_elem->name) - 1);
127 eo_elem->name[
sizeof(eo_elem->name) - 1] =
'\0';
129 eo_elem->name[0] =
'\0';
135 eo_elem->
stash = ODP_STASH_INVALID;
156 odp_ticketlock_unlock(&eo_elem->
lock);
163 if (unlikely(!param)) {
165 EM_ESCOPE_EO_PARAM_INIT,
166 "Param pointer NULL!");
180 if (unlikely(start == NULL || stop == NULL || receive == NULL)) {
182 "Mandatory EO function pointer(s) NULL!");
194 return eo_create(name, ¶m, EM_ESCOPE_EO_CREATE);
199 return eo_create(name, param, EM_ESCOPE_EO_CREATE_PARAM);
204 if (unlikely(!param)) {
206 EM_ESCOPE_EO_MULTIRCV_PARAM_INIT,
207 "Param pointer NULL!");
222 if (unlikely(!param ||
225 "Invalid param ptr:\n"
226 "Use em_eo_multircv_param_init() before create");
232 "Mandatory EO function pointer(s) NULL!");
238 "Max number of events too small:%d",
253 eo_elem = eo_elem_get(eo);
254 if (unlikely(eo_elem == NULL)) {
257 EM_ESCOPE_EO_CREATE_MULTIRCV,
258 "Invalid EO:%" PRI_EO "", eo);
262 odp_ticketlock_lock(&eo_elem->
lock);
266 strncpy(eo_elem->name, name,
sizeof(eo_elem->name) - 1);
267 eo_elem->name[
sizeof(eo_elem->name) - 1] =
'\0';
269 eo_elem->name[0] =
'\0';
275 eo_elem->
stash = ODP_STASH_INVALID;
296 odp_ticketlock_unlock(&eo_elem->
lock);
303 eo_elem_t *
const eo_elem = eo_elem_get(eo);
307 "Invalid EO:%" PRI_EO "!", eo);
311 "EO not allocated:%" PRI_EO "", eo);
316 "EO invalid state, cannot delete:%d", eo_elem->
state);
318 status = eo_delete_queue_all(eo_elem);
321 "EO delete: delete queues failed!");
324 status = eo_free(eo);
326 "EO delete failed!");
333 const eo_elem_t *eo_elem = eo_elem_get(eo);
335 if (name == NULL || maxlen == 0) {
337 "Invalid ptr or maxlen (name=0x%" PRIx64
", maxlen=%zu)",
344 if (unlikely(eo_elem == NULL)) {
346 "Invalid EO%" PRI_EO "", eo);
350 if (unlikely(!eo_allocated(eo_elem))) {
352 "EO not created:%" PRI_EO "", eo);
356 return eo_name(eo_elem, name, maxlen);
377eo_add_queue_escope(em_eo_t eo, em_queue_t queue,
380{
eo_elem_t *
const eo_elem = eo_elem_get(eo);
401 "Invalid queue type: %" PRI_QTYPE "", q_type);
406 "Invalid notif cfg given!");
409 err = eo_add_queue(eo_elem, q_elem);
411 "eo_add_queue(Q:%" PRI_QUEUE ") fails", queue);
414 err = queue_enable(q_elem);
416 "queue_enable(Q:%" PRI_QUEUE ") fails", queue);
423 "EO:%" PRI_EO " send notif fails", eo);
433 return eo_add_queue_escope(eo, queue, num_notif, notif_tbl,
434 EM_ESCOPE_EO_ADD_QUEUE);
441 return eo_add_queue_escope(eo, queue, 0, NULL,
442 EM_ESCOPE_EO_ADD_QUEUE_SYNC);
449 eo_elem_t *
const eo_elem = eo_elem_get(eo);
470 "Invalid queue type: %" PRI_QTYPE "", q_type);
474 "Invalid notif cfg given!");
477 "Can't remove Q:%" PRI_QUEUE ", not added to this EO",
486 ret = queue_disable(q_elem);
499 int reqs_sent = eo_remove_queue_local_req(eo_elem, q_elem, num_notif, notif_tbl);
502 "EO:%" PRI_EO " eo_remove_queue_local_req():%d", eo, reqs_sent);
504 if (reqs_sent == 0) {
510 ret = eo_rem_queue(eo_elem, q_elem);
523 eo_elem_t *
const eo_elem = eo_elem_get(eo);
544 EM_ESCOPE_EO_REMOVE_QUEUE_SYNC,
545 "Invalid queue type: %" PRI_QTYPE "", q_type);
549 "Can't remove Q:%" PRI_QUEUE ", not added to this EO",
561 ret = queue_disable(q_elem);
563 if (unlikely(ret !=
EM_OK)) {
565 "queue_disable(Q:%" PRI_QUEUE ") failed", queue);
566 goto eo_remove_queue_sync_error;
576 int reqs_sent = eo_remove_queue_sync_local_req(eo_elem, q_elem);
578 if (unlikely(reqs_sent < 0)) {
580 "EO:%" PRI_EO " eo_remove_queue_sync_local_req():%d",
582 goto eo_remove_queue_sync_error;
585 if (likely(reqs_sent > 0)) {
594 }
else if (reqs_sent == 0) {
600 ret = eo_rem_queue(eo_elem, q_elem);
602 if (unlikely(ret !=
EM_OK)) {
606 goto eo_remove_queue_sync_error;
612eo_remove_queue_sync_error:
622 eo_elem_t *
const eo_elem = eo_elem_get(eo);
626 EM_ESCOPE_EO_REMOVE_QUEUE_ALL,
627 "Invalid EO:%" PRI_EO "", eo);
629 EM_ESCOPE_EO_REMOVE_QUEUE_ALL,
630 "EO:%" PRI_EO " not created", eo);
633 "Invalid notif cfg given!");
635 ret = queue_disable_all(eo_elem);
637 "queue_disable_all() failed!");
645 int reqs_sent = eo_remove_queue_all_local_req(eo_elem, delete_queues,
646 num_notif, notif_tbl);
648 EM_ESCOPE_EO_REMOVE_QUEUE_ALL,
649 "EO:%" PRI_EO " eo_remove_queue_all_local_req():%d",
652 if (reqs_sent == 0) {
660 ret = eo_delete_queue_all(eo_elem);
662 ret = eo_rem_queue_all(eo_elem);
665 "EO:%" PRI_EO " remove all queues failed", eo);
675 eo_elem_t *
const eo_elem = eo_elem_get(eo);
679 EM_ESCOPE_EO_REMOVE_QUEUE_ALL_SYNC,
680 "Invalid EO:%" PRI_EO "", eo);
682 EM_ESCOPE_EO_REMOVE_QUEUE_ALL_SYNC,
683 "EO:%" PRI_EO " not created", eo);
688 ret = queue_disable_all(eo_elem);
689 if (unlikely(ret !=
EM_OK)) {
691 "queue_disable_all() failed!");
692 goto eo_remove_queue_all_sync_error;
701 int reqs_sent = eo_remove_queue_all_sync_local_req(eo_elem, delete_queues);
703 if (unlikely(reqs_sent < 0)) {
705 "EO:%" PRI_EO " eo_remove_queue_all_sync_local_req():%d",
707 goto eo_remove_queue_all_sync_error;
710 if (likely(reqs_sent > 0)) {
719 }
else if (reqs_sent == 0) {
727 ret = eo_delete_queue_all(eo_elem);
729 ret = eo_rem_queue_all(eo_elem);
731 if (unlikely(ret !=
EM_OK)) {
732 ret =
INTERNAL_ERROR(ret, EM_ESCOPE_EO_REMOVE_QUEUE_ALL_SYNC_DONE_CB,
733 "EO:%" PRI_EO " removing all queues failed", eo);
734 goto eo_remove_queue_all_sync_error;
740eo_remove_queue_all_sync_error:
749 eo_elem_t *
const eo_elem = eo_elem_get(eo);
753 "Invalid args: EO:%" PRI_EO " handler:%p", eo, handler);
756 "EO:%" PRI_EO " not created", eo);
758 odp_ticketlock_lock(&eo_elem->
lock);
760 odp_ticketlock_unlock(&eo_elem->
lock);
768 eo_elem_t *
const eo_elem = eo_elem_get(eo);
771 EM_ESCOPE_EO_UNREGISTER_ERROR_HANDLER,
772 "Invalid EO id %" PRI_EO "", eo);
774 EM_ESCOPE_EO_UNREGISTER_ERROR_HANDLER,
775 "EO not created:%" PRI_EO "", eo);
777 odp_ticketlock_lock(&eo_elem->
lock);
779 odp_ticketlock_unlock(&eo_elem->
lock);
789 eo_elem_t *
const eo_elem = eo_elem_get(eo);
795 "Invalid EO id %" PRI_EO "", eo);
798 "EO not created:%" PRI_EO "", eo);
801 "EO invalid state, cannot start:%d", eo_elem->
state);
804 "Invalid notif cfg given!");
809 eo_elem->
stash = eo_start_stash_create();
810 if (unlikely(eo_elem->
stash == ODP_STASH_INVALID)) {
812 "EO:%" PRI_EO " start stash creation fails", eo);
823 memset(&tmp_q_elem, 0,
sizeof(tmp_q_elem));
824 tmp_q_elem.
eo = (uint16_t)(uintptr_t)eo;
837 if (unlikely(ret !=
EM_OK)) {
839 "EO:%" PRI_EO " start func failed:%" PRIxSTAT
"",
851 int reqs_sent = eo_start_local_req(eo_elem, num_notif, notif_tbl);
853 if (unlikely(reqs_sent < 0)) {
856 "EO:%" PRI_EO " eo_start_local_req():%d",
881 ret = queue_enable_all(eo_elem);
882 if (unlikely(ret !=
EM_OK)) {
884 "EO:%" PRI_EO " queue_enable_all() failed", eo);
891 eo_start_send_buffered_events(eo_elem);
897 if (unlikely(ret !=
EM_OK)) {
899 "EO:%" PRI_EO " send notif fails", eo);
918 eo_elem_t *
const eo_elem = eo_elem_get(eo);
924 "Invalid EO id %" PRI_EO "", eo);
927 "EO not created:%" PRI_EO "", eo);
930 "EO invalid state, cannot start:%d", eo_elem->
state);
935 eo_elem->
stash = eo_start_stash_create();
936 if (unlikely(eo_elem->
stash == ODP_STASH_INVALID)) {
938 "EO:%" PRI_EO " start stash creation fails", eo);
951 memset(&tmp_q_elem, 0,
sizeof(tmp_q_elem));
952 tmp_q_elem.
eo = (uint16_t)(uintptr_t)eo;
964 if (unlikely(ret !=
EM_OK)) {
966 "EO:%" PRI_EO " start func failed:%" PRIxSTAT
"",
977 int reqs_sent = eo_start_sync_local_req(eo_elem);
979 if (unlikely(reqs_sent < 0)) {
981 "EO:%" PRI_EO " eo_start_sync_local_req():%d",
984 goto eo_start_sync_error;
1000 eo_start_send_buffered_events(eo_elem);
1018 ret = queue_enable_all(eo_elem);
1019 if (unlikely(ret !=
EM_OK)) {
1021 "EO:%" PRI_EO " queue_enable_all() failed", eo);
1022 goto eo_start_sync_error;
1028 eo_start_send_buffered_events(eo_elem);
1041 eo_elem_t *
const eo_elem = eo_elem_get(eo);
1046 "Invalid EO:%" PRI_EO "", eo);
1049 "EO invalid state, cannot stop:%d", eo_elem->
state);
1052 "Invalid notif cfg given!");
1060 queue_disable_all(eo_elem);
1068 int reqs_sent = eo_stop_local_req(eo_elem, num_notif, notif_tbl);
1070 if (unlikely(reqs_sent < 0)) {
1073 "EO:%" PRI_EO " eo_stop_local_req():%d",
1077 }
else if (unlikely(reqs_sent == 0)) {
1083 ret = eo_stop_done(eo_elem);
1090 "EO:%" PRI_EO " stop-func failed:%" PRI_STAT
"", eo, ret);
1100 eo_elem_t *
const eo_elem = eo_elem_get(eo);
1105 "Invalid EO:%" PRI_EO "", eo);
1108 "EO invalid state, cannot stop:%d", eo_elem->
state);
1119 ret = queue_disable_all(eo_elem);
1120 if (unlikely(ret !=
EM_OK))
1121 goto eo_stop_sync_error;
1129 int reqs_sent = eo_stop_sync_local_req(eo_elem);
1131 if (unlikely(reqs_sent < 0)) {
1134 "EO:%" PRI_EO " eo_stop_sync_local_req():%d",
1137 goto eo_stop_sync_error;
1140 if (reqs_sent > 0) {
1156 ret = eo_stop_done(eo_elem);
1159 "EO:%" PRI_EO " stop-func failed", eo);
1169 "Failure: EO:%" PRI_EO "", eo);
1174 return eo_current();
1179 const eo_elem_t *eo_elem = eo_elem_get(eo);
1184 "Invalid EO:%" PRI_EO "", eo);
1190 "EO:%" PRI_EO " not created!", eo);
1194 eo_state = eo_elem->
state;
1197 "Invalid EO state: EO:%" PRI_EO " state:%d",
1207 const eo_elem_t *eo_elem = eo_elem_get(eo);
1211 "Invalid EO:%" PRI_EO "", eo);
1217 "EO:%" PRI_EO " not created", eo);
1221 return eo_elem->
state;
1226 _eo_tbl_iter_idx = 0;
1227 const unsigned int eo_cnt = eo_count();
1238 while (!eo_allocated(&
em_shm->eo_tbl.eo_elem[_eo_tbl_iter_idx])) {
1244 return eo_idx2hdl(_eo_tbl_iter_idx);
1255 while (!eo_allocated(&
em_shm->eo_tbl.eo_elem[_eo_tbl_iter_idx])) {
1261 return eo_idx2hdl(_eo_tbl_iter_idx);
1267 const unsigned int max_queues =
em_shm->queue_tbl.max_queue_num;
1269 if (unlikely(eo_elem == NULL || !eo_allocated(eo_elem))) {
1271 "Invalid EO:%" PRI_EO "", eo);
1277 const unsigned int num_queues = odp_atomic_load_u32(&eo_elem->
num_queues);
1282 if (num_queues == 0) {
1283 _eo_q_iter_idx = max_queues;
1300 while (!queue_allocated(&queue_tbl->queue_elem[_eo_q_iter_idx]) ||
1301 queue_tbl->queue_elem[_eo_q_iter_idx].eo != (uint16_t)(uintptr_t)_eo_q_iter_eo) {
1303 if (_eo_q_iter_idx >= max_queues)
1307 return queue_idx2hdl(_eo_q_iter_idx);
1312 const unsigned int max_queues =
em_shm->queue_tbl.max_queue_num;
1314 if (_eo_q_iter_idx >= max_queues - 1)
1322 while (!queue_allocated(&queue_tbl->queue_elem[_eo_q_iter_idx]) ||
1323 queue_tbl->queue_elem[_eo_q_iter_idx].eo != (uint16_t)(uintptr_t)_eo_q_iter_eo) {
1325 if (_eo_q_iter_idx >= max_queues)
1329 return queue_idx2hdl(_eo_q_iter_idx);
1334 return (uint64_t)eo;
#define INTERNAL_ERROR(error, escope, fmt,...)
#define RETURN_ERROR_IF(cond, error, escope, fmt,...)
#define EM_CHECK_INIT_CALLED
void poll_unsched_ctrl_queue(void)
Poll EM's internal unscheduled control queues during dispatch.
em_status_t check_notif_tbl(const int num_notif, const em_notif_t notif_tbl[])
Check that the usage of a table of notifications is valid.
em_status_t send_notifs(const int num_notif, const em_notif_t notif_tbl[])
Helper func to send notifications events.
ENV_LOCAL em_locm_t em_locm
#define EM_EO_MULTIRCV_MAX_EVENTS
em_status_t em_eo_register_error_handler(em_eo_t eo, em_error_handler_t handler)
em_status_t em_eo_remove_queue_all_sync(em_eo_t eo, int delete_queues)
em_eo_t em_eo_first(unsigned int *num)
em_eo_t em_eo_current(void)
em_eo_t em_eo_create(const char *name, em_start_func_t start, em_start_local_func_t local_start, em_stop_func_t stop, em_stop_local_func_t local_stop, em_receive_func_t receive, const void *eo_ctx)
em_status_t em_eo_remove_queue_all(em_eo_t eo, int delete_queues, int num_notif, const em_notif_t notif_tbl[])
size_t em_eo_name(em_eo_t eo, char *name, size_t maxlen)
em_status_t em_eo_remove_queue(em_eo_t eo, em_queue_t queue, int num_notif, const em_notif_t notif_tbl[])
em_status_t em_eo_start(em_eo_t eo, em_status_t *result, const em_eo_conf_t *conf, int num_notif, const em_notif_t notif_tbl[])
em_status_t em_eo_stop(em_eo_t eo, int num_notif, const em_notif_t notif_tbl[])
em_status_t(* em_start_local_func_t)(void *eo_ctx, em_eo_t eo)
void(* em_receive_func_t)(void *eo_ctx, em_event_t event, em_event_type_t type, em_queue_t queue, void *q_ctx)
em_status_t(* em_stop_func_t)(void *eo_ctx, em_eo_t eo)
em_status_t(* em_stop_local_func_t)(void *eo_ctx, em_eo_t eo)
em_eo_t em_eo_find(const char *name)
void em_eo_param_init(em_eo_param_t *param)
em_queue_t em_eo_queue_next(void)
em_queue_t em_eo_queue_first(unsigned int *num, em_eo_t eo)
em_status_t em_eo_start_sync(em_eo_t eo, em_status_t *result, const em_eo_conf_t *conf)
void * em_eo_context(em_eo_t eo)
em_status_t em_eo_unregister_error_handler(em_eo_t eo)
em_status_t em_eo_add_queue(em_eo_t eo, em_queue_t queue, int num_notif, const em_notif_t notif_tbl[])
void em_eo_multircv_param_init(em_eo_multircv_param_t *param)
em_status_t em_eo_add_queue_sync(em_eo_t eo, em_queue_t queue)
em_eo_state_t em_eo_state(em_eo_t eo)
em_status_t(* em_start_func_t)(void *eo_ctx, em_eo_t eo, const em_eo_conf_t *conf)
em_status_t em_eo_stop_sync(em_eo_t eo)
uint64_t em_eo_to_u64(em_eo_t eo)
em_status_t em_eo_delete(em_eo_t eo)
em_status_t em_eo_remove_queue_sync(em_eo_t eo, em_queue_t queue)
em_eo_t em_eo_create_multircv(const char *name, const em_eo_multircv_param_t *param)
em_eo_t em_eo_create_param(const char *name, const em_eo_param_t *param)
@ EM_EO_START_LOCAL_MODE_CONFIG_FILE
@ EM_EO_START_LOCAL_MODE_LAST
@ EM_EO_STOP_LOCAL_MODE_CONFIG_FILE
@ EM_EO_STOP_LOCAL_MODE_LAST
em_status_t(* em_error_handler_t)(em_eo_t eo, em_status_t error, em_escope_t escope, va_list args)
@ EM_ERR_OPERATION_FAILED
em_queue_type_t em_queue_type(em_queue_t queue)
em_start_local_func_t local_start
uint32_t __internal_check
em_eo_start_local_mode_t local_start_mode
em_receive_multi_func_t receive_multi
em_stop_local_func_t local_stop
em_eo_stop_local_mode_t local_stop_mode
em_eo_start_local_mode_t local_start_mode
em_stop_local_func_t local_stop
uint32_t __internal_check
em_eo_stop_local_mode_t local_stop_mode
em_start_local_func_t local_start
em_receive_func_t receive
em_locm_current_t current
eo_elem_t * start_eo_elem
em_error_handler_t error_handler_func
em_eo_stop_local_mode_t stop_local_mode
em_receive_func_t receive_func
em_stop_local_func_t stop_local_func
em_receive_multi_func_t receive_multi_func
odp_atomic_u32_t num_queues
em_eo_start_local_mode_t start_local_mode
em_start_func_t start_func
em_start_local_func_t start_local_func