diff mbox series

[v2,04/22] drm: Don't test for IRQ support in VBLANK ioctls

Message ID 20210622141002.11590-5-tzimmermann@suse.de (mailing list archive)
State New, archived
Headers show
Series Deprecate struct drm_device.irq_enabled | expand

Commit Message

Thomas Zimmermann June 22, 2021, 2:09 p.m. UTC
For KMS drivers, replace the IRQ check in VBLANK ioctls with a check for
vblank support. IRQs might be enabled wthout vblanking being supported.

This change also removes the DRM framework's only dependency on IRQ state
for non-legacy drivers. For legacy drivers with userspace modesetting,
the original test remains in drm_wait_vblank_ioctl().

v2:
	* keep the old test for legacy drivers in
	  drm_wait_vblank_ioctl() (Daniel)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_irq.c    | 10 +++-------
 drivers/gpu/drm/drm_vblank.c | 13 +++++++++----
 2 files changed, 12 insertions(+), 11 deletions(-)

Comments

Liviu Dudau June 22, 2021, 3:25 p.m. UTC | #1
Hello,

On Tue, Jun 22, 2021 at 04:09:44PM +0200, Thomas Zimmermann wrote:
> For KMS drivers, replace the IRQ check in VBLANK ioctls with a check for
> vblank support. IRQs might be enabled wthout vblanking being supported.
> 
> This change also removes the DRM framework's only dependency on IRQ state
> for non-legacy drivers. For legacy drivers with userspace modesetting,
> the original test remains in drm_wait_vblank_ioctl().
> 
> v2:
> 	* keep the old test for legacy drivers in
> 	  drm_wait_vblank_ioctl() (Daniel)
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
>  drivers/gpu/drm/drm_irq.c    | 10 +++-------
>  drivers/gpu/drm/drm_vblank.c | 13 +++++++++----
>  2 files changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index c3bd664ea733..1d7785721323 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -74,10 +74,8 @@
>   * only supports devices with a single interrupt on the main device stored in
>   * &drm_device.dev and set as the device paramter in drm_dev_alloc().
>   *
> - * These IRQ helpers are strictly optional. Drivers which roll their own only
> - * need to set &drm_device.irq_enabled to signal the DRM core that vblank
> - * interrupts are working. Since these helpers don't automatically clean up the
> - * requested interrupt like e.g. devm_request_irq() they're not really
> + * These IRQ helpers are strictly optional. Since these helpers don't automatically
> + * clean up the requested interrupt like e.g. devm_request_irq() they're not really
>   * recommended.
>   */
>  
> @@ -91,9 +89,7 @@
>   * and after the installation.
>   *
>   * This is the simplified helper interface provided for drivers with no special
> - * needs. Drivers which need to install interrupt handlers for multiple
> - * interrupts must instead set &drm_device.irq_enabled to signal the DRM core
> - * that vblank interrupts are available.
> + * needs.
>   *
>   * @irq must match the interrupt number that would be passed to request_irq(),
>   * if called directly instead of using this helper function.
> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> index 3417e1ac7918..a98a4aad5037 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -1748,8 +1748,13 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
>  	unsigned int pipe_index;
>  	unsigned int flags, pipe, high_pipe;
>  
> -	if (!dev->irq_enabled)
> -		return -EOPNOTSUPP;
> +	if  (drm_core_check_feature(dev, DRIVER_MODESET)) {
> +		if (!drm_dev_has_vblank(dev))
> +			return -EOPNOTSUPP;
> +	} else {
> +		if (!dev->irq_enabled)
> +			return -EOPNOTSUPP;
> +	}

For a system call that is used quite a lot by userspace we have increased the code size
in a noticeable way. Can we not cache it privately?

Best regards,
Liviu

