Allocator hacks #48
Loading…
Reference in New Issue
No description provided.
Delete Branch "pca006132/zynq-rs:alloc-hack"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hacks on the allocator for M-Labs/artiq-zynq#32
alloc_in_core1
.LGTM
If we're sure that one of the allocators is always used by only one core, we could get rid of the Mutex for just that one.
For the core0 allocator, yes.
Actually I am considering doing a CPU ID check for core0 allocator deallocation, and panic/log when we try to deallocate from core1 to core0 allocator, to help pinpoint the possible location for memory leak, as we should not transfer something located in core0 to core1.
@ -10,0 +10,4 @@
static ALLOCATOR: CortexA9Alloc =
CortexA9Alloc(Mutex::new(Heap::empty()), Mutex::new(Heap::empty()));
static mut FORCE_CORE1: bool = false;
We shouldn't need FORCE_CORE1 anymore.
@ -51,0 +91,4 @@
// It is possible for core1 to get reset while allocation/deallocation,
// as all core1 states should be cleared after reset,
// forcing the mutex to be unlocked should be safe.
ALLOCATOR.1.force_unlock();
With core-specific allocators, we shouldn't need mutexes either.
Related note: Due to this problem of resets while holding a mutex, we probably want to prefer
static mut
over a mutex in code that is executed by core1 in artiq-zynq.@ -51,0 +101,4 @@
#[cfg(feature = "alloc_core")]
/// Allocate memory in core1 heap. Should only be invoked in core0.
/// Done by temporarily overriding a flag to change the global allocator used.
pub unsafe fn alloc_in_core1<F, T>(f: F) -> T
should be unneeded, remove
@ -24,0 +44,4 @@
if start0 <= const_ptr && const_ptr < end0 {
self.0.lock()
} else if start1 <= const_ptr && const_ptr < end1 {
self.1.lock()
We shouldn't need to deallocate things in the heap of the other core, so check for MPIDR and that address range matches.
Not used in ARTIQ, but to make this crate more generic, we should be able to use the single-core allocator with the linker symbols that define the location of the heap.
Yes, there are conditions detecting
cfg!(not(feature = "alloc_core"))
and use the allocator 0.Right, but this provides only
init_alloc_ddr
and not something that would use linker symbols.