45 em_queue_t shared_unsched_queue;
49 const char *err_str =
"";
51 EM_DBG(
"%s()\n", __func__);
59 shared_unsched_queue = queue_id2hdl(SHARED_INTERNAL_UNSCHED_QUEUE);
73 memset(&unsch_conf, 0,
sizeof(unsch_conf));
76 for (
int i = 0; i < num_cores; i++) {
79 queue_req = queue_id2hdl(FIRST_INTERNAL_UNSCHED_QUEUE + i);
80 snprintf(q_name,
sizeof(q_name),
"EMctrl-unschedQ-core%d", i);
99 em_queue_t unsched_queue;
100 em_event_t unsched_event;
103 unsched_queue = queue_id2hdl(SHARED_INTERNAL_UNSCHED_QUEUE);
111 if (unlikely(stat !=
EM_OK))
113 "shared unschedQ delete");
115 for (
int i = 0; i < num_cores; i++) {
116 unsched_queue = queue_id2hdl(FIRST_INTERNAL_UNSCHED_QUEUE + i);
126 if (unlikely(stat !=
EM_OK))
128 "core unschedQ:%d delete", i);
136 void (*f_done_callback)(
void *arg_ptr),
137 void *f_done_arg_ptr,
148 int unsent_count = mask_count;
151 em_event_t events[mask_count];
155 "Too large notif table (%i)", num_notif);
163 f_done_callback, f_done_arg_ptr,
164 num_notif, notif_tbl,
168 "Internal 'done' notif setup failed");
177 for (i = 0; i < mask_count - 1; i++) {
183 EM_ESCOPE_INTERNAL_NOTIF,
184 "Internal event alloc failed");
185 goto err_free_resources;
191 *i_event_tmp = *i_event;
194 events[i] = ctrl_event;
200 first_qidx = queue_id2idx(FIRST_INTERNAL_UNSCHED_QUEUE);
202 for (i = 0; i < core_count; i++) {
209 queue_idx2hdl(first_qidx + i),
211 if (unlikely(err !=
EM_OK)) {
213 "Event group send failed");
214 goto err_free_resources;
225 for (i = sent_count; i < alloc_count; i++)
242 if (unlikely(ret !=
EM_OK))
244 "Event group %" PRI_EGRP " delete failed (ret=%u)",
245 i_ev->
done.event_group, ret);
248 if (i_ev->
done.f_done_callback != NULL)
249 i_ev->
done.f_done_callback(i_ev->
done.f_done_arg_ptr);
254 num_notif = i_ev->
done.num_notif;
258 if (unlikely(ret !=
EM_OK))
260 "em_send() of notifs(%d) failed",
269 internal_event_receive(
void *eo_ctx, em_event_t event,
em_event_type_t type,
270 em_queue_t queue,
void *q_ctx)
279 if (unlikely(!i_event)) {
283 "Q:%" PRI_QUEUE ": Invalid event, evptr NULL", queue);
287 switch (i_event->
id) {
291 case EM_INTERNAL_DONE:
292 i_event__internal_done(i_event);
298 case QUEUE_GROUP_ADD_REQ:
305 case QUEUE_GROUP_REM_REQ:
311 case EO_START_LOCAL_REQ:
312 case EO_START_SYNC_LOCAL_REQ:
313 case EO_STOP_LOCAL_REQ:
314 case EO_STOP_SYNC_LOCAL_REQ:
315 case EO_REM_QUEUE_LOCAL_REQ:
316 case EO_REM_QUEUE_SYNC_LOCAL_REQ:
317 case EO_REM_QUEUE_ALL_LOCAL_REQ:
318 case EO_REM_QUEUE_ALL_SYNC_LOCAL_REQ:
324 EM_ESCOPE_INTERNAL_EVENT_RECV_FUNC,
325 "Internal ev-id:0x%" PRIx64
" Q:%" PRI_QUEUE "",
336 void (*f_done_callback)(
void *arg_ptr),
337 void *f_done_arg_ptr,
341 em_event_group_t event_group;
351 EM_ESCOPE_INTERNAL_DONE_W_NOTIF_REQ,
352 "Internal event 'DONE' alloc failed!");
360 EM_ESCOPE_INTERNAL_DONE_W_NOTIF_REQ,
361 "Event group create failed!");
366 i_event->
id = EM_INTERNAL_DONE;
367 i_event->
done.event_group = event_group;
368 i_event->
done.f_done_callback = f_done_callback;
369 i_event->
done.f_done_arg_ptr = f_done_arg_ptr;
370 i_event->
done.num_notif = num_notif;
372 for (
int i = 0; i < num_notif; i++) {
378 i_notif.
event = event;
379 if (sync_operation) {
380 i_notif.
queue = queue_id2hdl(FIRST_INTERNAL_UNSCHED_QUEUE +
383 i_notif.
queue = queue_id2hdl(SHARED_INTERNAL_UNSCHED_QUEUE);
394 if (unlikely(err !=
EM_OK)) {
396 "Event group apply failed");
415 if (err ==
EM_OK && num > 0) {
416 for (
int i = 0; i < num; i++)
417 em_free(free_notif_tbl[i].event);
428 for (
int i = 0; i < num_notif; i++) {
429 const em_event_t
event = notif_tbl[i].
event;
430 const em_queue_t queue = notif_tbl[i].
queue;
431 const em_event_group_t egrp = notif_tbl[i].
egroup;
434 if (invalid_egrp(egrp))
439 if (unlikely(err !=
EM_OK)) {
455 const bool is_external = queue_external(notif->
queue);
460 if (unlikely(q_elem == NULL || !queue_allocated(q_elem)))
466 event_group_elem_get(notif->
egroup);
468 if (unlikely(egrp_elem == NULL ||
469 !event_group_allocated(egrp_elem)))
484 if (unlikely(num_notif > 0 && notif_tbl == NULL))
487 for (
int i = 0; i < num_notif; i++) {
489 if (unlikely(err !=
EM_OK))
500 handle_ctrl_events(em_queue_t unsched_queue,
501 const em_event_t ev_tbl[],
const int num)
506 event_to_hdr_multi(ev_tbl, evhdr_tbl, num);
508 for (
int i = 0; i < num; i++) {
514 em_event_t
event = ev_tbl[i];
519 event_group_set_local(ev_hdr->
egrp, ev_hdr->
egrp_gen, 1);
521 internal_event_receive(NULL, event, event_type,
522 unsched_queue, NULL);
533 event_group_count_decrement(1);
552 const int deq_max = 16;
553 em_event_t core_ev_tbl[deq_max];
554 em_event_t shared_ev_tbl[deq_max];
560 core_num = queue_dequeue_multi(core_unsch_qelem,
561 core_ev_tbl, deq_max);
562 shared_num = queue_dequeue_multi(shared_unsch_qelem,
563 shared_ev_tbl, deq_max);
564 if (core_num <= 0 && shared_num <= 0)
577 handle_ctrl_events(core_unsched_queue, core_ev_tbl, core_num);
579 if (shared_num > 0) {
582 handle_ctrl_events(shared_unsched_queue, shared_ev_tbl, shared_num);