diff --git a/src/kernel/libroot/posix/malloc/arch-specific.cpp b/src/kernel/libroot/posix/malloc/arch-specific.cpp index 62592618bf..c86547d5f5 100644 --- a/src/kernel/libroot/posix/malloc/arch-specific.cpp +++ b/src/kernel/libroot/posix/malloc/arch-specific.cpp @@ -48,12 +48,15 @@ static free_chunk *sFreeChunks; extern "C" status_t __init_heap(void) { - sHeapAreaSize = kInitialHeapSize; - sHeapBase = 0x10000000; - // let the heap start at 256 MB for now + hoardHeap::initNumProcs(); + sHeapAreaSize = kInitialHeapSize; // ToDo: add a VM call that instructs other areas to avoid the space after the heap when possible // (and if not, create it at the end of that range, so that the heap can grow as much as possible) + // Then, move the heap back to 256 or 512 MB + sHeapBase = 0x30000000; + // let the heap start at 3*256 MB for now + sHeapArea = create_area("heap", (void **)&sHeapBase, B_BASE_ADDRESS, sHeapAreaSize, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); @@ -141,39 +144,6 @@ hoardUnsbrk(void *ptr, long size) } -void -hoardCreateThread(hoardThreadType &thread, - void *(*function)(void *), void *arg) -{ - thread = spawn_thread((int32 (*)(void *))function, "hoard thread", - B_NORMAL_PRIORITY, arg); - if (thread < B_OK) - debugger("spawn_thread() failed!"); - - resume_thread(thread); -} - - -void -hoardJoinThread(hoardThreadType &thread) -{ - wait_for_thread(thread, NULL); -} - - -void -hoardSetConcurrency(int) -{ -} - - -int -hoardGetThreadID(void) -{ - return find_thread(NULL); -} - - void hoardLockInit(hoardLockType &lock, const char *name) { @@ -198,39 +168,9 @@ hoardUnlock(hoardLockType &lock) } -int -hoardGetPageSize(void) -{ - return B_PAGE_SIZE; -} - - -int -hoardGetNumProcessors(void) -{ - system_info info; - if (get_system_info(&info) != B_OK) - return 1; - - return info.cpu_count; -} - - void hoardYield(void) { } - -unsigned long -hoardInterlockedExchange(unsigned long *oldval, - unsigned long newval) -{ - // This *should* be made atomic. It's never used in the BeOS - // version, so this is included strictly for completeness. - unsigned long o = *oldval; - *oldval = newval; - return o; -} - } // namespace BPrivate diff --git a/src/kernel/libroot/posix/malloc/arch-specific.h b/src/kernel/libroot/posix/malloc/arch-specific.h index c774879519..e717f65d02 100644 --- a/src/kernel/libroot/posix/malloc/arch-specific.h +++ b/src/kernel/libroot/posix/malloc/arch-specific.h @@ -37,20 +37,7 @@ operator new(size_t, void *_P) return _P; } -typedef thread_id hoardThreadType; - namespace BPrivate { -///// Thread-related wrappers. - -void hoardCreateThread(hoardThreadType &t, - void *(*function)(void *), void *arg); -void hoardJoinThread(hoardThreadType &t); -void hoardSetConcurrency(int n); - -// Return a thread identifier appropriate for hashing: -// if the system doesn't produce consecutive thread id's, -// some hackery may be necessary. -int hoardGetThreadID(void); ///// Lock-related wrappers. @@ -60,16 +47,12 @@ void hoardUnlock(hoardLockType &lock); ///// Memory-related wrapper. -int hoardGetPageSize(void); void *hoardSbrk(long size); void hoardUnsbrk(void *ptr, long size); ///// Other. void hoardYield(void); -int hoardGetNumProcessors(void); -unsigned long hoardInterlockedExchange(unsigned long *oldval, - unsigned long newval); } // namespace BPrivate diff --git a/src/kernel/libroot/posix/malloc/heap.cpp b/src/kernel/libroot/posix/malloc/heap.cpp index f53f65d7f8..5ded94723e 100644 --- a/src/kernel/libroot/posix/malloc/heap.cpp +++ b/src/kernel/libroot/posix/malloc/heap.cpp @@ -20,7 +20,6 @@ #include "config.h" #include "heap.h" -#define NEED_LG #include "processheap.h" #include "superblock.h" @@ -100,6 +99,31 @@ size_t hoardHeap::_threshold[hoardHeap::SIZE_CLASSES] = { #endif +int hoardHeap::_numProcessors; +int hoardHeap::_numProcessorsMask; + + +// Return ceil(log_2(num)). +// num must be positive. + +static int +lg(int num) +{ + assert(num > 0); + int power = 0; + int n = 1; + // Invariant: 2^power == n. + while (n < num) { + n <<= 1; + power++; + } + return power; +} + + +// #pragma mark - + + hoardHeap::hoardHeap(void) : _index(0), _reusableSuperblocks(NULL), _reusableSuperblocksCount(0) @@ -420,16 +444,17 @@ hoardHeap::freeBlock(block * &b, superblock * &sb, return 0; } -// Static initialization of the number of processors (and a mask). -int hoardHeap::_numProcessors; -int hoardHeap::_numProcessorsMask; - -hoardHeap::_initNumProcs::_initNumProcs(void) +void +hoardHeap::initNumProcs(void) { - hoardHeap::_numProcessors = hoardGetNumProcessors(); + system_info info; + if (get_system_info(&info) != B_OK) + hoardHeap::_numProcessors = 1; + else + hoardHeap::_numProcessors = info.cpu_count; + hoardHeap::_numProcessorsMask = - (1 << (lg(hoardGetNumProcessors()) + 1)) - 1; + (1 << (lg(hoardHeap::_numProcessors) + 1)) - 1; } -static hoardHeap::_initNumProcs initProcs; diff --git a/src/kernel/libroot/posix/malloc/heap.h b/src/kernel/libroot/posix/malloc/heap.h index cef837a0e8..4de101bd38 100644 --- a/src/kernel/libroot/posix/malloc/heap.h +++ b/src/kernel/libroot/posix/malloc/heap.h @@ -211,13 +211,7 @@ class hoardHeap { static size_t _threshold[SIZE_CLASSES]; public: - // A little helper class that we use to define some statics. - class _initNumProcs { - public: - _initNumProcs(void); - }; - - friend class _initNumProcs; + static void initNumProcs(void); protected: // number of CPUs, cached diff --git a/src/kernel/libroot/posix/malloc/processheap.h b/src/kernel/libroot/posix/malloc/processheap.h index 340ab1774c..5d9125e674 100644 --- a/src/kernel/libroot/posix/malloc/processheap.h +++ b/src/kernel/libroot/posix/malloc/processheap.h @@ -183,24 +183,6 @@ processHeap::getLog(int i) #endif -#ifdef NEED_LG -// Return ceil(log_2(num)). -// num must be positive. -static int -lg(int num) -{ - assert(num > 0); - int power = 0; - int n = 1; - // Invariant: 2^power == n. - while (n < num) { - n <<= 1; - power++; - } - return power; -} -#endif /* NEED_LG */ - // Hash out the thread id to a heap and return an index to that heap. int @@ -209,7 +191,7 @@ processHeap::getHeapIndex(void) // Here we use the number of processors as the maximum number of heaps. // In fact, for efficiency, we just round up to the highest power of two, // times two. - int tid = hoardGetThreadID() & _numProcessorsMask; + int tid = find_thread(NULL) & _numProcessorsMask; assert(tid < MAX_HEAPS); return tid; } diff --git a/src/kernel/libroot/posix/malloc/wrapper.cpp b/src/kernel/libroot/posix/malloc/wrapper.cpp index 54f01660ca..1422c20c96 100644 --- a/src/kernel/libroot/posix/malloc/wrapper.cpp +++ b/src/kernel/libroot/posix/malloc/wrapper.cpp @@ -115,7 +115,7 @@ memalign(size_t alignment, size_t size) extern "C" void * valloc(size_t size) { - return memalign(hoardGetPageSize(), size); + return memalign(B_PAGE_SIZE, size); }