Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751887AbdGFQ1P (ORCPT ); Thu, 6 Jul 2017 12:27:15 -0400 Received: from home.keithp.com ([63.227.221.253]:53092 "EHLO elaine.keithp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751653AbdGFQ1O (ORCPT ); Thu, 6 Jul 2017 12:27:14 -0400 From: Keith Packard To: Daniel Vetter Cc: linux-kernel@vger.kernel.org, Dave Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org Subject: Re: [PATCH 3/3] drm: Add CRTC_GET_SEQUENCE and CRTC_QUEUE_SEQUENCE ioctls In-Reply-To: <20170706075313.bn2exiklfabgc25t@phenom.ffwll.local> References: <20170705221013.27940-1-keithp@keithp.com> <20170705221013.27940-4-keithp@keithp.com> <20170706075313.bn2exiklfabgc25t@phenom.ffwll.local> Date: Thu, 06 Jul 2017 09:27:11 -0700 Message-ID: <86y3s1bkf4.fsf@keithp.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9015 Lines: 257 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Daniel Vetter writes: > I very much like this since the old ioctl really is a rather bad horror > show. And since it's tied in with ums drivers everything is > complicated. Thanks for your kind words. > I started a discussion a while back whether these should be restricted to > DRM_MASTER (i.e. the modeset resource owner) or available to everyone. > Since it's read-only I guess we can keep it accessible to everyone, but it > has a bit the problem that client app developers see this, think it does > what it does and then use it to schedule frames without asking the > compositor. Which sometimes even works, but isn't really proper design. > The reasons seems to be that on X11 there's no EGL extension for accurate > timing frame updates (DRI2/3 can do it ofc, and glx exposes it, but glx is > uncool or something like that). In the absence of a suitable EGL api, I'm not sure what to suggest, other than fixing EGL instead of blaming the kernel... However, for the leasing stuff, this doesn't really matter as I've got a master FD to play with, so if you wanted to restrict it to master, that'd be fine by me. >> + >> +/* >> + * Get crtc VBLANK count. >> + * >> + * \param dev DRM device >> + * \param data user arguement, pointing to a drm_crtc_get_sequence stru= cture. >> + * \param file_priv drm file private for the user's open file descriptor >> + */ > > Since this stuff isn't parsed by kerneldoc I tend to just free-form ioctl > comments completely. Someday maybe someone even gets around to doing > proper uabi documentation :-) Just an aside. I'm just trying to follow along with the local "conventions" in the file. Let me know if you have a future plan to make this better and I'll just reformat to suit. >> + >> +int drm_crtc_get_sequence_ioctl(struct drm_device *dev, void *data, >> + struct drm_file *file_priv) >> +{ >> + struct drm_crtc *crtc; >> + int pipe; >> + struct drm_crtc_get_sequence *get_seq =3D data; >> + struct timespec now; >> + > > You need a DRIVER_MODESET check here or the drm_crtc_find will oops. Same > below. Like this? diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index e39b2bd074e4..3738ff484f36 100644 =2D-- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -1712,6 +1712,9 @@ int drm_crtc_get_sequence_ioctl(struct drm_device *de= v, void *data, struct drm_crtc_get_sequence *get_seq =3D data; struct timespec now; =20 + if (!drm_core_check_feature(dev, DRIVER_MODESET)) + return -EINVAL; + if (!dev->irq_enabled) return -EINVAL; =20 @@ -1749,6 +1752,9 @@ int drm_crtc_queue_sequence_ioctl(struct drm_device *= dev, void *data, int ret; unsigned long spin_flags; =20 + if (!drm_core_check_feature(dev, DRIVER_MODESET)) + return -EINVAL; + if (!dev->irq_enabled) return -EINVAL; =20 >> + get_seq->sequence =3D drm_vblank_count_and_time(dev, pipe, &now); > > This can give you and old vblank if the vblank is off (i.e. sw state > hasn't be regularly updated). I think we want a new > drm_crtc_accurate_vblank_count_and_time variant. Right, I saw that code in the wait_vblank case and forgot to carry it over. Here's a duplicate of what that function does; we'll need this code in any case for drivers which don't provide the necessary support for accurate vblank counts: =2D-- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -1711,6 +1711,8 @@ int drm_crtc_get_sequence_ioctl(struct drm_device *de= v, void *data, int pipe; struct drm_crtc_get_sequence *get_seq =3D data; struct timespec now; + bool vblank_enabled; + int ret; =20 if (!drm_core_check_feature(dev, DRIVER_MODESET)) return -EINVAL; @@ -1724,8 +1726,19 @@ int drm_crtc_get_sequence_ioctl(struct drm_device *d= ev, void *data, =20 pipe =3D drm_crtc_index(crtc); =20 + vblank_enabled =3D dev->vblank_disable_immediately && READ_ONCE(vblank->e= nabled); + + if (!vblank_enabled) { + ret =3D drm_vblank_get(dev, pipe); + if (ret) { + DRM_DEBUG("crtc %d failed to acquire vblank counter, %d\n", pipe, ret); + return ret; + } + } get_seq->sequence =3D drm_vblank_count_and_time(dev, pipe, &now); get_seq->sequence_ns =3D timespec_to_ns(&now); + if (!vblank_enabled) + drm_vblank_put(dev, pipe); return 0; } > Another thing that is very ill-defined in the old vblank ioctl and that we > could fix here: Asking for vblanks when the CRTC is off is a bit silly. > Asking for the sequence when it's off makes some sense, but might still be > good to give userspace some indication in the new struct? This also from > the pov of the unpriviledge vblank waiter use-case that I wondered about > earlier. Hrm. It's certainly easy to do, however an application using this without knowing the enabled state of the crtc is probably not doing the right thing... Here's what that looks like, I think, in case we want to do this: =2D-- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -1735,6 +1735,12 @@ int drm_crtc_get_sequence_ioctl(struct drm_device *d= ev, void *data, return ret; } } + drm_modeset_lock(&crtc->mutex, NULL); + if (crtc->state) + get_seq->active =3D crtc->state->enable; + else + get_seq->active =3D crtc->enabled; + drm_modeset_unlock(&crtc->mutex); get_seq->sequence =3D drm_vblank_count_and_time(dev, pipe, &now); get_seq->sequence_ns =3D timespec_to_ns(&now); if (!vblank_enabled) >> + /* Check for valid signal edge */ >> + if (!(flags & DRM_CRTC_SEQUENCE_FIRST_PIXEL_OUT)) >> + return -EINVAL; > > This seems new, maybe drop it until we need it? It's part of Vulkan, so I want to expose it in the kernel API. And, making sure user-space isn't setting unexpected bits seems like a good idea. > drm_crtc_vblank_get pls, would be sweet if we can avoid the (dev, pipe) > pairs as much as possible. Same for all the others. Sure. I'll note that this is just a wrapper around drm_vblank_get/put at this point :-) > I think here there's no need for the accurate version, since we > force-enable the vblanks already. Agreed. >> + e->pipe =3D pipe; >> + e->event.base.type =3D DRM_EVENT_CRTC_SEQUENCE; >> + e->event.base.length =3D sizeof(e->event.seq); >> + e->event.seq.user_data =3D queue_seq->user_data; > > No need for crtc_id in this event? Or do we expect userspace to encode > that in the user_data somehow? I feared changing the size of the event and so I left that out. And, yes, userspace will almost certainly encode a pointer in the user_data, which can include whatever information it needs. > But might be useful just for consistency. This would require making the event larger, which seems like a bad idea... >> +#define DRM_CRTC_SEQUENCE_FIRST_PIXEL_OUT 0x00000004 /* Signal when fir= st pixel is displayed */ > > I thought this is already the semantics our current vblank events have (in > the timestamp, when exactly the event comes out isn't defined further than > "somewhere around vblank"). Since it's unsed I'd just remove this > #define. Vulkan has this single define, but may have more in the future so I wanted to make sure the application was able to tell if the kernel supported new modes if/when they appear. Reliably returning -EINVAL today when the application asks for something which isn't supported seems like good practice. > In both ioctl handlers pls make sure everything you don't look at is 0, > including unused stuff like pad. Otherwise userspace might fail to clear > them, and we can never use them in the future. Maybe just rename pad to > flags right away. Good idea. Above, you asked me to return whether the crtc was active in the get_sequence ioctl; I suggested putting that in the existing pad field, which would leave the whole structure defined. I've got tiny patches for each piece which I've stuck on my drm-sequence-64 branch at git://people.freedesktop.org/~keithp/linux.git drm-sequence-64 Most of those are included above, with the exception of the drm_crtc_vblank_get/put changes. Thanks much for your careful review. =2D-=20 =2Dkeith --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEw4O3eCVWE9/bQJ2R2yIaaQAAABEFAlleZN8ACgkQ2yIaaQAA ABHU7A/9G70gwwHHN2bOWDClUAVM69Qov1pd2I/ec/j/AybBqKffm0qpyH/1sIpx 5z+uXrUfpIU6ts+AHnbQNWB/yghk1wlY5xrJP/w65UxoJTLdpDn6Gb8AJmDLyyJy VrEOfi/whXR9AggLJCncpfzF9BGiE7qyizJ/3cBrr6msrpPqY/zx1yy+MYBIdJ7E gf73UDU5N6480BPUrPqxyZ2UpGUIbqAIbtfVANB5NtgF2C0Xc6CSqltsVRLP6T0X wLeiytv9DUaZ0cKdoqod3g9CyoW1bkm1CLSsGkGczSUDJAm2+hJoEiclfS/Ka+DD s+GR5GeZf3NxKcWzqexmztazRLF7Znmg2wwu+uaN7XBdKTWXKcFoJ2LBivonZpjX e5x9nFV+gxyj1+CjiwmWFbTEjT1BM07vHjDyWd8b2NQxDtYkROrHLtemqbrFB2Oy n312/z0HxddwWqsHjGpR6NhuDzD4xd+awUzvtbjPH2LqVbXKEfeRRJD7fUGNvUHy oj3vPUPaecd6OtmMFe6tPLN7BIKRn7IVIGqKPWwpx6qwU75ZFxSztPDBiwoYiGTW k8wMuSJnDmnVizjPEGRAaOfHplB5d3AuQe/RtNNb4XHVgpVTgyePdglHm/UHKt7n Y4MPM24q1IDSYszd9RHFNH9MCXOC3Qz4AhAJN/lyjKR+7duMlek= =r1hF -----END PGP SIGNATURE----- --=-=-=--