ethdev: deprecate port count function

Some DPDK applications wrongly assume these requirements:
    - no hotplug, i.e. ports are never detached
    - all allocated ports are available to the application

Such application iterates over ports by its own mean.
The most common pattern is to request the port count and
assume ports with index in the range [0..count[ can be used.

In order to fix this common mistake in all external applications,
the function rte_eth_dev_count is deprecated, while introducing
the new functions rte_eth_dev_count_avail and rte_eth_dev_count_total.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
This commit is contained in:
Thomas Monjalon 2018-04-05 17:33:22 +02:00
parent a9dbe18022
commit d9a42a69fe
76 changed files with 151 additions and 79 deletions

View File

@ -628,7 +628,7 @@ main(int argc, char **argv)
return 0;
}
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");

View File

@ -279,7 +279,7 @@ evt_dump_producer_type(struct evt_options *opt)
case EVT_PROD_TYPE_ETH_RX_ADPTR:
snprintf(name, EVT_PROD_MAX_NAME_LEN,
"Ethdev Rx Adapter producers");
evt_dump("nb_ethdev", "%d", rte_eth_dev_count());
evt_dump("nb_ethdev", "%d", rte_eth_dev_count_avail());
break;
case EVT_PROD_TYPE_EVENT_TIMER_ADPTR:
if (opt->timdev_use_burst)

View File

@ -11,7 +11,7 @@ atq_nb_event_queues(struct evt_options *opt)
{
/* nb_queues = number of producers */
return opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR ?
rte_eth_dev_count() : evt_nr_active_lcores(opt->plcores);
rte_eth_dev_count_avail() : evt_nr_active_lcores(opt->plcores);
}
static inline __attribute__((always_inline)) void

View File

@ -700,7 +700,7 @@ perf_ethdev_setup(struct evt_test *test, struct evt_options *opt)
opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR)
return 0;
if (!rte_eth_dev_count()) {
if (!rte_eth_dev_count_avail()) {
evt_err("No ethernet ports found.");
return -ENODEV;
}

View File

@ -11,7 +11,7 @@ perf_queue_nb_event_queues(struct evt_options *opt)
{
/* nb_queues = number of producers * number of stages */
uint8_t nb_prod = opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR ?
rte_eth_dev_count() : evt_nr_active_lcores(opt->plcores);
rte_eth_dev_count_avail() : evt_nr_active_lcores(opt->plcores);
return nb_prod * opt->nb_stages;
}

View File

@ -12,7 +12,7 @@ pipeline_atq_nb_event_queues(struct evt_options *opt)
{
RTE_SET_USED(opt);
return rte_eth_dev_count();
return rte_eth_dev_count_avail();
}
static int
@ -324,7 +324,7 @@ pipeline_atq_eventdev_setup(struct evt_test *test, struct evt_options *opt)
uint8_t nb_worker_queues = 0;
nb_ports = evt_nr_active_lcores(opt->wlcores);
nb_queues = rte_eth_dev_count();
nb_queues = rte_eth_dev_count_avail();
/* One extra port and queueu for Tx service */
if (t->mt_unsafe) {

View File

@ -166,7 +166,7 @@ pipeline_opt_check(struct evt_options *opt, uint64_t nb_queues)
*/
lcores = 2;
if (!rte_eth_dev_count()) {
if (!rte_eth_dev_count_avail()) {
evt_err("test needs minimum 1 ethernet dev");
return -1;
}
@ -234,7 +234,7 @@ pipeline_ethdev_setup(struct evt_test *test, struct evt_options *opt)
};
RTE_SET_USED(opt);
if (!rte_eth_dev_count()) {
if (!rte_eth_dev_count_avail()) {
evt_err("No ethernet ports found.\n");
return -ENODEV;
}
@ -419,7 +419,7 @@ pipeline_event_tx_service_setup(struct evt_test *test, struct evt_options *opt,
tx->dev_id = opt->dev_id;
tx->queue_id = tx_queue_id;
tx->port_id = tx_port_id;
tx->nb_ethports = rte_eth_dev_count();
tx->nb_ethports = rte_eth_dev_count_avail();
tx->t = t;
/* Register Tx service */

View File

@ -10,7 +10,7 @@
static __rte_always_inline int
pipeline_queue_nb_event_queues(struct evt_options *opt)
{
uint16_t eth_count = rte_eth_dev_count();
uint16_t eth_count = rte_eth_dev_count_avail();
return (eth_count * opt->nb_stages) + eth_count;
}
@ -333,7 +333,7 @@ pipeline_queue_eventdev_setup(struct evt_test *test, struct evt_options *opt)
uint8_t nb_worker_queues = 0;
nb_ports = evt_nr_active_lcores(opt->wlcores);
nb_queues = rte_eth_dev_count() * (nb_stages);
nb_queues = rte_eth_dev_count_avail() * (nb_stages);
/* Extra port for Tx service. */
if (t->mt_unsafe) {
@ -341,7 +341,7 @@ pipeline_queue_eventdev_setup(struct evt_test *test, struct evt_options *opt)
nb_ports++;
nb_queues++;
} else
nb_queues += rte_eth_dev_count();
nb_queues += rte_eth_dev_count_avail();
rte_event_dev_info_get(opt->dev_id, &info);

View File

@ -5546,7 +5546,7 @@ static void cmd_create_bonded_device_parsed(void *parsed_result,
port_id);
/* Update number of ports */
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
reconfig(port_id, res->socket);
rte_eth_promiscuous_enable(port_id);
}

View File

@ -1916,7 +1916,7 @@ attach_port(char *identifier)
reconfig(pi, socket_id);
rte_eth_promiscuous_enable(pi);
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
ports[pi].port_status = RTE_PORT_STOPPED;
@ -1944,7 +1944,7 @@ detach_port(portid_t port_id)
return;
}
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
printf("Port '%s' is detached. Now total ports is %d\n",
name, nb_ports);
@ -2585,7 +2585,7 @@ main(int argc, char** argv)
rte_pdump_init(NULL);
#endif
nb_ports = (portid_t) rte_eth_dev_count();
nb_ports = (portid_t) rte_eth_dev_count_avail();
if (nb_ports == 0)
TESTPMD_LOG(WARNING, "No probed ethernet devices\n");

View File

@ -153,6 +153,13 @@ API Changes
memory footprint which helps in better cache utilization when large number
of meter objects are used.
* ethdev: The function ``rte_eth_dev_count``, often mis-used to iterate
over ports, is deprecated and replaced by ``rte_eth_dev_count_avail``.
There is also a new function ``rte_eth_dev_count_total`` to get the
total number of allocated ports, available or not.
The hotplug-proof applications should use ``RTE_ETH_FOREACH_DEV`` or
``RTE_ETH_FOREACH_DEV_OWNED_BY`` as port iterators.
* ethdev, in struct ``struct rte_eth_dev_info``, field ``rte_pci_device *pci_dev``
replaced with field ``struct rte_device *device``.

View File

@ -163,7 +163,7 @@ Then, a call to init_dpdk(), defined in init.c, is made to initialize the poll m
if (ret < 0)
rte_exit(EXIT_FAILURE, "rte_pci_probe(): error %d\n", ret);
if (rte_eth_dev_count() < 2)
if (rte_eth_dev_count_avail() < 2)
rte_exit(EXIT_FAILURE, "Not enough Ethernet port available\n");
}

View File

@ -748,7 +748,7 @@ main(int argc, char *argv[])
argc -= ret;
argv += ret;
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "Give at least one port\n");
else if (nb_ports > MAX_PORTS)

