#include <stdbool.h>
#include <getopt.h>
#include "l2fwd_event.h"
#define L2FWD_EVENT_SINGLE 0x1
#define L2FWD_EVENT_BURST 0x2
#define L2FWD_EVENT_TX_DIRECT 0x4
#define L2FWD_EVENT_TX_ENQ 0x8
#define L2FWD_EVENT_UPDT_MAC 0x10
static inline int
l2fwd_event_service_enable(uint32_t service_id)
{
uint8_t min_service_count = UINT8_MAX;
uint32_t slcore_array[RTE_MAX_LCORE];
unsigned int slcore = 0;
uint8_t service_count;
int32_t slcore_count;
return -ENOENT;
if (slcore_count < 0)
return -ENOENT;
while (slcore_count--) {
slcore_array[slcore_count], 0) != 0)
return -ENOENT;
slcore_array[slcore_count]);
if (service_count < min_service_count) {
slcore = slcore_array[slcore_count];
min_service_count = service_count;
}
}
return -ENOENT;
return 0;
}
void
l2fwd_event_service_setup(struct l2fwd_resources *rsrc)
{
struct l2fwd_event_resources *evt_rsrc = rsrc->evt_rsrc;
uint32_t service_id, caps;
int ret, i;
&service_id);
if (ret != -ESRCH && ret != 0)
rte_panic(
"Error in starting eventdev service\n");
l2fwd_event_service_enable(service_id);
}
for (i = 0; i < evt_rsrc->rx_adptr.nb_rx_adptr; i++) {
evt_rsrc->rx_adptr.rx_adptr[i], &caps);
if (ret < 0)
rte_panic(
"Failed to get Rx adapter[%d] caps\n",
evt_rsrc->rx_adptr.rx_adptr[i]);
evt_rsrc->event_d_id,
&service_id);
if (ret != -ESRCH && ret != 0)
rte_panic(
"Error in starting Rx adapter[%d] service\n",
evt_rsrc->rx_adptr.rx_adptr[i]);
l2fwd_event_service_enable(service_id);
}
for (i = 0; i < evt_rsrc->tx_adptr.nb_tx_adptr; i++) {
evt_rsrc->tx_adptr.tx_adptr[i], &caps);
if (ret < 0)
rte_panic(
"Failed to get Rx adapter[%d] caps\n",
evt_rsrc->tx_adptr.tx_adptr[i]);
evt_rsrc->event_d_id,
&service_id);
if (ret != -ESRCH && ret != 0)
rte_panic(
"Error in starting Rx adapter[%d] service\n",
evt_rsrc->tx_adptr.tx_adptr[i]);
l2fwd_event_service_enable(service_id);
}
}
static void
l2fwd_event_capability_setup(struct l2fwd_event_resources *evt_rsrc)
{
uint32_t caps = 0;
uint16_t i;
int ret;
if (ret)
rte_panic(
"Invalid capability for Tx adptr port %d\n",
i);
evt_rsrc->tx_mode_q |= !(caps &
}
if (evt_rsrc->tx_mode_q)
l2fwd_event_set_generic_ops(&evt_rsrc->ops);
else
l2fwd_event_set_internal_port_ops(&evt_rsrc->ops);
}
l2fwd_get_free_event_port(struct l2fwd_event_resources *evt_rsrc)
{
static int index;
int port_id;
if (index >= evt_rsrc->evp.nb_ports) {
printf("No free event port is available\n");
return -1;
}
port_id = evt_rsrc->evp.event_p_id[index];
index++;
return port_id;
}
l2fwd_event_fwd(
struct l2fwd_resources *rsrc,
struct rte_event *ev,
const uint8_t tx_q_id, const uint64_t timer_period,
const uint32_t flags)
{
uint16_t dst_port;
dst_port = rsrc->dst_ports[mbuf->
port];
if (timer_period > 0)
__atomic_fetch_add(&rsrc->port_stats[mbuf->
port].rx,
1, __ATOMIC_RELAXED);
if (flags & L2FWD_EVENT_UPDT_MAC)
l2fwd_mac_updating(mbuf, dst_port, &rsrc->eth_addr[dst_port]);
if (flags & L2FWD_EVENT_TX_ENQ) {
}
if (flags & L2FWD_EVENT_TX_DIRECT)
if (timer_period > 0)
__atomic_fetch_add(&rsrc->port_stats[mbuf->
port].tx,
1, __ATOMIC_RELAXED);
}
l2fwd_event_loop_single(struct l2fwd_resources *rsrc,
const uint32_t flags)
{
struct l2fwd_event_resources *evt_rsrc = rsrc->evt_rsrc;
const int port_id = l2fwd_get_free_event_port(evt_rsrc);
const uint8_t tx_q_id = evt_rsrc->evq.event_q_id[
evt_rsrc->evq.nb_queues - 1];
const uint64_t timer_period = rsrc->timer_period;
const uint8_t event_d_id = evt_rsrc->event_d_id;
if (port_id < 0)
return;
printf("%s(): entering eventdev main loop on lcore %u\n", __func__,
while (!rsrc->force_quit) {
continue;
l2fwd_event_fwd(rsrc, &ev, tx_q_id, timer_period, flags);
if (flags & L2FWD_EVENT_TX_ENQ) {
&ev, 1) &&
!rsrc->force_quit)
;
}
if (flags & L2FWD_EVENT_TX_DIRECT) {
port_id,
&ev, 1, 0) &&
!rsrc->force_quit)
;
}
}
}
l2fwd_event_loop_burst(struct l2fwd_resources *rsrc,
const uint32_t flags)
{
struct l2fwd_event_resources *evt_rsrc = rsrc->evt_rsrc;
const int port_id = l2fwd_get_free_event_port(evt_rsrc);
const uint8_t tx_q_id = evt_rsrc->evq.event_q_id[
evt_rsrc->evq.nb_queues - 1];
const uint64_t timer_period = rsrc->timer_period;
const uint8_t event_d_id = evt_rsrc->event_d_id;
const uint8_t deq_len = evt_rsrc->deq_depth;
uint16_t nb_rx, nb_tx;
uint8_t i;
if (port_id < 0)
return;
printf("%s(): entering eventdev main loop on lcore %u\n", __func__,
while (!rsrc->force_quit) {
deq_len, 0);
if (nb_rx == 0)
continue;
for (i = 0; i < nb_rx; i++) {
l2fwd_event_fwd(rsrc, &ev[i], tx_q_id, timer_period,
flags);
}
if (flags & L2FWD_EVENT_TX_ENQ) {
ev, nb_rx);
while (nb_tx < nb_rx && !rsrc->force_quit)
port_id, ev + nb_tx,
nb_rx - nb_tx);
}
if (flags & L2FWD_EVENT_TX_DIRECT) {
port_id, ev,
nb_rx, 0);
while (nb_tx < nb_rx && !rsrc->force_quit)
event_d_id, port_id,
ev + nb_tx, nb_rx - nb_tx, 0);
}
}
}
l2fwd_event_loop(struct l2fwd_resources *rsrc,
const uint32_t flags)
{
if (flags & L2FWD_EVENT_SINGLE)
l2fwd_event_loop_single(rsrc, flags);
if (flags & L2FWD_EVENT_BURST)
l2fwd_event_loop_burst(rsrc, flags);
}
l2fwd_event_main_loop_tx_d(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop(rsrc,
L2FWD_EVENT_TX_DIRECT | L2FWD_EVENT_SINGLE);
}
l2fwd_event_main_loop_tx_d_brst(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop(rsrc, L2FWD_EVENT_TX_DIRECT | L2FWD_EVENT_BURST);
}
l2fwd_event_main_loop_tx_q(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop(rsrc, L2FWD_EVENT_TX_ENQ | L2FWD_EVENT_SINGLE);
}
l2fwd_event_main_loop_tx_q_brst(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop(rsrc, L2FWD_EVENT_TX_ENQ | L2FWD_EVENT_BURST);
}
l2fwd_event_main_loop_tx_d_mac(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop(rsrc, L2FWD_EVENT_UPDT_MAC |
L2FWD_EVENT_TX_DIRECT | L2FWD_EVENT_SINGLE);
}
l2fwd_event_main_loop_tx_d_brst_mac(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop(rsrc, L2FWD_EVENT_UPDT_MAC |
L2FWD_EVENT_TX_DIRECT | L2FWD_EVENT_BURST);
}
l2fwd_event_main_loop_tx_q_mac(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop(rsrc, L2FWD_EVENT_UPDT_MAC |
L2FWD_EVENT_TX_ENQ | L2FWD_EVENT_SINGLE);
}
l2fwd_event_main_loop_tx_q_brst_mac(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop(rsrc, L2FWD_EVENT_UPDT_MAC |
L2FWD_EVENT_TX_ENQ | L2FWD_EVENT_BURST);
}
l2fwd_event_vector_fwd(struct l2fwd_resources *rsrc,
const uint64_t timer_period, const uint32_t flags)
{
uint16_t i, j;
vec->
port = rsrc->dst_ports[mbufs[0]->
port];
if (flags & L2FWD_EVENT_TX_DIRECT)
if (timer_period > 0)
__atomic_fetch_add(&rsrc->port_stats[mbufs[0]->
port].rx,
for (i = 0, j = 1; i < vec->
nb_elem; i++, j++) {
if (flags & L2FWD_EVENT_UPDT_MAC)
l2fwd_mac_updating(
mbufs[i], vec->port,
&rsrc->eth_addr[vec->port]);
}
if (timer_period > 0)
__atomic_fetch_add(&rsrc->port_stats[vec->port].tx,
} else {
for (i = 0, j = 1; i < vec->
nb_elem; i++, j++) {
if (timer_period > 0)
__atomic_fetch_add(
&rsrc->port_stats[mbufs[i]->
port].rx, 1,
__ATOMIC_RELAXED);
mbufs[i]->
port = rsrc->dst_ports[mbufs[i]->
port];
if (flags & L2FWD_EVENT_UPDT_MAC)
l2fwd_mac_updating(
mbufs[i], mbufs[i]->
port,
&rsrc->eth_addr[mbufs[i]->
port]);
if (flags & L2FWD_EVENT_TX_DIRECT)
if (timer_period > 0)
__atomic_fetch_add(
&rsrc->port_stats[mbufs[i]->
port].tx, 1,
__ATOMIC_RELAXED);
}
}
}
l2fwd_event_loop_vector(struct l2fwd_resources *rsrc, const uint32_t flags)
{
struct l2fwd_event_resources *evt_rsrc = rsrc->evt_rsrc;
const int port_id = l2fwd_get_free_event_port(evt_rsrc);
const uint8_t tx_q_id =
evt_rsrc->evq.event_q_id[evt_rsrc->evq.nb_queues - 1];
const uint64_t timer_period = rsrc->timer_period;
const uint8_t event_d_id = evt_rsrc->event_d_id;
const uint8_t deq_len = evt_rsrc->deq_depth;
uint16_t nb_rx, nb_tx;
uint8_t i;
if (port_id < 0)
return;
printf("%s(): entering eventdev main loop on lcore %u\n", __func__,
while (!rsrc->force_quit) {
deq_len, 0);
if (nb_rx == 0)
continue;
for (i = 0; i < nb_rx; i++) {
if (flags & L2FWD_EVENT_TX_ENQ) {
}
l2fwd_event_vector_fwd(rsrc, ev[i].vec, timer_period,
flags);
}
if (flags & L2FWD_EVENT_TX_ENQ) {
nb_rx);
while (nb_tx < nb_rx && !rsrc->force_quit)
event_d_id, port_id, ev + nb_tx,
nb_rx - nb_tx);
}
if (flags & L2FWD_EVENT_TX_DIRECT) {
event_d_id, port_id, ev, nb_rx, 0);
while (nb_tx < nb_rx && !rsrc->force_quit)
event_d_id, port_id, ev + nb_tx,
nb_rx - nb_tx, 0);
}
}
}
l2fwd_event_main_loop_tx_d_vec(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop_vector(rsrc, L2FWD_EVENT_TX_DIRECT);
}
l2fwd_event_main_loop_tx_d_brst_vec(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop_vector(rsrc, L2FWD_EVENT_TX_DIRECT);
}
l2fwd_event_main_loop_tx_q_vec(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop_vector(rsrc, L2FWD_EVENT_TX_ENQ);
}
l2fwd_event_main_loop_tx_q_brst_vec(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop_vector(rsrc, L2FWD_EVENT_TX_ENQ);
}
l2fwd_event_main_loop_tx_d_mac_vec(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop_vector(rsrc,
L2FWD_EVENT_UPDT_MAC | L2FWD_EVENT_TX_DIRECT);
}
l2fwd_event_main_loop_tx_d_brst_mac_vec(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop_vector(rsrc,
L2FWD_EVENT_UPDT_MAC | L2FWD_EVENT_TX_DIRECT);
}
l2fwd_event_main_loop_tx_q_mac_vec(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop_vector(rsrc,
L2FWD_EVENT_UPDT_MAC | L2FWD_EVENT_TX_ENQ);
}
l2fwd_event_main_loop_tx_q_brst_mac_vec(struct l2fwd_resources *rsrc)
{
l2fwd_event_loop_vector(rsrc,
L2FWD_EVENT_UPDT_MAC | L2FWD_EVENT_TX_ENQ);
}
void
l2fwd_event_resource_setup(struct l2fwd_resources *rsrc)
{
const event_loop_cb event_loop[2][2][2][2] = {
[0][0][0][0] = l2fwd_event_main_loop_tx_d,
[0][0][0][1] = l2fwd_event_main_loop_tx_d_brst,
[0][0][1][0] = l2fwd_event_main_loop_tx_q,
[0][0][1][1] = l2fwd_event_main_loop_tx_q_brst,
[0][1][0][0] = l2fwd_event_main_loop_tx_d_mac,
[0][1][0][1] = l2fwd_event_main_loop_tx_d_brst_mac,
[0][1][1][0] = l2fwd_event_main_loop_tx_q_mac,
[0][1][1][1] = l2fwd_event_main_loop_tx_q_brst_mac,
[1][0][0][0] = l2fwd_event_main_loop_tx_d_vec,
[1][0][0][1] = l2fwd_event_main_loop_tx_d_brst_vec,
[1][0][1][0] = l2fwd_event_main_loop_tx_q_vec,
[1][0][1][1] = l2fwd_event_main_loop_tx_q_brst_vec,
[1][1][0][0] = l2fwd_event_main_loop_tx_d_mac_vec,
[1][1][0][1] = l2fwd_event_main_loop_tx_d_brst_mac_vec,
[1][1][1][0] = l2fwd_event_main_loop_tx_q_mac_vec,
[1][1][1][1] = l2fwd_event_main_loop_tx_q_brst_mac_vec,
};
struct l2fwd_event_resources *evt_rsrc;
uint32_t event_queue_cfg;
int ret;
sizeof(struct l2fwd_event_resources), 0);
if (evt_rsrc == NULL)
rsrc->evt_rsrc = evt_rsrc;
l2fwd_event_capability_setup(evt_rsrc);
event_queue_cfg = evt_rsrc->ops.event_device_setup(rsrc);
evt_rsrc->ops.event_queue_setup(rsrc, event_queue_cfg);
evt_rsrc->ops.event_port_setup(rsrc);
evt_rsrc->ops.adapter_setup(rsrc);
if (ret < 0)
evt_rsrc->ops.l2fwd_event_loop =
event_loop[rsrc->evt_vec.enabled][rsrc->mac_updating]
[evt_rsrc->tx_mode_q][evt_rsrc->has_burst];
}