Skip to content

Commit

Permalink
ethdev: add flow rule actions update API
Browse files Browse the repository at this point in the history
Introduce the new rte_flow_actions_update() API allowing users
to update the action list in the already existing rule.
Flow rules can be updated now without the need to destroy
the rule first and create a new one instead.
A single API call ensures that no packets are lost by
guaranteeing atomicity and flow state correctness.
The rte_flow_async_actions_update() is added as well.
The matcher is not updated, only the action list is.

Signed-off-by: Alexander Kozyrev <akozyrev@nvidia.com>
Acked-by: Ori Kam <orika@nvidia.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
  • Loading branch information
aleks-kozyrev authored and ovsrobot committed May 23, 2023
1 parent c41a103 commit fd2266c
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 0 deletions.
42 changes: 42 additions & 0 deletions doc/guides/prog_guide/rte_flow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3446,6 +3446,31 @@ Return values:

- 0 on success, a negative errno value otherwise and ``rte_errno`` is set.

Update
~~~~~~

Update an existing flow rule with a new set of actions.

.. code-block:: c
struct rte_flow *
rte_flow_actions_update(uint16_t port_id,
struct rte_flow *flow,
const struct rte_flow_action *actions[],
struct rte_flow_error *error);
Arguments:

- ``port_id``: port identifier of Ethernet device.
- ``flow``: flow rule handle to update.
- ``actions``: associated actions (list terminated by the END action).
- ``error``: perform verbose error reporting if not NULL. PMDs initialize
this structure in case of error only.

Return values:

- 0 on success, a negative errno value otherwise and ``rte_errno`` is set.

Flush
~~~~~

Expand Down Expand Up @@ -3795,6 +3820,23 @@ Enqueueing a flow rule destruction operation is similar to simple destruction.
void *user_data,
struct rte_flow_error *error);
Enqueue update operation
~~~~~~~~~~~~~~~~~~~~~~~~~~

Enqueueing a flow rule update operation to replace actions in the existing rule.

.. code-block:: c
int
rte_flow_async_actions_update(uint16_t port_id,
uint32_t queue_id,
const struct rte_flow_op_attr *op_attr,
struct rte_flow *flow,
const struct rte_flow_action actions[],
uint8_t actions_template_index,
void *user_data,
struct rte_flow_error *error);
Enqueue indirect action creation operation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
5 changes: 5 additions & 0 deletions doc/guides/rel_notes/release_23_07.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ New Features
Also, make sure to start the actual text at the margin.
=======================================================
* **Added flow rule update to the Flow API.**
* Added API for updating the action list in the already existing rule.
Introduced both rte_flow_actions_update() and
rte_flow_async_actions_update() functions.
Removed Items
-------------
Expand Down
29 changes: 29 additions & 0 deletions lib/ethdev/ethdev_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,17 @@ RTE_TRACE_POINT_FP(
rte_trace_point_emit_int(ret);
)

/* Called in loop in app/test-flow-perf */
RTE_TRACE_POINT_FP(
rte_flow_trace_actions_update,
RTE_TRACE_POINT_ARGS(uint16_t port_id, const struct rte_flow *flow,
const struct rte_flow_action *actions, int ret),
rte_trace_point_emit_u16(port_id);
rte_trace_point_emit_ptr(flow);
rte_trace_point_emit_ptr(actions);
rte_trace_point_emit_int(ret);
)

