Skip to contentSkip to conversation

drm/i915: avoid round-trip scaling errors in actual_brightness

RFC PATCH In review Jani Nikula 2 participants 4 messages Nov 20, 2014 – Dec 5, 2014

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

RFC PATCH 1/1 drm/i915: avoid round-trip scaling errors in actual_brightness

Due to scaling, the userspace and hardware brightness ranges might not have a 1:1 mapping, causing the backlight class sysfs actual_brightness not match the brightness attribute just written. While this is not a strict requirement per Documentation/ABI/stable/sysfs-class-backlight, try the userspace->hardware scaling for a match first and return the cached value to not confuse userspace.

The problem was already mitigated by

commit 673e7bbdb3920b62cfc6c710bea626b0a9b0f43a

Author: U. Artie Eoff <[email protected]>
Date:   Mon Sep 29 15:49:32 2014 -0700

drm/i915: intel_backlight scale() math WA

but this should be more robust for cases where the userspace expects actual_brightness to match the just written brightness.

Reference: http://mid.gmane.org/[email protected]
Reference: https://bugzilla.kernel.org/show_bug.cgi?id=85861

---
 drivers/gpu/drm/i915/intel_panel.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_panel.c +11 -1
index 4d63839bd9b4..675b56e105e7 100644
@@ -1024,7 +1024,17 @@ static int intel_backlight_device_get_brightness(struct backlight_device *bd)
 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 
 	hw_level = intel_panel_get_backlight(connector);
-	ret = scale_hw_to_user(connector, hw_level, bd->props.max_brightness);
+
+	/*
+	 * Check the userspace->hardware scaling for a match first to avoid
+	 * scaling errors in the userspace->hardware->userspace round-trip.
+	 */
+	if (hw_level == scale_user_to_hw(connector, bd->props.brightness,
+					 bd->props.max_brightness))
+		ret = bd->props.brightness;
+	else
+		ret = scale_hw_to_user(connector, hw_level,
+				       bd->props.max_brightness);
 
 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
 	intel_runtime_pm_put(dev_priv);
Signature · 6 lines
2.1.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Tested-by on v1 1/1
#1 lore raw
Quoted 22 lines

-----Original Message-----
From: Nikula, Jani
Sent: Thursday, November 20, 2014 3:59 AM
To: [email protected]
Cc: Nikula, Jani; Eoff, Ullysses A
Subject: [RFC PATCH] drm/i915: avoid round-trip scaling errors in actual_brightness

Due to scaling, the userspace and hardware brightness ranges might not have a 1:1 mapping, causing the backlight class sysfs actual_brightness not match the brightness attribute just written. While this is not a strict requirement per Documentation/ABI/stable/sysfs-class-backlight, try the userspace->hardware scaling for a match first and return the cached value to not confuse userspace.

The problem was already mitigated by

commit 673e7bbdb3920b62cfc6c710bea626b0a9b0f43a

Author: U. Artie Eoff <[email protected]>
Date:   Mon Sep 29 15:49:32 2014 -0700

drm/i915: intel_backlight scale() math WA

Quoted 7 lines

but this should be more robust for cases where the userspace expects actual_brightness to match the just written brightness.

Reference: http://mid.gmane.org/[email protected]
Reference: https://bugzilla.kernel.org/show_bug.cgi?id=85861

Quoted 28 lines
---
 drivers/gpu/drm/i915/intel_panel.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_panel.c +11 -2
index 4d63839bd9b4..675b56e105e7 100644
@@ -1024,7 +1024,17 @@ static int intel_backlight_device_get_brightness(struct backlight_device *bd)
 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 
 	hw_level = intel_panel_get_backlight(connector);
-	ret = scale_hw_to_user(connector, hw_level, bd->props.max_brightness);
+
+	/*
+	 * Check the userspace->hardware scaling for a match first to avoid
+	 * scaling errors in the userspace->hardware->userspace round-trip.
+	 */
+	if (hw_level == scale_user_to_hw(connector, bd->props.brightness,
+					 bd->props.max_brightness))
+		ret = bd->props.brightness;
+	else
+		ret = scale_hw_to_user(connector, hw_level,
+				       bd->props.max_brightness);
 
 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
 	intel_runtime_pm_put(dev_priv);
--
Quoted 1 line

2.1.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw

bump

Quoted 63 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Eoff, Ullysses A
Sent: Thursday, November 20, 2014 9:34 AM
To: Nikula, Jani; [email protected]
Subject: Re: [Intel-gfx] [RFC PATCH] drm/i915: avoid round-trip scaling errors in actual_brightness

Quoted 22 lines

