diff --git a/include/ke/time.h b/include/ke/time.h index b205289..8407312 100644 --- a/include/ke/time.h +++ b/include/ke/time.h @@ -64,7 +64,7 @@ void KeEnablePIT(void); void KeSleep(uint); Timer_t *KeSetTimer(uint delay); int KeGetTimer(Timer_t*); - +ulong KeGetTicks(void); //----------------------------------------------------------------------------// diff --git a/kaleid/kernel/ke/pit.c b/kaleid/kernel/ke/pit.c index a9d961c..4a0ee7b 100644 --- a/kaleid/kernel/ke/pit.c +++ b/kaleid/kernel/ke/pit.c @@ -219,3 +219,8 @@ ulong KeGetTimeStamp(void) + (time->year + time->century * 100) * dpy * 24 * 60 * 60; } + +ulong KeGetTicks(void) +{ + return Ticks; +} diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index 0bd1443..b13f0c6 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -89,7 +89,7 @@ void MmInitPaging(void) memzero((void *)&MmPageMapLevel4[0], 512*sizeof(ulong)); KalAllocMemoryEx((void**)&MmPhysicalPageTable, phDirSize, M_ZEROED, KPAGESIZE); - DebugLog("\t\t\t\tPhysical map addr : %p\n", MmPhysicalPageTable); + //DebugLog("\t\t\t\tPhysical map addr : %p\n", MmPhysicalPageTable); for (curAddrPML4 = 0; curAddrPML4 < 512 * KPAGESIZE * 0x8000000; @@ -170,31 +170,31 @@ void MmInitPaging(void) MmPT[index] = (ulong)curAddrPT | PRESENT; MmPhysicalPageTable[xedni] = (ulong)curAddrPT; MmStackGuards[0] = (ulong)curAddrPT; - //DebugLog("\tStack Guard at %p\n", curAddrPT); + DebugLog("\tStack Guard at %p\n", curAddrPT); } else if ((ulong)curAddrPT == (ulong)BtLoaderInfo.kernelEndAddr) { MmPT[index] = (ulong)curAddrPT | PRESENT; MmPhysicalPageTable[xedni] = (ulong)curAddrPT; MmStackGuards[1] = (ulong)curAddrPT; - //DebugLog("\tStack Guard at %p\n", curAddrPT); + DebugLog("\tStack Guard at %p\n", curAddrPT); } // SECTION .TEXT PROTECTION else if ((ulong)curAddrPT >= (ulong)&_text && (ulong)curAddrPT <= (ulong)&_text_end) { MmPT[index] = (ulong)curAddrPT | PRESENT; MmPhysicalPageTable[xedni] = (ulong)curAddrPT; - //DebugLog("\tSection .text at %p\n", curAddrPT); + DebugLog("\tSection .text at %p\n", curAddrPT); } // SECTION .DATA PROTECTION else if ((ulong)curAddrPT >= (ulong)&_data && (ulong)curAddrPT <= (ulong)&_data_end) { MmPT[index] = (ulong)curAddrPT | PRESENT | WRITETHR | READWRITE | NX; MmPhysicalPageTable[xedni] = (ulong)curAddrPT; - //DebugLog("\tSection .data at %p\n", curAddrPT); + DebugLog("\tSection .data at %p\n", curAddrPT); } // SECTION .RODATA PROTECTION else if ((ulong)curAddrPT >= (ulong)&_rodata && (ulong)curAddrPT <= (ulong)&_rodata_end) { MmPT[index] = (ulong)curAddrPT | PRESENT | NX; MmPhysicalPageTable[xedni] = (ulong)curAddrPT; - //DebugLog("\tSection .rodata at %p\n", curAddrPT); + DebugLog("\tSection .rodata at %p\n", curAddrPT); } // While we're inside the kernel pages else if ((ulong)curAddrPT <= MmPhysLastKernAddress) { diff --git a/kaleid/kernel/mm/palloc.c b/kaleid/kernel/mm/palloc.c index 1b663e7..6ce3356 100644 --- a/kaleid/kernel/mm/palloc.c +++ b/kaleid/kernel/mm/palloc.c @@ -29,6 +29,7 @@ #include #include #include +#include #include //--------- @@ -82,6 +83,23 @@ static void printBusyPages(void) } } +static ulong MmBusyPagesSpace(void) +{ + ulong c = 0; + AllocatedPage_t *busyPage = &busyPagesList; + + if (!busyPage->next) { + return 0; + } else { + while(busyPage->next) { + busyPage = busyPage->next; + c += 4096; + } + } + return c; +} + + static void addPageToBusyList(void *phyPageAddr, ulong id) { AllocatedPage_t *busyPage = &busyPagesList; @@ -247,30 +265,39 @@ error_t MmUnmapPageFrame(ulong id) return EOK; } +ulong tab[4000] = {0}; + error_t MmTestBusyPage(void) { - for (ulong curAddrPT = 0x00971cb000; curAddrPT <= 0x00971fb000; curAddrPT+= (ulong)KPAGESIZE) { - DebugLog("\t\t\t\tTable %p : %p\n", MmTransPhyToVirtAddr((void*)curAddrPT), MmTransVirtToPhyAddr((void*)curAddrPT)); - } - - /* ulong tab[2000] = {0}; */ - /* int j = 0; */ + int j = 0; /* for (int i = 0; i < 2000; i++) { */ /* if (rand() %2) { */ /* if (rand() %2) { */ - /* tab[j++] = MmAllocPageFrame(rand()%65536, NORMAL); */ + /* tab[j++] = MmAllocPageFrame(rand()%6553689, NORMAL); */ /* } else { */ - /* tab[j++] = MmAllocPageFrame(rand()%65536, CONTIGUOUS); */ + /* tab[j++] = MmAllocPageFrame(rand()%6553689, CONTIGUOUS); */ /* } */ /* } else { */ /* MmFreePageFrame(tab[rand() % (j+1)]); */ /* } */ + /* DebugLog("Alloc : %d; Free : %d; Count : %lu Mo\n", NSuccessfulAlloc, NSuccessfulFree, MmBusyPagesSpace() / MB); */ /* } */ - /* //printBusyPages(); */ + ulong a = KeGetTicks(); + tab[j++] = MmAllocPageFrame(50*MB, NORMAL); + tab[j++] = MmAllocPageFrame(50*MB, NORMAL); + tab[j++] = MmAllocPageFrame(50*MB, NORMAL); + tab[j++] = MmAllocPageFrame(50*MB, NORMAL); + tab[j++] = MmAllocPageFrame(50*MB, NORMAL); + ulong b = KeGetTicks(); - /* DebugLog("Alloc : %d; Free : %d\n", NSuccessfulAlloc, NSuccessfulFree); */ + DebugLog("Alloc time per MB : %lu\n", (b-a)/5/5); + + //printBusyPages(); + DebugLog("Alloc : %d; Free : %d; Count : %lu Mo\n", NSuccessfulAlloc, NSuccessfulFree, MmBusyPagesSpace() / MB); + + DebugLog("Finished !\n"); return EOK; }