added recent changes
This commit is contained in:
18
KernelModule/BSDmakefile.meson
Normal file
18
KernelModule/BSDmakefile.meson
Normal file
@@ -0,0 +1,18 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
# Copyright(c) 2017 Intel Corporation
|
||||
|
||||
# makefile for building kernel modules using meson
|
||||
# takes parameters from the environment
|
||||
|
||||
# source file is passed via KMOD_SRC as relative path, we only use final
|
||||
# (tail) component of it (:T), as VPATH is used to find actual file. The
|
||||
# VPATH is similarly extracted from the non-final (head) portion of the
|
||||
# path (:H) converted to absolute path (:tA). This use of VPATH is to have
|
||||
# the .o files placed in the build, not source directory
|
||||
|
||||
VPATH := ${KMOD_SRC:H:tA}
|
||||
SRCS := ${KMOD_SRC:T} device_if.h bus_if.h pci_if.h
|
||||
CFLAGS += $(KMOD_CFLAGS)
|
||||
.OBJDIR: ${KMOD_OBJDIR}
|
||||
|
||||
.include <bsd.kmod.mk>
|
||||
5
KernelModule/Hugepages/Makefile
Normal file
5
KernelModule/Hugepages/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
KMOD= superpage
|
||||
SRCS= superpage.c
|
||||
|
||||
.include <bsd.kmod.mk>
|
||||
|
||||
0
KernelModule/Hugepages/build
Normal file
0
KernelModule/Hugepages/build
Normal file
6
KernelModule/Hugepages/build.sh
Normal file
6
KernelModule/Hugepages/build.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
cc -O2 -pipe -march=morello -Xclang -morello-vararg=new -Xclang -morello-bounded-memargs=caller-only -mabi=purecap-benchmark -D__LP64__=1 -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc -include /usr/home/akilan/Alloc-Test/CHERI-Allocator/KernelModule/Hugepages/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fPIC -fdebug-prefix-map=./machine=/usr/src/sys/arm64/include -MD -MF.depend.superpage.o -MTsuperpage.o -mgeneral-regs-only -ffixed-x18 -march=morello -Xclang -morello-vararg=new -Xclang -morello-bounded-memargs=caller-only -mabi=purecap -ffreestanding -fwrapv -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-format-zero-length -Werror=implicit-function-declaration -std=gnu99 -c superpage.c -o superpage.o
|
||||
|
||||
ld -m aarch64elf_cheri -d -warn-common --build-id=sha1 --no-relax --morello-c64-plt -r -o superpage.kld superpage.o
|
||||
:> export_syms
|
||||
|
||||
objcopy --strip-debug superpage.ko
|
||||
4
KernelModule/Hugepages/meson.build
Normal file
4
KernelModule/Hugepages/meson.build
Normal file
@@ -0,0 +1,4 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
# Copyright(c) 2017 Intel Corporation
|
||||
|
||||
sources = files('superpage.c')
|
||||
59
KernelModule/Hugepages/superpage.c
Normal file
59
KernelModule/Hugepages/superpage.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/systm.h>
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_extern.h>
|
||||
#include <vm/vm_page.h>
|
||||
#include <vm/vm_kern.h>
|
||||
|
||||
#define HUGE_PAGE_SIZE (2 * 1024 * 1024) // 2MB Huge Page
|
||||
|
||||
static void *hugepage_ptr = NULL;
|
||||
|
||||
// Load function - allocate memory
|
||||
static int load_handler(module_t mod, int event, void *arg) {
|
||||
switch (event) {
|
||||
case MOD_LOAD:
|
||||
printf("Loading Huge Page Kernel Module...\n");
|
||||
|
||||
// Allocate contiguous memory
|
||||
hugepage_ptr = kmem_alloc_contig(HUGE_PAGE_SIZE, M_NOWAIT,
|
||||
VM_MIN_KERNEL_ADDRESS, VM_MAX_KERNEL_ADDRESS,
|
||||
HUGE_PAGE_SIZE, 0,
|
||||
VM_MEMATTR_DEFAULT);
|
||||
|
||||
if (hugepage_ptr == NULL) {
|
||||
printf("Failed to allocate a huge page!\n");
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
printf("Huge page allocated at %p\n", hugepage_ptr);
|
||||
break;
|
||||
|
||||
case MOD_UNLOAD:
|
||||
printf("Unloading Huge Page Kernel Module...\n");
|
||||
|
||||
// Free memory if allocated
|
||||
if (hugepage_ptr) {
|
||||
kmem_free(hugepage_ptr, HUGE_PAGE_SIZE);
|
||||
printf("Huge page freed.\n");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Register module
|
||||
static moduledata_t superpage_mod = {
|
||||
"superpage", // Module name
|
||||
load_handler,
|
||||
NULL
|
||||
};
|
||||
|
||||
DECLARE_MODULE(superpage, superpage_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
|
||||
|
||||
39
KernelModule/meson.build
Normal file
39
KernelModule/meson.build
Normal file
@@ -0,0 +1,39 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
# Copyright(c) 2018 Intel Corporation
|
||||
|
||||
kmods = ['Hugepages']
|
||||
|
||||
# for building kernel modules, we use kernel build system using make, as
|
||||
# with Linux. We have a skeleton BSDmakefile, which pulls many of its
|
||||
# values from the environment. Each module only has a single source file
|
||||
# right now, which allows us to simplify things. We pull in the sourcer
|
||||
# files from the individual meson.build files, and then use a custom
|
||||
# target to call make, passing in the values as env parameters.
|
||||
kmod_cflags = ['-I' + dpdk_build_root,
|
||||
'-I' + join_paths(dpdk_source_root, 'config'),
|
||||
'-include rte_config.h']
|
||||
|
||||
kmod_arch = 'MACHINE_ARCH_NULL='
|
||||
kmod_arch = 'MACHINE_ARCH=aarch64'
|
||||
|
||||
# to avoid warnings due to race conditions with creating the dev_if.h, etc.
|
||||
# files, serialize the kernel module builds. Each module will depend on
|
||||
# previous ones
|
||||
built_kmods = []
|
||||
foreach k:kmods
|
||||
subdir(k)
|
||||
built_kmods += custom_target(k,
|
||||
input: [files('BSDmakefile.meson'), sources],
|
||||
output: k + '.ko',
|
||||
command: ['make', '-f', '@INPUT0@',
|
||||
'KMOD_OBJDIR=@OUTDIR@',
|
||||
'KMOD_SRC=@INPUT1@',
|
||||
'KMOD=' + k,
|
||||
'KMOD_CFLAGS=' + ' '.join(kmod_cflags),
|
||||
'CC=clang',
|
||||
kmod_arch],
|
||||
depends: built_kmods, # make each module depend on prev
|
||||
build_by_default: get_option('enable_kmods'),
|
||||
install: get_option('enable_kmods'),
|
||||
install_dir: '/boot/modules/')
|
||||
endforeach
|
||||
Reference in New Issue
Block a user