Skip to contentSkip to conversation

radeon/PM Really wait for vblank before reclocking

PATCH In review Jaime Velasco Juan 3 participants 6 messages Feb 15, 2010 – Feb 17, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 radeon/PM Really wait for vblank before reclocking

The old code used a false condition so it always waited until timeout

---
 drivers/gpu/drm/radeon/radeon_pm.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/radeon/radeon_pm.c +6 -4
index a8e151e..842952f 100644
@@ -337,10 +337,12 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
 		rdev->pm.req_vblank |= (1 << 1);
 		drm_vblank_get(rdev->ddev, 1);
 	}
-	if (rdev->pm.active_crtcs)
-		wait_event_interruptible_timeout(
-			rdev->irq.vblank_queue, 0,
-			msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT));
+	if (rdev->pm.active_crtcs) {
+		long timeout = msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT);
+		__wait_event_interruptible_timeout(
+			rdev->irq.vblank_queue, 1,
+			timeout);
+	}
 	if (rdev->pm.req_vblank & (1 << 0)) {
 		rdev->pm.req_vblank &= ~(1 << 0);
 		drm_vblank_put(rdev->ddev, 0);
Signature · 8 lines
1.6.6.1


------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
--
#1 lore raw

2010/2/15 Jaime Velasco Juan <[email protected]>:

Quoted 16 lines

The old code used a false condition so it always waited until timeout

---
 drivers/gpu/drm/radeon/radeon_pm.c |   10 ++++++----

 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/radeon/radeon_pm.c +0 -0
index a8e151e..842952f 100644
@@ -337,10 +337,12 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
                rdev->pm.req_vblank |= (1 << 1);
                drm_vblank_get(rdev->ddev, 1);
        }

drivers/gpu/drm/radeon/radeon_pm.c static void radeon_pm_set_clocks(struct radeon_device *rdev) · line 345

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_pm.c +6 -4
-       if (rdev->pm.active_crtcs)
-               wait_event_interruptible_timeout(
-                       rdev->irq.vblank_queue, 0,
-                       msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT));
+       if (rdev->pm.active_crtcs) {
+               long timeout = msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT);
+               __wait_event_interruptible_timeout(
+                       rdev->irq.vblank_queue, 1,
+                       timeout);
+       }

Yeah, it seems logic was wrong, thanks.

Two questions: is there some real reason for using "timeout" variable? We don't re-use this anywhere. It seems useless, doesn't make code shorter, forces braces usage and you defined this inside braces, not on beginning of function, as kernel coding style says. Can you just drop this redundant variable?

Second: could you say what is "better" in using __wait_event_interruptible_timeout? Is this faster (doesn't check condition) or something?

Signature · 11 lines
Rafał

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel
#2 lore raw
Quoted 36 lines · Rafał Miłecki

2010/2/15 Jaime Velasco Juan <[email protected]>:

Quoted 16 lines

The old code used a false condition so it always waited until timeout

---
 drivers/gpu/drm/radeon/radeon_pm.c |   10 ++++++----

 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/radeon/radeon_pm.c +0 -0
index a8e151e..842952f 100644
@@ -337,10 +337,12 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
                rdev->pm.req_vblank |= (1 << 1);
                drm_vblank_get(rdev->ddev, 1);
        }

drivers/gpu/drm/radeon/radeon_pm.c static void radeon_pm_set_clocks(struct radeon_device *rdev) · line 345

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_pm.c +6 -4
-       if (rdev->pm.active_crtcs)
-               wait_event_interruptible_timeout(
-                       rdev->irq.vblank_queue, 0,
-                       msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT));
+       if (rdev->pm.active_crtcs) {
+               long timeout = msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT);
+               __wait_event_interruptible_timeout(
+                       rdev->irq.vblank_queue, 1,
+                       timeout);
+       }

Yeah, it seems logic was wrong, thanks.

Two questions: is there some real reason for using "timeout" variable? We don't re-use this anywhere. It seems useless, doesn't make code shorter, forces braces usage and you defined this inside braces, not on beginning of function, as kernel coding style says. Can you just drop this redundant variable?

Quoted 4 lines

Second: could you say what is "better" in using __wait_event_interruptible_timeout? Is this faster (doesn't check condition) or something?

I just took the code from the definition of wait_event_interruptible_timeout; that macro checks the condition before calling __wait_event_interruptible_timeout, where the task really goes to sleep, but __wait_event_interruptible_timeout changes the timeout parameter, so it needs to be a variable. I just tried to do the smallest change to the code. It's true that almost nobody else use this macro directly.

Even with this, I still see some ocasional glitches when reclocking the engine, but this does not stall rendering for 200ms as before (it was very noticeable). This has nothing to do with this patch, but is it really needed to take cp.mutex in radeon_pm_set_clocks? I've been doing some testing without doing it and it doesn't seem to break anything.

Regards

Quoted 2 lines
Signature · 1 line
Rafał

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel

#3 lore raw

2010/2/16 Jaime Velasco Juan <[email protected]>:

Quoted 48 lines · Rafał Miłecki
Quoted 36 lines

2010/2/15 Jaime Velasco Juan <[email protected]>:

Quoted 16 lines

The old code used a false condition so it always waited until timeout

---
 drivers/gpu/drm/radeon/radeon_pm.c |   10 ++++++----

 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/radeon/radeon_pm.c +0 -0
index a8e151e..842952f 100644
@@ -337,10 +337,12 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
                rdev->pm.req_vblank |= (1 << 1);
                drm_vblank_get(rdev->ddev, 1);
        }

