Some arch functions are no longer used, but called directly (like find_thread(NULL)
instead of hoardGetThreadID()). Removed unused arch functions. __init_heap() now calls hoardHeap::initNumProcs(); it's no longer initialized through a global constructor - that ensures that the heap can really be used by libroot's constructors (although it did work before as well, somehow). Moved the heap to 0x30000000 for now (limiting its size, but also ensuring free space after it) - until the VM can avoid the free space after the heap. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@11959 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -48,12 +48,15 @@ static free_chunk *sFreeChunks;
|
|||||||
extern "C" status_t
|
extern "C" status_t
|
||||||
__init_heap(void)
|
__init_heap(void)
|
||||||
{
|
{
|
||||||
sHeapAreaSize = kInitialHeapSize;
|
hoardHeap::initNumProcs();
|
||||||
sHeapBase = 0x10000000;
|
|
||||||
// let the heap start at 256 MB for now
|
|
||||||
|
|
||||||
|
sHeapAreaSize = kInitialHeapSize;
|
||||||
// ToDo: add a VM call that instructs other areas to avoid the space after the heap when possible
|
// 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)
|
// (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,
|
sHeapArea = create_area("heap", (void **)&sHeapBase, B_BASE_ADDRESS,
|
||||||
sHeapAreaSize, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
|
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
|
void
|
||||||
hoardLockInit(hoardLockType &lock, const char *name)
|
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
|
void
|
||||||
hoardYield(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
|
} // namespace BPrivate
|
||||||
|
|||||||
@@ -37,20 +37,7 @@ operator new(size_t, void *_P)
|
|||||||
return _P;
|
return _P;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef thread_id hoardThreadType;
|
|
||||||
|
|
||||||
namespace BPrivate {
|
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.
|
///// Lock-related wrappers.
|
||||||
|
|
||||||
@@ -60,16 +47,12 @@ void hoardUnlock(hoardLockType &lock);
|
|||||||
|
|
||||||
///// Memory-related wrapper.
|
///// Memory-related wrapper.
|
||||||
|
|
||||||
int hoardGetPageSize(void);
|
|
||||||
void *hoardSbrk(long size);
|
void *hoardSbrk(long size);
|
||||||
void hoardUnsbrk(void *ptr, long size);
|
void hoardUnsbrk(void *ptr, long size);
|
||||||
|
|
||||||
///// Other.
|
///// Other.
|
||||||
|
|
||||||
void hoardYield(void);
|
void hoardYield(void);
|
||||||
int hoardGetNumProcessors(void);
|
|
||||||
unsigned long hoardInterlockedExchange(unsigned long *oldval,
|
|
||||||
unsigned long newval);
|
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "heap.h"
|
#include "heap.h"
|
||||||
#define NEED_LG
|
|
||||||
#include "processheap.h"
|
#include "processheap.h"
|
||||||
#include "superblock.h"
|
#include "superblock.h"
|
||||||
|
|
||||||
@@ -100,6 +99,31 @@ size_t hoardHeap::_threshold[hoardHeap::SIZE_CLASSES] = {
|
|||||||
#endif
|
#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)
|
hoardHeap::hoardHeap(void)
|
||||||
:
|
:
|
||||||
_index(0), _reusableSuperblocks(NULL), _reusableSuperblocksCount(0)
|
_index(0), _reusableSuperblocks(NULL), _reusableSuperblocksCount(0)
|
||||||
@@ -420,16 +444,17 @@ hoardHeap::freeBlock(block * &b, superblock * &sb,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static initialization of the number of processors (and a mask).
|
|
||||||
|
|
||||||
int hoardHeap::_numProcessors;
|
void
|
||||||
int hoardHeap::_numProcessorsMask;
|
hoardHeap::initNumProcs(void)
|
||||||
|
|
||||||
hoardHeap::_initNumProcs::_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 =
|
hoardHeap::_numProcessorsMask =
|
||||||
(1 << (lg(hoardGetNumProcessors()) + 1)) - 1;
|
(1 << (lg(hoardHeap::_numProcessors) + 1)) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static hoardHeap::_initNumProcs initProcs;
|
|
||||||
|
|||||||
@@ -211,13 +211,7 @@ class hoardHeap {
|
|||||||
static size_t _threshold[SIZE_CLASSES];
|
static size_t _threshold[SIZE_CLASSES];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// A little helper class that we use to define some statics.
|
static void initNumProcs(void);
|
||||||
class _initNumProcs {
|
|
||||||
public:
|
|
||||||
_initNumProcs(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
friend class _initNumProcs;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// number of CPUs, cached
|
// number of CPUs, cached
|
||||||
|
|||||||
@@ -183,24 +183,6 @@ processHeap::getLog(int i)
|
|||||||
#endif
|
#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.
|
// Hash out the thread id to a heap and return an index to that heap.
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -209,7 +191,7 @@ processHeap::getHeapIndex(void)
|
|||||||
// Here we use the number of processors as the maximum number of heaps.
|
// 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,
|
// In fact, for efficiency, we just round up to the highest power of two,
|
||||||
// times two.
|
// times two.
|
||||||
int tid = hoardGetThreadID() & _numProcessorsMask;
|
int tid = find_thread(NULL) & _numProcessorsMask;
|
||||||
assert(tid < MAX_HEAPS);
|
assert(tid < MAX_HEAPS);
|
||||||
return tid;
|
return tid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ memalign(size_t alignment, size_t size)
|
|||||||
extern "C" void *
|
extern "C" void *
|
||||||
valloc(size_t size)
|
valloc(size_t size)
|
||||||
{
|
{
|
||||||
return memalign(hoardGetPageSize(), size);
|
return memalign(B_PAGE_SIZE, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user