EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
event_machine.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012, Nokia Siemens Networks
3 * Copyright (c) 2015-2025, Nokia Solutions and Networks
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef EVENT_MACHINE_H
33#define EVENT_MACHINE_H
34
35#pragma GCC visibility push(default)
36
37/**
38 * @file
39 * Event Machine API
40 *
41 * This file includes all other needed EM headers
42 */
43
44/** @mainpage
45 *
46 * @section section_1 General
47 * Event Machine (EM) is a framework and an architectural abstraction of an
48 * event driven, multicore optimized, processing concept originally developed
49 * for the networking data plane. It offers an easy programming concept for
50 * scalable and dynamically load balanced multicore applications with a very
51 * low overhead run-to-completion principle.
52 *
53 * Events, queues and execution objects (EO) along with the scheduler and the
54 * dispatcher form the main elements of the EM concept. An event is an
55 * application specific piece of data (like a message or a network packet)
56 * describing work, something to do. All processing in EM must be triggered by
57 * an event. Events are sent to asynchronous application specific EM queues.
58 * A dispatcher loop is run by a single thread on each core in the EM instance
59 * ("core" is used here to refer to a core or one HW thread on multi-threaded
60 * cores). The dispatcher on each core interfaces with the scheduler and asks
61 * for an event to process. The scheduler then evaluates the state of all the
62 * EM queues and gives the highest priority event available to the requesting
63 * dispatcher. The dispatcher looks up which EO owns the queue that the event
64 * came from and finally calls the EO's registered receive function to deliver
65 * the event for processing. When the event has been handled and the EO's
66 * receive function returns, it's again time for the dispatcher on that core to
67 * request another event from the scheduler and deliver it to the corresponding
68 * EO. The aforedescribed scenario happens in parallel on all cores running the
69 * EM instance. Events originating from a particular queue might thus be given
70 * for processing on any core, decided separately for each event by the
71 * scheduler as the dispatcher on a core requests more work - this is per-event
72 * dynamic load-balancing. EM contains mechanisms to ensure atomicity and event
73 * (re-)ordering.
74 *
75 * The EM concept has been designed to be highly efficient, operating in a
76 * run-to-completion manner on each participating core with neither context
77 * switching nor pre-emption slowing down the event processing loops.
78 * EM can run on bare metal for best performance or under an operating system
79 * with special arrangements (e.g. one thread per core with thread affinity).
80 *
81 * The concept and the API are intended to allow fairly easy implementations on
82 * general purpose or networking oriented multicore packet processing SoCs,
83 * which typically also contain accelerators for packet processing needs.
84 * Efficient integration with modern HW accelerators has been a major driver of
85 * the EM concept.
86 *
87 * One general principle of the EM API is that the function calls are mostly
88 * multicore safe. The application still needs to consider parallel processing
89 * data hazards and race conditions unless explicitly documented in the API for
90 * the function call in question. For example, one core might ask for a queue
91 * context while another core changes it, thus the returned context may be
92 * invalid (valid data, but either the old or the new value is returned). Thus
93 * modifications of shared state or data should be protected by an atomic
94 * context (if load balancing is used) or otherwise synchronized by the
95 * application itself. One simple way to achieve atomic processing is to use an
96 * atomic queue to serialize the EO's incoming events and perform management
97 * operations in the EO's receive function. This serialization limits the
98 * throughput of the atomic queue in question to the equivalent throughput of a
99 * single core, but since normally EM applications use multiple queues, all
100 * cores should get events to process and the total throughput will be relative
101 * to the number of cores running the EM instance.
102 *
103 * EM_64_BIT or EM_32_BIT (needs to be defined by the build) defines whether
104 * (most of) the types used in the API are 32 or 64 bits wide. NOTE, that this
105 * is a major decision, since it may limit value passing between different
106 * systems using the defined types directly. Using 64-bits may allow for a more
107 * efficient underlying implementation, as e.g. more data can be coded in
108 * 64-bit identifiers.
109 *
110 * @section section_2 Principles
111 * - This API attempts to guide towards a portable application architecture,
112 * but is not defined for portability by re-compilation. Many things are system
113 * specific giving more possibilities for efficient use of HW resources.
114 * - EM does not define event content (one exception, see em_alloc()). This is
115 * a choice made for performance reasons, since most HW devices use proprietary
116 * descriptors. This API enables the usage of those directly.
117 * - EM does not define a detailed queue scheduling discipline or an API to set
118 * it up with (or actually anything to configure a system). The priority value
119 * in this API is a (mapped) system specific QoS class label only.
120 * - In general, EM does not implement a full SW platform or a middleware
121 * solution, it implements a subset - a driver level part. For best
122 * performance it can be used directly from the applications.
123 *
124 * @section section_3 Inter-system communication
125 * EM does not define how to communicate with another EM instance or another
126 * system transparently. However, this is a typical need and the current API
127 * does have ways to achieve almost transparent communication between systems
128 * ("event chaining"):
129 * Since the queue identifier is a system specific value, it is easy to encode
130 * extra information into it in the EM implementation. For instance it could be
131 * split into two parts, where the lower part is a local queue id or index and
132 * the higher part, if not zero, points to another system. The implementation
133 * of em_send() can detect a non-local queue and forward events to the target
134 * using any transport mechanism available and once at the target instance the
135 * lower part is used to map to a local queue. For the application nothing
136 * changes. The problem is the lack of shared memory between those systems.
137 * The given event can be fully copied, but it should not have any references to
138 * sender's local memory. Thus it is not fully transparent if the event contains
139 * references to local memory (e.g. pointers).
140 *
141 * @section section_4 Files
142 * @subsection sub_1 EM API
143 * - event_machine.h
144 * - Event Machine API -the application should include this file only.
145 *
146 * Files included by event_machine.h:
147 * - event_machine_version.h
148 * - Event Machine version defines, macros and APIs
149 * - event_machine_deprecated.h
150 * - EM API deprecation defines & macros
151 * - event_machine_config.h
152 * - Event Machine constants and configuration options
153 * - event_machine_types.h
154 * - Event Machine basic types
155 * - event_machine_error.h
156 * - error logging and management related functionality
157 * - event_machine_init.h
158 * - Event Machine initialization and termination
159 * - event_machine_event.h
160 * - event related functionality
161 * - event_machine_packet.h
162 * - packet event related functionality
163 * - event_machine_pool.h
164 * - event pool related functionality
165 * - event_machine_eo.h
166 * - EO related functionality
167 * - event_machine_event_group.h
168 * - event group feature for fork-join type of operations using events
169 * - event_machine_atomic_group.h
170 * - functionality for atomic groups of queues (API 1.1)
171 * - event_machine_queue.h
172 * - queue related functionality
173 * - event_machine_queue_group.h
174 * - queue group related functionality
175 * - event_machine_core.h
176 * - core/thread related functionality
177 * - event_machine_core_mask.h
178 * - Core mask manipulation functions
179 * - event_machine_scheduler.h
180 * - scheduling related functionality
181 * - event_machine_dispatcher.h
182 * - dispatching related functionality
183 * - event_machine_hooks.h
184 * - API-hooks and idle-hooks
185 * - event_machine_timer.h
186 * - timer APIs
187 * - event_machine_timer_hw_specific.h
188 * - Platform specific timer definitions
189 *
190 * @subsection sub_2 Helper API
191 * These files must be separately included by the application on a need basis.
192 * - event_machine_helper.h
193 * - optional helper routines
194 * - event_machine_debug.h
195 * - optional debug helpers (only for debug use)
196 *
197 * @subsection sub_3 Extension API
198 * These files must be separately included by the application on a need basis.
199 * - event_machine_odp_ext.h
200 * - EM <-> ODP conversion functions and ODP related helpers
201 *
202 * @example hello.c
203 * @example api_hooks.c
204 * @example cli_top.c
205 * @example dispatcher_callback.c
206 * @example dyn_cores.c
207 * @example error.c
208 * @example event_group.c
209 * @example event_group_abort.c
210 * @example event_group_assign_end.c
211 * @example event_group_chaining.c
212 * @example event_types.c
213 * @example fractal.c
214 * @example ordered.c
215 * @example queue_types_ag.c
216 * @example queue_types_local.c
217 * @example queue_group.c
218 * @example timer_hello.c
219 * performance:
220 * @example atomic_processing_end.c
221 * @example loop_united.c
222 * @example pool_perf.c
223 * @example queue_groups.c
224 * @example queues.c
225 * @example queues_local.c
226 * @example queues_output.c
227 * @example queues_unscheduled.c
228 * @example scheduling_latency.c
229 * @example send_multi.c
230 * @example timer_test.c
231 * @example timer_test_periodic.c
232 * @example timer_test_ring.c
233 * bench:
234 * @example bench_event.c
235 * @example bench_pool.c
236 */
237
238/* EM deprecation macros & defines */
240/* EM version */
242/* EM config values */
244/* EM types */
246/* EM Error reporting and management */
248/* EM Core Mask types and manipulation functions */
250/* EM Core functions */
252/* EM Execution Object (EO) related functions */
254/* EM Queue functions */
256/* EM Queue Group functions */
258/* EM Event functions */
260/* EM Packet Event functions */
262/* EM Atomic Group functions */
264/* EM Event Group functions */
266/* EM Scheduler functions */
268/* EM Dispatcher functions */
270/* EM Event Pool functions */
272/* EM API hooks */
274/* EM initialization and termination */
276/* EM Timer HW/Platform specific */
278/* EM Timer */
280
281#pragma GCC visibility pop
282#endif /* EVENT_MACHINE_H */