Skip to contentSkip to conversation

Add support for testing panel power saving DRM property

PATCH Superseded Mario Limonciello 1 participant 3 messages May 19, 2024

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Add support for testing panel power saving DRM property

During the Display Next hackfest 2024 one of the topics discussed was the need for compositor to be able to relay intention to drivers that color fidelity is preferred over power savings.

To accomplish this a new optional DRM property is being introduced called "panel power saving". This property is an enum that can be configured by the compositor to "Allowed" or "Forbidden".

When a driver advertises support for this property and the compositor sets it to "Forbidden" then the driver will disable any power saving features that can compromise color fidelity.

This set of IGT changes introduces a new subtest that will cover the expected kernel behavior when switching between Allowed and Forbidden.

Mario Limonciello (2):
tests/amdgpu/amd_abm: Make set_abm_level return type int tests/amdgpu/amd_abm: Add support for panel_power_saving property

 tests/amdgpu/amd_abm.c | 98 +++++++++++++++++++++++++++++++++++++-----
 1 file changed, 88 insertions(+), 10 deletions(-)
Signature · 1 line
2.45.0
#1 lore raw

PATCH 1/2 tests/amdgpu/amd_abm: Make set_abm_level return type int

From: Mario Limonciello <[email protected]>

In order to bubble of cases of expeted errors on set_abm_level() change the return type to int.

---
 tests/amdgpu/amd_abm.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)
tests/amdgpu/amd_abm.c +23 -10
index 2882c2c18..f74c3012c 100644
@@ -104,10 +104,11 @@ static int backlight_write_brightness(int value)
 	return 0;
 }
 
-static void set_abm_level(data_t *data, igt_output_t *output, int level)
+static int set_abm_level(data_t *data, igt_output_t *output, int level)
 {
 	char buf[PATH_MAX];
 	int fd;
+	int ret;
 
 	igt_assert(snprintf(buf, PATH_MAX, PANEL_POWER_SAVINGS_PATH,
 			    output->name) < PATH_MAX);
@@ -116,8 +117,12 @@ static void set_abm_level(data_t *data, igt_output_t *output, int level)
 
 	igt_assert(fd != -1);
 
-	igt_assert_eq(snprintf(buf, sizeof(buf), "%d", level),
-		      write(fd, buf, 1));
+	snprintf(buf, sizeof(buf), "%d", level);
+	ret = write(fd, buf, 1);
+	if (ret < 0) {
+		close(fd);
+		return ret;
+	}
 
 	igt_assert_eq(close(fd), 0);
 
@@ -129,6 +134,7 @@ static void set_abm_level(data_t *data, igt_output_t *output, int level)
 			 DRM_MODE_DPMS_OFF);
 	kmstest_set_connector_dpms(data->drm_fd, output->config.connector,
 			 DRM_MODE_DPMS_ON);
+	return 0;
 }
 
 static int backlight_read_max_brightness(int *result)
@@ -192,7 +198,8 @@ static void backlight_dpms_cycle(data_t *data)
 		ret = backlight_read_max_brightness(&max_brightness);
 		igt_assert_eq(ret, 0);
 
-		set_abm_level(data, output, 0);
+		ret = set_abm_level(data, output, 0);
+		igt_assert_eq(ret, 0);
 		backlight_write_brightness(max_brightness / 2);
 		usleep(100000);
 		pwm_1 = read_target_backlight_pwm(data->drm_fd, output->name);
@@ -223,7 +230,8 @@ static void backlight_monotonic_basic(data_t *data)
 
 		brightness_step = max_brightness / 10;
 
-		set_abm_level(data, output, 0);
+		ret = set_abm_level(data, output, 0);
+		igt_assert_eq(ret, 0);
 		backlight_write_brightness(max_brightness);
 		usleep(100000);
 		prev_pwm = read_target_backlight_pwm(data->drm_fd, output->name);
