numam-dpdk/drivers/net/softnic/rte_eth_softnic_swq.c
William Tu f1f6ebc0ea eal: remove sys/queue.h from public headers
Currently there are some public headers that include 'sys/queue.h', which
is not POSIX, but usually provided by the Linux/BSD system library.
(Not in POSIX.1, POSIX.1-2001, or POSIX.1-2008. Present on the BSDs.)
The file is missing on Windows. During the Windows build, DPDK uses a
bundled copy, so building a DPDK library works fine.  But when OVS or other
applications use DPDK as a library, because some DPDK public headers
include 'sys/queue.h', on Windows, it triggers an error due to no such
file.

One solution is to install the 'lib/eal/windows/include/sys/queue.h' into
Windows environment, such as [1]. However, this means DPDK exports the
functionalities of 'sys/queue.h' into the environment, which might cause
symbols, macros, headers clashing with other applications.

The patch fixes it by removing the "#include <sys/queue.h>" from
DPDK public headers, so programs including DPDK headers don't depend
on the system to provide 'sys/queue.h'. When these public headers use
macros such as TAILQ_xxx, we replace it by the ones with RTE_ prefix.
For Windows, we copy the definitions from <sys/queue.h> to rte_os.h
in Windows EAL. Note that these RTE_ macros are compatible with
<sys/queue.h>, both at the level of API (to use with <sys/queue.h>
macros in C files) and ABI (to avoid breaking it).

Additionally, the TAILQ_FOREACH_SAFE is not part of <sys/queue.h>,
the patch replaces it with RTE_TAILQ_FOREACH_SAFE.

[1] http://mails.dpdk.org/archives/dev/2021-August/216304.html

Suggested-by: Nick Connolly <nick.connolly@mayadata.io>
Suggested-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Signed-off-by: William Tu <u9012063@gmail.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Narcisa Vasile <navasile@linux.microsoft.com>
2021-10-01 13:09:43 +02:00

115 lines
2.0 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2010-2018 Intel Corporation
*/
#include <stdlib.h>
#include <string.h>
#include <rte_string_fns.h>
#include <rte_tailq.h>
#include "rte_eth_softnic_internals.h"
int
softnic_swq_init(struct pmd_internals *p)
{
TAILQ_INIT(&p->swq_list);
return 0;
}
void
softnic_swq_free(struct pmd_internals *p)
{
for ( ; ; ) {
struct softnic_swq *swq;
swq = TAILQ_FIRST(&p->swq_list);
if (swq == NULL)
break;
TAILQ_REMOVE(&p->swq_list, swq, node);
rte_ring_free(swq->r);
free(swq);
}
}
void
softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p)
{
struct softnic_swq *swq, *tswq;
RTE_TAILQ_FOREACH_SAFE(swq, &p->swq_list, node, tswq) {
if ((strncmp(swq->name, "RXQ", strlen("RXQ")) == 0) ||
(strncmp(swq->name, "TXQ", strlen("TXQ")) == 0))
continue;
TAILQ_REMOVE(&p->swq_list, swq, node);
rte_ring_free(swq->r);
free(swq);
}
}
struct softnic_swq *
softnic_swq_find(struct pmd_internals *p,
const char *name)
{
struct softnic_swq *swq;
if (name == NULL)
return NULL;
TAILQ_FOREACH(swq, &p->swq_list, node)
if (strcmp(swq->name, name) == 0)
return swq;
return NULL;
}
struct softnic_swq *
softnic_swq_create(struct pmd_internals *p,
const char *name,
struct softnic_swq_params *params)
{
char ring_name[NAME_SIZE];
struct softnic_swq *swq;
struct rte_ring *r;
unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ;
/* Check input params */
if (name == NULL ||
softnic_swq_find(p, name) ||
params == NULL ||
params->size == 0)
return NULL;
/* Resource create */
snprintf(ring_name, sizeof(ring_name), "%s_%s",
p->params.name,
name);
r = rte_ring_create(ring_name,
params->size,
p->params.cpu_id,
flags);
if (r == NULL)
return NULL;
/* Node allocation */
swq = calloc(1, sizeof(struct softnic_swq));
if (swq == NULL) {
rte_ring_free(r);
return NULL;
}
/* Node fill in */
strlcpy(swq->name, name, sizeof(swq->name));
swq->r = r;
/* Node add to list */
TAILQ_INSERT_TAIL(&p->swq_list, swq, node);
return swq;
}