Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4546111pxj; Wed, 12 May 2021 07:56:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwN/WhtLTmysJz6qDMOCZOa+An4tWpv8HEcWPPBOwjY9KBNoHMjBR4fX+K3Z5hz8jTnQsov X-Received: by 2002:a05:6808:2d2:: with SMTP id a18mr728032oid.82.1620831410377; Wed, 12 May 2021 07:56:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620831410; cv=none; d=google.com; s=arc-20160816; b=nFofE7j62Ur7wLNTPyGh+QZPbzMKc2Xw/EiE9c2jwCgoV/6PDCRtjP6gJTWCCkeO9o H/wP8P8DV8CQ+2ACMMDCV2mr1d6pmLilOXl6bOVOCeuOmo2RzGJVvp5aVSz9etx+UWN4 VY9zoUP3zwVSPl6Huv/IKPmdP9BKbKcEF1SWOf3uiJhJLA4PsKeta6FcUprOef7BUJR6 90nE+rWZ+OHyXzdPg9gk+n1eqkA1aOduolWlclHtvgjt4gjCJaRtUtnDsKytvS/+brMm pa6imUqAs8FfugPCU7xQL9/tMb1RLfEmwQQpipcoDDXdE1n58YR9RPoRjKCaKalsxxyr luJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=fd/lp47bMDksEuCZvWNiiTTpOFVNkBriPN79wBwwZlk=; b=a+p+BO2X4fhDaoHXc7go5Q/hJ0d1uQrNta0Vq6DwcsMxsRx0aZaXv0iGxu+K8Y6PUg c6w3NFgJDCaBztjKIvuClTF2H/aQ0Q114gDofRzM97OXIvbNxUPPypveCzCdSd9tgvLr CyIjMY1boaZ33uYkP8PLRGbbdTibBqvXs2rJm9OmNQ0XhWWk6BQh/LmrzlvMc3NnGal0 cTOJryzG7pTW8pSt0aqvQNM3SwERfQwN+XBbBJWAgaViWWkwPGyGAbJT6TsCTvDUvSP+ +DnGz8+GKvg5PHJ0kyeYLAEggAlInv7kQEE7ujNnd1TuW4TJabhMirEZi6L4lgt6jRaL tvsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WPEFTeGb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k8si216875oic.37.2021.05.12.07.56.37; Wed, 12 May 2021 07:56:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WPEFTeGb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232191AbhELOzm (ORCPT + 99 others); Wed, 12 May 2021 10:55:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231830AbhELOyz (ORCPT ); Wed, 12 May 2021 10:54:55 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70F5DC061346 for ; Wed, 12 May 2021 07:53:46 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id j3-20020a05600c4843b02901484662c4ebso3184491wmo.0 for ; Wed, 12 May 2021 07:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fd/lp47bMDksEuCZvWNiiTTpOFVNkBriPN79wBwwZlk=; b=WPEFTeGb0JMfmKzK5eEiCGQAdd42KCSJ//onCHJLhX6KStKsTis44g4I5QVg+IUwiC qzKt2QoVeXoYJWPE17RbfYyCLzwETRPr48WToGxv+OfazCAdoC+94RpiecZcfe6DsK9h aH10s+MWdH0NGRo2sTQ8VS8zntmZxASFJgfdtV2wRa/sZ3zIX6zYLdumlgE6auCYqVdW cfagrj/KXPYQqUaDNqpIjhK7TnsmZsoA+eS1cb7/6cIHYpL/hOc8zirqgH87btnxOBvG QXUiaNjQ96w3OWHSJOkyEECxY/t0Q6fRItzfRhdU9mMe/nVS4ad/4tZmjjMX7fqKhy3H 3Gpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fd/lp47bMDksEuCZvWNiiTTpOFVNkBriPN79wBwwZlk=; b=OQlg4VUOjsg/mAUEubwo/g3PFF8s/JQ6mgl3fEVov6aT1EL1cf/JcQ4a5LnZOIB316 Y52oewnuZEJH5wsNRYGgK2KWGkccI1qyVMRrSpB8SS76mvQTpC2dVnxGw9tknfQWhnPu pGtDFCLsPbRLvsiDyYKG/zC+sZ1gRM7ir5j1WIynWwVByLvpdKN4S5EX+WgwlH49OIQB g56mytjx2vldmzYLd97C5XiCN42xVYLv3hM6hwJ1uZAPCPSqnaL5pdlY8tPrL3fNbj/Q m//IK6CnzIoW+v5BccuP87SKqL0f5FkWbboDzfi7oUv3AxOZck2aZzeC+cDkWlX6gdde fJvQ== X-Gm-Message-State: AOAM533KbBPDqgRpgWa/J8hUxFk4flkorgqwvSBWZ7P9/J483oWF9pHy qR/PVP6pFhntAwMj9FMuA+ipO1X87kFnHLky3Zs= X-Received: by 2002:a1c:4954:: with SMTP id w81mr12296554wma.49.1620831225047; Wed, 12 May 2021 07:53:45 -0700 (PDT) MIME-Version: 1.0 References: <20210508195641.397198-1-robdclark@gmail.com> <20210508195641.397198-2-robdclark@gmail.com> <20210512112330.0130a62a@eldfell> In-Reply-To: <20210512112330.0130a62a@eldfell> From: Rob Clark Date: Wed, 12 May 2021 07:57:26 -0700 Message-ID: Subject: Re: [PATCH 1/2] drm: Fix dirtyfb stalls To: Pekka Paalanen Cc: Daniel Vetter , Rob Clark , David Airlie , open list , dri-devel , Thomas Zimmermann Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 12, 2021 at 1:23 AM Pekka Paalanen wrote: > > On Tue, 11 May 2021 18:44:17 +0200 > Daniel Vetter wrote: > > > On Mon, May 10, 2021 at 12:06:05PM -0700, Rob Clark wrote: > > > On Mon, May 10, 2021 at 10:44 AM Daniel Vetter wrote: > > > > > > > > On Mon, May 10, 2021 at 6:51 PM Rob Clark wrote: > > > > > > > > > > On Mon, May 10, 2021 at 9:14 AM Daniel Vetter wrote: > > > > > > > > > > > > On Sat, May 08, 2021 at 12:56:38PM -0700, Rob Clark wrote: > > > > > > > From: Rob Clark > > > > > > > > > > > > > > drm_atomic_helper_dirtyfb() will end up stalling for vblank on "video > > > > > > > mode" type displays, which is pointless and unnecessary. Add an > > > > > > > optional helper vfunc to determine if a plane is attached to a CRTC > > > > > > > that actually needs dirtyfb, and skip over them. > > > > > > > > > > > > > > Signed-off-by: Rob Clark > > > > > > > > > > > > So this is a bit annoying because the idea of all these "remap legacy uapi > > > > > > to atomic constructs" helpers is that they shouldn't need/use anything > > > > > > beyond what userspace also has available. So adding hacks for them feels > > > > > > really bad. > > > > > > > > > > I suppose the root problem is that userspace doesn't know if dirtyfb > > > > > (or similar) is actually required or is a no-op. > > > > > > > > > > But it is perhaps less of a problem because this essentially boils > > > > > down to "x11 vs wayland", and it seems like wayland compositors for > > > > > non-vsync'd rendering just pageflips and throws away extra frames from > > > > > the app? > > > > > > > > Yeah it's about not adequately batching up rendering and syncing with > > > > hw. bare metal x11 is just especially stupid about it :-) > > > > > > > > > > Also I feel like it's not entirely the right thing to do here either. > > > > > > We've had this problem already on the fbcon emulation side (which also > > > > > > shouldn't be able to peek behind the atomic kms uapi curtain), and the fix > > > > > > there was to have a worker which batches up all the updates and avoids any > > > > > > stalls in bad places. > > > > > > > > > > I'm not too worried about fbcon not being able to render faster than > > > > > vblank. OTOH it is a pretty big problem for x11 > > > > > > > > That's why we'd let the worker get ahead at most one dirtyfb. We do > > > > the same with fbcon, which trivially can get ahead of vblank otherwise > > > > (if sometimes flushes each character, so you have to pile them up into > > > > a single update if that's still pending). > > > > > > > > > > Since this is for frontbuffer rendering userspace only we can probably get > > > > > > away with assuming there's only a single fb, so the implementation becomes > > > > > > pretty simple: > > > > > > > > > > > > - 1 worker, and we keep track of a single pending fb > > > > > > - if there's already a dirty fb pending on a different fb, we stall for > > > > > > the worker to start processing that one already (i.e. the fb we track is > > > > > > reset to NULL) > > > > > > - if it's pending on the same fb we just toss away all the updates and go > > > > > > with a full update, since merging the clip rects is too much work :-) I > > > > > > think there's helpers so you could be slightly more clever and just have > > > > > > an overall bounding box > > > > > > > > > > This doesn't really fix the problem, you still end up delaying sending > > > > > the next back-buffer to mesa > > > > > > > > With this the dirtyfb would never block. Also glorious frontbuffer > > > > tracking corruption is possible, but that's not the kernel's problem. > > > > So how would anything get held up in userspace. > > > > > > the part about stalling if a dirtyfb is pending was what I was worried > > > about.. but I suppose you meant the worker stalling, rather than > > > userspace stalling (where I had interpreted it the other way around). > > > As soon as userspace needs to stall, you're losing again. > > > > Nah, I did mean userspace stalling, so we can't pile up unlimited amounts > > of dirtyfb request in the kernel. > > > > But also I never expect userspace that uses dirtyfb to actually hit this > > stall point (otherwise we'd need to look at this again). It would really > > be only there as defense against abuse. > > > > > > > But we could re-work drm_framebuffer_funcs::dirty to operate on a > > > > > per-crtc basis and hoist the loop and check if dirtyfb is needed out > > > > > of drm_atomic_helper_dirtyfb() > > > > > > > > That's still using information that userspace doesn't have, which is a > > > > bit irky. We might as well go with your thing here then. > > > > > > arguably, this is something we should expose to userspace.. for DSI > > > command-mode panels, you probably want to make a different decision > > > with regard to how many buffers in your flip-chain.. > > > > > > Possibly we should add/remove the fb_damage_clips property depending > > > on the display type (ie. video/pull vs cmd/push mode)? > > > > I'm not sure whether atomic actually needs this exposed: > > - clients will do full flips for every frame anyway, I've not heard of > > anyone seriously doing frontbuffer rendering. > > That may or may not be changing, depending on whether the DRM drivers > will actually support tearing flips. There has been a huge amount of > debate for needing tearing for Wayland [1], and while I haven't really > joined that discussion, using front-buffer rendering (blits) to work > around the driver inability to flip-tear might be something some people > will want. jfwiw, there is a lot of hw that just can't do tearing pageflips.. I think this probably includes most arm hw. What is done instead is to skip the pageflip and render directly to the front-buffer. EGL_KHR_mutable_render_buffer is a thing you might be interested in.. it is wired up for android on i965 and there is a WIP MR[1] for mesa/st (gallium): Possibly it could be useful to add support for platform_wayland? [1] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10685 BR, -R > Personally, what I do agree with is that "tear if late from intended > vblank" is a feature that will be needed when VRR cannot be used. > However, I would also argue that multiple tearing updates per refresh > cycle is not a good idea, and I know people disagree with this because > practically all relevant games are using a naive main loop that makes > multi-tearing necessary for good input response. > > I'm not quite sure where this leaves the KMS UAPI usage patterns. Maybe > this matters, maybe not? > > Does it make a difference between using legacy DirtyFB vs. atomic > FB_DAMAGE_CLIPS property? > > Also mind that Wayland compositors would be dynamically switching > between "normal flips" and "tearing updates" depending on the > scenegraph. This switch should not be considered a "mode set". > > [1] https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/65 > > > Thanks, > pq