examples/vm_power: add check for port count

If we don't pass any ports to the app, we don't need to create
any mempools, and we don't need to init any ports.

Signed-off-by: David Hunt <david.hunt@intel.com>
Acked-by: Radu Nicolau <radu.nicolau@intel.com>
This commit is contained in:
David Hunt 2018-07-13 15:22:54 +01:00 committed by Thomas Monjalon
parent 6793a1f771
commit ace158c4a8

View File

@ -278,8 +278,10 @@ main(int argc, char **argv)
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());
if (nb_ports > 0) {
mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL",
NUM_MBUFS * nb_ports, MBUF_CACHE_SIZE, 0,
RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
if (mbuf_pool == NULL)
rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
@ -300,7 +302,8 @@ main(int argc, char **argv)
eth.addr_bytes[4] = portid + 0xf0;
if (port_init(portid, mbuf_pool) != 0)
rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 "\n",
rte_exit(EXIT_FAILURE,
"Cannot init port %"PRIu8 "\n",
portid);
for (w = 0; w < MAX_VFS; w++) {
@ -309,20 +312,22 @@ main(int argc, char **argv)
ret = rte_pmd_ixgbe_set_vf_mac_addr(portid,
w, &eth);
if (ret == -ENOTSUP)
ret = rte_pmd_i40e_set_vf_mac_addr(portid,
w, &eth);
ret = rte_pmd_i40e_set_vf_mac_addr(
portid, w, &eth);
if (ret == -ENOTSUP)
ret = rte_pmd_bnxt_set_vf_mac_addr(portid,
w, &eth);
ret = rte_pmd_bnxt_set_vf_mac_addr(
portid, w, &eth);
switch (ret) {
case 0:
printf("Port %d VF %d MAC: ",
portid, w);
for (j = 0; j < 6; j++) {
printf("%02x", eth.addr_bytes[j]);
if (j < 5)
printf(":");
for (j = 0; j < 5; j++) {
printf("%02x:",
eth.addr_bytes[j]);
}
printf("%02x\n", eth.addr_bytes[5]);
break;
}
printf("\n");
break;