EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
event_machine_odp_ext.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/**
32 * @file
33 * @defgroup em_odp_ext Conversions & extensions
34 * Event Machine ODP API extensions and conversion functions between EM and ODP
35 * @{
36 */
37
38#ifndef EVENT_MACHINE_ODP_EXT_H
39#define EVENT_MACHINE_ODP_EXT_H
40
41#pragma GCC visibility push(default)
42
43#include <odp_api.h>
44
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/**
53 * Get the associated ODP queue.
54 *
55 * The given EM queue must have been created with em_queue_create...() APIs.
56 *
57 * @param queue EM queue
58 *
59 * @return odp queue if successful, ODP_QUEUE_INVALID on error
60 */
61odp_queue_t em_odp_queue_odp(em_queue_t queue);
62
63/**
64 * Get the associated EM queue.
65 *
66 * The associated EM queue must have been created with em_queue_create...() APIs
67 *
68 * @param queue ODP queue
69 *
70 * @return em queue if successful, EM_QUEUE_UNDEF on error
71 */
72em_queue_t em_odp_queue_em(odp_queue_t queue);
73
74/**
75 * @brief Map the given scheduled ODP pktin event queues to new EM queues.
76 *
77 * Creates new EM queues and maps them to use the given scheduled ODP pktin
78 * event queues.
79 * Enables direct scheduling of packets as EM events via EM queues.
80 * EM queues based on scheduled ODP pktin queues are a bit special in how they
81 * are created and how they are deleted:
82 * - creation is done via this function by providing the already set up
83 * scheduled ODP pktin event queues to use.
84 * - deletion of one of the returned EM queues will not delete the underlying
85 * ODP pktin event queue. The ODP queues in question are deleted when
86 * the ODP pktio is terminated.
87 * The scheduled ODP pktin event queues must have been set up with an
88 * ODP schedule group that belongs to an existing EM queue group. Also the used
89 * priority must mappable to an EM priority.
90 *
91 * Setup example:
92 * @code
93 * // Configure ODP pktin queues
94 * odp_pktin_queue_param_t pktin_queue_param;
95 * odp_pktin_queue_param_init(&pktin_queue_param);
96 * pktin_queue_param.num_queues = num;
97 * pktin_queue_param.queue_param.type = ODP_QUEUE_TYPE_SCHED;
98 * pktin_queue_param.queue_param.sched.prio = ODP prio mappable to EM prio
99 * pktin_queue_param.queue_param.sched.sync = PARALLEL | ATOMIC | ORDERED;
100 * pktin_queue_param.queue_param.sched.group = em_odp_qgrp2odp(EM qgroup);
101 * ...
102 * ret = odp_pktin_queue_config(pktio, &pktin_queue_param);
103 * if (ret < 0)
104 * error(...);
105 *
106 * // Obtain ODP pktin event queues used for scheduled packet input
107 * odp_queue_t pktin_sched_queues[num];
108 * ret = odp_pktin_event_queue(pktio, pktin_sched_queues['out'], num);
109 * if (ret != num)
110 * error(...);
111 *
112 * // Create EM queues mapped to the scheduled ODP pktin event queues
113 * em_queue_t queues_em[num];
114 * ret = em_odp_pktin_event_queues2em(pktin_sched_queues['in'],
115 * queues_em['out'], num);
116 * if (ret != num)
117 * error(...);
118 *
119 * // Add the EM queues to an EM EO and once the EO has been started it
120 * // will receive pktio events directly from the scheduler.
121 * for (int i = 0; i < num; i++)
122 * err = em_eo_add_queue_sync(eo, queues_em);
123 * @endcode
124 *
125 * @param[in] odp_pktin_evqueues Array of ODP pktin event queues to convert to
126 * EM-queues. The array must contain 'num' valid
127 * ODP-queue handles (as returned by the
128 * odp_pktin_event_queue() function).
129 * @param[out] queues Output array into which the corresponding
130 * EM-queue handles are written.
131 * Array must fit 'num' entries.
132 * @param num Number of entries in 'odp_pktin_evqueues[]'
133 * and 'queues[]'.
134 * @return int Number of EM queues created that correspond to the given
135 * ODP pktin event queues
136 * @retval <0 on failure
137 */
138int em_odp_pktin_event_queues2em(const odp_queue_t odp_pktin_evqueues[/*num*/],
139 em_queue_t queues[/*out:num*/], int num);
140
141/**
142 * Get the EM event header size.
143 *
144 * Needed e.g. when configuring a separate ODP packet pool and have pktio
145 * allocate events usable by EM from there:
146 * @code
147 * odp_pool_param_t::pkt.uarea_size = em_odp_event_hdr_size();
148 * @endcode
149 *
150 * @return EM event header size.
151 */
152uint32_t em_odp_event_hdr_size(void);
153
154/**
155 * Convert EM event handle to ODP event handle.
156 *
157 * @param event EM-event handle
158 *
159 * @return ODP event handle.
160 */
161odp_event_t em_odp_event2odp(em_event_t event);
162
163/**
164 * Convert EM event handles to ODP event handles
165 *
166 * @param events Array of EM-events to convert to ODP-events.
167 * The 'events[]' array must contain 'num' valid
168 * event handles.
169 * @param[out] odp_events Output array into which the corresponding ODP-event
170 * handles are written. Array must fit 'num' entries.
171 * @param num Number of entries in 'events[]' and 'odp_events[]'.
172 */
173void em_odp_events2odp(const em_event_t events[/*num*/],
174 odp_event_t odp_events[/*out:num*/], int num);
175
176/**
177 * Convert ODP event handle to EM event handle.
178 *
179 * The event must have been allocated by EM originally.
180 *
181 * @param odp_event ODP-event handle
182 *
183 * @return EM event handle.
184 */
185em_event_t em_odp_event2em(odp_event_t odp_event);
186
187/**
188 * Convert EM event handles to ODP event handles
189 *
190 * @param odp_events Array of ODP-events to convert to EM-events.
191 * The 'odp_events[]' array must contain 'num' valid
192 * ODP-event handles.
193 * @param[out] events Output array into which the corresponding EM-event
194 * handles are written. Array must fit 'num' entries.
195 * @param num Number of entries in 'odp_events[]' and 'events[]'.
196 */
197void em_odp_events2em(const odp_event_t odp_events[/*num*/],
198 em_event_t events[/*out:num*/], int num);
199
200/**
201 * @brief Get the ODP pools used as subpools in a given EM event pool.
202 *
203 * An EM event pool consists of 1 to 'EM_MAX_SUBPOOLS' subpools. Each subpool
204 * is an ODP pool. This function outputs the ODP pool handles of these subpools
205 * into a user-provided array and returns the number of handles written.
206 *
207 * The obtained ODP pools must not be deleted or alterede outside of EM,
208 * e.g. these ODP pools must only be deleted as part of an EM event pool
209 * using em_pool_delete().
210 *
211 * ODP pool handles obtained through this function can be used to
212 * - configure ODP pktio to use an ODP pool created via EM (allows for
213 * better ESV tracking)
214 * - print ODP-level pool statistics with ODP APIs etc.
215 *
216 * Note that direct allocations and free:s via ODP APIs will bypass
217 * EM checks (e.g. ESV) and might cause errors unless properly handled:
218 * - use em_odp_event2em() to initialize as an EM event
219 * - use em_event_mark_free() before ODP-free operations (SW- or HW-free)
220 *
221 * @param pool EM event pool handle.
222 * @param[out] odp_pools Output array to be filled with the ODP pools used as
223 * subpools in the given EM event pool. The array must
224 * fit 'num' entries.
225 * @param num Number of entries in the 'odp_pools[]' array.
226 * Using 'num=EM_MAX_SUBPOOLS' will always be large
227 * enough to fit all subpools in the EM event pool.
228 *
229 * @return The number of ODP pools filled into 'odp_pools[]'
230 */
231int em_odp_pool2odp(em_pool_t pool, odp_pool_t odp_pools[/*out*/], int num);
232
233/**
234 * @brief Get the EM event pool that the given ODP pool belongs to
235 *
236 * An EM event pool consists of 1 to 'EM_MAX_SUBPOOLS' subpools. Each subpool
237 * is an ODP pool. This function returns the EM event pool that contains the
238 * given ODP pool as a subpool.
239 *
240 * @param odp_pool ODP pool
241 *
242 * @return The EM event pool that contains the subpool 'odp_pool' or
243 * EM_POOL_UNDEF if 'odp_pool' is not part of any EM event pool.
244 */
245em_pool_t em_odp_pool2em(odp_pool_t odp_pool);
246
247/**
248 * @brief Get the ODP schedule group that corresponds to the given EM queue group
249 *
250 * @param queue_group
251 *
252 * @return ODP schedule group handle
253 * @retval ODP_SCHED_GROUP_INVALID on error
254 */
255odp_schedule_group_t em_odp_qgrp2odp(em_queue_group_t queue_group);
256
257/**
258 * Enqueue external packets into EM
259 *
260 * Enqueue packets from outside of EM into EM queues for processing.
261 * This function will initialize the odp packets properly as EM events before
262 * enqueueing them into EM.
263 * The odp packets might be polled from pktio or some other external source,
264 * e.g. the em_conf_local_t::input_poll_fn() function (see em_init_local()) can
265 * use this API to enqueue polled packets into EM queues.
266 * Inside EM, the application must use em_send...() instead to send/enqueue
267 * events into EM queues.
268 *
269 * @param pkt_tbl Array of external ODP-packets to enqueue into EM as events.
270 * The 'pkt_tbl[]' array must contain 'num' valid ODP packet
271 * handles.
272 * @param num The number of packets in the 'pkt_tbl[]' array, must be >0.
273 * @param queue EM queue into which to send/enqueue the packets as EM-events.
274 *
275 * @return The number of ODP packets successfully send/enqueued as EM-events
276 */
277int em_odp_pkt_enqueue(const odp_packet_t pkt_tbl[/*num*/], int num,
278 em_queue_t queue);
279
280/**
281 * @brief Get the odp timer_pool from EM timer handle
282 *
283 * Returns the corresponding odp timer_pool from a valid EM timer handle.
284 * This can be used for e.g. debugging.
285 *
286 * DO NOT use any odp apis directly to modify the odp timer_pool created by EM.
287 *
288 * @param tmr em timer handle
289 *
290 * @return odp timer_pool or ODP_TIMER_POOL_INVALID on failure
291 */
292odp_timer_pool_t em_odp_timer2odp(em_timer_t tmr);
293
294/**
295 * @brief Get the odp timer from EM timeout handle
296 *
297 * Returns the corresponding odp timer from a valid EM tmo handle.
298 * This can be used for e.g. debugging.
299 *
300 * DO NOT use any odp apis directly to modify the odp timer created by EM.
301 *
302 * @param tmo em timeout handle
303 *
304 * @return odp timer or ODP_TIMER_INVALID on failure
305 */
306odp_timer_t em_odp_tmo2odp(em_tmo_t tmo);
307
308/**
309 * @}
310 */
311#ifdef __cplusplus
312}
313#endif
314
315#pragma GCC visibility pop
316#endif /* EVENT_MACHINE_ODP_EXT_H */
int em_odp_pkt_enqueue(const odp_packet_t pkt_tbl[], int num, em_queue_t queue)
odp_schedule_group_t em_odp_qgrp2odp(em_queue_group_t queue_group)
Get the ODP schedule group that corresponds to the given EM queue group.
int em_odp_pool2odp(em_pool_t pool, odp_pool_t odp_pools[], int num)
Get the ODP pools used as subpools in a given EM event pool.
em_pool_t em_odp_pool2em(odp_pool_t odp_pool)
Get the EM event pool that the given ODP pool belongs to.
odp_event_t em_odp_event2odp(em_event_t event)
odp_timer_t em_odp_tmo2odp(em_tmo_t tmo)
Get the odp timer from EM timeout handle.
int em_odp_pktin_event_queues2em(const odp_queue_t odp_pktin_evqueues[], em_queue_t queues[], int num)
Map the given scheduled ODP pktin event queues to new EM queues.
em_queue_t em_odp_queue_em(odp_queue_t queue)
void em_odp_events2em(const odp_event_t odp_events[], em_event_t events[], int num)
odp_timer_pool_t em_odp_timer2odp(em_timer_t tmr)
Get the odp timer_pool from EM timer handle.
uint32_t em_odp_event_hdr_size(void)
void em_odp_events2odp(const em_event_t events[], odp_event_t odp_events[], int num)
odp_queue_t em_odp_queue_odp(em_queue_t queue)
em_event_t em_odp_event2em(odp_event_t odp_event)