Minimise printing in physmem - turns out serial output is SLOW.
This commit is contained in:
parent
c5be09fc5d
commit
9b0aceac55
|
@ -26,7 +26,7 @@
|
||||||
#define MIN_ORDER 3
|
#define MIN_ORDER 3
|
||||||
#define PEEK(type, address) (*((volatile type*)(address)))
|
#define PEEK(type, address) (*((volatile type*)(address)))
|
||||||
|
|
||||||
uint8_t* Memory = ((uint8_t*)(&end));
|
uint8_t* Memory = ((uint8_t*)(&memstart));
|
||||||
uint8_t* MemoryStart;
|
uint8_t* MemoryStart;
|
||||||
size_t MemoryBuckets;
|
size_t MemoryBuckets;
|
||||||
|
|
||||||
|
@ -135,28 +135,28 @@ static directptr_t BuddyAllocate(buddy_t* Buddy, size_t Size) {
|
||||||
|
|
||||||
TicketAttemptLock(&Buddy->Lock);
|
TicketAttemptLock(&Buddy->Lock);
|
||||||
|
|
||||||
SerialPrintf("Searching for a valid order to allocate into. Condition: {\r\n\tOrder: %d,\r\n\tSize: 0x%x\r\n}\r\n\n", InitialOrder, WantedSize);
|
//SerialPrintf("Searching for a valid order to allocate into. Condition: {\r\n\tOrder: %d,\r\n\tSize: 0x%x\r\n}\r\n\n", InitialOrder, WantedSize);
|
||||||
|
|
||||||
for(int Order = InitialOrder; Order < Buddy->MaxOrder; Order++) {
|
for(int Order = InitialOrder; Order < Buddy->MaxOrder; Order++) {
|
||||||
//SerialPrintf("\tCurrent Order: %d, Buddy entry: %x\r\n", Order, Buddy->List[Order - MIN_ORDER]);
|
//SerialPrintf("\tCurrent Order: %d, Buddy entry: %x\r\n", Order, Buddy->List[Order - MIN_ORDER]);
|
||||||
if(Buddy->List[Order - MIN_ORDER] != 0) {
|
if(Buddy->List[Order - MIN_ORDER] != 0) {
|
||||||
SerialPrintf("\tFound a valid Order!\r\n");
|
//SerialPrintf("\tFound a valid Order!\r\n");
|
||||||
directptr_t Address = Buddy->List[Order - MIN_ORDER];
|
directptr_t Address = Buddy->List[Order - MIN_ORDER];
|
||||||
Buddy->List[Order - MIN_ORDER] = PEEK(directptr_t, Address);
|
Buddy->List[Order - MIN_ORDER] = PEEK(directptr_t, Address);
|
||||||
TicketUnlock(&Buddy->Lock);
|
TicketUnlock(&Buddy->Lock);
|
||||||
|
|
||||||
size_t FoundSize = 1ull << Order;
|
size_t FoundSize = 1ull << Order;
|
||||||
|
|
||||||
SerialPrintf("\tAdding area - Address 0x%p, Size 0x%x\r\n\n", Address, FoundSize);
|
//SerialPrintf("\tAdding area - Address 0x%p, Size 0x%x\r\n\n", Address, FoundSize);
|
||||||
|
|
||||||
AddRangeToBuddy(Buddy, (void*)((size_t)Address + WantedSize), FoundSize - WantedSize);
|
AddRangeToBuddy(Buddy, (void*)((size_t)Address + WantedSize), FoundSize - WantedSize);
|
||||||
|
|
||||||
SerialPrintf("\tArea added!\r\n\n");
|
//SerialPrintf("\tArea added!\r\n");
|
||||||
return Address;
|
return Address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SerialPrintf("BuddyAllocate: Unable to find a valid order to allocate!\r\nInitial Order: %d, WantedSize: 0x%x\r\n\r\n", InitialOrder, WantedSize);
|
//SerialPrintf("BuddyAllocate: Unable to find a valid order to allocate!\r\nInitial Order: %d, WantedSize: 0x%x\r\n\r\n", InitialOrder, WantedSize);
|
||||||
|
|
||||||
TicketUnlock(&Buddy->Lock);
|
TicketUnlock(&Buddy->Lock);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -164,16 +164,14 @@ static directptr_t BuddyAllocate(buddy_t* Buddy, size_t Size) {
|
||||||
|
|
||||||
void InitMemoryManager() {
|
void InitMemoryManager() {
|
||||||
|
|
||||||
size_t BootstructSize = bootldr.size;
|
SerialPrintf("[ Mem] Counting memory..\r\n");
|
||||||
size_t BootstructLoc = (size_t) &bootldr;
|
|
||||||
|
|
||||||
size_t BootstructEnd = BootstructLoc + BootstructSize;
|
|
||||||
MemorySize = 0;
|
MemorySize = 0;
|
||||||
size_t MemMapEntryCount = 0;
|
size_t MemMapEntryCount = 0;
|
||||||
|
|
||||||
MMapEnt* MemMap = &bootldr.mmap;
|
MMapEnt* MemMap = &bootldr.mmap;
|
||||||
|
|
||||||
while((size_t) MemMap < BootstructEnd) {
|
while((size_t) MemMap < ((size_t) &bootldr) + bootldr.size) {
|
||||||
if(MMapEnt_IsFree(MemMap)) {
|
if(MMapEnt_IsFree(MemMap)) {
|
||||||
MemorySize += MMapEnt_Size(MemMap);
|
MemorySize += MMapEnt_Size(MemMap);
|
||||||
}
|
}
|
||||||
|
@ -181,38 +179,20 @@ void InitMemoryManager() {
|
||||||
MemMap++;
|
MemMap++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SerialPrintf("[ Mem] Counted %d entries in the memory map..\r\n", MemMapEntryCount);
|
||||||
|
|
||||||
MemoryPages = MemorySize / PAGE_SIZE;
|
MemoryPages = MemorySize / PAGE_SIZE;
|
||||||
MemoryBuckets = MemoryPages / PAGES_PER_BUCKET;
|
|
||||||
|
|
||||||
if(MemoryBuckets * PAGES_PER_BUCKET < MemoryPages)
|
|
||||||
MemoryBuckets++; // Always round up
|
|
||||||
|
|
||||||
|
|
||||||
memset(Memory, 0, MemoryBuckets);
|
|
||||||
|
|
||||||
MemoryStart = (uint8_t*) PAGE_ALIGN((size_t)(Memory + MemoryBuckets));
|
|
||||||
|
|
||||||
|
|
||||||
SerialPrintf("Initializing Memory.\r\n");
|
|
||||||
|
|
||||||
SerialPrintf("%u MB of memory detected.\r\n", (MemorySize / 1024) / 1024);
|
|
||||||
|
|
||||||
for(size_t i = 0; i < MemoryBuckets; i++) {
|
|
||||||
if(Memory[i] != 0)
|
|
||||||
SerialPrintf("Memory at 0x%p is not empty!", Memory + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
SerialPrintf("[ Mem] %u MB of memory detected.\r\n", (MemorySize / 1024) / 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ListMemoryMap() {
|
void ListMemoryMap() {
|
||||||
|
|
||||||
SerialPrintf("BIOS-Provided memory map:\r\n");
|
SerialPrintf("[ Mem] BIOS-Provided memory map:\r\n");
|
||||||
|
|
||||||
|
|
||||||
|
for(MMapEnt* MapEntry = &bootldr.mmap; (size_t)MapEntry < (size_t) &bootldr + bootldr.size; MapEntry++) {
|
||||||
for(MMapEnt* MapEntry = &bootldr.mmap; (size_t)MapEntry < (size_t)&bootldr + bootldr.size; MapEntry++) {
|
|
||||||
char EntryType[8] = {0};
|
char EntryType[8] = {0};
|
||||||
switch(MMapEnt_Type(MapEntry)) {
|
switch(MMapEnt_Type(MapEntry)) {
|
||||||
case MMAP_FREE:
|
case MMAP_FREE:
|
||||||
|
@ -234,10 +214,10 @@ void ListMemoryMap() {
|
||||||
|
|
||||||
|
|
||||||
if(entry_from != 0 && entry_to != 0)
|
if(entry_from != 0 && entry_to != 0)
|
||||||
SerialPrintf("[ mem 0x%p-0x%p] %s\r\n", entry_from, entry_to, EntryType);
|
SerialPrintf("[ Mem] 0x%p-0x%p %s\r\n", entry_from, entry_to, EntryType);
|
||||||
|
|
||||||
if(MMapEnt_Type(MapEntry) == MMAP_FREE) {
|
if(MMapEnt_Type(MapEntry) == MMAP_FREE) {
|
||||||
SerialPrintf("\tAdding this entry to the physical memory manager!\r\n");
|
SerialPrintf("[ Mem] Adding this entry to the physical memory manager!\r\n");
|
||||||
AddRangeToPhysMem((void*)((char*)(MMapEnt_Ptr(MapEntry) /* + DIRECT_REGION*/ )), MMapEnt_Size(MapEntry));
|
AddRangeToPhysMem((void*)((char*)(MMapEnt_Ptr(MapEntry) /* + DIRECT_REGION*/ )), MMapEnt_Size(MapEntry));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -247,7 +227,7 @@ void ListMemoryMap() {
|
||||||
|
|
||||||
void AddRangeToPhysMem(directptr_t Base, size_t Size) {
|
void AddRangeToPhysMem(directptr_t Base, size_t Size) {
|
||||||
if(Base < (void*)(LOWER_REGION + DIRECT_REGION)) {
|
if(Base < (void*)(LOWER_REGION + DIRECT_REGION)) {
|
||||||
SerialPrintf("New range in lower memory: 0x%p, size 0x%x\r\n", Base, Size);
|
SerialPrintf("[ Mem] New range in lower memory: 0x%p, size 0x%x\r\n", Base, Size);
|
||||||
AddRangeToBuddy(&LowBuddy, Base, Size);
|
AddRangeToBuddy(&LowBuddy, Base, Size);
|
||||||
} else {
|
} else {
|
||||||
if(HighBuddy.Base == NULL) {
|
if(HighBuddy.Base == NULL) {
|
||||||
|
@ -273,12 +253,12 @@ directptr_t PhysAllocateMem(size_t Size) {
|
||||||
directptr_t Pointer = NULL;
|
directptr_t Pointer = NULL;
|
||||||
|
|
||||||
if(HighBuddy.Base == 0) {
|
if(HighBuddy.Base == 0) {
|
||||||
SerialPrintf("Attempting allocation into high memory.\n");
|
//SerialPrintf("Attempting allocation into high memory.\n");
|
||||||
Pointer = BuddyAllocate(&HighBuddy, Size);
|
Pointer = BuddyAllocate(&HighBuddy, Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Pointer == NULL) {
|
if(Pointer == NULL) {
|
||||||
SerialPrintf("Attempting allocation into low memory.\n");
|
//SerialPrintf("Attempting allocation into low memory.\n");
|
||||||
Pointer = BuddyAllocate(&LowBuddy, Size);
|
Pointer = BuddyAllocate(&LowBuddy, Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user