#include "pipeline_common.h"
worker_generic(void *arg)
{
struct worker_data *data = (struct worker_data *)arg;
uint8_t dev_id = data->dev_id;
uint8_t port_id = data->port_id;
size_t sent = 0, received = 0;
while (!fdata->done) {
if (fdata->cap.scheduler)
fdata->cap.scheduler(lcore_id);
if (!fdata->worker_core[lcore_id]) {
continue;
}
&ev, 1, 0);
if (nb_rx == 0) {
continue;
}
received++;
% cdata.num_fids;
work();
sent++;
}
if (!cdata.quiet)
printf(" worker %u thread done. RX=%zu TX=%zu\n",
return 0;
}
static int
worker_generic_burst(void *arg)
{
struct worker_data *data = (struct worker_data *)arg;
uint8_t dev_id = data->dev_id;
uint8_t port_id = data->port_id;
size_t sent = 0, received = 0;
while (!fdata->done) {
uint16_t i;
if (fdata->cap.scheduler)
fdata->cap.scheduler(lcore_id);
if (!fdata->worker_core[lcore_id]) {
continue;
}
if (nb_rx == 0) {
continue;
}
received += nb_rx;
for (i = 0; i < nb_rx; i++) {
if (events[i].queue_id == cdata.qid[0])
events[i].flow_id = events[i].mbuf->hash.rss
% cdata.num_fids;
events[i].queue_id = cdata.next_qid[events[i].queue_id];
events[i].sched_type = cdata.queue_type;
work();
}
events, nb_rx);
while (nb_tx < nb_rx && !fdata->done)
events + nb_tx,
nb_rx - nb_tx);
sent += nb_tx;
}
if (!cdata.quiet)
printf(" worker %u thread done. RX=%zu TX=%zu\n",
return 0;
}
consumer(void)
{
static uint64_t received;
static uint64_t last_pkts;
static uint64_t last_time;
static uint64_t start_time;
int i;
uint8_t dev_id = cons_data.dev_id;
uint8_t port_id = cons_data.port_id;
do {
&packet, 1, 0);
if (n == 0) {
return 0;
}
if (start_time == 0)
received++;
exchange_mac(packet.
mbuf);
packet.mbuf);
if (cons_data.release)
&packet, n);
if (!cdata.quiet && received >= last_pkts + (1<<22)) {
const uint64_t total_ms = (now - start_time) / freq_khz;
const uint64_t delta_ms = (now - last_time) / freq_khz;
uint64_t delta_pkts = received - last_pkts;
printf("# %s RX=%"PRIu64", time %"PRIu64 "ms, "
"avg %.3f mpps [current %.3f mpps]\n",
__func__,
received,
total_ms,
received / (total_ms * 1000.0),
delta_pkts / (delta_ms * 1000.0));
last_pkts = received;
last_time = now;
}
cdata.num_packets--;
if (cdata.num_packets <= 0)
fdata->done = 1;
} while (!fdata->done && fdata->tx_single);
return 0;
}
consumer_burst(void)
{
static uint64_t received;
static uint64_t last_pkts;
static uint64_t last_time;
static uint64_t start_time;
unsigned int i, j;
uint8_t dev_id = cons_data.dev_id;
uint8_t port_id = cons_data.port_id;
do {
if (n == 0) {
return 0;
}
if (start_time == 0)
last_time = start_time = rte_get_timer_cycles();
received += n;
for (i = 0; i < n; i++) {
uint8_t outport = packets[i].mbuf->port;
exchange_mac(packets[i].mbuf);
packets[i].mbuf);
}
if (cons_data.release) {
uint16_t nb_tx;
packets, n);
while (nb_tx < n)
port_id, packets + nb_tx,
n - nb_tx);
}
if (!cdata.quiet && received >= last_pkts + (1<<22)) {
const uint64_t total_ms = (now - start_time) / freq_khz;
const uint64_t delta_ms = (now - last_time) / freq_khz;
uint64_t delta_pkts = received - last_pkts;
printf("# consumer RX=%"PRIu64", time %"PRIu64 "ms, "
"avg %.3f mpps [current %.3f mpps]\n",
received,
total_ms,
received / (total_ms * 1000.0),
delta_pkts / (delta_ms * 1000.0));
last_pkts = received;
last_time = now;
}
cdata.num_packets -= n;
if (cdata.num_packets <= 0)
fdata->done = 1;
} while (!fdata->done && fdata->tx_single);
return 0;
}
static int
setup_eventdev_generic(struct cons_data *cons_data,
struct worker_data *worker_data)
{
const uint8_t dev_id = 0;
const uint8_t nb_queues = cdata.num_stages + 1;
const uint8_t nb_ports = cdata.num_workers + 1;
.nb_event_ports = nb_ports,
.nb_events_limit = 4096,
.nb_event_queue_flows = 1024,
.nb_event_port_dequeue_depth = 128,
.nb_event_port_enqueue_depth = 128,
};
.enqueue_depth = 64,
.new_event_threshold = 4096,
};
.nb_atomic_flows = 1024,
.nb_atomic_order_sequences = 1024,
};
.enqueue_depth = 128,
.new_event_threshold = 4096,
};
};
struct port_link worker_queues[MAX_NUM_STAGES];
uint8_t disable_implicit_release;
struct port_link tx_queue;
unsigned int i;
if (ndev < 1) {
printf("%d: No Eventdev Devices Found\n", __LINE__);
return -1;
}
printf("\tEventdev %d: %s\n", dev_id, dev_info.driver_name);
disable_implicit_release = (dev_info.event_dev_cap &
if (dev_info.max_event_port_dequeue_depth <
dev_info.max_event_port_dequeue_depth;
if (dev_info.max_event_port_enqueue_depth <
dev_info.max_event_port_enqueue_depth;
if (ret < 0) {
printf("%d: Error configuring device\n", __LINE__);
return -1;
}
printf(" Stages:\n");
for (i = 0; i < cdata.num_stages; i++) {
printf("%d: error creating qid %d\n", __LINE__, i);
return -1;
}
cdata.qid[i] = i;
cdata.next_qid[i] = i+1;
worker_queues[i].queue_id = i;
if (cdata.enable_queue_priorities) {
const uint32_t prio_delta =
}
const char *type_str = "Atomic";
type_str = "Ordered";
break;
type_str = "Parallel";
break;
}
printf("\tStage %d, Type %s\tPriority = %d\n", i, type_str,
}
printf("\n");
printf("%d: error creating qid %d\n", __LINE__, i);
return -1;
}
tx_queue.queue_id = i;
for (i = 0; i < cdata.num_workers; i++) {
struct worker_data *w = &worker_data[i];
w->dev_id = dev_id;
printf("Error setting up port %d\n", i);
return -1;
}
uint32_t s;
for (s = 0; s < cdata.num_stages; s++) {
&worker_queues[s].queue_id,
&worker_queues[s].priority,
1) != 1) {
printf("%d: error creating link for port %d\n",
__LINE__, i);
return -1;
}
}
w->port_id = i;
}
printf("Error setting up port %d\n", i);
return -1;
}
&tx_queue.priority, 1) != 1) {
printf("%d: error creating link for port %d\n",
__LINE__, i);
return -1;
}
*cons_data = (struct cons_data){.dev_id = dev_id,
.port_id = i,
.release = disable_implicit_release };
&fdata->evdev_service_id);
if (ret != -ESRCH && ret != 0) {
printf("Error getting the service ID for sw eventdev\n");
return -1;
}
printf("Error starting eventdev\n");
return -1;
}
return dev_id;
}
static void
init_rx_adapter(uint16_t nb_ports)
{
int i;
int ret;
uint8_t evdev_id = 0;
.enqueue_depth = 8,
.new_event_threshold = 1200,
};
if (rx_p_conf.
dequeue_depth > dev_info.max_event_port_dequeue_depth)
if (rx_p_conf.
enqueue_depth > dev_info.max_event_port_enqueue_depth)
&rx_p_conf);
if (ret)
rte_exit(EXIT_FAILURE,
"failed to create rx adapter[%d]",
cdata.rx_adapter_id);
memset(&queue_conf, 0, sizeof(queue_conf));
for (i = 0; i < nb_ports; i++) {
uint32_t cap;
if (ret)
"failed to get event rx adapter "
"capabilities");
-1, &queue_conf);
if (ret)
"Failed to add queues to Rx adapter");
}
&fdata->rxadptr_service_id);
if (ret != -ESRCH && ret != 0) {
"Error getting the service ID for sw eventdev\n");
}
if (ret)
rte_exit(EXIT_FAILURE,
"Rx adapter[%d] start failed",
cdata.rx_adapter_id);
}
static void
generic_opt_check(void)
{
int i;
int ret;
uint32_t cap = 0;
uint8_t rx_needed = 0;
if (cdata.all_type_queues && !(eventdev_info.event_dev_cap &
"Event dev doesn't support all type queues\n");
if (ret)
"failed to get event rx adapter capabilities");
rx_needed |=
}
if (cdata.worker_lcore_mask == 0 ||
(rx_needed && cdata.rx_lcore_mask == 0) ||
cdata.tx_lcore_mask == 0 || (cdata.sched_lcore_mask == 0
&& !(eventdev_info.event_dev_cap &
printf("Core part of pipeline was not assigned any cores. "
"This will stall the pipeline, please check core masks "
"(use -h for details on setting core masks):\n"
"\trx: %"PRIu64"\n\ttx: %"PRIu64"\n\tsched: %"PRIu64
"\n\tworkers: %"PRIu64"\n",
cdata.rx_lcore_mask, cdata.tx_lcore_mask,
cdata.sched_lcore_mask,
cdata.worker_lcore_mask);
}
memset(fdata->sched_core, 0,
sizeof(unsigned int) * MAX_NUM_CORE);
}
void
set_worker_generic_setup_data(struct setup_data *caps, bool burst)
{
if (burst) {
caps->consumer = consumer_burst;
caps->worker = worker_generic_burst;
} else {
caps->consumer = consumer;
caps->worker = worker_generic;
}
caps->adptr_setup = init_rx_adapter;
caps->scheduler = schedule_devices;
caps->evdev_setup = setup_eventdev_generic;
caps->check_opt = generic_opt_check;
}