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:
Axel Dörfler
2005-03-23 15:08:25 +00:00
parent 531cc7dc91
commit ffc80308e6
6 changed files with 43 additions and 119 deletions
@@ -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
@@ -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
+34 -9
View File
@@ -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;
+1 -7
View File
@@ -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
+1 -19
View File
@@ -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;
}
+1 -1
View File
@@ -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);
}