drivers/gpu/drm/radeon/radeon_pm.c static void radeon_pm_set_clocks(struct radeon_device *rdev) · line 345

Quoted 10 lines
drivers/gpu/drm/radeon/radeon_pm.c +6 -4
-       if (rdev->pm.active_crtcs)
-               wait_event_interruptible_timeout(
-                       rdev->irq.vblank_queue, 0,
-                       msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT));
+       if (rdev->pm.active_crtcs) {
+               long timeout = msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT);
+               __wait_event_interruptible_timeout(
+                       rdev->irq.vblank_queue, 1,
+                       timeout);
+       }

Yeah, it seems logic was wrong, thanks.

Two questions: is there some real reason for using "timeout" variable? We don't re-use this anywhere. It seems useless, doesn't make code shorter, forces braces usage and you defined this inside braces, not on beginning of function, as kernel coding style says. Can you just drop this redundant variable?

Quoted 4 lines

Second: could you say what is "better" in using __wait_event_interruptible_timeout? Is this faster (doesn't check condition) or something?

I just took the code from the definition of wait_event_interruptible_timeout; that macro checks the condition before calling __wait_event_interruptible_timeout, where the task really goes to sleep, but __wait_event_interruptible_timeout changes the timeout parameter, so it needs to be a variable. I just tried to do the smallest change to the code. It's true that almost nobody else use this macro directly.

Quoted 6 lines

Even with this, I still see some ocasional glitches when reclocking the engine, but this does not stall rendering for 200ms as before (it was very noticeable). This has nothing to do with this patch, but is it really needed to take cp.mutex in radeon_pm_set_clocks? I've been doing some testing without doing it and it doesn't seem to break anything.

You generally don't want to change the clock while the engine using it is active.

Alex

Quoted 4 lines

Regards

Quoted 2 lines

--
Rafał

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel

#4 lore raw
In reply to Rafał Miłecki
Quoted 21 lines · W dniu 15 lutego 2010 18:52 użytkownik Rafał Miłecki <[email protected]> napisał:

2010/2/15 Jaime Velasco Juan <[email protected]>:

Quoted 20 lines

The old code used a false condition so it always waited until timeout

---
 drivers/gpu/drm/radeon/radeon_pm.c |   10 ++++++----

 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/radeon/radeon_pm.c +0 -4
index a8e151e..842952f 100644
@@ -337,10 +337,12 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
                rdev->pm.req_vblank |= (1 << 1);
                drm_vblank_get(rdev->ddev, 1);
        }
-       if (rdev->pm.active_crtcs)
-               wait_event_interruptible_timeout(
-                       rdev->irq.vblank_queue, 0,
-                       msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT));
Quoted 8 lines

drivers/gpu/drm/radeon/radeon_pm.c static void radeon_pm_set_clocks(struct radeon_device *rdev) · line 345

Quoted 6 lines
drivers/gpu/drm/radeon/radeon_pm.c +6 -0
+       if (rdev->pm.active_crtcs) {
+               long timeout = msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT);
+               __wait_event_interruptible_timeout(
+                       rdev->irq.vblank_queue, 1,
+                       timeout);
+       }

Yeah, it seems logic was wrong, thanks.

To make it clear (I didn't understand that correctly earlier):

include/linux/wait.h:
wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses

So using your __ prefix and "1" as condition argument is some hack that could work indeed...

But maybe there is some "real" kernel function that simply waits for wake_up with timeout?

Signature · 11 lines
Rafał

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel
#5 lore raw
Quoted 37 lines · W dniu 17 lutego 2010 19:22 użytkownik Rafał Miłecki <[email protected]> napisał:
Quoted 21 lines · W dniu 15 lutego 2010 18:52 użytkownik Rafał Miłecki <[email protected]> napisał:

2010/2/15 Jaime Velasco Juan <[email protected]>:

Quoted 20 lines

The old code used a false condition so it always waited until timeout

---
 drivers/gpu/drm/radeon/radeon_pm.c |   10 ++++++----

 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/radeon/radeon_pm.c +0 -4
index a8e151e..842952f 100644
@@ -337,10 +337,12 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev)
                rdev->pm.req_vblank |= (1 << 1);
                drm_vblank_get(rdev->ddev, 1);
        }
-       if (rdev->pm.active_crtcs)
-               wait_event_interruptible_timeout(
-                       rdev->irq.vblank_queue, 0,
-                       msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT));
Quoted 8 lines

drivers/gpu/drm/radeon/radeon_pm.c static void radeon_pm_set_clocks(struct radeon_device *rdev) · line 345

Quoted 6 lines
drivers/gpu/drm/radeon/radeon_pm.c +6 -0
+       if (rdev->pm.active_crtcs) {
+               long timeout = msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT);
+               __wait_event_interruptible_timeout(
+                       rdev->irq.vblank_queue, 1,
+                       timeout);
+       }

Yeah, it seems logic was wrong, thanks.

To make it clear (I didn't understand that correctly earlier):

include/linux/wait.h:
wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses

Quoted 5 lines

So using your __ prefix and "1" as condition argument is some hack that could work indeed...

But maybe there is some "real" kernel function that simply waits for wake_up with timeout?

Your solution doesn't work because __wait_event_interruptible checks once more for condition before scheduling. If finds "1" and so it breaks loop immediately.

Signature · 11 lines
Rafał

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel