Skip to content

Commit

Permalink
Kernel: Track process memory usage, fix EndProcess deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
fido2020 committed Jan 20, 2021
1 parent c936f95 commit 0b91899
Show file tree
Hide file tree
Showing 7 changed files with 727 additions and 697 deletions.
15 changes: 10 additions & 5 deletions Applications/LemonMonitor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ Lemon::GUI::Window* window;
Lemon::GUI::ListView* listView;
Lemon::GUI::ListColumn procName = {.name = "Process", .displayWidth = 168};
Lemon::GUI::ListColumn procID = {.name = "PID", .displayWidth = 48};
Lemon::GUI::ListColumn procUptime = {.name = "Uptime", .displayWidth = 64};
Lemon::GUI::ListColumn procCPUUsage = {.name = "CPU Usage", .displayWidth = 80};
Lemon::GUI::ListColumn procCPUUsage = {.name = "CPU Usage", .displayWidth = 48};
Lemon::GUI::ListColumn procMemUsage = {.name = "Mem Usage", .displayWidth = 80};
Lemon::GUI::ListColumn procUptime = {.name = "Uptime", .displayWidth = 80};

int main(int argc, char** argv){
window = new Lemon::GUI::Window("LemonMonitor", {360, 400}, 0, Lemon::GUI::WindowType::GUI);
window = new Lemon::GUI::Window("LemonMonitor", {424, 480}, 0, Lemon::GUI::WindowType::GUI);

listView = new Lemon::GUI::ListView({0, 0, 0, 0});
listView->AddColumn(procName);
listView->AddColumn(procID);
listView->AddColumn(procUptime);
listView->AddColumn(procCPUUsage);
listView->AddColumn(procMemUsage);
listView->AddColumn(procUptime);
listView->SetLayout(Lemon::GUI::LayoutSize::Stretch, Lemon::GUI::LayoutSize::Stretch);

window->AddWidget(listView);
Expand Down Expand Up @@ -63,6 +65,9 @@ int main(int argc, char** argv){
char uptime[40];
snprintf(uptime, 39, "%lum %lus", proc.runningTime / 60, proc.runningTime % 60);

char usedMem[40];
snprintf(usedMem, 39, "%lu KB", proc.usedMem);

char usage[6];
if(processTimer.find(proc.pid) != processTimer.end()){
ProcessCPUTime& pTime = processTimer.at(proc.pid);
Expand All @@ -80,7 +85,7 @@ int main(int argc, char** argv){
processTimer[proc.pid] = {.diff = 0, .activeUs = proc.activeUs, .lastUsage = 0 };
}

Lemon::GUI::ListItem pItem = {.details = {proc.name, std::to_string(proc.pid), uptime, usage}};
Lemon::GUI::ListItem pItem = {.details = {proc.name, std::to_string(proc.pid), usage, usedMem, uptime}};
listView->AddItem(pItem);
}

Expand Down
4 changes: 4 additions & 0 deletions Kernel/include/arch/x86_64/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ typedef struct process {
Vector<fs_fd_t*> fileDescriptors;
List<thread_t*> blocking; // Threads blocking awaiting a state change
HashMap<uintptr_t, Scheduler::FutexThreadBlocker*> futexWaitQueue;

uintptr_t usedMemoryBlocks;
} process_t;

typedef struct {
Expand All @@ -69,6 +71,8 @@ typedef struct {

uint64_t runningTime; // Amount of time in seconds that the process has been running
uint64_t activeUs;

uint64_t usedMem; // Used memory in KB
} process_info_t;

namespace Scheduler{
Expand Down
2 changes: 2 additions & 0 deletions Kernel/src/arch/x86_64/elf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ elf_info_t LoadELFSegments(process_t* proc, void* _elf, uintptr_t base){
for(unsigned j = 0; j < ((elfPHdr.memSize + (elfPHdr.vaddr & 0xFFF) + 0xFFF) >> 12); j++){
uint64_t phys = Memory::AllocatePhysicalMemoryBlock();
Memory::MapVirtualMemory4K(phys, base + (elfPHdr.vaddr & ~0xFFFUL) + j * PAGE_SIZE_4K, 1, proc->addressSpace);

proc->usedMemoryBlocks++;
}
}

Expand Down
Loading

0 comments on commit 0b91899

Please sign in to comment.