From patchwork Fri Sep 13 17:15:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1162176 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="I7t1V4Ex"; 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 46VMk06msBz9s4Y for ; Sat, 14 Sep 2019 03:16:24 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id AEFA0D9B; Fri, 13 Sep 2019 17:16:21 +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 A1D8ED9A for ; Fri, 13 Sep 2019 17:16:20 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2D3E27D2 for ; Fri, 13 Sep 2019 17:16:20 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id x2so3552991wmj.2 for ; Fri, 13 Sep 2019 10:16:20 -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=biY7UIQ8L8THypGZTbK4DUtkADyjyuKPyXknZ3Bo7Nk=; b=I7t1V4ExJuF/kvWNANxQQPV2n2YVCZJt6DUaKBABc+C8fcPgGcTyOlQqK7rATYNpmY y1MvhISA/OLTrrijGwr0C1Y+X+1N4npV2ARKswCMc/oFi1GgqtVzoSr7krOdNhhySqQI 5C0mr1DzNRpeRb4k5FF1fcX8MbADcEQQDXlrNFVYoMz7hkuO2raGlqoUd+JTp+JaJtRj 6K4fOHhpXaGgxWP+0g7rJd+Sc/fIXdLP9FIpTCE2uE34M49O0Mako3KmOoNam1u0NJF9 bSDgU+GIhfof18dA5sQNEFpb4UWPGvQjYWAK+62hLCQmGLKpF4bUu1Vi4QRdeEsu9+cp Jrhg== 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=biY7UIQ8L8THypGZTbK4DUtkADyjyuKPyXknZ3Bo7Nk=; b=NDuVYoFB6Ydc5PHPfNNtWU1B22UdwAxgw0NjOp1zfvNVySz4r6LyoNN5sLcPJW+ueK Gb6zkX6qOQOMSmaRAnLfIBotboVM5040Mc327oPjLRJUdYvJcaVM2Ad/Wl1LK2PRyPj7 RTSI7ahRhdALw/0kJRcp37aRFqmQ/DuZk1+xgOzluHDR2SL/OVXrkMMceINjwkJpp0Se u0m0ThpaR+1Klzo6qszhtmv6NWd0GKGED8qLZ0ILjYxTslNbJJaQJlbiLBa9sDC7tY5H wE6EOA+py40EBzpB4CZlt1T3u8/IXxa1/1Vdw9vFJ/o3dH/mr/v9fpY5PRhKcLzkn6cS r9Ng== X-Gm-Message-State: APjAAAVJfJTdbLHtnLp95hO3e28mKvw7wbT7/Z6YM53wv8rmdU09SKR7 aMA5mOVU5CqegCl5YgsuSvtOR6+1QzM= X-Google-Smtp-Source: APXvYqzP5uDEXIGyyvBQOD5wBNIrn2ji6rLbj7wpZiK3ibEXriqzUcu2wnuA6L5Y3NUZUOvW4ECe+w== X-Received: by 2002:a1c:cf8c:: with SMTP id f134mr4462676wmg.174.1568394978395; Fri, 13 Sep 2019 10:16:18 -0700 (PDT) Received: from sc9-mailhost2.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id h8sm1706563wmc.5.2019.09.13.10.16.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Sep 2019 10:16:17 -0700 (PDT) From: William Tu To: dev@openvswitch.org Date: Fri, 13 Sep 2019 10:15:31 -0700 Message-Id: <1568394931-82238-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@samsung.com Subject: [ovs-dev] [PATCH] netdev-afxdp: 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. Signed-off-by: William Tu --- lib/netdev-afxdp.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/netdev-afxdp.c b/lib/netdev-afxdp.c index e5b058d08a09..a94d77468cb7 100644 --- a/lib/netdev-afxdp.c +++ b/lib/netdev-afxdp.c @@ -552,11 +552,39 @@ out: 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)); + const char *numa_node_path; + long int node_id; + char buffer[4]; + FILE *stream; + int n; + + numa_node_path = xasprintf("/sys/class/net/%s/device/numa_node", + netdev_get_name(netdev)); + stream = fopen(numa_node_path, "r"); + if (!stream) { + /* Virtual device does not have this info. */ + VLOG_WARN_RL(&rl, "Open %s failed: %s, use numa_id 0", + numa_node_path, ovs_strerror(errno)); + return 0; + } + + n = fread(buffer, 1, sizeof buffer, stream); + if (!n) { + goto error; + } + + node_id = strtol(buffer, NULL, 10); + if (node_id < 0 || node_id > 2) { + goto error; + } + + fclose(stream); + return (int)node_id; + +error: + VLOG_WARN_RL(&rl, "Error detecting numa node of %s, use numa_id 0", + numa_node_path); + fclose(stream); return 0; }