EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
event_machine_scheduler.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_SCHEDULER_H_
32#define EVENT_MACHINE_SCHEDULER_H_
33
34#pragma GCC visibility push(default)
35
36/**
37 * @file
38 * @defgroup em_scheduler Scheduler
39 * Event Machine event scheduling related services
40 * @{
41 *
42 * Most of the event scheduling is a system dependent implementation but the
43 * common services here can be used for performance tuning etc.
44 *
45 * Do not include this from the application, event_machine.h will
46 * do it for you.
47 */
48
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55/**
56 * Scheduling context types
57 */
58typedef enum {
59 /**
60 * Parallel or released context
61 */
63 /**
64 * Atomic context
65 */
67 /**
68 * Ordered context
69 */
72
73/**
74 * A hint to release an atomic processing context.
75 *
76 * This function can be used to release the atomic context before returning from
77 * the EO receive function.
78 *
79 * After this API call is the scheduler allowed to schedule another event from
80 * the same atomic queue (or atomic group) that established the current
81 * atomic context, to another (or same) core.
82 *
83 * When an event has been received from an atomic queue, the scheduler is
84 * allowed to schedule another event from the same atomic queue to another,
85 * or same, core after this API call. This increases parallelism and may improve
86 * performance - however, the exclusive processing and ordering might be lost.
87 * Note, however, that this is a hint only, the scheduler is still allowed to
88 * keep the atomic context until scheduling the next event.
89 *
90 * Can only be called from within the EO receive function.
91 *
92 * The call is ignored if the currently active scheduling context type is not
93 * atomic (EM_SCHED_CONTEXT_TYPE_ATOMIC, see em_sched_context_type_current()).
94 *
95 * Pseudo-code example:
96 * @code
97 * receive_func(void* eo_ctx, em_event_t event, em_event_type_t type,
98 * em_queue_t queue, void* q_ctx)
99 * {
100 * if(is_my_atomic_queue(q_ctx))
101 * {
102 * // this needs to be done atomically:
103 * update_sequence_number(event);
104 *
105 * em_atomic_processing_end();
106 * // do other processing (potentially) in parallel:
107 * do_long_parallel_work();
108 * }
109 * }
110 * @endcode
111 *
112 * @see em_receive_func_t(), event_machine_queue.h
113 */
114void em_atomic_processing_end(void);
115
116/**
117 * A hint to allow release of the ordered processing context.
118 *
119 * This function can be used to tell the scheduler that all events to be sent
120 * under the current ordering context are already sent. Events sent after this
121 * are no longer required to be kept in order. This may increase system
122 * performance. It permits early release of the ordering context, but an
123 * EM implementation is still allowed to keep it until scheduling the next
124 * incoming event.
125 *
126 * Can only be called from within the EO receive function.
127 *
128 * The call is ignored if the currently active scheduling context type is not
129 * ordered (EM_SCHED_CONTEXT_TYPE_ORDERED, see em_sched_context_type_current()).
130 *
131 * The ordering context cannot be resumed after it has been released.
132 *
133 * @see em_receive_func_t(), event_machine_queue.h
134 */
136
137/**
138 * A hint to start scheduling for this core
139 *
140 * This is a performance optimization hint with no functional effect. A hint is
141 * given to the scheduler to start scheduling the next event for the calling
142 * core as it is about to end processing of the current event. This can be used
143 * to reduce the latency of scheduling.
144 * Depending on the actual scheduler implementation, this may be a no-operation.
145 */
146void em_preschedule(void);
147
148/**
149 * Return the currently active scheduling context type
150 *
151 * Returns the current scheduling context type (none, ordered, atomic) and
152 * optionally the queue that determines the context.
153 * Note, that the scheduling context type is not the same as the queue type
154 * since the scheduling context type could have been released by the user, or
155 * inherited by local queue processing.
156 *
157 * This function is mainly for handling local queues that inherit the scheduling
158 * context that was active for the sending EO. The scheduling context can be
159 * unpredictable unless the processing chain is carefully crafted.
160 * This function will return the active scheduling context type and queue of the
161 * last event from the scheduler (i.e. the scheduled queue of the EO that sent
162 * the event to the first local queue in the chain).
163 *
164 * @param[out] queue if not NULL, set to the queue that determines the current
165 * sched context
166 *
167 * @return current context type
168 *
169 * @see em_queue_create(), em_sched_context_type_t
170 */
172em_sched_context_type_current(em_queue_t *queue);
173
174/**
175 * @}
176 */
177#ifdef __cplusplus
178}
179#endif
180
181#pragma GCC visibility pop
182#endif /* EVENT_MACHINE_SCHEDULER_H_ */
void em_ordered_processing_end(void)
em_sched_context_type_t em_sched_context_type_current(em_queue_t *queue)
void em_preschedule(void)
void em_atomic_processing_end(void)
em_sched_context_type_t
@ EM_SCHED_CONTEXT_TYPE_ORDERED
@ EM_SCHED_CONTEXT_TYPE_NONE
@ EM_SCHED_CONTEXT_TYPE_ATOMIC