RTE_TRACE_POINT_FP(
rte_flow_trace_query,
RTE_TRACE_POINT_ARGS(uint16_t port_id, const struct rte_flow *flow,
Expand Down Expand Up @@ -2345,6 +2356,24 @@ RTE_TRACE_POINT_FP(
rte_trace_point_emit_ptr(flow);
)

RTE_TRACE_POINT_FP(
rte_flow_trace_async_actions_update,
RTE_TRACE_POINT_ARGS(uint16_t port_id, uint32_t queue_id,
const struct rte_flow_op_attr *op_attr,
const struct rte_flow *flow,
const struct rte_flow_action *actions,
uint8_t actions_template_index,
const void *user_data, int ret),
rte_trace_point_emit_u16(port_id);
rte_trace_point_emit_u32(queue_id);
rte_trace_point_emit_ptr(op_attr);
rte_trace_point_emit_ptr(flow);
rte_trace_point_emit_ptr(actions);
rte_trace_point_emit_u8(actions_template_index);
rte_trace_point_emit_ptr(user_data);
rte_trace_point_emit_int(ret);
)

RTE_TRACE_POINT_FP(
rte_flow_trace_pull,
RTE_TRACE_POINT_ARGS(uint16_t port_id, uint32_t queue_id,
Expand Down
6 changes: 6 additions & 0 deletions lib/ethdev/ethdev_trace_points.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ RTE_TRACE_POINT_REGISTER(rte_flow_trace_create,
RTE_TRACE_POINT_REGISTER(rte_flow_trace_destroy,
lib.ethdev.flow.destroy)

RTE_TRACE_POINT_REGISTER(rte_flow_trace_actions_update,
lib.ethdev.flow.update)

RTE_TRACE_POINT_REGISTER(rte_flow_trace_flush,
lib.ethdev.flow.flush)

Expand Down Expand Up @@ -580,6 +583,9 @@ RTE_TRACE_POINT_REGISTER(rte_flow_trace_async_create,
RTE_TRACE_POINT_REGISTER(rte_flow_trace_async_destroy,
lib.ethdev.flow.async_destroy)

RTE_TRACE_POINT_REGISTER(rte_flow_trace_async_actions_update,
lib.ethdev.flow.async_update)

RTE_TRACE_POINT_REGISTER(rte_flow_trace_push,
lib.ethdev.flow.push)

Expand Down
54 changes: 54 additions & 0 deletions lib/ethdev/rte_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,32 @@ rte_flow_destroy(uint16_t port_id,
NULL, rte_strerror(ENOSYS));
}

int
rte_flow_actions_update(uint16_t port_id,
struct rte_flow *flow,
const struct rte_flow_action actions[],
struct rte_flow_error *error)
{
struct rte_eth_dev *dev = &rte_eth_devices[port_id];
const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
int ret;

if (unlikely(!ops))
return -rte_errno;
if (likely(!!ops->actions_update)) {
fts_enter(dev);
ret = ops->actions_update(dev, flow, actions, error);
fts_exit(dev);

rte_flow_trace_actions_update(port_id, flow, actions, ret);

return flow_err(port_id, ret, error);
}
return rte_flow_error_set(error, ENOSYS,
RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
NULL, rte_strerror(ENOSYS));
}

/* Destroy all flow rules associated with a port. */
int
rte_flow_flush(uint16_t port_id,
Expand Down Expand Up @@ -1985,6 +2011,34 @@ rte_flow_async_destroy(uint16_t port_id,
return ret;
}

int
rte_flow_async_actions_update(uint16_t port_id,
uint32_t queue_id,
const struct rte_flow_op_attr *op_attr,
struct rte_flow *flow,
const struct rte_flow_action actions[],
uint8_t actions_template_index,
void *user_data,
struct rte_flow_error *error)
{
struct rte_eth_dev *dev = &rte_eth_devices[port_id];
const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
int ret;

ret = flow_err(port_id,
ops->async_actions_update(dev, queue_id, op_attr,
flow, actions,
actions_template_index,
user_data, error),
error);

rte_flow_trace_async_actions_update(port_id, queue_id, op_attr, flow,
actions, actions_template_index,
user_data, ret);

return ret;
}

int
rte_flow_push(uint16_t port_id,
uint32_t queue_id,
Expand Down
62 changes: 62 additions & 0 deletions lib/ethdev/rte_flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4343,6 +4343,29 @@ rte_flow_destroy(uint16_t port_id,
struct rte_flow *flow,
struct rte_flow_error *error);

/**
* Update a flow rule with new actions on a given port.
*
* @param port_id
* Port identifier of Ethernet device.
* @param flow
* Flow rule handle to update.
* @param[in] actions
* Associated actions (list terminated by the END action).
* @param[out] error
* Perform verbose error reporting if not NULL. PMDs initialize this
* structure in case of error only.
*
* @return
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
__rte_experimental
int
rte_flow_actions_update(uint16_t port_id,
struct rte_flow *flow,
const struct rte_flow_action actions[],
struct rte_flow_error *error);

/**
* Destroy all flow rules associated with a port.
*
Expand Down Expand Up @@ -5770,6 +5793,45 @@ rte_flow_async_destroy(uint16_t port_id,
void *user_data,
struct rte_flow_error *error);

/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice.
*
* Enqueue rule update operation.
*
* @param port_id
* Port identifier of Ethernet device.
* @param queue_id
* Flow queue used to insert the rule.
* @param[in] op_attr
* Rule creation operation attributes.
* @param[in] flow
* Flow rule to be updated.
* @param[in] actions
* List of actions to be used.
* The list order should match the order in the actions template.
* @param[in] actions_template_index
* Actions template index in the table.
* @param[in] user_data
* The user data that will be returned on the completion events.
* @param[out] error
* Perform verbose error reporting if not NULL.
* PMDs initialize this structure in case of error only.
*
* @return
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
__rte_experimental
int
rte_flow_async_actions_update(uint16_t port_id,
uint32_t queue_id,
const struct rte_flow_op_attr *op_attr,
struct rte_flow *flow,
const struct rte_flow_action actions[],
uint8_t actions_template_index,
void *user_data,
struct rte_flow_error *error);

/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice.
Expand Down
16 changes: 16 additions & 0 deletions lib/ethdev/rte_flow_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,22 @@ struct rte_flow_ops {
const void *update, void *query,
enum rte_flow_query_update_mode qu_mode,
void *user_data, struct rte_flow_error *error);
/** See rte_flow_actions_update(). */
int (*actions_update)
(struct rte_eth_dev *dev,
struct rte_flow *flow,
const struct rte_flow_action actions[],
struct rte_flow_error *error);
/** See rte_flow_async_actions_update() */
int (*async_actions_update)
(struct rte_eth_dev *dev,
uint32_t queue_id,
const struct rte_flow_op_attr *op_attr,
struct rte_flow *flow,
const struct rte_flow_action actions[],
uint8_t actions_template_index,
void *user_data,
struct rte_flow_error *error);
};

/**
Expand Down
4 changes: 4 additions & 0 deletions lib/ethdev/version.map
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ EXPERIMENTAL {
rte_flow_action_handle_query_update;
rte_flow_async_action_handle_query_update;
rte_flow_async_create_by_index;

# added in 23.07
rte_flow_actions_update;
rte_flow_async_actions_update;
};

INTERNAL {
Expand Down

0 comments on commit fd2266c

Please sign in to comment.