Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5020784rwb; Tue, 6 Sep 2022 17:12:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR6rh1BmnI5phTjoFSgHtQfUAdI7pECRcEs9xGYbDWrR48RIspt2YljzB2T6rp/yDu0r9VSM X-Received: by 2002:a05:6402:1f89:b0:44e:798b:75c6 with SMTP id c9-20020a0564021f8900b0044e798b75c6mr839369edc.407.1662509563679; Tue, 06 Sep 2022 17:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662509563; cv=none; d=google.com; s=arc-20160816; b=KDHRHtAZLfQdTuFtPcuvzS8ZE3vOY1pllK9jYHj0UuBBmE6m42JLf+eOEtmtw8aH/2 RKi2gBzzqE8OBjrFdirIfgopJjQQr6MYMQxuwtHrRvXo4/ozyXc49EqgJbq14IaBshJP V9SmkEeGGbMUGDZnFY/Pu/e6cGau/Q0Mj/pxMAYKcQZd99BccuesLmjdQxzRo9gpaYjD 2KsMgcIcAQPahtsxlsIIeOrAZ2nj0ZIqg3yPWh2UmTnKj/sTvFzONKIosRi0ZbBF5MBO F058GtogoayKYe+E3ufo0lF6QGILgX8DmWul/d4fEpaWRpEidxE6d7zoPdwKhTNA8s4m /WhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rh1S7QUmN9msoqxI7fEuUgQGRHwthEWICM05M3Wc2aQ=; b=mvFrtmYkqyEjeqSOVYaCnazRGywei9Hr6k+C+hwMWKYieNqDaBQAr7EhA3ScpVZANJ 2hI80S9vVlM53NK06Cd801gCNOt/1EUNnvvdDSEVDNFBhDhl4wVGJPEKwN1DAUT2Fkmb W4BkDLL8ju8ID1YlT6MMnGhzrtK4Fmfo/v+VVyGG0WixFKUDyqs/E9qDu2M8Irj5iOnB YEWUIEh6cNvACQvl5Ky1ZbfcH/fdE5tsHqvqFFIFy299Usno87zt0wZZm3gvqKJ4ERTx oy9aOIzWzS3TH67SzKf/mSSH3m33e7sIcErCjCka8ov4QnWu3tbO0LWNQw7wzAkaNmq3 IjpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=r8Mf6Sqi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb8-20020a0564020d0800b00442edebe687si13330089edb.633.2022.09.06.17.12.17; Tue, 06 Sep 2022 17:12:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=r8Mf6Sqi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229644AbiIGAH2 (ORCPT + 99 others); Tue, 6 Sep 2022 20:07:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229486AbiIGAHX (ORCPT ); Tue, 6 Sep 2022 20:07:23 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1445493227 for ; Tue, 6 Sep 2022 17:07:09 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id p18so12846413plr.8 for ; Tue, 06 Sep 2022 17:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=rh1S7QUmN9msoqxI7fEuUgQGRHwthEWICM05M3Wc2aQ=; b=r8Mf6Sqiq08D2xmr3VMEf6Fo6zCarWl1mXQXHKzP96Q077bnWiaFRP8QeDaVwmEvc7 6EL95xuZqp6FcqJqGTtNXdaDwJoUBICVw3PZrIgsO43iNMZTnnsGNf3ETRN2aEZBj82y CXPV5AR/3dK+S0LMLQiCuTKHeWSzCM4nRDBAP+oeuIrHcv3gof/UEUH7edtzwHmRhUd+ v3K/GgE1VDgT55UhxpRKoxicP7UzoJr84BkIxtOROUYEvsCglp56Vx8fyoa9mdirVPEJ vMc+9zcOqUuw0Rer5G+CTcCGCKCA3IcmZfFPkW9IF2x25+5n/EtX2Ih7Q+RGw7Sjhh1B IX8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=rh1S7QUmN9msoqxI7fEuUgQGRHwthEWICM05M3Wc2aQ=; b=7Fm02j4XQq6r56OGof8mTw3ozNPD0xH7Rb7V9UaQCTnBFKaV6qaMKoHfa5h+8/a3vY w0V+lZAkuUdna9oplxvmMOSn4CbkR9WMa7DZ0Le24w4ioG4lyYdMcaSDNb28M1qs6y17 oJEC/56z+rGZLyBjI43VI8fMz9WdZsoEiNABt7cp7iB5fGxpboe8bM3vAm8lAQZx9iwd DzvYRv/ytZW918J5oHm6T65/9IiDyUpaY4Fkj2pW2BVkuroaPE2buDZdC0GnGK3wIg3E g6cW00z6FevyILUiM0FoN7sCMxyWZygp1Cl66Ac3S9X+zf4rhqfQtN2GJCBlxhMXqAAq 0oyw== X-Gm-Message-State: ACgBeo1Jd6xV4Ug4SNblVH/pvfT1rt3XipVXnEcet63VHvR+cxDDbTtJ dw0dnNCUDK8a8TZdcYtqHqOuHg== X-Received: by 2002:a17:90b:14d2:b0:1fb:acff:998 with SMTP id jz18-20020a17090b14d200b001fbacff0998mr1007403pjb.70.1662509228243; Tue, 06 Sep 2022 17:07:08 -0700 (PDT) Received: from google.com (201.215.168.34.bc.googleusercontent.com. [34.168.215.201]) by smtp.gmail.com with ESMTPSA id y20-20020aa78f34000000b00537b8aa0a46sm11201922pfr.96.2022.09.06.17.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 17:07:07 -0700 (PDT) Date: Wed, 7 Sep 2022 00:07:03 +0000 From: William McVicker To: Bjorn Helgaas Cc: Bjorn Helgaas , kernel-team@android.com, Sajid Dalvi , Matthias Kaehlcke , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] PCI/PM: Switch D3Hot delay to also use usleep_range Message-ID: References: <20220817230821.47048-1-willmcvicker@google.com> <20220902221340.GA379310@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220902221340.GA379310@bhelgaas> X-Spam-Status: No, score=-15.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/02/2022, Bjorn Helgaas wrote: > On Wed, Aug 17, 2022 at 11:08:21PM +0000, Will McVicker wrote: > > From: Sajid Dalvi > > > > Since the PCI spec requires a 10ms D3Hot delay (defined by > > PCI_PM_D3HOT_WAIT) and a few of the PCI quirks update the D3Hot delay up > > to 120ms, let's add support for both usleep_range and msleep based on > > the delay time to improve the delay accuracy. > > > > This patch is based off of a commit from Sajid Dalvi > > in the Pixel 6 kernel tree [1]. Testing on a Pixel 6, found that the > > 10ms delay for the Exynos PCIe device was on average delaying for 19ms > > when the spec requires 10ms. Switching from msleep to uslseep_range > > therefore decreases the resume time on a Pixel 6 on average by 9ms. > > Add the "PCIe r6.0, sec 5.9" spec reference for the 10ms delay for > transitions to or from D3hot. > > s/D3Hot/D3hot/ to match other usage (at least in Linux; the spec does > use "D3Hot") > > s/uslseep_range/usleep_range/ > > Add "()" after function names. Thanks for the suggestions! I'll update these in the next patchset. > > In the subject, "Switch ... to *also* use usleep_range": what does the > "also" mean? It sounds like it's referring to some other place where > we also use usleep_range()? I was intending to mean usleep_range() will be used when the the delay <=20 ms, else msleep() will be used. If we drop msleep() altogether as suggested in your comments below, then I can change this to be: "Switch D3hot delay to use usleep_range." > > > [1] https://android.googlesource.com/kernel/gs/+/18a8cad68d8e6d50f339a716a18295e6d987cee3 > > > > Signed-off-by: Sajid Dalvi > > Signed-off-by: Will McVicker > > --- > > drivers/pci/pci.c | 16 +++++++++++----- > > 1 file changed, 11 insertions(+), 5 deletions(-) > > > > v3: > > * Use DIV_ROUND_CLOSEST instead of bit manipulation. > > * Minor refactor to use max() where relavant. > > > > v2: > > * Update to use 20-25% upper bound > > * Update to use usleep_range() for <=20ms, else use msleep() > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > index 95bc329e74c0..cfa8386314f2 100644 > > --- a/drivers/pci/pci.c > > +++ b/drivers/pci/pci.c > > @@ -66,13 +66,19 @@ struct pci_pme_device { > > > > static void pci_dev_d3_sleep(struct pci_dev *dev) > > { > > - unsigned int delay = dev->d3hot_delay; > > + unsigned int delay_ms = max(dev->d3hot_delay, pci_pm_d3hot_delay); > > > > - if (delay < pci_pm_d3hot_delay) > > - delay = pci_pm_d3hot_delay; > > + if (delay_ms) { > > + if (delay_ms <= 20) { > > + /* Use a 20% upper bound with 1ms minimum */ > > + unsigned int upper = max(DIV_ROUND_CLOSEST(delay_ms, 5), 1U); > > > > - if (delay) > > - msleep(delay); > > + usleep_range(delay_ms * USEC_PER_MSEC, > > + (delay_ms + upper) * USEC_PER_MSEC); > > + } else { > > + msleep(delay_ms); > > I hate the fact that we have to check for those ancient Intel chips at > all, but having to read through the usleep_range() vs msleep() thing > is just painful. > > fsleep() would be much simpler, but I am sympathetic that the fsleep() > range of 10-20ms probably wouldn't get the benefit you want. > > I wish Documentation/timers/timers-howto.rst included a reason why we > should use msleep() instead of usleep_range() for longer sleeps. Is > there a reason not to do this: I'm not familiar with the reasons behind these two beside what the documentation states. I don't know what happens when you use usleep_range() with a delay >20ms. > > static void pci_dev_d3_sleep(struct pci_dev *dev) > { > unsigned int delay_ms = max(dev->d3hot_delay, pci_pm_d3hot_delay); > unsigned int upper; > > if (delay_ms) { > /* 20% upper bound, 1ms minimum */ > upper = max(DIV_ROUND_CLOSEST(delay_ms, 5), 1U) > usleep_range(delay_ms * USEC_PER_MSEC, > (delay_ms + upper) * USEC_PER_MSEC); > } > } > > Since the Intel quirk is for 120ms, a 20% upper bound would make the > range 120-144ms. Would that be a problem? Those chips are ancient; > the list is untouched since it was added in 2006. The point of > usleep_range() is to allow the scheduler to coalesce the wakeup with > other events, so it seems unlikely we'd ever wait the whole 144ms. I > vote for optimizing the readability over sleep/resume time for > already-broken chips. I'm totally fine with this, but I don't really know what the impact would be to those old Intel chips. > > Bjorn Thanks, Will