Skip to contentSkip to conversation

Add support for testing power saving policy DRM property

PATCH Superseded Mario Limonciello 2 participants 9 messages May 22, 2024 – Jun 18, 2024 Library code

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for testing power saving policy 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 or low latency is preferred over power savings.

To accomplish this a new optional DRM property is being introduced called "power saving policy". This property is a bit mask that can be configured by the compositor to for it's requirements.

When a driver advertises support for this property and the compositor sets requirements then the driver will disable any appplicable power saving features that can compromise the requirements.

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

Mario Limonciello (4):
Add support for API for drivers to set power saving policy 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_psr: Add support for power saving policy property

 lib/igt_kms.c          | 26 +++++++++++++++
 lib/igt_kms.h          |  6 ++++
 tests/amdgpu/amd_abm.c | 72 ++++++++++++++++++++++++++++++++++------
 tests/amdgpu/amd_psr.c | 74 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 168 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/4 Add support for API for drivers to set power saving policy

---
 lib/igt_kms.c | 26 ++++++++++++++++++++++++++
 lib/igt_kms.h |  6 ++++++
 2 files changed, 32 insertions(+)
lib/igt_kms.c +26 -0
index af63d13b1..4ce5e4a95 100644
@@ -6581,3 +6581,29 @@ int get_num_scalers(int drm_fd, enum pipe pipe)
 
 	return num_scalers;
 }
+
+static int toggle_power_saving_policy_prop(int drm_fd, igt_output_t *output, uint64_t policy)
+{
+	uint32_t type = DRM_MODE_OBJECT_CONNECTOR;
+	bool prop_exists;
+	uint32_t prop_id;
+
+	prop_exists = kmstest_get_property(
+		drm_fd, output->id, type, "power saving policy",
+		&prop_id, NULL, NULL);
+
+	if (!prop_exists)
+		return -ENODEV;
+
+	return drmModeObjectSetProperty(drm_fd, output->id, type, prop_id, policy);
+}
+
+int clear_power_saving_policy(int drm_fd, igt_output_t *output)
+{
+	return toggle_power_saving_policy_prop(drm_fd, output, 0);
+}
+
+int set_panel_power_saving_policy(int drm_fd, igt_output_t *output, uint64_t policy)
+{
+	return toggle_power_saving_policy_prop(drm_fd, output, policy);
+}
lib/igt_kms.h +6 -0
index 01604dac9..129b88576 100644
@@ -1223,4 +1223,10 @@ bool igt_check_output_is_dp_mst(igt_output_t *output);
 int igt_get_dp_mst_connector_id(igt_output_t *output);
 int get_num_scalers(int drm_fd, enum pipe pipe);
 
+#define DRM_MODE_REQUIRE_COLOR_ACCURACY	BIT(0)	/* Compositor requires color accuracy */
+#define DRM_MODE_REQUIRE_LOW_LATENCY	BIT(1)	/* Compositor requires low latency */
+
+int clear_power_saving_policy(int drm_fd, igt_output_t *output);
+int set_panel_power_saving_policy(int drm_fd, igt_output_t *output, uint64_t policy);
+
 #endif /* __IGT_KMS_H__ */
Signature · 1 line
2.43.0
#2 lore raw

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

In reply to Mario Limonciello

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.43.0
#3 lore raw