>  
>  	if (vblwait->request.type & _DRM_VBLANK_SIGNAL)
>  		return -EINVAL;
> @@ -2023,7 +2028,7 @@ int drm_crtc_get_sequence_ioctl(struct drm_device *dev, void *data,
>  	if (!drm_core_check_feature(dev, DRIVER_MODESET))
>  		return -EOPNOTSUPP;
>  
> -	if (!dev->irq_enabled)
> +	if (!drm_dev_has_vblank(dev))
>  		return -EOPNOTSUPP;
>  
>  	crtc = drm_crtc_find(dev, file_priv, get_seq->crtc_id);
> @@ -2082,7 +2087,7 @@ int drm_crtc_queue_sequence_ioctl(struct drm_device *dev, void *data,
>  	if (!drm_core_check_feature(dev, DRIVER_MODESET))
>  		return -EOPNOTSUPP;
>  
> -	if (!dev->irq_enabled)
> +	if (!drm_dev_has_vblank(dev))
>  		return -EOPNOTSUPP;
>  
>  	crtc = drm_crtc_find(dev, file_priv, queue_seq->crtc_id);
> -- 
> 2.32.0
>
Thomas Zimmermann June 23, 2021, 6:43 a.m. UTC | #2
Hi Liviu

Am 22.06.21 um 17:25 schrieb Liviu Dudau:
> Hello,
> 
> On Tue, Jun 22, 2021 at 04:09:44PM +0200, Thomas Zimmermann wrote:
>> For KMS drivers, replace the IRQ check in VBLANK ioctls with a check for
>> vblank support. IRQs might be enabled wthout vblanking being supported.
>>
>> This change also removes the DRM framework's only dependency on IRQ state
>> for non-legacy drivers. For legacy drivers with userspace modesetting,
>> the original test remains in drm_wait_vblank_ioctl().
>>
>> v2:
>> 	* keep the old test for legacy drivers in
>> 	  drm_wait_vblank_ioctl() (Daniel)
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>> ---
>>   drivers/gpu/drm/drm_irq.c    | 10 +++-------
>>   drivers/gpu/drm/drm_vblank.c | 13 +++++++++----
>>   2 files changed, 12 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
>> index c3bd664ea733..1d7785721323 100644
>> --- a/drivers/gpu/drm/drm_irq.c
>> +++ b/drivers/gpu/drm/drm_irq.c
>> @@ -74,10 +74,8 @@
>>    * only supports devices with a single interrupt on the main device stored in
>>    * &drm_device.dev and set as the device paramter in drm_dev_alloc().
>>    *
>> - * These IRQ helpers are strictly optional. Drivers which roll their own only
>> - * need to set &drm_device.irq_enabled to signal the DRM core that vblank
>> - * interrupts are working. Since these helpers don't automatically clean up the
>> - * requested interrupt like e.g. devm_request_irq() they're not really
>> + * These IRQ helpers are strictly optional. Since these helpers don't automatically
>> + * clean up the requested interrupt like e.g. devm_request_irq() they're not really
>>    * recommended.
>>    */
>>   
>> @@ -91,9 +89,7 @@
>>    * and after the installation.
>>    *
>>    * This is the simplified helper interface provided for drivers with no special
>> - * needs. Drivers which need to install interrupt handlers for multiple
>> - * interrupts must instead set &drm_device.irq_enabled to signal the DRM core
>> - * that vblank interrupts are available.
>> + * needs.
>>    *
>>    * @irq must match the interrupt number that would be passed to request_irq(),
>>    * if called directly instead of using this helper function.
>> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
>> index 3417e1ac7918..a98a4aad5037 100644
>> --- a/drivers/gpu/drm/drm_vblank.c
>> +++ b/drivers/gpu/drm/drm_vblank.c
>> @@ -1748,8 +1748,13 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
>>   	unsigned int pipe_index;
>>   	unsigned int flags, pipe, high_pipe;
>>   
>> -	if (!dev->irq_enabled)
>> -		return -EOPNOTSUPP;
>> +	if  (drm_core_check_feature(dev, DRIVER_MODESET)) {
>> +		if (!drm_dev_has_vblank(dev))
>> +			return -EOPNOTSUPP;
>> +	} else {
>> +		if (!dev->irq_enabled)
>> +			return -EOPNOTSUPP;
>> +	}
> 
> For a system call that is used quite a lot by userspace we have increased the code size
> in a noticeable way. Can we not cache it privately?

I'm not quite sure that I understand your concern. The additionally 
called functions are trivial one-liners; probably inlined anyway.

However, irq_enabled is only relevant for legacy drivers and will 
eventually disappear behind CONFIG_DRM_LEGACY. We can rewrite the test 
like this:

ifdef CONFIG_DRM_LEGACY
   if (unlikely(check_feature(dev, DRIVER_LEGACY))) {
     if (!irq_enabled)
       return;
   } else
#endif
   {
     if (!has_vblank_support(dev))
       return;
   }

As CONFIG_DRM_LEGACY is most likely disabled on concurrent systems, we'd 
get a single test for the modern drivers. If DRM_LEGACYis on, the 
compiler at least knows that the else branch is preferred.

Best regards
Thomas
Liviu Dudau June 23, 2021, 12:15 p.m. UTC | #3
Hi Thomas,

On Wed, Jun 23, 2021 at 08:43:07AM +0200, Thomas Zimmermann wrote:
> Hi Liviu
> 
> Am 22.06.21 um 17:25 schrieb Liviu Dudau:
> > Hello,
> > 
> > On Tue, Jun 22, 2021 at 04:09:44PM +0200, Thomas Zimmermann wrote:
> > > For KMS drivers, replace the IRQ check in VBLANK ioctls with a check for
> > > vblank support. IRQs might be enabled wthout vblanking being supported.
> > > 
> > > This change also removes the DRM framework's only dependency on IRQ state
> > > for non-legacy drivers. For legacy drivers with userspace modesetting,
> > > the original test remains in drm_wait_vblank_ioctl().
> > > 
> > > v2:
> > > 	* keep the old test for legacy drivers in
> > > 	  drm_wait_vblank_ioctl() (Daniel)
> > > 
> > > Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> > > ---
> > >   drivers/gpu/drm/drm_irq.c    | 10 +++-------
> > >   drivers/gpu/drm/drm_vblank.c | 13 +++++++++----
> > >   2 files changed, 12 insertions(+), 11 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> > > index c3bd664ea733..1d7785721323 100644
> > > --- a/drivers/gpu/drm/drm_irq.c
> > > +++ b/drivers/gpu/drm/drm_irq.c
> > > @@ -74,10 +74,8 @@
> > >    * only supports devices with a single interrupt on the main device stored in
> > >    * &drm_device.dev and set as the device paramter in drm_dev_alloc().
> > >    *
> > > - * These IRQ helpers are strictly optional. Drivers which roll their own only
> > > - * need to set &drm_device.irq_enabled to signal the DRM core that vblank
> > > - * interrupts are working. Since these helpers don't automatically clean up the
> > > - * requested interrupt like e.g. devm_request_irq() they're not really
> > > + * These IRQ helpers are strictly optional. Since these helpers don't automatically
> > > + * clean up the requested interrupt like e.g. devm_request_irq() they're not really
> > >    * recommended.
> > >    */
> > > @@ -91,9 +89,7 @@
> > >    * and after the installation.
> > >    *
> > >    * This is the simplified helper interface provided for drivers with no special
> > > - * needs. Drivers which need to install interrupt handlers for multiple
> > > - * interrupts must instead set &drm_device.irq_enabled to signal the DRM core
> > > - * that vblank interrupts are available.
> > > + * needs.
> > >    *
> > >    * @irq must match the interrupt number that would be passed to request_irq(),
> > >    * if called directly instead of using this helper function.
> > > diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> > > index 3417e1ac7918..a98a4aad5037 100644
> > > --- a/drivers/gpu/drm/drm_vblank.c
> > > +++ b/drivers/gpu/drm/drm_vblank.c
> > > @@ -1748,8 +1748,13 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
> > >   	unsigned int pipe_index;
> > >   	unsigned int flags, pipe, high_pipe;
> > > -	if (!dev->irq_enabled)
> > > -		return -EOPNOTSUPP;
> > > +	if  (drm_core_check_feature(dev, DRIVER_MODESET)) {
> > > +		if (!drm_dev_has_vblank(dev))
> > > +			return -EOPNOTSUPP;
> > > +	} else {
> > > +		if (!dev->irq_enabled)
> > > +			return -EOPNOTSUPP;
> > > +	}
> > 
> > For a system call that is used quite a lot by userspace we have increased the code size
> > in a noticeable way. Can we not cache it privately?
> 
> I'm not quite sure that I understand your concern. The additionally called
> functions are trivial one-liners; probably inlined anyway.

They are inlined. However we replace the pointer dereference (which can be calculated
at compile time as offset from a base pointer) with the code in
drm_core_check_all_features() that does 3 pointer dereferences, masking and logical
AND before checking for matching value.

> 
> However, irq_enabled is only relevant for legacy drivers and will eventually
> disappear behind CONFIG_DRM_LEGACY. We can rewrite the test like this:

I get the point that irq_enabled is legacy. However the IOCTL call is not and usually
is used in time critical code to wait for vblank before starting the old buffers for
a new frame. At 60Hz that's probably less of a concern, but at 120Hz refresh rate and
reduced vblank time your time slice allocation for new work matters.

Best regards,
Liviu

> 
> ifdef CONFIG_DRM_LEGACY
>   if (unlikely(check_feature(dev, DRIVER_LEGACY))) {
>     if (!irq_enabled)
>       return;
>   } else
> #endif
>   {
>     if (!has_vblank_support(dev))
>       return;
>   }
> 
> As CONFIG_DRM_LEGACY is most likely disabled on concurrent systems, we'd get
> a single test for the modern drivers. If DRM_LEGACYis on, the compiler at
> least knows that the else branch is preferred.
> 
> Best regards
> Thomas
> 
> -- 
> Thomas Zimmermann
> Graphics Driver Developer
> SUSE Software Solutions Germany GmbH
> Maxfeldstr. 5, 90409 Nürnberg, Germany
> (HRB 36809, AG Nürnberg)
> Geschäftsführer: Felix Imendörffer
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index c3bd664ea733..1d7785721323 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -74,10 +74,8 @@ 
  * only supports devices with a single interrupt on the main device stored in
  * &drm_device.dev and set as the device paramter in drm_dev_alloc().
  *
- * These IRQ helpers are strictly optional. Drivers which roll their own only
- * need to set &drm_device.irq_enabled to signal the DRM core that vblank
- * interrupts are working. Since these helpers don't automatically clean up the
- * requested interrupt like e.g. devm_request_irq() they're not really
+ * These IRQ helpers are strictly optional. Since these helpers don't automatically
+ * clean up the requested interrupt like e.g. devm_request_irq() they're not really
  * recommended.
  */
 
@@ -91,9 +89,7 @@ 
  * and after the installation.
  *
  * This is the simplified helper interface provided for drivers with no special
- * needs. Drivers which need to install interrupt handlers for multiple
- * interrupts must instead set &drm_device.irq_enabled to signal the DRM core
- * that vblank interrupts are available.
+ * needs.
  *
  * @irq must match the interrupt number that would be passed to request_irq(),
  * if called directly instead of using this helper function.
diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 3417e1ac7918..a98a4aad5037 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -1748,8 +1748,13 @@  int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
 	unsigned int pipe_index;
 	unsigned int flags, pipe, high_pipe;
 
-	if (!dev->irq_enabled)
-		return -EOPNOTSUPP;
+	if  (drm_core_check_feature(dev, DRIVER_MODESET)) {
+		if (!drm_dev_has_vblank(dev))
+			return -EOPNOTSUPP;
+	} else {
+		if (!dev->irq_enabled)
+			return -EOPNOTSUPP;
+	}
 
 	if (vblwait->request.type & _DRM_VBLANK_SIGNAL)
 		return -EINVAL;
@@ -2023,7 +2028,7 @@  int drm_crtc_get_sequence_ioctl(struct drm_device *dev, void *data,
 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
 		return -EOPNOTSUPP;
 
-	if (!dev->irq_enabled)
+	if (!drm_dev_has_vblank(dev))
 		return -EOPNOTSUPP;
 
 	crtc = drm_crtc_find(dev, file_priv, get_seq->crtc_id);
@@ -2082,7 +2087,7 @@  int drm_crtc_queue_sequence_ioctl(struct drm_device *dev, void *data,
 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
 		return -EOPNOTSUPP;
 
-	if (!dev->irq_enabled)
+	if (!drm_dev_has_vblank(dev))
 		return -EOPNOTSUPP;
 
 	crtc = drm_crtc_find(dev, file_priv, queue_seq->crtc_id);