[PATCH v7 5/7] ring/soring: introduce Staged Ordered Ring
Morten Brørup
mb at smartsharesystems.com
Thu Nov 7 13:07:54 CET 2024
> From: Konstantin Ananyev [mailto:konstantin.ananyev at huawei.com]
> Sent: Wednesday, 30 October 2024 22.23
> +.. code-block:: c
> +
> + /*
> + * use pointer to mbuf as soring element, while tx_state
> + * as a metadata.
> + * In this example we use a soring with just one stage.
> + */
> + union tx_state {
> + /* negative values for error */
> + int32_t rc;
> + /* otherwise contain valid TX port and queue IDs*/
> + struct {
> + uint16_t port_id;
> + uint16_t queue_id;
> + } tx;
One space too much in indentation before "} tx;".
> + };
> + struct rte_soring *soring;
> +
> +
> +producer/consumer part:
> +
> +.. code-block:: c
> +
> + struct rte_mbuf *pkts[MAX_PKT_BURST];
> + union tx_state txst[MAX_PKT_BURST];
> + ...
> + /* enqueue - writes to soring objects array no need to update
> metadata */
> + uint32_t num = MAX_PKT_BURST;
> + num = rte_soring_enqueue_burst(soring, pkts, num, NULL);
> + ....
> + /* dequeux - reads both packets and related tx_state */
> + uint32_t num = MAX_PKT_BURST;
> + num = rte_soring_dequeux_burst(soring, pkts, txst, num, NULL);
> +
> + /*
> + * TX packets out, or drop in case of error.
> + * Note that we don't need to dereference the soring objects
> itself
> + * to make a decision.
> + */
> + uint32_t i, j, k, n;
> + struct rte_mbuf *dr[MAX_PKT_BURST];
> +
> + k = 0;
> + for (i = 0; i != num; i++) {
> + /* packet processing reports an error */
> + if (txst[i].rc < 0)
> + dr[k++] = pkts[i];
> + /* valid packet, send it out */
> + else {
> + /* group consequitive packets with the same port and
> queue IDs */
> + for (j = i + 1; j < num; j++)
> + if (txst[j].rc != txst[i].rc)
> + break;
> +
> + n = rte_eth_tx_burst(txst[i].tx.port_id,
> txst[i].tx.queue_id,
> + pkts + i, j - i);
> + if (i + n != j) {
> + /* decide with unsent packets if any */
Indentation is off in the next few lines.
> + }
> + }
> + }
> + /* drop errorneous packets */
> + if (k != 0)
> + rte_pktmbuf_free_bulk(dr, k);
> +++ b/lib/ring/rte_soring.c
> @@ -0,0 +1,198 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2024 Huawei Technologies Co., Ltd
> + */
> +
> +#include <inttypes.h>
> +
> +#include "soring.h"
> +#include <rte_string_fns.h>
> +
> +RTE_LOG_REGISTER_DEFAULT(soring_logtype, INFO);
> +
> +static uint32_t
> +soring_calc_elem_num(uint32_t count)
> +{
> + return rte_align32pow2(count + 1);
> +}
> +
> +static int
> +soring_check_param(uint32_t esize, uint32_t stsize, uint32_t count,
stsize -> msize or meta_size
Throughout the code, where stsize is used.
> + uint32_t stages)
> +{
> + if (stages == 0) {
> + SORING_LOG(ERR, "invalid number of stages: %u", stages);
> + return -EINVAL;
> + }
> +
> + /* Check if element size is a multiple of 4B */
> + if (esize == 0 || esize % 4 != 0) {
> + SORING_LOG(ERR, "invalid element size: %u", esize);
> + return -EINVAL;
> + }
> +
> + /* Check if ret-code size is a multiple of 4B */
ret-code -> meta
> + if (stsize % 4 != 0) {
> + SORING_LOG(ERR, "invalid retcode size: %u", stsize);
retcode -> meta
> + return -EINVAL;
> + }
> +
> + /* count must be a power of 2 */
> + if (rte_is_power_of_2(count) == 0 ||
> + (count > RTE_SORING_ELEM_MAX + 1)) {
> + SORING_LOG(ERR, "invalid number of elements: %u", count);
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
For the next version with above fixes,
Acked-by: Morten Brørup <mb at smartsharesystems.com>
More information about the dev
mailing list