View File

@ -193,7 +193,7 @@ struct lcore_params {
static int
lcore_rx(struct lcore_params *p)
{
const uint16_t nb_ports = rte_eth_dev_count();
const uint16_t nb_ports = rte_eth_dev_count_avail();
const int socket_id = rte_socket_id();
uint16_t port;
struct rte_mbuf *bufs[BURST_SIZE*2];
@ -542,7 +542,7 @@ lcore_worker(struct lcore_params *p)
* for single port, xor_val will be zero so we won't modify the output
* port, otherwise we send traffic from 0 to 1, 2 to 3, and vice versa
*/
const unsigned xor_val = (rte_eth_dev_count() > 1);
const unsigned xor_val = (rte_eth_dev_count_avail() > 1);
struct rte_mbuf *buf[8] __rte_cache_aligned;
for (i = 0; i < 8; i++)
@ -678,7 +678,7 @@ main(int argc, char *argv[])
"1 lcore for packet TX\n"
"and at least 1 lcore for worker threads\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "Error: no ethernet ports detected\n");
if (nb_ports != 1 && (nb_ports & 1))

View File

@ -251,7 +251,7 @@ int main(int argc, char **argv)
if (cnt_args_parsed < 0)
rte_exit(EXIT_FAILURE, "rte_eal_init(): Failed");
cnt_ports = rte_eth_dev_count();
cnt_ports = rte_eth_dev_count_avail();
printf("Number of NICs: %i\n", cnt_ports);
if (cnt_ports == 0)
rte_exit(EXIT_FAILURE, "No available NIC ports!\n");

View File

@ -429,7 +429,7 @@ int
main(int argc, char **argv)
{
struct worker_data *worker_data;
unsigned int num_ports;
uint16_t num_ports;
int lcore_id;
int err;
@ -451,7 +451,7 @@ main(int argc, char **argv)
/* Parse cli options*/
parse_app_args(argc, argv);
num_ports = rte_eth_dev_count();
num_ports = rte_eth_dev_count_avail();
if (num_ports == 0)
rte_panic("No ethernet ports found\n");

View File

@ -422,7 +422,7 @@ setup_eventdev_worker_tx(struct cons_data *cons_data,
const uint8_t dev_id = 0;
const uint8_t nb_ports = cdata.num_workers;
uint8_t nb_slots = 0;
uint8_t nb_queues = rte_eth_dev_count();
uint8_t nb_queues = rte_eth_dev_count_avail();
/*
* In case where all type queues are not enabled, use queues equal to
@ -431,7 +431,7 @@ setup_eventdev_worker_tx(struct cons_data *cons_data,
*/
if (!atq) {
nb_queues *= cdata.num_stages;
nb_queues += rte_eth_dev_count();
nb_queues += rte_eth_dev_count_avail();
}
struct rte_event_dev_config config = {

View File

@ -559,7 +559,7 @@ main(int argc, char** argv)
}
/* Get number of ports found in scan */
nb_sys_ports = rte_eth_dev_count();
nb_sys_ports = rte_eth_dev_count_avail();
if (nb_sys_ports == 0)
FATAL_ERROR("No supported Ethernet device found");
/* Find highest port set in portmask */

View File

@ -752,7 +752,7 @@ int
main(int argc, char *argv[])
{
struct rte_mempool *mbuf_pool;
uint8_t nb_ports;
uint16_t nb_ports;
uint16_t portid;
int ret;
int socket_id;
@ -776,7 +776,7 @@ main(int argc, char *argv[])
rte_exit(EXIT_FAILURE, "Invalid flow_classify parameters\n");
/* Check that there is an even number of ports to send/receive on. */
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports < 2 || (nb_ports & 1))
rte_exit(EXIT_FAILURE, "Error: number of ports must be even\n");

View File

@ -50,6 +50,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk)
LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk)
LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk)
CFLAGS += -DALLOW_EXPERIMENTAL_API
build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@ -75,6 +77,7 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc
include $(RTE_SDK)/mk/rte.vars.mk
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)

