Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3942992ybg; Mon, 28 Oct 2019 23:06:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3cn+7vr+uIZm/M0r9SXh3p5AEG1bh561JNprYawlwj/WsbmuQZTon7yKtrDhEZce2G63L X-Received: by 2002:a17:906:e101:: with SMTP id gj1mr1521440ejb.253.1572329211708; Mon, 28 Oct 2019 23:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572329211; cv=none; d=google.com; s=arc-20160816; b=hN95cIYcndyLwvHboVCTdJ6P0M6gct73+etllQw8WAmaaOdd+wqzUJMgxT/wLKDoU5 wMboACXia0cWq8AMxpNy+iQY/mFWiDkvSZO7qOugpo26ae08XW7KNpXQY4PZQ9QO7Ztx xZrYxXB8uB3lMEmjRB0Vlnmk97oGQS8/0nR55cHruGXlzBLHylvn4vSnINgDA2SjFpkv +39XxC+HGHTs7iqsiZbbt1vfCYGRIIbPSquK/InpKFCeHMKa6BNXR4ryphX29Acj/7P3 1/LWH2Dzs5dh6DjyaLsKObqPHUZs/R4la2bvDv9V0+WZzDOn2eJrrAkVlg38PrrCQ6cd ghdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=/8Rur5Pty80k5lMPnsEahXbKqsft7F2CsN6kEZIOz70=; b=YwcIkKayxEoFbq20MxWub/vA6GORQGgB8OGfLQhyw0oBHa/3F/mDlXDECsOFoJdRqg xMeSnFL+RkpfoGpCMnPvnbVv5LIQmVFqXbIvrl1tlAu8xiNyyoLRE/OrzM9GJxOpUwzz Hj1bFayQfymCgNj5hd/f1y0XLdXkoYyueTlU5ObMO9lYHaS3cGca9hx9dar3RvuiaS7i OKuIr/0pQvQ6PIhqHrPRlxeswiWiNE7L6G27ftURoIOHCv+lc9e8dIiR1t9r4xkVDnNz tGLhYhsDNb/n7+qkvlQtNlRquL1axTaY13zrnesK6WHxXXE3lclWRUAyd28+oV3rHXD4 +uTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b53si9391649edb.419.2019.10.28.23.06.27; Mon, 28 Oct 2019 23:06:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732737AbfJ1Q37 (ORCPT + 99 others); Mon, 28 Oct 2019 12:29:59 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35625 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731006AbfJ1Q36 (ORCPT ); Mon, 28 Oct 2019 12:29:58 -0400 Received: by mail-pl1-f193.google.com with SMTP id x6so1789681pln.2 for ; Mon, 28 Oct 2019 09:29:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=/8Rur5Pty80k5lMPnsEahXbKqsft7F2CsN6kEZIOz70=; b=sZGHfis8SxT7PDy4BnFG9d9khmAs7D0xY82w0NiROTk9y8cAL3Mfm+JccTBx502v0l 5FHTEHkYaJ1JrxXYPynO22BJluJsmBBkLWru2W+2fEFEUTUljaicTXxihoxENqZyWfTY 9LS08zGaB9x9E5MMsfOA5MeKQJ2/GoQvmSM3F5zr4Dqs6KS+IjTeT8TA1NfrBq74ekc/ WtE9PcZFYj8TUxEvwfjVGysIaCRwiEDl3YbUeRr6ndrNG55FoGtHmXoQqfLPgdA7Nbf9 ImCrpp6hY24/zfZGmT+x28YDaT6qBN2JSwp+cAm4C9lXlRwvg1UvvwHONOyVfiqXp0dh M3PQ== X-Gm-Message-State: APjAAAX9f7rqV7iPvPM1d6oyTy2IjpF9q6x+fmeg4u7ZfKSZJrNaX5Jq iCpTYnlZyX+Zs0xVZLkbm47Owb+CsDU= X-Received: by 2002:a17:902:a98b:: with SMTP id bh11mr20116578plb.321.1572280197972; Mon, 28 Oct 2019 09:29:57 -0700 (PDT) Received: from sultan-box.localdomain ([104.200.129.62]) by smtp.gmail.com with ESMTPSA id v2sm11423626pgf.39.2019.10.28.09.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 09:29:57 -0700 (PDT) Date: Mon, 28 Oct 2019 09:29:55 -0700 From: Sultan Alsawaf To: Jason Gunthorpe Cc: "Martin K. Petersen" , Thomas Hellstrom , Palmer Dabbelt , Sakari Ailus , Ming Lei , Gal Pressman , linux-kernel@vger.kernel.org Subject: Re: [PATCH] scatterlist: Speed up for_each_sg() loop macro Message-ID: <20191028162955.GB32593@sultan-box.localdomain> References: <20191025213359.7538-1-sultan@kerneltoast.com> <20191028141734.GD29652@ziepe.ca> <20191028161848.GA32593@sultan-box.localdomain> <20191028162320.GF29652@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191028162320.GF29652@ziepe.ca> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 28, 2019 at 01:23:20PM -0300, Jason Gunthorpe wrote: > On Mon, Oct 28, 2019 at 09:18:48AM -0700, Sultan Alsawaf wrote: > > On Mon, Oct 28, 2019 at 11:17:34AM -0300, Jason Gunthorpe wrote: > > > This is a big change in the algorithm, why are you sure it is OK? > > > > I'm sure it's OK because the test module I provided in the commit message > > encapsulates all the possible edge cases of sg chaining: > > -An sglist with >=1 && <=(SG_MAX_SINGLE_ALLOC-1) nents (no chaining, the last > > element in the array is unused) > > -An sglist with SG_MAX_SINGLE_ALLOC nents (no chaining, the last element in the > > array isn't an sg chain link) > > -An sglist with >SG_MAX_SINGLE_ALLOC && <=2*(SG_MAX_SINGLE_ALLOC-1) nents (there > > is one chain to another array, and the other array's last element is unused) > > -An sglist with (2*SG_MAX_SINGLE_ALLOC)-1 nents (there is one chain to another > > array, and the other array's last element isn't an sg chain link) > > -An sglist with 2*SG_MAX_SINGLE_ALLOC nents (there are two chains to other > > arrays, and the 3rd array contains 2 sgs & its last element is unused) > > -An sglist with >2*SG_MAX_SINGLE_ALLOC && <(3*SG_MAX_SINGLE_ALLOC)-1 nents > > (there are two chains to other arrays, and the 3rd array's last element isn't > > an sg chain) > > This testing is making assumptions about how 'nr' is used and the > construction of the sgl though > > If any chains are partially populated, or for some reason the driver > starts at a different sgl, it will break. You'll need to somehow > show none of those possibilities are happening. I haven't personally witnessed any for_each_sg() use that starts at a different sgl, but this is something I considered as well. The optimal solution would be to alter for_each_sg() to replace the `sg` and `nr` arguments with a single sg_table pointer argument instead. Users that genuinely need to start at a different sgl can just craft their own for-loop with sg_next. This would require changes to a lot of files though, and I wanted to see how the mailing list felt about this change before embarking on that. Sultan