igt/gem_mmap_wc: Test cpu mmap vs wc mmap coherency

Similar to the cpu mmap vs gtt mmap coherency test.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson
2016-01-08 16:32:29 +00:00
parent 571b876544
commit a6090c7191
4 changed files with 88 additions and 52 deletions
+2 -52
View File
@@ -253,56 +253,6 @@ test_write_gtt(int fd)
munmap(src, OBJECT_SIZE);
}
static unsigned int clflush_size;
static int setup_clflush(void)
{
FILE *file;
char *line = NULL;
size_t size = 0;
int first_stanza = 1;
int has_clflush = 0;
file = fopen("/proc/cpuinfo", "r");
if (file == NULL)
return 0;
while (getline(&line, &size, file) != -1) {
if (strncmp(line, "processor", 9) == 0) {
if (!first_stanza)
break;
first_stanza = 0;
}
if (strncmp(line, "flags", 5) == 0) {
if (strstr(line, "clflush"))
has_clflush = 1;
}
if (strncmp(line, "clflush size", 12) == 0) {
char *colon = strchr(line, ':');
if (colon)
clflush_size = atoi(colon + 1);
}
}
free(line);
fclose(file);
return has_clflush && clflush_size;
}
static void clflush(void *addr, int size)
{
char *p, *end;
end = (char *)addr + size;
p = (char *)((uintptr_t)addr & ~((uintptr_t)clflush_size - 1));
asm volatile("mfence" ::: "memory");
for (; p < end; p += clflush_size)
asm volatile("clflush %0" : "+m" (*(volatile char *)p));
asm volatile("mfence" ::: "memory");
}
static void
test_coherency(int fd)
{
@@ -310,7 +260,7 @@ test_coherency(int fd)
uint32_t *gtt, *cpu;
int i;
igt_require(setup_clflush());
igt_require(igt_setup_clflush());
handle = gem_create(fd, OBJECT_SIZE);
@@ -321,7 +271,7 @@ test_coherency(int fd)
for (i = 0; i < OBJECT_SIZE / 64; i++) {
int x = 16*i + (i%16);
gtt[x] = i;
clflush(&cpu[x], sizeof(cpu[x]));
igt_clflush_range(&cpu[x], sizeof(cpu[x]));
igt_assert_eq(cpu[x], i);
}