aboutsummaryrefslogtreecommitdiff
path: root/core/test
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2015-05-12 18:12:20 +0800
committerStewart Smith <stewart@linux.vnet.ibm.com>2015-05-13 14:01:35 +1000
commitf96dd8b3d82543ea733a7ab0e854b8331875d524 (patch)
tree41b87ac71ac02d24b0a37dc556974522e97c3831 /core/test
parent8f527a0290068f1b2224fcfd7d88d91eab6ddd6f (diff)
downloadskiboot-f96dd8b3d82543ea733a7ab0e854b8331875d524.zip
skiboot-f96dd8b3d82543ea733a7ab0e854b8331875d524.tar.gz
skiboot-f96dd8b3d82543ea733a7ab0e854b8331875d524.tar.bz2
core: Move free-list locking to a separate per-region lock
Currently, we have a single lock for the entire mem_region system; this protects both the global region list, and the allocations from each region. This means we can't allocate memory while traversing the global region list, as any malloc/realloc/free will try to acquire the mem_region lock again. This change separates the locking into different functions. We keep the mem_region_lock to protect the regions list, and introduce a per-region lock to protect allocations from the regions' free_lists. Then we remove the open-coded invocations of mem_alloc, where we'd avoided malloc() due to the above locking issue. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'core/test')
-rw-r--r--core/test/run-malloc-speed.c2
-rw-r--r--core/test/run-malloc.c28
-rw-r--r--core/test/run-mem_region.c2
-rw-r--r--core/test/run-mem_region_init.c2
4 files changed, 17 insertions, 17 deletions
diff --git a/core/test/run-malloc-speed.c b/core/test/run-malloc-speed.c
index 18c0de9..713a74b 100644
--- a/core/test/run-malloc-speed.c
+++ b/core/test/run-malloc-speed.c
@@ -90,7 +90,7 @@ int main(void)
+ skiboot_heap.len);
}
assert(mem_check(&skiboot_heap));
- assert(mem_region_lock.lock_val == 0);
+ assert(skiboot_heap.free_list_lock.lock_val == 0);
free(region_start(&skiboot_heap));
real_free(p);
return 0;
diff --git a/core/test/run-malloc.c b/core/test/run-malloc.c
index bbd2a48..723cb10 100644
--- a/core/test/run-malloc.c
+++ b/core/test/run-malloc.c
@@ -92,45 +92,45 @@ int main(void)
assert(p);
assert(p > (char *)test_heap);
assert(p + (1ULL << i) <= (char *)test_heap + TEST_HEAP_SIZE);
- assert(!mem_region_lock.lock_val);
+ assert(!skiboot_heap.free_list_lock.lock_val);
free(p);
- assert(!mem_region_lock.lock_val);
+ assert(!skiboot_heap.free_list_lock.lock_val);
assert(heap_empty());
}
/* Realloc as malloc. */
- mem_region_lock.lock_val = 0;
+ skiboot_heap.free_list_lock.lock_val = 0;
p = realloc(NULL, 100);
assert(p);
- assert(!mem_region_lock.lock_val);
+ assert(!skiboot_heap.free_list_lock.lock_val);
/* Realloc as free. */
p = realloc(p, 0);
assert(!p);
- assert(!mem_region_lock.lock_val);
+ assert(!skiboot_heap.free_list_lock.lock_val);
assert(heap_empty());
/* Realloc longer. */
p = realloc(NULL, 100);
assert(p);
- assert(!mem_region_lock.lock_val);
+ assert(!skiboot_heap.free_list_lock.lock_val);
p2 = realloc(p, 200);
assert(p2 == p);
- assert(!mem_region_lock.lock_val);
+ assert(!skiboot_heap.free_list_lock.lock_val);
free(p);
- assert(!mem_region_lock.lock_val);
+ assert(!skiboot_heap.free_list_lock.lock_val);
assert(heap_empty());
/* Realloc shorter. */
- mem_region_lock.lock_val = 0;
+ skiboot_heap.free_list_lock.lock_val = 0;
p = realloc(NULL, 100);
- assert(!mem_region_lock.lock_val);
+ assert(!skiboot_heap.free_list_lock.lock_val);
assert(p);
p2 = realloc(p, 1);
- assert(!mem_region_lock.lock_val);
+ assert(!skiboot_heap.free_list_lock.lock_val);
assert(p2 == p);
free(p);
- assert(!mem_region_lock.lock_val);
+ assert(!skiboot_heap.free_list_lock.lock_val);
assert(heap_empty());
/* zalloc failure */
@@ -152,7 +152,7 @@ int main(void)
assert(p2[63] == 'c');
free(p2);
assert(heap_empty());
- assert(!mem_region_lock.lock_val);
+ assert(!skiboot_heap.free_list_lock.lock_val);
/* Realloc with failure to allocate new size */
p2 = malloc(TEST_HEAP_SIZE - sizeof(struct alloc_hdr)*2);
@@ -176,7 +176,7 @@ int main(void)
free(p);
free(p4);
assert(heap_empty());
- assert(!mem_region_lock.lock_val);
+ assert(!skiboot_heap.free_list_lock.lock_val);
real_free(test_heap);
return 0;
diff --git a/core/test/run-mem_region.c b/core/test/run-mem_region.c
index db1ca02..e27459b 100644
--- a/core/test/run-mem_region.c
+++ b/core/test/run-mem_region.c
@@ -244,7 +244,7 @@ int main(void)
list_del(&r->list);
mem_free(&skiboot_heap, r, __location__);
}
- assert(mem_region_lock.lock_val == 0);
+ assert(skiboot_heap.free_list_lock.lock_val == 0);
__free(test_heap, "");
return 0;
}
diff --git a/core/test/run-mem_region_init.c b/core/test/run-mem_region_init.c
index bb606ef..7624057 100644
--- a/core/test/run-mem_region_init.c
+++ b/core/test/run-mem_region_init.c
@@ -177,7 +177,7 @@ int main(void)
}
assert(mem_check(&skiboot_heap));
}
- assert(mem_region_lock.lock_val == 0);
+ assert(skiboot_heap.free_list_lock.lock_val == 0);
real_free(heap);
return 0;
}