Adds memory measurement.
This commit is contained in:
parent
3b6bd5ca87
commit
dc1166758e
3 changed files with 40 additions and 1 deletions
|
@ -30,4 +30,9 @@ public:
|
||||||
* Frees a given page by pointer.
|
* Frees a given page by pointer.
|
||||||
*/
|
*/
|
||||||
static void free(physical_t page);
|
static void free(physical_t page);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the free memory.
|
||||||
|
*/
|
||||||
|
static uint32_t getFreeMemory();
|
||||||
};
|
};
|
|
@ -33,12 +33,14 @@ extern "C" void init(Structure const & data)
|
||||||
if(mmap.length == 0) {
|
if(mmap.length == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if(mmap.isFree() == false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Console::main
|
Console::main
|
||||||
<< "mmap: "
|
<< "mmap: "
|
||||||
<< "start: " << hex(mmap.base) << ", length: " << hex(mmap.length)
|
<< "start: " << hex(mmap.base) << ", length: " << hex(mmap.length)
|
||||||
<< ", " << mmap.entry_size
|
<< ", " << mmap.entry_size
|
||||||
<< ", " << sizeof(mmap)
|
<< ", " << sizeof(mmap)
|
||||||
<< ", free:" << mmap.isFree()
|
|
||||||
<< "\n";
|
<< "\n";
|
||||||
if(mmap.base > 0xFFFFFFFF) {
|
if(mmap.base > 0xFFFFFFFF) {
|
||||||
Console::main << "mmap out of 4 gigabyte range." << "\n";
|
Console::main << "mmap out of 4 gigabyte range." << "\n";
|
||||||
|
@ -67,11 +69,23 @@ extern "C" void init(Structure const & data)
|
||||||
ptr += 0x1000;
|
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++) {
|
for(int i = 0; i < 10; i++) {
|
||||||
bool success;
|
bool success;
|
||||||
physical_t page = PMM::alloc(success);
|
physical_t page = PMM::alloc(success);
|
||||||
Console::main << "allocated page " << i << " [" << success << "]: " << page << "\n";
|
Console::main << "allocated page " << i << " [" << success << "]: " << page << "\n";
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static_assert(sizeof(void*) == 4, "Target platform is not 32 bit.");
|
static_assert(sizeof(void*) == 4, "Target platform is not 32 bit.");
|
|
@ -95,4 +95,24 @@ void PMM::free(physical_t page)
|
||||||
|
|
||||||
// Mark the selected bit as free.
|
// Mark the selected bit as free.
|
||||||
bitmap[idx] |= (1<<bit);
|
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;
|
||||||
}
|
}
|
Loading…
Reference in a new issue