libroot: Fix Hoard when the CPU count is not a power of two
This commit is contained in:
parent
82727571c3
commit
8cf2f36c37
@ -99,6 +99,7 @@ size_t hoardHeap::_threshold[hoardHeap::SIZE_CLASSES] = {
|
||||
#endif
|
||||
|
||||
|
||||
int hoardHeap::fMaxThreadHeaps = 1;
|
||||
int hoardHeap::_numProcessors;
|
||||
int hoardHeap::_numProcessorsMask;
|
||||
|
||||
@ -454,7 +455,7 @@ hoardHeap::initNumProcs(void)
|
||||
else
|
||||
hoardHeap::_numProcessors = info.cpu_count;
|
||||
|
||||
hoardHeap::_numProcessorsMask =
|
||||
(1 << (lg(hoardHeap::_numProcessors) + 1)) - 1;
|
||||
fMaxThreadHeaps = 1 << (lg(_numProcessors) + 1);
|
||||
_numProcessorsMask = fMaxThreadHeaps - 1;
|
||||
}
|
||||
|
||||
|
@ -205,6 +205,12 @@ class hoardHeap {
|
||||
static void initNumProcs(void);
|
||||
|
||||
protected:
|
||||
// The maximum number of thread heaps we allow. (NOT the maximum
|
||||
// number of threads -- Hoard imposes no such limit.) This must be
|
||||
// a power of two! NB: This number is twice the maximum number of
|
||||
// PROCESSORS supported by Hoard.
|
||||
static int fMaxThreadHeaps;
|
||||
|
||||
// number of CPUs, cached
|
||||
static int _numProcessors;
|
||||
static int _numProcessorsMask;
|
||||
|
@ -37,8 +37,7 @@ using namespace BPrivate;
|
||||
|
||||
processHeap::processHeap()
|
||||
:
|
||||
kMaxThreadHeaps(_numProcessors * 2),
|
||||
theap((HEAPTYPE*)hoardSbrk(sizeof(HEAPTYPE) * kMaxThreadHeaps)),
|
||||
theap((HEAPTYPE*)hoardSbrk(sizeof(HEAPTYPE) * fMaxThreadHeaps)),
|
||||
#if HEAP_FRAG_STATS
|
||||
_currentAllocated(0),
|
||||
_currentRequested(0),
|
||||
@ -48,32 +47,32 @@ processHeap::processHeap()
|
||||
#endif
|
||||
#if HEAP_LOG
|
||||
_log((Log<MemoryRequest>*)
|
||||
hoardSbrk(sizeof(Log<MemoryRequest>) * (kMaxThreadHeaps + 1))),
|
||||
hoardSbrk(sizeof(Log<MemoryRequest>) * (fMaxThreadHeaps + 1))),
|
||||
#endif
|
||||
_buffer(NULL),
|
||||
_bufferCount(0)
|
||||
{
|
||||
if (theap == NULL)
|
||||
return;
|
||||
new(theap) HEAPTYPE[kMaxThreadHeaps];
|
||||
new(theap) HEAPTYPE[fMaxThreadHeaps];
|
||||
|
||||
#if HEAP_LOG
|
||||
if (_log == NULL)
|
||||
return;
|
||||
new(_log) Log<MemoryRequest>[kMaxThreadHeaps + 1];
|
||||
new(_log) Log<MemoryRequest>[fMaxThreadHeaps + 1];
|
||||
#endif
|
||||
|
||||
int i;
|
||||
// The process heap is heap 0.
|
||||
setIndex(0);
|
||||
for (i = 0; i < kMaxThreadHeaps; i++) {
|
||||
for (i = 0; i < fMaxThreadHeaps; i++) {
|
||||
// Set every thread's process heap to this one.
|
||||
theap[i].setpHeap(this);
|
||||
// Set every thread heap's index.
|
||||
theap[i].setIndex(i + 1);
|
||||
}
|
||||
#if HEAP_LOG
|
||||
for (i = 0; i < kMaxThreadHeaps + 1; i++) {
|
||||
for (i = 0; i < fMaxThreadHeaps + 1; i++) {
|
||||
char fname[255];
|
||||
sprintf(fname, "log%d", i);
|
||||
unlink(fname);
|
||||
@ -94,7 +93,7 @@ processHeap::stats(void)
|
||||
#if HEAP_STATS
|
||||
int umax = 0;
|
||||
int amax = 0;
|
||||
for (int j = 0; j < kMaxThreadHeaps; j++) {
|
||||
for (int j = 0; j < fMaxThreadHeaps; j++) {
|
||||
for (int i = 0; i < SIZE_CLASSES; i++) {
|
||||
amax += theap[j].maxAllocated(i) * sizeFromClass(i);
|
||||
umax += theap[j].maxInUse(i) * sizeFromClass(i);
|
||||
@ -118,7 +117,7 @@ processHeap::stats(void)
|
||||
#if HEAP_LOG
|
||||
printf("closing logs.\n");
|
||||
fflush(stdout);
|
||||
for (int i = 0; i < kMaxThreadHeaps + 1; i++) {
|
||||
for (int i = 0; i < fMaxThreadHeaps + 1; i++) {
|
||||
_log[i].close();
|
||||
}
|
||||
#endif
|
||||
|
@ -132,12 +132,6 @@ class processHeap : public hoardHeap {
|
||||
processHeap(const processHeap &);
|
||||
const processHeap & operator=(const processHeap &);
|
||||
|
||||
// The maximum number of thread heaps we allow. (NOT the maximum
|
||||
// number of threads -- Hoard imposes no such limit.) This must be
|
||||
// a power of two! NB: This number is twice the maximum number of
|
||||
// PROCESSORS supported by Hoard.
|
||||
const int kMaxThreadHeaps;
|
||||
|
||||
// The per-thread heaps.
|
||||
HEAPTYPE* theap;
|
||||
|
||||
@ -174,7 +168,7 @@ processHeap::getHeap(int i)
|
||||
{
|
||||
assert(theap != NULL);
|
||||
assert(i >= 0);
|
||||
assert(i < kMaxThreadHeaps);
|
||||
assert(i < fMaxThreadHeaps);
|
||||
return theap[i];
|
||||
}
|
||||
|
||||
@ -185,7 +179,7 @@ processHeap::getLog(int i)
|
||||
{
|
||||
assert(_log != NULL);
|
||||
assert(i >= 0);
|
||||
assert(i < kMaxThreadHeaps + 1);
|
||||
assert(i < fMaxThreadHeaps + 1);
|
||||
return _log[i];
|
||||
}
|
||||
#endif
|
||||
@ -200,7 +194,7 @@ processHeap::getHeapIndex(void)
|
||||
// In fact, for efficiency, we just round up to the highest power of two,
|
||||
// times two.
|
||||
int tid = find_thread(NULL) & _numProcessorsMask;
|
||||
assert(tid < kMaxThreadHeaps);
|
||||
assert(tid < fMaxThreadHeaps);
|
||||
return tid;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user