4 * Copyright 2016 Cavium.
5 * Copyright 2016 Intel Corporation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Cavium nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifndef _RTE_EVENTDEV_H_
36 #define _RTE_EVENTDEV_H_
41 * RTE Event Device API
43 * In a polling model, lcores poll ethdev ports and associated rx queues
44 * directly to look for packet. In an event driven model, by contrast, lcores
45 * call the scheduler that selects packets for them based on programmer
46 * specified criteria. Eventdev library adds support for event driven
47 * programming model, which offer applications automatic multicore scaling,
48 * dynamic load balancing, pipelining, packet ingress order maintenance and
49 * synchronization services to simplify application packet processing.
51 * The Event Device API is composed of two parts:
53 * - The application-oriented Event API that includes functions to setup
54 * an event device (configure it, setup its queues, ports and start it), to
55 * establish the link between queues to port and to receive events, and so on.
57 * - The driver-oriented Event API that exports a function allowing
58 * an event poll Mode Driver (PMD) to simultaneously register itself as
59 * an event device driver.
61 * Event device components:
65 * +-------+ | | flow 0 | |
66 * |Packet | | +-------------+ |
67 * |event | | +-------------+ |
68 * | | | | flow 1 | |port_link(port0, queue0)
69 * +-------+ | +-------------+ | | +--------+
70 * +-------+ | +-------------+ o-----v-----o |dequeue +------+
71 * |Crypto | | | flow n | | | event +------->|Core 0|
72 * |work | | +-------------+ o----+ | port 0 | | |
73 * |done ev| | event queue 0 | | +--------+ +------+
74 * +-------+ +-----------------+ |
76 * |Timer | +-----------------+ | +--------+
77 * |expiry | | +-------------+ | +------o |dequeue +------+
78 * |event | | | flow 0 | o-----------o event +------->|Core 1|
79 * +-------+ | +-------------+ | +----o port 1 | | |
80 * Event enqueue | +-------------+ | | +--------+ +------+
81 * o-------------> | | flow 1 | | |
82 * enqueue( | +-------------+ | |
83 * queue_id, | | | +--------+ +------+
84 * flow_id, | +-------------+ | | | |dequeue |Core 2|
85 * sched_type, | | flow n | o-----------o event +------->| |
86 * event_type, | +-------------+ | | | port 2 | +------+
87 * subev_type, | event queue 1 | | +--------+
88 * event) +-----------------+ | +--------+
89 * | | |dequeue +------+
90 * +-------+ +-----------------+ | | event +------->|Core n|
91 * |Core | | +-------------+ o-----------o port n | | |
92 * |(SW) | | | flow 0 | | | +--------+ +--+---+
93 * |event | | +-------------+ | | |
94 * +-------+ | +-------------+ | | |
95 * ^ | | flow 1 | | | |
96 * | | +-------------+ o------+ |
97 * | | +-------------+ | |
99 * | | +-------------+ | |
100 * | | event queue n | |
101 * | +-----------------+ |
103 * +-----------------------------------------------------------+
105 * Event device: A hardware or software-based event scheduler.
107 * Event: A unit of scheduling that encapsulates a packet or other datatype
108 * like SW generated event from the CPU, Crypto work completion notification,
109 * Timer expiry event notification etc as well as metadata.
110 * The metadata includes flow ID, scheduling type, event priority, event_type,
111 * sub_event_type etc.
113 * Event queue: A queue containing events that are scheduled by the event dev.
114 * An event queue contains events of different flows associated with scheduling
115 * types, such as atomic, ordered, or parallel.
117 * Event port: An application's interface into the event dev for enqueue and
118 * dequeue operations. Each event port can be linked with one or more
119 * event queues for dequeue operations.
121 * By default, all the functions of the Event Device API exported by a PMD
122 * are lock-free functions which assume to not be invoked in parallel on
123 * different logical cores to work on the same target object. For instance,
124 * the dequeue function of a PMD cannot be invoked in parallel on two logical
125 * cores to operates on same event port. Of course, this function
126 * can be invoked in parallel by different logical cores on different ports.
127 * It is the responsibility of the upper level application to enforce this rule.
129 * In all functions of the Event API, the Event device is
130 * designated by an integer >= 0 named the device identifier *dev_id*
132 * At the Event driver level, Event devices are represented by a generic
133 * data structure of type *rte_event_dev*.
135 * Event devices are dynamically registered during the PCI/SoC device probing
136 * phase performed at EAL initialization time.
137 * When an Event device is being probed, a *rte_event_dev* structure and
138 * a new device identifier are allocated for that device. Then, the
139 * event_dev_init() function supplied by the Event driver matching the probed
140 * device is invoked to properly initialize the device.
142 * The role of the device init function consists of resetting the hardware or
143 * software event driver implementations.
145 * If the device init operation is successful, the correspondence between
146 * the device identifier assigned to the new device and its associated
147 * *rte_event_dev* structure is effectively registered.
148 * Otherwise, both the *rte_event_dev* structure and the device identifier are
151 * The functions exported by the application Event API to setup a device
152 * designated by its device identifier must be invoked in the following order:
153 * - rte_event_dev_configure()
154 * - rte_event_queue_setup()
155 * - rte_event_port_setup()
156 * - rte_event_port_link()
157 * - rte_event_dev_start()
159 * Then, the application can invoke, in any order, the functions
160 * exported by the Event API to schedule events, dequeue events, enqueue events,
161 * change event queue(s) to event port [un]link establishment and so on.
163 * Application may use rte_event_[queue/port]_default_conf_get() to get the
164 * default configuration to set up an event queue or event port by
165 * overriding few default values.
167 * If the application wants to change the configuration (i.e. call
168 * rte_event_dev_configure(), rte_event_queue_setup(), or
169 * rte_event_port_setup()), it must call rte_event_dev_stop() first to stop the
170 * device and then do the reconfiguration before calling rte_event_dev_start()
171 * again. The schedule, enqueue and dequeue functions should not be invoked
172 * when the device is stopped.
174 * Finally, an application can close an Event device by invoking the
175 * rte_event_dev_close() function.
177 * Each function of the application Event API invokes a specific function
178 * of the PMD that controls the target device designated by its device
181 * For this purpose, all device-specific functions of an Event driver are
182 * supplied through a set of pointers contained in a generic structure of type
184 * The address of the *event_dev_ops* structure is stored in the *rte_event_dev*
185 * structure by the device init function of the Event driver, which is
186 * invoked during the PCI/SoC device probing phase, as explained earlier.
188 * In other words, each function of the Event API simply retrieves the
189 * *rte_event_dev* structure associated with the device identifier and
190 * performs an indirect invocation of the corresponding driver function
191 * supplied in the *event_dev_ops* structure of the *rte_event_dev* structure.
193 * For performance reasons, the address of the fast-path functions of the
194 * Event driver is not contained in the *event_dev_ops* structure.
195 * Instead, they are directly stored at the beginning of the *rte_event_dev*
196 * structure to avoid an extra indirect memory access during their invocation.
198 * RTE event device drivers do not use interrupts for enqueue or dequeue
199 * operation. Instead, Event drivers export Poll-Mode enqueue and dequeue
200 * functions to applications.
202 * An event driven based application has following typical workflow on fastpath:
206 * rte_event_schedule(dev_id);
208 * rte_event_dequeue(...);
212 * rte_event_enqueue(...);
216 * The events are injected to event device through *enqueue* operation by
217 * event producers in the system. The typical event producers are ethdev
218 * subsystem for generating packet events, CPU(SW) for generating events based
219 * on different stages of application processing, cryptodev for generating
220 * crypto work completion notification etc
222 * The *dequeue* operation gets one or more events from the event ports.
223 * The application process the events and send to downstream event queue through
224 * rte_event_enqueue_burst() if it is an intermediate stage of event processing,
225 * on the final stage, the application may send to different subsystem like
226 * ethdev to send the packet/event on the wire using ethdev
227 * rte_eth_tx_burst() API.
229 * The point at which events are scheduled to ports depends on the device.
230 * For hardware devices, scheduling occurs asynchronously without any software
231 * intervention. Software schedulers can either be distributed
232 * (each worker thread schedules events to its own port) or centralized
233 * (a dedicated thread schedules to all ports). Distributed software schedulers
234 * perform the scheduling in rte_event_dequeue_burst(), whereas centralized
235 * scheduler logic is located in rte_event_schedule().
236 * The RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED capability flag is not set
237 * indicates the device is centralized and thus needs a dedicated scheduling
238 * thread that repeatedly calls rte_event_schedule().
246 #include <rte_common.h>
247 #include <rte_memory.h>
249 struct rte_mbuf; /* we just use mbuf pointers; no need to include rte_mbuf.h */
251 /* Event device capability bitmap flags */
252 #define RTE_EVENT_DEV_CAP_QUEUE_QOS (1ULL << 0)
253 /**< Event scheduling prioritization is based on the priority associated with
256 * @see rte_event_queue_setup()
258 #define RTE_EVENT_DEV_CAP_EVENT_QOS (1ULL << 1)
259 /**< Event scheduling prioritization is based on the priority associated with
260 * each event. Priority of each event is supplied in *rte_event* structure
261 * on each enqueue operation.
263 * @see rte_event_enqueue_burst()
265 #define RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED (1ULL << 2)
266 /**< Event device operates in distributed scheduling mode.
267 * In distributed scheduling mode, event scheduling happens in HW or
268 * rte_event_dequeue_burst() or the combination of these two.
269 * If the flag is not set then eventdev is centralized and thus needs a
270 * dedicated scheduling thread that repeatedly calls rte_event_schedule().
272 * @see rte_event_schedule(), rte_event_dequeue_burst()
275 /* Event device priority levels */
276 #define RTE_EVENT_DEV_PRIORITY_HIGHEST 0
277 /**< Highest priority expressed across eventdev subsystem
278 * @see rte_event_queue_setup(), rte_event_enqueue_burst()
279 * @see rte_event_port_link()
281 #define RTE_EVENT_DEV_PRIORITY_NORMAL 128
282 /**< Normal priority expressed across eventdev subsystem
283 * @see rte_event_queue_setup(), rte_event_enqueue_burst()
284 * @see rte_event_port_link()
286 #define RTE_EVENT_DEV_PRIORITY_LOWEST 255
287 /**< Lowest priority expressed across eventdev subsystem
288 * @see rte_event_queue_setup(), rte_event_enqueue_burst()
289 * @see rte_event_port_link()
293 * Get the total number of event devices that have been successfully
297 * The total number of usable event devices.
300 rte_event_dev_count(void);
303 * Get the device identifier for the named event device.
306 * Event device name to select the event device identifier.
309 * Returns event device identifier on success.
310 * - <0: Failure to find named event device.
313 rte_event_dev_get_dev_id(const char *name);
316 * Return the NUMA socket to which a device is connected.
319 * The identifier of the device.
321 * The NUMA socket id to which the device is connected or
322 * a default of zero if the socket could not be determined.
323 * -(-EINVAL) dev_id value is out of range.
326 rte_event_dev_socket_id(uint8_t dev_id);
329 * Event device information
331 struct rte_event_dev_info {
332 const char *driver_name; /**< Event driver name */
333 struct rte_pci_device *pci_dev; /**< PCI information */
334 uint32_t min_dequeue_timeout_ns;
335 /**< Minimum supported global dequeue timeout(ns) by this device */
336 uint32_t max_dequeue_timeout_ns;
337 /**< Maximum supported global dequeue timeout(ns) by this device */
338 uint32_t dequeue_timeout_ns;
339 /**< Configured global dequeue timeout(ns) for this device */
340 uint8_t max_event_queues;
341 /**< Maximum event_queues supported by this device */
342 uint32_t max_event_queue_flows;
343 /**< Maximum supported flows in an event queue by this device*/
344 uint8_t max_event_queue_priority_levels;
345 /**< Maximum number of event queue priority levels by this device.
346 * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
348 uint8_t max_event_priority_levels;
349 /**< Maximum number of event priority levels by this device.
350 * Valid when the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability
352 uint8_t max_event_ports;
353 /**< Maximum number of event ports supported by this device */
354 uint8_t max_event_port_dequeue_depth;
355 /**< Maximum number of events can be dequeued at a time from an
356 * event port by this device.
357 * A device that does not support bulk dequeue will set this as 1.
359 uint32_t max_event_port_enqueue_depth;
360 /**< Maximum number of events can be enqueued at a time from an
361 * event port by this device.
362 * A device that does not support bulk enqueue will set this as 1.
364 int32_t max_num_events;
365 /**< A *closed system* event dev has a limit on the number of events it
366 * can manage at a time. An *open system* event dev does not have a
367 * limit and will specify this as -1.
369 uint32_t event_dev_cap;
370 /**< Event device capabilities(RTE_EVENT_DEV_CAP_)*/
374 * Retrieve the contextual information of an event device.
377 * The identifier of the device.
379 * @param[out] dev_info
380 * A pointer to a structure of type *rte_event_dev_info* to be filled with the
381 * contextual information of the device.
384 * - 0: Success, driver updates the contextual information of the event device
385 * - <0: Error code returned by the driver info get function.
389 rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info);
391 /* Event device configuration bitmap flags */
392 #define RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT (1ULL << 0)
393 /**< Override the global *dequeue_timeout_ns* and use per dequeue timeout in ns.
394 * @see rte_event_dequeue_timeout_ticks(), rte_event_dequeue_burst()
397 /** Event device configuration structure */
398 struct rte_event_dev_config {
399 uint32_t dequeue_timeout_ns;
400 /**< rte_event_dequeue_burst() timeout on this device.
401 * This value should be in the range of *min_dequeue_timeout_ns* and
402 * *max_dequeue_timeout_ns* which previously provided in
403 * rte_event_dev_info_get()
404 * @see RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
406 int32_t nb_events_limit;
407 /**< Applies to *closed system* event dev only. This field indicates a
408 * limit to ethdev-like devices to limit the number of events injected
409 * into the system to not overwhelm core-to-core events.
410 * This value cannot exceed the *max_num_events* which previously
411 * provided in rte_event_dev_info_get()
413 uint8_t nb_event_queues;
414 /**< Number of event queues to configure on this device.
415 * This value cannot exceed the *max_event_queues* which previously
416 * provided in rte_event_dev_info_get()
418 uint8_t nb_event_ports;
419 /**< Number of event ports to configure on this device.
420 * This value cannot exceed the *max_event_ports* which previously
421 * provided in rte_event_dev_info_get()
423 uint32_t nb_event_queue_flows;
424 /**< Number of flows for any event queue on this device.
425 * This value cannot exceed the *max_event_queue_flows* which previously
426 * provided in rte_event_dev_info_get()
428 uint8_t nb_event_port_dequeue_depth;
429 /**< Maximum number of events can be dequeued at a time from an
430 * event port by this device.
431 * This value cannot exceed the *max_event_port_dequeue_depth*
432 * which previously provided in rte_event_dev_info_get()
433 * @see rte_event_port_setup()
435 uint32_t nb_event_port_enqueue_depth;
436 /**< Maximum number of events can be enqueued at a time from an
437 * event port by this device.
438 * This value cannot exceed the *max_event_port_enqueue_depth*
439 * which previously provided in rte_event_dev_info_get()
440 * @see rte_event_port_setup()
442 uint32_t event_dev_cfg;
443 /**< Event device config flags(RTE_EVENT_DEV_CFG_)*/
447 * Configure an event device.
449 * This function must be invoked first before any other function in the
450 * API. This function can also be re-invoked when a device is in the
453 * The caller may use rte_event_dev_info_get() to get the capability of each
454 * resources available for this event device.
457 * The identifier of the device to configure.
459 * The event device configuration structure.
462 * - 0: Success, device configured.
463 * - <0: Error code returned by the driver configuration function.
466 rte_event_dev_configure(uint8_t dev_id,
467 const struct rte_event_dev_config *dev_conf);
470 /* Event queue specific APIs */
472 /* Event queue configuration bitmap flags */
473 #define RTE_EVENT_QUEUE_CFG_DEFAULT (0)
474 /**< Default value of *event_queue_cfg* when rte_event_queue_setup() invoked
475 * with queue_conf == NULL
477 * @see rte_event_queue_setup()
479 #define RTE_EVENT_QUEUE_CFG_TYPE_MASK (3ULL << 0)
480 /**< Mask for event queue schedule type configuration request */
481 #define RTE_EVENT_QUEUE_CFG_ALL_TYPES (0ULL << 0)
482 /**< Allow ATOMIC,ORDERED,PARALLEL schedule type enqueue
484 * @see RTE_SCHED_TYPE_ORDERED, RTE_SCHED_TYPE_ATOMIC, RTE_SCHED_TYPE_PARALLEL
485 * @see rte_event_enqueue_burst()
487 #define RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY (1ULL << 0)
488 /**< Allow only ATOMIC schedule type enqueue
490 * The rte_event_enqueue_burst() result is undefined if the queue configured
491 * with ATOMIC only and sched_type != RTE_SCHED_TYPE_ATOMIC
493 * @see RTE_SCHED_TYPE_ATOMIC, rte_event_enqueue_burst()
495 #define RTE_EVENT_QUEUE_CFG_ORDERED_ONLY (2ULL << 0)
496 /**< Allow only ORDERED schedule type enqueue
498 * The rte_event_enqueue_burst() result is undefined if the queue configured
499 * with ORDERED only and sched_type != RTE_SCHED_TYPE_ORDERED
501 * @see RTE_SCHED_TYPE_ORDERED, rte_event_enqueue_burst()
503 #define RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY (3ULL << 0)
504 /**< Allow only PARALLEL schedule type enqueue
506 * The rte_event_enqueue_burst() result is undefined if the queue configured
507 * with PARALLEL only and sched_type != RTE_SCHED_TYPE_PARALLEL
509 * @see RTE_SCHED_TYPE_PARALLEL, rte_event_enqueue_burst()
511 #define RTE_EVENT_QUEUE_CFG_SINGLE_LINK (1ULL << 2)
512 /**< This event queue links only to a single event port.
514 * @see rte_event_port_setup(), rte_event_port_link()
517 /** Event queue configuration structure */
518 struct rte_event_queue_conf {
519 uint32_t nb_atomic_flows;
520 /**< The maximum number of active flows this queue can track at any
521 * given time. The value must be in the range of
522 * [1 - nb_event_queue_flows)] which previously provided in
523 * rte_event_dev_info_get().
525 uint32_t nb_atomic_order_sequences;
526 /**< The maximum number of outstanding events waiting to be
527 * reordered by this queue. In other words, the number of entries in
528 * this queue’s reorder buffer.When the number of events in the
529 * reorder buffer reaches to *nb_atomic_order_sequences* then the
530 * scheduler cannot schedule the events from this queue and invalid
531 * event will be returned from dequeue until one or more entries are
533 * The value must be in the range of [1 - nb_event_queue_flows)]
534 * which previously supplied to rte_event_dev_configure().
536 uint32_t event_queue_cfg; /**< Queue cfg flags(EVENT_QUEUE_CFG_) */
538 /**< Priority for this event queue relative to other event queues.
539 * The requested priority should in the range of
540 * [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
541 * The implementation shall normalize the requested priority to
542 * event device supported priority value.
543 * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
548 * Retrieve the default configuration information of an event queue designated
549 * by its *queue_id* from the event driver for an event device.
551 * This function intended to be used in conjunction with rte_event_queue_setup()
552 * where caller needs to set up the queue by overriding few default values.
555 * The identifier of the device.
557 * The index of the event queue to get the configuration information.
558 * The value must be in the range [0, nb_event_queues - 1]
559 * previously supplied to rte_event_dev_configure().
560 * @param[out] queue_conf
561 * The pointer to the default event queue configuration data.
563 * - 0: Success, driver updates the default event queue configuration data.
564 * - <0: Error code returned by the driver info get function.
566 * @see rte_event_queue_setup()
570 rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
571 struct rte_event_queue_conf *queue_conf);
574 * Allocate and set up an event queue for an event device.
577 * The identifier of the device.
579 * The index of the event queue to setup. The value must be in the range
580 * [0, nb_event_queues - 1] previously supplied to rte_event_dev_configure().
582 * The pointer to the configuration data to be used for the event queue.
583 * NULL value is allowed, in which case default configuration used.
585 * @see rte_event_queue_default_conf_get()
588 * - 0: Success, event queue correctly set up.
589 * - <0: event queue configuration failed
592 rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
593 const struct rte_event_queue_conf *queue_conf);
596 * Get the number of event queues on a specific event device
599 * Event device identifier.
601 * - The number of configured event queues
604 rte_event_queue_count(uint8_t dev_id);
607 * Get the priority of the event queue on a specific event device
610 * Event device identifier.
612 * Event queue identifier.
614 * - If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then the
615 * configured priority of the event queue in
616 * [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST] range
617 * else the value RTE_EVENT_DEV_PRIORITY_NORMAL
620 rte_event_queue_priority(uint8_t dev_id, uint8_t queue_id);
622 /* Event port specific APIs */
624 /** Event port configuration structure */
625 struct rte_event_port_conf {
626 int32_t new_event_threshold;
627 /**< A backpressure threshold for new event enqueues on this port.
628 * Use for *closed system* event dev where event capacity is limited,
629 * and cannot exceed the capacity of the event dev.
630 * Configuring ports with different thresholds can make higher priority
631 * traffic less likely to be backpressured.
632 * For example, a port used to inject NIC Rx packets into the event dev
633 * can have a lower threshold so as not to overwhelm the device,
634 * while ports used for worker pools can have a higher threshold.
635 * This value cannot exceed the *nb_events_limit*
636 * which previously supplied to rte_event_dev_configure()
638 uint8_t dequeue_depth;
639 /**< Configure number of bulk dequeues for this event port.
640 * This value cannot exceed the *nb_event_port_dequeue_depth*
641 * which previously supplied to rte_event_dev_configure()
643 uint8_t enqueue_depth;
644 /**< Configure number of bulk enqueues for this event port.
645 * This value cannot exceed the *nb_event_port_enqueue_depth*
646 * which previously supplied to rte_event_dev_configure()
651 * Retrieve the default configuration information of an event port designated
652 * by its *port_id* from the event driver for an event device.
654 * This function intended to be used in conjunction with rte_event_port_setup()
655 * where caller needs to set up the port by overriding few default values.
658 * The identifier of the device.
660 * The index of the event port to get the configuration information.
661 * The value must be in the range [0, nb_event_ports - 1]
662 * previously supplied to rte_event_dev_configure().
663 * @param[out] port_conf
664 * The pointer to the default event port configuration data
666 * - 0: Success, driver updates the default event port configuration data.
667 * - <0: Error code returned by the driver info get function.
669 * @see rte_event_port_setup()
673 rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
674 struct rte_event_port_conf *port_conf);
677 * Allocate and set up an event port for an event device.
680 * The identifier of the device.
682 * The index of the event port to setup. The value must be in the range
683 * [0, nb_event_ports - 1] previously supplied to rte_event_dev_configure().
685 * The pointer to the configuration data to be used for the queue.
686 * NULL value is allowed, in which case default configuration used.
688 * @see rte_event_port_default_conf_get()
691 * - 0: Success, event port correctly set up.
692 * - <0: Port configuration failed
693 * - (-EDQUOT) Quota exceeded(Application tried to link the queue configured
694 * with RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
697 rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
698 const struct rte_event_port_conf *port_conf);
701 * Get the number of dequeue queue depth configured for event port designated
702 * by its *port_id* on a specific event device
705 * Event device identifier.
707 * Event port identifier.
709 * - The number of configured dequeue queue depth
711 * @see rte_event_dequeue_burst()
714 rte_event_port_dequeue_depth(uint8_t dev_id, uint8_t port_id);
717 * Get the number of enqueue queue depth configured for event port designated
718 * by its *port_id* on a specific event device
721 * Event device identifier.
723 * Event port identifier.
725 * - The number of configured enqueue queue depth
727 * @see rte_event_enqueue_burst()
730 rte_event_port_enqueue_depth(uint8_t dev_id, uint8_t port_id);
733 * Get the number of ports on a specific event device
736 * Event device identifier.
738 * - The number of configured ports
741 rte_event_port_count(uint8_t dev_id);
744 * Start an event device.
746 * The device start step is the last one and consists of setting the event
747 * queues to start accepting the events and schedules to event ports.
749 * On success, all basic functions exported by the API (event enqueue,
750 * event dequeue and so on) can be invoked.
753 * Event device identifier
755 * - 0: Success, device started.
756 * - <0: Error code of the driver device start function.
759 rte_event_dev_start(uint8_t dev_id);
762 * Stop an event device. The device can be restarted with a call to
763 * rte_event_dev_start()
766 * Event device identifier.
769 rte_event_dev_stop(uint8_t dev_id);
772 * Close an event device. The device cannot be restarted!
775 * Event device identifier
778 * - 0 on successfully closing device
779 * - <0 on failure to close device
780 * - (-EAGAIN) if device is busy
783 rte_event_dev_close(uint8_t dev_id);
785 /* Scheduler type definitions */
786 #define RTE_SCHED_TYPE_ORDERED 0
787 /**< Ordered scheduling
789 * Events from an ordered flow of an event queue can be scheduled to multiple
790 * ports for concurrent processing while maintaining the original event order.
791 * This scheme enables the user to achieve high single flow throughput by
792 * avoiding SW synchronization for ordering between ports which bound to cores.
794 * The source flow ordering from an event queue is maintained when events are
795 * enqueued to their destination queue within the same ordered flow context.
796 * An event port holds the context until application call
797 * rte_event_dequeue_burst() from the same port, which implicitly releases
799 * User may allow the scheduler to release the context earlier than that
800 * by invoking rte_event_enqueue_burst() with RTE_EVENT_OP_RELEASE operation.
802 * Events from the source queue appear in their original order when dequeued
803 * from a destination queue.
804 * Event ordering is based on the received event(s), but also other
805 * (newly allocated or stored) events are ordered when enqueued within the same
806 * ordered context. Events not enqueued (e.g. released or stored) within the
807 * context are considered missing from reordering and are skipped at this time
808 * (but can be ordered again within another context).
810 * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
813 #define RTE_SCHED_TYPE_ATOMIC 1
814 /**< Atomic scheduling
816 * Events from an atomic flow of an event queue can be scheduled only to a
817 * single port at a time. The port is guaranteed to have exclusive (atomic)
818 * access to the associated flow context, which enables the user to avoid SW
819 * synchronization. Atomic flows also help to maintain event ordering
820 * since only one port at a time can process events from a flow of an
823 * The atomic queue synchronization context is dedicated to the port until
824 * application call rte_event_dequeue_burst() from the same port,
825 * which implicitly releases the context. User may allow the scheduler to
826 * release the context earlier than that by invoking rte_event_enqueue_burst()
827 * with RTE_EVENT_OP_RELEASE operation.
829 * @see rte_event_queue_setup(), rte_event_dequeue_burst(), RTE_EVENT_OP_RELEASE
832 #define RTE_SCHED_TYPE_PARALLEL 2
833 /**< Parallel scheduling
835 * The scheduler performs priority scheduling, load balancing, etc. functions
836 * but does not provide additional event synchronization or ordering.
837 * It is free to schedule events from a single parallel flow of an event queue
838 * to multiple events ports for concurrent processing.
839 * The application is responsible for flow context synchronization and
840 * event ordering (SW synchronization).
842 * @see rte_event_queue_setup(), rte_event_dequeue_burst()
845 /* Event types to classify the event source */
846 #define RTE_EVENT_TYPE_ETHDEV 0x0
847 /**< The event generated from ethdev subsystem */
848 #define RTE_EVENT_TYPE_CRYPTODEV 0x1
849 /**< The event generated from crypodev subsystem */
850 #define RTE_EVENT_TYPE_TIMERDEV 0x2
851 /**< The event generated from timerdev subsystem */
852 #define RTE_EVENT_TYPE_CPU 0x3
853 /**< The event generated from cpu for pipelining.
854 * Application may use *sub_event_type* to further classify the event
856 #define RTE_EVENT_TYPE_MAX 0x10
857 /**< Maximum number of event types */
859 /* Event enqueue operations */
860 #define RTE_EVENT_OP_NEW 0
861 /**< The event producers use this operation to inject a new event to the
864 #define RTE_EVENT_OP_FORWARD 1
865 /**< The CPU use this operation to forward the event to different event queue or
866 * change to new application specific flow or schedule type to enable
869 #define RTE_EVENT_OP_RELEASE 2
870 /**< Release the flow context associated with the schedule type.
872 * If current flow's scheduler type method is *RTE_SCHED_TYPE_ATOMIC*
873 * then this function hints the scheduler that the user has completed critical
874 * section processing in the current atomic context.
875 * The scheduler is now allowed to schedule events from the same flow from
876 * an event queue to another port. However, the context may be still held
877 * until the next rte_event_dequeue_burst() call, this call allows but does not
878 * force the scheduler to release the context early.
880 * Early atomic context release may increase parallelism and thus system
881 * performance, but the user needs to design carefully the split into critical
882 * vs non-critical sections.
884 * If current flow's scheduler type method is *RTE_SCHED_TYPE_ORDERED*
885 * then this function hints the scheduler that the user has done all that need
886 * to maintain event order in the current ordered context.
887 * The scheduler is allowed to release the ordered context of this port and
888 * avoid reordering any following enqueues.
890 * Early ordered context release may increase parallelism and thus system
893 * If current flow's scheduler type method is *RTE_SCHED_TYPE_PARALLEL*
894 * or no scheduling context is held then this function may be an NOOP,
895 * depending on the implementation.
900 * The generic *rte_event* structure to hold the event attributes
901 * for dequeue and enqueue operation
908 /** Event attributes for dequeue or enqueue operation */
911 /**< Targeted flow identifier for the enqueue and
913 * The value must be in the range of
914 * [0, nb_event_queue_flows - 1] which
915 * previously supplied to rte_event_dev_configure().
917 uint32_t sub_event_type:8;
918 /**< Sub-event types based on the event source.
919 * @see RTE_EVENT_TYPE_CPU
921 uint32_t event_type:4;
922 /**< Event type to classify the event source.
923 * @see RTE_EVENT_TYPE_ETHDEV, (RTE_EVENT_TYPE_*)
926 /**< The type of event enqueue operation - new/forward/
927 * etc.This field is not preserved across an instance
928 * and is undefined on dequeue.
929 * @see RTE_EVENT_OP_NEW, (RTE_EVENT_OP_*)
932 /**< Reserved for future use */
933 uint8_t sched_type:2;
934 /**< Scheduler synchronization type (RTE_SCHED_TYPE_*)
935 * associated with flow id on a given event queue
936 * for the enqueue and dequeue operation.
939 /**< Targeted event queue identifier for the enqueue or
941 * The value must be in the range of
942 * [0, nb_event_queues - 1] which previously supplied to
943 * rte_event_dev_configure().
946 /**< Event priority relative to other events in the
947 * event queue. The requested priority should in the
948 * range of [RTE_EVENT_DEV_PRIORITY_HIGHEST,
949 * RTE_EVENT_DEV_PRIORITY_LOWEST].
950 * The implementation shall normalize the requested
951 * priority to supported priority value.
952 * Valid when the device has
953 * RTE_EVENT_DEV_CAP_EVENT_QOS capability.
956 /**< Implementation specific opaque value.
957 * An implementation may use this field to hold
958 * implementation specific value to share between
959 * dequeue and enqueue operation.
960 * The application should not modify this field.
968 /**< Opaque 64-bit value */
970 /**< Opaque event pointer */
971 struct rte_mbuf *mbuf;
972 /**< mbuf pointer if dequeued event is associated with mbuf */
977 struct rte_eventdev_driver;
978 struct rte_eventdev_ops;
981 typedef void (*event_schedule_t)(struct rte_eventdev *dev);
982 /**< @internal Schedule one or more events in the event dev. */
984 typedef uint16_t (*event_enqueue_t)(void *port, const struct rte_event *ev);
985 /**< @internal Enqueue event on port of a device */
987 typedef uint16_t (*event_enqueue_burst_t)(void *port,
988 const struct rte_event ev[], uint16_t nb_events);
989 /**< @internal Enqueue burst of events on port of a device */
991 typedef uint16_t (*event_dequeue_t)(void *port, struct rte_event *ev,
992 uint64_t timeout_ticks);
993 /**< @internal Dequeue event from port of a device */
995 typedef uint16_t (*event_dequeue_burst_t)(void *port, struct rte_event ev[],
996 uint16_t nb_events, uint64_t timeout_ticks);
997 /**< @internal Dequeue burst of events from port of a device */
999 #define RTE_EVENTDEV_NAME_MAX_LEN (64)
1000 /**< @internal Max length of name of event PMD */
1004 * The data part, with no function pointers, associated with each device.
1006 * This structure is safe to place in shared memory to be common among
1007 * different processes in a multi-process configuration.
1009 struct rte_eventdev_data {
1011 /**< Socket ID where memory is allocated */
1013 /**< Device ID for this instance */
1015 /**< Number of event queues. */
1017 /**< Number of event ports. */
1019 /**< Array of pointers to ports. */
1020 uint8_t *ports_dequeue_depth;
1021 /**< Array of port dequeue depth. */
1022 uint8_t *ports_enqueue_depth;
1023 /**< Array of port enqueue depth. */
1024 uint8_t *queues_prio;
1025 /**< Array of queue priority. */
1026 uint16_t *links_map;
1027 /**< Memory to store queues to port connections. */
1029 /**< PMD-specific private data */
1030 uint32_t event_dev_cap;
1031 /**< Event device capabilities(RTE_EVENT_DEV_CAP_)*/
1032 struct rte_event_dev_config dev_conf;
1033 /**< Configuration applied to device. */
1036 uint8_t dev_started : 1;
1037 /**< Device state: STARTED(1)/STOPPED(0) */
1039 char name[RTE_EVENTDEV_NAME_MAX_LEN];
1040 /**< Unique identifier name */
1041 } __rte_cache_aligned;
1043 /** @internal The data structure associated with each event device. */
1044 struct rte_eventdev {
1045 event_schedule_t schedule;
1046 /**< Pointer to PMD schedule function. */
1047 event_enqueue_t enqueue;
1048 /**< Pointer to PMD enqueue function. */
1049 event_enqueue_burst_t enqueue_burst;
1050 /**< Pointer to PMD enqueue burst function. */
1051 event_dequeue_t dequeue;
1052 /**< Pointer to PMD dequeue function. */
1053 event_dequeue_burst_t dequeue_burst;
1054 /**< Pointer to PMD dequeue burst function. */
1056 struct rte_eventdev_data *data;
1057 /**< Pointer to device data */
1058 const struct rte_eventdev_ops *dev_ops;
1059 /**< Functions exported by PMD */
1060 struct rte_pci_device *pci_dev;
1061 /**< PCI info. supplied by probing */
1062 const struct rte_eventdev_driver *driver;
1063 /**< Driver for this device */
1066 uint8_t attached : 1;
1067 /**< Flag indicating the device is attached */
1068 } __rte_cache_aligned;
1070 extern struct rte_eventdev *rte_eventdevs;
1071 /** @internal The pool of rte_eventdev structures. */
1075 * Schedule one or more events in the event dev.
1077 * An event dev implementation may define this is a NOOP, for instance if
1078 * the event dev performs its scheduling in hardware.
1081 * The identifier of the device.
1084 rte_event_schedule(uint8_t dev_id)
1086 struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1088 (*dev->schedule)(dev);
1092 * Enqueue a burst of events objects or an event object supplied in *rte_event*
1093 * structure on an event device designated by its *dev_id* through the event
1094 * port specified by *port_id*. Each event object specifies the event queue on
1095 * which it will be enqueued.
1097 * The *nb_events* parameter is the number of event objects to enqueue which are
1098 * supplied in the *ev* array of *rte_event* structure.
1100 * The rte_event_enqueue_burst() function returns the number of
1101 * events objects it actually enqueued. A return value equal to *nb_events*
1102 * means that all event objects have been enqueued.
1105 * The identifier of the device.
1107 * The identifier of the event port.
1109 * Points to an array of *nb_events* objects of type *rte_event* structure
1110 * which contain the event object enqueue operations to be processed.
1112 * The number of event objects to enqueue, typically number of
1113 * rte_event_port_enqueue_depth() available for this port.
1116 * The number of event objects actually enqueued on the event device. The
1117 * return value can be less than the value of the *nb_events* parameter when
1118 * the event devices queue is full or if invalid parameters are specified in a
1119 * *rte_event*. If return value is less than *nb_events*, the remaining events
1120 * at the end of ev[] are not consumed,and the caller has to take care of them
1122 * @see rte_event_port_enqueue_depth()
1124 static inline uint16_t
1125 rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
1126 const struct rte_event ev[], uint16_t nb_events)
1128 struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1131 * Allow zero cost non burst mode routine invocation if application
1132 * requests nb_events as const one
1135 return (*dev->enqueue)(
1136 dev->data->ports[port_id], ev);
1138 return (*dev->enqueue_burst)(
1139 dev->data->ports[port_id], ev, nb_events);
1143 * Converts nanoseconds to *timeout_ticks* value for rte_event_dequeue_burst()
1145 * If the device is configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT flag
1146 * then application can use this function to convert timeout value in
1147 * nanoseconds to implementations specific timeout value supplied in
1148 * rte_event_dequeue_burst()
1151 * The identifier of the device.
1153 * Wait time in nanosecond
1154 * @param[out] timeout_ticks
1155 * Value for the *timeout_ticks* parameter in rte_event_dequeue_burst()
1161 * @see rte_event_dequeue_burst(), RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1162 * @see rte_event_dev_configure()
1166 rte_event_dequeue_timeout_ticks(uint8_t dev_id, uint64_t ns,
1167 uint64_t *timeout_ticks);
1170 * Dequeue a burst of events objects or an event object from the event port
1171 * designated by its *event_port_id*, on an event device designated
1174 * rte_event_dequeue_burst() does not dictate the specifics of scheduling
1175 * algorithm as each eventdev driver may have different criteria to schedule
1176 * an event. However, in general, from an application perspective scheduler may
1177 * use the following scheme to dispatch an event to the port.
1179 * 1) Selection of event queue based on
1180 * a) The list of event queues are linked to the event port.
1181 * b) If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then event
1182 * queue selection from list is based on event queue priority relative to
1183 * other event queue supplied as *priority* in rte_event_queue_setup()
1184 * c) If the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability then event
1185 * queue selection from the list is based on event priority supplied as
1186 * *priority* in rte_event_enqueue_burst()
1187 * 2) Selection of event
1188 * a) The number of flows available in selected event queue.
1189 * b) Schedule type method associated with the event
1191 * The *nb_events* parameter is the maximum number of event objects to dequeue
1192 * which are returned in the *ev* array of *rte_event* structure.
1194 * The rte_event_dequeue_burst() function returns the number of events objects
1195 * it actually dequeued. A return value equal to *nb_events* means that all
1196 * event objects have been dequeued.
1198 * The number of events dequeued is the number of scheduler contexts held by
1199 * this port. These contexts are automatically released in the next
1200 * rte_event_dequeue_burst() invocation, or invoking rte_event_enqueue_burst()
1201 * with RTE_EVENT_OP_RELEASE operation can be used to release the
1205 * The identifier of the device.
1207 * The identifier of the event port.
1209 * Points to an array of *nb_events* objects of type *rte_event* structure
1210 * for output to be populated with the dequeued event objects.
1212 * The maximum number of event objects to dequeue, typically number of
1213 * rte_event_port_dequeue_depth() available for this port.
1215 * @param timeout_ticks
1216 * - 0 no-wait, returns immediately if there is no event.
1217 * - >0 wait for the event, if the device is configured with
1218 * RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT then this function will wait until
1219 * the event available or *timeout_ticks* time.
1220 * if the device is not configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT
1221 * then this function will wait until the event available or
1222 * *dequeue_timeout_ns* ns which was previously supplied to
1223 * rte_event_dev_configure()
1226 * The number of event objects actually dequeued from the port. The return
1227 * value can be less than the value of the *nb_events* parameter when the
1228 * event port's queue is not full.
1230 * @see rte_event_port_dequeue_depth()
1232 static inline uint16_t
1233 rte_event_dequeue_burst(uint8_t dev_id, uint8_t port_id, struct rte_event ev[],
1234 uint16_t nb_events, uint64_t timeout_ticks)
1236 struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1239 * Allow zero cost non burst mode routine invocation if application
1240 * requests nb_events as const one
1243 return (*dev->dequeue)(
1244 dev->data->ports[port_id], ev, timeout_ticks);
1246 return (*dev->dequeue_burst)(
1247 dev->data->ports[port_id], ev, nb_events,
1252 * Link multiple source event queues supplied in *queues* to the destination
1253 * event port designated by its *port_id* with associated service priority
1254 * supplied in *priorities* on the event device designated by its *dev_id*.
1256 * The link establishment shall enable the event port *port_id* from
1257 * receiving events from the specified event queue(s) supplied in *queues*
1259 * An event queue may link to one or more event ports.
1260 * The number of links can be established from an event queue to event port is
1261 * implementation defined.
1263 * Event queue(s) to event port link establishment can be changed at runtime
1264 * without re-configuring the device to support scaling and to reduce the
1265 * latency of critical work by establishing the link with more event ports
1269 * The identifier of the device.
1272 * Event port identifier to select the destination port to link.
1275 * Points to an array of *nb_links* event queues to be linked
1276 * to the event port.
1277 * NULL value is allowed, in which case this function links all the configured
1278 * event queues *nb_event_queues* which previously supplied to
1279 * rte_event_dev_configure() to the event port *port_id*
1282 * Points to an array of *nb_links* service priorities associated with each
1283 * event queue link to event port.
1284 * The priority defines the event port's servicing priority for
1285 * event queue, which may be ignored by an implementation.
1286 * The requested priority should in the range of
1287 * [RTE_EVENT_DEV_PRIORITY_HIGHEST, RTE_EVENT_DEV_PRIORITY_LOWEST].
1288 * The implementation shall normalize the requested priority to
1289 * implementation supported priority value.
1290 * NULL value is allowed, in which case this function links the event queues
1291 * with RTE_EVENT_DEV_PRIORITY_NORMAL servicing priority
1294 * The number of links to establish
1297 * The number of links actually established. The return value can be less than
1298 * the value of the *nb_links* parameter when the implementation has the
1299 * limitation on specific queue to port link establishment or if invalid
1300 * parameters are specified in *queues*
1301 * If the return value is less than *nb_links*, the remaining links at the end
1302 * of link[] are not established, and the caller has to take care of them.
1303 * If return value is less than *nb_links* then implementation shall update the
1304 * rte_errno accordingly, Possible rte_errno values are
1305 * (-EDQUOT) Quota exceeded(Application tried to link the queue configured with
1306 * RTE_EVENT_QUEUE_CFG_SINGLE_LINK to more than one event ports)
1307 * (-EINVAL) Invalid parameter
1311 rte_event_port_link(uint8_t dev_id, uint8_t port_id,
1312 const uint8_t queues[], const uint8_t priorities[],
1316 * Unlink multiple source event queues supplied in *queues* from the destination
1317 * event port designated by its *port_id* on the event device designated
1320 * The unlink establishment shall disable the event port *port_id* from
1321 * receiving events from the specified event queue *queue_id*
1323 * Event queue(s) to event port unlink establishment can be changed at runtime
1324 * without re-configuring the device.
1327 * The identifier of the device.
1330 * Event port identifier to select the destination port to unlink.
1333 * Points to an array of *nb_unlinks* event queues to be unlinked
1334 * from the event port.
1335 * NULL value is allowed, in which case this function unlinks all the
1336 * event queue(s) from the event port *port_id*.
1339 * The number of unlinks to establish
1342 * The number of unlinks actually established. The return value can be less
1343 * than the value of the *nb_unlinks* parameter when the implementation has the
1344 * limitation on specific queue to port unlink establishment or
1345 * if invalid parameters are specified.
1346 * If the return value is less than *nb_unlinks*, the remaining queues at the
1347 * end of queues[] are not established, and the caller has to take care of them.
1348 * If return value is less than *nb_unlinks* then implementation shall update
1349 * the rte_errno accordingly, Possible rte_errno values are
1350 * (-EINVAL) Invalid parameter
1354 rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
1355 uint8_t queues[], uint16_t nb_unlinks);
1358 * Retrieve the list of source event queues and its associated service priority
1359 * linked to the destination event port designated by its *port_id*
1360 * on the event device designated by its *dev_id*.
1363 * The identifier of the device.
1366 * Event port identifier.
1368 * @param[out] queues
1369 * Points to an array of *queues* for output.
1370 * The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1371 * store the event queue(s) linked with event port *port_id*
1373 * @param[out] priorities
1374 * Points to an array of *priorities* for output.
1375 * The caller has to allocate *RTE_EVENT_MAX_QUEUES_PER_DEV* bytes to
1376 * store the service priority associated with each event queue linked
1379 * The number of links established on the event port designated by its
1385 rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
1386 uint8_t queues[], uint8_t priorities[]);
1389 * Dump internal information about *dev_id* to the FILE* provided in *f*.
1392 * The identifier of the device.
1395 * A pointer to a file for output
1402 rte_event_dev_dump(uint8_t dev_id, FILE *f);
1408 #endif /* _RTE_EVENTDEV_H_ */