kms_rotation_crc: Remove useless comments
[platform/upstream/intel-gpu-tools.git] / tests / pm_rps.c
index fc6bac6..c1156a5 100644 (file)
 #include <getopt.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <errno.h>
+
 #include "drmtest.h"
-#include "intel_gpu_tools.h"
+#include "intel_io.h"
 #include "intel_bufmgr.h"
 #include "intel_batchbuffer.h"
+#include "intel_chipset.h"
 #include "igt_debugfs.h"
+#include "ioctl_wrappers.h"
 
 static int drm_fd;
 
@@ -63,8 +67,6 @@ struct junk {
        { "cur", "r", NULL }, { "min", "rb+", NULL }, { "max", "rb+", NULL }, { "RP0", "r", NULL }, { "RP1", "r", NULL }, { "RPn", "r", NULL }, { NULL, NULL, NULL }
 };
 
-static igt_debugfs_t dfs;
-
 static int readval(FILE *filp)
 {
        int val;
@@ -110,25 +112,25 @@ static int do_writeval(FILE *filp, int val, int lerrno)
 
 static void checkit(const int *freqs)
 {
-       igt_assert(freqs[MIN] <= freqs[MAX]);
-       igt_assert(freqs[CUR] <= freqs[MAX]);
-       igt_assert(freqs[MIN] <= freqs[CUR]);
-       igt_assert(freqs[RPn] <= freqs[MIN]);
-       igt_assert(freqs[MAX] <= freqs[RP0]);
-       igt_assert(freqs[RP1] <= freqs[RP0]);
-       igt_assert(freqs[RPn] <= freqs[RP1]);
+       igt_assert_cmpint(freqs[MIN], <=, freqs[MAX]);
+       igt_assert_cmpint(freqs[CUR], <=, freqs[MAX]);
+       igt_assert_cmpint(freqs[MIN], <=, freqs[CUR]);
+       igt_assert_cmpint(freqs[RPn], <=, freqs[MIN]);
+       igt_assert_cmpint(freqs[MAX], <=, freqs[RP0]);
+       igt_assert_cmpint(freqs[RP1], <=, freqs[RP0]);
+       igt_assert_cmpint(freqs[RPn], <=, freqs[RP1]);
        igt_assert(freqs[RP0] != 0);
        igt_assert(freqs[RP1] != 0);
 }
 
 static void matchit(const int *freqs1, const int *freqs2)
 {
-       igt_assert(freqs1[CUR] == freqs2[CUR]);
-       igt_assert(freqs1[MIN] == freqs2[MIN]);
-       igt_assert(freqs1[MAX] == freqs2[MAX]);
-       igt_assert(freqs1[RP0] == freqs2[RP0]);
-       igt_assert(freqs1[RP1] == freqs2[RP1]);
-       igt_assert(freqs1[RPn] == freqs2[RPn]);
+       igt_assert_cmpint(freqs1[CUR], ==, freqs2[CUR]);
+       igt_assert_cmpint(freqs1[MIN], ==, freqs2[MIN]);
+       igt_assert_cmpint(freqs1[MAX], ==, freqs2[MAX]);
+       igt_assert_cmpint(freqs1[RP0], ==, freqs2[RP0]);
+       igt_assert_cmpint(freqs1[RP1], ==, freqs2[RP1]);
+       igt_assert_cmpint(freqs1[RPn], ==, freqs2[RPn]);
 }
 
 static void dump(const int *freqs)
@@ -156,6 +158,7 @@ static struct load_helper {
        enum load load;
        bool exit;
        struct igt_helper_process igt_proc;
+       drm_intel_bo *src, *dst;
 } lh;
 
 static void load_helper_signal_handler(int sig)
@@ -195,9 +198,10 @@ static void emit_store_dword_imm(uint32_t val)
 }
 
 #define LOAD_HELPER_PAUSE_USEC 500
+#define LOAD_HELPER_BO_SIZE (16*1024*1024)
 static void load_helper_set_load(enum load load)
 {
-       assert(lh.igt_proc.running);
+       igt_assert(lh.igt_proc.running);
 
        if (lh.load == load)
                return;
@@ -226,6 +230,10 @@ static void load_helper_run(enum load load)
                signal(SIGUSR2, load_helper_signal_handler);
 
                while (!lh.exit) {
+                       if (lh.load == HIGH)
+                               intel_copy_bo(lh.batch, lh.dst, lh.src,
+                                             LOAD_HELPER_BO_SIZE);
+
                        emit_store_dword_imm(val);
                        intel_batchbuffer_flush_on_ring(lh.batch, 0);
                        val++;
@@ -270,6 +278,13 @@ static void load_helper_init(void)
        lh.target_buffer = drm_intel_bo_alloc(lh.bufmgr, "target bo",
                                              4096, 4096);
        igt_assert(lh.target_buffer);
+
+       lh.dst = drm_intel_bo_alloc(lh.bufmgr, "dst bo",
+                                   LOAD_HELPER_BO_SIZE, 4096);
+       igt_assert(lh.dst);
+       lh.src = drm_intel_bo_alloc(lh.bufmgr, "src bo",
+                                   LOAD_HELPER_BO_SIZE, 4096);
+       igt_assert(lh.src);
 }
 
 static void load_helper_deinit(void)
@@ -279,6 +294,10 @@ static void load_helper_deinit(void)
 
        if (lh.target_buffer)
                drm_intel_bo_unreference(lh.target_buffer);
+       if (lh.src)
+               drm_intel_bo_unreference(lh.src);
+       if (lh.dst)
+               drm_intel_bo_unreference(lh.dst);
 
        if (lh.batch)
                intel_batchbuffer_free(lh.batch);
@@ -287,37 +306,6 @@ static void load_helper_deinit(void)
                drm_intel_bufmgr_destroy(lh.bufmgr);
 }
 
