Skip to contentSkip to conversation

drm/vblank: Simplify drm_dev_has_vblank()

PATCH In review Rob Clark 4 participants 6 messages Apr 3, 2023 – Apr 5, 2023

Subsystems (2)
lore
Share & tools
lore

Rob Clark

author
#0 lore raw

PATCH 1/1 drm/vblank: Simplify drm_dev_has_vblank()

From: Rob Clark <[email protected]>

What does vblank have to do with num_crtcs? Well, this was technically correct, but you'd have to go look at where num_crtcs is initialized to understand why. Lets just replace it with the simpler and more obvious check.

---
 drivers/gpu/drm/drm_vblank.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_vblank.c +1 -1
index 877e2067534f..ad34c235d853 100644
@@ -575,7 +575,7 @@ EXPORT_SYMBOL(drm_vblank_init);
  */
 bool drm_dev_has_vblank(const struct drm_device *dev)
 {
-	return dev->num_crtcs != 0;
+	return !!dev->vblank;
 }
 EXPORT_SYMBOL(drm_dev_has_vblank);
 
Signature · 1 line
2.39.2
#1 lore raw
Quoted 17 lines · Rob Clark

From: Rob Clark <[email protected]>

What does vblank have to do with num_crtcs? Well, this was technically correct, but you'd have to go look at where num_crtcs is initialized to understand why. Lets just replace it with the simpler and more obvious check.

---
 drivers/gpu/drm/drm_vblank.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_vblank.c +0 -0
index 877e2067534f..ad34c235d853 100644

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_vblank_init); · line 578

Quoted 5 lines
drivers/gpu/drm/drm_vblank.c +1 -1
@@ -575,7 +575,7 @@ EXPORT_SYMBOL(drm_vblank_init);
  */
 bool drm_dev_has_vblank(const struct drm_device *dev)
 {
-	return dev->num_crtcs != 0;
+	return !!dev->vblank;

The compiler knows how to turn things into a boolean.

Or I guess if we want to be a bit more explicit we could write this as
return dev->vblank != NULL;
but IIRC that will make checkpatch complain because of someone's personal taste.

Quoted 5 lines
drivers/gpu/drm/drm_vblank.c +0 -0
 }
 EXPORT_SYMBOL(drm_dev_has_vblank);
 
Signature · 1 line
2.39.2
Signature · 2 lines
Ville Syrjälä
Intel
#2 lore raw
Quoted 25 lines · Ville Syrjälä
Quoted 17 lines · Rob Clark

From: Rob Clark <[email protected]>

What does vblank have to do with num_crtcs? Well, this was technically correct, but you'd have to go look at where num_crtcs is initialized to understand why. Lets just replace it with the simpler and more obvious check.

---
 drivers/gpu/drm/drm_vblank.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_vblank.c +0 -0
index 877e2067534f..ad34c235d853 100644

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_vblank_init); · line 578

Quoted 5 lines
drivers/gpu/drm/drm_vblank.c +1 -1
@@ -575,7 +575,7 @@ EXPORT_SYMBOL(drm_vblank_init);
  */
 bool drm_dev_has_vblank(const struct drm_device *dev)
 {
-	return dev->num_crtcs != 0;
+	return !!dev->vblank;

The compiler knows how to turn things into a boolean.

Quoted 5 lines
Quoted 1 line

Or I guess if we want to be a bit more explicit we could

write this as
return dev->vblank != NULL;
but IIRC that will make checkpatch complain because of someone's personal taste.

checkpatch isn't an absolute thing. :)

Signature · 1 line
~Randy
#3 lore raw
In reply to Rob Clark
Quoted 6 lines · Rob Clark

From: Rob Clark <[email protected]>

What does vblank have to do with num_crtcs? Well, this was technically correct, but you'd have to go look at where num_crtcs is initialized to understand why. Lets just replace it with the simpler and more obvious check.

If you want to fix this, then I think the right fix is to rename num_crtcs to be something like num_vblank_crtcs. It's a historical accident back when vblanks without kms was a thing.

Plan B is someone gets really busy and fixes up the entire vblank mess and moves it into drm_crtc struct. Now that the dri1 drivers are gone we could indeed do that.

Or maybe instead a patch to improve the kerneldoc for drm_dev->num_crtc? -Daniel

Quoted 21 lines
---
 drivers/gpu/drm/drm_vblank.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_vblank.c +1 -1
index 877e2067534f..ad34c235d853 100644
@@ -575,7 +575,7 @@ EXPORT_SYMBOL(drm_vblank_init);
  */
 bool drm_dev_has_vblank(const struct drm_device *dev)
 {
-	return dev->num_crtcs != 0;
+	return !!dev->vblank;
 }
 EXPORT_SYMBOL(drm_dev_has_vblank);
 
Signature · 1 line
2.39.2
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#4 lore raw
Quoted 8 lines · Daniel Vetter
Quoted 6 lines · Rob Clark

From: Rob Clark <[email protected]>

What does vblank have to do with num_crtcs? Well, this was technically correct, but you'd have to go look at where num_crtcs is initialized to understand why. Lets just replace it with the simpler and more obvious check.

Quoted 7 lines

If you want to fix this, then I think the right fix is to rename num_crtcs to be something like num_vblank_crtcs. It's a historical accident back when vblanks without kms was a thing.

Plan B is someone gets really busy and fixes up the entire vblank mess and moves it into drm_crtc struct. Now that the dri1 drivers are gone we could indeed do that.

And easy first step could to simply wrap all the naked &dev->vblank[drm_crtc_index()] things into a function call with some cocci/etc. That way most of the vblank code doesn't need to care where that thing actually lives.

Signature · 2 lines
Ville Syrjälä
Intel
#5 lore raw
Quoted 13 lines · Ville Syrjälä
Quoted 12 lines · Daniel Vetter
Quoted 6 lines · Rob Clark

From: Rob Clark <[email protected]>

What does vblank have to do with num_crtcs? Well, this was technically correct, but you'd have to go look at where num_crtcs is initialized to understand why. Lets just replace it with the simpler and more obvious check.

If you want to fix this, then I think the right fix is to rename num_crtcs to be something like num_vblank_crtcs. It's a historical accident back when vblanks without kms was a thing.

Quoted 8 lines
Quoted 3 lines

Plan B is someone gets really busy and fixes up the entire vblank mess and moves it into drm_crtc struct. Now that the dri1 drivers are gone we could indeed do that.

And easy first step could to simply wrap all the naked &dev->vblank[drm_crtc_index()] things into a function call with some cocci/etc. That way most of the vblank code doesn't need to care where that thing actually lives.

Yeah I think that might work out. Roughly:
- Wrap all the drm_vblank_crtc lookups
- Emebed it into drm_crtc, delete the drm_device->vblank array
- rename drm_device->num_crtc to something more meaningful maybe and move into drm_modeset_config

The big holdup always was step 2 because we still had to care about legacy drivers without drm_crtc, which meant you'd have to have two paths, which was kinda really annoying.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch