Adds memory measurement.

This commit is contained in:
Felix Queißner 2016-05-05 11:35:08 +02:00
parent 3b6bd5ca87
commit dc1166758e
3 changed files with 40 additions and 1 deletions

View file

@ -30,4 +30,9 @@ public:
* Frees a given page by pointer.
*/
static void free(physical_t page);
/**
* Returns the free memory.
*/
static uint32_t getFreeMemory();
};

View file

@ -33,12 +33,14 @@ extern "C" void init(Structure const & data)
if(mmap.length == 0) {
continue;
}
if(mmap.isFree() == false) {
continue;
}
Console::main
<< "mmap: "
<< "start: " << hex(mmap.base) << ", length: " << hex(mmap.length)
<< ", " << mmap.entry_size
<< ", " << sizeof(mmap)
<< ", free:" << mmap.isFree()
<< "\n";
if(mmap.base > 0xFFFFFFFF) {
Console::main << "mmap out of 4 gigabyte range." << "\n";
@ -67,11 +69,23 @@ extern "C" void init(Structure const & data)
ptr += 0x1000;
}
auto freeMemory = PMM::getFreeMemory();
Console::main
<< "Free: "
<< (freeMemory >> 20) << "MB, "
<< (freeMemory >> 10) << "KB, "
<< (freeMemory >> 0) << "B, "
<< (freeMemory >> 12) << "Pages\n";
/*
for(int i = 0; i < 10; i++) {
bool success;
physical_t page = PMM::alloc(success);
Console::main << "allocated page " << i << " [" << success << "]: " << page << "\n";
}
*/
}
static_assert(sizeof(void*) == 4, "Target platform is not 32 bit.");

View file

@ -95,4 +95,24 @@ void PMM::free(physical_t page)
// Mark the selected bit as free.
bitmap[idx] |= (1<<bit);
}
uint32_t PMM::getFreeMemory()
{
uint32_t freeMemory = 0;
for(uint32_t idx = 0; idx < BitmapLength; idx++) {
// fast skip when no bit is set
if(bitmap[idx] == 0) {
continue;
}
for(uint32_t bit = 0; bit < 32; bit++) {
uint32_t mask = (1<<bit);
if((bitmap[idx] & mask) == 0) {
// If bit is not set, ignore the bit.
continue;
}
freeMemory += 0x1000;
}
}
return freeMemory;
}