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 C188CA0503; Fri, 1 Apr 2022 11:08:56 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A1DD04067E; Fri, 1 Apr 2022 11:08:56 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id EFADC4014F for ; Fri, 1 Apr 2022 11:08:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648804134; x=1680340134; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=8B3WQh9YD33V/Uce/bPLRut0xpRc71oJ6K/aOg5A44Y=; b=A9wbLa1v4im5fucJI2RFQBIvkszII8S0N8AsOq2VaI1O7E4l3iw7j13P DQUrBUATB49bzxaGLuH0eaNgaih7p4wquvkdRDKjueH8xuCwcbdp66uJA juD5QuXorbFCNzV58XnXn6TKSRABM4QJLn6bLwC9RjM8mqqu3lwXjOAXv EU5gfRh/OhseM6tRKojTpyxPW/IMchd/SJGt5eosQXVFqF/cfg776LZe+ 80VLjItJKIkSHLrV7F9/BCk/4RDUm3U26zW8WP3zQAK4O1D9V2yKnnoP8 VhQHqww4rKevzv9add+myy7YzRqNkX7Fy39knPwVu9qsbvOnbGsFKiArx A==; X-IronPort-AV: E=McAfee;i="6200,9189,10303"; a="285014256" X-IronPort-AV: E=Sophos;i="5.90,226,1643702400"; d="scan'208";a="285014256" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2022 02:08:51 -0700 X-IronPort-AV: E=Sophos;i="5.90,226,1643702400"; d="scan'208";a="567317051" Received: from bricha3-mobl.ger.corp.intel.com ([10.252.20.202]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 01 Apr 2022 02:08:48 -0700 Date: Fri, 1 Apr 2022 10:08:44 +0100 From: Bruce Richardson To: Kevin Laatz Cc: dev@dpdk.org Subject: Re: [PATCH v2] dma/idxd: add generic option for queue config Message-ID: References: <20220330150700.435875-1-kevin.laatz@intel.com> <20220331172112.575972-1-kevin.laatz@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220331172112.575972-1-kevin.laatz@intel.com> 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 On Thu, Mar 31, 2022 at 06:21:12PM +0100, Kevin Laatz wrote: > The device config script currently uses some defaults to configure > devices in a generic way. > > With the addition of this option, users have more control over how > queues are configured. > > Signed-off-by: Kevin Laatz > --- > drivers/dma/idxd/dpdk_idxd_cfg.py | 39 ++++++++++++++++++++++++------- > 1 file changed, 30 insertions(+), 9 deletions(-) > > diff --git a/drivers/dma/idxd/dpdk_idxd_cfg.py b/drivers/dma/idxd/dpdk_idxd_cfg.py > index 3f5d5ee752..704cf775ed 100755 > --- a/drivers/dma/idxd/dpdk_idxd_cfg.py > +++ b/drivers/dma/idxd/dpdk_idxd_cfg.py > @@ -63,8 +63,24 @@ def get_dsa_id(pci): > sys.exit(f"Could not get device ID for device {pci}") > > > -def configure_dsa(dsa_id, queues, prefix): > +def parse_wq_opts(wq_opts): > + "Parse user-specified queue configuration, creating a dict of options" > + opt_dict = {} > + for wq_opt in wq_opts: > + try: > + opt, val = wq_opt.split("=") > + except ValueError: > + sys.exit("Invalid --wq-option format, use format 'option=value'") > + opt_dict[opt] = val > + return opt_dict > + Can I suggest a shorter version of this: def parse_wq_opts(wq_opts): "Parse ... " try: return {o.split('=')[0]: o.split('=')[1] for o in wq_opts} except: ... > + > +def configure_dsa(dsa_id, args): > "Configure the DSA instance with appropriate number of queues" > + queues = args.q > + prefix = args.prefix > + wq_opts = args.wq_option > + Do we really save much using all these variables? The "queues" one might be useful and clearer, but I wonder how much we save by avoiding the "args." part of the rest? For example, wq_opts is only used once. > dsa_dir = SysfsDir(f"/sys/bus/dsa/devices/dsa{dsa_id}") > > max_groups = dsa_dir.read_int("max_groups") > @@ -83,14 +99,17 @@ def configure_dsa(dsa_id, queues, prefix): > > # configure each queue > for q in range(nb_queues): > + default_dict = {"group_id": q % nb_groups, > + "type": "user", > + "mode": "dedicated", > + "name": f"{prefix}_wq{dsa_id}.{q}", > + "priority": 1, > + "max_batch_size": 1024, > + "size": int(max_work_queues_size / nb_queues)} > + config_dict = parse_wq_opts(wq_opts) > + write_dict = {**default_dict, **config_dict} These two lines could be replaced by: default_dict.update(parse_wq_opts(...)) though in this case, you probably want to rename default_dict to write_dict - or maybe even to "qcfg" or something more meaningful. > 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, > - "max_batch_size": 1024, > - "size": int(max_work_queues_size / nb_queues)}) > + wq_dir.write_values(write_dict) > > # enable device and then queues > idxd_dir = SysfsDir(get_drv_dir("idxd")) > @@ -112,6 +131,8 @@ def main(args): > 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('--wq-option', action='append', > + help="Provide additional config option for queues (format 'x=y')") > arg_p.add_argument('--reset', action='store_true', > help="Reset DSA device and its queues") > parsed_args = arg_p.parse_args(args[1:]) > @@ -121,7 +142,7 @@ def main(args): > if parsed_args.reset: > reset_device(dsa_id) > else: > - configure_dsa(dsa_id, parsed_args.q, parsed_args.prefix) > + configure_dsa(dsa_id, parsed_args) > > > if __name__ == "__main__": > -- > 2.31.1 >