View File

@ -232,7 +232,7 @@ int
main(int argc, char **argv)
{
int ret;
uint8_t nr_ports;
uint16_t nr_ports;
struct rte_flow_error error;
ret = rte_eal_init(argc, argv);
@ -243,7 +243,7 @@ main(int argc, char **argv)
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
nr_ports = rte_eth_dev_count();
nr_ports = rte_eth_dev_count_avail();
if (nr_ports == 0)
rte_exit(EXIT_FAILURE, ":: no Ethernet ports found\n");
port_id = 0;

View File

@ -9,3 +9,4 @@
sources = files(
'main.c',
)
allow_experimental_apis = true

View File

@ -843,7 +843,7 @@ main(int argc, char **argv)
struct rte_eth_txconf *txconf;
struct rx_queue *rxq;
int socket, ret;
unsigned nb_ports;
uint16_t nb_ports;
uint16_t queueid = 0;
unsigned lcore_id = 0, rx_lcore_id = 0;
uint32_t n_tx_queue, nb_lcores;
@ -861,7 +861,7 @@ main(int argc, char **argv)
if (ret < 0)
rte_exit(EXIT_FAILURE, "Invalid arguments");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "No ports found!\n");

View File

@ -1008,7 +1008,7 @@ main(int argc, char **argv)
if (ret < 0)
rte_exit(EXIT_FAILURE, "Invalid IP reassembly parameters\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "No ports found!\n");

View File

@ -674,7 +674,7 @@ main(int argc, char **argv)
if (clone_pool == NULL)
rte_exit(EXIT_FAILURE, "Cannot init clone mbuf pool\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "No physical ports!\n");
if (nb_ports > MAX_PORTS)

View File

@ -926,7 +926,7 @@ main(int argc, char** argv)
}
/* Get number of ports found in scan */
nb_sys_ports = rte_eth_dev_count();
nb_sys_ports = rte_eth_dev_count_avail();
if (nb_sys_ports == 0)
rte_exit(EXIT_FAILURE, "No supported Ethernet device found\n");

View File

@ -173,7 +173,7 @@ main(int argc, char *argv[])
argv += ret;
/* Check that there is an even number of ports to send/receive on. */
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports < 2 || (nb_ports & 1))
rte_exit(EXIT_FAILURE, "Error: number of ports must be even\n");

