Skip to content

Commit

Permalink
infra/port: handle siblings on removal
Browse files Browse the repository at this point in the history
On device removal, check if the port has siblings
before calling rte_dev_remove.

Fixes: https://github.com/rjarry/grout/issues/40
Signed-off-by: Christophe Fontaine <[email protected]>
  • Loading branch information
christophefontaine committed Jul 24, 2024
1 parent c7fcf4b commit 5b2e1e3
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion modules/infra/control/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,29 @@ int iface_port_reconfig(

static const struct iface *port_ifaces[RTE_MAX_ETHPORTS];

static bool all_txrx_queue_stopped(uint16_t port_id) {
struct rte_eth_rxq_info rxqinfo;
struct rte_eth_txq_info txqinfo;
uint8_t queue_id = 0;
bool stopped = true;

while (rte_eth_rx_queue_info_get(port_id, queue_id++, &rxqinfo) == 0) {
stopped &= rxqinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED;
}

queue_id = 0;
while (rte_eth_tx_queue_info_get(port_id, queue_id++, &txqinfo) == 0) {
stopped &= txqinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED;
}
return stopped;
}

static int iface_port_fini(struct iface *iface) {
struct iface_info_port *port = (struct iface_info_port *)iface->info;
bool sibling_is_active = false;
struct rte_eth_dev_info info;
struct worker *worker, *tmp;
uint16_t sibling_port_id;
size_t n_workers;
int ret;

Expand All @@ -344,7 +363,13 @@ static int iface_port_fini(struct iface *iface) {
LOG(ERR, "rte_eth_dev_stop: %s", rte_strerror(-ret));
if ((ret = rte_eth_dev_close(port->port_id)) < 0)
LOG(ERR, "rte_eth_dev_close: %s", rte_strerror(-ret));
if (info.device != NULL && (ret = rte_dev_remove(info.device)) < 0)

// Do not release resources if the port has active siblings
RTE_ETH_FOREACH_DEV_SIBLING(sibling_port_id, port->port_id) {
sibling_is_active |= !all_txrx_queue_stopped(sibling_port_id);
}

if (!sibling_is_active && info.device != NULL && (ret = rte_dev_remove(info.device)) < 0)
LOG(ERR, "rte_dev_remove: %s", rte_strerror(-ret));
if (port->pool != NULL) {
rte_mempool_free(port->pool);
Expand Down

0 comments on commit 5b2e1e3

Please sign in to comment.