app/testpmd: fix mempool creation by socket id
authorShahaf Shuler <shahafs@mellanox.com>
Tue, 9 May 2017 07:28:37 +0000 (10:28 +0300)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 10 May 2017 16:39:50 +0000 (18:39 +0200)
The test assumes the socket ids are contiguous. This
is not necessarily the case on all servers and may cause
mempool creation to fail.

Fixing it by detecting the list of valid socket ids and
use it for the mempool creation.

Fixes: 7acf894d07d1 ("app/testpmd: detect numa socket count")
Cc: stable@dpdk.org
Signed-off-by: Shahaf Shuler <shahafs@mellanox.com>
Acked-by: Jingjing Wu <jingjing.wu@intel.com>
app/test-pmd/parameters.c
app/test-pmd/testpmd.c
app/test-pmd/testpmd.h

index 23f2fa3..a480d8f 100644 (file)
@@ -369,6 +369,18 @@ parse_queue_stats_mapping_config(const char *q_arg, int is_rx)
        return 0;
 }
 
+static void
+print_invalid_socket_id_error(void)
+{
+       unsigned int i = 0;
+
+       printf("Invalid socket id, options are: ");
+       for (i = 0; i < num_sockets; i++) {
+               printf("%u%s", socket_ids[i],
+                     (i == num_sockets - 1) ? "\n" : ",");
+       }
+}
+
 static int
 parse_portnuma_config(const char *q_arg)
 {
@@ -414,9 +426,8 @@ parse_portnuma_config(const char *q_arg)
                        return -1;
                }
                socket_id = (uint8_t)int_fld[FLD_SOCKET];
-               if(socket_id >= max_socket) {
-                       printf("Invalid socket id, range is [0, %d]\n",
-                                max_socket - 1);
+               if (new_socket_id(socket_id)) {
+                       print_invalid_socket_id_error();
                        return -1;
                }
                port_numa[port_id] = socket_id;
@@ -474,9 +485,8 @@ parse_ringnuma_config(const char *q_arg)
                        return -1;
                }
                socket_id = (uint8_t)int_fld[FLD_SOCKET];
-               if (socket_id >= max_socket) {
-                       printf("Invalid socket id, range is [0, %d]\n",
-                               max_socket - 1);
+               if (new_socket_id(socket_id)) {
+                       print_invalid_socket_id_error();
                        return -1;
                }
                ring_flag = (uint8_t)int_fld[FLD_FLAG];
@@ -732,12 +742,13 @@ launch_args_parse(int argc, char** argv)
                                           "invalid ring-numa configuration\n");
                        if (!strcmp(lgopts[opt_idx].name, "socket-num")) {
                                n = atoi(optarg);
-                               if((uint8_t)n < max_socket)
+                               if (!new_socket_id((uint8_t)n)) {
                                        socket_num = (uint8_t)n;
-                               else
+                               } else {
+                                       print_invalid_socket_id_error();
                                        rte_exit(EXIT_FAILURE,
-                                               "The socket number should be < %d\n",
-                                               max_socket);
+                                               "Invalid socket id");
+                               }
                        }
                        if (!strcmp(lgopts[opt_idx].name, "mbuf-size")) {
                                n = atoi(optarg);
index cec1cb9..d1041af 100644 (file)
@@ -365,7 +365,8 @@ struct queue_stats_mappings *rx_queue_stats_mappings = rx_queue_stats_mappings_a
 uint16_t nb_tx_queue_stats_mappings = 0;
 uint16_t nb_rx_queue_stats_mappings = 0;
 
-unsigned max_socket = 0;
+unsigned int num_sockets = 0;
+unsigned int socket_ids[RTE_MAX_NUMA_NODES];
 
 #ifdef RTE_LIBRTE_BITRATE
 /* Bitrate statistics */
@@ -387,6 +388,22 @@ static void eth_event_callback(uint8_t port_id,
  */
 static int all_ports_started(void);
 
+/*
+ * Helper function to check if socket is allready discovered.
+ * If yes, return positive value. If not, return zero.
+ */
+int
+new_socket_id(unsigned int socket_id)
+{
+       unsigned int i;
+
+       for (i = 0; i < num_sockets; i++) {
+               if (socket_ids[i] == socket_id)
+                       return 0;
+       }
+       return 1;
+}
+
 /*
  * Setup default configuration.
  */
@@ -399,11 +416,14 @@ set_default_fwd_lcores_config(void)
 
        nb_lc = 0;
        for (i = 0; i < RTE_MAX_LCORE; i++) {
-               sock_num = rte_lcore_to_socket_id(i) + 1;
-               if (sock_num > max_socket) {
-                       if (sock_num > RTE_MAX_NUMA_NODES)
-                               rte_exit(EXIT_FAILURE, "Total sockets greater than %u\n", RTE_MAX_NUMA_NODES);
-                       max_socket = sock_num;
+               sock_num = rte_lcore_to_socket_id(i);
+               if (new_socket_id(sock_num)) {
+                       if (num_sockets >= RTE_MAX_NUMA_NODES) {
+                               rte_exit(EXIT_FAILURE,
+                                        "Total sockets greater than %u\n",
+                                        RTE_MAX_NUMA_NODES);
+                       }
+                       socket_ids[num_sockets++] = sock_num;
                }
                if (!rte_lcore_is_enabled(i))
                        continue;
@@ -517,7 +537,7 @@ check_socket_id(const unsigned int socket_id)
 {
        static int warning_once = 0;
 
-       if (socket_id >= max_socket) {
+       if (new_socket_id(socket_id)) {
                if (!warning_once && numa_support)
                        printf("Warning: NUMA should be configured manually by"
                               " using --port-numa-config and"
@@ -609,8 +629,9 @@ init_config(void)
        if (numa_support) {
                uint8_t i;
 
-               for (i = 0; i < max_socket; i++)
-                       mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool, i);
+               for (i = 0; i < num_sockets; i++)
+                       mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool,
+                                        socket_ids[i]);
        } else {
                if (socket_num == UMA_NO_CONFIG)
                        mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool, 0);
index 3c6a59a..e6c43ba 100644 (file)
@@ -343,7 +343,8 @@ extern lcoreid_t nb_lcores; /**< Number of logical cores probed at init time. */
 extern lcoreid_t nb_cfg_lcores; /**< Number of configured logical cores. */
 extern lcoreid_t nb_fwd_lcores; /**< Number of forwarding logical cores. */
 extern unsigned int fwd_lcores_cpuids[RTE_MAX_LCORE];
-extern unsigned max_socket;
+extern unsigned int num_sockets;
+extern unsigned int socket_ids[RTE_MAX_NUMA_NODES];
 
 /*
  * Configuration of Ethernet ports:
@@ -638,6 +639,7 @@ enum print_warning {
        DISABLED_WARN
 };
 int port_id_is_invalid(portid_t port_id, enum print_warning warning);
+int new_socket_id(unsigned int socket_id);
 
 /*
  * Work-around of a compilation error with ICC on invocations of the