From patchwork Wed Oct 2 20:26:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1170902 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OuSWjOKT"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46k73j0N80z9sPJ for ; Thu, 3 Oct 2019 06:27:28 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C711C15E1; Wed, 2 Oct 2019 20:27:24 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id B8FC615AD for ; Wed, 2 Oct 2019 20:27:23 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 447BA5D0 for ; Wed, 2 Oct 2019 20:27:23 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id d26so229667pgl.7 for ; Wed, 02 Oct 2019 13:27:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Rj4jP4pP8BkdCzimKEicI44H5HGnc0SIkD939RU5Y7g=; b=OuSWjOKTBqA9UtVmmJsjvlQbaFsbPqbptNeaFY0nQ0ReLohJ/I0SVImypjJVIyVwtn Y7OF/fUvZFGv1SVKi8mPejFvmpIGsYdx4UjXYFxHkUWnD0mdp9GrewNntp2/zMi6zaBi 31NkoE1j7ElvztJW5B1VLXhaGWBFYI1kTrsbTZdnfT04IeX1bQPoa9Ilp1e3uuQ2cDH1 YnuY8rXzkr2dd3W64tecgnLDnFkCyZb0rDJoFNAMpGK/CD/4rhU8E9EHv3vbWnKnpw64 xrM5Ikk75ZMftSeOgYJI1Jo3TS8/RXgC+oRxzpbA1DXorrRfjOJluMAxeyHIT2JRpkCp l7fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Rj4jP4pP8BkdCzimKEicI44H5HGnc0SIkD939RU5Y7g=; b=J3ThGyinEQdmoNIkEbTnhRVnNg8nt2mHsNgnZ7FyDj5STomdSopUgj3VhLhIOy7UW4 20FlPOgrS3Ph861bPpuPDcigCdEpS8n+SA2eV4OBrIWo5c67Y2F4YqlH+aa++ywJ1uG0 njgvhehV7cfz2NOnup8Kr+2oBn2UloBSRDYy0k4JbPZxS0kF+SC3OFTDsUPyhY+i4FSR M1VsOd0iPElzwHmkzD72gAIeluHi1HXczPUPak3KER2sqSsYphm6M8MI5WNrmRejlIdo iTHbphZto5MIVwsl4abOhWNaEWu+rZbVbdCPimRgXcleDBcutLMW/Ic5XlCaN3XS/bD0 5v9Q== X-Gm-Message-State: APjAAAXvMByg+oudmf2ETBTAEdoKZeSY/apTy9/8Bn92jIECVc/MwtKe okZOeEd/Pp/+34D+Sw7gDgnyklE5/bk= X-Google-Smtp-Source: APXvYqyplCIo4WeoO5iWIRXD6rtSQd7PEHypXbd65ACp7ZhfI1zvYaq+pFsMkvFnacgYuD+13Ctijg== X-Received: by 2002:a17:90a:fe0b:: with SMTP id ck11mr6489525pjb.87.1570048042186; Wed, 02 Oct 2019 13:27:22 -0700 (PDT) Received: from sc9-mailhost3.vmware.com ([66.170.99.95]) by smtp.gmail.com with ESMTPSA id v32sm229787pga.38.2019.10.02.13.27.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Oct 2019 13:27:21 -0700 (PDT) From: William Tu To: dev@openvswitch.org Date: Wed, 2 Oct 2019 13:26:57 -0700 Message-Id: <1570048017-94384-1-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCHv3] netdev-linux: Detect numa node id. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The patch detects the numa node id from the name of the netdev, by reading the '/sys/class/net//device/numa_node'. If not available, ex: virtual device, or any error happens, return numa id 0. Currently only the afxdp netdev type uses it, other linux netdev types are disabled due to no use case. Tested-at: https://travis-ci.org/williamtu/ovs-travis/builds/592728452 Signed-off-by: William Tu --- v3: Feedbacks from Ilya and Eelco - update doc, afxdp.rst - fix coding style - fix limit of numa node max, by using ovs_numa_numa_id_is_valid - move the function to netdev-linux - cache the result of numa_id - add security check for netdev name - use fscanf instead of read and convert to int - revise some error message content v2: address feedback from Eelco fix memory leak of xaspintf log using INFO instead of WARN --- Documentation/intro/install/afxdp.rst | 1 - lib/netdev-afxdp.c | 11 ------- lib/netdev-linux-private.h | 2 ++ lib/netdev-linux.c | 57 ++++++++++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 13 deletions(-) diff --git a/Documentation/intro/install/afxdp.rst b/Documentation/intro/install/afxdp.rst index 820e9d993d8f..6c00c4ad1356 100644 --- a/Documentation/intro/install/afxdp.rst +++ b/Documentation/intro/install/afxdp.rst @@ -309,7 +309,6 @@ Below is a script using namespaces and veth peer:: Limitations/Known Issues ------------------------ -#. Device's numa ID is always 0, need a way to find numa id from a netdev. #. No QoS support because AF_XDP netdev by-pass the Linux TC layer. A possible work-around is to use OpenFlow meter action. #. Most of the tests are done using i40e single port. Multiple ports and diff --git a/lib/netdev-afxdp.c b/lib/netdev-afxdp.c index 6e01803272aa..95bf6dcd5b2b 100644 --- a/lib/netdev-afxdp.c +++ b/lib/netdev-afxdp.c @@ -549,17 +549,6 @@ out: return err; } -int -netdev_afxdp_get_numa_id(const struct netdev *netdev) -{ - /* FIXME: Get netdev's PCIe device ID, then find - * its NUMA node id. - */ - VLOG_INFO("FIXME: Device %s always use numa id 0.", - netdev_get_name(netdev)); - return 0; -} - static void xsk_remove_xdp_program(uint32_t ifindex, int xdpmode) { diff --git a/lib/netdev-linux-private.h b/lib/netdev-linux-private.h index a350be151147..c8f2be47b10b 100644 --- a/lib/netdev-linux-private.h +++ b/lib/netdev-linux-private.h @@ -96,6 +96,8 @@ struct netdev_linux { /* LAG information. */ bool is_lag_master; /* True if the netdev is a LAG master. */ + int numa_id; /* NUMA node id. */ + #ifdef HAVE_AF_XDP /* AF_XDP information. */ struct xsk_socket_info **xsks; diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index f4819237370a..bdf077ed5dd0 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -236,6 +236,7 @@ enum { VALID_VPORT_STAT_ERROR = 1 << 5, VALID_DRVINFO = 1 << 6, VALID_FEATURES = 1 << 7, + VALID_NUMA_ID = 1 << 8, }; struct linux_lag_slave { @@ -1391,6 +1392,60 @@ netdev_linux_tap_batch_send(struct netdev *netdev_, return 0; } +static int OVS_UNUSED +netdev_linux_get_numa_id(const struct netdev *netdev_) +{ + struct netdev_linux *netdev = netdev_linux_cast(netdev_); + char *numa_node_path; + const char *name; + int node_id; + FILE *stream; + + if (netdev->cache_valid & VALID_NUMA_ID) { + return netdev->numa_id; + } + + name = netdev_get_name(netdev_); + if (strchr(name, '/') || strchr(name, '\\')) { + VLOG_ERR_RL(&rl, "\"%s\" is not a valid name for a port. " + "A valid name must not include '/' or '\\'." + "Using numa_id 0", name); + return 0; + } + + numa_node_path = xasprintf("/sys/class/net/%s/device/numa_node", name); + + stream = fopen(numa_node_path, "r"); + if (!stream) { + /* Virtual device does not have this info. */ + VLOG_INFO_RL(&rl, "%s: Can't open '%s': %s, using numa_id 0", + name, numa_node_path, ovs_strerror(errno)); + free(numa_node_path); + netdev->cache_valid |= VALID_NUMA_ID; + return 0; + } + + if (fscanf(stream, "%d", &node_id) != 1) { + goto error; + }; + + if (!ovs_numa_numa_id_is_valid(node_id)) { + goto error; + } + + netdev->numa_id = node_id; + netdev->cache_valid |= VALID_NUMA_ID; + fclose(stream); + free(numa_node_path); + return node_id; + +error: + VLOG_WARN_RL(&rl, "%s: Can't detect NUMA node, using numa_id 0", name); + free(numa_node_path); + fclose(stream); + return 0; +} + /* Sends 'batch' on 'netdev'. Returns 0 if successful, otherwise a positive * errno value. Returns EAGAIN without blocking if the packet cannot be queued * immediately. Returns EMSGSIZE if a partial packet was transmitted or if @@ -3298,7 +3353,7 @@ const struct netdev_class netdev_afxdp_class = { .set_config = netdev_afxdp_set_config, .get_config = netdev_afxdp_get_config, .reconfigure = netdev_afxdp_reconfigure, - .get_numa_id = netdev_afxdp_get_numa_id, + .get_numa_id = netdev_linux_get_numa_id, .send = netdev_afxdp_batch_send, .rxq_construct = netdev_afxdp_rxq_construct, .rxq_destruct = netdev_afxdp_rxq_destruct,