DPDK patches and discussions
 help / color / mirror / Atom feed
From: Kevin Laatz <kevin.laatz@intel.com>
To: dev@dpdk.org
Cc: bruce.richardson@intel.com, Kevin Laatz <kevin.laatz@intel.com>
Subject: [dpdk-dev] [PATCH v2 1/2] raw/ioat: add pci address handling to python script
Date: Fri, 28 May 2021 14:19:01 +0100	[thread overview]
Message-ID: <20210528131902.344423-2-kevin.laatz@intel.com> (raw)
In-Reply-To: <20210528131902.344423-1-kevin.laatz@intel.com>

Currently the user needs to find the DSA instance number for any DSA device
they would like to configure using this script, which can be cumbersome and
error-prone since the instance numbering changes when changing the binding
of the devices between vfio-pci and idxd.

This patch improved the usability of the script by adding the ability to
specify the DSA device to configure using the device's PCI address instead
of the DSA instance number. For example, "$dpdk_idxd_cfg.py 0" and
"$dpdk_idxd_cfg.py 6a:01.0" are both valid references to the same device
(assuming the numbering).

Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>

---
v2:
   - split the device reset change into its own patch
   - changed sysfs dir search
   - improved error case handling
---
 drivers/raw/ioat/dpdk_idxd_cfg.py | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/drivers/raw/ioat/dpdk_idxd_cfg.py b/drivers/raw/ioat/dpdk_idxd_cfg.py
index ff06d9e240..ad8393a645 100755
--- a/drivers/raw/ioat/dpdk_idxd_cfg.py
+++ b/drivers/raw/ioat/dpdk_idxd_cfg.py
@@ -29,6 +29,26 @@ def write_values(self, values):
                 f.write(str(contents))
 
 
+def get_pci_dir(pci):
+    "Search for the sysfs directory of the PCI device"
+    base_dir = '/sys/bus/pci/devices/'
+    for path, dirs, files in os.walk(base_dir):
+        for dir in dirs:
+            if pci in dir:
+                return os.path.join(base_dir, dir)
+    sys.exit(f"Could not find sysfs directory for device {pci}")
+
+
+def get_dsa_id(pci):
+    "Get the DSA instance ID using the PCI address of the device"
+    pci_dir = get_pci_dir(pci)
+    for path, dirs, files in os.walk(pci_dir):
+        for dir in dirs:
+            if dir.startswith('dsa') and 'wq' not in dir:
+                return int(dir[3:])
+    sys.exit(f"Could not get device ID for device {pci}")
+
+
 def configure_dsa(dsa_id, queues, prefix):
     "Configure the DSA instance with appropriate number of queues"
     dsa_dir = SysfsDir(f"/sys/bus/dsa/devices/dsa{dsa_id}")
@@ -68,14 +88,18 @@ def main(args):
     "Main function, does arg parsing and calls config function"
     arg_p = argparse.ArgumentParser(
         description="Configure whole DSA device instance for DPDK use")
-    arg_p.add_argument('dsa_id', type=int, help="DSA instance number")
+    arg_p.add_argument('dsa_id',
+                       help="Specify DSA instance either via DSA instance number or PCI address")
     arg_p.add_argument('-q', metavar='queues', type=int, default=255,
                        help="Number of queues to set up")
     arg_p.add_argument('--name-prefix', metavar='prefix', dest='prefix',
                        default="dpdk",
                        help="Prefix for workqueue name to mark for DPDK use [default: 'dpdk']")
     parsed_args = arg_p.parse_args(args[1:])
-    configure_dsa(parsed_args.dsa_id, parsed_args.q, parsed_args.prefix)
+
+    dsa_id = parsed_args.dsa_id
+    dsa_id = get_dsa_id(dsa_id) if ':' in dsa_id else dsa_id
+    configure_dsa(dsa_id, parsed_args.q, parsed_args.prefix)
 
 
 if __name__ == "__main__":
-- 
2.30.2


  reply	other threads:[~2021-05-28 13:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-27 13:26 [dpdk-dev] [PATCH] raw/ioat: extend python script functionality Kevin Laatz
2021-05-27 14:27 ` Bruce Richardson
2021-05-27 14:46   ` Laatz, Kevin
2021-05-28 13:19 ` [dpdk-dev] [PATCH v2 0/2] extend idxd config " Kevin Laatz
2021-05-28 13:19   ` Kevin Laatz [this message]
2021-05-28 13:34     ` [dpdk-dev] [PATCH v2 1/2] raw/ioat: add pci address handling to python script Bruce Richardson
2021-05-28 13:19   ` [dpdk-dev] [PATCH v2 2/2] raw/ioat: add device reset " Kevin Laatz
2021-05-28 13:37     ` Bruce Richardson
2021-05-28 13:55   ` [dpdk-dev] [PATCH v3 0/2] extend idxd config script functionality Kevin Laatz
2021-05-28 13:55     ` [dpdk-dev] [PATCH v3 1/2] raw/ioat: add pci address handling to python script Kevin Laatz
2021-05-28 13:55     ` [dpdk-dev] [PATCH v3 2/2] raw/ioat: add device reset " Kevin Laatz
2021-06-17  7:32     ` [dpdk-dev] [PATCH v3 0/2] extend idxd config script functionality Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210528131902.344423-2-kevin.laatz@intel.com \
    --to=kevin.laatz@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).