@@ -257,7 +265,8 @@ static void backlight_monotonic_abm(data_t *data)
 
 		brightness_step = max_brightness / 10;
 		for (i = 1; i < 5; i++) {
-			set_abm_level(data, output, 0);
+			ret = set_abm_level(data, output, 0);
+			igt_assert_eq(ret, 0);
 			backlight_write_brightness(max_brightness);
 			usleep(100000);
 			prev_pwm = read_target_backlight_pwm(data->drm_fd, output->name);
@@ -289,14 +298,16 @@ static void abm_enabled(data_t *data)
 		ret = backlight_read_max_brightness(&max_brightness);
 		igt_assert_eq(ret, 0);
 
-		set_abm_level(data, output, 0);
+		ret = set_abm_level(data, output, 0);
+		igt_assert_eq(ret, 0);
 		backlight_write_brightness(max_brightness);
 		usleep(100000);
 		prev_pwm = read_target_backlight_pwm(data->drm_fd, output->name);
 		pwm_without_abm = prev_pwm;
 
 		for (i = 1; i < 5; i++) {
-			set_abm_level(data, output, i);
+			ret = set_abm_level(data, output, i);
+			igt_assert_eq(ret, 0);
 			usleep(100000);
 			pwm = read_target_backlight_pwm(data->drm_fd, output->name);
 			igt_assert(pwm <= prev_pwm);
@@ -323,7 +334,8 @@ static void abm_gradual(data_t *data)
 
 		igt_assert_eq(ret, 0);
 
-		set_abm_level(data, output, 0);
+		ret = set_abm_level(data, output, 0);
+		igt_assert_eq(ret, 0);
 		backlight_write_brightness(max_brightness);
 
 		sleep(convergence_delay);
@@ -331,7 +343,8 @@ static void abm_gradual(data_t *data)
 		curr = read_current_backlight_pwm(data->drm_fd, output->name);
 
 		igt_assert_eq(prev_pwm, curr);
-		set_abm_level(data, output, 4);
+		ret = set_abm_level(data, output, 4);
+		igt_assert_eq(ret, 0);
 		for (i = 0; i < 10; i++) {
 			usleep(100000);
 			pwm = read_current_backlight_pwm(data->drm_fd, output->name);
Signature · 1 line
2.45.0
#2 lore raw

PATCH 2/2 tests/amdgpu/amd_abm: Add support for panel_power_saving property

In reply to Mario Limonciello

From: Mario Limonciello <[email protected]>

When the "panel power saving" property is set to forbidden the compositor has indicated that userspace prefers to have color accuracy and fidelity instead of power saving.

Verify that the sysfs file behaves as expected in this situation.

---
 tests/amdgpu/amd_abm.c | 65 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
tests/amdgpu/amd_abm.c +65 -0
index f74c3012c..971cda153 100644
@@ -104,6 +104,32 @@ static int backlight_write_brightness(int value)
 	return 0;
 }
 
+static int toggle_panel_power_saving_prop(data_t *data, igt_output_t *output, bool forbid)
+{
+	uint32_t type = DRM_MODE_OBJECT_CONNECTOR;
+	bool prop_exists;
+	uint32_t prop_id;
+
+	prop_exists = kmstest_get_property(
+		data->drm_fd, output->id, type, "panel power saving",
+		&prop_id, NULL, NULL);
+
+	if (!prop_exists)
+		return -ENODEV;
+
+	return drmModeObjectSetProperty(data->drm_fd, output->id, type, prop_id, forbid);
+}
+
+static int allow_panel_power_saving(data_t *data, igt_output_t *output)
+{
+	return toggle_panel_power_saving_prop(data, output, false);
+}
+
+static int forbid_panel_power_saving(data_t *data, igt_output_t *output)
+{
+	return toggle_panel_power_saving_prop(data, output, true);
+}
+
 static int set_abm_level(data_t *data, igt_output_t *output, int level)
 {
 	char buf[PATH_MAX];
@@ -365,6 +391,43 @@ static void abm_gradual(data_t *data)
 	}
 }
 
+
+static void abm_forbidden(data_t *data)
+{
+	igt_output_t *output;
+	enum pipe pipe;
+	int target, r;
+
+	for_each_pipe_with_valid_output(&data->display, pipe, output) {
+		if (output->config.connector->connector_type != DRM_MODE_CONNECTOR_eDP)
+			continue;
+
+		r = allow_panel_power_saving(data, output);
+		if (r == -ENODEV) {
+			igt_skip("No panel power saving prop\n");
+			return;
+		}
+		igt_assert_eq(r, 0);
+
+		target = 3;
+		r = set_abm_level(data, output, target);
+		igt_assert_eq(r, 0);
+
+		r = forbid_panel_power_saving(data, output);
+		igt_assert_eq(r, 0);
+
+		target = 0;
+		r = set_abm_level(data, output, target);
+		igt_assert_eq(r, -1);
+
+		r = allow_panel_power_saving(data, output);
+		igt_assert_eq(r, 0);
+
+		r = set_abm_level(data, output, target);
+		igt_assert_eq(r, 0);
+	}
+}
+
 igt_main
 {
 	data_t data = {};
@@ -393,6 +456,8 @@ igt_main
 		abm_enabled(&data);
 	igt_subtest("abm_gradual")
 		abm_gradual(&data);
+	igt_subtest("abm_forbidden")
+		abm_forbidden(&data);
 
 	igt_fixture {
 		igt_display_fini(&data.display);
Signature · 1 line
2.45.0