Skip to contentSkip to conversation

drm/i915: rc6 residency (fix the fix)

PATCH Applied Ben Widawsky 3 participants 10 messages Apr 20, 2012 – Apr 23, 2012

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

PATCH 1/1 drm/i915: rc6 residency (fix the fix)

Chris' fix for my 32b breakage was incorrect. do_div returns a remainder. Go back to a divide macro which is more 32b friendly.

Tested on x86-64.

This has only been compile tested on 32b systems.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48756

---
 drivers/gpu/drm/i915/i915_sysfs.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_sysfs.c +2 -2
index f1b5108..bd6350b 100644
@@ -39,8 +39,8 @@ static u32 calc_residency(struct drm_device *dev, const u32 reg)
 	if (!intel_enable_rc6(dev))
 		return 0;
 
-	raw_time = I915_READ(reg) * 128ULL + 500;
-	return do_div(raw_time, 100000);
+	raw_time = I915_READ(reg) * 128ULL;
+	return DIV_ROUND_UP_ULL(raw_time, 1000) / 100;
 }
 
 static ssize_t
Signature · 1 line
1.7.10
#1 lore raw
Quoted 10 lines · Ben Widawsky

Chris' fix for my 32b breakage was incorrect. do_div returns a remainder. Go back to a divide macro which is more 32b friendly.

Tested on x86-64.

This has only been compile tested on 32b systems.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48756

Sincere-apologies: Chris Wilson <[email protected]>

Had I looked for the equivalent 64bit DIV_ROUND_UP, I could have saved myself some embarrassment.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#2 lore raw
Quoted 8 lines · Chris Wilson
Quoted 7 lines · Ben Widawsky

Chris' fix for my 32b breakage was incorrect. do_div returns a remainder. Go back to a divide macro which is more 32b friendly.

Tested on x86-64.

This has only been compile tested on 32b systems.

Quoted 7 lines
Quoted 3 lines

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48756

Sincere-apologies: Chris Wilson <[email protected]>

Had I looked for the equivalent 64bit DIV_ROUND_UP, I could have saved myself some embarrassment.

Queued for -next, thanks for the patch.
-Daniel

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#3 lore raw
In reply to Ben Widawsky
Quoted 6 lines · Ben Widawsky

Chris' fix for my 32b breakage was incorrect. do_div returns a remainder. Go back to a divide macro which is more 32b friendly.

Tested on x86-64.

This has only been compile tested on 32b systems.

Doesn't compile on my 32-bit systems.

Still does a 64-bit divide.

Quoted 12 lines

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48756

---
 drivers/gpu/drm/i915/i915_sysfs.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_sysfs.c +0 -0
index f1b5108..bd6350b 100644

drivers/gpu/drm/i915/i915_sysfs.c static u32 calc_residency(struct drm_device *dev, const u32 reg) · line 43

Quoted 7 lines
drivers/gpu/drm/i915/i915_sysfs.c +2 -2
@@ -39,8 +39,8 @@ static u32 calc_residency(struct drm_device *dev, const u32 reg)
 	if (!intel_enable_rc6(dev))
 		return 0;
 
-	raw_time = I915_READ(reg) * 128ULL + 500;
-	return do_div(raw_time, 100000);
+	raw_time = I915_READ(reg) * 128ULL;
+	return DIV_ROUND_UP_ULL(raw_time, 1000) / 100;

return (u32)DIV_ROUND_UP_ULL(raw_time, 1000) / 100; -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#4 lore raw
Quoted 11 lines · On Sun, 22 Apr 2012 16:49:53 +0100 Chris Wilson <[email protected]>…
Quoted 6 lines · Ben Widawsky

Chris' fix for my 32b breakage was incorrect. do_div returns a remainder. Go back to a divide macro which is more 32b friendly.

Tested on x86-64.

This has only been compile tested on 32b systems.

Doesn't compile on my 32-bit systems.

Still does a 64-bit divide.

This is weird. I don't understand what's broken exactly. It should be dividing an unsigned long long, which the 32b compiler should have no issue with. The macro itself expands to do_div which was your original fix.

What is the error message you get?

Quoted 23 lines
Quoted 13 lines

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48756

---
 drivers/gpu/drm/i915/i915_sysfs.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_sysfs.c index f1b5108..bd6350b 100644