-static void stop_rings(void)
-{
-       int fd;
-       static const char data[] = "0xf";
-
-       fd = igt_debugfs_open(&dfs, "i915_ring_stop", O_WRONLY);
-       igt_assert(fd >= 0);
-
-       igt_debug("injecting ring stop\n");
-       igt_assert(write(fd, data, sizeof(data)) == sizeof(data));
-
-       close(fd);
-}
-
-static bool rings_stopped(void)
-{
-       int fd;
-       static char buf[128];
-       unsigned long long val;
-
-       fd = igt_debugfs_open(&dfs, "i915_ring_stop", O_RDONLY);
-       igt_assert(fd >= 0);
-
-       igt_assert(read(fd, buf, sizeof(buf)) > 0);
-       close(fd);
-
-       sscanf(buf, "%llx", &val);
-
-       return (bool)val;
-}
-
 static void min_max_config(void (*check)(void))
 {
        int fmid = (origfreqs[RPn] + origfreqs[RP0]) / 2;
@@ -403,7 +391,7 @@ static void basic_check(void)
 }
 
 #define IDLE_WAIT_TIMESTEP_MSEC 100
-#define IDLE_WAIT_TIMEOUT_MSEC 3000
+#define IDLE_WAIT_TIMEOUT_MSEC 10000
 static void idle_check(void)
 {
        int freqs[NUMFREQ];
@@ -421,7 +409,7 @@ static void idle_check(void)
                wait += IDLE_WAIT_TIMESTEP_MSEC;
        } while (wait < IDLE_WAIT_TIMEOUT_MSEC);
 
-       igt_assert(freqs[CUR] == freqs[MIN]);
+       igt_assert_cmpint(freqs[CUR], ==, freqs[MIN]);
        igt_debug("Required %d msec to reach cur=min\n", wait);
 }
 
@@ -444,12 +432,12 @@ static void loaded_check(void)
                wait += LOADED_WAIT_TIMESTEP_MSEC;
        } while (wait < LOADED_WAIT_TIMEOUT_MSEC);
 
-       igt_assert(freqs[CUR] == freqs[MAX]);
+       igt_assert_cmpint(freqs[CUR], ==, freqs[MAX]);
        igt_debug("Required %d msec to reach cur=max\n", wait);
 }
 
 #define STABILIZE_WAIT_TIMESTEP_MSEC 100
-#define STABILIZE_WAIT_TIMEOUT_MSEC 2000
+#define STABILIZE_WAIT_TIMEOUT_MSEC 10000
 static void stabilize_check(int *freqs)
 {
        int wait = 0;
@@ -469,13 +457,19 @@ static void reset(void)
        int pre_freqs[NUMFREQ];
        int post_freqs[NUMFREQ];
 
+       /*
+        * quiescent_gpu upsets the gpu and makes it get pegged to max somehow.
+        * Don't ask.
+        */
+       sleep(10);
+
        igt_debug("Apply low load...\n");
        load_helper_run(LOW);
        stabilize_check(pre_freqs);
 
        igt_debug("Stop rings...\n");
-       stop_rings();
-       while (rings_stopped())
+       igt_set_stop_rings(STOP_RING_DEFAULTS);
+       while (igt_get_stop_rings())
                usleep(1000 * 100);
        igt_debug("Ring stop cleared\n");
 
@@ -497,6 +491,43 @@ static void reset(void)
        idle_check();
 }
 
+static void blocking(void)
+{
+       int pre_freqs[NUMFREQ];
+       int post_freqs[NUMFREQ];
+
+       int fd = drm_open_any();
+       igt_assert(fd >= 0);
+
+       /*
+        * quiescent_gpu upsets the gpu and makes it get pegged to max somehow.
+        * Don't ask.
+        */
+       sleep(10);
+
+       igt_debug("Apply low load...\n");
+       load_helper_run(LOW);
+       stabilize_check(pre_freqs);
+       load_helper_stop();
+
+       sleep(5);
+
+       igt_debug("Kick gpu hard ...\n");
+       /* This relies on the blocking waits in quiescent_gpu and the kernel
+        * boost logic to ramp the gpu to full load. */
+       gem_quiescent_gpu(fd);
+       gem_quiescent_gpu(fd);
+
+       igt_debug("Apply low load again...\n");
+       load_helper_run(LOW);
+       stabilize_check(post_freqs);
+       load_helper_stop();
+       matchit(pre_freqs, post_freqs);
+
+       igt_debug("Removing load...\n");
+       idle_check();
+}
+
 static void pm_rps_exit_handler(int sig)
 {
        if (origfreqs[MIN] > readval(stuff[MAX].filp)) {
@@ -542,8 +573,6 @@ igt_main
                igt_install_exit_handler(pm_rps_exit_handler);
 
                load_helper_init();
-
-               igt_debugfs_init(&dfs);
        }
 
        igt_subtest("basic-api")
@@ -560,4 +589,7 @@ igt_main
 
        igt_subtest("reset")
                reset();
+
+       igt_subtest("blocking")
+               blocking();
 }