From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4C46CA0C43; Wed, 20 Oct 2021 18:32:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E0BC3411BA; Wed, 20 Oct 2021 18:30:53 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id 50AAB41231 for ; Wed, 20 Oct 2021 18:30:49 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10143"; a="226286546" X-IronPort-AV: E=Sophos;i="5.87,167,1631602800"; d="scan'208";a="226286546" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2021 09:30:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,167,1631602800"; d="scan'208";a="494708329" Received: from silpixa00401122.ir.intel.com ([10.55.128.10]) by orsmga008.jf.intel.com with ESMTP; 20 Oct 2021 09:30:46 -0700 From: Kevin Laatz To: dev@dpdk.org Cc: thomas@monjalon.net, bruce.richardson@intel.com, fengchengwen@huawei.com, jerinj@marvell.com, conor.walsh@intel.com, Kevin Laatz Date: Wed, 20 Oct 2021 16:30:11 +0000 Message-Id: <20211020163013.2125016-15-kevin.laatz@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211020163013.2125016-1-kevin.laatz@intel.com> References: <20210827172048.558704-1-kevin.laatz@intel.com> <20211020163013.2125016-1-kevin.laatz@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v11 14/16] dma/idxd: move dpdk_idxd_cfg.py from raw to dma X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Conor Walsh Move the example script for configuring IDXD devices bound to the IDXD kernel driver from raw to dma, and create a symlink to still allow use from raw. Signed-off-by: Conor Walsh Signed-off-by: Kevin Laatz Acked-by: Bruce Richardson --- drivers/dma/idxd/dpdk_idxd_cfg.py | 117 +++++++++++++++++++++++++++++ drivers/raw/ioat/dpdk_idxd_cfg.py | 118 +----------------------------- 2 files changed, 118 insertions(+), 117 deletions(-) create mode 100755 drivers/dma/idxd/dpdk_idxd_cfg.py mode change 100755 => 120000 drivers/raw/ioat/dpdk_idxd_cfg.py diff --git a/drivers/dma/idxd/dpdk_idxd_cfg.py b/drivers/dma/idxd/dpdk_idxd_cfg.py new file mode 100755 index 0000000000..fcc27822ef --- /dev/null +++ b/drivers/dma/idxd/dpdk_idxd_cfg.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2020 Intel Corporation + +""" +Configure an entire Intel DSA instance, using idxd kernel driver, for DPDK use +""" + +import sys +import argparse +import os +import os.path + + +class SysfsDir: + "Used to read/write paths in a sysfs directory" + def __init__(self, path): + self.path = path + + def read_int(self, filename): + "Return a value from sysfs file" + with open(os.path.join(self.path, filename)) as f: + return int(f.readline()) + + def write_values(self, values): + "write dictionary, where key is filename and value is value to write" + for filename, contents in values.items(): + with open(os.path.join(self.path, filename), "w") as f: + f.write(str(contents)) + + +def reset_device(dsa_id): + "Reset the DSA device and all its queues" + drv_dir = SysfsDir("/sys/bus/dsa/drivers/dsa") + drv_dir.write_values({"unbind": f"dsa{dsa_id}"}) + + +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}") + drv_dir = SysfsDir("/sys/bus/dsa/drivers/dsa") + + max_groups = dsa_dir.read_int("max_groups") + max_engines = dsa_dir.read_int("max_engines") + max_queues = dsa_dir.read_int("max_work_queues") + max_work_queues_size = dsa_dir.read_int("max_work_queues_size") + + nb_queues = min(queues, max_queues) + if queues > nb_queues: + print(f"Setting number of queues to max supported value: {max_queues}") + + # we want one engine per group, and no more engines than queues + nb_groups = min(max_engines, max_groups, nb_queues) + for grp in range(nb_groups): + dsa_dir.write_values({f"engine{dsa_id}.{grp}/group_id": grp}) + + # configure each queue + for q in range(nb_queues): + wq_dir = SysfsDir(os.path.join(dsa_dir.path, f"wq{dsa_id}.{q}")) + wq_dir.write_values({"group_id": q % nb_groups, + "type": "user", + "mode": "dedicated", + "name": f"{prefix}_wq{dsa_id}.{q}", + "priority": 1, + "size": int(max_work_queues_size / nb_queues)}) + + # enable device and then queues + drv_dir.write_values({"bind": f"dsa{dsa_id}"}) + for q in range(nb_queues): + drv_dir.write_values({"bind": f"wq{dsa_id}.{q}"}) + + +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', + 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']") + arg_p.add_argument('--reset', action='store_true', + help="Reset DSA device and its queues") + parsed_args = arg_p.parse_args(args[1:]) + + dsa_id = parsed_args.dsa_id + dsa_id = get_dsa_id(dsa_id) if ':' in dsa_id else dsa_id + if parsed_args.reset: + reset_device(dsa_id) + else: + configure_dsa(dsa_id, parsed_args.q, parsed_args.prefix) + + +if __name__ == "__main__": + main(sys.argv) diff --git a/drivers/raw/ioat/dpdk_idxd_cfg.py b/drivers/raw/ioat/dpdk_idxd_cfg.py deleted file mode 100755 index fcc27822ef..0000000000 --- a/drivers/raw/ioat/dpdk_idxd_cfg.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: BSD-3-Clause -# Copyright(c) 2020 Intel Corporation - -""" -Configure an entire Intel DSA instance, using idxd kernel driver, for DPDK use -""" - -import sys -import argparse -import os -import os.path - - -class SysfsDir: - "Used to read/write paths in a sysfs directory" - def __init__(self, path): - self.path = path - - def read_int(self, filename): - "Return a value from sysfs file" - with open(os.path.join(self.path, filename)) as f: - return int(f.readline()) - - def write_values(self, values): - "write dictionary, where key is filename and value is value to write" - for filename, contents in values.items(): - with open(os.path.join(self.path, filename), "w") as f: - f.write(str(contents)) - - -def reset_device(dsa_id): - "Reset the DSA device and all its queues" - drv_dir = SysfsDir("/sys/bus/dsa/drivers/dsa") - drv_dir.write_values({"unbind": f"dsa{dsa_id}"}) - - -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}") - drv_dir = SysfsDir("/sys/bus/dsa/drivers/dsa") - - max_groups = dsa_dir.read_int("max_groups") - max_engines = dsa_dir.read_int("max_engines") - max_queues = dsa_dir.read_int("max_work_queues") - max_work_queues_size = dsa_dir.read_int("max_work_queues_size") - - nb_queues = min(queues, max_queues) - if queues > nb_queues: - print(f"Setting number of queues to max supported value: {max_queues}") - - # we want one engine per group, and no more engines than queues - nb_groups = min(max_engines, max_groups, nb_queues) - for grp in range(nb_groups): - dsa_dir.write_values({f"engine{dsa_id}.{grp}/group_id": grp}) - - # configure each queue - for q in range(nb_queues): - wq_dir = SysfsDir(os.path.join(dsa_dir.path, f"wq{dsa_id}.{q}")) - wq_dir.write_values({"group_id": q % nb_groups, - "type": "user", - "mode": "dedicated", - "name": f"{prefix}_wq{dsa_id}.{q}", - "priority": 1, - "size": int(max_work_queues_size / nb_queues)}) - - # enable device and then queues - drv_dir.write_values({"bind": f"dsa{dsa_id}"}) - for q in range(nb_queues): - drv_dir.write_values({"bind": f"wq{dsa_id}.{q}"}) - - -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', - 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']") - arg_p.add_argument('--reset', action='store_true', - help="Reset DSA device and its queues") - parsed_args = arg_p.parse_args(args[1:]) - - dsa_id = parsed_args.dsa_id - dsa_id = get_dsa_id(dsa_id) if ':' in dsa_id else dsa_id - if parsed_args.reset: - reset_device(dsa_id) - else: - configure_dsa(dsa_id, parsed_args.q, parsed_args.prefix) - - -if __name__ == "__main__": - main(sys.argv) diff --git a/drivers/raw/ioat/dpdk_idxd_cfg.py b/drivers/raw/ioat/dpdk_idxd_cfg.py new file mode 120000 index 0000000000..85545548d1 --- /dev/null +++ b/drivers/raw/ioat/dpdk_idxd_cfg.py @@ -0,0 +1 @@ +../../dma/idxd/dpdk_idxd_cfg.py \ No newline at end of file -- 2.30.2