drivers/gpu/drm/i915/i915_sysfs.c static u32 calc_residency(struct drm_device *dev, · line 43

Quoted 7 lines
drivers/gpu/drm/i915/i915_sysfs.c +2 -2
@@ -39,8 +39,8 @@ static u32 calc_residency(struct drm_device *dev,
 const u32 reg) if (!intel_enable_rc6(dev))
 		return 0;
 
-	raw_time = I915_READ(reg) * 128ULL + 500;
-	return do_div(raw_time, 100000);
+	raw_time = I915_READ(reg) * 128ULL;
+	return DIV_ROUND_UP_ULL(raw_time, 1000) / 100;

return (u32)DIV_ROUND_UP_ULL(raw_time, 1000) / 100; -Chris

#5 lore raw
Quoted 13 lines · Ben Widawsky
Quoted 10 lines · On Sun, 22 Apr 2012 16:49:53 +0100 Chris Wilson <[email protected]>…
Quoted 6 lines · Ben Widawsky

Chris' fix for my 32b breakage was incorrect. do_div returns a remainder. Go back to a divide macro which is more 32b friendly.

Tested on x86-64.

This has only been compile tested on 32b systems.

Doesn't compile on my 32-bit systems.

Quoted 8 lines
Quoted 1 line

Still does a 64-bit divide.

This is weird. I don't understand what's broken exactly. It should be dividing an unsigned long long, which the 32b compiler should have no issue with. The macro itself expands to do_div which was your original fix.

What is the error message you get?

Undefined reference to __udivid3.

The reason is that the result of DIV_ROUND_UP_ULL is a 64-bit value, which we then proceed to divide by 100.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#6 lore raw
Quoted 22 lines · On Sun, 22 Apr 2012 18:39:23 +0100 Chris Wilson <[email protected]>…
Quoted 20 lines · Ben Widawsky
Quoted 11 lines · On Sun, 22 Apr 2012 16:49:53 +0100 Chris Wilson <[email protected]>…
Quoted 6 lines · Ben Widawsky

Chris' fix for my 32b breakage was incorrect. do_div returns a remainder. Go back to a divide macro which is more 32b friendly.

Tested on x86-64.

This has only been compile tested on 32b systems.

Doesn't compile on my 32-bit systems.

Still does a 64-bit divide.

This is weird. I don't understand what's broken exactly. It should be dividing an unsigned long long, which the 32b compiler should have no issue with. The macro itself expands to do_div which was your original fix.

Quoted 7 lines
Quoted 1 line

What is the error message you get?

Undefined reference to __udivid3.

The reason is that the result of DIV_ROUND_UP_ULL is a 64-bit value, which we then proceed to divide by 100.
-Chris

Does div_round64 work for you? I think that is the best solution.

#7 lore raw
Quoted 1 line · Ben Widawsky

Does div_round64 work for you? I think that is the best solution.

Only exists in drivers/cpuidle/governors/menu.c, and still would need a do_div to avoid the subsequent 64-bit division.

The choice appears to be either perform the divide by 1000 using do_div, or note that a u32 * 128 / 1000 is also a u32 and so cast the result of DIV_ROUND_UP_ULL back to u32.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#8 lore raw
In reply to Chris Wilson
Quoted 22 lines · On Sun, 22 Apr 2012 18:39:23 +0100 Chris Wilson <[email protected]>…
Quoted 20 lines · Ben Widawsky
Quoted 11 lines · On Sun, 22 Apr 2012 16:49:53 +0100 Chris Wilson <[email protected]>…
Quoted 6 lines · Ben Widawsky

Chris' fix for my 32b breakage was incorrect. do_div returns a remainder. Go back to a divide macro which is more 32b friendly.

Tested on x86-64.

This has only been compile tested on 32b systems.

Doesn't compile on my 32-bit systems.

Still does a 64-bit divide.

This is weird. I don't understand what's broken exactly. It should be dividing an unsigned long long, which the 32b compiler should have no issue with. The macro itself expands to do_div which was your original fix.

Quoted 7 lines
Quoted 1 line

What is the error message you get?

Undefined reference to __udivid3.

The reason is that the result of DIV_ROUND_UP_ULL is a 64-bit value, which we then proceed to divide by 100.
-Chris

For the sake of picking nits, this is a linker fail, not a compiler one. The only reason I make note of it is I was only compiling the .ko when I did my testing.

So lesson learned, can't we just:

drivers/gpu/drm/i915/i915_sysfs.c +1 -1
index bd6350b..79f8344 100644
@@ -40,7 +40,7 @@ static u32 calc_residency(struct drm_device *dev, const u32 reg)
                return 0;
 
        raw_time = I915_READ(reg) * 128ULL;
-       return DIV_ROUND_UP_ULL(raw_time, 1000) / 100;
+       return DIV_ROUND_UP_ULL(raw_time, 100000);
 }
 
 static ssize_t
#9 lore raw
Quoted 33 lines · Ben Widawsky
Quoted 22 lines · On Sun, 22 Apr 2012 18:39:23 +0100 Chris Wilson <[email protected]>…
Quoted 20 lines · Ben Widawsky
Quoted 11 lines · On Sun, 22 Apr 2012 16:49:53 +0100 Chris Wilson <[email protected]>…
Quoted 6 lines · Ben Widawsky

Chris' fix for my 32b breakage was incorrect. do_div returns a remainder. Go back to a divide macro which is more 32b friendly.

Tested on x86-64.

This has only been compile tested on 32b systems.

Doesn't compile on my 32-bit systems.

Still does a 64-bit divide.

This is weird. I don't understand what's broken exactly. It should be dividing an unsigned long long, which the 32b compiler should have no issue with. The macro itself expands to do_div which was your original fix.

Quoted 7 lines
Quoted 1 line

What is the error message you get?

Undefined reference to __udivid3.

The reason is that the result of DIV_ROUND_UP_ULL is a 64-bit value, which we then proceed to divide by 100.
-Chris

Quoted 5 lines

For the sake of picking nits, this is a linker fail, not a compiler one. The only reason I make note of it is I was only compiling the .ko when I did my testing.

So lesson learned, can't we just:

Done.
-Daniel

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48