From 703992b6cf592645ce22fe00fc3d0b7adcf96987 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Fri, 21 Oct 2016 00:21:01 +0200 Subject: [PATCH] add hbmem support --- hermit/arch/x86/kernel/entry.asm | 4 ++++ hermit/include/hermit/memory.h | 24 ++++++++++++++++++++++++ hermit/kernel/main.c | 4 ++++ hermit/kernel/syscall.c | 13 ++++++++++--- hermit/mm/Makefile | 2 +- hermit/mm/memory.c | 3 +++ 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/hermit/arch/x86/kernel/entry.asm b/hermit/arch/x86/kernel/entry.asm index 18fc73f9a..a8b38fd62 100644 --- a/hermit/arch/x86/kernel/entry.asm +++ b/hermit/arch/x86/kernel/entry.asm @@ -67,6 +67,8 @@ align 4 global header_size global disable_x2apic global mb_info + global hbmem_base + global hbmem_size base dq 0 limit dq 0 cpu_freq dd 0 @@ -88,6 +90,8 @@ align 4 disable_x2apic dd 1 single_kernel dd 1 mb_info dq 0 + hbmem_base dq 0 + hbmem_size dq 0 ; Bootstrap page tables are used during the initialization. align 4096 diff --git a/hermit/include/hermit/memory.h b/hermit/include/hermit/memory.h index 04ab0949e..89ed45f0c 100644 --- a/hermit/include/hermit/memory.h +++ b/hermit/include/hermit/memory.h @@ -60,4 +60,28 @@ int put_pages(size_t phyaddr, size_t npages); */ static inline int put_page(size_t phyaddr) { return put_pages(phyaddr, 1); } +/** @brief Request physical hbmem page frames */ +size_t hbmem_get_pages(size_t npages); + +/** @brief Get a single hbmem page + * + * Convenience function: uses hbmem_get_pages(1); + */ +static inline size_t hbmem_get_page(void) { return hbmem_get_pages(1); } + +/** @brief release physical page frames */ +int hbmem_put_pages(size_t phyaddr, size_t npages); + +/** @brief Put a single hbmem page + * + * Convenience function: uses hbmem_put_pages(1); + */ +static inline int hbmem_put_page(size_t phyaddr) { return hbmem_put_pages(phyaddr, 1); } + +/** @brief check if high memory bandwidth is available */ +int is_hbmem_available(void); + +/** @brief Initialize the high bandwidth memory subsystem */ +int hbmemory_init(void); + #endif diff --git a/hermit/kernel/main.c b/hermit/kernel/main.c index 4165ed9cb..dfd494e4d 100644 --- a/hermit/kernel/main.c +++ b/hermit/kernel/main.c @@ -80,6 +80,8 @@ extern const void percore_start; extern const void percore_end0; extern const void percore_end; extern char __BUILD_DATE; +extern size_t hbmem_base; +extern size_t hbmem_size; /* Page frame counters */ extern atomic_int64_t total_pages; @@ -592,6 +594,8 @@ int hermit_main(void) 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)); kprintf("Core %d is the boot processor\n", boot_processor); + if (hbmem_base) + kprintf("Found high bandwidth memory at 0x%zx (size 0x%zx)\n", hbmem_base, hbmem_size); #if 0 print_pci_adapters(); diff --git a/hermit/kernel/syscall.c b/hermit/kernel/syscall.c index fc5753638..4f110f682 100644 --- a/hermit/kernel/syscall.c +++ b/hermit/kernel/syscall.c @@ -496,7 +496,10 @@ int sys_rcce_init(int session_id) goto out; } - paddr = get_pages(RCCE_MPB_SIZE / PAGE_SIZE); + if (is_hbmem_available()) + paddr = hbmem_get_pages(RCCE_MPB_SIZE / PAGE_SIZE); + else + paddr = get_pages(RCCE_MPB_SIZE / PAGE_SIZE); if (BUILTIN_EXPECT(!paddr, 0)) { err = -ENOMEM; @@ -592,8 +595,12 @@ int sys_rcce_fini(int session_id) goto out; } - if (rcce_mpb[i].mpb[isle]) - put_pages(rcce_mpb[i].mpb[isle], RCCE_MPB_SIZE / PAGE_SIZE); + if (rcce_mpb[i].mpb[isle]) { + if (is_hbmem_available()) + hbmem_put_pages(rcce_mpb[i].mpb[isle], RCCE_MPB_SIZE / PAGE_SIZE); + else + put_pages(rcce_mpb[i].mpb[isle], RCCE_MPB_SIZE / PAGE_SIZE); + } rcce_mpb[i].mpb[isle] = 0; for(j=0; (j