Skip to contentSkip to conversation

Add two new subtests to pm_rps

PATCH New [email protected] 1 participant 6 messages Jan 29, 2014 – Feb 5, 2014 Library code

lore
Share & tools
lore
#0 lore raw

From: Jeff McGee <[email protected]>

Jeff McGee (4):
pm_rps: New subtest min-max-config-idle
lib/drmtest: Add igt_wait_helper
pm_rps: Add load helper for loading gpu
pm_rps: New subtest min-max-config-loaded

 lib/drmtest.c  |  17 +++++
 lib/drmtest.h  |   1 +
 tests/pm_rps.c | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 214 insertions(+), 4 deletions(-)
Signature · 1 line
1.8.5.2
#1 lore raw

PATCH 1/4 pm_rps: New subtest min-max-config-idle

From: Jeff McGee <[email protected]>

Like subtest basic-api, but additionally requires that current frequency is settling to the configured minimum within reasonable time since we are idle.

---
 tests/pm_rps.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
tests/pm_rps.c +30 -1
index 7d9069a..dabc2ba 100644
@@ -204,9 +204,12 @@ static void min_max_config(void (*check)(void))
 	log("\nIncrease max above RP0 (invalid)...\n");
 	writeval_inval(stuff[MAX].filp, origfreqs[RP0] + 1000);
 	check();
+
+	writeval(stuff[MIN].filp, origfreqs[MIN]);
+	writeval(stuff[MAX].filp, origfreqs[MAX]);
 }
 
-static void idle_check(void)
+static void basic_check(void)
 {
 	int freqs[NUMFREQ];
 
@@ -215,6 +218,29 @@ static void idle_check(void)
 	checkit(freqs);
 }
 
+#define IDLE_WAIT_TIMESTEP_MSEC 100
+#define IDLE_WAIT_TIMEOUT_MSEC 3000
+static void idle_check(void)
+{
+	int freqs[NUMFREQ];
+	int wait = 0;
+
+	/* Monitor frequencies until cur settles down to min, which should
+	 * happen within the allotted time */
+	do {
+		read_freqs(freqs);
+		dump(freqs);
+		checkit(freqs);
+		if (freqs[CUR] == freqs[MIN])
+			break;
+		usleep(1000 * IDLE_WAIT_TIMESTEP_MSEC);
+		wait += IDLE_WAIT_TIMESTEP_MSEC;
+	} while (wait < IDLE_WAIT_TIMEOUT_MSEC);
+
+	igt_assert(freqs[CUR] == freqs[MIN]);
+	log("Required %d msec to reach cur=min\n", wait);
+}
+
 static void pm_rps_exit_handler(int sig)
 {
 	if (origfreqs[MIN] > readval(stuff[MAX].filp)) {
@@ -291,6 +317,9 @@ int main(int argc, char **argv)
 	}
 
 	igt_subtest("basic-api")
+		min_max_config(basic_check);
+
+	igt_subtest("min-max-config-idle")
 		min_max_config(idle_check);
 
 	igt_exit();
Signature · 1 line
1.8.5.2
#2 lore raw

PATCH 2/4 lib/drmtest: Add igt_wait_helper

In reply to [email protected]

From: Jeff McGee <[email protected]>

igt_wait_helper compliments igt_stop_helper and is used when helper processes are expected to exit naturally.

---
 lib/drmtest.c | 17 +++++++++++++++++
 lib/drmtest.h |  1 +
 2 files changed, 18 insertions(+)
lib/drmtest.c +17 -0
index 8bc70a3..d3d81a3 100644
@@ -1241,6 +1241,23 @@ void igt_stop_helper(struct igt_helper_process *proc)
 	helper_process_count--;
 }
 
