From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-we0-f179.google.com (mail-we0-f179.google.com [74.125.82.179]) by dpdk.org (Postfix) with ESMTP id 73401AFD5 for ; Tue, 15 Apr 2014 15:51:45 +0200 (CEST) Received: by mail-we0-f179.google.com with SMTP id x48so9280922wes.24 for ; Tue, 15 Apr 2014 06:51:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=9+8FbEbppuzht3godzr42G496orXt3K+K1XdqQfWvr4=; b=K+kVZ+sdLi7SvZ6yAn6+eY8FDp3nWj5hYvI/tZ8SePxVPdWpeqZVLAEtEaeM0AnslB wnDVlnqi9SdBsn4HTYfLAt8tiA+bP7zntK3lRz9GhD/fjMAEoSURAIx4Y+4dGW0ilPkK AJBVJ/4Plv67ThuOMEZw/konNmHB74jlM38b+Rxp+tuf/z9RGEZv1oTiY1vDVciLA9Sb yTmHE+ON2cFlD/PF9lP9/J5m41eE4I2aZ10jYGERBqE74/G5t+A6FJz09wmJx60Oy4dv Ax56y2+rFijRJaKoIM1oZT9zhbhHNMCIPkLtE896dqIko21c67GSbRxpoWemHsO8KLAE HaUw== X-Gm-Message-State: ALoCoQk+brZu5JdQR02L5esrZzK2O1v/4PTsutwwIw8qGepSR+cm7fbOmNS6X44mfjEu0Mj2W+bw X-Received: by 10.194.84.101 with SMTP id x5mr1812901wjy.52.1397569905848; Tue, 15 Apr 2014 06:51:45 -0700 (PDT) Received: from alcyon.dev.6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id lh6sm29825743wjb.27.2014.04.15.06.51.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Apr 2014 06:51:45 -0700 (PDT) From: David Marchand To: dev@dpdk.org Date: Tue, 15 Apr 2014 15:51:39 +0200 Message-Id: <1397569899-18315-1-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.7.10.4 Cc: Liu Xiaofeng Subject: [dpdk-dev] [PATCH] app/testpmd: check socket id validity X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Apr 2014 13:51:45 -0000 From: Liu Xiaofeng Now socket id is from device's numa_node, if it is invalid, just set it to 0 as default to avoid crash which will be caused by the reference to port_per_socket[socket_id]. Also one warning is displayed to user that port-numa-config and ring-numa-config parameters should be used along with --numa for NUMA mode. A check for NUMA_NO_CONFIG was also missing from init_fwd_stream(). Signed-off-by: Liu Xiaofeng --- app/test-pmd/config.c | 6 ++---- app/test-pmd/testpmd.c | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 0816227..1feb133 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -244,7 +244,6 @@ port_infos_display(portid_t port_id) struct rte_port *port; struct rte_eth_link link; int vlan_offload; - int socket_id; struct rte_mempool * mp; static const char *info_border = "*********************"; @@ -254,11 +253,10 @@ port_infos_display(portid_t port_id) } port = &ports[port_id]; rte_eth_link_get_nowait(port_id, &link); - socket_id = rte_eth_dev_socket_id(port_id); printf("\n%s Infos for port %-2d %s\n", info_border, port_id, info_border); print_ethaddr("MAC address: ", &port->eth_addr); - printf("\nConnect to socket: %d",socket_id); + printf("\nConnect to socket: %d", port->socket_id); if (port_numa[port_id] != NUMA_NO_CONFIG) { mp = mbuf_pool_find(port_numa[port_id]); @@ -266,7 +264,7 @@ port_infos_display(portid_t port_id) printf("\nmemory allocation on the socket: %d", port_numa[port_id]); } else - printf("\nmemory allocation on the socket: %d",socket_id); + printf("\nmemory allocation on the socket: %d",port->socket_id); printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down")); printf("Link speed: %u Mbps\n", (unsigned) link.link_speed); diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 04dca57..97229a5 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -475,6 +475,27 @@ mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf, } } +/* + * Check given socket id is valid or not with NUMA mode, + * if valid, return 0, else return -1 + */ +static int +check_socket_id(const unsigned int socket_id) +{ + static int warning_once = 0; + + if (socket_id >= MAX_SOCKET) { + if (!warning_once && numa_support) + printf("Warning: NUMA should be configured manually by" + " using --port-numa-config and" + " --ring-numa-config parameters along with" + " --numa.\n"); + warning_once = 1; + return -1; + } + return 0; +} + static void init_config(void) { @@ -559,6 +580,10 @@ init_config(void) port_per_socket[port_numa[pid]]++; else { uint32_t socket_id = rte_eth_dev_socket_id(pid); + + /* if socket_id is invalid, set to 0 */ + if (check_socket_id(socket_id) < 0) + socket_id = 0; port_per_socket[socket_id]++; } } @@ -611,8 +636,17 @@ init_fwd_streams(void) port->dev_info.max_tx_queues); return -1; } - if (numa_support) - port->socket_id = rte_eth_dev_socket_id(pid); + if (numa_support) { + if (port_numa[pid] != NUMA_NO_CONFIG) + port->socket_id = port_numa[pid]; + else { + port->socket_id = rte_eth_dev_socket_id(pid); + + /* if socket_id is invalid, set to 0 */ + if (check_socket_id(port->socket_id) < 0) + port->socket_id = 0; + } + } else { if (socket_num == UMA_NO_CONFIG) port->socket_id = 0; @@ -1215,7 +1249,7 @@ start_port(portid_t pid) port->need_reconfig = 0; printf("Configuring Port %d (socket %d)\n", pi, - rte_eth_dev_socket_id(pi)); + port->socket_id); /* configure port */ diag = rte_eth_dev_configure(pi, nb_rxq, nb_txq, &(port->dev_conf)); -- 1.7.10.4