View File

@ -2311,7 +2311,7 @@ initialize_ports(struct l2fwd_crypto_options *options)
{
uint16_t last_portid = 0, portid;
unsigned enabled_portcount = 0;
unsigned nb_ports = rte_eth_dev_count();
unsigned nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0) {
printf("No Ethernet ports - bye\n");

View File

@ -770,7 +770,7 @@ main(int argc, char **argv)
if (l2fwd_pktmbuf_pool == NULL)
rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");

View File

@ -561,7 +561,7 @@ main(int argc, char **argv)
if (l2fwd_pktmbuf_pool == NULL)
rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");

View File

@ -545,7 +545,7 @@ main(int argc, char **argv)
/* convert to number of cycles */
timer_period *= rte_get_timer_hz();
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");

View File

@ -1891,7 +1891,7 @@ main(int argc, char **argv)
if (ret < 0)
rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (check_port_config() < 0)
rte_exit(EXIT_FAILURE, "check_port_config failed\n");

View File

@ -1650,7 +1650,7 @@ main(int argc, char **argv)
if (ret < 0)
rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (check_port_config() < 0)
rte_exit(EXIT_FAILURE, "check_port_config failed\n");

View File

@ -949,7 +949,7 @@ main(int argc, char **argv)
if (ret < 0)
rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (check_port_config() < 0)
rte_exit(EXIT_FAILURE, "check_port_config failed\n");

View File

@ -826,7 +826,7 @@ main(int argc, char **argv)
if (ret < 0)
rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (check_port_config() < 0)
rte_exit(EXIT_FAILURE, "check_port_config failed\n");

View File

@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk)
LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk)
LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk)
CFLAGS += -DALLOW_EXPERIMENTAL_API
build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@ -48,6 +50,7 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc
include $(RTE_SDK)/mk/rte.vars.mk
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)

View File

@ -542,7 +542,7 @@ main(int argc, char **argv)
if (lsi_pktmbuf_pool == NULL)
rte_panic("Cannot init mbuf pool\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
rte_panic("No Ethernet port - bye\n");

View File

@ -6,6 +6,7 @@
# To build this example as a standalone application with an already-installed
# DPDK instance, use 'make'
allow_experimental_apis = true
sources = files(
'main.c'
)

View File

@ -14,6 +14,7 @@ APP = mp_client
# all source are stored in SRCS-y
SRCS-y := client.c
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += $(WERROR_FLAGS) -O3
CFLAGS += -I$(SRCDIR)/../shared

View File

@ -220,7 +220,7 @@ main(int argc, char *argv[])
if (parse_app_args(argc, argv) < 0)
rte_exit(EXIT_FAILURE, "Invalid command-line arguments\n");
if (rte_eth_dev_count() == 0)
if (rte_eth_dev_count_avail() == 0)
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
rx_ring = rte_ring_lookup(get_rx_queue_name(client_id));

View File

@ -23,6 +23,7 @@ SRCS-y := main.c init.c args.c
INC := $(sort $(wildcard *.h))
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += $(WERROR_FLAGS) -O3
CFLAGS += -I$(SRCDIR)/../shared

View File

@ -243,7 +243,7 @@ init(int argc, char *argv[])
argv += retval;
/* get total number of ports */
total_ports = rte_eth_dev_count();
total_ports = rte_eth_dev_count_total();
/* set up array for port data */
mz = rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports),

