[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH] kernel2: Speicherverbrauch 'ps'



+ 'ps' zeigt nun den Speicher, den jeder Prozess verbraucht

Signed-off-by: Patrick Pokatilo <shyxormz@xxxxxxxxxx>
---
 src/kernel2/include/tasks.h     |    3 +++
 src/kernel2/src/syscalls/mem.c  |    6 ++++++
 src/kernel2/src/syscalls/pm.c   |    4 +++-
 src/kernel2/src/tasks/modules.c |    1 +
 src/kernel2/src/tasks/pm.c      |    2 ++
 5 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/src/kernel2/include/tasks.h b/src/kernel2/include/tasks.h
index fc0bc88..df73e1d 100644
--- a/src/kernel2/include/tasks.h
+++ b/src/kernel2/include/tasks.h
@@ -99,6 +99,9 @@ typedef struct pm_process {
      * aufgerufen werden
      */
     list_t* on_destroy;
+
+    /// Speicherverbrauch des Prozesses
+    uintmax_t memory_used;
 } pm_process_t;
 
 typedef struct {
diff --git a/src/kernel2/src/syscalls/mem.c b/src/kernel2/src/syscalls/mem.c
index 20f9e73..4126fdf 100644
--- a/src/kernel2/src/syscalls/mem.c
+++ b/src/kernel2/src/syscalls/mem.c
@@ -54,6 +54,8 @@ vaddr_t syscall_mem_allocate(size_t bytes, syscall_arg_t flags, paddr_t* phys)
     vaddr_t address = NULL;
     size_t page_count = NUM_PAGES(PAGE_ALIGN_ROUND_UP(bytes));
 
+    current_process->memory_used += page_count << PAGE_SHIFT;
+
     if (flags & 0x80) {
         // ISA-DMA-Speicher
         // Physisch zusammenhaengend und nur in den ersten 16 MB
@@ -100,6 +102,8 @@ vaddr_t syscall_mem_allocate_physical(
     size_t bytes, paddr_t position, syscall_arg_t flags)
 {
     size_t page_count = NUM_PAGES(PAGE_ALIGN_ROUND_UP(bytes));
+
+    current_process->memory_used += page_count << PAGE_SHIFT;
 
     return mmc_automap(&mmc_current_context(), position, page_count,
         USER_MEM_START, USER_MEM_END, MM_FLAGS_USER_DATA);
@@ -117,6 +121,8 @@ void syscall_mem_free(vaddr_t start, size_t bytes)
     start = (vaddr_t) PAGE_ALIGN_ROUND_DOWN((uintptr_t) start);
     size_t num_pages = NUM_PAGES(bytes);
 
+    current_process->memory_used -= num_pages << PAGE_SHIFT;
+
     // Jetzt werden die Seiten freigegeben
     while (num_pages-- != 0) {
         // Physische Adresse ausfindig machen und Page in der
diff --git a/src/kernel2/src/syscalls/pm.c b/src/kernel2/src/syscalls/pm.c
index 0b36df3..33cd7bc 100644
--- a/src/kernel2/src/syscalls/pm.c
+++ b/src/kernel2/src/syscalls/pm.c
@@ -172,6 +172,8 @@ void syscall_init_child_page(pid_t pid, vaddr_t dest, vaddr_t src, size_t size)
 
     // Anzahl der Seiten berechnen
     size_t num_pages = NUM_PAGES(size);
+    current_proccess->memory_used -= num_pages << PAGE_SHIFT;
+    process->memory_used += num_pages << PAGE_SHIFT;
 
     // Adressen kopieren damit sie veraendert werden koennen
     // Sie duerfen nicht ueberschrieben werden, weil sie am Schluss noch
@@ -298,7 +300,7 @@ void* syscall_pm_enumerate_tasks(void)
         // hinter die aktuelle setzen.
         cmdlines += cmdline_size;
 
-        task_info->tasks[i].memory_used = 0; // TODO
+        task_info->tasks[i].memory_used = task->memory_used;
     }
 
     return task_info;
diff --git a/src/kernel2/src/tasks/modules.c b/src/kernel2/src/tasks/modules.c
index 8dac7a5..cca11c4 100644
--- a/src/kernel2/src/tasks/modules.c
+++ b/src/kernel2/src/tasks/modules.c
@@ -201,6 +201,7 @@ void load_multiboot_modules(struct multiboot_info* multiboot_info)
                 &init_process->context,
                 (paddr_t) multiboot_module->start, pages,
                 MM_USER_START, MM_USER_END, MM_FLAGS_USER_DATA);
+            init->process->memory_used +=  pages << PAGE_SHIFT;
 
             // TODO: Den Speicher aus dem Kerneladressraum unmappen
 
diff --git a/src/kernel2/src/tasks/pm.c b/src/kernel2/src/tasks/pm.c
index 94fbbbf..846323a 100644
--- a/src/kernel2/src/tasks/pm.c
+++ b/src/kernel2/src/tasks/pm.c
@@ -168,6 +168,8 @@ pm_process_t* pm_create(pm_process_t* parent, const char* cmdline)
 
     list_push(process_list, process);
 
+    process->memory_used = 0;
+
     return process;
 }
 
-- 
1.7.0.4