mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-09 00:00:03 +01:00
use 64bit counters to determine the memory usage
This commit is contained in:
parent
71fe70c5a6
commit
43308244dc
2 changed files with 22 additions and 22 deletions
|
@ -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");
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
#include <asm/atomic.h>
|
||||
#include <asm/page.h>
|
||||
|
||||
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<limit; addr+=PAGE_SIZE) {
|
||||
atomic_int32_inc(&total_pages);
|
||||
atomic_int32_inc(&total_available_pages);
|
||||
atomic_int64_inc(&total_pages);
|
||||
atomic_int64_inc(&total_available_pages);
|
||||
}
|
||||
|
||||
// mark kernel as used, we use 2MB pages to map the kernel
|
||||
for(addr=(size_t) &kernel_start; addr<(((size_t) &kernel_end + 0x200000ULL) & 0xFFFFFFFFFFE00000ULL); addr+=PAGE_SIZE) {
|
||||
atomic_int32_inc(&total_allocated_pages);
|
||||
atomic_int32_dec(&total_available_pages);
|
||||
atomic_int64_inc(&total_allocated_pages);
|
||||
atomic_int64_dec(&total_available_pages);
|
||||
}
|
||||
|
||||
//initialize free list
|
||||
|
|
Loading…
Add table
Reference in a new issue