View File

@ -941,7 +941,7 @@ main(int argc, char **argv)
for (i = 0; i < RTE_MAX_LCORE; i++)
lcore_resource[i].lcore_id = i;
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");

View File

@ -418,7 +418,7 @@ main(int argc, char **argv)
argv += ret;
/* determine the NIC devices available */
if (rte_eth_dev_count() == 0)
if (rte_eth_dev_count_avail() == 0)
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
/* parse application arguments (those after the EAL ones) */

View File

@ -27,6 +27,7 @@ VPATH := $(SRCDIR)/../lib
SRCS-y := bridge.c
SRCS-y += compat_netmap.c
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += -O3 -I$(SRCDIR)/../lib -I$(SRCDIR)/../netmap
CFLAGS += $(WERROR_FLAGS)

View File

@ -236,7 +236,7 @@ int main(int argc, char *argv[])
if (ports.num == 0)
rte_exit(EXIT_FAILURE, "no ports specified\n");
if (rte_eth_dev_count() < 1)
if (rte_eth_dev_count_avail() < 1)
rte_exit(EXIT_FAILURE, "Not enough ethernet ports available\n");
pool = rte_pktmbuf_pool_create("mbuf_pool", MBUF_PER_POOL, 32, 0,

View File

@ -430,7 +430,7 @@ rx_thread(struct rte_ring *ring_out)
static int
worker_thread(void *args_ptr)
{
const uint8_t nb_ports = rte_eth_dev_count();
const uint16_t nb_ports = rte_eth_dev_count_avail();
uint16_t i, ret = 0;
uint16_t burst_size = 0;
struct worker_thread_args *args;
@ -644,7 +644,7 @@ main(int argc, char **argv)
"1 lcore for packet TX\n"
"and at least 1 lcore for worker threads\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "Error: no ethernet ports detected\n");
if (nb_ports != 1 && (nb_ports & 1))

View File

@ -3514,7 +3514,7 @@ main(int argc, char **argv)
if (ret < 0)
rte_exit(EXIT_FAILURE, "init_rx_rings failed\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (check_port_config() < 0)
rte_exit(EXIT_FAILURE, "check_port_config failed\n");

View File

@ -727,7 +727,7 @@ main(int argc, char *argv[])
rte_exit(EXIT_FAILURE, "Error with PTP initialization\n");
/* Check that there is an even number of ports to send/receive on. */
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
/* Creates a new mempool in memory to hold the mbufs. */
mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS * nb_ports,

View File

@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk)
LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk)
LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk)
CFLAGS += -DALLOW_EXPERIMENTAL_API
build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@ -55,6 +57,7 @@ all:
clean:
else
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)
CFLAGS_args.o := -D_GNU_SOURCE

View File

@ -298,7 +298,7 @@ int app_init(void)
char ring_name[MAX_NAME_LEN];
char pool_name[MAX_NAME_LEN];
if (rte_eth_dev_count() == 0)
if (rte_eth_dev_count_avail() == 0)
rte_exit(EXIT_FAILURE, "No Ethernet port - bye\n");
/* load configuration profile */

View File

@ -7,6 +7,7 @@
# DPDK instance, use 'make'
deps += ['sched', 'cfgfile']
allow_experimental_apis = true
sources = files(
'app_thread.c', 'args.c', 'cfg_file.c', 'cmdline.c',
'init.c', 'main.c', 'stats.c'

View File

@ -16,6 +16,7 @@ APP = qw
# all source are stored in SRCS-y
SRCS-y := args.c init.c main.c
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += -O3 -DQW_SOFTWARE_FC
CFLAGS += $(WERROR_FLAGS)

View File

@ -112,7 +112,7 @@ void configure_eth_port(uint16_t port_id)
void
init_dpdk(void)
{
if (rte_eth_dev_count() < 2)
if (rte_eth_dev_count_avail() < 2)
rte_exit(EXIT_FAILURE, "Not enough ethernet port available\n");
}

View File

@ -188,7 +188,7 @@ main(int argc, char *argv[])
argc -= ret;
argv += ret;
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports < 2 || (nb_ports & 1))
rte_exit(EXIT_FAILURE, "Error: number of ports must be even\n");

View File

@ -14,6 +14,7 @@ APP = node
# all source are stored in SRCS-y
SRCS-y := node.c
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += $(WERROR_FLAGS) -O3
CFLAGS += -I$(SRCDIR)/../shared

View File

@ -320,7 +320,7 @@ main(int argc, char *argv[])
if (parse_app_args(argc, argv) < 0)
rte_exit(EXIT_FAILURE, "Invalid command-line arguments\n");
if (rte_eth_dev_count() == 0)
if (rte_eth_dev_count_avail() == 0)
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
rx_ring = rte_ring_lookup(get_rx_queue_name(node_id));

View File

@ -23,6 +23,7 @@ SRCS-y := main.c init.c args.c
INC := $(sort $(wildcard *.h))
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += $(WERROR_FLAGS) -O3
CFLAGS += -I$(SRCDIR)/../shared

View File

@ -310,7 +310,7 @@ init(int argc, char *argv[])
argv += retval;
/* get total number of ports */
total_ports = rte_eth_dev_count();
total_ports = rte_eth_dev_count_avail();
/* set up array for port data */
mz = rte_memzone_reserve(MZ_SHARED_INFO, sizeof(*info),

View File

@ -173,7 +173,7 @@ main(int argc, char *argv[])
argv += ret;
/* Check that there is an even number of ports to send/receive on. */
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports < 2 || (nb_ports & 1))
rte_exit(EXIT_FAILURE, "Error: number of ports must be even\n");

View File

@ -10,3 +10,5 @@ allow_experimental_apis = true
sources = files(
'basicfwd.c'
)
allow_experimental_apis = true

View File

