Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp548968imc; Sun, 10 Mar 2019 13:44:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxquIEZ6bPLAl3yGGwshFTWzoM9yRRb9YZEzqLe/A/DPlcp8RcfB6cvx9HKzZ8O/EEDZ7pm X-Received: by 2002:a63:8743:: with SMTP id i64mr26986621pge.69.1552250680935; Sun, 10 Mar 2019 13:44:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552250680; cv=none; d=google.com; s=arc-20160816; b=d02gnPIChX/mNYgq77iGkyN+mlj6/VcdbrHMLA6Kw9spd8o/y6F55MvSpBW4I21/97 xPa39ypfFZQ3xSUcc/60Dnl20m0PGj9J0iWiAsG0Di9nyNJbzClZQDlS412II01Rxzpu Xd9p85EN+numJeyLl7xgHjlzp4Ji2ESgUr1Rb9ZqaOTmavMIIJux0EVA3x+eqyLGZvHb SaPwrA5c8SXtzH8uP2uMZZ/qmRwGa9vUg51jXTrihYDUjovga/CbtXtjEgKjoF5ooyMw m0NqBa12iTEHHzQRZ2Ij/PuRqYoysfMkQ1Uwwz8oiSVvOsVMyKnOoOYeMzPWKk5MJjfd bSgA== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BJpjV2zMYyI2iypQGgXFuxmY9q4KzTrjBtn9MNt+Ivo=; b=Q2zkbjPOpn7eyOn7a767qMpeOM2glX665HqhCiKrcJalboojPgOtOjcOdITahIIcK6 j6ITxQ/6Wi0489Y6rx0CCV08HTz4M/c8i69azJJpR54ru1lEeSCofKEkIRHY3Mh4Nas9 JIKHEuzxWyKVCRhtlJF569F7Z3wPZPOIRHfFI2c3b+nOYYVRxxlpu8CwiQjAd09NVNce tV1wZyGAjKlYj8VfcwMynrvDruUcmhICTWI5UynGqGSXPSSYTspRoXH+su+yXpEs06UZ HYSpEK+IqE7aV74ITxsv4tE9UsHSnL8UM/HwwPeA8wZXqvsgIV4LJhI1gLD3Ue5kPKis l2Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tnhuvbRy; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si3254887pgp.452.2019.03.10.13.44.24; Sun, 10 Mar 2019 13:44: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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tnhuvbRy; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726855AbfCJUfM (ORCPT + 99 others); Sun, 10 Mar 2019 16:35:12 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:46389 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726798AbfCJUfM (ORCPT ); Sun, 10 Mar 2019 16:35:12 -0400 Received: by mail-qt1-f196.google.com with SMTP id z25so2886293qti.13 for ; Sun, 10 Mar 2019 13:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=BJpjV2zMYyI2iypQGgXFuxmY9q4KzTrjBtn9MNt+Ivo=; b=tnhuvbRyF4CDv9incE31fqWQ1jO5kQCkVpbcHsTXdxhfRwcufKe2x4mRF5EV2gek43 D89PY3jVccznnkhkKn/rT2E0Y+QSqSupUQnaJhoeZzWwt+y4tVRvEZxzhap2NIgPIiKC iqau/fnNg15iNBZGuRPSDnTf/EMvGCJalfBPs7lbvPVastBb9VyctUlrn1/7R7gzHKdX Cte8y+XGDuzXYcomcx4yjJDxYgIxSgnjqmH/GodWfLglC1hanTVswaVt1k1PRGpFH9GK WaqwgzFMSHgRfa0BcAZduciNaZ37IjpGo3p9f0Kuna4tBdPTKQzOMjB9f/e0TPq6h60J gMQg== 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:content-transfer-encoding :in-reply-to:user-agent; bh=BJpjV2zMYyI2iypQGgXFuxmY9q4KzTrjBtn9MNt+Ivo=; b=TCYDeuV4kDssIBhLAh6MMOyp1iq4/h/VgG06jdzI01vrsQFwdgCcOfVhqZ/tBvG7bV BnHPtYAJeymtE0XPIR2tewZksHddnGpgHWO8E10zQu/rCa1EK2wLmKxj0/jZlxNPtjUR ltPgxureVFXyuHiD3Z6IArpPqHPl7grEqIn5utwdMX+DJch+59pLByPFFS0j9knj6x9p oKvywolD/ktTVq9+EFKWSMqa0Fenrq5euzpLnr+2LkWsHPMhws5YIJg3H9K26YOF8GKr mnVATwKkYgaC63Ulqf2J+RLfXXu+ZUheTPSZjrg/LaCrYLEoIovN55y2bjTSOlv2Ua+x d0Bw== X-Gm-Message-State: APjAAAXc+LlPjCXgbjkJsj6IAZFrAwzMuvG7IgTBisqbaZnHGSXZPPmU LmCKufujgWO5Zld7TR8scKg= X-Received: by 2002:a0c:93d5:: with SMTP id g21mr23656464qvg.10.1552250110487; Sun, 10 Mar 2019 13:35:10 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id p67sm2149993qkd.39.2019.03.10.13.35.06 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 10 Mar 2019 13:35:08 -0700 (PDT) Date: Sun, 10 Mar 2019 17:35:05 -0300 From: Rodrigo Siqueira To: Ville =?utf-8?B?U3lyasOkbMOk?= Cc: Shayenne Moura , Haneen Mohammed , David Airlie , dri-devel , Linux Kernel Mailing List Subject: Re: [PATCH] drm/vkms: Solve bug on kms_crc_cursor tests Message-ID: <20190310203505.2needmil76a4rc74@smtp.gmail.com> References: <20190225142606.gov32asdq3qe375q@smtp.gmail.com> <20190228101107.GL2665@phenom.ffwll.local> <20190228140341.GG20097@intel.com> <20190301152558.GR20097@intel.com> <20190301184147.GS20097@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190301184147.GS20097@intel.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/01, Ville Syrjälä wrote: > On Fri, Mar 01, 2019 at 03:35:35PM -0300, Shayenne Moura wrote: > > Em sex, 1 de mar de 2019 às 12:26, Ville Syrjälä > > escreveu: > > > > > > On Fri, Mar 01, 2019 at 11:55:11AM -0300, Shayenne Moura wrote: > > > > Em qui, 28 de fev de 2019 às 11:03, Ville Syrjälä > > > > escreveu: > > > > > > > > > > On Thu, Feb 28, 2019 at 11:11:07AM +0100, Daniel Vetter wrote: > > > > > > On Mon, Feb 25, 2019 at 11:26:06AM -0300, Shayenne Moura wrote: > > > > > > > vkms_crc_work_handle needs the value of the actual frame to > > > > > > > schedule the workqueue that calls periodically the vblank > > > > > > > handler and the destroy state functions. However, the frame > > > > > > > value returned from vkms_vblank_simulate is updated and > > > > > > > diminished in vblank_get_timestamp because it is not in a > > > > > > > vblank interrupt, and return an inaccurate value. > > > > > > > > > > > > > > Solve this getting the actual vblank frame directly from the > > > > > > > vblank->count inside the `struct drm_crtc`, instead of using > > > > > > > the `drm_accurate_vblank_count` function. > > > > > > > > > > > > > > Signed-off-by: Shayenne Moura > > > > > > > > > > > > Sorry for the delay, I'm a bit swamped right now :-/ > > > > > > > > > > > > Debug work you're doing here is really impressive! But I have no idea > > > > > > what's going on. It doesn't look like it's just papering over a bug (like > > > > > > the in_vblank_irq check we've discussed on irc), but I also have no idea > > > > > > why it works. > > > > > > > > > > > > I'll pull in Ville, he understands this better than me. > > > > > > > > > > It's not entirely clear what we're trying to fix. From what I can see > > > > > the crc work seems to be in no way synchronized with page flips, so > > > > > I'm not sure how all this is really supposed to work. > > > > > > > > > > > > > Hi, Ville! > > > > > > > > Thank you for the review! :) > > > > > > > > I do not understand well what crc code is doing, but the issue that I found > > > > is related to the vblank timestamp and frame count. > > > > > > > > When vkms handles the crc_cursor it uses the start frame and end frame > > > > values to verify if it needs to call the function 'drm_crtc_add_crc_entry()' > > > > for each frame. > > > > > > > > However, when getting the frame count, the code is calling the function > > > > drm_update_vblank_count(dev, pipe, false) and, because of the 'false', > > > > subtracting the actual vblank timestamp (consequently, the frame count > > > > value), causing conflicts. > > > > > > The in_vblank_irq behavour looks sane to me. What are these conflicts? > > > > > > > The entire history was: > > - I sent the patch with bugfix for vblank extra frame. The patch changed > > our function vkms_get_vblank_timestamp() to look like this: > > > > bool vkms_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe, > > int *max_error, ktime_t *vblank_time, > > bool in_vblank_irq) > > { > > struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev); > > struct vkms_output *output = &vkmsdev->output; > > > > *vblank_time = output->vblank_hrtimer.node.expires; > > > > + if (!in_vblank_irq) > > + *vblank_time -= output->period_ns; > > > > return true; > > } > > > > - This patch solve the issue that I was looking for (extra vblank > > frames on kms_flip). > > > > - However, kms_cursor_crc tests, which passed before my patch, started to fail. > > > > - Debugging them, I found that the problem was inside of function > > `vkms_vblank_simulate()` > > when it was handling the crc_enabled (inside if (state && output->crc_enabled)) > > and inside the function vkms_crc_work_handle() too. > > > > - Following the steps: > > 1. Inside vkms_vblank_simulate() we call drm_crtc_accurate_vblank_count() > > 2. In its turn, drm_crtc_accurate_vblank_count() calls the function > > drm_update_vblank_count(dev, pipe, false). /* This false is default */ > > 3. Finally, the “false” used in drm_update_vblank_count(), will be > > passed to vkms_get_vblank_timestamp() and the condition “if > > (!in_vblank_irq)” will be executed multiple times (we don’t want it). > > > > - Inside vkms_crc, the issue is that the returned frame value change for > > every call of drm_crtc_accurate_vblank_count() because > > in_vblank_irq == false. Hi Ville, > OK. So why is it changing? AFAICS it should not change unless the > timer was moved forward in between the calls. Yes Ville, you’re right. We have to update it only when the function vkms_vblank_simulate() is invoked (timer move forward), and FWIU we do it when we call drm_crtc_handle_vblank(). However, the current implementation of vkms, has a call to drm_crtc_accurate_vblank_count() inside the vkms_vblank_simulate() which is a problem because it also update the vblank value. FWIU, this patch fixes this issue by taking the count value in the data struct instead of call drm_crtc_accurate_vblank_count() which will avoid the extra update. Thanks, Best Regards > > > > - To solve this, I used the value already calculated on vblank->count, > > instead of using the helper function that updates the value. > > > > Shayenne > > > > > > > > > > Does it make sense? I am not sure about this crc code behavior. > > > > > > > > Shayenne > > > > > > > > > > -Daniel > > > > > > > > > > > > > --- > > > > > > > drivers/gpu/drm/vkms/vkms_crc.c | 4 +++- > > > > > > > drivers/gpu/drm/vkms/vkms_crtc.c | 4 +++- > > > > > > > 2 files changed, 6 insertions(+), 2 deletions(-) > > > > > > > > > > > > > > diff --git a/drivers/gpu/drm/vkms/vkms_crc.c b/drivers/gpu/drm/vkms/vkms_crc.c > > > > > > > index d7b409a3c0f8..09a8b00ef1f1 100644 > > > > > > > --- a/drivers/gpu/drm/vkms/vkms_crc.c > > > > > > > +++ b/drivers/gpu/drm/vkms/vkms_crc.c > > > > > > > @@ -161,6 +161,8 @@ void vkms_crc_work_handle(struct work_struct *work) > > > > > > > struct vkms_output *out = drm_crtc_to_vkms_output(crtc); > > > > > > > struct vkms_device *vdev = container_of(out, struct vkms_device, > > > > > > > output); > > > > > > > + unsigned int pipe = drm_crtc_index(crtc); > > > > > > > + struct drm_vblank_crtc *vblank = &crtc->dev->vblank[pipe]; > > > > > > > struct vkms_crc_data *primary_crc = NULL; > > > > > > > struct vkms_crc_data *cursor_crc = NULL; > > > > > > > struct drm_plane *plane; > > > > > > > @@ -196,7 +198,7 @@ void vkms_crc_work_handle(struct work_struct *work) > > > > > > > if (primary_crc) > > > > > > > crc32 = _vkms_get_crc(primary_crc, cursor_crc); > > > > > > > > > > > > > > - frame_end = drm_crtc_accurate_vblank_count(crtc); > > > > > > > + frame_end = vblank->count; > > > > > > > > > > > > > > /* queue_work can fail to schedule crc_work; add crc for > > > > > > > * missing frames > > > > > > > diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c > > > > > > > index 8a9aeb0a9ea8..9bf3268e2e92 100644 > > > > > > > --- a/drivers/gpu/drm/vkms/vkms_crtc.c > > > > > > > +++ b/drivers/gpu/drm/vkms/vkms_crtc.c > > > > > > > @@ -10,6 +10,8 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) > > > > > > > vblank_hrtimer); > > > > > > > struct drm_crtc *crtc = &output->crtc; > > > > > > > struct vkms_crtc_state *state = to_vkms_crtc_state(crtc->state); > > > > > > > + unsigned int pipe = drm_crtc_index(crtc); > > > > > > > + struct drm_vblank_crtc *vblank = &crtc->dev->vblank[pipe]; > > > > > > > u64 ret_overrun; > > > > > > > bool ret; > > > > > > > > > > > > > > @@ -20,7 +22,7 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) > > > > > > > DRM_ERROR("vkms failure on handling vblank"); > > > > > > > > > > > > > > if (state && output->crc_enabled) { > > > > > > > - u64 frame = drm_crtc_accurate_vblank_count(crtc); > > > > > > > + u64 frame = vblank->count; > > > > > > > > > > > > > > /* update frame_start only if a queued vkms_crc_work_handle() > > > > > > > * has read the data > > > > > > > -- > > > > > > > 2.17.1 > > > > > > > > > > > > > > > > > > > -- > > > > > > Daniel Vetter > > > > > > Software Engineer, Intel Corporation > > > > > > http://blog.ffwll.ch > > > > > > _______________________________________________ > > > > > > dri-devel mailing list > > > > > > dri-devel@lists.freedesktop.org > > > > > > https://lists.freedesktop.org/mailman/listinfo/dri-devel > > > > > > > > > > -- > > > > > Ville Syrjälä > > > > > Intel > > > > > > -- > > > Ville Syrjälä > > > Intel > > -- > Ville Syrjälä > Intel -- Rodrigo Siqueira https://siqueira.tech Graduate Student Department of Computer Science University of São Paulo