eventdev: add device stop flush callback

When an event device is stopped, it drains all event queues and ports.
These events may contain pointers, so to prevent memory leaks eventdev now
supports a user-provided flush callback that is called during the queue
drain process. This callback is stored in process memory, so the callback
must be registered by any process that may call rte_event_dev_stop().

This commit also clarifies the behavior of rte_event_dev_stop().

This follows this mailing list discussion:
http://dpdk.org/ml/archives/dev/2018-January/087484.html

Signed-off-by: Gage Eads <gage.eads@intel.com>
Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
This commit is contained in:
Gage Eads 2018-04-02 13:03:30 -05:00 committed by Thomas Monjalon
parent b770f952de
commit d593a8177f
10 changed files with 83 additions and 9 deletions

View File

@ -571,7 +571,7 @@ dpaa_event_eth_rx_adapter_stop(const struct rte_eventdev *dev,
return 0;
}
static const struct rte_eventdev_ops dpaa_eventdev_ops = {
static struct rte_eventdev_ops dpaa_eventdev_ops = {
.dev_infos_get = dpaa_event_dev_info_get,
.dev_configure = dpaa_event_dev_configure,
.dev_start = dpaa_event_dev_start,

View File

@ -696,7 +696,7 @@ dpaa2_eventdev_eth_stop(const struct rte_eventdev *dev,
return 0;
}
static const struct rte_eventdev_ops dpaa2_eventdev_ops = {
static struct rte_eventdev_ops dpaa2_eventdev_ops = {
.dev_infos_get = dpaa2_eventdev_info_get,
.dev_configure = dpaa2_eventdev_configure,
.dev_start = dpaa2_eventdev_start,

View File

@ -591,7 +591,7 @@ ssovf_selftest(const char *key __rte_unused, const char *value,
}
/* Initialize and register event driver with DPDK Application */
static const struct rte_eventdev_ops ssovf_ops = {
static struct rte_eventdev_ops ssovf_ops = {
.dev_infos_get = ssovf_info_get,
.dev_configure = ssovf_configure,
.queue_def_conf = ssovf_queue_def_conf,

View File

@ -607,7 +607,7 @@ set_do_test(const char *key __rte_unused, const char *value, void *opaque)
static int
opdl_probe(struct rte_vdev_device *vdev)
{
static const struct rte_eventdev_ops evdev_opdl_ops = {
static struct rte_eventdev_ops evdev_opdl_ops = {
.dev_configure = opdl_dev_configure,
.dev_infos_get = opdl_info_get,
.dev_close = opdl_close,

View File

@ -319,7 +319,7 @@ skeleton_eventdev_dump(struct rte_eventdev *dev, FILE *f)
/* Initialize and register event driver with DPDK Application */
static const struct rte_eventdev_ops skeleton_eventdev_ops = {
static struct rte_eventdev_ops skeleton_eventdev_ops = {
.dev_infos_get = skeleton_eventdev_info_get,
.dev_configure = skeleton_eventdev_configure,
.dev_start = skeleton_eventdev_start,

View File

@ -772,7 +772,7 @@ static int32_t sw_sched_service_func(void *args)
static int
sw_probe(struct rte_vdev_device *vdev)
{
static const struct rte_eventdev_ops evdev_sw_ops = {
static struct rte_eventdev_ops evdev_sw_ops = {
.dev_configure = sw_dev_configure,
.dev_infos_get = sw_info_get,
.dev_close = sw_close,

View File

@ -1123,6 +1123,23 @@ rte_event_dev_start(uint8_t dev_id)
return 0;
}
int
rte_event_dev_stop_flush_callback_register(uint8_t dev_id,
eventdev_stop_flush_t callback, void *userdata)
{
struct rte_eventdev *dev;
RTE_EDEV_LOG_DEBUG("Stop flush register dev_id=%" PRIu8, dev_id);
RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
dev = &rte_eventdevs[dev_id];
dev->dev_ops->dev_stop_flush = callback;
dev->data->dev_stop_flush_arg = userdata;
return 0;
}
void
rte_event_dev_stop(uint8_t dev_id)
{

View File

@ -244,6 +244,7 @@ extern "C" {
#include <rte_errno.h>
struct rte_mbuf; /* we just use mbuf pointers; no need to include rte_mbuf.h */
struct rte_event;
/* Event device capability bitmap flags */
#define RTE_EVENT_DEV_CAP_QUEUE_QOS (1ULL << 0)
@ -835,15 +836,60 @@ int
rte_event_dev_start(uint8_t dev_id);
/**
* Stop an event device. The device can be restarted with a call to
* rte_event_dev_start()
* Stop an event device.
*
* This function causes all queued events to be drained, including those
* residing in event ports. While draining events out of the device, this
* function calls the user-provided flush callback (if one was registered) once
* per event.
*
* The device can be restarted with a call to rte_event_dev_start(). Threads
* that continue to enqueue/dequeue while the device is stopped, or being
* stopped, will result in undefined behavior. This includes event adapters,
* which must be stopped prior to stopping the eventdev.
*
* @param dev_id
* Event device identifier.
*
* @see rte_event_dev_stop_flush_callback_register()
*/
void
rte_event_dev_stop(uint8_t dev_id);
typedef void (*eventdev_stop_flush_t)(uint8_t dev_id, struct rte_event event,
void *arg);
/**< Callback function called during rte_event_dev_stop(), invoked once per
* flushed event.
*/
/**
* Registers a callback function to be invoked during rte_event_dev_stop() for
* each flushed event. This function can be used to properly dispose of queued
* events, for example events containing memory pointers.
*
* The callback function is only registered for the calling process. The
* callback function must be registered in every process that can call
* rte_event_dev_stop().
*
* To unregister a callback, call this function with a NULL callback pointer.
*
* @param dev_id
* The identifier of the device.
* @param callback
* Callback function invoked once per flushed event.
* @param userdata
* Argument supplied to callback.
*
* @return
* - 0 on success.
* - -EINVAL if *dev_id* is invalid
*
* @see rte_event_dev_stop()
*/
int
rte_event_dev_stop_flush_callback_register(uint8_t dev_id,
eventdev_stop_flush_t callback, void *userdata);
/**
* Close an event device. The device cannot be restarted!
*
@ -1152,6 +1198,8 @@ struct rte_eventdev_data {
/* Service initialization state */
uint32_t service_id;
/* Service ID*/
void *dev_stop_flush_arg;
/**< User-provided argument for event flush function */
RTE_STD_C11
uint8_t dev_started : 1;
@ -1178,7 +1226,7 @@ struct rte_eventdev {
struct rte_eventdev_data *data;
/**< Pointer to device data */
const struct rte_eventdev_ops *dev_ops;
struct rte_eventdev_ops *dev_ops;
/**< Functions exported by PMD */
struct rte_device *dev;
/**< Device info. supplied by probing */

View File

@ -642,6 +642,9 @@ struct rte_eventdev_ops {
eventdev_selftest dev_selftest;
/**< Start eventdev Selftest */
eventdev_stop_flush_t dev_stop_flush;
/**< User-provided event flush function */
};
/**

View File

@ -74,3 +74,9 @@ DPDK_18.02 {
rte_event_dev_selftest;
} DPDK_17.11;
DPDK_18.05 {
global:
rte_event_dev_stop_flush_callback_register;
} DPDK_18.02;