ethdev: deprecate port count function
authorThomas Monjalon <thomas@monjalon.net>
Thu, 5 Apr 2018 15:33:22 +0000 (17:33 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 17 Apr 2018 22:48:41 +0000 (00:48 +0200)
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>
76 files changed:
app/proc-info/main.c
app/test-eventdev/evt_options.h
app/test-eventdev/test_perf_atq.c
app/test-eventdev/test_perf_common.c
app/test-eventdev/test_perf_queue.c
app/test-eventdev/test_pipeline_atq.c
app/test-eventdev/test_pipeline_common.c
app/test-eventdev/test_pipeline_queue.c
app/test-pmd/cmdline.c
app/test-pmd/testpmd.c
doc/guides/rel_notes/release_18_05.rst
doc/guides/sample_app_ug/quota_watermark.rst
examples/bond/main.c
examples/distributor/main.c
examples/ethtool/ethtool-app/main.c
examples/eventdev_pipeline/main.c
examples/eventdev_pipeline/pipeline_worker_tx.c
examples/exception_path/main.c
examples/flow_classify/flow_classify.c
examples/flow_filtering/Makefile
examples/flow_filtering/main.c
examples/flow_filtering/meson.build
examples/ip_fragmentation/main.c
examples/ip_reassembly/main.c
examples/ipv4_multicast/main.c
examples/kni/main.c
examples/l2fwd-cat/l2fwd-cat.c
examples/l2fwd-crypto/main.c
examples/l2fwd-jobstats/main.c
examples/l2fwd-keepalive/main.c
examples/l2fwd/main.c
examples/l3fwd-acl/main.c
examples/l3fwd-power/main.c
examples/l3fwd-vf/main.c
examples/l3fwd/main.c
examples/link_status_interrupt/Makefile
examples/link_status_interrupt/main.c
examples/link_status_interrupt/meson.build
examples/multi_process/client_server_mp/mp_client/Makefile
examples/multi_process/client_server_mp/mp_client/client.c
examples/multi_process/client_server_mp/mp_server/Makefile
examples/multi_process/client_server_mp/mp_server/init.c
examples/multi_process/l2fwd_fork/main.c
examples/multi_process/symmetric_mp/main.c
examples/netmap_compat/bridge/Makefile
examples/netmap_compat/bridge/bridge.c
examples/packet_ordering/main.c
examples/performance-thread/l3fwd-thread/main.c
examples/ptpclient/ptpclient.c
examples/qos_sched/Makefile
examples/qos_sched/init.c
examples/qos_sched/meson.build
examples/quota_watermark/qw/Makefile
examples/quota_watermark/qw/init.c
examples/rxtx_callbacks/main.c
examples/server_node_efd/node/Makefile
examples/server_node_efd/node/node.c
examples/server_node_efd/server/Makefile
examples/server_node_efd/server/init.c
examples/skeleton/basicfwd.c
examples/skeleton/meson.build
examples/tep_termination/main.c
examples/vhost/main.c
examples/vm_power_manager/main.c
examples/vmdq/main.c
examples/vmdq_dcb/main.c
lib/librte_ether/rte_ethdev.c
lib/librte_ether/rte_ethdev.h
lib/librte_ether/rte_ethdev_version.map
lib/librte_eventdev/rte_event_eth_rx_adapter.c
test/test/test_event_eth_rx_adapter.c
test/test/test_kni.c
test/test/test_link_bonding_mode4.c
test/test/test_link_bonding_rssconf.c
test/test/test_pmd_perf.c
test/test/test_pmd_ring.c

index 115df9d..539e132 100644 (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");
 
index 1bc7ea0..f3de48a 100644 (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)
index b3a3127..9715a2c 100644 (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
index d1bd5e9..d00f918 100644 (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;
        }
index 74469a5..04ce941 100644 (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;
 }
 
index dd71897..26dc79f 100644 (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) {
index b4dbe37..719518f 100644 (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 */
index 02fc27c..ca5f457 100644 (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);
 
index b10650b..d584f95 100644 (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);
        }
index 7f7560d..d6da419 100644 (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");
 
index 149e73b..2d6f9d8 100644 (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``.
 
index 8baec4d..67200e1 100644 (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");
     }
 
index d4097d0..d8edc64 100644 (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)
index 2e6b09d..2c59364 100644 (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))
index 702feab..c1815bb 100644 (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");
index 48358a7..b698e4c 100644 (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");
 
index fc98128..3dbde92 100644 (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 = {
index 996f493..2b381a5 100644 (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 */
index d0e537e..3b087ce 100644 (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");
 
index 01bb4cd..f41b368 100644 (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)
 
index 0bb81a8..db03c9c 100644 (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;
index 407795c..9494933 100644 (file)
@@ -9,3 +9,4 @@
 sources = files(
        'main.c',
 )
+allow_experimental_apis = true
index f525c3a..8952ea4 100644 (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");
 
index ddff358..3e8e79c 100644 (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");
 
index 23b266b..ad2072f 100644 (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)
index 901480a..4b162de 100644 (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");
 
index ed48780..0e6078a 100644 (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");
 
index b1ad192..4220448 100644 (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");
index 2482248..34553fa 100644 (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");
 
index e9ad91a..a18b707 100644 (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");
 
index f8ca29c..6908435 100644 (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");
 
index 2c891b4..33ad467 100644 (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");
index d6a0926..596d645 100644 (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");
index dd0e057..aaafb7b 100644 (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");
index ec1da5c..bf7dbd8 100644 (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");
index 1606821..d778fcb 100644 (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)
 
index ad0dd39..f568956 100644 (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");
 
index c34e11e..2b0a250 100644 (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'
 )
index 298e1b0..3bfcd75 100644 (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
 
index 92955e9..c23dd3f 100644 (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));
index 3e244e2..af7246e 100644 (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
 
index 1c465cc..30c8e44 100644 (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),
index 6b130f2..94318ab 100644 (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");
 
index 75cad0c..16f21a1 100644 (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) */
index a7c9c14..071c09d 100644 (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)
 
index 59c5e43..cb1882e 100644 (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,
index 676cb6f..7ace7d1 100644 (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))
index 699b99d..f51e6b0 100644 (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");
index 55be3f7..c44013b 100644 (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,
index 0f0a31f..e6dfbef 100644 (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
index 8914f76..c9e4879 100644 (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 */
index 289b81c..5101652 100644 (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'
index 84299e5..d0a9b3c 100644 (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)
 
index d4a6918..00725bc 100644 (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");
 }
 
index 84b09cf..e63ea28 100644 (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");
 
index fffbe35..dc3191a 100644 (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
 
index 84f7bcf..3b97fbd 100644 (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));
index cbb91eb..d5456f9 100644 (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
 
index 07b6882..7dfe2fa 100644 (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),
index 5ac1dc8..03bc358 100644 (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");
 
index ef46b18..89ddba2 100644 (file)
@@ -10,3 +10,5 @@ allow_experimental_apis = true
 sources = files(
        'basicfwd.c'
 )
+
+allow_experimental_apis = true
index e868541..8543a98 100644 (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
index 7cddac7..84e0d63 100644 (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
index db0ddb0..c9805a4 100644 (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());
index 2f3eb74..52596dd 100644 (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
index 9c68ab0..2626a2f 100644 (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
index 3c049ef..7821a88 100644 (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;
        }
index 4f417f5..7e4e57b 100644 (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.
  *
index 34df6c8..8fe0788 100644 (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;
index bf5b44f..aec2703 100644 (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,
index 2234df0..ab55398 100644 (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);
 
index 3d1be56..56773c8 100644 (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;
index 426877a..33c1fab 100644 (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);
index 4cc08f5..6a1a28d 100644 (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");
index 0e64a58..54bc4f6 100644 (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);
index 0787e4e..2196201 100644 (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.