-----Original Message-----
From: Nikula, Jani
Sent: Thursday, November 20, 2014 3:59 AM
To: [email protected]
Cc: Nikula, Jani; Eoff, Ullysses A
Subject: [RFC PATCH] drm/i915: avoid round-trip scaling errors in actual_brightness

Due to scaling, the userspace and hardware brightness ranges might not have a 1:1 mapping, causing the backlight class sysfs actual_brightness not match the brightness attribute just written. While this is not a strict requirement per Documentation/ABI/stable/sysfs-class-backlight, try the userspace->hardware scaling for a match first and return the cached value to not confuse userspace.

The problem was already mitigated by

commit 673e7bbdb3920b62cfc6c710bea626b0a9b0f43a

Author: U. Artie Eoff <[email protected]>
Date:   Mon Sep 29 15:49:32 2014 -0700

drm/i915: intel_backlight scale() math WA

Quoted 7 lines

but this should be more robust for cases where the userspace expects actual_brightness to match the just written brightness.

Reference: http://mid.gmane.org/[email protected]
Reference: https://bugzilla.kernel.org/show_bug.cgi?id=85861

Quoted 25 lines
---
 drivers/gpu/drm/i915/intel_panel.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_panel.c +11 -1
index 4d63839bd9b4..675b56e105e7 100644
@@ -1024,7 +1024,17 @@ static int intel_backlight_device_get_brightness(struct backlight_device *bd)
 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 
 	hw_level = intel_panel_get_backlight(connector);
-	ret = scale_hw_to_user(connector, hw_level, bd->props.max_brightness);
+
+	/*
+	 * Check the userspace->hardware scaling for a match first to avoid
+	 * scaling errors in the userspace->hardware->userspace round-trip.
+	 */
+	if (hw_level == scale_user_to_hw(connector, bd->props.brightness,
+					 bd->props.max_brightness))
+		ret = bd->props.brightness;
+	else
+		ret = scale_hw_to_user(connector, hw_level,
+				       bd->props.max_brightness);
 
Quoted 9 lines
Quoted 4 lines
drivers/gpu/drm/i915/intel_panel.c +0 -1
 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
 	intel_runtime_pm_put(dev_priv);
--

2.1.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
Quoted 1 line · Ullysses A

bump

Talked about this with Daniel a while back, his take was, "preemptively catering to bonghits userspace means we'll have less wiggle-room in the future"

BR,
Jani.

Quoted 73 lines
Quoted 73 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Eoff, Ullysses A
Sent: Thursday, November 20, 2014 9:34 AM
To: Nikula, Jani; [email protected]
Subject: Re: [Intel-gfx] [RFC PATCH] drm/i915: avoid round-trip scaling errors in actual_brightness

Quoted 22 lines

-----Original Message-----
From: Nikula, Jani
Sent: Thursday, November 20, 2014 3:59 AM
To: [email protected]
Cc: Nikula, Jani; Eoff, Ullysses A
Subject: [RFC PATCH] drm/i915: avoid round-trip scaling errors in actual_brightness

Due to scaling, the userspace and hardware brightness ranges might not have a 1:1 mapping, causing the backlight class sysfs actual_brightness not match the brightness attribute just written. While this is not a strict requirement per Documentation/ABI/stable/sysfs-class-backlight, try the userspace->hardware scaling for a match first and return the cached value to not confuse userspace.

The problem was already mitigated by

commit 673e7bbdb3920b62cfc6c710bea626b0a9b0f43a

Author: U. Artie Eoff <[email protected]>
Date:   Mon Sep 29 15:49:32 2014 -0700

drm/i915: intel_backlight scale() math WA

Quoted 7 lines

but this should be more robust for cases where the userspace expects actual_brightness to match the just written brightness.

Reference: http://mid.gmane.org/[email protected]
Reference: https://bugzilla.kernel.org/show_bug.cgi?id=85861

Quoted 28 lines
---
 drivers/gpu/drm/i915/intel_panel.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_panel.c +11 -2
index 4d63839bd9b4..675b56e105e7 100644
@@ -1024,7 +1024,17 @@ static int intel_backlight_device_get_brightness(struct backlight_device *bd)
 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 
 	hw_level = intel_panel_get_backlight(connector);
-	ret = scale_hw_to_user(connector, hw_level, bd->props.max_brightness);
+
+	/*
+	 * Check the userspace->hardware scaling for a match first to avoid
+	 * scaling errors in the userspace->hardware->userspace round-trip.
+	 */
+	if (hw_level == scale_user_to_hw(connector, bd->props.brightness,
+					 bd->props.max_brightness))
+		ret = bd->props.brightness;
+	else
+		ret = scale_hw_to_user(connector, hw_level,
+				       bd->props.max_brightness);
 
 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
 	intel_runtime_pm_put(dev_priv);
--
Quoted 1 line

2.1.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx