Skip to contentSkip to conversation

tests/pm_rc6_residency: simplify the residency counter check

PATCH New Imre Deak 1 participant 7 messages May 18, 2015

lore
Share & tools
lore

Imre Deak

author
#0 lore raw

PATCH 1/7 tests/pm_rc6_residency: simplify the residency counter check

The temporary vars only obfuscated things, so get rid of them. Also remove some redundant asserts and info messages.

The only functional change is that the counter delta will be checked only against a percentage based accuracy range (90%-100%) and not against a hard-coded limit (RC6_FUDGE). The two checks serve the same purpose and the former one is clearer.

---
 tests/pm_rc6_residency.c | 44 +++++++-------------------------------------
 1 file changed, 7 insertions(+), 37 deletions(-)
tests/pm_rc6_residency.c +7 -37
index a945b47..ad33292 100644
@@ -36,7 +36,6 @@
 #include "intel_chipset.h"
 
 #define SLEEP_DURATION 3000 // in milliseconds
-#define RC6_FUDGE 900 // in milliseconds
 #define CODE_TIME 50 // in microseconfs
 
 static unsigned int readit(const char *path)
@@ -89,46 +88,17 @@ static void read_rc6_residency( int value[], const char *name_of_rc6_residency)
 
 static void residency_accuracy(int value[],const char *name_of_rc6_residency)
 {
-	unsigned int flag_counter,flag_support;
-	double counter_result = 0;
 	unsigned int diff;
-	unsigned int  tmp_counter, tmp_support;
-	double counter;
-	flag_counter = 0;
-	flag_support = 0;
-	diff = (value[1] - value[0]);
+	double ratio;
 
-	igt_assert_f(diff <= (SLEEP_DURATION + RC6_FUDGE),"Diff was too high. That is unpossible\n");
-	igt_assert_f(diff >= (SLEEP_DURATION - RC6_FUDGE),"GPU was not in RC6 long enough. Check that "
-							"the GPU is as idle as possible(ie. no X, "
-							"running and running no other tests)\n");
+	diff = value[1] - value[0];
 
-	counter = ((double)value[1] - (double)value[0]) /(double) (SLEEP_DURATION + CODE_TIME);
+	ratio = (double)diff / (SLEEP_DURATION + CODE_TIME);
 
-	if( counter > 0.9 ){
-		counter_result = counter;
-		tmp_counter = 1;
-	}
-	else
-		tmp_counter = 0;
-
-	if( value [1] == 0){
-		tmp_support = 0;
-		igt_info("This machine/configuration doesn't support %s\n", name_of_rc6_residency);
-	}
-	else
-		tmp_support = 1;
-
-	flag_counter = flag_counter + tmp_counter;
-	flag_counter = flag_counter << 1;
-
-	flag_support = flag_support + tmp_support;
-	flag_support = flag_support << 1;
-
-	igt_info("The residency counter: %f \n", counter_result);
-	igt_skip_on_f(flag_support == 0 , "This machine didn't entry %s state.\n", name_of_rc6_residency);
-	igt_assert_f((flag_counter != 0) && (counter_result <=1) , "Sysfs RC6 residency counter is inaccurate.\n");
-	igt_info("This machine entry %s state.\n", name_of_rc6_residency);
+	igt_info("Residency in %s or deeper state: %u ms (ratio to expected duration: %.02f)\n",
+		 name_of_rc6_residency, diff, ratio);
+	igt_assert_f(ratio > 0.9 && ratio <= 1,
+		     "Sysfs RC6 residency counter is inaccurate.\n");
 }
 
 igt_main
Signature · 6 lines
2.1.4

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

PATCH 2/7 tetst/pm_rc6_residency: sanitize counter check function arguments

The counter check function (residency_accuracy) cares only about the counter delta, so no need to pass it the start/stop values separately. Simplify things to prepare for the upcoming patches.

No functional change.

---
 tests/pm_rc6_residency.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
tests/pm_rc6_residency.c +11 -10
index ad33292..ed20d3e 100644
@@ -54,13 +54,14 @@ static unsigned int readit(const char *path)
 	return ret;
 }
 
-static void read_rc6_residency( int value[], const char *name_of_rc6_residency)
+static int read_rc6_residency(const char *name_of_rc6_residency)
 {
 	unsigned int i;
 	const int device = drm_get_card();
 	char *path ;
 	int  ret;
 	FILE *file;
+	int value[2];
 
 	/* For some reason my ivb isn't idle even after syncing up with the gpu.
 	 * Let's add a sleept just to make it happy. */
@@ -84,15 +85,15 @@ static void read_rc6_residency( int value[], const char *name_of_rc6_residency)
 		value[i] = readit(path);
 	}
 	free(path);
+
+	return value[1] - value[0];
 }
 
-static void residency_accuracy(int value[],const char *name_of_rc6_residency)
+static void residency_accuracy(unsigned int diff,
+			       const char *name_of_rc6_residency)
 {
-	unsigned int diff;
 	double ratio;
 
-	diff = value[1] - value[0];
-
 	ratio = (double)diff / (SLEEP_DURATION + CODE_TIME);
 
 	igt_info("Residency in %s or deeper state: %u ms (ratio to expected duration: %.02f)\n",
@@ -105,7 +106,7 @@ igt_main
 {
 	int fd;
 	int devid = 0;
-	int rc6[2], rc6p[2], rc6pp[2], media[2];
+	int rc6, rc6p, rc6pp, media;
 
 	igt_skip_on_simulation();
 
@@ -115,13 +116,13 @@ igt_main
 		devid = intel_get_drm_devid(fd);
 		close(fd);
 
-		read_rc6_residency(rc6, "rc6");
+		rc6 = read_rc6_residency("rc6");
 		if (IS_VALLEYVIEW(devid) || IS_CHERRYVIEW(devid))
-			read_rc6_residency(media, "media_rc6");
+			media = read_rc6_residency("media_rc6");
 
 		if (IS_GEN6(devid) || IS_IVYBRIDGE(devid)) {
-			read_rc6_residency(rc6p, "rc6p");
-			read_rc6_residency(rc6pp, "rc6pp");
+			rc6p = read_rc6_residency("rc6p");
+			rc6pp = read_rc6_residency("rc6pp");
 		}
 	}
 
Signature · 6 lines
2.1.4

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

PATCH 3/7 tests/pm_rc6_residency: factor out the code to measure residencies

In reply to Imre Deak

The upcoming patches will add some additional logic around reading out the counter values, so factor out the readout code to prepare for those patches.

No functional change.

---
 tests/pm_rc6_residency.c | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)
tests/pm_rc6_residency.c +25 -13
index ed20d3e..14573eb 100644
@@ -38,6 +38,13 @@
 #define SLEEP_DURATION 3000 // in milliseconds
 #define CODE_TIME 50 // in microseconfs
 
+struct residencies {
+	int rc6;
+	int media_rc6;
+	int rc6p;
+	int rc6pp;
+};
+
 static unsigned int readit(const char *path)
 {
 	unsigned int ret;
@@ -102,11 +109,23 @@ static void residency_accuracy(unsigned int diff,
 		     "Sysfs RC6 residency counter is inaccurate.\n");
 }
 
+static void measure_residencies(int devid, struct residencies *res)
+{
+	res->rc6 = read_rc6_residency("rc6");
+	if (IS_VALLEYVIEW(devid) || IS_CHERRYVIEW(devid))
+		res->media_rc6 = read_rc6_residency("media_rc6");
+
+	if (IS_GEN6(devid) || IS_IVYBRIDGE(devid)) {
+		res->rc6p = read_rc6_residency("rc6p");
+		res->rc6pp = read_rc6_residency("rc6pp");
+	}
+}
+
 igt_main
 {
 	int fd;
 	int devid = 0;
-	int rc6, rc6p, rc6pp, media;
+	struct residencies res;
 
 	igt_skip_on_simulation();
 
@@ -116,29 +135,22 @@ igt_main
 		devid = intel_get_drm_devid(fd);
 		close(fd);
 
-		rc6 = read_rc6_residency("rc6");
-		if (IS_VALLEYVIEW(devid) || IS_CHERRYVIEW(devid))
-			media = read_rc6_residency("media_rc6");
-
-		if (IS_GEN6(devid) || IS_IVYBRIDGE(devid)) {
-			rc6p = read_rc6_residency("rc6p");
-			rc6pp = read_rc6_residency("rc6pp");
-		}
+		measure_residencies(devid, &res);
 	}
 
 	igt_subtest("rc6-accuracy")
-		residency_accuracy(rc6, "rc6");
+		residency_accuracy(res.rc6, "rc6");
 	igt_subtest("media-rc6-accuracy")
 		if (IS_VALLEYVIEW(devid) || IS_CHERRYVIEW(devid))
-			residency_accuracy(media, "media_rc6");
+			residency_accuracy(res.media_rc6, "media_rc6");
 	igt_subtest("rc6p-accuracy") {
 		if (!IS_GEN6(devid) && !IS_IVYBRIDGE(devid))
 			igt_skip("This platform doesn't support RC6p\n");
-		residency_accuracy(rc6p, "rc6p");
+		residency_accuracy(res.rc6p, "rc6p");
 	}
 	igt_subtest("rc6pp-accuracy") {
 		if (!IS_GEN6(devid) && !IS_IVYBRIDGE(devid))
 			igt_skip("This platform doesn't support RC6pp\n");
-		residency_accuracy(rc6pp, "rc6pp");
+		residency_accuracy(res.rc6pp, "rc6pp");
 	}
 }
Signature · 6 lines
2.1.4

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

PATCH 4/7 tests/pm_rc6_residency: sanitize the RC6 enabled mask check

In reply to Imre Deak

The way the test checks for the RC6 enabled mask atm doesn't work:
calling igt_success outside of any subtests doesn't have any effect. This means the test will run a 11 second idle loop for each RC6 state regardless if the platform supports these or have them enabled. Fix this by checking explicitly if a given RC6 state is enabled before reading out/checking the corresponding counter.

With this fix we can also get rid of the GEN6/IVB checks, since the RC6 mask check makes them redundant. We still need the VLV/CHV checks, since media RC6 doesn't have a separate bit in the mask.

---
 tests/pm_rc6_residency.c | 71 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 46 insertions(+), 25 deletions(-)
tests/pm_rc6_residency.c +46 -25
index 14573eb..276fd41 100644
@@ -38,6 +38,10 @@
 #define SLEEP_DURATION 3000 // in milliseconds
 #define CODE_TIME 50 // in microseconfs
 
+#define RC6_ENABLED	1
+#define RC6P_ENABLED	2
+#define RC6PP_ENABLED	4
+
 struct residencies {
 	int rc6;
 	int media_rc6;
@@ -61,29 +65,33 @@ static unsigned int readit(const char *path)
 	return ret;
 }
 