+void igt_wait_helper(struct igt_helper_process *proc)
+{
+	int status;
+
+	assert(proc->running);
+
+	while (waitpid(proc->pid, &status, 0) == -1 &&
+	       errno == EINTR)
+		;
+	igt_assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);
+
+	proc->running = false;
+
+	helper_process_pids[proc->id] = -1;
+	helper_process_count--;
+}
+
 static void children_exit_handler(int sig)
 {
 	int ret;
lib/drmtest.h +1 -0
index d42a6f7..f945a7e 100644
@@ -290,6 +290,7 @@ struct igt_helper_process {
 };
 bool __igt_fork_helper(struct igt_helper_process *proc);
 void igt_stop_helper(struct igt_helper_process *proc);
+void igt_wait_helper(struct igt_helper_process *proc);
 #define igt_fork_helper(proc) \
 	for (; __igt_fork_helper(proc); exit(0))
 
Signature · 1 line
1.8.5.2
#3 lore raw

PATCH 3/4 pm_rps: Add load helper for loading gpu

In reply to [email protected]

From: Jeff McGee <[email protected]>

The load helper submits repeated dword store commands to keep the gpu loaded while subtests running in the parent process check for expected rps response.

---
 tests/pm_rps.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 137 insertions(+), 3 deletions(-)
tests/pm_rps.c +137 -3
index dabc2ba..555bb7c 100644
@@ -33,9 +33,14 @@
 #include <unistd.h>
 #include <getopt.h>
 #include "drmtest.h"
+#include "intel_gpu_tools.h"
+#include "intel_bufmgr.h"
+#include "intel_batchbuffer.h"
 
 static bool verbose = false;
 
+static int drm_fd;
+
 static const char sysfs_base_path[] = "/sys/class/drm/card%d/gt_%s_freq_mhz";
 enum {
 	CUR,
@@ -137,6 +142,131 @@ static void dumpit(const int *freqs)
 #define dump(x) if (verbose) dumpit(x)
 #define log(...) if (verbose) printf(__VA_ARGS__)
 
+static struct load_helper {
+	int devid;
+	int has_ppgtt;
+	drm_intel_bufmgr *bufmgr;
+	struct intel_batchbuffer *batch;
+	drm_intel_bo *target_buffer;
+	bool ready;
+	bool exit;
+	struct igt_helper_process igt_proc;
+} lh;
+
+static void load_helper_signal_handler(int sig)
+{
+	lh.exit = true;
+}
+
+static void emit_store_dword_imm(uint32_t val)
+{
+	int cmd;
+	struct intel_batchbuffer *batch = lh.batch;
+
+	cmd = MI_STORE_DWORD_IMM;
+	if (!lh.has_ppgtt)
+		cmd |= MI_MEM_VIRTUAL;
+
+	if (intel_gen(lh.devid) >= 8) {
+		BEGIN_BATCH(4);
+		OUT_BATCH(cmd);
+		OUT_RELOC(lh.target_buffer, I915_GEM_DOMAIN_INSTRUCTION,
+			  I915_GEM_DOMAIN_INSTRUCTION, 0);
+		OUT_BATCH(0);
+		OUT_BATCH(val);
+		ADVANCE_BATCH();
+	} else {
+		BEGIN_BATCH(4);
+		OUT_BATCH(cmd);
+		OUT_BATCH(0); /* reserved */
+		OUT_RELOC(lh.target_buffer, I915_GEM_DOMAIN_INSTRUCTION,
+			  I915_GEM_DOMAIN_INSTRUCTION, 0);
+		OUT_BATCH(val);
+		ADVANCE_BATCH();
+	}
+}
+
+static void load_helper_run(void)
+{
+	assert(!lh.igt_proc.running);
+
+	igt_require(lh.ready == true);
+
+	igt_fork_helper(&lh.igt_proc) {
+		uint32_t val = 0;
+
+		signal(SIGUSR1, load_helper_signal_handler);
+
+		while (!lh.exit) {
+			emit_store_dword_imm(val);
+			intel_batchbuffer_flush_on_ring(lh.batch, 0);
+			val++;
+		}
+
+		log("load helper sent %u dword writes\n", val);
+	}
+}
+
+static void load_helper_stop(void)
+{
+	assert(lh.igt_proc.running);
+	kill(lh.igt_proc.pid, SIGUSR1);
+	igt_wait_helper(&lh.igt_proc);
+}
+
+/* The load helper resource is used by only some subtests. We attempt to
+ * initialize in igt_fixture but do our igt_require check only if a
+ * subtest attempts to run it */
+static void load_helper_init(void)
+{
+	lh.devid = intel_get_drm_devid(drm_fd);
+	lh.has_ppgtt = gem_uses_aliasing_ppgtt(drm_fd);
+
+	/* MI_STORE_DATA can only use GTT address on gen4+/g33 and needs
+	 * snoopable mem on pre-gen6. */
+	if (intel_gen(lh.devid) < 6) {
+		log("load helper init failed: pre-gen6 not supported\n");
+		return;
+	}
+
+	lh.bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
+	if (!lh.bufmgr) {
+		log("load helper init failed: buffer manager init\n");
+		return;
+	}
+	drm_intel_bufmgr_gem_enable_reuse(lh.bufmgr);
+
+	lh.batch = intel_batchbuffer_alloc(lh.bufmgr, lh.devid);
+	if (!lh.batch) {
+		log("load helper init failed: batch buffer alloc\n");
+		return;
+	}
+
+	lh.target_buffer = drm_intel_bo_alloc(lh.bufmgr, "target bo",
+					      4096, 4096);
+	if (!lh.target_buffer) {
+		log("load helper init failed: target buffer alloc\n");
+		return;
+	}
+
+	lh.ready = true;
+}
+
+static void load_helper_deinit(void)
+{
+	if (lh.igt_proc.running)
+		load_helper_stop();
+
+	if (lh.target_buffer)
+		drm_intel_bo_unreference(lh.target_buffer);
+
+	if (lh.batch)
+		intel_batchbuffer_free(lh.batch);
+
+	if (lh.bufmgr)
+		drm_intel_bufmgr_destroy(lh.bufmgr);
+}
+
 static void min_max_config(void (*check)(void))
 {
 	int fmid = (origfreqs[RPn] + origfreqs[RP0]) / 2;
@@ -250,6 +380,9 @@ static void pm_rps_exit_handler(int sig)
 		writeval(stuff[MIN].filp, origfreqs[MIN]);
 		writeval(stuff[MAX].filp, origfreqs[MAX]);
 	}
+
+	load_helper_deinit();
+	close(drm_fd);
 }
 
 static int opt_handler(int opt, int opt_index)
@@ -291,11 +424,10 @@ int main(int argc, char **argv)
 	igt_fixture {
 		const int device = drm_get_card();
 		struct junk *junk = stuff;
-		int fd, ret;
+		int ret;
 
 		/* Use drm_open_any to verify device existence */
-		fd = drm_open_any();
-		close(fd);
+		drm_fd = drm_open_any();
 
 		do {
 			int val = -1;
@@ -314,6 +446,8 @@ int main(int argc, char **argv)
 		read_freqs(origfreqs);
 
 		igt_install_exit_handler(pm_rps_exit_handler);
+
+		load_helper_init();
 	}
 
 	igt_subtest("basic-api")
Signature · 1 line
1.8.5.2
#4 lore raw

PATCH 4/4 pm_rps: New subtest min-max-config-loaded

In reply to [email protected]

From: Jeff McGee <[email protected]>

Like subtest basic-api, but additionally requires that current frequency is increasing to the configured maximum within reasonable time since we are loaded.

---
 tests/pm_rps.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
tests/pm_rps.c +29 -0
index 555bb7c..709e341 100644
@@ -371,6 +371,29 @@ static void idle_check(void)
 	log("Required %d msec to reach cur=min\n", wait);
 }
 
+#define LOADED_WAIT_TIMESTEP_MSEC 100
+#define LOADED_WAIT_TIMEOUT_MSEC 3000
+static void loaded_check(void)
+{
+	int freqs[NUMFREQ];
+	int wait = 0;
+
+	/* Monitor frequencies until cur increases to max, which should
+	 * happen within the allotted time */
+	do {
+		read_freqs(freqs);
+		dump(freqs);
+		checkit(freqs);
+		if (freqs[CUR] == freqs[MAX])
+			break;
+		usleep(1000 * LOADED_WAIT_TIMESTEP_MSEC);
+		wait += LOADED_WAIT_TIMESTEP_MSEC;
+	} while (wait < LOADED_WAIT_TIMEOUT_MSEC);
+
+	igt_assert(freqs[CUR] == freqs[MAX]);
+	log("Required %d msec to reach cur=max\n", wait);
+}
+
 static void pm_rps_exit_handler(int sig)
 {
 	if (origfreqs[MIN] > readval(stuff[MAX].filp)) {
@@ -456,5 +479,11 @@ int main(int argc, char **argv)
 	igt_subtest("min-max-config-idle")
 		min_max_config(idle_check);
 
+	igt_subtest("min-max-config-loaded") {
+		load_helper_run();
+		min_max_config(loaded_check);
+		load_helper_stop();
+	}
+
 	igt_exit();
 }
Signature · 1 line
1.8.5.2