Skip to contentSkip to conversation

IGT PSR Fix-ups

PATCH Superseded Jim Bride 3 participants 19 messages Jun 30, 2017 – Jul 7, 2017 Library code

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jim Bride

author
#0 lore raw

v2 cover IGT PSR Fix-ups

These patches, along with the kernel series at
https://patchwork.freedesktop.org/series/24049/ allow our PSR IGT tests to run more predictably on HSW, BDW, and SKL. These patches depend on the kernel series in order to run properly. On the systems I have available the following sets of tests run and pass. I still see some very sporadic (every few hundred tests executions or so) failures to read the sink CRC on SKL.

HSW:
* kms_psr_sink_crc (all)
* kms_frontbuffer_tracking (subtests psr-1p*, my system doesn't support FBC)
* kms_fbcon_fbt (subtests psr*)

BDW and SKL:
* kms_psr_sink_crc (all)
* kms_frontbuffer_tracking (subtests psr-1p* and fbcpsr-1p*)
* kms_fbcon_fbt (all)

Jim Bride (6):
tests/kms_psr_sink_crc: Change assert_or_manual() to a macro
lib: Add PSR utility functions to igt library. tests/kms_psr_sink_crc: Refactor to use new PSR library primitives tests/kms_frontbuffer_tracking: Refactor to use IGT PSR library
functions
tests/kms_frontbuffer_tracking: Fix multidraw subtest tests/kms_fbcon_fbt: Refactor to use IGT PSR library functions

 lib/Makefile.sources             |   2 +
 lib/igt.h                        |   1 +
 lib/igt_psr.c                    | 235 +++++++++++++++++++++++++++++++++++++++
 lib/igt_psr.h                    |  43 +++++++
 tests/kms_fbcon_fbt.c            |  54 +++------
 tests/kms_frontbuffer_tracking.c | 122 ++++----------------
 tests/kms_psr_sink_crc.c         | 144 ++++++++++++------------
 7 files changed, 391 insertions(+), 210 deletions(-)
 create mode 100644 lib/igt_psr.c
 create mode 100644 lib/igt_psr.h
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#1 lore raw

PATCH v2 1/6 tests/kms_psr_sink_crc: Change assert_or_manual() to a macro

Make assert_or_manual() a macro so that we get accurate line number information when this assertion fails.

v2: Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>
---
 tests/kms_psr_sink_crc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tests/kms_psr_sink_crc.c +5 -5
index bd3fa5e..1a03719 100644
@@ -278,11 +278,11 @@ static bool is_green(char *crc)
 		(bh & mask) == 0);
 }
 
