EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
event_machine_dispatcher.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#ifndef EVENT_MACHINE_DISPATCHER_H_
32#define EVENT_MACHINE_DISPATCHER_H_
33
34#pragma GCC visibility push(default)
35
36/**
37 * @file
38 * @defgroup em_dispatcher Dispatcher
39 * Event Machine dispatcher related services.
40 * @{
41 *
42 * The EM dispatcher contains the main loop of processing on each EM-core of
43 * type 'worker' or 'control', and interfaces with the event scheduler to obtain
44 * events for processing.
45 * Further, the EM dispatcher is responsible for passing the events received
46 * on an EM-core, from the scheduler, to the correct EO-receive function along
47 * with information about which queue the events originated from, what their
48 * event types are etc. Different flavours of the EM dispatch APIs exist along
49 * with configuration options.
50 *
51 * Note that only EM-cores of type EM_CORE_TYPE_WORKER and EM_CORE_TYPE_CONTROL
52 * can call the EM dispatch functions. Calling dispatch functions on an
53 * EM external thread/process (EM_CORE_TYPE_EXTERNAL) is not allowed and will
54 * result in error.
55 *
56 * EM provides APIs to register, or unregister, dispatch callback hooks, i.e.
57 * user provided callback functions that will be run just before EM calls the
58 * EO-receive function or after returning from it. These callbacks are referred
59 * to as dispatch enter- and exit-callbacks respectively.
60 * The dispatch callbacks can be used to collect debug information, statistics
61 * or implement new functionality.
62 *
63 * The dispatch enter-callbacks are called before entering the EO-receive
64 * function on each EM-core separately. Events can be dropped by an enter-
65 * callback. Neither the EO-receive function nor any further enter-callbacks
66 * will be called if all events have been dropped by the callbacks already run.
67 * The callback itself needs to handle the events it drops, e.g. free them.
68 *
69 * The dispatch exit-callbacks are called after the EO-receive function returns
70 * and have no arguments except for the EO handle. Note that all exit-callbacks
71 * are always called (even if the enter-callbacks dropped the events causing the
72 * rest of the enter-callbacks and the EO-receive function to be skipped).
73 *
74 * Multiple callbacks can be registered. The calling order of multiple
75 * registered callbacks is the order of registration. If the same function is
76 * registered twice then it will be called twice. The max amount of simultaneous
77 * callbacks is set by the define 'EM_CALLBACKS_MAX'.
78 *
79 * EM does not know of any connection or relationship between registered
80 * dispatch enter- and/or exit-callbacks. All dispatch callbacks are treated as
81 * independent entries. Functionality that e.g. depends on both an enter- and an
82 * exit-callback being run must take into acconut that the previous
83 * enter-callbacks might have dropped all events, thus skipping the following
84 * enter-callbacks - but still running all exit-callbacks.
85 */
86
89
90#ifdef __cplusplus
91extern "C" {
92#endif
93
94/**
95 * @brief EM dispatch duration selection flags
96 *
97 * Combining (bitwise OR) several DURATION flags will instruct the EM dispatcher
98 * to dispatch until the first 'duration' condition is met, whichever happens
99 * first.
100 */
101typedef enum {
102 /** Select: dispatch forever, never return */
104 /** Select: dispatch until em_dispatch_opt_t::duration.rounds reached */
106 /** Select: dispatch until em_dispatch_opt_t::duration.ns reached */
108 /** Select: dispatch until em_dispatch_opt_t::duration.events reached */
110
111 /** Select: dispatch until em_dispatch_opt_t::duration.no_events.rounds reached */
113 /** Select: dispatch until em_dispatch_opt_t::duration.no_events.ns reached */
115
116 /* Keep last, for error checking */
117 EM_DISPATCH_DURATION_LAST
119
120/**
121 * Dispatch duration.
122 *
123 * Select which dispatch duration, or combination, is to be used with the
124 * em_dispatch_duration() function.
125 * Bitwise OR .select-flags for a combination.
126 * Dispatch will end when one of the selected 'duration' options is
127 * reached, whichever is hit first.
128 */
129typedef struct {
130 /**
131 * Select which 'duration'-fields that should be taken into account
132 * when evaluating the em_dispatch_duration() run time.
133 *
134 * Only the duration fields that correspond to set .select-flags
135 * will be used.
136 */
138
139 /*
140 * Duration fields / values below considered according to .select-flags:
141 */
142
143 /**
144 * Dispatch for the given number of rounds, if used must be > 0.
145 * Only considered if .select contains EM_DISPATCH_DURATION_ROUNDS.
146 */
147 uint64_t rounds;
148
149 /**
150 * Dispatch (at least) for the given time in nanoseconds,
151 * if used must be > 0.
152 * Only considered if .select contains EM_DISPATCH_DURATION_NS.
153 *
154 * Using a large value for the option 'wait_ns' relative to .ns
155 * might delay the return from dispatch.
156 *
157 * The runtime of the EO-receive function for the last batch of events
158 * is not covered by .ns.
159 * EM will request new events to dispatch while the
160 * elapsed dispatch time is < .ns.
161 */
162 uint64_t ns;
163
164 /**
165 * Dispatch until (at least) the given number of events have been
166 * handled, if used must be > 0.
167 * Only considered if .select contains EM_DISPATCH_DURATION_EVENTS.
168 *
169 * Note that the option 'burst_size' affects the number of events
170 * dispatched. EM will request new events to dispatch while the number
171 * of dispatched events is < .events and then handle the whole burst.
172 *
173 * The option 'sched_pause=true' might also increase the number of
174 * events dispatched since the EM dispatcher needs to fetch and handle
175 * any leftover events held locally by the scheduler before returning.
176 */
177 uint64_t events;
178
179 struct {
180 /**
181 * Dispatch until no events have been received for the
182 * given number of rounds, if used must be > 0.
183 * Only considered if .select contains
184 * EM_DISPATCH_DURATION_NO_EVENTS_ROUNDS.
185 */
186 uint64_t rounds;
187
188 /**
189 * Dispatch until no events have been received for the
190 * given time in nanoseconds, if used must be > 0.
191 * Only considered if .select contains
192 * EM_DISPATCH_DURATION_NO_EVENTS_NS.
193 */
194 uint64_t ns;
195 } no_events;
197
198/**
199 * @brief EM dispatch options
200 *
201 * The options must be initialized once with em_dispatch_opt_init() before
202 * using them with other em_dispatch_...() calls for the first time. Further
203 * calls to em_dispatch_...() with the same options structure do not need
204 * initialization and the user is allowed to modify the options between calls
205 * to change the dispatch behaviour.
206 *
207 * @see em_dispatch_opt_init(), em_dispatch_duration() etc.
208 */
209typedef struct {
210 /**
211 * Scheduler wait-for-events timeout in nanoseconds, might save power.
212 * The scheduler will wait for events, if no immediately available, for
213 * 'wait_ns' nanoseconds per scheduling / dispatch round.
214 *
215 * Note that using a large 'wait_ns' value relative to a
216 * dispatch duration in 'ns' might delay the return from dispatch.
217 *
218 * 0: do not wait for events (default)
219 */
220 uint64_t wait_ns;
221
222 /**
223 * Scheduler burst size.
224 * The max number of events the dispatcher will request in one burst
225 * from the scheduler.
226 *
227 * default: EM_SCHED_MULTI_MAX_BURST
228 */
229 uint16_t burst_size;
230
231 /**
232 * Override the possibly configured dispatcher input-polling callback
233 * (set via em_conf_local_t::input_poll_fn).
234 *
235 * false: Do not skip the input-poll callback if configured (default).
236 * true: Skip the input-poll callback in the dispatcher.
237 */
238 bool skip_input_poll; /* override em_conf_t configuration */
239
240 /**
241 * Override the possibly configured dispatcher output-drain callback
242 * (set via em_conf_local_t::output_drain_fn).
243 *
244 * false: Do not skip the output-drain callback if configured (default).
245 * true: Skip the output-drain callback in the dispatcher.
246 */
247 bool skip_output_drain; /* override em_conf_t configuration */
248
249 /**
250 * Pause the scheduler on the calling core when exiting the EM dispatch
251 * function. If enabled, will also resume the scheduling when entering
252 * dispatch. Pausing also implicitly causes the dispatcher to fetch and
253 * handle any leftover events held locally by the scheduler before
254 * returning.
255 *
256 * false: Do not pause and resume the scheduler when entering and
257 * exiting dispatch (default).
258 * true: Pause scheduling when exiting dispatch and resume scheduling
259 * when entering. EM will further empty and dispatch any remaining
260 * events locally stashed in the scheduler before returning
261 * causing some extra dispatch 'rounds' to be run.
262 */
264
265 /**
266 * Internal check - don't touch!
267 *
268 * EM will verify that em_dispatch_opt_init(opt) has been called
269 * before use with dispatch functions.
270 */
273
274/**
275 * @brief Dispatch results
276 *
277 * Output struct for returning the results of the em_dispatch_...() functions
278 * in. Usage of 'em_dispatch_results_t *results' with dispatch functions is
279 * optional and 'NULL' can be used if not interested in the results.
280 */
281typedef struct {
282 /**
283 * The number of dispatch rounds that were run.
284 */
285 uint64_t rounds;
286
287 /**
288 * The time in nanoseconds that dispatch was run.
289 * Only filled if requesting EM to dispatch for a certain amount of
290 * time, i.e. if EM_DISPATCH_DURATION_NS or
291 * EM_DISPATCH_DURATION_NO_EVENTS_NS duration selection flags were set
292 * in em_dispatch_duration_t::select when using em_dispatch_duration().
293 * Also set when used with em_dispatch_ns().
294 */
295 uint64_t ns;
296
297 /**
298 * The number of events that were dispatched.
299 */
300 uint64_t events;
302
303/**
304 * @brief Initialize the EM dispatch options.
305 *
306 * The options passed to em_dispatch_...() need to be initialized once before
307 * first use. Further calls to em_dispatch_...() with the same options structure
308 * do not need initialization and the user is allowed to modify the options
309 * between calls to change dispatch behaviour.
310 *
311 * This function may be called before em_init() or em_init_core() since it only
312 * sets the default values for the 'em_dispatch_opt_t *opt' argument.
313 *
314 * @param opt
315 */
317
318/**
319 * @brief Run the EM dispatcher for a certain duration with options.
320 *
321 * Called by an EM-core to dispatch (with options) events for EM processing.
322 * The EM dispatcher internally queries the scheduler for events for the
323 * calling EM-core and then dispatches them for processing, i.e. passes the
324 * events to the application EO's receive-function based on the queue the events
325 * were received / dequeued from.
326 *
327 * @note Only EM-cores of type EM_CORE_TYPE_WORKER and EM_CORE_TYPE_CONTROL
328 * can call the EM dispatch functions. Calling dispatch functions on an
329 * EM external thread/process (EM_CORE_TYPE_EXTERNAL) is not allowed.
330 *
331 * Combining (bitwise OR) several DURATION selection flags
332 * (see em_dispatch_duration_select_t) will dispatch until the first
333 * duration-condition is met, whichever happens first.
334 *
335 * Example usage:
336 * @code
337 * em_dispatch_duration_t duration;
338 * em_dispatch_opt_t opt;
339 * em_dispatch_results_t results;
340 * em_status_t status;
341 *
342 * em_dispatch_opt_init(&opt); // Mandatory once before first use!
343 * opt.wait_ns = 10000; // Wait max 10 us for events from scheduler
344 * opt.sched_pause = false; // Don't pause scheduling on return
345 *
346 * // Dispatch for 1000 rounds, 200 us or until 300 events have been
347 * // handled. Return when the first of these conditions is met.
348 * duration.select = EM_DISPATCH_DURATION_ROUNDS |
349 * EM_DISPATCH_DURATION_NS |
350 * EM_DISPATCH_DURATION_EVENTS;
351 * duration.rounds = 1000;
352 * duration.ns = 200000; // 200 us
353 * duration.events = 300;
354 * ...
355 * do {
356 * // Dispatch until '.rounds' or '.ns' or '.events' reached
357 * status = em_dispatch_duration(&duration, &opt, &results);
358 * ...
359 * // Update 'duration' and 'opt' based on 'results'
360 * // and/or runtime conditions
361 * } while (do_dispatch(&results, ...));
362 *
363 * // Prepare to leave EM dispatching
364 * duration.select = EM_DISPATCH_DURATION_NO_EVENTS_NS;
365 * duration.no_events.ns = 100000;
366 * opt.wait_ns = 0; // No waiting for events
367 * opt.skip_input_poll = true; // No callbacks
368 * opt.skip_output_drain = true; // -"-
369 * opt.sched_pause = true; // Pause scheduling on this EM-core
370 *
371 * status = em_dispatch_duration(&duration, &opt, &results);
372 * // Leave EM dispatching for a while
373 * @endcode
374 *
375 * @param duration Dispatch duration.
376 * @param opt Dispatch options (optional, can be NULL).
377 * If used, must have been initialized with
378 * em_dispatch_opt_init(). One initialization is enough,
379 * later calls to em_dispatch_...(...opt) can reuse (the
380 * possibly modified) 'opt'.
381 * Using NULL is the same as passing 'opt' initialized
382 * with em_dispatch_opt_init(&opt) without further changes.
383 * @param[out] results Dispatch results (optional, can be NULL).
384 * Filled for successful dispatch scenarios, i.e. when the
385 * return value is EM_OK.
386 *
387 * @return Error status code
388 * @retval EM_OK when dispatch was successful, 'result' is filled (if provided)
389 * @retval other than EM_OK on error, 'result' is untouched
390 */
392 const em_dispatch_opt_t *opt,
393 em_dispatch_results_t *results /*out*/);
394/**
395 * @brief Run the EM dispatcher for a given amount of time (in nanoseconds).
396 *
397 * Similar to em_dispatch_duration(), but with a simplified dispatch duration:
398 * here only the number of nanoseconds to dispatch is provided.
399 *
400 * Using a large value for 'opt.wait_ns' relative to 'ns' might delay the
401 * return from dispatch.
402 *
403 * The runtime of the EO-receive function for the last batch of events
404 * is not covered by 'ns'.
405 * EM will request new events to dispatch while the elapsed time is < 'ns'.
406 *
407 * @note Only EM-cores of type EM_CORE_TYPE_WORKER and EM_CORE_TYPE_CONTROL
408 * can call the EM dispatch functions. Calling dispatch functions on an
409 * EM external thread/process (EM_CORE_TYPE_EXTERNAL) is not allowed.
410 *
411 * @see em_dispatch_duration() for documentation and usage.
412 *
413 * @param ns Dispatch duration in nanoseconds.
414 * Note that 'ns=0' is not allowed!
415 * @param opt Dispatch options (optional, can be NULL).
416 * If used, must have been initialized with
417 * em_dispatch_opt_init(). One initialization is enough,
418 * later calls to em_dispatch_...(...opt) can reuse (the
419 * possibly modified) 'opt'.
420 * Using NULL is the same as passing 'opt' initialized
421 * with em_dispatch_opt_init(&opt) without further changes.
422 * @param[out] results Dispatch results (optional, can be NULL).
423 * Filled for successful dispatch scenarios, i.e. when the
424 * return value is EM_OK.
425 *
426 * @return Error status code
427 * @retval EM_OK when dispatch was successful, 'result' is filled (if provided)
428 * @retval other than EM_OK on error, 'result' is untouched
429 */
430em_status_t em_dispatch_ns(uint64_t ns,
431 const em_dispatch_opt_t *opt,
432 em_dispatch_results_t *results /*out*/);
433
434/**
435 * @brief Run the EM dispatcher until a given number of events have been
436 * dispatched.
437 *
438 * Similar to em_dispatch_duration(), but with a simplified dispatch duration:
439 * here only the number of events to dispatch is provided.
440 *
441 * Note that 'opt.burst_size' affects the number of events dispatched.
442 * EM will request new events to dispatch while the number of dispatched
443 * events is < .events and then handle the whole burst.
444 *
445 * The option 'opt.sched_pause=true' might also increase the number of
446 * events dispatched since the EM dispatcher needs to fetch and handle
447 * any leftover events held locally by the scheduler before returning.
448 *
449 * @note Only EM-cores of type EM_CORE_TYPE_WORKER and EM_CORE_TYPE_CONTROL
450 * can call the EM dispatch functions. Calling dispatch functions on an
451 * EM external thread/process (EM_CORE_TYPE_EXTERNAL) is not allowed.
452 *
453 * @see em_dispatch_duration() for documentation and usage.
454 *
455 * @param events Dispatch duration events. Dispatch until the given
456 * number of events have been dispatched.
457 * Note that 'events=0' is not allowed!
458 * @param opt Dispatch options (optional, can be NULL).
459 * If used, must have been initialized with
460 * em_dispatch_opt_init(). One initialization is enough,
461 * later calls to em_dispatch_...(...opt) can reuse (the
462 * possibly modified) 'opt'.
463 * Using NULL is the same as passing 'opt' initialized
464 * with em_dispatch_opt_init(&opt) without further changes.
465 * @param[out] results Dispatch results (optional, can be NULL).
466 * Filled for successful dispatch scenarios, i.e. when the
467 * return value is EM_OK.
468 *
469 * @return Error status code
470 * @retval EM_OK when dispatch was successful, 'result' is filled (if provided)
471 * @retval other than EM_OK on error, 'result' is untouched
472 */
473em_status_t em_dispatch_events(uint64_t events,
474 const em_dispatch_opt_t *opt,
475 em_dispatch_results_t *results /*out*/);
476
477/**
478 * @brief Run the EM dispatcher for a given number of dispatch-rounds.
479 *
480 * Similar to em_dispatch_duration(), but with a simplified dispatch duration:
481 * here only the number of rounds to dispatch is provided.
482 *
483 * @note Only EM-cores of type EM_CORE_TYPE_WORKER and EM_CORE_TYPE_CONTROL
484 * can call the EM dispatch functions. Calling dispatch functions on an
485 * EM external thread/process (EM_CORE_TYPE_EXTERNAL) is not allowed.
486 *
487 * @see em_dispatch_duration() for documentation and usage.
488 *
489 * @param rounds Dispatch duration rounds. Dispatch for the given number
490 * of rounds.
491 * Note that 'rounds=0' is not allowed!
492 * @param opt Dispatch options (optional, can be NULL).
493 * If used, must have been initialized with
494 * em_dispatch_opt_init(). One initialization is enough,
495 * later calls to em_dispatch_...(...opt) can reuse (the
496 * possibly modified) 'opt'.
497 * Using NULL is the same as passing 'opt' initialized
498 * with em_dispatch_opt_init(&opt) without further changes.
499 * @param[out] results Dispatch results (optional, can be NULL).
500 * Filled for successful dispatch scenarios, i.e. when the
501 * return value is EM_OK.
502 *
503 * @return Error status code
504 * @retval EM_OK when dispatch was successful, 'result' is filled (if provided)
505 * @retval other than EM_OK on error, 'result' is untouched
506 */
507em_status_t em_dispatch_rounds(uint64_t rounds,
508 const em_dispatch_opt_t *opt,
509 em_dispatch_results_t *results /*out*/);
510
511/**
512 * EM event dispatch
513 *
514 * Called by an EM-core to dispatch events for EM processing.
515 * The EM dispatcher internally queries the scheduler for events for the
516 * calling EM-core and then dispatches them for processing, i.e. passes the
517 * events to the application EO's receive-function based on the queue the events
518 * were received / dequeued from.
519 *
520 * See the EM config file for options controlling the global behaviour of
521 * em_dispatch().
522 *
523 * @note Only EM-cores of type EM_CORE_TYPE_WORKER and EM_CORE_TYPE_CONTROL
524 * can call the EM dispatch functions. Calling dispatch functions on an
525 * EM external thread/process (EM_CORE_TYPE_EXTERNAL) is not allowed.
526 *
527 * @param rounds Dispatch rounds before returning,
528 * 0 means 'never return from dispatch'
529 *
530 * @return The number of events dispatched on this core.
531 * Only makes sense if 'rounds > 0'
532 *
533 * @see em_dispatch_duration() for a function that enables dispatching
534 * with more options.
535 */
536uint64_t em_dispatch(uint64_t rounds);
537
538/**
539 * Dispatch enter-callback.
540 *
541 * Common dispatch callback run before EO-receive functions of both the
542 * em_receive_func_t and em_receive_multi_func_t types (i.e. for EOs created
543 * with either em_eo_create() or em_eo_create_multircv()).
544 *
545 * Enter-callbacks are run just before entering EO-receive functions, they can
546 * be useful for debugging, collecting statistics, manipulating events before
547 * they reach the EO or implementing new services needing synchronization
548 * between cores.
549 * Some of the arguments common for both types of EO receive functions are
550 * passed as pointers to the enter-callback so that the callback can optionally
551 * modify them. If modified, the new values will go to the next callback and
552 * eventually to the EO-receive function.
553 *
554 * Events can be dropped by changing the event-entries in the events[num]-array
555 * to EM_EVENT_UNDEF. Neither EO-receive nor any further enter-callbacks will
556 * be called if all events have been dropped by the callbacks already run, i.e.
557 * no callback will be called with 'num=0'.
558 * The callback itself needs to handle the events it drops, e.g. free them.
559 * Note: EM will remove entries of EM_EVENT_UNDEF from the events[]-array before
560 * calling the next enter-callback (if several registered) or the
561 * receive function and adjust 'num' accordingly for the call.
562 *
563 * Functionality that e.g. depends on both an enter- and an exit-callback being
564 * run must take into acconut that the previous enter-callbacks might have
565 * dropped all events, thus skipping the following enter-callbacks - but still
566 * running all exit-callbacks.
567 *
568 * The EO handle can be used to separate callback functionality per EO and the
569 * core id can be obtained for core specific functionality.
570 *
571 * Callback functions can be called concurrently from different cores.
572 *
573 * @see em_dispatch_register_enter_cb()
574 */
575typedef void (*em_dispatch_enter_func_t)(em_eo_t eo, void **eo_ctx,
576 em_event_t events[/*in/out*/], int num,
577 em_queue_t *queue, void **q_ctx);
578
579/**
580 * Dispatcher exit-callback.
581 *
582 * The exit-callbacks are run after EO-receive returns.
583 * Some arguments given to EO-receive might not be valid afterwards, thus
584 * the only argument given to the exit callback is the EO handle.
585 *
586 * Callback functions can be called concurrently from different cores.
587 *
588 * Functionality that e.g. depends on both an enter- and an exit-callback being
589 * run must take into acconut that the previous enter-callbacks might have
590 * dropped all events, thus skipping the following enter-callbacks - but still
591 * running all exit-callbacks.
592 *
593 * @see em_dispatch_register_exit_cb()
594 */
595typedef void (*em_dispatch_exit_func_t)(em_eo_t eo);
596
597/**
598 * Register a dispatch enter-callback
599 *
600 * Register a global function to be called by the dispatcher just before calling
601 * an EO-receive function. This can be useful for debugging, collecting
602 * statistics, manipulating events before they reach the EO or implementing new
603 * services needing synchronization between cores.
604 *
605 * The function registered should be kept short since it will be run each time
606 * just before calling EO-receive. All registered callbacks will further
607 * increase the processing time.
608 *
609 * Multiple callbacks can be registered.
610 * The order of calling multiple registered functions is the order of
611 * registration. If same function is registered twice it will be called twice.
612 * The maximum number of simultaneous callbacks is system specific
613 * (EM_CALLBACKS_MAX).
614 *
615 * @note A newly registered callback takes effect at scheduler-burst
616 * granularity (not per event). Events from a burst already pulled
617 * from the scheduler before the registration may bypass the new
618 * callback. The new callback is guaranteed to be called from the
619 * next scheduler burst onwards on each core.
620 *
621 * @param func Dispatch enter-callback function
622 *
623 * @return EM_OK if callback registration succeeded
624 *
625 * @see em_dispatch_enter_func_t for further documentation
626 */
628
629/**
630 * Unregister a dispatch enter-callback
631 *
632 * This can be used to unregister a previously registered enter-callback.
633 *
634 * The given function is searched for and, if found, removed from the call list.
635 * If the same function has been registered multiple times, only one reference
636 * is removed per unregister call.
637 * Note that when this function returns, no new calls to the unregistered
638 * callback are started from the next scheduler burst onwards on each
639 * core. A burst already in progress on another core might still invoke
640 * the callback for its remaining events. Additionally, another core
641 * could be in the middle of executing the function, so care must be
642 * taken before removing anything it may still use.
643 *
644 * @param func Dispatch enter-callback function
645 *
646 * @return EM_OK if the given function was found and removed.
647 */
649
650/**
651 * Register a dispatch exit-callback
652 *
653 * Register a global function to be called by the dispatcher just after return
654 * from an EO-receive function.
655 *
656 * The function registered should be kept short since it will be run each time
657 * just after EO-receive returns. All registered callbacks will further increase
658 * the processing time.
659 *
660 * Multiple callbacks can be registered.
661 * The order of calling multiple registered functions is the order of
662 * registration. If same function is registered twice it will be called twice.
663 * The maximum number of simultaneous callbacks is system specific
664 * (EM_CALLBACKS_MAX).
665 *
666 * @note A newly registered callback takes effect at scheduler-burst
667 * granularity (not per event). Events from a burst already pulled
668 * from the scheduler before the registration may bypass the new
669 * callback. The new callback is guaranteed to be called from the
670 * next scheduler burst onwards on each core.
671 *
672 * @param func Dispatch exit-callback function
673 *
674 * @return EM_OK if callback registration succeeded
675 *
676 * @see em_dispatch_exit_func_t for further documentation
677 */
679
680/**
681 * Unregister a dispatch exit-callback
682 *
683 * This can be used to unregister a previously registered exit-callback.
684 *
685 * The given function is searched for and, if found, removed from the call list.
686 * If the same function has been registered multiple times, only one reference
687 * is removed per unregister call.
688 * Note that when this function returns, no new calls to the unregistered
689 * callback are started from the next scheduler burst onwards on each
690 * core. A burst already in progress on another core might still invoke
691 * the callback for its remaining events. Additionally, another core
692 * could be in the middle of executing the function, so care must be
693 * taken before removing anything it may still use.
694 *
695 * @param func Dispatch exit-callback function
696 *
697 * @return EM_OK if the given function was found and removed.
698 *
699 * @see em_dispatch_exit_func_t
700 */
702
703/**
704 * @}
705 */
706#ifdef __cplusplus
707}
708#endif
709
710#pragma GCC visibility pop
711#endif /* EVENT_MACHINE_DISPATCHER_H_ */
em_status_t em_dispatch_events(uint64_t events, const em_dispatch_opt_t *opt, em_dispatch_results_t *results)
Run the EM dispatcher until a given number of events have been dispatched.
em_status_t em_dispatch_unregister_exit_cb(em_dispatch_exit_func_t func)
em_status_t em_dispatch_register_enter_cb(em_dispatch_enter_func_t func)
uint64_t em_dispatch(uint64_t rounds)
void em_dispatch_opt_init(em_dispatch_opt_t *opt)
Initialize the EM dispatch options.
em_status_t em_dispatch_register_exit_cb(em_dispatch_exit_func_t func)
em_status_t em_dispatch_ns(uint64_t ns, const em_dispatch_opt_t *opt, em_dispatch_results_t *results)
Run the EM dispatcher for a given amount of time (in nanoseconds).
em_status_t em_dispatch_rounds(uint64_t rounds, const em_dispatch_opt_t *opt, em_dispatch_results_t *results)
Run the EM dispatcher for a given number of dispatch-rounds.
em_status_t em_dispatch_unregister_enter_cb(em_dispatch_enter_func_t func)
em_status_t em_dispatch_duration(const em_dispatch_duration_t *duration, const em_dispatch_opt_t *opt, em_dispatch_results_t *results)
Run the EM dispatcher for a certain duration with options.
void(* em_dispatch_enter_func_t)(em_eo_t eo, void **eo_ctx, em_event_t events[], int num, em_queue_t *queue, void **q_ctx)
void(* em_dispatch_exit_func_t)(em_eo_t eo)
em_dispatch_duration_select_t
EM dispatch duration selection flags.
@ EM_DISPATCH_DURATION_ROUNDS
@ EM_DISPATCH_DURATION_NO_EVENTS_NS
@ EM_DISPATCH_DURATION_EVENTS
@ EM_DISPATCH_DURATION_NS
@ EM_DISPATCH_DURATION_FOREVER
@ EM_DISPATCH_DURATION_NO_EVENTS_ROUNDS
uint32_t em_status_t
em_dispatch_duration_select_t select