igt/gem_exec_(nop|blt): Repeat measurements at min/max GPU frequencies

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2015-03-26 12:09:57 +00:00
parent 7763349a9a
commit 2659cbbf64
2 changed files with 225 additions and 23 deletions

View File

@ -283,8 +283,92 @@ static void run(int object_size, bool dumb)
close(fd); close(fd);
} }
static int sysfs_read(const char *name)
{
char buf[4096];
int sysfd;
int len;
sprintf(buf, "/sys/class/drm/card%d/%s",
drm_get_card(), name);
sysfd = open(buf, O_RDONLY);
if (sysfd < 0)
return -1;
len = read(sysfd, buf, sizeof(buf)-1);
close(sysfd);
if (len < 0)
return -1;
buf[len] = '\0';
return atoi(buf);
}
static int sysfs_write(const char *name, int value)
{
char buf[4096];
int sysfd;
int len;
sprintf(buf, "/sys/class/drm/card%d/%s",
drm_get_card(), name);
sysfd = open(buf, O_WRONLY);
if (sysfd < 0)
return -1;
len = sprintf(buf, "%d", value);
len = write(sysfd, buf, len);
close(sysfd);
if (len < 0)
return len;
return 0;
}
static void set_auto_freq(void)
{
int min = sysfs_read("gt_RPn_freq_mhz");
int max = sysfs_read("gt_RP0_freq_mhz");
if (max <= min)
return;
igt_debug("Setting min to %dMHz, and max to %dMHz\n", min, max);
sysfs_write("gt_min_freq_mhz", min);
sysfs_write("gt_max_freq_mhz", max);
}
static void set_min_freq(void)
{
int min = sysfs_read("gt_RPn_freq_mhz");
igt_require(min > 0);
igt_debug("Setting min/max to %dMHz\n", min);
igt_require(sysfs_write("gt_min_freq_mhz", min) == 0 &&
sysfs_write("gt_max_freq_mhz", min) == 0);
}
static void set_max_freq(void)
{
int max = sysfs_read("gt_RP0_freq_mhz");
igt_require(max > 0);
igt_debug("Setting min/max to %dMHz\n", max);
igt_require(sysfs_write("gt_max_freq_mhz", max) == 0 &&
sysfs_write("gt_min_freq_mhz", max) == 0);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
const struct {
const char *suffix;
void (*func)(void);
} rps[] = {
{ "", set_auto_freq },
{ "-min", set_min_freq },
{ "-max", set_max_freq },
{ NULL, NULL },
}, *r;
int min = -1, max = -1;
int i; int i;
igt_subtest_init(argc, argv); igt_subtest_init(argc, argv);
@ -300,14 +384,26 @@ int main(int argc, char **argv)
return 0; return 0;
} }
igt_subtest("cold") min = sysfs_read("gt_min_freq_mhz");
max = sysfs_read("gt_max_freq_mhz");
for (r = rps; r->suffix; r++) {
r->func();
igt_subtest_f("cold%s", r->suffix)
run(OBJECT_SIZE, false); run(OBJECT_SIZE, false);
igt_subtest("normal") igt_subtest_f("normal%s", r->suffix)
run(OBJECT_SIZE, false); run(OBJECT_SIZE, false);
igt_subtest("dumb-buf") igt_subtest_f("dumb-buf%s", r->suffix)
run(OBJECT_SIZE, true); run(OBJECT_SIZE, true);
}
if (min > 0)
sysfs_write("gt_min_freq_mhz", min);
if (max > 0)
sysfs_write("gt_max_freq_mhz", max);
igt_exit(); igt_exit();
} }

View File