@ -1156,7 +1156,7 @@ main(int argc, char *argv[])
nb_switching_cores = rte_lcore_count()-1;
/* Get the number of physical ports. */
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
/*
* Update the global var NB_PORTS and global array PORTS

View File

@ -1448,7 +1448,7 @@ main(int argc, char *argv[])
rte_exit(EXIT_FAILURE,"Not enough cores\n");
/* Get the number of physical ports. */
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
/*
* Update the global var NUM_PORTS and global array PORTS

View File

@ -278,7 +278,7 @@ main(int argc, char **argv)
if (ret < 0)
rte_exit(EXIT_FAILURE, "Invalid arguments\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS * nb_ports,
MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());

View File

@ -580,7 +580,7 @@ main(int argc, char *argv[])
if (rte_lcore_count() > RTE_MAX_LCORE)
rte_exit(EXIT_FAILURE, "Not enough cores\n");
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
/*
* Update the global var NUM_PORTS and global array PORTS

View File

@ -642,7 +642,7 @@ main(int argc, char *argv[])
" number of cores(1-%d)\n\n", RTE_MAX_LCORE);
}
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
/*
* Update the global var NUM_PORTS and global array PORTS

View File

@ -534,6 +534,12 @@ rte_eth_dev_get_sec_ctx(uint16_t port_id)
uint16_t
rte_eth_dev_count(void)
{
return rte_eth_dev_count_avail();
}
uint16_t
rte_eth_dev_count_avail(void)
{
uint16_t p;
uint16_t count;
@ -546,6 +552,18 @@ rte_eth_dev_count(void)
return count;
}
uint16_t
rte_eth_dev_count_total(void)
{
uint16_t port, count = 0;
for (port = 0; port < RTE_MAX_ETHPORTS; port++)
if (rte_eth_devices[port].state != RTE_ETH_DEV_UNUSED)
count++;
return count;
}
int
rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
{
@ -601,7 +619,7 @@ int
rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
{
int ret = -1;
int current = rte_eth_dev_count();
int current = rte_eth_dev_count_total();
char *name = NULL;
char *args = NULL;
@ -619,7 +637,7 @@ rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
goto err;
/* no point looking at the port count if no port exists */
if (!rte_eth_dev_count()) {
if (!rte_eth_dev_count_total()) {
ethdev_log(ERR, "No port found for device (%s)", name);
ret = -1;
goto err;
@ -627,8 +645,9 @@ rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
/* if nothing happened, there is a bug here, since some driver told us
* it did attach a device, but did not create a port.
* FIXME: race condition in case of plug-out of another device
*/
if (current == rte_eth_dev_count()) {
if (current == rte_eth_dev_count_total()) {
ret = -1;
goto err;
}

View File

@ -1385,8 +1385,31 @@ int __rte_experimental rte_eth_dev_owner_get(const uint16_t port_id,
* @return
* - The total number of usable Ethernet devices.
*/
__rte_deprecated
uint16_t rte_eth_dev_count(void);
/**
* Get the number of ports which are usable for the application.
*
* These devices must be iterated by using the macro
* ``RTE_ETH_FOREACH_DEV`` or ``RTE_ETH_FOREACH_DEV_OWNED_BY``
* to deal with non-contiguous ranges of devices.
*
* @return
* The count of available Ethernet devices.
*/
uint16_t __rte_experimental rte_eth_dev_count_avail(void);
/**
* Get the total number of ports which are allocated.
*
* Some devices may not be available for the application.
*
* @return
* The total count of Ethernet devices.
*/
uint16_t __rte_experimental rte_eth_dev_count_total(void);
/**
* Attach a new Ethernet device specified by arguments.
*

View File

@ -206,6 +206,8 @@ DPDK_18.02 {
EXPERIMENTAL {
global:
rte_eth_dev_count_avail;
rte_eth_dev_count_total;
rte_eth_dev_is_removed;
rte_eth_dev_owner_delete;
rte_eth_dev_owner_get;
@ -228,4 +230,4 @@ EXPERIMENTAL {
rte_mtr_stats_read;
rte_mtr_stats_update;
} DPDK_17.11;
} DPDK_18.02;

View File

@ -900,7 +900,8 @@ rte_event_eth_rx_adapter_create_ext(uint8_t id, uint8_t dev_id,
rx_adapter->conf_arg = conf_arg;
strcpy(rx_adapter->mem_name, mem_name);
rx_adapter->eth_devices = rte_zmalloc_socket(rx_adapter->mem_name,
rte_eth_dev_count() *
/* FIXME: incompatible with hotplug */
rte_eth_dev_count_total() *
sizeof(struct eth_device_info), 0,
socket_id);
rte_convert_rss_key((const uint32_t *)default_rss_key,

View File

@ -164,7 +164,7 @@ testsuite_setup(void)
* so rte_eth_dev_start invokes rte_event_dev_start internally, so
* call init_ports after rte_event_dev_configure
*/
err = init_ports(rte_eth_dev_count());
err = init_ports(rte_eth_dev_count_total());
TEST_ASSERT(err == 0, "Port initialization failed err %d\n", err);
err = rte_event_eth_rx_adapter_caps_get(TEST_DEV_ID, TEST_ETHDEV_ID,
@ -273,7 +273,7 @@ adapter_queue_add_del(void)
queue_config.servicing_weight = 1;
err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID,
rte_eth_dev_count(),
rte_eth_dev_count_total(),
-1, &queue_config);
TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);

View File

@ -489,7 +489,7 @@ test_kni(void)
return -1;
}
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports == 0) {
printf("no supported nic port found\n");
return -1;

View File

@ -425,7 +425,7 @@ test_setup(void)
TEST_ASSERT(retval >= 0,
"Failed to create ring ethdev '%s'\n", name);
port->port_id = rte_eth_dev_count() - 1;
port->port_id = rte_eth_dev_count_avail() - 1;
}
retval = configure_ethdev(port->port_id, 1);

View File

@ -521,7 +521,7 @@ test_setup(void)
FOR_EACH_PORT(n, port) {
port = &test_params.slave_ports[n];
port_id = rte_eth_dev_count();
port_id = rte_eth_dev_count_avail();
snprintf(name, sizeof(name), SLAVE_DEV_NAME_FMT, port_id);
retval = rte_vdev_init(name, "size=64,copy=0");

View File

@ -676,7 +676,7 @@ test_pmd_perf(void)
signal(SIGUSR1, signal_handler);
signal(SIGUSR2, signal_handler);
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
if (nb_ports < NB_ETHPORTS_USED) {
printf("At least %u port(s) used for perf. test\n",
NB_ETHPORTS_USED);

View File

@ -399,7 +399,7 @@ test_pmd_ring(void)
int port, cmdl_port0 = -1;
uint8_t nb_ports;
nb_ports = rte_eth_dev_count();
nb_ports = rte_eth_dev_count_avail();
printf("nb_ports=%d\n", (int)nb_ports);
/* create the rings and eth_rings in the test code.