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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
int hoardHeap::fMaxThreadHeaps = 1;
|
||||||
int hoardHeap::_numProcessors;
|
int hoardHeap::_numProcessors;
|
||||||
int hoardHeap::_numProcessorsMask;
|
int hoardHeap::_numProcessorsMask;
|
||||||
|
|
||||||
@ -454,7 +455,7 @@ hoardHeap::initNumProcs(void)
|
|||||||
else
|
else
|
||||||
hoardHeap::_numProcessors = info.cpu_count;
|
hoardHeap::_numProcessors = info.cpu_count;
|
||||||
|
|
||||||
hoardHeap::_numProcessorsMask =
|
fMaxThreadHeaps = 1 << (lg(_numProcessors) + 1);
|
||||||
(1 << (lg(hoardHeap::_numProcessors) + 1)) - 1;
|
_numProcessorsMask = fMaxThreadHeaps - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,6 +205,12 @@ class hoardHeap {
|
|||||||
static void initNumProcs(void);
|
static void initNumProcs(void);
|
||||||
|
|
||||||
protected:
|
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
|
// number of CPUs, cached
|
||||||
static int _numProcessors;
|
static int _numProcessors;
|
||||||
static int _numProcessorsMask;
|
static int _numProcessorsMask;
|
||||||
|
@ -37,8 +37,7 @@ using namespace BPrivate;
|
|||||||
|
|
||||||
processHeap::processHeap()
|
processHeap::processHeap()
|
||||||
:
|
:
|
||||||
kMaxThreadHeaps(_numProcessors * 2),
|
theap((HEAPTYPE*)hoardSbrk(sizeof(HEAPTYPE) * fMaxThreadHeaps)),
|
||||||
theap((HEAPTYPE*)hoardSbrk(sizeof(HEAPTYPE) * kMaxThreadHeaps)),
|
|
||||||
#if HEAP_FRAG_STATS
|
#if HEAP_FRAG_STATS
|
||||||
_currentAllocated(0),
|
_currentAllocated(0),
|
||||||
_currentRequested(0),
|
_currentRequested(0),
|
||||||
@ -48,32 +47,32 @@ processHeap::processHeap()
|
|||||||
#endif
|
#endif
|
||||||
#if HEAP_LOG
|
#if HEAP_LOG
|
||||||
_log((Log<MemoryRequest>*)
|
_log((Log<MemoryRequest>*)
|
||||||
hoardSbrk(sizeof(Log<MemoryRequest>) * (kMaxThreadHeaps + 1))),
|
hoardSbrk(sizeof(Log<MemoryRequest>) * (fMaxThreadHeaps + 1))),
|
||||||
#endif
|
#endif
|
||||||
_buffer(NULL),
|
_buffer(NULL),
|
||||||
_bufferCount(0)
|
_bufferCount(0)
|
||||||
{
|
{
|
||||||
if (theap == NULL)
|
if (theap == NULL)
|
||||||
return;
|
return;
|
||||||
new(theap) HEAPTYPE[kMaxThreadHeaps];
|
new(theap) HEAPTYPE[fMaxThreadHeaps];
|
||||||
|
|
||||||
#if HEAP_LOG
|
#if HEAP_LOG
|
||||||
if (_log == NULL)
|
if (_log == NULL)
|
||||||
return;
|
return;
|
||||||
new(_log) Log<MemoryRequest>[kMaxThreadHeaps + 1];
|
new(_log) Log<MemoryRequest>[fMaxThreadHeaps + 1];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
// The process heap is heap 0.
|
// The process heap is heap 0.
|
||||||
setIndex(0);
|
setIndex(0);
|
||||||
for (i = 0; i < kMaxThreadHeaps; i++) {
|
for (i = 0; i < fMaxThreadHeaps; i++) {
|
||||||
// Set every thread's process heap to this one.
|
// Set every thread's process heap to this one.
|
||||||
theap[i].setpHeap(this);
|
theap[i].setpHeap(this);
|
||||||
// Set every thread heap's index.
|
// Set every thread heap's index.
|
||||||
theap[i].setIndex(i + 1);
|
theap[i].setIndex(i + 1);
|
||||||
}
|
}
|
||||||
#if HEAP_LOG
|
#if HEAP_LOG
|
||||||
for (i = 0; i < kMaxThreadHeaps + 1; i++) {
|
for (i = 0; i < fMaxThreadHeaps + 1; i++) {
|
||||||
char fname[255];
|
char fname[255];
|
||||||
sprintf(fname, "log%d", i);
|
sprintf(fname, "log%d", i);
|
||||||
unlink(fname);
|
unlink(fname);
|
||||||
@ -94,7 +93,7 @@ processHeap::stats(void)
|
|||||||
#if HEAP_STATS
|
#if HEAP_STATS
|
||||||
int umax = 0;
|
int umax = 0;
|
||||||
int amax = 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++) {
|
for (int i = 0; i < SIZE_CLASSES; i++) {
|
||||||
amax += theap[j].maxAllocated(i) * sizeFromClass(i);
|
amax += theap[j].maxAllocated(i) * sizeFromClass(i);
|
||||||
umax += theap[j].maxInUse(i) * sizeFromClass(i);
|
umax += theap[j].maxInUse(i) * sizeFromClass(i);
|
||||||
@ -118,7 +117,7 @@ processHeap::stats(void)
|
|||||||
#if HEAP_LOG
|
#if HEAP_LOG
|
||||||
printf("closing logs.\n");
|
printf("closing logs.\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
for (int i = 0; i < kMaxThreadHeaps + 1; i++) {
|
for (int i = 0; i < fMaxThreadHeaps + 1; i++) {
|
||||||
_log[i].close();
|
_log[i].close();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -132,12 +132,6 @@ class processHeap : public hoardHeap {
|
|||||||
processHeap(const processHeap &);
|
processHeap(const processHeap &);
|
||||||
const processHeap & operator=(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.
|
// The per-thread heaps.
|
||||||
HEAPTYPE* theap;
|
HEAPTYPE* theap;
|
||||||
|
|
||||||
@ -174,7 +168,7 @@ processHeap::getHeap(int i)
|
|||||||
{
|
{
|
||||||
assert(theap != NULL);
|
assert(theap != NULL);
|
||||||
assert(i >= 0);
|
assert(i >= 0);
|
||||||
assert(i < kMaxThreadHeaps);
|
assert(i < fMaxThreadHeaps);
|
||||||
return theap[i];
|
return theap[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +179,7 @@ processHeap::getLog(int i)
|
|||||||
{
|
{
|
||||||
assert(_log != NULL);
|
assert(_log != NULL);
|
||||||
assert(i >= 0);
|
assert(i >= 0);
|
||||||
assert(i < kMaxThreadHeaps + 1);
|
assert(i < fMaxThreadHeaps + 1);
|
||||||
return _log[i];
|
return _log[i];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -200,7 +194,7 @@ processHeap::getHeapIndex(void)
|
|||||||
// 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 = find_thread(NULL) & _numProcessorsMask;
|
int tid = find_thread(NULL) & _numProcessorsMask;
|
||||||
assert(tid < kMaxThreadHeaps);
|
assert(tid < fMaxThreadHeaps);
|
||||||
return tid;
|
return tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user