Received: by 10.213.65.68 with SMTP id h4csp1710980imn; Thu, 29 Mar 2018 09:33:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/m81D4IBcfn780G9bQ+v85PZn5WXnOIRbVQX/TylrZr9cXryEX5mCLV13y2dgDSIj7ze7O X-Received: by 2002:a17:902:724b:: with SMTP id c11-v6mr8922803pll.192.1522341220945; Thu, 29 Mar 2018 09:33:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522341220; cv=none; d=google.com; s=arc-20160816; b=WYbomt7pI2/gAGRUMYwn4tUy33k96Srgyfx+04wQxO5yXg6etglIOrjKLrOUDSq8do vNWO7GKLdWPg0oRuOwdDWqJC3DwBHlSBP+OGezi2jARwFihqn7rfVl8snL8h0LN0daa+ LEmv9IwckhMnysqxqJZdAjaKB6WQuqBcSDkrlJiVgzsKVXowzqNI3qfAFK1ne8JmGHja PxzI/jg2riDitbT/5t5iBz5AarGQRawEg7OM2XfBr1MNXkFtJkIhSFVJg9vswc5Arycz SnxKBahyuWYXqj2OcnhPxKYemQ82YFVhyjQfCPbRyYEIE1HfdEZ54MMyggo9ZfhfcwEz Dwog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=aT9+Yy5lJF9Cb+CdlrkJyjfS/Onb7jJjS/hKgD03RIs=; b=MqKfOYBrac+U6Jtt/xQ/nkoV3ZHxRz3j8ViypwZN8FBh/kfKDm+BvQ2HhwS4j/1CKD 0QvVHteeF6iZ84cgm7xn3thgUJ7TtiQrLgu4BmoTlNOdgIZ8rzGVN06xOWG2ItOILqXx z/7U4iWDWl7bqioC4Yp3oeQf4kfIfabrWhL0LGVC8rxlvAVg3MnW9cJDmURUzD7UdbGe KxnfYU6F0y/8iRkDYfMX/vq/KA722tsGww30FUHD+Lt7nID3N2fThXcMp1Ln272diMjj 614o+chNN6AUV8He5OOyI5Q7dKpv0pCXVD0YeC0fgm12AvpxxuVN+kEqGr6JTqIGpGC8 DIxw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n61-v6si6659776plb.112.2018.03.29.09.33.26; Thu, 29 Mar 2018 09:33:40 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752249AbeC2QcS (ORCPT + 99 others); Thu, 29 Mar 2018 12:32:18 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:43851 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751182AbeC2QcR (ORCPT ); Thu, 29 Mar 2018 12:32:17 -0400 Received: from 167-98-27-229.cust-167.exponential-e.net ([167.98.27.229] helo=xylophone) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1f1aTF-0000wj-WF; Thu, 29 Mar 2018 17:32:14 +0100 Message-ID: <1522341133.2654.22.camel@codethink.co.uk> Subject: Re: [PATCH AUTOSEL for 4.4 016/115] drm: Defer disabling the vblank IRQ until the next interrupt (for instant-off) From: Ben Hutchings To: Sasha Levin , "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Cc: Chris Wilson , Ville =?ISO-8859-1?Q?Syrj=E4l=E4?= , Daniel Vetter , Michel =?ISO-8859-1?Q?D=E4nzer?= , Laurent Pinchart , Dave Airlie , Mario Kleiner , Daniel Vetter Date: Thu, 29 Mar 2018 17:32:13 +0100 In-Reply-To: <20180303223010.27106-16-alexander.levin@microsoft.com> References: <20180303223010.27106-1-alexander.levin@microsoft.com> <20180303223010.27106-16-alexander.levin@microsoft.com> Organization: Codethink Ltd. Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2018-03-03 at 22:30 +0000, Sasha Levin wrote: > From: Chris Wilson > > [ Upstream commit 608b20506941969ea30d8c08dc9ae02bb87dbf7d ] I think we need this one too: commit 75cff0837c14eaf632efabb8d7ab9eec6394d20d Author: Chris Wilson Date:   Fri Mar 24 17:30:58 2017 +0000     drm: Make the decision to keep vblank irq enabled earlier Ben. > On vblank instant-off systems, we can get into a situation where the cost > of enabling and disabling the vblank IRQ around a drmWaitVblank query > dominates. And with the advent of even deeper hardware sleep state, > touching registers becomes ever more expensive.  However, we know that if > the user wants the current vblank counter, they are also very likely to > immediately queue a vblank wait and so we can keep the interrupt around > and only turn it off if we have no further vblank requests queued within > the interrupt interval. > > After vblank event delivery, this patch adds a shadow of one vblank where > the interrupt is kept alive for the user to query and queue another vblank > event. Similarly, if the user is using blocking drmWaitVblanks, the > interrupt will be disabled on the IRQ following the wait completion. > However, if the user is simply querying the current vblank counter and > timestamp, the interrupt will be disabled after every IRQ and the user > will enabled it again on the first query following the IRQ. > > v2: Mario Kleiner - > After testing this, one more thing that would make sense is to move > the disable block at the end of drm_handle_vblank() instead of at the > top. > > Turns out that if high precision timestaming is disabled or doesn't > work for some reason (as can be simulated by echo 0 > > /sys/module/drm/parameters/timestamp_precision_usec), then with your > delayed disable code at its current place, the vblank counter won't > increment anymore at all for instant queries, ie. with your other > "instant query" patches. Clients which repeatedly query the counter > and wait for it to progress will simply hang, spinning in an endless > query loop. There's that comment in vblank_disable_and_save: > > "* Skip this step if there isn't any high precision timestamp >  * available. In that case we can't account for this and just >  * hope for the best. >  */ > > With the disable happening after leading edge of vblank (== hw counter > increment already happened) but before the vblank counter/timestamp > handling in drm_handle_vblank, that step is needed to keep the counter > progressing, so skipping it is bad. > > Now without high precision timestamping support, a kms driver must not > set dev->vblank_disable_immediate = true, as this would cause problems > for clients, so this shouldn't matter, but it would be good to still > make this robust against a future kms driver which might have > unreliable high precision timestamping, e.g., high precision > timestamping that intermittently doesn't work. > > v3: Patch before coffee needs extra coffee. > > Testcase: igt/kms_vblank > Signed-off-by: Chris Wilson > Cc: Ville Syrjälä > Cc: Daniel Vetter > Cc: Michel Dänzer > Cc: Laurent Pinchart > Cc: Dave Airlie , > Cc: Mario Kleiner > Reviewed-by: Ville Syrjälä > Signed-off-by: Daniel Vetter > Link: http://patchwork.freedesktop.org/patch/msgid/20170315204027.20160-1-chris@chris-wilson.co.uk > Signed-off-by: Sasha Levin > --- >  drivers/gpu/drm/drm_irq.c | 14 ++++++++++++-- >  1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c > index 8090989185b2..4ddbc49125cd 100644 > --- a/drivers/gpu/drm/drm_irq.c > +++ b/drivers/gpu/drm/drm_irq.c > @@ -1271,9 +1271,9 @@ void drm_vblank_put(struct drm_device *dev, unsigned int pipe) >   if (atomic_dec_and_test(&vblank->refcount)) { >   if (drm_vblank_offdelay == 0) >   return; > - else if (dev->vblank_disable_immediate || drm_vblank_offdelay < 0) > + else if (drm_vblank_offdelay < 0) >   vblank_disable_fn((unsigned long)vblank); > - else > + else if (!dev->vblank_disable_immediate) >   mod_timer(&vblank->disable_timer, >     jiffies + ((drm_vblank_offdelay * HZ)/1000)); >   } > @@ -1902,6 +1902,16 @@ bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe) >   wake_up(&vblank->queue); >   drm_handle_vblank_events(dev, pipe); >   > + /* With instant-off, we defer disabling the interrupt until after > +  * we finish processing the following vblank. The disable has to > +  * be last (after drm_handle_vblank_events) so that the timestamp > +  * is always accurate. > +  */ > + if (dev->vblank_disable_immediate && > +     drm_vblank_offdelay > 0 && > +     !atomic_read(&vblank->refcount)) > + vblank_disable_fn((unsigned long)vblank); > + >   spin_unlock_irqrestore(&dev->event_lock, irqflags); >   >   return true; > --  > 2.14.1 -- Ben Hutchings Software Developer, Codethink Ltd.