-static void assert_or_manual(bool condition, const char *expected)
-{
-	igt_debug_manual_check("no-crc", expected);
-	igt_assert(igt_interactive_debug || condition);
-}
+#define assert_or_manual(condition, expected)             \
+do {                                                      \
+	igt_debug_manual_check("no-crc", expected);       \
+	igt_assert(igt_interactive_debug || condition);   \
+} while (0)
 
 static void run_test(data_t *data)
 {
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#3 lore raw

PATCH v2 2/6 lib: Add PSR utility functions to igt library.

In reply to Jim Bride

Factor out some code that was replicated in three test utilities into some new IGT library functions so that we are checking PSR status in a consistent fashion across all of our PSR tests.

v2: * Add sink CRC helper function
* Misc. bug fixes
* Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>
---
 lib/Makefile.sources |   2 +
 lib/igt.h            |   1 +
 lib/igt_psr.c        | 235 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_psr.h        |  43 ++++++++++
 4 files changed, 281 insertions(+)
 create mode 100644 lib/igt_psr.c
 create mode 100644 lib/igt_psr.h
lib/Makefile.sources +2 -0
index 53fdb54..6a73c8c 100644
@@ -83,6 +83,8 @@ lib_source_list =	 	\
 	uwildmat/uwildmat.c	\
 	igt_kmod.c		\
 	igt_kmod.h		\
+	igt_psr.c		\
+	igt_psr.h		\
 	$(NULL)
 
 .PHONY: version.h.tmp
lib/igt.h +1 -0
index a069deb..0b8e3a8 100644
@@ -37,6 +37,7 @@
 #include "igt_gt.h"
 #include "igt_kms.h"
 #include "igt_pm.h"
+#include "igt_psr.h"
 #include "igt_stats.h"
 #ifdef HAVE_CHAMELIUM
 #include "igt_chamelium.h"
lib/igt_psr.c new file +235 -0

235 lines not on this page · raw message

lib/igt_psr.h new file +43 -0

43 lines not on this page · raw message

Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#8 lore raw

PATCH v2 3/6 tests/kms_psr_sink_crc: Refactor to use new PSR library primitives

In reply to Jim Bride

v2: * Minor functional tweaks & bug fixes
* Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>
---
 tests/kms_psr_sink_crc.c | 134 +++++++++++++++++++++++------------------------
 1 file changed, 66 insertions(+), 68 deletions(-)
tests/kms_psr_sink_crc.c +66 -68
index 1a03719..50d002d 100644
@@ -33,8 +33,6 @@
 
 bool running_with_psr_disabled;
 
-#define CRC_BLACK "000000000000"
-
 enum operations {
 	PAGE_FLIP,
 	MMAP_GTT,
@@ -64,13 +62,15 @@ static const char *op_str(enum operations op)
 
 typedef struct {
 	int drm_fd;
+	int debugfs_fd;
+	int crc_fd;
 	int test_plane;
 	enum operations op;
 	uint32_t devid;
 	uint32_t crtc_id;
 	igt_display_t display;
 	drm_intel_bufmgr *bufmgr;
-	struct igt_fb fb_green, fb_white;
+	struct igt_fb fb_green, fb_white, fb_blue;
 	igt_plane_t *primary, *sprite, *cursor;
 	int mod_size;
 	int mod_stride;
@@ -98,6 +98,7 @@ static void setup_output(data_t *data)
 {
 	igt_display_t *display = &data->display;
 	igt_output_t *output;
+	drmModeModeInfoPtr mode = NULL;
 	enum pipe pipe;
 
 	for_each_pipe_with_valid_output(display, pipe, output) {
@@ -106,10 +107,15 @@ static void setup_output(data_t *data)
 		if (c->connector_type != DRM_MODE_CONNECTOR_eDP)
 			continue;
 
+		if (!igt_psr_find_good_mode(c, &mode))
+			continue;
+
+		igt_assert(mode != NULL);
+		igt_output_override_mode(output, mode);
 		igt_output_set_pipe(output, pipe);
 		data->crtc_id = output->config.crtc->crtc_id;
 		data->output = output;
-		data->mode = igt_output_get_mode(output);
+		data->mode = &output->override_mode;
 
 		return;
 	}
@@ -119,10 +125,33 @@ static void display_init(data_t *data)
 {
 	igt_display_init(&data->display, data->drm_fd);
 	setup_output(data);
+
+	/* We need to be able to do a modeset before we enable PSR to
+	 * ensure that we are running at a mode such that PSR setup can
+	 * complete within a single vblank interval.
+	 */
+	igt_debug("Selected mode:\n");
+	kmstest_dump_mode(data->mode);
+	igt_create_color_fb(data->drm_fd,
+			    data->mode->hdisplay, data->mode->vdisplay,
+			    DRM_FORMAT_XRGB8888,
+			    LOCAL_I915_FORMAT_MOD_X_TILED,
+			    0.0, .0, 1.0,
+			    &data->fb_blue);
+
+	data->primary = igt_output_get_plane_type(data->output,
+						  DRM_PLANE_TYPE_PRIMARY);
+	igt_plane_set_fb(data->primary, &data->fb_blue);
+	igt_display_commit(&data->display);
+	igt_set_module_param_int("enable_psr", running_with_psr_disabled ?
+				 0 : 1);
 }
 
 static void display_fini(data_t *data)
 {
+	close(data->crc_fd);
+	close(data->debugfs_fd);
+	igt_output_override_mode(data->output, NULL);
 	igt_display_fini(&data->display);
 }
 
@@ -192,90 +221,59 @@ static void fill_render(data_t *data, uint32_t handle, unsigned char color)
 	gem_bo_busy(data->drm_fd, handle);
 }
 
-static bool psr_possible(data_t *data)
+static inline bool psr_possible(data_t *data)
 {
-	char buf[512];
-
-	igt_debugfs_read(data->drm_fd, "i915_edp_psr_status", buf);
-
 	return running_with_psr_disabled ||
-		strstr(buf, "Sink_Support: yes\n");
+		igt_psr_sink_support(data->drm_fd);
 }
 
-static bool psr_active(data_t *data)
+static inline bool psr_active(data_t *data)
 {
-	char buf[512];
-
-	igt_debugfs_read(data->drm_fd, "i915_edp_psr_status", buf);
-
 	return running_with_psr_disabled ||
-		strstr(buf, "HW Enabled & Active bit: yes\n");
+		igt_psr_active(data->drm_fd);
 }
 
-static bool wait_psr_entry(data_t *data)
+static inline bool wait_psr_entry(data_t *data)
 {
-	int timeout = 5;
-	while (timeout--) {
-		if (psr_active(data))
-			return true;
-		sleep(1);
-	}
-	return false;
+	return running_with_psr_disabled ||
+		igt_psr_await_status(data->drm_fd, true);
 }
 
 static void get_sink_crc(data_t *data, char *crc) {
-	int dir;
+	int rc, tries = 10;
 
+	memset(crc, 0, 6);
 	if (igt_interactive_debug)
 		return;
 
-	dir = igt_debugfs_dir(data->drm_fd);
-	igt_require_f(igt_sysfs_scanf(dir, "i915_sink_crc_eDP1", "%s\n", crc),
-		      "Sink CRC is unreliable on this machine. Try manual debug with --interactive-debug=no-crc\n");
-	close(dir);
-
-	igt_debug("%s\n", crc);
+	do {
+		rc = igt_psr_get_sink_crc(data->crc_fd, crc);
+		if (rc)
+			usleep(50000);
+	} while (rc && --tries);
+
+	if (rc)
+		igt_skip("Could not get sink CRC after ten tries.\n");
+	
+	igt_debug("CRC: %hhx %hhx %hhx %hhx %hhx %hhx\n",
+		  crc[0], crc[1], crc[2], crc[3], crc[4], crc[5]);
 	igt_debug_wait_for_keypress("crc");
 
 	/* The important value was already taken.
 	 * Now give a time for human eyes
 	 */
 	usleep(300000);
-
-	/* Black screen is always invalid */
-	igt_assert(strcmp(crc, CRC_BLACK) != 0);
 }
 
 static bool is_green(char *crc)
 {
-	char color_mask[5] = "FFFF\0";
-	char rs[5], gs[5], bs[5];
-	unsigned int rh, gh, bh, mask;
-	int ret;
+	unsigned int rh, gh, bh;
 
-	if (igt_interactive_debug)
-		return false;
+	rh = (crc[1] << 8) | crc[0];
+	gh = (crc[3] << 8) | crc[2];
+	bh = (crc[5] << 8) | crc[4];
 
-	sscanf(color_mask, "%4x", &mask);
-
-	memcpy(rs, &crc[0], 4);
-	rs[4] = '\0';
-	ret = sscanf(rs, "%4x", &rh);
-	igt_require(ret > 0);
-
-	memcpy(gs, &crc[4], 4);
-	gs[4] = '\0';
-	ret = sscanf(gs, "%4x", &gh);
-	igt_require(ret > 0);
-
-	memcpy(bs, &crc[8], 4);
-	bs[4] = '\0';
-	ret = sscanf(bs, "%4x", &bh);
-	igt_require(ret > 0);
-
-	return ((rh & mask) == 0 &&
-		(gh & mask) != 0 &&
-		(bh & mask) == 0);
+	return ((rh == 0) && (gh != 0) && (bh == 0));
 }
 
 #define assert_or_manual(condition, expected)             \
@@ -289,8 +287,8 @@ static void run_test(data_t *data)
 	uint32_t handle = data->fb_white.gem_handle;
 	igt_plane_t *test_plane;
 	void *ptr;
-	char ref_crc[12];
-	char crc[12];
+	char ref_crc[6];
+	char crc[6];
 	const char *expected = "";
 
 	/* Confirm that screen became Green */
@@ -347,9 +345,9 @@ static void run_test(data_t *data)
 		memset(ptr, 0xff, data->mod_size);
 		get_sink_crc(data, crc);
 		if (data->test_plane == DRM_PLANE_TYPE_PRIMARY)
-			assert_or_manual(strcmp(ref_crc, crc) == 0, "screen WHITE");
+			assert_or_manual(memcmp(ref_crc, crc, sizeof(crc)) == 0, "screen WHITE");
 		else
-			assert_or_manual(strcmp(ref_crc, crc) == 0,
+			assert_or_manual(memcmp(ref_crc, crc, sizeof(crc)) == 0,
 			       "GREEN background with WHITE box");
 
 		igt_info("Waiting 10s...\n");
@@ -392,7 +390,7 @@ static void run_test(data_t *data)
 		break;
 	}
 	get_sink_crc(data, crc);
-	assert_or_manual(strcmp(ref_crc, crc) != 0, expected);
+	assert_or_manual(memcmp(ref_crc, crc, sizeof(crc)) != 0, expected);
 }
 
 static void test_cleanup(data_t *data) {
@@ -504,12 +502,11 @@ int main(int argc, char *argv[])
 
 	igt_fixture {
 		data.drm_fd = drm_open_driver_master(DRIVER_INTEL);
+		data.debugfs_fd = igt_debugfs_dir(data.drm_fd);
+		data.crc_fd = igt_psr_open_sink_crc(data.debugfs_fd);
 		kmstest_set_vt_graphics_mode();
 		data.devid = intel_get_drm_devid(data.drm_fd);
 
-		igt_set_module_param_int("enable_psr", running_with_psr_disabled ?
-					 0 : 1);
-
 		igt_skip_on(!psr_possible(&data));
 
 		data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
@@ -517,6 +514,7 @@ int main(int argc, char *argv[])
 		drm_intel_bufmgr_gem_enable_reuse(data.bufmgr);
 
 		display_init(&data);
+		igt_skip_on(!psr_possible(&data));
 	}
 
 	igt_subtest("psr_basic") {
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#9 lore raw

PATCH v2 4/6 tests/kms_frontbuffer_tracking: Refactor to use IGT PSR library functions

In reply to Jim Bride

v2: * Minor functional tweaks and bug fixes
* Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>
---
 tests/kms_frontbuffer_tracking.c | 119 +++++++--------------------------------
 1 file changed, 19 insertions(+), 100 deletions(-)
tests/kms_frontbuffer_tracking.c +19 -100
index c24e4a8..3a8b754 100644
@@ -183,7 +183,7 @@ struct {
 };
 
 
-#define SINK_CRC_SIZE 12
+#define SINK_CRC_SIZE 6
 typedef struct {
 	char data[SINK_CRC_SIZE];
 } sink_crc_t;
@@ -327,28 +327,6 @@ drmModeModeInfo std_1024_mode = {
 	.name = "Custom 1024x768",
 };
 
-static drmModeModeInfoPtr get_connector_smallest_mode(drmModeConnectorPtr c)
-{
-	int i;
-	drmModeModeInfoPtr smallest = NULL;
-
-	for (i = 0; i < c->count_modes; i++) {
-		drmModeModeInfoPtr mode = &c->modes[i];
-
-		if (!smallest)
-			smallest = mode;
-
-		if (mode->hdisplay * mode->vdisplay <
-		    smallest->hdisplay * smallest->vdisplay)
-			smallest = mode;
-	}
-
-	if (c->connector_type == DRM_MODE_CONNECTOR_eDP)
-		smallest = &std_1024_mode;
-
-	return smallest;
-}
-
 static drmModeConnectorPtr get_connector(uint32_t id)
 {
 	int i;
@@ -421,30 +399,6 @@ static void init_mode_params(struct modeset_params *params, uint32_t crtc_id,
 	params->sprite.h = 64;
 }
 
-static bool connector_get_mode(drmModeConnectorPtr c, drmModeModeInfoPtr *mode)
-{
-	*mode = NULL;
-
-	if (c->connection != DRM_MODE_CONNECTED || !c->count_modes)
-		return false;
-
-	if (c->connector_type == DRM_MODE_CONNECTOR_eDP && opt.no_edp)
-		return false;
-
-	if (opt.small_modes)
-		*mode = get_connector_smallest_mode(c);
-	else
-		*mode = &c->modes[0];
-
-	 /* On HSW the CRC WA is so awful that it makes you think everything is
-	  * bugged. */
-	if (IS_HASWELL(intel_get_drm_devid(drm.fd)) &&
-	    c->connector_type == DRM_MODE_CONNECTOR_eDP)
-		*mode = &std_1024_mode;
-
-	return true;
-}
-
 static bool connector_supports_pipe_a(drmModeConnectorPtr connector)
 {
 	int i;
@@ -473,7 +427,7 @@ static bool find_connector(bool edp_only, bool pipe_a, uint32_t forbidden_id,
 			continue;
 		if (c->connector_id == forbidden_id)
 			continue;
-		if (!connector_get_mode(c, &mode))
+		if (!igt_psr_find_good_mode(c, &mode))
 			continue;
 
 		*ret_connector = c;
@@ -804,23 +758,6 @@ static void fbc_print_status(void)
 	igt_info("FBC status:\n%s\n", buf);
 }
 
-static bool psr_is_enabled(void)
-{
-	char buf[256];
-
-	debugfs_read("i915_edp_psr_status", buf);
-	return strstr(buf, "\nActive: yes\n") &&
-	       strstr(buf, "\nHW Enabled & Active bit: yes\n");
-}
-
-static void psr_print_status(void)
-{
-	char buf[256];
-
-	debugfs_read("i915_edp_psr_status", buf);
-	igt_info("PSR status:\n%s\n", buf);
-}
-
 static struct timespec fbc_get_last_action(void)
 {
 	struct timespec ret = { 0, 0 };
@@ -926,44 +863,31 @@ static bool fbc_wait_until_enabled(void)
 	return igt_wait(fbc_is_enabled(), 2000, 1);
 }
 
-static bool psr_wait_until_enabled(void)
-{
-	return igt_wait(psr_is_enabled(), 5000, 1);
-}
-
 #define fbc_enable() igt_set_module_param_int("enable_fbc", 1)
 #define fbc_disable() igt_set_module_param_int("enable_fbc", 0)
-#define psr_enable() igt_set_module_param_int("enable_psr", 1)
-#define psr_disable() igt_set_module_param_int("enable_psr", 0)
 
 static void get_sink_crc(sink_crc_t *crc, bool mandatory)
 {
-	int rc, errno_;
+	int rc;
 
 	if (!sink_crc.supported) {
 		memcpy(crc, "unsupported!", SINK_CRC_SIZE);
 		return;
 	}
 
-	lseek(sink_crc.fd, 0, SEEK_SET);
-
-	rc = read(sink_crc.fd, crc->data, SINK_CRC_SIZE);
-	errno_ = errno;
-
-	if (rc == -1 && errno_ == ENOTTY) {
+	rc = igt_psr_get_sink_crc(sink_crc.fd, crc->data);
+	if (rc == ENOTTY) {
 		igt_info("Sink CRC not supported: panel doesn't support it\n");
 		sink_crc.supported = false;
-	} else if (rc == -1 && errno_ == ETIMEDOUT) {
-		if (sink_crc.reliable) {
-			igt_info("Sink CRC is unreliable on this machine.\n");
+	} else if (rc == ETIMEDOUT) {
+		if (sink_crc.reliable) 
 			sink_crc.reliable = false;
-		}
+		
 
 		if (mandatory)
 			igt_skip("Sink CRC is unreliable on this machine.\n");
 	} else {
-		igt_assert_f(rc != -1, "Unexpected error: %d\n", errno_);
-		igt_assert(rc == SINK_CRC_SIZE);
+		igt_assert_f(rc == 0, "Unexpected error: %d\n", rc);
 	}
 }
 
@@ -1180,7 +1104,7 @@ static void disable_features(const struct test_mode *t)
 		return;
 
 	fbc_disable();
-	psr_disable();
+	igt_psr_disable();
 }
 
 static void *busy_thread_func(void *data)
@@ -1432,7 +1356,7 @@ static void setup_sink_crc(void)
 	fill_fb_region(&prim_mode_params.fb, COLOR_PRIM_BG);
 	set_mode_for_params(&prim_mode_params);
 
-	sink_crc.fd = openat(drm.debugfs, "i915_sink_crc_eDP1", O_RDONLY);
+	sink_crc.fd = igt_psr_open_sink_crc(drm.debugfs);
 	igt_assert_lte(0, sink_crc.fd);
 
 	/* Do a first read to try to detect if it's supported. */
@@ -1547,14 +1471,6 @@ static void teardown_fbc(void)
 {
 }
 
-static bool psr_sink_has_support(void)
-{
-	char buf[256];
-
-	debugfs_read("i915_edp_psr_status", buf);
-	return strstr(buf, "Sink_Support: yes\n");
-}
-
 static void setup_psr(void)
 {
 	if (get_connector(prim_mode_params.connector_id)->connector_type !=
@@ -1563,7 +1479,7 @@ static void setup_psr(void)
 		return;
 	}
 
-	if (!psr_sink_has_support()) {
+	if (!igt_psr_sink_support(drm.fd)) {
 		igt_info("Can't test PSR: not supported by sink.\n");
 		return;
 	}
@@ -1717,12 +1633,15 @@ static int adjust_assertion_flags(const struct test_mode *t, int flags)
 	}								\
 									\
 	if (flags_ & ASSERT_PSR_ENABLED) {				\
-		if (!psr_wait_until_enabled()) {			\
-			psr_print_status();				\
+		if (!igt_psr_await_status(drm.fd, true)) {		\
+			igt_psr_print_status(drm.fd);			\
 			igt_assert_f(false, "PSR disabled\n");		\
 		}							\
 	} else if (flags_ & ASSERT_PSR_DISABLED) {			\
-		igt_assert(!psr_wait_until_enabled());			\
+		if (!igt_psr_await_status(drm.fd, false)) {		\
+			igt_psr_print_status(drm.fd);                   \
+			igt_assert_f(false, "PSR enabled\n");		\
+		}							\
 	}								\
 } while (0)
 
@@ -1822,7 +1741,7 @@ static void enable_features_for_test(const struct test_mode *t)
 	if (t->feature & FEATURE_FBC)
 		fbc_enable();
 	if (t->feature & FEATURE_PSR)
-		psr_enable();
+		igt_psr_enable();
 }
 
 static void check_test_requirements(const struct test_mode *t)
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#14 lore raw

PATCH v2 5/6 tests/kms_frontbuffer_tracking: Fix multidraw subtest

In reply to Jim Bride

The multidraw subtest was not taking whether or not the GEM buffer had ever been in write-combining mode when checking for PSR state, so fix that.

---
 tests/kms_frontbuffer_tracking.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/kms_frontbuffer_tracking.c +2 -1
index 3a8b754..c52d7a0 100644
@@ -2059,7 +2059,8 @@ static void multidraw_subtest(const struct test_mode *t)
 				assertions = used_method != IGT_DRAW_MMAP_GTT ?
 					     ASSERT_LAST_ACTION_CHANGED :
 					     ASSERT_NO_ACTION_CHANGE;
-				if (op_disables_psr(t, used_method))
+				if (op_disables_psr(t, used_method) &&
+				    !wc_used)
 					assertions |= ASSERT_PSR_DISABLED;
 
 				do_assertions(assertions);
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#17 lore raw

PATCH v2 6/6 tests/kms_fbcon_fbt: Refactor to use IGT PSR library functions

In reply to Jim Bride

v2: * Minor functional tweaks and bug fixes
* Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>
---
 tests/kms_fbcon_fbt.c | 54 +++++++++++++++++----------------------------------
 1 file changed, 18 insertions(+), 36 deletions(-)
tests/kms_fbcon_fbt.c +18 -36
index d009091..593adb9 100644
@@ -103,8 +103,9 @@ static bool fbc_is_enabled(int fd)
 	return strstr(buf, "FBC enabled\n");
 }
 
-static bool fbc_wait_until_enabled(int fd)
+static bool fbc_wait_until_enabled(int fd, bool enabled)
 {
+	enabled = enabled;
 	return igt_wait(fbc_is_enabled(fd), 5000, 1);
 }
 
@@ -124,6 +125,13 @@ static void set_mode_for_one_screen(struct drm_info *drm, struct igt_fb *fb,
 
 		if (c->connection == DRM_MODE_CONNECTED && c->count_modes &&
 		    connector_possible(c)) {
+			if (c->connector_type == DRM_MODE_CONNECTOR_eDP) {
+				bool bret;
+
+				bret = igt_psr_find_good_mode(c, &mode);
+				if (bret)
+					break;
+			}
 			mode = &c->modes[0];
 			break;
 		}
@@ -147,35 +155,9 @@ static void set_mode_for_one_screen(struct drm_info *drm, struct igt_fb *fb,
 	igt_assert_eq(rc, 0);
 }
 
-static bool psr_supported_on_chipset(int fd)
-{
-	char buf[256];
-
-	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
-	return strstr(buf, "Sink_Support: yes\n");
-}
-
-static bool connector_can_psr(drmModeConnectorPtr connector)
-{
-	return (connector->connector_type == DRM_MODE_CONNECTOR_eDP);
-}
-
-static bool psr_is_enabled(int fd)
-{
-	char buf[256];
-
-	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
-	return strstr(buf, "\nActive: yes\n");
-}
-
-static bool psr_wait_until_enabled(int fd)
-{
-	return igt_wait(psr_is_enabled(fd), 5000, 1);
-}
-
 struct feature {
 	bool (*supported_on_chipset)(int fd);
-	bool (*wait_until_enabled)(int fd);
+	bool (*wait_until_enabled)(int fd, bool status);
 	bool (*connector_possible_fn)(drmModeConnectorPtr connector);
 	const char *param_name;
 } fbc = {
@@ -184,9 +166,9 @@ struct feature {
 	.connector_possible_fn = connector_can_fbc,
 	.param_name = "enable_fbc",
 }, psr = {
-	.supported_on_chipset = psr_supported_on_chipset,
-	.wait_until_enabled = psr_wait_until_enabled,
-	.connector_possible_fn = connector_can_psr,
+	.supported_on_chipset = igt_psr_sink_support,
+	.wait_until_enabled = igt_psr_await_status,
+	.connector_possible_fn = igt_psr_valid_connector,
 	.param_name = "enable_psr",
 };
 
@@ -210,17 +192,17 @@ static void subtest(struct feature *feature, bool suspend)
 
 	kmstest_unset_all_crtcs(drm.fd, drm.res);
 	wait_user("Modes unset.");
-	igt_assert(!feature->wait_until_enabled(drm.fd));
+	igt_assert(!feature->wait_until_enabled(drm.fd, true));
 
 	set_mode_for_one_screen(&drm, &fb, feature->connector_possible_fn);
 	wait_user("Screen set.");
-	igt_assert(feature->wait_until_enabled(drm.fd));
+	igt_assert(feature->wait_until_enabled(drm.fd, true));
 
 	if (suspend) {
 		igt_system_suspend_autoresume(SUSPEND_STATE_MEM,
 					      SUSPEND_TEST_NONE);
 		sleep(5);
-		igt_assert(feature->wait_until_enabled(drm.fd));
+		igt_assert(feature->wait_until_enabled(drm.fd, true));
 	}
 
 	igt_remove_fb(drm.fd, &fb);
@@ -230,13 +212,13 @@ static void subtest(struct feature *feature, bool suspend)
 	sleep(3);
 
 	wait_user("Back to fbcon.");
-	igt_assert(!feature->wait_until_enabled(drm.fd));
+	igt_assert(!feature->wait_until_enabled(drm.fd, true));
 
 	if (suspend) {
 		igt_system_suspend_autoresume(SUSPEND_STATE_MEM,
 					      SUSPEND_TEST_NONE);
 		sleep(5);
-		igt_assert(!feature->wait_until_enabled(drm.fd));
+		igt_assert(!feature->wait_until_enabled(drm.fd, true));
 	}
 }
 
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v2 1/6
#2 lore raw

Re: [PATCH IGT v2 1/6] tests/kms_psr_sink_crc: Change assert_or_manual() to a macro

In reply to Jim Bride

oh! at least one good reason why igt is full of macros! :(

Quoted 40 lines · Jim Bride

Make assert_or_manual() a macro so that we get accurate line number information when this assertion fails.

v2: Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>
---
 tests/kms_psr_sink_crc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tests/kms_psr_sink_crc.c +5 -6
index bd3fa5e..1a03719 100644
@@ -278,11 +278,11 @@ static bool is_green(char *crc)
                (bh & mask) == 0);
 }
 
-static void assert_or_manual(bool condition, const char *expected)
-{
-       igt_debug_manual_check("no-crc", expected);
-       igt_assert(igt_interactive_debug || condition);
-}
+#define assert_or_manual(condition, expected)             \
+do {                                                      \
+       igt_debug_manual_check("no-crc", expected);       \
+       igt_assert(igt_interactive_debug || condition);   \
+} while (0)
 
 static void run_test(data_t *data)
 {
--

2.7.4

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

Signature · 6 lines
Rodrigo Vivi
Blog: http://blog.vivi.eng.br
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

Re: [PATCH IGT v2 2/6] lib: Add PSR utility functions to igt library.

In reply to Jim Bride
Quoted 228 lines · Jim Bride

Factor out some code that was replicated in three test utilities into some new IGT library functions so that we are checking PSR status in a consistent fashion across all of our PSR tests.

v2: * Add sink CRC helper function
* Misc. bug fixes
* Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>
---
 lib/Makefile.sources |   2 +
 lib/igt.h            |   1 +
 lib/igt_psr.c        | 235 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_psr.h        |  43 ++++++++++
 4 files changed, 281 insertions(+)
 create mode 100644 lib/igt_psr.c
 create mode 100644 lib/igt_psr.h
lib/Makefile.sources +2 -0
index 53fdb54..6a73c8c 100644
@@ -83,6 +83,8 @@ lib_source_list =             \
        uwildmat/uwildmat.c     \
        igt_kmod.c              \
        igt_kmod.h              \
+       igt_psr.c               \
+       igt_psr.h               \
        $(NULL)
 
 .PHONY: version.h.tmp
lib/igt.h +1 -0
index a069deb..0b8e3a8 100644
@@ -37,6 +37,7 @@
 #include "igt_gt.h"
 #include "igt_kms.h"
 #include "igt_pm.h"
+#include "igt_psr.h"
 #include "igt_stats.h"
 #ifdef HAVE_CHAMELIUM
 #include "igt_chamelium.h"
lib/igt_psr.c new file +177 -0
new file mode 100644
index 0000000..a2823bf
@@ -0,0 +1,235 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "igt.h"
+#include <stdio.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <string.h>
+#include <fcntl.h>
+
+/**
+ * SECTION:igt_psr
+ * @short_description: Panel Self Refresh helpers
+ * @title: Panel Self Refresh
+ * @include: igt.h
+ *
+ * This library provides various helpers to enable Panel Self Refresh,
+ * as well as to check the state of PSR on the system (enabled vs.
+ * disabled, active vs. inactive) or to wait for PSR to be active
+ * or inactive.
+ */
+
+/**
+ * igt_psr_source_support:
+ *
+ * Returns true if the source supports PSR.
+ */
+bool igt_psr_source_support(int fd)
+{
+       char buf[512];
+
+       igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+
+       return strstr(buf, "Source_OK: yes\n");
+}
+
+
+/**
+ * igt_psr_sink_support:
+ *
+ * Returns true if the current eDP panel supports PSR.
+ */
+bool igt_psr_sink_support(int fd)
+{
+       char buf[256];
+
+       igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+       return strstr(buf, "Sink_Support: yes\n");
+}
+
+/**
+ * igt_psr_possible:
+ *
+ * Returns true if both the source and sink support PSR.
+ */
+bool igt_psr_possible(int fd)
+{
+       char buf[512];
+
+       igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+
+       return igt_psr_source_support(fd) && igt_psr_sink_support(fd);
+}
+
+/**
+ * igt_psr_active:
+ *
+ * Returns true if PSR is active on the panel.
+ */
+bool igt_psr_active(int fd)
+{
+       char buf[512];
+       bool actret = false;
+       bool hwactret = false;
+
+       igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+       hwactret = (strstr(buf, "HW Enabled & Active bit: yes\n") != NULL);
+       actret = (strstr(buf, "Active: yes\n") != NULL);
+       igt_debug("hwactret: %s actret: %s\n", hwactret ? "true" : "false",
+                actret ? "true" : "false");
+       return hwactret && actret;
+}
+
+/**
+ * igt_psr_await_status:
+ * @active: A boolean that causes the function to wait for PSR to activate
+ *          if set to true, or to wait for PSR to deactivate if false.
+ *
+ * Returns true if the requested condition is met.
+ */
+bool igt_psr_await_status(int fd, bool active)
+{
+       const int timeout = 10;
+       int count = 0;
+       while (count < timeout) {
+               if (igt_psr_active(fd) == active) {
+                       igt_debug("PSR %s after %d seconds.\n",
+                                 active ? "Active" : "Inactive", count);
+                       return true;
+               }
+               count++;
+               sleep(1);
+       }
+       return false;
+}
+
+/**
+ * igt_psr_enabled:
+ *
+ * Returns true if the PSR feature is enabled.
+ */
+bool igt_psr_enabled(int fd)
+{
+       char buf[256];
+
+       igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+       return strstr(buf, "Enabled: yes\n");
+}
+
+/**
+ * igt_psr_print_status:
+ *
+ * Dumps the contents of i915_edp_psr_status from debugfs.
+ */
+void igt_psr_print_status(int fd)
+{
+        char buf[256];
+
+        igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+        igt_info("PSR status:\n%s\n", buf);
+}
+
+/**
+ * igt_psr_valid_connector:
+ * @connector: a drmModeConnector pointer to check
+ *
+ * Returns true if connector is an eDP connector.
+ */
+bool igt_psr_valid_connector(drmModeConnectorPtr connector)
+{
+       return (connector->connector_type == DRM_MODE_CONNECTOR_eDP);
+}
+
+/**
+ * igt_psr_find_good_mode
+ * @connector: a drmModeConnector pointer to find the mode on
+ * @mode: a drmModeModePtr pointer that is set to the matching mode
+ *
+ * Returns true (and populates *mode with the match) if a valid
+ * PSR mdoe is found, and false otherwise.
+ */
+bool igt_psr_find_good_mode(drmModeConnectorPtr connector,
+                           drmModeModeInfoPtr *mode)
+{
+       int i;
+
+       if (!connector->count_modes) {

lib/igt_psr.c line 187

Quoted 10 lines
lib/igt_psr.c new file +10 -0
+               igt_warn("no modes for connector %d.\n",
+                        connector->connector_id);
+               return false;
+       } else {
+               igt_debug("Connector has %d modes.\n", connector->count_modes);
+       }
+
+       for (i = 0; i < connector->count_modes; i++) {
+               if ((connector->modes[i].vtotal -
+                    connector->modes[i].vdisplay) >= 36) {

why 36?

doesn't this depend on the panel setup time and on mode resolution?

Quoted 104 lines
lib/igt_psr.c new file +48 -0
+                       igt_debug("Mode %d good for PSR.\n", i);
+                       *mode = &(connector->modes[i]);
+                       return true;
+               } else {
+                       igt_debug("Throwing out mode %d\n", i);
+               }
+       }
+       return false;
+}
+
+int igt_psr_open_sink_crc(int drm_fd)
+{
+       int crc_fd;
+
+       crc_fd = openat(drm_fd, "i915_sink_crc_eDP1", O_RDONLY);
+       igt_assert_lte(0, crc_fd);
+       return crc_fd;
+}
+
+
+int igt_psr_get_sink_crc(int fd, char *data)
+{
+       int rc, errno_;
+       char buf[13];
+
+       memset(buf, 0, 13);
+       lseek(fd, 0, SEEK_SET);
+
+       rc = read(fd, buf, 12);
+       errno_ = errno;
+
+       if (rc == -1) {
+               if (errno_ == ENOTTY)
+                       igt_info("Sink CRC not supported: panel doesn't support it\n");
+               else if (errno_ != ETIMEDOUT)
+                       igt_assert_f(rc != -1, "Unexpected error: %d\n",
+                                    errno_);
+               return errno_;
+       } else {
+               int i;
+               unsigned long long val = strtoull(buf, NULL, 16);
+
+               for (i = 5; i >= 0; i--, val >>= 8) {
+                       data[i] = (unsigned char) (val & 0xff);
+               }
+               return 0;
+       }
+}
lib/igt_psr.h new file +43 -1
new file mode 100644
index 0000000..d94cdfa
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef IGT_PSR_H
+#define IGT_PSR_H
+
+#define igt_psr_enable() igt_set_module_param_int("enable_psr", 1)
+#define igt_psr_disable() igt_set_module_param_int("enable_psr", 0)
+
+bool igt_psr_sink_support(int fd);
+bool igt_psr_source_support(int fd);
+bool igt_psr_possible(int fd);
+bool igt_psr_active(int fd);
+bool igt_psr_await_status(int fd, bool active);
+bool igt_psr_enabled(int fd);
+void igt_psr_print_status(int fd);
+bool igt_psr_valid_connector(drmModeConnectorPtr connector);
+bool igt_psr_find_good_mode(drmModeConnectorPtr connector,
+                           drmModeModeInfoPtr *mode);
+int igt_psr_open_sink_crc(int drm_fd);
+int igt_psr_get_sink_crc(int fd, char *data);
+
+#endif /* IGT_PSR_H */
--

2.7.4

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

Signature · 6 lines
Rodrigo Vivi
Blog: http://blog.vivi.eng.br
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#10 lore raw

Re: [PATCH IGT v2 4/6] tests/kms_frontbuffer_tracking: Refactor to use IGT PSR library functions

In reply to Jim Bride

I believe it would be better to create the psr lib with only one function at time and on every patch that adds the new function already removes that from here and from frontbuffer tracking test as well...

easier to review and to make sure that we are not changing the behaviour.

also...

Quoted 15 lines · Jim Bride

v2: * Minor functional tweaks and bug fixes
* Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>
---
 tests/kms_frontbuffer_tracking.c | 119 +++++++--------------------------------
 1 file changed, 19 insertions(+), 100 deletions(-)
tests/kms_frontbuffer_tracking.c +0 -0
index c24e4a8..3a8b754 100644

tests/kms_frontbuffer_tracking.c struct { · line 186

Quoted 5 lines
tests/kms_frontbuffer_tracking.c +1 -1
@@ -183,7 +183,7 @@ struct {
 };
 
 
-#define SINK_CRC_SIZE 12
+#define SINK_CRC_SIZE 6

I believe this deserves a separated patch...

Quoted 107 lines
tests/kms_frontbuffer_tracking.c +1 -69
 typedef struct {
        char data[SINK_CRC_SIZE];
 } sink_crc_t;
@@ -327,28 +327,6 @@ drmModeModeInfo std_1024_mode = {
        .name = "Custom 1024x768",
 };
 
-static drmModeModeInfoPtr get_connector_smallest_mode(drmModeConnectorPtr c)
-{
-       int i;
-       drmModeModeInfoPtr smallest = NULL;
-
-       for (i = 0; i < c->count_modes; i++) {
-               drmModeModeInfoPtr mode = &c->modes[i];
-
-               if (!smallest)
-                       smallest = mode;
-
-               if (mode->hdisplay * mode->vdisplay <
-                   smallest->hdisplay * smallest->vdisplay)
-                       smallest = mode;
-       }
-
-       if (c->connector_type == DRM_MODE_CONNECTOR_eDP)
-               smallest = &std_1024_mode;
-
-       return smallest;
-}
-
 static drmModeConnectorPtr get_connector(uint32_t id)
 {
        int i;
@@ -421,30 +399,6 @@ static void init_mode_params(struct modeset_params *params, uint32_t crtc_id,
        params->sprite.h = 64;
 }
 
-static bool connector_get_mode(drmModeConnectorPtr c, drmModeModeInfoPtr *mode)
-{
-       *mode = NULL;
-
-       if (c->connection != DRM_MODE_CONNECTED || !c->count_modes)
-               return false;
-
-       if (c->connector_type == DRM_MODE_CONNECTOR_eDP && opt.no_edp)
-               return false;
-
-       if (opt.small_modes)
-               *mode = get_connector_smallest_mode(c);
-       else
-               *mode = &c->modes[0];
-
-        /* On HSW the CRC WA is so awful that it makes you think everything is
-         * bugged. */
-       if (IS_HASWELL(intel_get_drm_devid(drm.fd)) &&
-           c->connector_type == DRM_MODE_CONNECTOR_eDP)
-               *mode = &std_1024_mode;
-
-       return true;
-}
-
 static bool connector_supports_pipe_a(drmModeConnectorPtr connector)
 {
        int i;
@@ -473,7 +427,7 @@ static bool find_connector(bool edp_only, bool pipe_a, uint32_t forbidden_id,
                        continue;
                if (c->connector_id == forbidden_id)
                        continue;
-               if (!connector_get_mode(c, &mode))
+               if (!igt_psr_find_good_mode(c, &mode))
                        continue;
 
                *ret_connector = c;
@@ -804,23 +758,6 @@ static void fbc_print_status(void)
        igt_info("FBC status:\n%s\n", buf);
 }
 
-static bool psr_is_enabled(void)
-{
-       char buf[256];
-
-       debugfs_read("i915_edp_psr_status", buf);
-       return strstr(buf, "\nActive: yes\n") &&
-              strstr(buf, "\nHW Enabled & Active bit: yes\n");
-}
-
-static void psr_print_status(void)
-{
-       char buf[256];
-
-       debugfs_read("i915_edp_psr_status", buf);
-       igt_info("PSR status:\n%s\n", buf);
-}
-
 static struct timespec fbc_get_last_action(void)
 {
        struct timespec ret = { 0, 0 };
@@ -926,44 +863,31 @@ static bool fbc_wait_until_enabled(void)
        return igt_wait(fbc_is_enabled(), 2000, 1);
 }
 
-static bool psr_wait_until_enabled(void)
-{
-       return igt_wait(psr_is_enabled(), 5000, 1);
-}
-
 #define fbc_enable() igt_set_module_param_int("enable_fbc", 1)
 #define fbc_disable() igt_set_module_param_int("enable_fbc", 0)

tests/kms_frontbuffer_tracking.c static bool fbc_wait_until_enabled(void) · line 874

Quoted 10 lines
tests/kms_frontbuffer_tracking.c +1 -3
-#define psr_enable() igt_set_module_param_int("enable_psr", 1)
-#define psr_disable() igt_set_module_param_int("enable_psr", 0)
 
 static void get_sink_crc(sink_crc_t *crc, bool mandatory)
 {
-       int rc, errno_;
+       int rc;
 
        if (!sink_crc.supported) {
                memcpy(crc, "unsupported!", SINK_CRC_SIZE);

this doesn't fit anymore

Quoted 108 lines
tests/kms_frontbuffer_tracking.c +16 -28
                return;
        }
 
-       lseek(sink_crc.fd, 0, SEEK_SET);
-
-       rc = read(sink_crc.fd, crc->data, SINK_CRC_SIZE);
-       errno_ = errno;
-
-       if (rc == -1 && errno_ == ENOTTY) {
+       rc = igt_psr_get_sink_crc(sink_crc.fd, crc->data);
+       if (rc == ENOTTY) {
                igt_info("Sink CRC not supported: panel doesn't support it\n");
                sink_crc.supported = false;
-       } else if (rc == -1 && errno_ == ETIMEDOUT) {
-               if (sink_crc.reliable) {
-                       igt_info("Sink CRC is unreliable on this machine.\n");
+       } else if (rc == ETIMEDOUT) {
+               if (sink_crc.reliable)
                        sink_crc.reliable = false;
-               }
+
 
                if (mandatory)
                        igt_skip("Sink CRC is unreliable on this machine.\n");
        } else {
-               igt_assert_f(rc != -1, "Unexpected error: %d\n", errno_);
-               igt_assert(rc == SINK_CRC_SIZE);
+               igt_assert_f(rc == 0, "Unexpected error: %d\n", rc);
        }
 }
 
@@ -1180,7 +1104,7 @@ static void disable_features(const struct test_mode *t)
                return;
 
        fbc_disable();
-       psr_disable();
+       igt_psr_disable();
 }
 
 static void *busy_thread_func(void *data)
@@ -1432,7 +1356,7 @@ static void setup_sink_crc(void)
        fill_fb_region(&prim_mode_params.fb, COLOR_PRIM_BG);
        set_mode_for_params(&prim_mode_params);
 
-       sink_crc.fd = openat(drm.debugfs, "i915_sink_crc_eDP1", O_RDONLY);
+       sink_crc.fd = igt_psr_open_sink_crc(drm.debugfs);
        igt_assert_lte(0, sink_crc.fd);
 
        /* Do a first read to try to detect if it's supported. */
@@ -1547,14 +1471,6 @@ static void teardown_fbc(void)
 {
 }
 
-static bool psr_sink_has_support(void)
-{
-       char buf[256];
-
-       debugfs_read("i915_edp_psr_status", buf);
-       return strstr(buf, "Sink_Support: yes\n");
-}
-
 static void setup_psr(void)
 {
        if (get_connector(prim_mode_params.connector_id)->connector_type !=
@@ -1563,7 +1479,7 @@ static void setup_psr(void)
                return;
        }
 
-       if (!psr_sink_has_support()) {
+       if (!igt_psr_sink_support(drm.fd)) {
                igt_info("Can't test PSR: not supported by sink.\n");
                return;
        }
@@ -1717,12 +1633,15 @@ static int adjust_assertion_flags(const struct test_mode *t, int flags)
        }                                                               \
                                                                        \
        if (flags_ & ASSERT_PSR_ENABLED) {                              \
-               if (!psr_wait_until_enabled()) {                        \
-                       psr_print_status();                             \
+               if (!igt_psr_await_status(drm.fd, true)) {              \
+                       igt_psr_print_status(drm.fd);                   \
                        igt_assert_f(false, "PSR disabled\n");          \
                }                                                       \
        } else if (flags_ & ASSERT_PSR_DISABLED) {                      \
-               igt_assert(!psr_wait_until_enabled());                  \
+               if (!igt_psr_await_status(drm.fd, false)) {             \
+                       igt_psr_print_status(drm.fd);                   \
+                       igt_assert_f(false, "PSR enabled\n");           \
+               }                                                       \
        }                                                               \
 } while (0)
 
@@ -1822,7 +1741,7 @@ static void enable_features_for_test(const struct test_mode *t)
        if (t->feature & FEATURE_FBC)
                fbc_enable();
        if (t->feature & FEATURE_PSR)
-               psr_enable();
+               igt_psr_enable();
 }
 
 static void check_test_requirements(const struct test_mode *t)
--

2.7.4

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

Signature · 6 lines
Rodrigo Vivi
Blog: http://blog.vivi.eng.br
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#15 lore raw

Re: [PATCH IGT v2 5/6] tests/kms_frontbuffer_tracking: Fix multidraw subtest

In reply to Jim Bride
cc Paulo Zanoni...
Quoted 30 lines · Jim Bride

The multidraw subtest was not taking whether or not the GEM buffer had ever been in write-combining mode when checking for PSR state, so fix that.

---
 tests/kms_frontbuffer_tracking.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/kms_frontbuffer_tracking.c +2 -2
index 3a8b754..c52d7a0 100644
@@ -2059,7 +2059,8 @@ static void multidraw_subtest(const struct test_mode *t)
                                assertions = used_method != IGT_DRAW_MMAP_GTT ?
                                             ASSERT_LAST_ACTION_CHANGED :
                                             ASSERT_NO_ACTION_CHANGE;
-                               if (op_disables_psr(t, used_method))
+                               if (op_disables_psr(t, used_method) &&
+                                   !wc_used)
                                        assertions |= ASSERT_PSR_DISABLED;
 
                                do_assertions(assertions);
--

2.7.4

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

Signature · 6 lines
Rodrigo Vivi
Blog: http://blog.vivi.eng.br
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#12 lore raw

Re: [PATCH IGT v2 4/6] tests/kms_frontbuffer_tracking: Refactor to use IGT PSR library functions

In reply to Jim Bride

Em Sex, 2017-06-30 às 12:12 -0700, Jim Bride escreveu:

Quoted 6 lines

v2: * Minor functional tweaks and bug fixes
    * Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>

This patch is not just a refactor. It changes a how the code behaves. Please split it into many patches: one patch replaces code with equivalent code from the PSR library, and the other patches should each do one of the actual code changes that this patch does.

Quoted 14 lines

---
 tests/kms_frontbuffer_tracking.c | 119 +++++++--------------------
------------

 1 file changed, 19 insertions(+), 100 deletions(-)
tests/kms_frontbuffer_tracking.c +0 -0
index c24e4a8..3a8b754 100644
@@ -183,7 +183,7 @@ struct {
  };


tests/kms_frontbuffer_tracking.c struct { · line 186

Quoted 2 lines
tests/kms_frontbuffer_tracking.c +1 -1
-#define SINK_CRC_SIZE 12
+#define SINK_CRC_SIZE 6

As Rodrigo mentioned, this is going to break.

Quoted 69 lines

 typedef struct {
  char data[SINK_CRC_SIZE];
 } sink_crc_t;

tests/kms_frontbuffer_tracking.c +0 -0
@@ -327,28 +327,6 @@ drmModeModeInfo std_1024_mode = {
  	.name = "Custom 1024x768",
  };


-static drmModeModeInfoPtr get_connector_smallest_mode(drmModeConnectorPtr c)

tests/kms_frontbuffer_tracking.c +0 -21
-{
-	int i;
-	drmModeModeInfoPtr smallest = NULL;
-
-	for (i = 0; i < c->count_modes; i++) {
-		drmModeModeInfoPtr mode = &c->modes[i];
-
-		if (!smallest)
-			smallest = mode;
-
-		if (mode->hdisplay * mode->vdisplay <
-		    smallest->hdisplay * smallest->vdisplay)
-			smallest = mode;
-	}
-
-	if (c->connector_type == DRM_MODE_CONNECTOR_eDP)
-		smallest = &std_1024_mode;
-
-	return smallest;
-}
-

 static drmModeConnectorPtr get_connector(uint32_t id) {
  int i;

tests/kms_frontbuffer_tracking.c +0 -0
@@ -421,30 +399,6 @@ static void init_mode_params(struct
 modeset_params *params, uint32_t crtc_id,
  	params->sprite.h = 64;
  }


-static bool connector_get_mode(drmModeConnectorPtr c, drmModeModeInfoPtr *mode)

tests/kms_frontbuffer_tracking.c +0 -7
-{
-	*mode = NULL;
-
-	if (c->connection != DRM_MODE_CONNECTED || !c->count_modes)
-		return false;
-
-	if (c->connector_type == DRM_MODE_CONNECTOR_eDP &&

opt.no_edp)

tests/kms_frontbuffer_tracking.c +0 -8
-		return false;
-
-	if (opt.small_modes)
-		*mode = get_connector_smallest_mode(c);
-	else
-		*mode = &c->modes[0];
-
-	 /* On HSW the CRC WA is so awful that it makes you think

everything is

tests/kms_frontbuffer_tracking.c +0 -8
-	  * bugged. */
-	if (IS_HASWELL(intel_get_drm_devid(drm.fd)) &&
-	    c->connector_type == DRM_MODE_CONNECTOR_eDP)
-		*mode = &std_1024_mode;
-
-	return true;
-}
-

 static bool connector_supports_pipe_a(drmModeConnectorPtr connector) {
  int i;

tests/kms_frontbuffer_tracking.c static bool find_connector(bool edp_only, bool · line 431

Quoted 6 lines
tests/kms_frontbuffer_tracking.c +1 -1
@@ -473,7 +427,7 @@ static bool find_connector(bool edp_only, bool
 pipe_a, uint32_t forbidden_id,
  			continue;
  		if (c->connector_id == forbidden_id)
  			continue;
-		if (!connector_get_mode(c, &mode))
+		if (!igt_psr_find_good_mode(c, &mode))

igt_psr_find_good_mode() doesn't seem to do what connector_get_mode() does, we can't use it. This is going to introduce bugs.

Quoted 59 lines
tests/kms_frontbuffer_tracking.c +0 -0
  			continue;


  *ret_connector = c;

tests/kms_frontbuffer_tracking.c +0 -0
@@ -804,23 +758,6 @@ static void fbc_print_status(void)
  	igt_info("FBC status:\n%s\n", buf);
  }

tests/kms_frontbuffer_tracking.c +0 -17
-static bool psr_is_enabled(void)
-{
-	char buf[256];
-
-	debugfs_read("i915_edp_psr_status", buf);
-	return strstr(buf, "\nActive: yes\n") &&
-	       strstr(buf, "\nHW Enabled & Active bit: yes\n");
-}
-
-static void psr_print_status(void)
-{
-	char buf[256];
-
-	debugfs_read("i915_edp_psr_status", buf);
-	igt_info("PSR status:\n%s\n", buf);
-}
-

 static struct timespec fbc_get_last_action(void)
 {
  struct timespec ret = { 0, 0 };

tests/kms_frontbuffer_tracking.c +0 -0
@@ -926,44 +863,31 @@ static bool fbc_wait_until_enabled(void)
  	return igt_wait(fbc_is_enabled(), 2000, 1);
  }

tests/kms_frontbuffer_tracking.c +0 -5
-static bool psr_wait_until_enabled(void)
-{
-	return igt_wait(psr_is_enabled(), 5000, 1);
-}
-

 #define fbc_enable() igt_set_module_param_int("enable_fbc", 1) #define fbc_disable() igt_set_module_param_int("enable_fbc", 0)

tests/kms_frontbuffer_tracking.c +0 -2
-#define psr_enable() igt_set_module_param_int("enable_psr", 1)
-#define psr_disable() igt_set_module_param_int("enable_psr", 0)


 static void get_sink_crc(sink_crc_t *crc, bool mandatory) {

tests/kms_frontbuffer_tracking.c +1 -1
-	int rc, errno_;
+	int rc;


  if (!sink_crc.supported) {
  memcpy(crc, "unsupported!", SINK_CRC_SIZE); return;
  }

tests/kms_frontbuffer_tracking.c +2 -6
-	lseek(sink_crc.fd, 0, SEEK_SET);
-
-	rc = read(sink_crc.fd, crc->data, SINK_CRC_SIZE);
-	errno_ = errno;
-
-	if (rc == -1 && errno_ == ENOTTY) {
+	rc = igt_psr_get_sink_crc(sink_crc.fd, crc->data);
+	if (rc == ENOTTY) {
Quoted 2 lines

  igt_info("Sink CRC not supported: panel doesn't support it\n");

We'll print this twice now.

Quoted 11 lines

  sink_crc.supported = false;

tests/kms_frontbuffer_tracking.c +0 -3
-	} else if (rc == -1 && errno_ == ETIMEDOUT) {
-		if (sink_crc.reliable) {
-			igt_info("Sink CRC is unreliable on this

machine.\n");

tests/kms_frontbuffer_tracking.c +2 -0
+	} else if (rc == ETIMEDOUT) {
+		if (sink_crc.reliable) 

  sink_crc.reliable = false;

tests/kms_frontbuffer_tracking.c +1 -1
-		}
+		

There are some problems with white spaces in the lines above: a double blank line and trailing spaces at the end of lines.

Quoted 101 lines

  if (mandatory)
  igt_skip("Sink CRC is unreliable on this machine.\n");
  } else {

tests/kms_frontbuffer_tracking.c +0 -1
-		igt_assert_f(rc != -1, "Unexpected error: %d\n",

errno_);

tests/kms_frontbuffer_tracking.c +1 -1
-		igt_assert(rc == SINK_CRC_SIZE);
+		igt_assert_f(rc == 0, "Unexpected error: %d\n", rc);

  }
 }

tests/kms_frontbuffer_tracking.c +0 -0
@@ -1180,7 +1104,7 @@ static void disable_features(const struct
 test_mode *t)
  		return;


  fbc_disable();

tests/kms_frontbuffer_tracking.c +1 -1
-	psr_disable();
+	igt_psr_disable();

 }

 static void *busy_thread_func(void *data)

tests/kms_frontbuffer_tracking.c +0 -0
@@ -1432,7 +1356,7 @@ static void setup_sink_crc(void)
  	fill_fb_region(&prim_mode_params.fb, COLOR_PRIM_BG);
  	set_mode_for_params(&prim_mode_params);

tests/kms_frontbuffer_tracking.c +0 -1
-	sink_crc.fd = openat(drm.debugfs, "i915_sink_crc_eDP1",

O_RDONLY);

tests/kms_frontbuffer_tracking.c +1 -0
+	sink_crc.fd = igt_psr_open_sink_crc(drm.debugfs);

  igt_assert_lte(0, sink_crc.fd);

  /* Do a first read to try to detect if it's supported. */

tests/kms_frontbuffer_tracking.c +0 -0
@@ -1547,14 +1471,6 @@ static void teardown_fbc(void)
  {
  }

tests/kms_frontbuffer_tracking.c +0 -8
-static bool psr_sink_has_support(void)
-{
-	char buf[256];
-
-	debugfs_read("i915_edp_psr_status", buf);
-	return strstr(buf, "Sink_Support: yes\n");
-}
-

 static void setup_psr(void)
 {
  if (get_connector(prim_mode_params.connector_id)-

Quoted 1 line

connector_type !=

tests/kms_frontbuffer_tracking.c +0 -0
@@ -1563,7 +1479,7 @@ static void setup_psr(void)
  		return;
  	}

tests/kms_frontbuffer_tracking.c +1 -1
-	if (!psr_sink_has_support()) {
+	if (!igt_psr_sink_support(drm.fd)) {

  igt_info("Can't test PSR: not supported by sink.\n");
  return;
  }

tests/kms_frontbuffer_tracking.c +0 -0
@@ -1717,12 +1633,15 @@ static int adjust_assertion_flags(const
 struct test_mode *t, int flags)
  	}								
 \


\
  if (flags_ & ASSERT_PSR_ENABLED) {
\

tests/kms_frontbuffer_tracking.c +0 -1
-		if (!psr_wait_until_enabled()) {			

\

tests/kms_frontbuffer_tracking.c +0 -1
-			psr_print_status();				

\

tests/kms_frontbuffer_tracking.c +1 -0
+		if (!igt_psr_await_status(drm.fd, true)) {		

\

tests/kms_frontbuffer_tracking.c +1 -0
+			igt_psr_print_status(drm.fd);		
	\
 			igt_assert_f(false, "PSR disabled\n");	
	\

  }
\
  } else if (flags_ & ASSERT_PSR_DISABLED) { \

tests/kms_frontbuffer_tracking.c +0 -1
-		igt_assert(!psr_wait_until_enabled());		
	\
tests/kms_frontbuffer_tracking.c +1 -0
+		if (!igt_psr_await_status(drm.fd, false)) {		

\

tests/kms_frontbuffer_tracking.c +1 -0
+			igt_psr_print_status(drm.fd);               

    \

tests/kms_frontbuffer_tracking.c +1 -0
+			igt_assert_f(false, "PSR enabled\n");	
	\
tests/kms_frontbuffer_tracking.c +1 -0
+		}							

\
  }
\
 } while (0)

tests/kms_frontbuffer_tracking.c +1 -1
@@ -1822,7 +1741,7 @@ static void enable_features_for_test(const
 struct test_mode *t)
  	if (t->feature & FEATURE_FBC)
  		fbc_enable();
  	if (t->feature & FEATURE_PSR)
-		psr_enable();
+		igt_psr_enable();
  }
Quoted 2 lines


 static void check_test_requirements(const struct test_mode *t)

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

#6 lore raw

Re: [PATCH IGT v2 2/6] lib: Add PSR utility functions to igt library.

In reply to Jim Bride

Em Sex, 2017-06-30 às 12:12 -0700, Jim Bride escreveu:

Quoted 122 lines

Factor out some code that was replicated in three test utilities into some new IGT library functions so that we are checking PSR status in a consistent fashion across all of our PSR tests.

v2: * Add sink CRC helper function
    * Misc. bug fixes
    * Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>

---
 lib/Makefile.sources |   2 +
 lib/igt.h            |   1 +
 lib/igt_psr.c        | 235
+++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_psr.h        |  43 ++++++++++

 4 files changed, 281 insertions(+)

 create mode 100644 lib/igt_psr.c
 create mode 100644 lib/igt_psr.h

lib/Makefile.sources +2 -0
index 53fdb54..6a73c8c 100644
@@ -83,6 +83,8 @@ lib_source_list =	 	\
  	uwildmat/uwildmat.c	\
  	igt_kmod.c		\
  	igt_kmod.h		\
+	igt_psr.c		\
+	igt_psr.h		\
  	$(NULL)


 .PHONY: version.h.tmp

lib/igt.h +1 -0
index a069deb..0b8e3a8 100644
@@ -37,6 +37,7 @@
  #include "igt_gt.h"
  #include "igt_kms.h"
  #include "igt_pm.h"
+#include "igt_psr.h"
  #include "igt_stats.h"
  #ifdef HAVE_CHAMELIUM
  #include "igt_chamelium.h"
lib/igt_psr.c new file +4 -0
new file mode 100644
index 0000000..a2823bf
@@ -0,0 +1,235 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */

lib/igt_psr.c new file +15 -0
+
+#include "igt.h"
+#include <stdio.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <string.h>
+#include <fcntl.h>
+
+/**
+ * SECTION:igt_psr
+ * @short_description: Panel Self Refresh helpers
+ * @title: Panel Self Refresh
+ * @include: igt.h
+ *
+ * This library provides various helpers to enable Panel Self

Refresh,
+ * as well as to check the state of PSR on the system (enabled vs.
+ * disabled, active vs. inactive) or to wait for PSR to be active
+ * or inactive.
+ */

lib/igt_psr.c new file +14 -0
+
+/**
+ * igt_psr_source_support:
+ *
+ * Returns true if the source supports PSR.
+ */
+bool igt_psr_source_support(int fd)
+{
+	char buf[512];
+
+	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+
+	return strstr(buf, "Source_OK: yes\n");
+}

lib/igt_psr.c line 65

Quoted 10 lines
lib/igt_psr.c new file +10 -0
+
+
+/**
+ * igt_psr_sink_support:
+ *
+ * Returns true if the current eDP panel supports PSR.
+ */
+bool igt_psr_sink_support(int fd)
+{
+	char buf[256];

Why are some buffers 512 while the others are 256? They're both for the same file.

Quoted 59 lines
lib/igt_psr.c new file +17 -0
+
+	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+	return strstr(buf, "Sink_Support: yes\n");
+}
+
+/**
+ * igt_psr_possible:
+ *
+ * Returns true if both the source and sink support PSR.
+ */
+bool igt_psr_possible(int fd)
+{
+	char buf[512];
+
+	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+
+	return igt_psr_source_support(fd) &&

igt_psr_sink_support(fd);

lib/igt_psr.c new file +15 -0
+}
+
+/**
+ * igt_psr_active:
+ *
+ * Returns true if PSR is active on the panel.
+ */
+bool igt_psr_active(int fd)
+{
+	char buf[512];
+	bool actret = false;
+	bool hwactret = false;
+
+	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+	hwactret = (strstr(buf, "HW Enabled & Active bit: yes\n") !=

NULL);

lib/igt_psr.c new file +2 -0
+	actret = (strstr(buf, "Active: yes\n") != NULL);
+	igt_debug("hwactret: %s actret: %s\n", hwactret ? "true" :

"false",

lib/igt_psr.c new file +7 -0
+		 actret ? "true" : "false");
+	return hwactret && actret;
+}
+
+/**
+ * igt_psr_await_status:
+ * @active: A boolean that causes the function to wait for PSR to

activate
+ *          if set to true, or to wait for PSR to deactivate if false.
+ *
+ * Returns true if the requested condition is met.
+ */

lib/igt_psr.c new file +8 -0
+bool igt_psr_await_status(int fd, bool active)
+{
+	const int timeout = 10;
+	int count = 0;
+	while (count < timeout) {
+		if (igt_psr_active(fd) == active) {
+			igt_debug("PSR %s after %d seconds.\n",
+				  active ? "Active" : "Inactive",

count);

lib/igt_psr.c line 124

Quoted 6 lines
lib/igt_psr.c new file +6 -0
+			return true;
+		}
+		count++;
+		sleep(1);
+	}
+	return false;

Since this is in a lib now, can you please make use of igt_wait or just make it work as expected when the signal helper is active?

Quoted 60 lines
lib/igt_psr.c new file +37 -0
+}
+
+/**
+ * igt_psr_enabled:
+ *
+ * Returns true if the PSR feature is enabled.
+ */
+bool igt_psr_enabled(int fd)
+{
+	char buf[256];
+
+	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+	return strstr(buf, "Enabled: yes\n");
+}
+
+/**
+ * igt_psr_print_status:
+ *
+ * Dumps the contents of i915_edp_psr_status from debugfs.
+ */
+void igt_psr_print_status(int fd)
+{
+        char buf[256];
+
+        igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+        igt_info("PSR status:\n%s\n", buf);
+}
+
+/**
+ * igt_psr_valid_connector:
+ * @connector: a drmModeConnector pointer to check
+ *
+ * Returns true if connector is an eDP connector.
+ */
+bool igt_psr_valid_connector(drmModeConnectorPtr connector)
+{
+	return (connector->connector_type ==

DRM_MODE_CONNECTOR_eDP);

lib/igt_psr.c new file +21 -0
+}
+
+/**
+ * igt_psr_find_good_mode
+ * @connector: a drmModeConnector pointer to find the mode on
+ * @mode: a drmModeModePtr pointer that is set to the matching mode
+ *
+ * Returns true (and populates *mode with the match) if a valid
+ * PSR mdoe is found, and false otherwise.
+ */
+bool igt_psr_find_good_mode(drmModeConnectorPtr connector,
+			    drmModeModeInfoPtr *mode)
+{
+	int i;
+
+	if (!connector->count_modes) {
+		igt_warn("no modes for connector %d.\n",
+			 connector->connector_id);
+		return false;
+	} else {
+		igt_debug("Connector has %d modes.\n", connector-
Quoted 1 line

count_modes);

lib/igt_psr.c line 190

Quoted 8 lines
lib/igt_psr.c new file +8 -0
+	}
+
+	for (i = 0; i < connector->count_modes; i++) {
+		if ((connector->modes[i].vtotal -
+		     connector->modes[i].vdisplay) >= 36) {
+			igt_debug("Mode %d good for PSR.\n", i);
+			*mode = &(connector->modes[i]);
+			return true;

Since the callers may be trying to find modes that fit other restrictions (e.g., kms_frontbuffer_tracking) I'd suggest you to extract igt_psr_mode_is_compatible(mode) with the vtotal/vdisplay check.

Quoted 7 lines
lib/igt_psr.c new file +7 -0
+		} else {
+			igt_debug("Throwing out mode %d\n", i);
+		}
+	}
+	return false;
+}
+

lib/igt_psr.c line 207

Quoted 10 lines
lib/igt_psr.c new file +10 -0
+int igt_psr_open_sink_crc(int drm_fd)
+{
+	int crc_fd;
+
+	crc_fd = openat(drm_fd, "i915_sink_crc_eDP1", O_RDONLY);
+	igt_assert_lte(0, crc_fd);
+	return crc_fd;
+}
+
+

Please add documentation for this one, especially around the expectation for "data".

Quoted 18 lines
lib/igt_psr.c new file +14 -0
+int igt_psr_get_sink_crc(int fd, char *data)
+{
+	int rc, errno_;
+	char buf[13];
+
+	memset(buf, 0, 13);
+	lseek(fd, 0, SEEK_SET);
+
+	rc = read(fd, buf, 12);
+	errno_ = errno;
+
+	if (rc == -1) {
+		if (errno_ == ENOTTY)
+			igt_info("Sink CRC not supported: panel

doesn't support it\n");

lib/igt_psr.c new file +2 -0
+		else if (errno_ != ETIMEDOUT)
+			igt_assert_f(rc != -1, "Unexpected error:

%d\n",

lib/igt_psr.c line 232

Quoted 9 lines
lib/igt_psr.c new file +9 -0
+				     errno_);
+		return errno_;
+	} else {
+		int i;
+		unsigned long long val = strtoull(buf, NULL, 16);
+
+		for (i = 5; i >= 0; i--, val >>= 8) {
+			data[i] = (unsigned char) (val & 0xff);
+		}

This is a very non-trivial piece of code, a comment here would be good.
Why are we doing this? I'm not sure what's the value in converting CRC
data formats when the only thing we do is check for equality.

Quoted 56 lines
lib/igt_psr.c new file +3 -0
+		return 0;
+	}
+}
lib/igt_psr.h new file +4 -0
new file mode 100644
index 0000000..d94cdfa
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */

lib/igt_psr.h new file +11 -0
+
+#ifndef IGT_PSR_H
+#define IGT_PSR_H
+
+#define igt_psr_enable() igt_set_module_param_int("enable_psr", 1)
+#define igt_psr_disable() igt_set_module_param_int("enable_psr", 0)
+
+bool igt_psr_sink_support(int fd);
+bool igt_psr_source_support(int fd);
+bool igt_psr_possible(int fd);
+bool igt_psr_active(int fd);

lib/igt_psr.h line 43

Quoted 10 lines
lib/igt_psr.h new file +10 -0
+bool igt_psr_await_status(int fd, bool active);
+bool igt_psr_enabled(int fd);
+void igt_psr_print_status(int fd);
+bool igt_psr_valid_connector(drmModeConnectorPtr connector);
+bool igt_psr_find_good_mode(drmModeConnectorPtr connector,
+			    drmModeModeInfoPtr *mode);
+int igt_psr_open_sink_crc(int drm_fd);
+int igt_psr_get_sink_crc(int fd, char *data);
+
+#endif /* IGT_PSR_H */

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

#13 lore raw

Re: [PATCH IGT v2 4/6] tests/kms_frontbuffer_tracking: Refactor to use IGT PSR library functions

In reply to Jim Bride

Em Sex, 2017-06-30 às 12:12 -0700, Jim Bride escreveu:

Quoted 128 lines

v2: * Minor functional tweaks and bug fixes
    * Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>

---
 tests/kms_frontbuffer_tracking.c | 119 +++++++--------------------
------------

 1 file changed, 19 insertions(+), 100 deletions(-)
tests/kms_frontbuffer_tracking.c +0 -0
index c24e4a8..3a8b754 100644
@@ -183,7 +183,7 @@ struct {
  };


tests/kms_frontbuffer_tracking.c +1 -1
-#define SINK_CRC_SIZE 12
+#define SINK_CRC_SIZE 6

 typedef struct {
  char data[SINK_CRC_SIZE];
 } sink_crc_t;

tests/kms_frontbuffer_tracking.c +0 -0
@@ -327,28 +327,6 @@ drmModeModeInfo std_1024_mode = {
  	.name = "Custom 1024x768",
  };


-static drmModeModeInfoPtr get_connector_smallest_mode(drmModeConnectorPtr c)

tests/kms_frontbuffer_tracking.c +0 -21
-{
-	int i;
-	drmModeModeInfoPtr smallest = NULL;
-
-	for (i = 0; i < c->count_modes; i++) {
-		drmModeModeInfoPtr mode = &c->modes[i];
-
-		if (!smallest)
-			smallest = mode;
-
-		if (mode->hdisplay * mode->vdisplay <
-		    smallest->hdisplay * smallest->vdisplay)
-			smallest = mode;
-	}
-
-	if (c->connector_type == DRM_MODE_CONNECTOR_eDP)
-		smallest = &std_1024_mode;
-
-	return smallest;
-}
-

 static drmModeConnectorPtr get_connector(uint32_t id) {
  int i;

tests/kms_frontbuffer_tracking.c +0 -0
@@ -421,30 +399,6 @@ static void init_mode_params(struct
 modeset_params *params, uint32_t crtc_id,
  	params->sprite.h = 64;
  }


-static bool connector_get_mode(drmModeConnectorPtr c, drmModeModeInfoPtr *mode)

tests/kms_frontbuffer_tracking.c +0 -7
-{
-	*mode = NULL;
-
-	if (c->connection != DRM_MODE_CONNECTED || !c->count_modes)
-		return false;
-
-	if (c->connector_type == DRM_MODE_CONNECTOR_eDP &&

opt.no_edp)

tests/kms_frontbuffer_tracking.c +0 -8
-		return false;
-
-	if (opt.small_modes)
-		*mode = get_connector_smallest_mode(c);
-	else
-		*mode = &c->modes[0];
-
-	 /* On HSW the CRC WA is so awful that it makes you think

everything is

tests/kms_frontbuffer_tracking.c +0 -8
-	  * bugged. */
-	if (IS_HASWELL(intel_get_drm_devid(drm.fd)) &&
-	    c->connector_type == DRM_MODE_CONNECTOR_eDP)
-		*mode = &std_1024_mode;
-
-	return true;
-}
-

 static bool connector_supports_pipe_a(drmModeConnectorPtr connector) {
  int i;

tests/kms_frontbuffer_tracking.c +1 -1
@@ -473,7 +427,7 @@ static bool find_connector(bool edp_only, bool
 pipe_a, uint32_t forbidden_id,
  			continue;
  		if (c->connector_id == forbidden_id)
  			continue;
-		if (!connector_get_mode(c, &mode))
+		if (!igt_psr_find_good_mode(c, &mode))
  			continue;


  *ret_connector = c;

tests/kms_frontbuffer_tracking.c +0 -0
@@ -804,23 +758,6 @@ static void fbc_print_status(void)
  	igt_info("FBC status:\n%s\n", buf);
  }

tests/kms_frontbuffer_tracking.c +0 -17
-static bool psr_is_enabled(void)
-{
-	char buf[256];
-
-	debugfs_read("i915_edp_psr_status", buf);
-	return strstr(buf, "\nActive: yes\n") &&
-	       strstr(buf, "\nHW Enabled & Active bit: yes\n");
-}
-
-static void psr_print_status(void)
-{
-	char buf[256];
-
-	debugfs_read("i915_edp_psr_status", buf);
-	igt_info("PSR status:\n%s\n", buf);
-}
-

 static struct timespec fbc_get_last_action(void)
 {
  struct timespec ret = { 0, 0 };

tests/kms_frontbuffer_tracking.c +0 -0
@@ -926,44 +863,31 @@ static bool fbc_wait_until_enabled(void)
  	return igt_wait(fbc_is_enabled(), 2000, 1);
  }

tests/kms_frontbuffer_tracking.c static bool fbc_wait_until_enabled(void) · line 931

Quoted 3 lines
tests/kms_frontbuffer_tracking.c +0 -3
-static bool psr_wait_until_enabled(void)
-{
-	return igt_wait(psr_is_enabled(), 5000, 1);

Changing the timeout from 5s to 10s is going to significantly increase the runtime for kms_frontbuffer_tracking.

Quoted 120 lines
tests/kms_frontbuffer_tracking.c +0 -2
-}
-

 #define fbc_enable() igt_set_module_param_int("enable_fbc", 1) #define fbc_disable() igt_set_module_param_int("enable_fbc", 0)

tests/kms_frontbuffer_tracking.c +0 -2
-#define psr_enable() igt_set_module_param_int("enable_psr", 1)
-#define psr_disable() igt_set_module_param_int("enable_psr", 0)


 static void get_sink_crc(sink_crc_t *crc, bool mandatory) {

tests/kms_frontbuffer_tracking.c +1 -1
-	int rc, errno_;
+	int rc;


  if (!sink_crc.supported) {
  memcpy(crc, "unsupported!", SINK_CRC_SIZE); return;
  }

tests/kms_frontbuffer_tracking.c +2 -6
-	lseek(sink_crc.fd, 0, SEEK_SET);
-
-	rc = read(sink_crc.fd, crc->data, SINK_CRC_SIZE);
-	errno_ = errno;
-
-	if (rc == -1 && errno_ == ENOTTY) {
+	rc = igt_psr_get_sink_crc(sink_crc.fd, crc->data);
+	if (rc == ENOTTY) {

  igt_info("Sink CRC not supported: panel doesn't support it\n");
  sink_crc.supported = false;

tests/kms_frontbuffer_tracking.c +0 -3
-	} else if (rc == -1 && errno_ == ETIMEDOUT) {
-		if (sink_crc.reliable) {
-			igt_info("Sink CRC is unreliable on this

machine.\n");

tests/kms_frontbuffer_tracking.c +2 -0
+	} else if (rc == ETIMEDOUT) {
+		if (sink_crc.reliable) 

  sink_crc.reliable = false;

tests/kms_frontbuffer_tracking.c +1 -1
-		}
+		


  if (mandatory)
  igt_skip("Sink CRC is unreliable on this machine.\n");
  } else {

tests/kms_frontbuffer_tracking.c +0 -1
-		igt_assert_f(rc != -1, "Unexpected error: %d\n",

errno_);

tests/kms_frontbuffer_tracking.c +1 -1
-		igt_assert(rc == SINK_CRC_SIZE);
+		igt_assert_f(rc == 0, "Unexpected error: %d\n", rc);

  }
 }

tests/kms_frontbuffer_tracking.c +0 -0
@@ -1180,7 +1104,7 @@ static void disable_features(const struct
 test_mode *t)
  		return;


  fbc_disable();

tests/kms_frontbuffer_tracking.c +1 -1
-	psr_disable();
+	igt_psr_disable();

 }

 static void *busy_thread_func(void *data)

tests/kms_frontbuffer_tracking.c +0 -0
@@ -1432,7 +1356,7 @@ static void setup_sink_crc(void)
  	fill_fb_region(&prim_mode_params.fb, COLOR_PRIM_BG);
  	set_mode_for_params(&prim_mode_params);

tests/kms_frontbuffer_tracking.c +0 -1
-	sink_crc.fd = openat(drm.debugfs, "i915_sink_crc_eDP1",

O_RDONLY);

tests/kms_frontbuffer_tracking.c +1 -0
+	sink_crc.fd = igt_psr_open_sink_crc(drm.debugfs);

  igt_assert_lte(0, sink_crc.fd);

  /* Do a first read to try to detect if it's supported. */

tests/kms_frontbuffer_tracking.c +0 -0
@@ -1547,14 +1471,6 @@ static void teardown_fbc(void)
  {
  }

tests/kms_frontbuffer_tracking.c +0 -8
-static bool psr_sink_has_support(void)
-{
-	char buf[256];
-
-	debugfs_read("i915_edp_psr_status", buf);
-	return strstr(buf, "Sink_Support: yes\n");
-}
-

 static void setup_psr(void)
 {
  if (get_connector(prim_mode_params.connector_id)-

Quoted 1 line

connector_type !=

tests/kms_frontbuffer_tracking.c +0 -0
@@ -1563,7 +1479,7 @@ static void setup_psr(void)
  		return;
  	}

tests/kms_frontbuffer_tracking.c +1 -1
-	if (!psr_sink_has_support()) {
+	if (!igt_psr_sink_support(drm.fd)) {

  igt_info("Can't test PSR: not supported by sink.\n");
  return;
  }

tests/kms_frontbuffer_tracking.c +0 -0
@@ -1717,12 +1633,15 @@ static int adjust_assertion_flags(const
 struct test_mode *t, int flags)
  	}								
 \


\
  if (flags_ & ASSERT_PSR_ENABLED) {
\

tests/kms_frontbuffer_tracking.c +0 -1
-		if (!psr_wait_until_enabled()) {			

\

tests/kms_frontbuffer_tracking.c +0 -1
-			psr_print_status();				

\

tests/kms_frontbuffer_tracking.c +1 -0
+		if (!igt_psr_await_status(drm.fd, true)) {	
	\
tests/kms_frontbuffer_tracking.c +1 -0
+			igt_psr_print_status(drm.fd);		
	\
 			igt_assert_f(false, "PSR disabled\n");	
	\

  }
\
  } else if (flags_ & ASSERT_PSR_DISABLED) { \

tests/kms_frontbuffer_tracking.c +0 -1
-		igt_assert(!psr_wait_until_enabled());		
	\

tests/kms_frontbuffer_tracking.c

Quoted 1 line
tests/kms_frontbuffer_tracking.c +1 -0
+		if (!igt_psr_await_status(drm.fd, false)) {	

There's a difference between "wait until disabled" and "wait until enabled". If we're expecting PSR to be disabled and we call wait_until_enabled(), we guarantee that PSR is going to be disabled during the whole timeout. And that's the point: guarantee that PSR stays disabled during the entire time, i.e., nothing enables it at any point in the next $timeout seconds. It could be the case that PSR got disabled and then re-enabled due to some delayed work function, and we want to prevent that by staying the whole timeout re-checking its status.

So here, if we just assert that PSR got disabled at some point during the timeout, we're changing the behavior of the test and we're losing the original purpose of the assertion.

Quoted 19 lines
	\
tests/kms_frontbuffer_tracking.c +1 -0
+			igt_psr_print_status(drm.fd);               

    \

tests/kms_frontbuffer_tracking.c +1 -0
+			igt_assert_f(false, "PSR enabled\n");	
	\
tests/kms_frontbuffer_tracking.c +1 -0
+		}							

\
  }
\
 } while (0)

tests/kms_frontbuffer_tracking.c +1 -1
@@ -1822,7 +1741,7 @@ static void enable_features_for_test(const
 struct test_mode *t)
  	if (t->feature & FEATURE_FBC)
  		fbc_enable();
  	if (t->feature & FEATURE_PSR)
-		psr_enable();
+		igt_psr_enable();
  }
Quoted 2 lines


 static void check_test_requirements(const struct test_mode *t)

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

#18 lore raw

Re: [PATCH IGT v2 6/6] tests/kms_fbcon_fbt: Refactor to use IGT PSR library functions

In reply to Jim Bride

Em Sex, 2017-06-30 às 12:12 -0700, Jim Bride escreveu:

Quoted 22 lines

v2: * Minor functional tweaks and bug fixes
    * Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>

---
 tests/kms_fbcon_fbt.c | 54 +++++++++++++++++----------------------
------------

 1 file changed, 18 insertions(+), 36 deletions(-)
tests/kms_fbcon_fbt.c +0 -0
index d009091..593adb9 100644
@@ -103,8 +103,9 @@ static bool fbc_is_enabled(int fd)
  	return strstr(buf, "FBC enabled\n");
  }

tests/kms_fbcon_fbt.c +1 -1
-static bool fbc_wait_until_enabled(int fd)
+static bool fbc_wait_until_enabled(int fd, bool enabled)

 {

tests/kms_fbcon_fbt.c static bool fbc_is_enabled(int fd) · line 108

Quoted 1 line
tests/kms_fbcon_fbt.c +1 -0
+	enabled = enabled;

If GCC is complaining, please use the appropriate annotations instead of doing this.

Quoted 41 lines

  return igt_wait(fbc_is_enabled(fd), 5000, 1); }

tests/kms_fbcon_fbt.c +0 -0
@@ -124,6 +125,13 @@ static void set_mode_for_one_screen(struct
 drm_info *drm, struct igt_fb *fb,


  if (c->connection == DRM_MODE_CONNECTED && c-

Quoted 1 line

count_modes &&

      connector_possible(c)) {

tests/kms_fbcon_fbt.c +1 -0
+			if (c->connector_type ==

DRM_MODE_CONNECTOR_eDP) {

tests/kms_fbcon_fbt.c +3 -0
+				bool bret;
+
+				bret = igt_psr_find_good_mode(c,

&mode);

tests/kms_fbcon_fbt.c +3 -0
+				if (bret)
+					break;
+			}

  mode = &c->modes[0];
  break;
  }

tests/kms_fbcon_fbt.c +0 -0
@@ -147,35 +155,9 @@ static void set_mode_for_one_screen(struct
 drm_info *drm, struct igt_fb *fb,
  	igt_assert_eq(rc, 0);
  }

tests/kms_fbcon_fbt.c +0 -11
-static bool psr_supported_on_chipset(int fd)
-{
-	char buf[256];
-
-	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
-	return strstr(buf, "Sink_Support: yes\n");
-}
-
-static bool connector_can_psr(drmModeConnectorPtr connector)
-{
-	return (connector->connector_type ==

DRM_MODE_CONNECTOR_eDP);

tests/kms_fbcon_fbt.c +0 -3
-}
-
-static bool psr_is_enabled(int fd)

tests/kms_fbcon_fbt.c static void set_mode_for_one_screen(struct drm_info *drm, struct igt_fb *fb, · line 173

Quoted 10 lines
tests/kms_fbcon_fbt.c +0 -10
-{
-	char buf[256];
-
-	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
-	return strstr(buf, "\nActive: yes\n");
-}
-
-static bool psr_wait_until_enabled(int fd)
-{
-	return igt_wait(psr_is_enabled(fd), 5000, 1);

Same problem here as we had in patch 4: changing the timeout from 5 to 10 is going to impact runtime significantly.

Quoted 61 lines
tests/kms_fbcon_fbt.c +0 -2
-}
-

 struct feature {
  bool (*supported_on_chipset)(int fd);

tests/kms_fbcon_fbt.c +1 -1
-	bool (*wait_until_enabled)(int fd);
+	bool (*wait_until_enabled)(int fd, bool status);

  bool (*connector_possible_fn)(drmModeConnectorPtr connector);
  const char *param_name;
 } fbc = {

tests/kms_fbcon_fbt.c +3 -3
@@ -184,9 +166,9 @@ struct feature {
  	.connector_possible_fn = connector_can_fbc,
  	.param_name = "enable_fbc",
  }, psr = {
-	.supported_on_chipset = psr_supported_on_chipset,
-	.wait_until_enabled = psr_wait_until_enabled,
-	.connector_possible_fn = connector_can_psr,
+	.supported_on_chipset = igt_psr_sink_support,
+	.wait_until_enabled = igt_psr_await_status,
+	.connector_possible_fn = igt_psr_valid_connector,
  	.param_name = "enable_psr",
  };

tests/kms_fbcon_fbt.c +0 -0
@@ -210,17 +192,17 @@ static void subtest(struct feature *feature,
 bool suspend)


  kmstest_unset_all_crtcs(drm.fd, drm.res);
  wait_user("Modes unset.");

tests/kms_fbcon_fbt.c +1 -1
-	igt_assert(!feature->wait_until_enabled(drm.fd));
+	igt_assert(!feature->wait_until_enabled(drm.fd, true));


  set_mode_for_one_screen(&drm, &fb, feature-

Quoted 1 line

connector_possible_fn);

  wait_user("Screen set.");

tests/kms_fbcon_fbt.c +1 -1
-	igt_assert(feature->wait_until_enabled(drm.fd));
+	igt_assert(feature->wait_until_enabled(drm.fd, true));


  if (suspend) { igt_system_suspend_autoresume(SUSPEND_STATE_MEM, SUSPEND_TEST_NONE); sleep(5);

tests/kms_fbcon_fbt.c +1 -1
-		igt_assert(feature->wait_until_enabled(drm.fd));
+		igt_assert(feature->wait_until_enabled(drm.fd,

true));
  }

  igt_remove_fb(drm.fd, &fb);

tests/kms_fbcon_fbt.c +0 -0
@@ -230,13 +212,13 @@ static void subtest(struct feature *feature,
 bool suspend)
  	sleep(3);


  wait_user("Back to fbcon.");

tests/kms_fbcon_fbt.c +1 -1
-	igt_assert(!feature->wait_until_enabled(drm.fd));
+	igt_assert(!feature->wait_until_enabled(drm.fd, true));


  if (suspend) { igt_system_suspend_autoresume(SUSPEND_STATE_MEM, SUSPEND_TEST_NONE); sleep(5);

tests/kms_fbcon_fbt.c +1 -1
-		igt_assert(!feature->wait_until_enabled(drm.fd));
+		igt_assert(!feature->wait_until_enabled(drm.fd,
Quoted 4 lines

true));
  }
 }

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

author
#5 lore raw

Re: [PATCH IGT v2 2/6] lib: Add PSR utility functions to igt library.

In reply to Rodrigo Vivi
Quoted 242 lines · Rodrigo Vivi
Quoted 228 lines · Jim Bride

Factor out some code that was replicated in three test utilities into some new IGT library functions so that we are checking PSR status in a consistent fashion across all of our PSR tests.

v2: * Add sink CRC helper function
* Misc. bug fixes
* Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>
---
 lib/Makefile.sources |   2 +
 lib/igt.h            |   1 +
 lib/igt_psr.c        | 235 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_psr.h        |  43 ++++++++++
 4 files changed, 281 insertions(+)
 create mode 100644 lib/igt_psr.c
 create mode 100644 lib/igt_psr.h
lib/Makefile.sources +2 -0
index 53fdb54..6a73c8c 100644
@@ -83,6 +83,8 @@ lib_source_list =             \
        uwildmat/uwildmat.c     \
        igt_kmod.c              \
        igt_kmod.h              \
+       igt_psr.c               \
+       igt_psr.h               \
        $(NULL)
 
 .PHONY: version.h.tmp
lib/igt.h +1 -0
index a069deb..0b8e3a8 100644
@@ -37,6 +37,7 @@
 #include "igt_gt.h"
 #include "igt_kms.h"
 #include "igt_pm.h"
+#include "igt_psr.h"
 #include "igt_stats.h"
 #ifdef HAVE_CHAMELIUM
 #include "igt_chamelium.h"
lib/igt_psr.c new file +177 -0
new file mode 100644
index 0000000..a2823bf
@@ -0,0 +1,235 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "igt.h"
+#include <stdio.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <string.h>
+#include <fcntl.h>
+
+/**
+ * SECTION:igt_psr
+ * @short_description: Panel Self Refresh helpers
+ * @title: Panel Self Refresh
+ * @include: igt.h
+ *
+ * This library provides various helpers to enable Panel Self Refresh,
+ * as well as to check the state of PSR on the system (enabled vs.
+ * disabled, active vs. inactive) or to wait for PSR to be active
+ * or inactive.
+ */
+
+/**
+ * igt_psr_source_support:
+ *
+ * Returns true if the source supports PSR.
+ */
+bool igt_psr_source_support(int fd)
+{
+       char buf[512];
+
+       igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+
+       return strstr(buf, "Source_OK: yes\n");
+}
+
+
+/**
+ * igt_psr_sink_support:
+ *
+ * Returns true if the current eDP panel supports PSR.
+ */
+bool igt_psr_sink_support(int fd)
+{
+       char buf[256];
+
+       igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+       return strstr(buf, "Sink_Support: yes\n");
+}
+
+/**
+ * igt_psr_possible:
+ *
+ * Returns true if both the source and sink support PSR.
+ */
+bool igt_psr_possible(int fd)
+{
+       char buf[512];
+
+       igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+
+       return igt_psr_source_support(fd) && igt_psr_sink_support(fd);
+}
+
+/**
+ * igt_psr_active:
+ *
+ * Returns true if PSR is active on the panel.
+ */
+bool igt_psr_active(int fd)
+{
+       char buf[512];
+       bool actret = false;
+       bool hwactret = false;
+
+       igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+       hwactret = (strstr(buf, "HW Enabled & Active bit: yes\n") != NULL);
+       actret = (strstr(buf, "Active: yes\n") != NULL);
+       igt_debug("hwactret: %s actret: %s\n", hwactret ? "true" : "false",
+                actret ? "true" : "false");
+       return hwactret && actret;
+}
+
+/**
+ * igt_psr_await_status:
+ * @active: A boolean that causes the function to wait for PSR to activate
+ *          if set to true, or to wait for PSR to deactivate if false.
+ *
+ * Returns true if the requested condition is met.
+ */
+bool igt_psr_await_status(int fd, bool active)
+{
+       const int timeout = 10;
+       int count = 0;
+       while (count < timeout) {
+               if (igt_psr_active(fd) == active) {
+                       igt_debug("PSR %s after %d seconds.\n",
+                                 active ? "Active" : "Inactive", count);
+                       return true;
+               }
+               count++;
+               sleep(1);
+       }
+       return false;
+}
+
+/**
+ * igt_psr_enabled:
+ *
+ * Returns true if the PSR feature is enabled.
+ */
+bool igt_psr_enabled(int fd)
+{
+       char buf[256];
+
+       igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+       return strstr(buf, "Enabled: yes\n");
+}
+
+/**
+ * igt_psr_print_status:
+ *
+ * Dumps the contents of i915_edp_psr_status from debugfs.
+ */
+void igt_psr_print_status(int fd)
+{
+        char buf[256];
+
+        igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+        igt_info("PSR status:\n%s\n", buf);
+}
+
+/**
+ * igt_psr_valid_connector:
+ * @connector: a drmModeConnector pointer to check
+ *
+ * Returns true if connector is an eDP connector.
+ */
+bool igt_psr_valid_connector(drmModeConnectorPtr connector)
+{
+       return (connector->connector_type == DRM_MODE_CONNECTOR_eDP);
+}
+
+/**
+ * igt_psr_find_good_mode
+ * @connector: a drmModeConnector pointer to find the mode on
+ * @mode: a drmModeModePtr pointer that is set to the matching mode
+ *
+ * Returns true (and populates *mode with the match) if a valid
+ * PSR mdoe is found, and false otherwise.
+ */
+bool igt_psr_find_good_mode(drmModeConnectorPtr connector,
+                           drmModeModeInfoPtr *mode)
+{
+       int i;
+
+       if (!connector->count_modes) {

lib/igt_psr.c line 187

Quoted 10 lines
lib/igt_psr.c new file +10 -0
+               igt_warn("no modes for connector %d.\n",
+                        connector->connector_id);
+               return false;
+       } else {
+               igt_debug("Connector has %d modes.\n", connector->count_modes);
+       }
+
+       for (i = 0; i < connector->count_modes; i++) {
+               if ((connector->modes[i].vtotal -
+                    connector->modes[i].vdisplay) >= 36) {

why 36?

Quoted 1 line

doesn't this depend on the panel setup time and on mode resolution?

We assume the worst case that the spec allows for this calculation as far as panel setup time goes. I should probably consider a #define here but basically 36 lines is what I came up with as a rough calculation as to how many lines of vertical blank are needed to accommodate the worst-case panel setup time.

Quoted 100 lines
Quoted 100 lines
lib/igt_psr.c new file +48 -0
+                       igt_debug("Mode %d good for PSR.\n", i);
+                       *mode = &(connector->modes[i]);
+                       return true;
+               } else {
+                       igt_debug("Throwing out mode %d\n", i);
+               }
+       }
+       return false;
+}
+
+int igt_psr_open_sink_crc(int drm_fd)
+{
+       int crc_fd;
+
+       crc_fd = openat(drm_fd, "i915_sink_crc_eDP1", O_RDONLY);
+       igt_assert_lte(0, crc_fd);
+       return crc_fd;
+}
+
+
+int igt_psr_get_sink_crc(int fd, char *data)
+{
+       int rc, errno_;
+       char buf[13];
+
+       memset(buf, 0, 13);
+       lseek(fd, 0, SEEK_SET);
+
+       rc = read(fd, buf, 12);
+       errno_ = errno;
+
+       if (rc == -1) {
+               if (errno_ == ENOTTY)
+                       igt_info("Sink CRC not supported: panel doesn't support it\n");
+               else if (errno_ != ETIMEDOUT)
+                       igt_assert_f(rc != -1, "Unexpected error: %d\n",
+                                    errno_);
+               return errno_;
+       } else {
+               int i;
+               unsigned long long val = strtoull(buf, NULL, 16);
+
+               for (i = 5; i >= 0; i--, val >>= 8) {
+                       data[i] = (unsigned char) (val & 0xff);
+               }
+               return 0;
+       }
+}
lib/igt_psr.h new file +43 -1
new file mode 100644
index 0000000..d94cdfa
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef IGT_PSR_H
+#define IGT_PSR_H
+
+#define igt_psr_enable() igt_set_module_param_int("enable_psr", 1)
+#define igt_psr_disable() igt_set_module_param_int("enable_psr", 0)
+
+bool igt_psr_sink_support(int fd);
+bool igt_psr_source_support(int fd);
+bool igt_psr_possible(int fd);
+bool igt_psr_active(int fd);
+bool igt_psr_await_status(int fd, bool active);
+bool igt_psr_enabled(int fd);
+void igt_psr_print_status(int fd);
+bool igt_psr_valid_connector(drmModeConnectorPtr connector);
+bool igt_psr_find_good_mode(drmModeConnectorPtr connector,
+                           drmModeModeInfoPtr *mode);
+int igt_psr_open_sink_crc(int drm_fd);
+int igt_psr_get_sink_crc(int fd, char *data);
+
+#endif /* IGT_PSR_H */
--

2.7.4

Quoted 10 lines
Quoted 4 lines

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

Signature · 2 lines
Rodrigo Vivi
Blog: http://blog.vivi.eng.br

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

author
#7 lore raw

Re: [PATCH IGT v2 2/6] lib: Add PSR utility functions to igt library.

In reply to Paulo Zanoni
Quoted 128 lines · Paulo Zanoni

Em Sex, 2017-06-30 às 12:12 -0700, Jim Bride escreveu:

Quoted 127 lines

Factor out some code that was replicated in three test utilities into some new IGT library functions so that we are checking PSR status in a consistent fashion across all of our PSR tests.

v2: * Add sink CRC helper function
    * Misc. bug fixes
    * Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>

---
 lib/Makefile.sources |   2 +
 lib/igt.h            |   1 +
 lib/igt_psr.c        | 235
+++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_psr.h        |  43 ++++++++++

 4 files changed, 281 insertions(+)

 create mode 100644 lib/igt_psr.c
 create mode 100644 lib/igt_psr.h

lib/Makefile.sources +2 -0
index 53fdb54..6a73c8c 100644
@@ -83,6 +83,8 @@ lib_source_list =	 	\
  	uwildmat/uwildmat.c	\
  	igt_kmod.c		\
  	igt_kmod.h		\
+	igt_psr.c		\
+	igt_psr.h		\
  	$(NULL)


 .PHONY: version.h.tmp

lib/igt.h +1 -0
index a069deb..0b8e3a8 100644
@@ -37,6 +37,7 @@
  #include "igt_gt.h"
  #include "igt_kms.h"
  #include "igt_pm.h"
+#include "igt_psr.h"
  #include "igt_stats.h"
  #ifdef HAVE_CHAMELIUM
  #include "igt_chamelium.h"
lib/igt_psr.c new file +4 -0
new file mode 100644
index 0000000..a2823bf
@@ -0,0 +1,235 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */

lib/igt_psr.c new file +15 -0
+
+#include "igt.h"
+#include <stdio.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <string.h>
+#include <fcntl.h>
+
+/**
+ * SECTION:igt_psr
+ * @short_description: Panel Self Refresh helpers
+ * @title: Panel Self Refresh
+ * @include: igt.h
+ *
+ * This library provides various helpers to enable Panel Self

Refresh,
+ * as well as to check the state of PSR on the system (enabled vs.
+ * disabled, active vs. inactive) or to wait for PSR to be active
+ * or inactive.
+ */

lib/igt_psr.c new file +19 -0
+
+/**
+ * igt_psr_source_support:
+ *
+ * Returns true if the source supports PSR.
+ */
+bool igt_psr_source_support(int fd)
+{
+	char buf[512];
+
+	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+
+	return strstr(buf, "Source_OK: yes\n");
+}
+
+
+/**
+ * igt_psr_sink_support:
+ *
Quoted 8 lines

lib/igt_psr.c line 65

Quoted 5 lines

+ * Returns true if the current eDP panel supports PSR.
+ */

lib/igt_psr.c new file +3 -0
+bool igt_psr_sink_support(int fd)
+{
+	char buf[256];

Why are some buffers 512 while the others are 256? They're both for the same file.

It's arbitrary. I'll make things consistent when I revisit this patch.

Quoted 60 lines
Quoted 60 lines
lib/igt_psr.c new file +17 -0
+
+	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+	return strstr(buf, "Sink_Support: yes\n");
+}
+
+/**
+ * igt_psr_possible:
+ *
+ * Returns true if both the source and sink support PSR.
+ */
+bool igt_psr_possible(int fd)
+{
+	char buf[512];
+
+	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+
+	return igt_psr_source_support(fd) &&

igt_psr_sink_support(fd);

lib/igt_psr.c new file +15 -0
+}
+
+/**
+ * igt_psr_active:
+ *
+ * Returns true if PSR is active on the panel.
+ */
+bool igt_psr_active(int fd)
+{
+	char buf[512];
+	bool actret = false;
+	bool hwactret = false;
+
+	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+	hwactret = (strstr(buf, "HW Enabled & Active bit: yes\n") !=

NULL);

lib/igt_psr.c new file +2 -0
+	actret = (strstr(buf, "Active: yes\n") != NULL);
+	igt_debug("hwactret: %s actret: %s\n", hwactret ? "true" :

"false",

lib/igt_psr.c new file +7 -0
+		 actret ? "true" : "false");
+	return hwactret && actret;
+}
+
+/**
+ * igt_psr_await_status:
+ * @active: A boolean that causes the function to wait for PSR to

activate
+ *          if set to true, or to wait for PSR to deactivate if false.
+ *
+ * Returns true if the requested condition is met.
+ */

lib/igt_psr.c new file +8 -0
+bool igt_psr_await_status(int fd, bool active)
+{
+	const int timeout = 10;
+	int count = 0;
+	while (count < timeout) {
+		if (igt_psr_active(fd) == active) {
+			igt_debug("PSR %s after %d seconds.\n",
+				  active ? "Active" : "Inactive",

count);

lib/igt_psr.c new file +1 -0
+			return true;
Quoted 8 lines

lib/igt_psr.c line 124

Quoted 5 lines
lib/igt_psr.c new file +5 -0
+		}
+		count++;
+		sleep(1);
+	}
+	return false;

Since this is in a lib now, can you please make use of igt_wait or just make it work as expected when the signal helper is active?

Sure.

Quoted 61 lines
Quoted 61 lines
lib/igt_psr.c new file +37 -0
+}
+
+/**
+ * igt_psr_enabled:
+ *
+ * Returns true if the PSR feature is enabled.
+ */
+bool igt_psr_enabled(int fd)
+{
+	char buf[256];
+
+	igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+	return strstr(buf, "Enabled: yes\n");
+}
+
+/**
+ * igt_psr_print_status:
+ *
+ * Dumps the contents of i915_edp_psr_status from debugfs.
+ */
+void igt_psr_print_status(int fd)
+{
+        char buf[256];
+
+        igt_debugfs_read(fd, "i915_edp_psr_status", buf);
+        igt_info("PSR status:\n%s\n", buf);
+}
+
+/**
+ * igt_psr_valid_connector:
+ * @connector: a drmModeConnector pointer to check
+ *
+ * Returns true if connector is an eDP connector.
+ */
+bool igt_psr_valid_connector(drmModeConnectorPtr connector)
+{
+	return (connector->connector_type ==

DRM_MODE_CONNECTOR_eDP);

lib/igt_psr.c new file +21 -0
+}
+
+/**
+ * igt_psr_find_good_mode
+ * @connector: a drmModeConnector pointer to find the mode on
+ * @mode: a drmModeModePtr pointer that is set to the matching mode
+ *
+ * Returns true (and populates *mode with the match) if a valid
+ * PSR mdoe is found, and false otherwise.
+ */
+bool igt_psr_find_good_mode(drmModeConnectorPtr connector,
+			    drmModeModeInfoPtr *mode)
+{
+	int i;
+
+	if (!connector->count_modes) {
+		igt_warn("no modes for connector %d.\n",
+			 connector->connector_id);
+		return false;
+	} else {
+		igt_debug("Connector has %d modes.\n", connector-
Quoted 1 line

count_modes);

Quoted 13 lines

lib/igt_psr.c line 190

Quoted 8 lines
lib/igt_psr.c new file +8 -0
+	}
+
+	for (i = 0; i < connector->count_modes; i++) {
+		if ((connector->modes[i].vtotal -
+		     connector->modes[i].vdisplay) >= 36) {
+			igt_debug("Mode %d good for PSR.\n", i);
+			*mode = &(connector->modes[i]);
+			return true;

Since the callers may be trying to find modes that fit other restrictions (e.g., kms_frontbuffer_tracking) I'd suggest you to extract igt_psr_mode_is_compatible(mode) with the vtotal/vdisplay check.

Can you explain what you mean by extract here? Do you mean have it live somewhere other than with the other PSR functions? If so, what would you suggest?

Quoted 13 lines
Quoted 13 lines
lib/igt_psr.c new file +12 -0
+		} else {
+			igt_debug("Throwing out mode %d\n", i);
+		}
+	}
+	return false;
+}
+
+int igt_psr_open_sink_crc(int drm_fd)
+{
+	int crc_fd;
+
+	crc_fd = openat(drm_fd, "i915_sink_crc_eDP1", O_RDONLY);
Quoted 8 lines

lib/igt_psr.c line 207

Quoted 5 lines
lib/igt_psr.c new file +5 -0
+	igt_assert_lte(0, crc_fd);
+	return crc_fd;
+}
+
+

Please add documentation for this one, especially around the expectation for "data".

Good call.

Quoted 23 lines
Quoted 23 lines
lib/igt_psr.c new file +14 -0
+int igt_psr_get_sink_crc(int fd, char *data)
+{
+	int rc, errno_;
+	char buf[13];
+
+	memset(buf, 0, 13);
+	lseek(fd, 0, SEEK_SET);
+
+	rc = read(fd, buf, 12);
+	errno_ = errno;
+
+	if (rc == -1) {
+		if (errno_ == ENOTTY)
+			igt_info("Sink CRC not supported: panel

doesn't support it\n");

lib/igt_psr.c new file +2 -0
+		else if (errno_ != ETIMEDOUT)
+			igt_assert_f(rc != -1, "Unexpected error:

%d\n",

lib/igt_psr.c new file +5 -0
+				     errno_);
+		return errno_;
+	} else {
+		int i;
+		unsigned long long val = strtoull(buf, NULL, 16);
Quoted 8 lines

lib/igt_psr.c line 232

Quoted 4 lines
lib/igt_psr.c new file +4 -0
+
+		for (i = 5; i >= 0; i--, val >>= 8) {
+			data[i] = (unsigned char) (val & 0xff);
+		}

This is a very non-trivial piece of code, a comment here would be good.
Why are we doing this? I'm not sure what's the value in converting CRC
data formats when the only thing we do is check for equality.

We were actually dealing with the CRC values differently across tests. In some cases the values were kept as strings and compared with string funcs, and in others they were converted to binary values and then compared with memcmp. I chose to have the binary values be what is used. I'll add a comment.

Quoted 58 lines
Quoted 58 lines
lib/igt_psr.c new file +3 -0
+		return 0;
+	}
+}
lib/igt_psr.h new file +4 -0
new file mode 100644
index 0000000..d94cdfa
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */

lib/igt_psr.h new file +13 -0
+
+#ifndef IGT_PSR_H
+#define IGT_PSR_H
+
+#define igt_psr_enable() igt_set_module_param_int("enable_psr", 1)
+#define igt_psr_disable() igt_set_module_param_int("enable_psr", 0)
+
+bool igt_psr_sink_support(int fd);
+bool igt_psr_source_support(int fd);
+bool igt_psr_possible(int fd);
+bool igt_psr_active(int fd);
+bool igt_psr_await_status(int fd, bool active);
+bool igt_psr_enabled(int fd);
Quoted 8 lines

lib/igt_psr.h line 43

Quoted 8 lines
lib/igt_psr.h new file +8 -0
+void igt_psr_print_status(int fd);
+bool igt_psr_valid_connector(drmModeConnectorPtr connector);
+bool igt_psr_find_good_mode(drmModeConnectorPtr connector,
+			    drmModeModeInfoPtr *mode);
+int igt_psr_open_sink_crc(int drm_fd);
+int igt_psr_get_sink_crc(int fd, char *data);
+
+#endif /* IGT_PSR_H */

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

Reviewed-by on v2 5/6
#16 lore raw

Re: [PATCH IGT v2 5/6] tests/kms_frontbuffer_tracking: Fix multidraw subtest

In reply to Jim Bride

Em Sex, 2017-06-30 às 12:12 -0700, Jim Bride escreveu:

Quoted 4 lines

The multidraw subtest was not taking whether or not the GEM buffer had
ever been in write-combining mode when checking for PSR state, so fix that.

Quoted 23 lines

---
 tests/kms_frontbuffer_tracking.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
tests/kms_frontbuffer_tracking.c +0 -0
index 3a8b754..c52d7a0 100644
@@ -2059,7 +2059,8 @@ static void multidraw_subtest(const struct
 test_mode *t)

  assertions = used_method != IGT_DRAW_MMAP_GTT ?
       ASSERT_LAST_ACTION_CHAN GED :
       ASSERT_NO_ACTION_CHANGE ;

tests/kms_frontbuffer_tracking.c +1 -1
-				if (op_disables_psr(t, used_method))
+				if (op_disables_psr(t, used_method)

&&

tests/kms_frontbuffer_tracking.c +1 -0
+				    !wc_used)
Quoted 4 lines

  assertions |= ASSERT_PSR_DISABLED;

  do_assertions(assertions);

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

author
#11 lore raw

Re: [PATCH IGT v2 4/6] tests/kms_frontbuffer_tracking: Refactor to use IGT PSR library functions

In reply to Rodrigo Vivi
Quoted 5 lines · Rodrigo Vivi

I believe it would be better to create the psr lib with only one function at time and on every patch that adds the new function already removes that from here and from frontbuffer tracking test as well...

easier to review and to make sure that we are not changing the behaviour.

I'm testing a new series with the requested structural changes and review feedback to-date. I hope to send them out on Monday (testing takes a while.)

Jim

Quoted 246 lines

also...

Quoted 15 lines · Jim Bride

v2: * Minor functional tweaks and bug fixes
* Rebase

Cc Rodrigo Vivi <[email protected]>
Cc Paulo Zanoni <[email protected]>
---
 tests/kms_frontbuffer_tracking.c | 119 +++++++--------------------------------
 1 file changed, 19 insertions(+), 100 deletions(-)
tests/kms_frontbuffer_tracking.c +0 -0
index c24e4a8..3a8b754 100644

tests/kms_frontbuffer_tracking.c struct { · line 186

Quoted 5 lines
tests/kms_frontbuffer_tracking.c +1 -1
@@ -183,7 +183,7 @@ struct {
 };
 
 
-#define SINK_CRC_SIZE 12
+#define SINK_CRC_SIZE 6

I believe this deserves a separated patch...

Quoted 107 lines
tests/kms_frontbuffer_tracking.c +1 -69
 typedef struct {
        char data[SINK_CRC_SIZE];
 } sink_crc_t;
@@ -327,28 +327,6 @@ drmModeModeInfo std_1024_mode = {
        .name = "Custom 1024x768",
 };
 
-static drmModeModeInfoPtr get_connector_smallest_mode(drmModeConnectorPtr c)
-{
-       int i;
-       drmModeModeInfoPtr smallest = NULL;
-
-       for (i = 0; i < c->count_modes; i++) {
-               drmModeModeInfoPtr mode = &c->modes[i];
-
-               if (!smallest)
-                       smallest = mode;
-
-               if (mode->hdisplay * mode->vdisplay <
-                   smallest->hdisplay * smallest->vdisplay)
-                       smallest = mode;
-       }
-
-       if (c->connector_type == DRM_MODE_CONNECTOR_eDP)
-               smallest = &std_1024_mode;
-
-       return smallest;
-}
-
 static drmModeConnectorPtr get_connector(uint32_t id)
 {
        int i;
@@ -421,30 +399,6 @@ static void init_mode_params(struct modeset_params *params, uint32_t crtc_id,
        params->sprite.h = 64;
 }
 
-static bool connector_get_mode(drmModeConnectorPtr c, drmModeModeInfoPtr *mode)
-{
-       *mode = NULL;
-
-       if (c->connection != DRM_MODE_CONNECTED || !c->count_modes)
-               return false;
-
-       if (c->connector_type == DRM_MODE_CONNECTOR_eDP && opt.no_edp)
-               return false;
-
-       if (opt.small_modes)
-               *mode = get_connector_smallest_mode(c);
-       else
-               *mode = &c->modes[0];
-
-        /* On HSW the CRC WA is so awful that it makes you think everything is
-         * bugged. */
-       if (IS_HASWELL(intel_get_drm_devid(drm.fd)) &&
-           c->connector_type == DRM_MODE_CONNECTOR_eDP)
-               *mode = &std_1024_mode;
-
-       return true;
-}
-
 static bool connector_supports_pipe_a(drmModeConnectorPtr connector)
 {
        int i;
@@ -473,7 +427,7 @@ static bool find_connector(bool edp_only, bool pipe_a, uint32_t forbidden_id,
                        continue;
                if (c->connector_id == forbidden_id)
                        continue;
-               if (!connector_get_mode(c, &mode))
+               if (!igt_psr_find_good_mode(c, &mode))
                        continue;
 
                *ret_connector = c;
@@ -804,23 +758,6 @@ static void fbc_print_status(void)
        igt_info("FBC status:\n%s\n", buf);
 }
 
-static bool psr_is_enabled(void)
-{
-       char buf[256];
-
-       debugfs_read("i915_edp_psr_status", buf);
-       return strstr(buf, "\nActive: yes\n") &&
-              strstr(buf, "\nHW Enabled & Active bit: yes\n");
-}
-
-static void psr_print_status(void)
-{
-       char buf[256];
-
-       debugfs_read("i915_edp_psr_status", buf);
-       igt_info("PSR status:\n%s\n", buf);
-}
-
 static struct timespec fbc_get_last_action(void)
 {
        struct timespec ret = { 0, 0 };
@@ -926,44 +863,31 @@ static bool fbc_wait_until_enabled(void)
        return igt_wait(fbc_is_enabled(), 2000, 1);
 }
 
-static bool psr_wait_until_enabled(void)
-{
-       return igt_wait(psr_is_enabled(), 5000, 1);
-}
-
 #define fbc_enable() igt_set_module_param_int("enable_fbc", 1)
 #define fbc_disable() igt_set_module_param_int("enable_fbc", 0)

tests/kms_frontbuffer_tracking.c static bool fbc_wait_until_enabled(void) · line 874

Quoted 10 lines
tests/kms_frontbuffer_tracking.c +1 -3
-#define psr_enable() igt_set_module_param_int("enable_psr", 1)
-#define psr_disable() igt_set_module_param_int("enable_psr", 0)
 
 static void get_sink_crc(sink_crc_t *crc, bool mandatory)
 {
-       int rc, errno_;
+       int rc;
 
        if (!sink_crc.supported) {
                memcpy(crc, "unsupported!", SINK_CRC_SIZE);

this doesn't fit anymore

Quoted 100 lines
tests/kms_frontbuffer_tracking.c +16 -27
                return;
        }
 
-       lseek(sink_crc.fd, 0, SEEK_SET);
-
-       rc = read(sink_crc.fd, crc->data, SINK_CRC_SIZE);
-       errno_ = errno;
-
-       if (rc == -1 && errno_ == ENOTTY) {
+       rc = igt_psr_get_sink_crc(sink_crc.fd, crc->data);
+       if (rc == ENOTTY) {
                igt_info("Sink CRC not supported: panel doesn't support it\n");
                sink_crc.supported = false;
-       } else if (rc == -1 && errno_ == ETIMEDOUT) {
-               if (sink_crc.reliable) {
-                       igt_info("Sink CRC is unreliable on this machine.\n");
+       } else if (rc == ETIMEDOUT) {
+               if (sink_crc.reliable)
                        sink_crc.reliable = false;
-               }
+
 
                if (mandatory)
                        igt_skip("Sink CRC is unreliable on this machine.\n");
        } else {
-               igt_assert_f(rc != -1, "Unexpected error: %d\n", errno_);
-               igt_assert(rc == SINK_CRC_SIZE);
+               igt_assert_f(rc == 0, "Unexpected error: %d\n", rc);
        }
 }
 
@@ -1180,7 +1104,7 @@ static void disable_features(const struct test_mode *t)
                return;
 
        fbc_disable();
-       psr_disable();
+       igt_psr_disable();
 }
 
 static void *busy_thread_func(void *data)
@@ -1432,7 +1356,7 @@ static void setup_sink_crc(void)
        fill_fb_region(&prim_mode_params.fb, COLOR_PRIM_BG);
        set_mode_for_params(&prim_mode_params);
 
-       sink_crc.fd = openat(drm.debugfs, "i915_sink_crc_eDP1", O_RDONLY);
+       sink_crc.fd = igt_psr_open_sink_crc(drm.debugfs);
        igt_assert_lte(0, sink_crc.fd);
 
        /* Do a first read to try to detect if it's supported. */
@@ -1547,14 +1471,6 @@ static void teardown_fbc(void)
 {
 }
 
-static bool psr_sink_has_support(void)
-{
-       char buf[256];
-
-       debugfs_read("i915_edp_psr_status", buf);
-       return strstr(buf, "Sink_Support: yes\n");
-}
-
 static void setup_psr(void)
 {
        if (get_connector(prim_mode_params.connector_id)->connector_type !=
@@ -1563,7 +1479,7 @@ static void setup_psr(void)
                return;
        }
 
-       if (!psr_sink_has_support()) {
+       if (!igt_psr_sink_support(drm.fd)) {
                igt_info("Can't test PSR: not supported by sink.\n");
                return;
        }
@@ -1717,12 +1633,15 @@ static int adjust_assertion_flags(const struct test_mode *t, int flags)
        }                                                               \
                                                                        \
        if (flags_ & ASSERT_PSR_ENABLED) {                              \
-               if (!psr_wait_until_enabled()) {                        \
-                       psr_print_status();                             \
+               if (!igt_psr_await_status(drm.fd, true)) {              \
+                       igt_psr_print_status(drm.fd);                   \
                        igt_assert_f(false, "PSR disabled\n");          \
                }                                                       \
        } else if (flags_ & ASSERT_PSR_DISABLED) {                      \
-               igt_assert(!psr_wait_until_enabled());                  \
+               if (!igt_psr_await_status(drm.fd, false)) {             \
+                       igt_psr_print_status(drm.fd);                   \
+                       igt_assert_f(false, "PSR enabled\n");           \
+               }                                                       \
        }                                                               \
 } while (0)
 
@@ -1822,7 +1741,7 @@ static void enable_features_for_test(const struct test_mode *t)
        if (t->feature & FEATURE_FBC)
                fbc_enable();
        if (t->feature & FEATURE_PSR)
-               psr_enable();
+               igt_psr_enable();
 }
 
Quoted 14 lines
Quoted 8 lines
tests/kms_frontbuffer_tracking.c +0 -1
 static void check_test_requirements(const struct test_mode *t)
--

2.7.4

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

Signature · 2 lines
Rodrigo Vivi
Blog: http://blog.vivi.eng.br

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