+static unsigned long get_rc6_enabled_mask(void)
+{
+	unsigned long rc6_mask;
+	char *path;
+	int ret;
+
+	ret = asprintf(&path, "/sys/class/drm/card%d/power/rc6_enable",
+		       drm_get_card());
+	igt_assert_neq(ret, -1);
+	rc6_mask = readit(path);
+	free(path);
+
+	return rc6_mask;
+}
+
 static int read_rc6_residency(const char *name_of_rc6_residency)
 {
 	unsigned int i;
 	const int device = drm_get_card();
 	char *path ;
 	int  ret;
-	FILE *file;
 	int value[2];
 
 	/* For some reason my ivb isn't idle even after syncing up with the gpu.
 	 * Let's add a sleept just to make it happy. */
 	sleep(5);
 
-	ret = asprintf(&path, "/sys/class/drm/card%d/power/rc6_enable", device);
-	igt_assert_neq(ret, -1);
-
-	file = fopen(path, "r");
-	igt_require(file);
-
-	/* claim success if no rc6 enabled. */
-	if (readit(path) == 0)
-		igt_success();
-
 	for(i = 0; i < 2; i++)
 	{
 		sleep(SLEEP_DURATION / 1000);
@@ -109,20 +117,26 @@ static void residency_accuracy(unsigned int diff,
 		     "Sysfs RC6 residency counter is inaccurate.\n");
 }
 
-static void measure_residencies(int devid, struct residencies *res)
+static void measure_residencies(int devid, unsigned int rc6_mask,
+				struct residencies *res)
 {
-	res->rc6 = read_rc6_residency("rc6");
-	if (IS_VALLEYVIEW(devid) || IS_CHERRYVIEW(devid))
+	if (rc6_mask & RC6_ENABLED)
+		res->rc6 = read_rc6_residency("rc6");
+
+	if ((rc6_mask & RC6_ENABLED) &&
+	    (IS_VALLEYVIEW(devid) || IS_CHERRYVIEW(devid)))
 		res->media_rc6 = read_rc6_residency("media_rc6");
 
-	if (IS_GEN6(devid) || IS_IVYBRIDGE(devid)) {
+	if (rc6_mask & RC6P_ENABLED)
 		res->rc6p = read_rc6_residency("rc6p");
+
+	if (rc6_mask & RC6PP_ENABLED)
 		res->rc6pp = read_rc6_residency("rc6pp");
-	}
 }
 
 igt_main
 {
+	unsigned int rc6_mask;
 	int fd;
 	int devid = 0;
 	struct residencies res;
@@ -135,22 +149,29 @@ igt_main
 		devid = intel_get_drm_devid(fd);
 		close(fd);
 
-		measure_residencies(devid, &res);
+		rc6_mask = get_rc6_enabled_mask();
+		measure_residencies(devid, rc6_mask, &res);
 	}
 
-	igt_subtest("rc6-accuracy")
+	igt_subtest("rc6-accuracy") {
+		igt_skip_on(!(rc6_mask & RC6_ENABLED));
+
 		residency_accuracy(res.rc6, "rc6");
-	igt_subtest("media-rc6-accuracy")
-		if (IS_VALLEYVIEW(devid) || IS_CHERRYVIEW(devid))
-			residency_accuracy(res.media_rc6, "media_rc6");
+	}
+	igt_subtest("media-rc6-accuracy") {
+		igt_skip_on(!((rc6_mask & RC6_ENABLED) &&
+			      (IS_VALLEYVIEW(devid) || IS_CHERRYVIEW(devid))));
+
+		residency_accuracy(res.media_rc6, "media_rc6");
+	}
 	igt_subtest("rc6p-accuracy") {
-		if (!IS_GEN6(devid) && !IS_IVYBRIDGE(devid))
-			igt_skip("This platform doesn't support RC6p\n");
+		igt_skip_on(!(rc6_mask & RC6P_ENABLED));
+
 		residency_accuracy(res.rc6p, "rc6p");
 	}
 	igt_subtest("rc6pp-accuracy") {
-		if (!IS_GEN6(devid) && !IS_IVYBRIDGE(devid))
-			igt_skip("This platform doesn't support RC6pp\n");
+		igt_skip_on(!(rc6_mask & RC6PP_ENABLED));
+
 		residency_accuracy(res.rc6pp, "rc6pp");
 	}
 }
Signature · 6 lines
2.1.4

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

PATCH 5/7 tests/pm_rc6_residency: remove redundant idle loops

In reply to Imre Deak

Currently the test runs a separate idle loop when reading out each RC6 counter. But there is no need for this, we can have a signle idle loop and read out all the counters at once.

This prepares for an upcoming patch where we need to consider the RC6P and RC6PP counters as well when checking RC6.

---
 tests/pm_rc6_residency.c | 49 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 16 deletions(-)
tests/pm_rc6_residency.c +33 -16
index 276fd41..7c89362 100644
@@ -82,26 +82,18 @@ static unsigned long get_rc6_enabled_mask(void)
 
 static int read_rc6_residency(const char *name_of_rc6_residency)
 {
-	unsigned int i;
+	unsigned int residency;
 	const int device = drm_get_card();
 	char *path ;
 	int  ret;
-	int value[2];
 
-	/* For some reason my ivb isn't idle even after syncing up with the gpu.
-	 * Let's add a sleept just to make it happy. */
-	sleep(5);
-
-	for(i = 0; i < 2; i++)
-	{
-		sleep(SLEEP_DURATION / 1000);
-		ret = asprintf(&path, "/sys/class/drm/card%d/power/%s_residency_ms",device,name_of_rc6_residency);
-		igt_assert_neq(ret, -1);
-		value[i] = readit(path);
-	}
+	ret = asprintf(&path, "/sys/class/drm/card%d/power/%s_residency_ms",
+		       device, name_of_rc6_residency);
+	igt_assert_neq(ret, -1);
+	residency = readit(path);
 	free(path);
 
-	return value[1] - value[0];
+	return residency;
 }
 
 static void residency_accuracy(unsigned int diff,
@@ -117,8 +109,8 @@ static void residency_accuracy(unsigned int diff,
 		     "Sysfs RC6 residency counter is inaccurate.\n");
 }
 