PATCH v2 3/4 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 | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
tests/amdgpu/amd_abm.c +39 -0
index f74c3012c..3fa1366fa 100644
@@ -365,6 +365,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 = clear_power_saving_policy(data->drm_fd, output);
+		if (r == -ENODEV) {
+			igt_skip("No power saving policy prop\n");
+			return;
+		}
+		igt_assert_eq(r, 0);
+
+		target = 3;
+		r = set_abm_level(data, output, target);
+		igt_assert_eq(r, 0);
+
+		r = set_panel_power_saving_policy(data->drm_fd, output, DRM_MODE_REQUIRE_COLOR_ACCURACY);
+		igt_assert_eq(r, 0);
+
+		target = 0;
+		r = set_abm_level(data, output, target);
+		igt_assert_eq(r, -1);
+
+		r = clear_power_saving_policy(data->drm_fd, 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 +430,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.43.0
#4 lore raw

Re: [PATCH v2 3/4] tests/amdgpu/amd_abm: Add support for panel_power_saving property

Thanks for the tests! FYI IGT patches should also cc [email protected]

Some comments inline:

Quoted 37 lines · 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 | 39 +++++++++++++++++++++++++++++++++++++++
  1 file changed, 39 insertions(+)
tests/amdgpu/amd_abm.c +16 -0
index f74c3012c..3fa1366fa 100644
@@ -365,6 +365,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 = clear_power_saving_policy(data->drm_fd, output);
+		if (r == -ENODEV) {
+			igt_skip("No power saving policy prop\n");
+			return;
+		}

tests/amdgpu/amd_abm.c static void abm_gradual(data_t *data) · line 393

Quoted 10 lines
tests/amdgpu/amd_abm.c +10 -0
+		igt_assert_eq(r, 0);
+
+		target = 3;
+		r = set_abm_level(data, output, target);
+		igt_assert_eq(r, 0);
+
+		r = set_panel_power_saving_policy(data->drm_fd, output, DRM_MODE_REQUIRE_COLOR_ACCURACY);
+		igt_assert_eq(r, 0);
+
+		target = 0;

Is there a purpose of setting target abm to 0 (disabled) here?

I suppose it should fail given that we've set REQUIRE_COLOR_ACCURACY. Though I'm not sure why we can't keep target = 3.

Thanks,
Leo

Quoted 23 lines
tests/amdgpu/amd_abm.c +13 -0
+		r = set_abm_level(data, output, target);
+		igt_assert_eq(r, -1);
+
+		r = clear_power_saving_policy(data->drm_fd, 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 +430,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);
#5 lore raw

Re: [PATCH v2 3/4] tests/amdgpu/amd_abm: Add support for panel_power_saving property

Quoted 57 lines · Leo Li

Thanks for the tests! FYI IGT patches should also cc [email protected]

Some comments inline:

Quoted 38 lines · 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 | 39 +++++++++++++++++++++++++++++++++++++++

  1 file changed, 39 insertions(+)
tests/amdgpu/amd_abm.c +17 -0
index f74c3012c..3fa1366fa 100644
@@ -365,6 +365,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 = clear_power_saving_policy(data->drm_fd, output);
+        if (r == -ENODEV) {
+            igt_skip("No power saving policy prop\n");
+            return;
+        }
+        igt_assert_eq(r, 0);

tests/amdgpu/amd_abm.c static void abm_gradual(data_t *data) · line 394

Quoted 10 lines
tests/amdgpu/amd_abm.c +9 -0
+
+        target = 3;
+        r = set_abm_level(data, output, target);
+        igt_assert_eq(r, 0);
+
+        r = set_panel_power_saving_policy(data->drm_fd, output, 
 DRM_MODE_REQUIRE_COLOR_ACCURACY);
+        igt_assert_eq(r, 0);
+
+        target = 0;

Is there a purpose of setting target abm to 0 (disabled) here?

Quoted 2 lines

I suppose it should fail given that we've set REQUIRE_COLOR_ACCURACY. Though I'm not sure why we can't keep target = 3.

Yes I think this would work as well to prove a failure. I'll change it.

Quoted 26 lines

Thanks,
Leo

Quoted 22 lines
tests/amdgpu/amd_abm.c +11 -0
+        r = set_abm_level(data, output, target);
+        igt_assert_eq(r, -1);
+
+        r = clear_power_saving_policy(data->drm_fd, output);
+        igt_assert_eq(r, 0);
+
+        r = set_abm_level(data, output, target);
+        igt_assert_eq(r, 0);
+    }
+}
+

  igt_main
  {
      data_t data = {};

tests/amdgpu/amd_abm.c +2 -0
@@ -393,6 +430,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);
#6 lore raw

PATCH v2 4/4 tests/amdgpu/amd_psr: Add support for `power saving policy` property

In reply to Mario Limonciello

Verify that the property has disabled PSR

---
 tests/amdgpu/amd_psr.c | 74 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
tests/amdgpu/amd_psr.c +74 -0
index 9da161a09..a9f4a6aa5 100644
@@ -338,6 +338,78 @@ static void run_check_psr(data_t *data, bool test_null_crtc) {
 	test_fini(data);
 }
 
