2017-12-19 15:49:03 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright(c) 2010-2014 Intel Corporation
|
2014-05-29 10:12:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <rte_mbuf.h>
|
2014-11-07 17:28:09 +00:00
|
|
|
#include <rte_memory.h>
|
2014-05-29 10:12:14 +00:00
|
|
|
#include <rte_memzone.h>
|
|
|
|
#include <rte_errno.h>
|
2017-03-20 10:08:32 +00:00
|
|
|
#include <rte_compat.h>
|
2014-05-29 10:12:14 +00:00
|
|
|
#include <rte_string_fns.h>
|
|
|
|
#include <rte_eal_memconfig.h>
|
2017-06-05 08:58:43 +00:00
|
|
|
#include <rte_pause.h>
|
|
|
|
|
2017-03-20 10:08:25 +00:00
|
|
|
#include "rte_distributor_v20.h"
|
2017-03-20 10:08:26 +00:00
|
|
|
#include "rte_distributor_private.h"
|
2014-05-29 10:12:14 +00:00
|
|
|
|
2017-03-20 10:08:30 +00:00
|
|
|
TAILQ_HEAD(rte_distributor_list, rte_distributor_v20);
|
2014-05-29 10:12:14 +00:00
|
|
|
|
2015-03-04 21:50:08 +00:00
|
|
|
static struct rte_tailq_elem rte_distributor_tailq = {
|
|
|
|
.name = "RTE_DISTRIBUTOR",
|
|
|
|
};
|
|
|
|
EAL_REGISTER_TAILQ(rte_distributor_tailq)
|
|
|
|
|
2014-05-29 10:12:14 +00:00
|
|
|
/**** APIs called by workers ****/
|
|
|
|
|
2014-06-19 21:12:35 +00:00
|
|
|
void
|
2017-03-20 10:08:30 +00:00
|
|
|
rte_distributor_request_pkt_v20(struct rte_distributor_v20 *d,
|
2014-05-29 10:12:14 +00:00
|
|
|
unsigned worker_id, struct rte_mbuf *oldpkt)
|
|
|
|
{
|
2017-03-20 10:08:30 +00:00
|
|
|
union rte_distributor_buffer_v20 *buf = &d->bufs[worker_id];
|
2014-05-29 10:12:14 +00:00
|
|
|
int64_t req = (((int64_t)(uintptr_t)oldpkt) << RTE_DISTRIB_FLAG_BITS)
|
|
|
|
| RTE_DISTRIB_GET_BUF;
|
|
|
|
while (unlikely(buf->bufptr64 & RTE_DISTRIB_FLAGS_MASK))
|
|
|
|
rte_pause();
|
|
|
|
buf->bufptr64 = req;
|
2014-06-19 21:12:35 +00:00
|
|
|
}
|
2017-03-20 10:08:32 +00:00
|
|
|
VERSION_SYMBOL(rte_distributor_request_pkt, _v20, 2.0);
|
2014-06-19 21:12:35 +00:00
|
|
|
|
|
|
|
struct rte_mbuf *
|
2017-03-20 10:08:30 +00:00
|
|
|
rte_distributor_poll_pkt_v20(struct rte_distributor_v20 *d,
|
2014-06-19 21:12:35 +00:00
|
|
|
unsigned worker_id)
|
|
|
|
{
|
2017-03-20 10:08:30 +00:00
|
|
|
union rte_distributor_buffer_v20 *buf = &d->bufs[worker_id];
|
2014-06-19 21:12:35 +00:00
|
|
|
if (buf->bufptr64 & RTE_DISTRIB_GET_BUF)
|
|
|
|
return NULL;
|
|
|
|
|
2014-05-29 10:12:14 +00:00
|
|
|
/* since bufptr64 is signed, this should be an arithmetic shift */
|
|
|
|
int64_t ret = buf->bufptr64 >> RTE_DISTRIB_FLAG_BITS;
|
|
|
|
return (struct rte_mbuf *)((uintptr_t)ret);
|
|
|
|
}
|
2017-03-20 10:08:32 +00:00
|
|
|
VERSION_SYMBOL(rte_distributor_poll_pkt, _v20, 2.0);
|
2014-05-29 10:12:14 +00:00
|
|
|
|
2014-06-19 21:12:35 +00:00
|
|
|
struct rte_mbuf *
|
2017-03-20 10:08:30 +00:00
|
|
|
rte_distributor_get_pkt_v20(struct rte_distributor_v20 *d,
|
2014-06-19 21:12:35 +00:00
|
|
|
unsigned worker_id, struct rte_mbuf *oldpkt)
|
|
|
|
{
|
|
|
|
struct rte_mbuf *ret;
|
2017-03-20 10:08:30 +00:00
|
|
|
rte_distributor_request_pkt_v20(d, worker_id, oldpkt);
|
|
|
|
while ((ret = rte_distributor_poll_pkt_v20(d, worker_id)) == NULL)
|
2014-06-19 21:12:35 +00:00
|
|
|
rte_pause();
|
|
|
|
return ret;
|
|
|
|
}
|
2017-03-20 10:08:32 +00:00
|
|
|
VERSION_SYMBOL(rte_distributor_get_pkt, _v20, 2.0);
|
2014-06-19 21:12:35 +00:00
|
|
|
|
2014-05-29 10:12:14 +00:00
|
|
|
int
|
2017-03-20 10:08:30 +00:00
|
|
|
rte_distributor_return_pkt_v20(struct rte_distributor_v20 *d,
|
2014-05-29 10:12:14 +00:00
|
|
|
unsigned worker_id, struct rte_mbuf *oldpkt)
|
|
|
|
{
|
2017-03-20 10:08:30 +00:00
|
|
|
union rte_distributor_buffer_v20 *buf = &d->bufs[worker_id];
|
2014-05-29 10:12:14 +00:00
|
|
|
uint64_t req = (((int64_t)(uintptr_t)oldpkt) << RTE_DISTRIB_FLAG_BITS)
|
|
|
|
| RTE_DISTRIB_RETURN_BUF;
|
|
|
|
buf->bufptr64 = req;
|
|
|
|
return 0;
|
|
|
|
}
|
2017-03-20 10:08:32 +00:00
|
|
|
VERSION_SYMBOL(rte_distributor_return_pkt, _v20, 2.0);
|
2014-05-29 10:12:14 +00:00
|
|
|
|
|
|
|
/**** APIs called on distributor core ***/
|
|
|
|
|
|
|
|
/* as name suggests, adds a packet to the backlog for a particular worker */
|
|
|
|
static int
|
|
|
|
add_to_backlog(struct rte_distributor_backlog *bl, int64_t item)
|
|
|
|
{
|
|
|
|
if (bl->count == RTE_DISTRIB_BACKLOG_SIZE)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
bl->pkts[(bl->start + bl->count++) & (RTE_DISTRIB_BACKLOG_MASK)]
|
|
|
|
= item;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* takes the next packet for a worker off the backlog */
|
|
|
|
static int64_t
|
|
|
|
backlog_pop(struct rte_distributor_backlog *bl)
|
|
|
|
{
|
|
|
|
bl->count--;
|
|
|
|
return bl->pkts[bl->start++ & RTE_DISTRIB_BACKLOG_MASK];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stores a packet returned from a worker inside the returns array */
|
|
|
|
static inline void
|
2017-03-20 10:08:30 +00:00
|
|
|
store_return(uintptr_t oldbuf, struct rte_distributor_v20 *d,
|
2014-05-29 10:12:14 +00:00
|
|
|
unsigned *ret_start, unsigned *ret_count)
|
|
|
|
{
|
|
|
|
/* store returns in a circular buffer - code is branch-free */
|
|
|
|
d->returns.mbufs[(*ret_start + *ret_count) & RTE_DISTRIB_RETURNS_MASK]
|
|
|
|
= (void *)oldbuf;
|
|
|
|
*ret_start += (*ret_count == RTE_DISTRIB_RETURNS_MASK) & !!(oldbuf);
|
|
|
|
*ret_count += (*ret_count != RTE_DISTRIB_RETURNS_MASK) & !!(oldbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2017-03-20 10:08:30 +00:00
|
|
|
handle_worker_shutdown(struct rte_distributor_v20 *d, unsigned int wkr)
|
2014-05-29 10:12:14 +00:00
|
|
|
{
|
|
|
|
d->in_flight_tags[wkr] = 0;
|
2014-11-10 14:44:02 +00:00
|
|
|
d->in_flight_bitmask &= ~(1UL << wkr);
|
2014-05-29 10:12:14 +00:00
|
|
|
d->bufs[wkr].bufptr64 = 0;
|
|
|
|
if (unlikely(d->backlog[wkr].count != 0)) {
|
|
|
|
/* On return of a packet, we need to move the
|
|
|
|
* queued packets for this core elsewhere.
|
|
|
|
* Easiest solution is to set things up for
|
|
|
|
* a recursive call. That will cause those
|
|
|
|
* packets to be queued up for the next free
|
|
|
|
* core, i.e. it will return as soon as a
|
|
|
|
* core becomes free to accept the first
|
|
|
|
* packet, as subsequent ones will be added to
|
|
|
|
* the backlog for that core.
|
|
|
|
*/
|
|
|
|
struct rte_mbuf *pkts[RTE_DISTRIB_BACKLOG_SIZE];
|
|
|
|
unsigned i;
|
|
|
|
struct rte_distributor_backlog *bl = &d->backlog[wkr];
|
|
|
|
|
|
|
|
for (i = 0; i < bl->count; i++) {
|
|
|
|
unsigned idx = (bl->start + i) &
|
|
|
|
RTE_DISTRIB_BACKLOG_MASK;
|
|
|
|
pkts[i] = (void *)((uintptr_t)(bl->pkts[idx] >>
|
|
|
|
RTE_DISTRIB_FLAG_BITS));
|
|
|
|
}
|
2014-11-10 14:44:02 +00:00
|
|
|
/* recursive call.
|
|
|
|
* Note that the tags were set before first level call
|
|
|
|
* to rte_distributor_process.
|
|
|
|
*/
|
2017-03-20 10:08:30 +00:00
|
|
|
rte_distributor_process_v20(d, pkts, i);
|
2014-05-29 10:12:14 +00:00
|
|
|
bl->count = bl->start = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this function is called when process() fn is called without any new
|
|
|
|
* packets. It goes through all the workers and clears any returned packets
|
|
|
|
* to do a partial flush.
|
|
|
|
*/
|
|
|
|
static int
|
2017-03-20 10:08:30 +00:00
|
|
|
process_returns(struct rte_distributor_v20 *d)
|
2014-05-29 10:12:14 +00:00
|
|
|
{
|
|
|
|
unsigned wkr;
|
|
|
|
unsigned flushed = 0;
|
|
|
|
unsigned ret_start = d->returns.start,
|
|
|
|
ret_count = d->returns.count;
|
|
|
|
|
|
|
|
for (wkr = 0; wkr < d->num_workers; wkr++) {
|
|
|
|
|
|
|
|
const int64_t data = d->bufs[wkr].bufptr64;
|
|
|
|
uintptr_t oldbuf = 0;
|
|
|
|
|
|
|
|
if (data & RTE_DISTRIB_GET_BUF) {
|
|
|
|
flushed++;
|
|
|
|
if (d->backlog[wkr].count)
|
|
|
|
d->bufs[wkr].bufptr64 =
|
|
|
|
backlog_pop(&d->backlog[wkr]);
|
|
|
|
else {
|
|
|
|
d->bufs[wkr].bufptr64 = RTE_DISTRIB_GET_BUF;
|
|
|
|
d->in_flight_tags[wkr] = 0;
|
2014-11-10 14:44:02 +00:00
|
|
|
d->in_flight_bitmask &= ~(1UL << wkr);
|
2014-05-29 10:12:14 +00:00
|
|
|
}
|
|
|
|
oldbuf = data >> RTE_DISTRIB_FLAG_BITS;
|
|
|
|
} else if (data & RTE_DISTRIB_RETURN_BUF) {
|
|
|
|
handle_worker_shutdown(d, wkr);
|
|
|
|
oldbuf = data >> RTE_DISTRIB_FLAG_BITS;
|
|
|
|
}
|
|
|
|
|
|
|
|
store_return(oldbuf, d, &ret_start, &ret_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->returns.start = ret_start;
|
|
|
|
d->returns.count = ret_count;
|
|
|
|
|
|
|
|
return flushed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process a set of packets to distribute them to workers */
|
|
|
|
int
|
2017-03-20 10:08:30 +00:00
|
|
|
rte_distributor_process_v20(struct rte_distributor_v20 *d,
|
2014-05-29 10:12:14 +00:00
|
|
|
struct rte_mbuf **mbufs, unsigned num_mbufs)
|
|
|
|
{
|
|
|
|
unsigned next_idx = 0;
|
|
|
|
unsigned wkr = 0;
|
|
|
|
struct rte_mbuf *next_mb = NULL;
|
|
|
|
int64_t next_value = 0;
|
|
|
|
uint32_t new_tag = 0;
|
|
|
|
unsigned ret_start = d->returns.start,
|
|
|
|
ret_count = d->returns.count;
|
|
|
|
|
|
|
|
if (unlikely(num_mbufs == 0))
|
|
|
|
return process_returns(d);
|
|
|
|
|
|
|
|
while (next_idx < num_mbufs || next_mb != NULL) {
|
|
|
|
|
|
|
|
int64_t data = d->bufs[wkr].bufptr64;
|
|
|
|
uintptr_t oldbuf = 0;
|
|
|
|
|
|
|
|
if (!next_mb) {
|
|
|
|
next_mb = mbufs[next_idx++];
|
|
|
|
next_value = (((int64_t)(uintptr_t)next_mb)
|
|
|
|
<< RTE_DISTRIB_FLAG_BITS);
|
2014-11-06 13:55:32 +00:00
|
|
|
/*
|
2017-10-30 07:03:01 +00:00
|
|
|
* User is advocated to set tag value for each
|
2014-11-10 14:44:02 +00:00
|
|
|
* mbuf before calling rte_distributor_process.
|
|
|
|
* User defined tags are used to identify flows,
|
|
|
|
* or sessions.
|
2014-11-06 13:55:32 +00:00
|
|
|
*/
|
2014-11-10 14:44:02 +00:00
|
|
|
new_tag = next_mb->hash.usr;
|
2014-05-29 10:12:14 +00:00
|
|
|
|
2014-11-10 14:44:02 +00:00
|
|
|
/*
|
|
|
|
* Note that if RTE_DISTRIB_MAX_WORKERS is larger than 64
|
|
|
|
* then the size of match has to be expanded.
|
|
|
|
*/
|
|
|
|
uint64_t match = 0;
|
2014-05-29 10:12:14 +00:00
|
|
|
unsigned i;
|
2014-11-06 13:55:32 +00:00
|
|
|
/*
|
|
|
|
* to scan for a match use "xor" and "not" to get a 0/1
|
|
|
|
* value, then use shifting to merge to single "match"
|
|
|
|
* variable, where a one-bit indicates a match for the
|
|
|
|
* worker given by the bit-position
|
|
|
|
*/
|
2014-05-29 10:12:14 +00:00
|
|
|
for (i = 0; i < d->num_workers; i++)
|
|
|
|
match |= (!(d->in_flight_tags[i] ^ new_tag)
|
|
|
|
<< i);
|
|
|
|
|
2014-11-10 14:44:02 +00:00
|
|
|
/* Only turned-on bits are considered as match */
|
|
|
|
match &= d->in_flight_bitmask;
|
|
|
|
|
2014-05-29 10:12:14 +00:00
|
|
|
if (match) {
|
|
|
|
next_mb = NULL;
|
2014-11-10 14:44:02 +00:00
|
|
|
unsigned worker = __builtin_ctzl(match);
|
2014-05-29 10:12:14 +00:00
|
|
|
if (add_to_backlog(&d->backlog[worker],
|
|
|
|
next_value) < 0)
|
|
|
|
next_idx--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((data & RTE_DISTRIB_GET_BUF) &&
|
|
|
|
(d->backlog[wkr].count || next_mb)) {
|
|
|
|
|
|
|
|
if (d->backlog[wkr].count)
|
|
|
|
d->bufs[wkr].bufptr64 =
|
|
|
|
backlog_pop(&d->backlog[wkr]);
|
|
|
|
|
|
|
|
else {
|
|
|
|
d->bufs[wkr].bufptr64 = next_value;
|
|
|
|
d->in_flight_tags[wkr] = new_tag;
|
2014-11-10 14:44:02 +00:00
|
|
|
d->in_flight_bitmask |= (1UL << wkr);
|
2014-05-29 10:12:14 +00:00
|
|
|
next_mb = NULL;
|
|
|
|
}
|
|
|
|
oldbuf = data >> RTE_DISTRIB_FLAG_BITS;
|
|
|
|
} else if (data & RTE_DISTRIB_RETURN_BUF) {
|
|
|
|
handle_worker_shutdown(d, wkr);
|
|
|
|
oldbuf = data >> RTE_DISTRIB_FLAG_BITS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* store returns in a circular buffer */
|
|
|
|
store_return(oldbuf, d, &ret_start, &ret_count);
|
|
|
|
|
|
|
|
if (++wkr == d->num_workers)
|
|
|
|
wkr = 0;
|
|
|
|
}
|
|
|
|
/* to finish, check all workers for backlog and schedule work for them
|
|
|
|
* if they are ready */
|
|
|
|
for (wkr = 0; wkr < d->num_workers; wkr++)
|
|
|
|
if (d->backlog[wkr].count &&
|
|
|
|
(d->bufs[wkr].bufptr64 & RTE_DISTRIB_GET_BUF)) {
|
|
|
|
|
|
|
|
int64_t oldbuf = d->bufs[wkr].bufptr64 >>
|
|
|
|
RTE_DISTRIB_FLAG_BITS;
|
|
|
|
store_return(oldbuf, d, &ret_start, &ret_count);
|
|
|
|
|
|
|
|
d->bufs[wkr].bufptr64 = backlog_pop(&d->backlog[wkr]);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->returns.start = ret_start;
|
|
|
|
d->returns.count = ret_count;
|
|
|
|
return num_mbufs;
|
|
|
|
}
|
2017-03-20 10:08:32 +00:00
|
|
|
VERSION_SYMBOL(rte_distributor_process, _v20, 2.0);
|
2014-05-29 10:12:14 +00:00
|
|
|
|
|
|
|
/* return to the caller, packets returned from workers */
|
|
|
|
int
|
2017-03-20 10:08:30 +00:00
|
|
|
rte_distributor_returned_pkts_v20(struct rte_distributor_v20 *d,
|
2014-05-29 10:12:14 +00:00
|
|
|
struct rte_mbuf **mbufs, unsigned max_mbufs)
|
|
|
|
{
|
|
|
|
struct rte_distributor_returned_pkts *returns = &d->returns;
|
|
|
|
unsigned retval = (max_mbufs < returns->count) ?
|
|
|
|
max_mbufs : returns->count;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < retval; i++) {
|
|
|
|
unsigned idx = (returns->start + i) & RTE_DISTRIB_RETURNS_MASK;
|
|
|
|
mbufs[i] = returns->mbufs[idx];
|
|
|
|
}
|
|
|
|
returns->start += i;
|
|
|
|
returns->count -= i;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2017-03-20 10:08:32 +00:00
|
|
|
VERSION_SYMBOL(rte_distributor_returned_pkts, _v20, 2.0);
|
2014-05-29 10:12:14 +00:00
|
|
|
|
|
|
|
/* return the number of packets in-flight in a distributor, i.e. packets
|
2017-11-10 08:24:23 +00:00
|
|
|
* being worked on or queued up in a backlog.
|
|
|
|
*/
|
2014-05-29 10:12:14 +00:00
|
|
|
static inline unsigned
|
2017-03-20 10:08:30 +00:00
|
|
|
total_outstanding(const struct rte_distributor_v20 *d)
|
2014-05-29 10:12:14 +00:00
|
|
|
{
|
2014-11-10 14:44:02 +00:00
|
|
|
unsigned wkr, total_outstanding;
|
|
|
|
|
|
|
|
total_outstanding = __builtin_popcountl(d->in_flight_bitmask);
|
2014-05-29 10:12:14 +00:00
|
|
|
|
|
|
|
for (wkr = 0; wkr < d->num_workers; wkr++)
|
2014-11-10 14:44:02 +00:00
|
|
|
total_outstanding += d->backlog[wkr].count;
|
|
|
|
|
2014-05-29 10:12:14 +00:00
|
|
|
return total_outstanding;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* flush the distributor, so that there are no outstanding packets in flight or
|
|
|
|
* queued up. */
|
|
|
|
int
|
2017-03-20 10:08:30 +00:00
|
|
|
rte_distributor_flush_v20(struct rte_distributor_v20 *d)
|
2014-05-29 10:12:14 +00:00
|
|
|
{
|
|
|
|
const unsigned flushed = total_outstanding(d);
|
|
|
|
|
|
|
|
while (total_outstanding(d) > 0)
|
2017-03-20 10:08:30 +00:00
|
|
|
rte_distributor_process_v20(d, NULL, 0);
|
2014-05-29 10:12:14 +00:00
|
|
|
|
|
|
|
return flushed;
|
|
|
|
}
|
2017-03-20 10:08:32 +00:00
|
|
|
VERSION_SYMBOL(rte_distributor_flush, _v20, 2.0);
|
2014-05-29 10:12:14 +00:00
|
|
|
|
|
|
|
/* clears the internal returns array in the distributor */
|
|
|
|
void
|
2017-03-20 10:08:30 +00:00
|
|
|
rte_distributor_clear_returns_v20(struct rte_distributor_v20 *d)
|
2014-05-29 10:12:14 +00:00
|
|
|
{
|
|
|
|
d->returns.start = d->returns.count = 0;
|
|
|
|
#ifndef __OPTIMIZE__
|
|
|
|
memset(d->returns.mbufs, 0, sizeof(d->returns.mbufs));
|
|
|
|
#endif
|
|
|
|
}
|
2017-03-20 10:08:32 +00:00
|
|
|
VERSION_SYMBOL(rte_distributor_clear_returns, _v20, 2.0);
|
2014-05-29 10:12:14 +00:00
|
|
|
|
|
|
|
/* creates a distributor instance */
|
2017-03-20 10:08:30 +00:00
|
|
|
struct rte_distributor_v20 *
|
|
|
|
rte_distributor_create_v20(const char *name,
|
2014-05-29 10:12:14 +00:00
|
|
|
unsigned socket_id,
|
|
|
|
unsigned num_workers)
|
|
|
|
{
|
2017-03-20 10:08:30 +00:00
|
|
|
struct rte_distributor_v20 *d;
|
2014-05-29 10:12:14 +00:00
|
|
|
struct rte_distributor_list *distributor_list;
|
|
|
|
char mz_name[RTE_MEMZONE_NAMESIZE];
|
|
|
|
const struct rte_memzone *mz;
|
|
|
|
|
|
|
|
/* compilation-time checks */
|
2014-11-19 12:26:06 +00:00
|
|
|
RTE_BUILD_BUG_ON((sizeof(*d) & RTE_CACHE_LINE_MASK) != 0);
|
2014-11-10 14:44:02 +00:00
|
|
|
RTE_BUILD_BUG_ON((RTE_DISTRIB_MAX_WORKERS & 7) != 0);
|
|
|
|
RTE_BUILD_BUG_ON(RTE_DISTRIB_MAX_WORKERS >
|
|
|
|
sizeof(d->in_flight_bitmask) * CHAR_BIT);
|
2014-05-29 10:12:14 +00:00
|
|
|
|
2014-11-10 14:44:02 +00:00
|
|
|
if (name == NULL || num_workers >= RTE_DISTRIB_MAX_WORKERS) {
|
2014-05-29 10:12:14 +00:00
|
|
|
rte_errno = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-24 18:15:28 +00:00
|
|
|
snprintf(mz_name, sizeof(mz_name), RTE_DISTRIB_PREFIX"%s", name);
|
2014-05-29 10:12:14 +00:00
|
|
|
mz = rte_memzone_reserve(mz_name, sizeof(*d), socket_id, NO_FLAGS);
|
|
|
|
if (mz == NULL) {
|
|
|
|
rte_errno = ENOMEM;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
d = mz->addr;
|
2014-06-24 18:15:28 +00:00
|
|
|
snprintf(d->name, sizeof(d->name), "%s", name);
|
2014-05-29 10:12:14 +00:00
|
|
|
d->num_workers = num_workers;
|
|
|
|
|
2015-03-04 21:50:08 +00:00
|
|
|
distributor_list = RTE_TAILQ_CAST(rte_distributor_tailq.head,
|
|
|
|
rte_distributor_list);
|
|
|
|
|
2014-05-29 10:12:14 +00:00
|
|
|
rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
|
|
|
|
TAILQ_INSERT_TAIL(distributor_list, d, next);
|
|
|
|
rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
|
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
2017-03-20 10:08:32 +00:00
|
|
|
VERSION_SYMBOL(rte_distributor_create, _v20, 2.0);
|