-static void measure_residencies(int devid, unsigned int rc6_mask,
-				struct residencies *res)
+static void read_residencies(int devid, unsigned int rc6_mask,
+			     struct residencies *res)
 {
 	if (rc6_mask & RC6_ENABLED)
 		res->rc6 = read_rc6_residency("rc6");
@@ -134,6 +126,31 @@ static void measure_residencies(int devid, unsigned int rc6_mask,
 		res->rc6pp = read_rc6_residency("rc6pp");
 }
 
+static void measure_residencies(int devid, unsigned int rc6_mask,
+				struct residencies *res)
+{
+	struct residencies start = { };
+	struct residencies end = { };
+
+	if (!rc6_mask)
+		return;
+
+	/*
+	 * For some reason my ivb isn't idle even after syncing up with the gpu.
+	 * Let's add a sleep just to make it happy.
+	 */
+	sleep(8);
+
+	read_residencies(devid, rc6_mask, &start);
+	sleep(SLEEP_DURATION / 1000);
+	read_residencies(devid, rc6_mask, &end);
+
+	res->rc6 = end.rc6 - start.rc6;
+	res->rc6p = end.rc6p - start.rc6p;
+	res->rc6pp = end.rc6pp - start.rc6pp;
+	res->media_rc6 = end.media_rc6 - start.media_rc6;
+}
+
 igt_main
 {
 	unsigned int rc6_mask;
Signature · 6 lines
2.1.4

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

PATCH 6/7 tests/pm_rc6_residency: fix counter readout in case of wrap-around

In reply to Imre Deak
---
 tests/pm_rc6_residency.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
tests/pm_rc6_residency.c +16 -3
index 7c89362..54a6b10 100644
@@ -131,6 +131,7 @@ static void measure_residencies(int devid, unsigned int rc6_mask,
 {
 	struct residencies start = { };
 	struct residencies end = { };
+	int retry;
 
 	if (!rc6_mask)
 		return;
@@ -141,9 +142,21 @@ static void measure_residencies(int devid, unsigned int rc6_mask,
 	 */
 	sleep(8);
 
-	read_residencies(devid, rc6_mask, &start);
-	sleep(SLEEP_DURATION / 1000);
-	read_residencies(devid, rc6_mask, &end);
+	/*
+	 * Retry in case of counter wrap-around. We simply re-run the
+	 * measurement, since the valid counter range is different on
+	 * different platforms and so fixing it up would be non-trivial.
+	 */
+	for (retry = 0; retry < 2; retry++) {
+		read_residencies(devid, rc6_mask, &start);
+		sleep(SLEEP_DURATION / 1000);
+		read_residencies(devid, rc6_mask, &end);
+
+		if (end.rc6 >= start.rc6 && end.media_rc6 >= start.media_rc6 &&
+		    end.rc6p >= start.rc6p && end.rc6pp >= start.rc6pp)
+			break;
+	}
+	igt_assert_f(retry < 2, "residency values are not consistent\n");
 
 	res->rc6 = end.rc6 - start.rc6;
 	res->rc6p = end.rc6p - start.rc6p;
Signature · 6 lines
2.1.4

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

PATCH 7/7 tests/pm_rc6_residency: fix check if RC6P or RC6PP is enabled

In reply to Imre Deak

The test checks the residency in a given RC6 state or any deeper states that are also enabled. For example the RC6 subtest checks the combined residency in RC6/RC6P/RC6PP. Since the kernel reported value for the RC6 residency doesn't include the RC6P or RC6PP residency we need to adjust the RC6 value accordingly. A similar adjustment is needed for the RC6P subtest.

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

---
 tests/pm_rc6_residency.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
tests/pm_rc6_residency.c +11 -0
index 54a6b10..9203d2f 100644
@@ -162,6 +162,17 @@ static void measure_residencies(int devid, unsigned int rc6_mask,
 	res->rc6p = end.rc6p - start.rc6p;
 	res->rc6pp = end.rc6pp - start.rc6pp;
 	res->media_rc6 = end.media_rc6 - start.media_rc6;
+
+	/*
+	 * For the purposes of this test case we want a given residency value
+	 * to include the time spent in the corresponding RC state _and_ also
+	 * the time spent in any enabled deeper states. So for example if any
+	 * of RC6P or RC6PP is enabled we want the time spent in these states
+	 * to be also included in the RC6 residency value. The kernel reported
+	 * residency values are exclusive, so add up things here.
+	 */
+	res->rc6p += res->rc6pp;
+	res->rc6 += res->rc6p;
 }
 
 igt_main
Signature · 6 lines
2.1.4

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