1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00

musage.c update with allocator

This commit is contained in:
Adrien Bourmault 2020-01-23 17:38:51 +01:00
parent 0ebb53d312
commit eecabef0a0
4 changed files with 94 additions and 52 deletions

View File

@ -47,7 +47,11 @@ ulong MmAllocPageFrameEx(void ***frameListPtr, size_t *pageNumber, size_t size,
ulong MmAllocPageFrame(size_t size, bool contiguous); ulong MmAllocPageFrame(size_t size, bool contiguous);
void MmFreePageFrame(ulong id); void MmFreePageFrame(ulong id);
error_t MmTestBusyPage(ulong size, ulong flags); ulong MmGetBusyPageSize(void);
ulong MmGetTotalPageSize(void);
error_t MmMapPageFrame(ulong id, void *virtAddr, ulong flags);
error_t MmUnmapPageFrame(ulong id);
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//

View File

@ -87,7 +87,7 @@ static void printBusyPages(void)
} }
} }
static ulong MmBusyPagesSpace(void) ulong MmGetBusyPageSize(void)
{ {
ulong c = 0; ulong c = 0;
AllocatedPage_t *busyPage = &busyPagesList; AllocatedPage_t *busyPage = &busyPagesList;
@ -103,6 +103,12 @@ static ulong MmBusyPagesSpace(void)
return c; return c;
} }
ulong MmGetTotalPageSize(void)
{
// Maximum PHYSICAL address in memory
ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize;
return (phRamSize - (MmPhysLastKernAddress + KPAGESIZE));
}
static void addPageToBusyList(void *phyPageAddrBegin, void *phyPageAddrEnd, ulong id) static void addPageToBusyList(void *phyPageAddrBegin, void *phyPageAddrEnd, ulong id)
{ {
@ -275,50 +281,3 @@ error_t MmUnmapPageFrame(ulong id)
return EOK; return EOK;
} }
ulong tab[4000] = {0};
error_t MmTestBusyPage(ulong size, ulong flags)
{
/* for (int i = 0; i < 2000; i++) { */
/* if (rand() %2) { */
/* if (rand() %2) { */
/* tab[j++] = MmAllocPageFrame(rand()%6553689, NORMAL); */
/* } else { */
/* 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); */
/* } */
ulong a = KeGetTicks();
DebugLog("Start alloc 1: %lu s\n", a/1000);
tab[0] = MmAllocPageFrame(size*KB, NORMAL);
ulong b = KeGetTicks();
DebugLog("End alloc : %lu s\n", b/1000);
DebugLog("Alloc time : %lu s\n", (b-a)/1000);
DebugLog("Alloc : %d; Free : %d; Count : %lu Mo\n", NSuccessfulAlloc, NSuccessfulFree, MmBusyPagesSpace() / MB);
printBusyPages();
a = KeGetTicks();
DebugLog("Start map at %p wit %p: %lu ms\n", USERSPACE, flags, a);
MmMapPageFrame(tab[0], (void*)(USERSPACE), flags);
b = KeGetTicks();
DebugLog("End map : %lu ms\n", b);
DebugLog("Map time : %lu ms\n", (b-a));
a = KeGetTicks();
DebugLog("Start unmap at %p wit %p: %lu ms\n", USERSPACE, flags, a);
MmUnmapPageFrame(tab[0]);
b = KeGetTicks();
DebugLog("End map : %lu ms\n", b);
DebugLog("Map time : %lu ms\n", (b-a));
DebugLog("Finished !\n");
return EOK;
}

View File

@ -24,6 +24,8 @@
#include <io/vga.h> #include <io/vga.h>
#include <mm/heap.h> #include <mm/heap.h>
#include <mm/palloc.h>
#include <mm/paging.h>
#include <sh/shell.h> #include <sh/shell.h>
#include <init/boot.h> #include <init/boot.h>
@ -258,5 +260,37 @@ error_t CmdMemUsage(int argc, char **argv, char *cmdline)
heap_max heap_max
); );
KernLog("Kernel page allocator\n");
KernLog("\t%COccupied size:\t%C%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C (%d pages)\n",
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_MB(MmGetBusyPageSize()),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB(MmGetBusyPageSize()),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(MmGetBusyPageSize()),
VGA_COLOR_DARK_GREY,
shcol,
MmGetBusyPageSize()/KPAGESIZE
);
KernLog("\t%CTotal size:\t%C%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C (%d pages)\n\n",
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_MB(MmGetTotalPageSize()),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB(MmGetTotalPageSize()),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(MmGetTotalPageSize()),
VGA_COLOR_DARK_GREY,
shcol,
MmGetTotalPageSize()/KPAGESIZE
);
return EOK; return EOK;
} }

View File

@ -241,8 +241,51 @@ error_t CmdPageUnmap(int argc, char **argv, char *cmdline)
error_t CmdPageAlloc(int argc, char **argv, char *cmdline) error_t CmdPageAlloc(int argc, char **argv, char *cmdline)
{ {
error_t err = MmTestBusyPage(strtoul(argv[1], NULL, 0), strtoul(argv[2], NULL, 0)); if (argc != 4) {
return err; KernLog("Invalid arguments !\n");
return EINVAL;
}
size_t size = (size_t)atol(argv[1]);
void *virtaddr = (void *)strtol(argv[2], NULL, 16);
ulong flags = (ulong)atol(argv[3]);
KernLog("Allocating %d o...\n", size);
ulong id = MmAllocPageFrame(size, false);
KernLog("Allocated with id : %lu\n", id);
KernLog("Mapping pages id %d at %p (flags %#x)...\n", id, virtaddr, flags);
error_t err = MmMapPageFrame(id, virtaddr, flags);
if (err == EOK)
KernLog("Successful mapped.\n");
else
KernLog("Failed to map !\n");
return EOK;
}
error_t CmdPageFree(int argc, char **argv, char *cmdline)
{
if (argc != 2) {
KernLog("Invalid arguments !\n");
return EINVAL;
}
ulong id = (ulong)atol(argv[1]);
KernLog("Unmapping pages id %d...\n", id);
error_t err = MmUnmapPageFrame(id);
if (err == EOK)
KernLog("Success unmaping.\n");
else {
KernLog("Failed to unmap !\n");
return EFAILED;
}
KernLog("Freeing pages id %d...\n", id);
MmFreePageFrame(id);
return EOK;
} }
error_t CmdPF(int argc, char **argv, char *cmdline) error_t CmdPF(int argc, char **argv, char *cmdline)
@ -311,7 +354,9 @@ static Command_t testcmdtable[] =
" virtual address (paging)"}, " virtual address (paging)"},
{ "pmap", CmdPageMap, "Map a page to given physical addr" }, { "pmap", CmdPageMap, "Map a page to given physical addr" },
{ "punmap", CmdPageUnmap, "Unmap a page" }, { "punmap", CmdPageUnmap, "Unmap a page" },
{ "palloc", CmdPageAlloc, "Alloc x KB of pages" }, { "palloc", CmdPageAlloc, "Alloc x B of pages at y address"
"with z flags"},
{ "pfree", CmdPageFree, "Free a page block of id x" },
{ "pf", CmdPF, "Provoke a PF. Usage: pfault <address>"}, { "pf", CmdPF, "Provoke a PF. Usage: pfault <address>"},
{ "shell", CmdShell, "Start a new shell (nested)", }, { "shell", CmdShell, "Start a new shell (nested)", },
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" }, { "stkov", CmdStackOverflow, "Provoke a stack overflow" },