@ -46,6 +46,60 @@
#define LOCAL_I915_EXEC_VEBOX (4<<0) #define LOCAL_I915_EXEC_VEBOX (4<<0)
const uint32_t batch[2] = {MI_BATCH_BUFFER_END};
int device;
static int sysfs_read(const char *name)
{
char buf[4096];
struct stat st;
int sysfd;
int len;
if (fstat(device, &st))
return -1;
sprintf(buf, "/sys/class/drm/card%d/%s",
(int)(st.st_rdev & 0x7f), name);
sysfd = open(buf, O_RDONLY);
if (sysfd < 0)
return -1;
len = read(sysfd, buf, sizeof(buf)-1);
close(sysfd);
if (len < 0)
return -1;
buf[len] = '\0';
return atoi(buf);
}
static int sysfs_write(const char *name, int value)
{
char buf[4096];
struct stat st;
int sysfd;
int len;
if (fstat(device, &st))
return -1;
sprintf(buf, "/sys/class/drm/card%d/%s",
(int)(st.st_rdev & 0x7f), name);
sysfd = open(buf, O_WRONLY);
if (sysfd < 0)
return -1;
len = sprintf(buf, "%d", value);
len = write(sysfd, buf, len);
close(sysfd);
if (len < 0)
return len;
return 0;
}
static int dcmp(const void *A, const void *B) static int dcmp(const void *A, const void *B)
{ {
double a = *(double *)A, b = *(double *)B; double a = *(double *)A, b = *(double *)B;
@ -71,6 +125,9 @@ static void loop(int fd, uint32_t handle, unsigned ring_id, const char *ring_nam
int count; int count;
gem_require_ring(fd, ring_id); gem_require_ring(fd, ring_id);
igt_debug("RPS frequency range [%d, %d]\n",
sysfs_read("gt_min_freq_mhz"),
sysfs_read("gt_max_freq_mhz"));
memset(&gem_exec, 0, sizeof(gem_exec)); memset(&gem_exec, 0, sizeof(gem_exec));
gem_exec[0].handle = handle; gem_exec[0].handle = handle;
@ -115,34 +172,83 @@ static void loop(int fd, uint32_t handle, unsigned ring_id, const char *ring_nam
} }
} }
uint32_t batch[2] = {MI_BATCH_BUFFER_END}; static void set_auto_freq(void)
uint32_t handle; {
int fd; int min = sysfs_read("gt_RPn_freq_mhz");
int max = sysfs_read("gt_RP0_freq_mhz");
if (max <= min)
return;
igt_debug("Setting min to %dMHz, and max to %dMHz\n", min, max);
sysfs_write("gt_min_freq_mhz", min);
sysfs_write("gt_max_freq_mhz", max);
}
static void set_min_freq(void)
{
int min = sysfs_read("gt_RPn_freq_mhz");
igt_require(min > 0);
igt_debug("Setting min/max to %dMHz\n", min);
igt_require(sysfs_write("gt_min_freq_mhz", min) == 0 &&
sysfs_write("gt_max_freq_mhz", min) == 0);
}
static void set_max_freq(void)
{
int max = sysfs_read("gt_RP0_freq_mhz");
igt_require(max > 0);
igt_debug("Setting min/max to %dMHz\n", max);
igt_require(sysfs_write("gt_max_freq_mhz", max) == 0 &&
sysfs_write("gt_min_freq_mhz", max) == 0);
}
igt_main igt_main
{ {
igt_fixture { const struct {
fd = drm_open_any(); const char *suffix;
void (*func)(void);
handle = gem_create(fd, 4096); } rps[] = {
gem_write(fd, handle, 0, batch, sizeof(batch)); { "", set_auto_freq },
} { "-min", set_min_freq },
{ "-max", set_max_freq },
igt_subtest("render") { NULL, NULL },
loop(fd, handle, I915_EXEC_RENDER, "render"); }, *r;
int min = -1, max = -1;
igt_subtest("bsd") uint32_t handle = 0;
loop(fd, handle, I915_EXEC_BSD, "bsd");
igt_subtest("blt")
loop(fd, handle, I915_EXEC_BLT, "blt");
igt_subtest("vebox")
loop(fd, handle, LOCAL_I915_EXEC_VEBOX, "vebox");
igt_fixture { igt_fixture {
gem_close(fd, handle); device = drm_open_any();
close(fd); min = sysfs_read("gt_min_freq_mhz");
max = sysfs_read("gt_max_freq_mhz");
handle = gem_create(device, 4096);
gem_write(device, handle, 0, batch, sizeof(batch));
}
for (r = rps; r->suffix; r++) {
r->func();
igt_subtest_f("render%s", r->suffix)
loop(device, handle, I915_EXEC_RENDER, "render");
igt_subtest_f("bsd%s", r->suffix)
loop(device, handle, I915_EXEC_BSD, "bsd");
igt_subtest_f("blt%s", r->suffix)
loop(device, handle, I915_EXEC_BLT, "blt");
igt_subtest_f("vebox%s", r->suffix)
loop(device, handle, LOCAL_I915_EXEC_VEBOX, "vebox");
}
igt_fixture {
gem_close(device, handle);
if (min > 0)
sysfs_write("gt_min_freq_mhz", min);
if (max > 0)
sysfs_write("gt_max_freq_mhz", max);
close(device);
} }
} }