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