From 43308244dc725ea3846a627a318eb78e191d089f Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 30 Jul 2015 22:57:28 +0200 Subject: [PATCH] use 64bit counters to determine the memory usage --- hermit/kernel/main.c | 14 +++++++------- hermit/mm/memory.c | 30 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/hermit/kernel/main.c b/hermit/kernel/main.c index cdf68a004..1dc1fa19e 100644 --- a/hermit/kernel/main.c +++ b/hermit/kernel/main.c @@ -53,9 +53,9 @@ extern const void percore_end; extern char __BUILD_DATE; /* Page frame counters */ -extern atomic_int32_t total_pages; -extern atomic_int32_t total_allocated_pages; -extern atomic_int32_t total_available_pages; +extern atomic_int64_t total_pages; +extern atomic_int64_t total_allocated_pages; +extern atomic_int64_t total_available_pages; extern atomic_int32_t cpu_online; @@ -143,11 +143,11 @@ int main(void) kprintf("This is Hermit %s, build date %u\n", VERSION, &__BUILD_DATE); kprintf("Kernel starts at %p and ends at %p\n", &kernel_start, &kernel_end); kprintf("Per core data starts at %p and ends at %p\n", &percore_start, &percore_end); - kprintf("Per core size 0x%llx\n", (size_t) &percore_end0 - (size_t) &percore_start); + kprintf("Per core size 0x%zd\n", (size_t) &percore_end0 - (size_t) &percore_start); kprintf("Processor frequency: %u MHz\n", get_cpu_frequency()); - kprintf("Total memory: %lu KiB\n", atomic_int32_read(&total_pages) * PAGE_SIZE / 1024); - kprintf("Current allocated memory: %lu KiB\n", atomic_int32_read(&total_allocated_pages) * PAGE_SIZE / 1024); - kprintf("Current available memory: %lu KiB\n", atomic_int32_read(&total_available_pages) * PAGE_SIZE / 1024); + kprintf("Total memory: %zd MiB\n", atomic_int64_read(&total_pages) * PAGE_SIZE / (1024ULL*1024ULL)); + kprintf("Current allocated memory: %zd KiB\n", atomic_int64_read(&total_allocated_pages) * PAGE_SIZE / 1024ULL); + kprintf("Current available memory: %zd MiB\n", atomic_int64_read(&total_available_pages) * PAGE_SIZE / (1024ULL*1024ULL)); #if 1 kputs("Filesystem:\n"); diff --git a/hermit/mm/memory.c b/hermit/mm/memory.c index ee5aed4c5..aca8955fb 100644 --- a/hermit/mm/memory.c +++ b/hermit/mm/memory.c @@ -34,8 +34,8 @@ #include #include -extern uint32_t base; -extern uint32_t limit; +extern uint64_t base; +extern uint64_t limit; typedef struct free_list { size_t start, end; @@ -55,9 +55,9 @@ static spinlock_t list_lock = SPINLOCK_INIT; static free_list_t init_list; static free_list_t* free_start = &init_list; -atomic_int32_t total_pages = ATOMIC_INIT(0); -atomic_int32_t total_allocated_pages = ATOMIC_INIT(0); -atomic_int32_t total_available_pages = ATOMIC_INIT(0); +atomic_int64_t total_pages = ATOMIC_INIT(0); +atomic_int64_t total_allocated_pages = ATOMIC_INIT(0); +atomic_int64_t total_available_pages = ATOMIC_INIT(0); size_t get_pages(size_t npages) { @@ -66,7 +66,7 @@ size_t get_pages(size_t npages) if (BUILTIN_EXPECT(!npages, 0)) return 0; - if (BUILTIN_EXPECT(npages > atomic_int32_read(&total_available_pages), 0)) + if (BUILTIN_EXPECT(npages > atomic_int64_read(&total_available_pages), 0)) return 0; spinlock_lock(&list_lock); @@ -94,8 +94,8 @@ out: spinlock_unlock(&list_lock); if (ret) { - atomic_int32_add(&total_allocated_pages, npages); - atomic_int32_sub(&total_available_pages, npages); + atomic_int64_add(&total_allocated_pages, npages); + atomic_int64_sub(&total_available_pages, npages); } return ret; @@ -139,8 +139,8 @@ int put_pages(size_t phyaddr, size_t npages) out: spinlock_unlock(&list_lock); - atomic_int32_sub(&total_allocated_pages, npages); - atomic_int32_add(&total_available_pages, npages); + atomic_int64_sub(&total_allocated_pages, npages); + atomic_int64_add(&total_available_pages, npages); return 0; @@ -199,18 +199,18 @@ int memory_init(void) return ret; } - kprintf("base 0x%llx, limit 0x%llx\n", base, limit); + kprintf("base 0x%zx, limit 0x%zx\n", base, limit); // mark available memory as free for(addr=base; addr