summaryrefslogtreecommitdiff
path: root/tests/eviction_common.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-03-09 12:27:32 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2017-03-09 12:30:20 +0000
commitd592fb9d40084de0d4bd107e817233b2ac5bb1b9 (patch)
tree515b76d0612da69ce258c465002ad3b6ddb96406 /tests/eviction_common.c
parent76f300d4d2475249a51c538cc41989f10f8c263a (diff)
igt/evictions: Isolate the mlock check in a separate process
The initial mlock() is to check we can assigned all of memory to ourselves -- without the kernel killing us. Move that check to an isolated process so that we sacrifice the child. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'tests/eviction_common.c')
-rw-r--r--tests/eviction_common.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/tests/eviction_common.c b/tests/eviction_common.c
index e39555de..300eb03d 100644
--- a/tests/eviction_common.c
+++ b/tests/eviction_common.c
@@ -133,8 +133,8 @@ static void mlocked_evictions(int fd, struct igt_eviction_test_ops *ops,
uint64_t surface_size,
uint64_t surface_count)
{
+ unsigned int *can_mlock;
uint64_t sz, pin;
- void *locked;
intel_require_memory(surface_count, surface_size, CHECK_RAM);
@@ -148,17 +148,22 @@ static void mlocked_evictions(int fd, struct igt_eviction_test_ops *ops,
(long long)pin/(1024*1024),
(long long)(pin + sz)/(1024*1024));
- locked = malloc(pin + sz);
- if (locked != NULL && mlock(locked, pin + sz)) {
- free(locked);
- locked = NULL;
- } else {
- munlock(locked, pin + sz);
- free(locked);
+ can_mlock = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
+ igt_assert(can_mlock != MAP_FAILED);
+
+ igt_fork(child, 1) {
+ void *locked;
+
+ locked = malloc(pin + sz);
+ if (locked != NULL && !mlock(locked, pin + sz))
+ *can_mlock = 1;
}
- igt_require(locked);
+ igt_waitchildren();
+ igt_require(*can_mlock);
+ munmap(can_mlock, 4096);
igt_fork(child, 1) {
+ void *locked;
uint32_t *bo;
uint64_t n;
int ret;