+static void psr_forbidden(data_t *data)
+{
+	int edp_idx, ret, i, psr_state;
+	igt_fb_t ref_fb, ref_fb2;
+	igt_fb_t *flip_fb;
+	igt_output_t *output;
+
+	test_init(data);
+
+	edp_idx = check_conn_type(data, DRM_MODE_CONNECTOR_eDP);
+	igt_skip_on_f(edp_idx == -1, "no eDP connector found\n");
+
+	/* check if eDP support PSR1, PSR-SU.
+	 */
+	igt_skip_on(!psr_mode_supported(data, PSR_MODE_1) && !psr_mode_supported(data, PSR_MODE_2));
+	for_each_connected_output(&data->display, output) {
+
+		if (output->config.connector->connector_type != DRM_MODE_CONNECTOR_eDP)
+			continue;
+		ret = clear_power_saving_policy(data->fd, output);
+		if (ret == -ENODEV) {
+			igt_skip("No power saving policy prop\n");
+			return;
+		}
+		igt_require(ret == 0);
+
+		/* try to engage PSR */
+		ret = set_panel_power_saving_policy(data->fd, output, DRM_MODE_REQUIRE_LOW_LATENCY);
+		igt_assert_eq(ret, 0);
+
+		igt_create_color_fb(data->fd, data->mode->hdisplay,
+				    data->mode->vdisplay, DRM_FORMAT_XRGB8888, 0, 1.0,
+				    0.0, 0.0, &ref_fb);
+		igt_create_color_fb(data->fd, data->mode->hdisplay,
+				    data->mode->vdisplay, DRM_FORMAT_XRGB8888, 0, 0.0,
+				    1.0, 0.0, &ref_fb2);
+
+		igt_plane_set_fb(data->primary, &ref_fb);
+
+		igt_display_commit_atomic(&data->display, DRM_MODE_ATOMIC_ALLOW_MODESET, 0);
+
+		for (i = 0; i < N_FLIPS; i++) {
+			if (i % 2 == 0)
+				flip_fb = &ref_fb2;
+			else
+				flip_fb = &ref_fb;
+
+			ret = drmModePageFlip(data->fd, output->config.crtc->crtc_id,
+					      flip_fb->fb_id, DRM_MODE_PAGE_FLIP_EVENT, NULL);
+			igt_require(ret == 0);
+			kmstest_wait_for_pageflip(data->fd);
+		}
+
+		/* PSR state takes some time to settle its value on static screen */
+		sleep(PSR_SETTLE_DELAY);
+
+		psr_state =  igt_amd_read_psr_state(data->fd, output->name);
+		igt_require(psr_state == PSR_STATE3);
+
+		igt_remove_fb(data->fd, &ref_fb);
+		igt_remove_fb(data->fd, &ref_fb2);
+
+		ret = clear_power_saving_policy(data->fd, output);
+		if (ret == -ENODEV) {
+			igt_skip("No power saving policy prop\n");
+			return;
+		}
+		igt_require(ret == 0);
+
+	}
+}
+
 static void run_check_psr_su_mpo(data_t *data, bool scaling, float scaling_ratio)
 {
 	int edp_idx = check_conn_type(data, DRM_MODE_CONNECTOR_eDP);
@@ -756,6 +828,8 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 	igt_describe("Test to validate PSR SU enablement with Visual Confirm "
 		     "and to validate PSR SU disable/re-enable w/ primary scaling ratio 0.75");
 	igt_subtest("psr_su_mpo_scaling_0_75") run_check_psr_su_mpo(&data, true, .75);
+	igt_describe("Test whether PSR can be forbidden");
+	igt_subtest("psr_forbidden") psr_forbidden(&data);
 
 	igt_fixture
 	{
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH v2 4/4] tests/amdgpu/amd_psr: Add support for `power saving policy` property

Quoted 61 lines · Mario Limonciello

Verify that the property has disabled PSR

---
  tests/amdgpu/amd_psr.c | 74 ++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 74 insertions(+)
tests/amdgpu/amd_psr.c +48 -0
index 9da161a09..a9f4a6aa5 100644
@@ -338,6 +338,78 @@ static void run_check_psr(data_t *data, bool test_null_crtc) {
  	test_fini(data);
  }
 
+static void psr_forbidden(data_t *data)
+{
+	int edp_idx, ret, i, psr_state;
+	igt_fb_t ref_fb, ref_fb2;
+	igt_fb_t *flip_fb;
+	igt_output_t *output;
+
+	test_init(data);
+
+	edp_idx = check_conn_type(data, DRM_MODE_CONNECTOR_eDP);
+	igt_skip_on_f(edp_idx == -1, "no eDP connector found\n");
+
+	/* check if eDP support PSR1, PSR-SU.
+	 */
+	igt_skip_on(!psr_mode_supported(data, PSR_MODE_1) && !psr_mode_supported(data, PSR_MODE_2));
+	for_each_connected_output(&data->display, output) {
+
+		if (output->config.connector->connector_type != DRM_MODE_CONNECTOR_eDP)
+			continue;
+		ret = clear_power_saving_policy(data->fd, output);
+		if (ret == -ENODEV) {
+			igt_skip("No power saving policy prop\n");
+			return;
+		}
+		igt_require(ret == 0);
+
+		/* try to engage PSR */
+		ret = set_panel_power_saving_policy(data->fd, output, DRM_MODE_REQUIRE_LOW_LATENCY);
+		igt_assert_eq(ret, 0);
+
+		igt_create_color_fb(data->fd, data->mode->hdisplay,
+				    data->mode->vdisplay, DRM_FORMAT_XRGB8888, 0, 1.0,
+				    0.0, 0.0, &ref_fb);
+		igt_create_color_fb(data->fd, data->mode->hdisplay,
+				    data->mode->vdisplay, DRM_FORMAT_XRGB8888, 0, 0.0,
+				    1.0, 0.0, &ref_fb2);
+
+		igt_plane_set_fb(data->primary, &ref_fb);
+
+		igt_display_commit_atomic(&data->display, DRM_MODE_ATOMIC_ALLOW_MODESET, 0);
+
+		for (i = 0; i < N_FLIPS; i++) {
+			if (i % 2 == 0)
+				flip_fb = &ref_fb2;
+			else
+				flip_fb = &ref_fb;
+
+			ret = drmModePageFlip(data->fd, output->config.crtc->crtc_id,

tests/amdgpu/amd_psr.c static void run_check_psr(data_t *data, bool test_null_crtc) { · line 398

Quoted 10 lines
tests/amdgpu/amd_psr.c +10 -0
+					      flip_fb->fb_id, DRM_MODE_PAGE_FLIP_EVENT, NULL);
+			igt_require(ret == 0);
+			kmstest_wait_for_pageflip(data->fd);
+		}
+
+		/* PSR state takes some time to settle its value on static screen */
+		sleep(PSR_SETTLE_DELAY);
+
+		psr_state =  igt_amd_read_psr_state(data->fd, output->name);
+		igt_require(psr_state == PSR_STATE3);

igt_fail_on* or igt_assert* should be used here, igt_require simply 'skips' the test if the condition evaluates to false.

Should we be instead asserting psr_state == PSR_STATE0 here for disabled, since we've set REQUIRE_LOW_LATENCY?

I think as part of this test, we can also check that PSR re-enables after clearing the power saving policy. Something like

ret = clear_power_saving_policy(data->fd, output); ... do some flipping ...
sleep(PSR_SETTLE_DELAY);
psr_state = igt_amd_read_psr_state(data->fd, output->name); igt_assert_f(psr_state == PSR_STATE3,

             "Panel not in PSR after clearing power saving policy\n");

Thanks,
Leo

Quoted 26 lines
tests/amdgpu/amd_psr.c +16 -0
+
+		igt_remove_fb(data->fd, &ref_fb);
+		igt_remove_fb(data->fd, &ref_fb2);
+
+		ret = clear_power_saving_policy(data->fd, output);
+		if (ret == -ENODEV) {
+			igt_skip("No power saving policy prop\n");
+			return;
+		}
+		igt_require(ret == 0);
+
+	}
+}
+
  static void run_check_psr_su_mpo(data_t *data, bool scaling, float scaling_ratio)
  {
  	int edp_idx = check_conn_type(data, DRM_MODE_CONNECTOR_eDP);
@@ -756,6 +828,8 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
  	igt_describe("Test to validate PSR SU enablement with Visual Confirm "
  		     "and to validate PSR SU disable/re-enable w/ primary scaling ratio 0.75");
  	igt_subtest("psr_su_mpo_scaling_0_75") run_check_psr_su_mpo(&data, true, .75);
+	igt_describe("Test whether PSR can be forbidden");
+	igt_subtest("psr_forbidden") psr_forbidden(&data);
 
  	igt_fixture
  	{
#8 lore raw

Re: [PATCH v2 4/4] tests/amdgpu/amd_psr: Add support for `power saving policy` property

Quoted 76 lines · Leo Li
Quoted 73 lines · Mario Limonciello

Verify that the property has disabled PSR
---
  tests/amdgpu/amd_psr.c | 74 ++++++++++++++++++++++++++++++++++++++++++

  1 file changed, 74 insertions(+)
tests/amdgpu/amd_psr.c +40 -0
index 9da161a09..a9f4a6aa5 100644
@@ -338,6 +338,78 @@ static void run_check_psr(data_t *data, bool 
 test_null_crtc) {
       test_fini(data);
   }
+static void psr_forbidden(data_t *data)
+{
+    int edp_idx, ret, i, psr_state;
+    igt_fb_t ref_fb, ref_fb2;
+    igt_fb_t *flip_fb;
+    igt_output_t *output;
+
+    test_init(data);
+
+    edp_idx = check_conn_type(data, DRM_MODE_CONNECTOR_eDP);
+    igt_skip_on_f(edp_idx == -1, "no eDP connector found\n");
+
+    /* check if eDP support PSR1, PSR-SU.
+     */
+    igt_skip_on(!psr_mode_supported(data, PSR_MODE_1) && 
 !psr_mode_supported(data, PSR_MODE_2));
+    for_each_connected_output(&data->display, output) {
+
+        if (output->config.connector->connector_type != 
 DRM_MODE_CONNECTOR_eDP)
+            continue;
+        ret = clear_power_saving_policy(data->fd, output);
+        if (ret == -ENODEV) {
+            igt_skip("No power saving policy prop\n");
+            return;
+        }
+        igt_require(ret == 0);
+
+        /* try to engage PSR */
+        ret = set_panel_power_saving_policy(data->fd, output, 
 DRM_MODE_REQUIRE_LOW_LATENCY);
+        igt_assert_eq(ret, 0);
+
+        igt_create_color_fb(data->fd, data->mode->hdisplay,
+                    data->mode->vdisplay, DRM_FORMAT_XRGB8888, 0, 1.0,
+                    0.0, 0.0, &ref_fb);
+        igt_create_color_fb(data->fd, data->mode->hdisplay,
+                    data->mode->vdisplay, DRM_FORMAT_XRGB8888, 0, 0.0,
+                    1.0, 0.0, &ref_fb2);
+
+        igt_plane_set_fb(data->primary, &ref_fb);
+
+        igt_display_commit_atomic(&data->display, 

DRM_MODE_ATOMIC_ALLOW_MODESET, 0);

tests/amdgpu/amd_psr.c +8 -0
+
+        for (i = 0; i < N_FLIPS; i++) {
+            if (i % 2 == 0)
+                flip_fb = &ref_fb2;
+            else
+                flip_fb = &ref_fb;
+
+            ret = drmModePageFlip(data->fd, 

output->config.crtc->crtc_id,
+                          flip_fb->fb_id, DRM_MODE_PAGE_FLIP_EVENT, NULL);
+            igt_require(ret == 0);
+            kmstest_wait_for_pageflip(data->fd);
+        }
+
+        /* PSR state takes some time to settle its value on static

Quoted 9 lines
Quoted 5 lines

screen */
+        sleep(PSR_SETTLE_DELAY);
+
+        psr_state =  igt_amd_read_psr_state(data->fd, output->name); +        igt_require(psr_state == PSR_STATE3);

igt_fail_on* or igt_assert* should be used here, igt_require simply 'skips' the test if the condition evaluates to false.

Got it; thanks.

Quoted 2 lines

Should we be instead asserting psr_state == PSR_STATE0 here for disabled, since we've set REQUIRE_LOW_LATENCY?

Yeah I think you're right.

Quoted 11 lines

I think as part of this test, we can also check that PSR re-enables after clearing the power saving policy. Something like

ret = clear_power_saving_policy(data->fd, output);
... do some flipping ...
sleep(PSR_SETTLE_DELAY);
psr_state = igt_amd_read_psr_state(data->fd, output->name); igt_assert_f(psr_state == PSR_STATE3,
             "Panel not in PSR after clearing power saving policy\n");

Agree, thanks.

Quoted 29 lines

Thanks,
Leo

Quoted 26 lines
tests/amdgpu/amd_psr.c +14 -0
+
+        igt_remove_fb(data->fd, &ref_fb);
+        igt_remove_fb(data->fd, &ref_fb2);
+
+        ret = clear_power_saving_policy(data->fd, output);
+        if (ret == -ENODEV) {
+            igt_skip("No power saving policy prop\n");
+            return;
+        }
+        igt_require(ret == 0);
+
+    }
+}
+

  static void run_check_psr_su_mpo(data_t *data, bool scaling, float scaling_ratio) {
      int edp_idx = check_conn_type(data, DRM_MODE_CONNECTOR_eDP);

tests/amdgpu/amd_psr.c +0 -0
@@ -756,6 +828,8 @@ igt_main_args("", long_options, help_str, 
 opt_handler, NULL)

      igt_describe("Test to validate PSR SU enablement with Visual Confirm " "and to validate PSR SU disable/re-enable w/ primary scaling ratio 0.75"); igt_subtest("psr_su_mpo_scaling_0_75") run_check_psr_su_mpo(&data, true, .75); +    igt_describe("Test whether PSR can be forbidden");
+    igt_subtest("psr_forbidden") psr_forbidden(&data);
      igt_fixture
      {