diff --git a/install.sh b/install.sh index 6d7fe83..d8a1a08 100755 --- a/install.sh +++ b/install.sh @@ -17,6 +17,7 @@ fi SYS_NAME='sledge' COMPILER='awsm' +COMPILER_EXECUTABLE='silverfish' # /opt/sledge SYS_PREFIX=${SYS_PREFIX:-"/opt/${SYS_NAME}"} @@ -57,7 +58,7 @@ rm -f "${SYS_BIN_DIR}"/* install -d -v "$SYS_BIN_DIR" || exit 1 # Link each of the binaries in the system bin directory -BINS=${COMPILER} +BINS=${COMPILER_EXECUTABLE} for bin in $BINS; do # i.e. ./silverfish/target/release/silverfish -> /opt/sledge/bin/silverfish ln -sfv "${SYS_COMPILER_REL_DIR}/${bin}" "${SYS_BIN_DIR}/${bin}" diff --git a/runtime/Makefile b/runtime/Makefile index c7c0a72..24f41bd 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -1,73 +1,74 @@ -CC=clang - -RTDIR=src/ -CFILES=${RTDIR}/*.c ${RTDIR}/libc/*.c ${RTDIR}/memory/common.c -RUNTIME=bin/sledgert -INC=include/ ARCH := $(shell uname -m) +TOTAL_CORES := $(shell getconf _NPROCESSORS_CONF) +PAGE_SIZE=$(shell getconf PAGESIZE) -OPTFLAGS = -O3 -OPTFLAGS += -flto -g -LDFLAGS = -Wl,--export-dynamic -ldl -lm -USE_MEM = USE_MEM_VM -CFLAGS = ${OPTFLAGS} -D${USE_MEM} -I${INC} -pthread -CFLAGS += -D${ARCH} -CFILES += ${RTDIR}/arch/${ARCH}/*.c -# CFLAGS += -DDEBUG -CFLAGS += -D_GNU_SOURCE -#CFLAGS += -DLOG_TO_FILE -#CFLAGS += -DUSE_HTTP_UVIO #-DUSE_HTTP_SYNC -#CFLAGS += -DUSE_SYSCALL -#CFLAGS += -DPREEMPT_DISABLE -NCORES_CONF := $(shell getconf _NPROCESSORS_CONF) -#todo:cross-compile -CFLAGS += -DNCORES=${NCORES_CONF} -#CFLAGS += -DNCORES=4 -CFLAGS += -DPAGE_SIZE=$(shell getconf PAGESIZE) +# Compiler Settings +CC=clang +CC_OPTIONS = -O3 -flto -g -pthread -D_GNU_SOURCE -MAKE= make --no-print-directory -THIRDPARTY=thirdparty +BINARY_NAME=sledgert -THIRDPARTY_DIST=${THIRDPARTY}/dist/ -THIRDPARTY_INC=${THIRDPARTY_DIST}/include/ -THIRDPARTY_LIB=${THIRDPARTY_DIST}/lib/ -LDFLAGS += -L${THIRDPARTY_LIB} -CFLAGS += -I${THIRDPARTY_INC} +NCORES = ${TOTAL_CORES} # Number of Cores. Options: {2...N or TOTAL_CORES} +USE_MEM = USE_MEM_VM # Options: {USE_MEM_GENERIC, USE_MEM_VM} -JSMNCFLAGS=-DJSMN_STATIC -DJSMN_STRICT -HTTPPARSEOBJ=${THIRDPARTY_LIB}/http_parser.o -CFILES += ${HTTPPARSEOBJ} +INCLUDES += -Iinclude/ -Ithirdparty/dist/include/ +# CFILES +CFILES += src/*.c +CFILES += src/arch/${ARCH}/*.c +CFILES += src/libc/*.c +CFILES += src/memory/common.c +CFILES += thirdparty/dist/lib/http_parser.o +# TODO: Is USE_MEM_GENERIC out of date? I do not see that file. +# Does that mean we can make USE_MEM_VM an invariant? ifeq ($(USE_MEM),USE_MEM_GENERIC) -CFILES += ${RTDIR}/memory/generic.c +CFILES += src/memory/generic.c else ifeq ($(USE_MEM),USE_MEM_VM) -CFILES += ${RTDIR}/memory/64bit_nix.c +CFILES += src/memory/64bit_nix.c endif +# Flags +CFLAGS += -D${ARCH} +#CFLAGS += -DDEBUG +#CFLAGS += -DLOG_TO_FILE +CFLAGS += -DNCORES=${NCORES} +CFLAGS += -DPAGE_SIZE=$(PAGE_SIZE) +#CFLAGS += -DPREEMPT_DISABLE +#CFLAGS += -DUSE_HTTP_UVIO #-DUSE_HTTP_SYNC +CFLAGS += -D${USE_MEM} +#CFLAGS += -DUSE_SYSCALL + +LDFLAGS += -Wl,--export-dynamic -ldl -lm +LDFLAGS += -Lthirdparty/dist/lib/ + +# Configuring JasmineEEE +JSMNCFLAGS += -DJSMN_STATIC +JSMNCFLAGS += -DJSMN_STRICT + all: clean runtime runtime: @echo "Compiling runtime" @mkdir -p bin/ - @${CC} ${CFLAGS} ${LDFLAGS} ${CFILES} ${JSMNCFLAGS} ${HTTPPARSECFLAGS} -L/usr/lib/ -luv $^ -o ${RUNTIME} + @${CC} ${CC_OPTIONS} ${INCLUDES} ${CFLAGS} ${LDFLAGS} ${CFILES} ${JSMNCFLAGS} -L/usr/lib/ -luv $^ -o bin/${BINARY_NAME} thirdparty: @echo "Compiling thirdparty" - @${MAKE} -C thirdparty build + @make --no-print-directory -C thirdparty build tools: # @echo "Compiling tools" - @${MAKE} -C tools + @make --no-print-directory -C tools clean: @rm -f core @echo "Cleaning up runtime" - @rm -f ${RUNTIME} + @rm -f bin/${BINARY_NAME} # @echo "Cleaning up tools" -# @${MAKE} -C tools clean +# @make --no-print-directory -C tools clean distclean: clean - @${MAKE} -C thirdparty clean + @make --no-print-directory -C thirdparty clean fetch: @git submodule update --init --recursive diff --git a/runtime/include/worker_thread.h b/runtime/include/worker_thread.h index 227de57..e1f989c 100644 --- a/runtime/include/worker_thread.h +++ b/runtime/include/worker_thread.h @@ -2,6 +2,8 @@ #include +#include "runtime.h" + /* If multicore, use all but the dedicated listener core If there are fewer cores than this, main dynamically overrides this and uses all available */ #define WORKER_THREAD_CORE_COUNT (NCORES > 1 ? NCORES - 1 : NCORES) diff --git a/runtime/tests/Makefile b/runtime/tests/Makefile index 3854cd3..1e759f2 100644 --- a/runtime/tests/Makefile +++ b/runtime/tests/Makefile @@ -1,11 +1,13 @@ include Makefile.inc -BENCH_DIR=../../silverfish/code_benches/ +BENCH_DIR=../../${WASM2OBJ_NAME}/code_benches TESTS=fibonacci empty work work1k work10k work100k work1m #TESTS=forever filesys sockserver sockclient empty TESTSRT=$(TESTS:%=%_rt) -BENCHES=adpcm basic_math binarytrees bitcount blowfish crc dijkstra fft function_pointers \ +BENCHES=basic_math binarytrees bitcount blowfish crc dijkstra fft function_pointers \ + gsm libjpeg mandelbrot patricia pgp qsort rsynth sha sqlite stringsearch susan +#BENCHES=adpcm basic_math binarytrees bitcount blowfish crc dijkstra fft function_pointers \ gsm libjpeg mandelbrot patricia pgp qsort rsynth sha sqlite stringsearch susan BENCHESSF=$(BENCHES:%=%_sf) @@ -35,22 +37,22 @@ clean: %_sf: @mkdir -p ${TMP_DIR} @echo "Compiling $(@:%_sf=%)" - ${WASMCC} ${$(@:%_sf=%)_CFLAGS} ${WASMCFLAGS} ${OPTFLAGS} ${BENCH_DIR}/$(@:%_sf=%)/*.c $(DUMMY) -o ${TMP_DIR}/$(@:%_sf=%).wasm - ${SFCC} ${TMP_DIR}/$(@:%_sf=%).wasm -o ${TMP_DIR}/$(@:%_sf=%).bc - ${CC} ${CFLAGS} ${OPTFLAGS} -D${USE_MEM} -D${ARCH} ${TMP_DIR}/$(@:%_sf=%).bc ${MEMC} ${RT_LIBC} ${RT_ENV} ${RT_RT} -lm -o ${TMP_DIR}/$(@:%_sf=%)_wasm.out - ${SFCC} --inline-constant-globals --runtime-globals ${TMP_DIR}/$(@:%_sf=%).wasm -o ${TMP_DIR}/$(@:%_sf=%).bc - ${CC} --shared -fPIC ${OPTFLAGS} -I${ART_INC} -D${USE_MEM} ${TMP_DIR}/$(@:%_sf=%).bc ${AMEMC} ${WASMISA} -lm -o ${TMP_DIR}/$(@:%_sf=%)_wasm.so - @cp ${TMP_DIR}/$(@:%_sf=%)_wasm.so ${ABIN_DIR} + ${WASMCC} ${$(@:%_sf=%)_CFLAGS} ${WASMCFLAGS} ${OPTFLAGS} ${BENCH_DIR}/$(@:%_sf=%)/*.c $(WASM2OBJ_DUMMY) -o ${TMP_DIR}/$(@:%_sf=%).wasm + ${WASM2OBJ_EXECUTABLE} ${TMP_DIR}/$(@:%_sf=%).wasm -o ${TMP_DIR}/$(@:%_sf=%).bc + ${CC} ${CFLAGS} ${OPTFLAGS} -D${USE_MEM} -D${ARCH} ${TMP_DIR}/$(@:%_sf=%).bc ${WASM2OBJ_MEMC} ${WASM2OBJ_RT_LIBC} ${WASM2OBJ_RT_ENV} ${WASM2OBJ_RT_RT} -lm -o ${TMP_DIR}/$(@:%_sf=%)_wasm.out + ${WASM2OBJ_EXECUTABLE} --inline-constant-globals --runtime-globals ${TMP_DIR}/$(@:%_sf=%).wasm -o ${TMP_DIR}/$(@:%_sf=%).bc + ${CC} --shared -fPIC ${OPTFLAGS} -I${SERVERLESS_RT_INC} -D${USE_MEM} ${TMP_DIR}/$(@:%_sf=%).bc ${SERVERLESS_MEMC} ${SERVERLESS_WASMISA} -lm -o ${TMP_DIR}/$(@:%_sf=%)_wasm.so + @cp ${TMP_DIR}/$(@:%_sf=%)_wasm.so ${SERVERLESS_BIN_DIR} # @rm -rf ${TMP_DIR} %_rt: @mkdir -p ${TMP_DIR} @echo "Compiling $(@:%_rt=%)" - ${WASMCC} ${$(@:%_rt=%)_CFLAGS} ${WASMCFLAGS} ${OPTFLAGS} $(@:%_rt=%)/*.c $(DUMMY) -o ${TMP_DIR}/$(@:%_rt=%).wasm - ${SFCC} ${TMP_DIR}/$(@:%_rt=%).wasm -o ${TMP_DIR}/$(@:%_rt=%).bc - ${CC} ${CFLAGS} ${OPTFLAGS} -D${USE_MEM} -D${ARCH} ${TMP_DIR}/$(@:%_rt=%).bc ${MEMC} ${RT_LIBC} ${RT_ENV} ${RT_RT} -lm -o ${TMP_DIR}/$(@:%_rt=%)_wasm.out - ${SFCC} --inline-constant-globals --runtime-globals ${TMP_DIR}/$(@:%_rt=%).wasm -o ${TMP_DIR}/$(@:%_rt=%).bc - ${CC} --shared -fPIC ${OPTFLAGS} -I${ART_INC} -D${USE_MEM} ${TMP_DIR}/$(@:%_rt=%).bc ${AMEMC} ${WASMISA} -o ${TMP_DIR}/$(@:%_rt=%)_wasm.so - @cp ${TMP_DIR}/$(@:%_rt=%)_wasm.so ${ABIN_DIR} + ${WASMCC} ${$(@:%_rt=%)_CFLAGS} ${WASMCFLAGS} ${OPTFLAGS} $(@:%_rt=%)/*.c $(WASM2OBJ_DUMMY) -o ${TMP_DIR}/$(@:%_rt=%).wasm + ${WASM2OBJ_EXECUTABLE} ${TMP_DIR}/$(@:%_rt=%).wasm -o ${TMP_DIR}/$(@:%_rt=%).bc + ${CC} ${CFLAGS} ${OPTFLAGS} -D${USE_MEM} -D${ARCH} ${TMP_DIR}/$(@:%_rt=%).bc ${WASM2OBJ_MEMC} ${WASM2OBJ_RT_LIBC} ${WASM2OBJ_RT_ENV} ${WASM2OBJ_RT_RT} -lm -o ${TMP_DIR}/$(@:%_rt=%)_wasm.out + ${WASM2OBJ_EXECUTABLE} --inline-constant-globals --runtime-globals ${TMP_DIR}/$(@:%_rt=%).wasm -o ${TMP_DIR}/$(@:%_rt=%).bc + ${CC} --shared -fPIC ${OPTFLAGS} -I${SERVERLESS_RT_INC} -D${USE_MEM} ${TMP_DIR}/$(@:%_rt=%).bc ${SERVERLESS_MEMC} ${SERVERLESS_WASMISA} -o ${TMP_DIR}/$(@:%_rt=%)_wasm.so + @cp ${TMP_DIR}/$(@:%_rt=%)_wasm.so ${SERVERLESS_BIN_DIR} # @rm -rf ${TMP_DIR} diff --git a/runtime/tests/Makefile.inc b/runtime/tests/Makefile.inc index ebc7f45..514b3f7 100644 --- a/runtime/tests/Makefile.inc +++ b/runtime/tests/Makefile.inc @@ -1,41 +1,46 @@ -BASE=sledge -SFCC=silverfish -CC=clang -WASMCC=wasm32-unknown-unknown-wasm-clang ARCH := $(shell uname -m) -OPTFLAGS=-O3 -flto -#same stack-size for all -WASMLINKFLAGS=-Wl,-z,stack-size=524288,--allow-undefined,--no-threads,--stack-first,--no-entry,--export-all,--export=main,--export=dummy -WASMCFLAGS=${WASMLINKFLAGS} -nostartfiles +CC=clang # Source -> Native +WASMCC=wasm32-unknown-unknown-wasm-clang # Source -> WebAssembly +OPTFLAGS=-O3 -flto MEMC_64=64bit_nix.c MEMC_NO=no_protection.c MEMC_GEN=generic.c MEMC_MPX=mpx.c MEMC_SEG=segmented.c +TMP_DIR=tmp/ -BASE_DIR=../../awsm/ -RT_DIR=${BASE_DIR}/runtime/ -RT_MEM=${RT_DIR}/memory/ -RT_LIBC=${RT_DIR}/libc/libc_backing.c -RT_RT=${RT_DIR}/runtime.c -RT_ENV=${RT_DIR}/libc/env.c ${RT_DIR}/libc/env_${ARCH}.c +# same stack-size for all +WASMLINKFLAGS=-Wl,-z,stack-size=524288,--allow-undefined,--no-threads,--stack-first,--no-entry,--export-all,--export=main,--export=dummy +WASMCFLAGS=${WASMLINKFLAGS} -nostartfiles -MEMC=${RT_MEM}/${MEMC_64} -DUMMY=${BASE_DIR}/code_benches/dummy.c +# aWsm Compiler Runtime (WebAssembly -> Native) +# Currently, the component which compiles WebAssembly modules to native code, is named aWsm +# However, the executable itself still currently retains the older name silverfish +WASM2OBJ_NAME=awsm +WASM2OBJ_EXECUTABLE=silverfish +WASM2OBJ_BASE_DIR=../../${WASM2OBJ_NAME} +WASM2OBJ_RT_DIR=${WASM2OBJ_BASE_DIR}/runtime/ +WASM2OBJ_RT_MEM=${WASM2OBJ_RT_DIR}/memory/ +WASM2OBJ_RT_LIBC=${WASM2OBJ_RT_DIR}/libc/libc_backing.c +WASM2OBJ_RT_RT=${WASM2OBJ_RT_DIR}/runtime.c +WASM2OBJ_RT_ENV=${WASM2OBJ_RT_DIR}/libc/env.c +# Is seems like the arch specific code no longer exists +# WASM2OBJ_RT_ENV=${WASM2OBJ_RT_DIR}/libc/env.c ${WASM2OBJ_RT_DIR}/libc/env_${ARCH}.c +WASM2OBJ_MEMC=${WASM2OBJ_RT_MEM}/${MEMC_64} +WASM2OBJ_DUMMY=${WASM2OBJ_BASE_DIR}/code_benches/dummy.c # for SLEdge -ABASE_DIR=../../ -ART_DIR=${ABASE_DIR}/runtime/ -ART_INC=${ART_DIR}/include/ +SERVERLESS_BASE=sledge +SERVERLESS_BASE_DIR=../../ +SERVERLESS_RT_DIR=${SERVERLESS_BASE_DIR}/runtime/ +SERVERLESS_RT_INC=${SERVERLESS_RT_DIR}/include/ +SERVERLESS_BIN_DIR=${SERVERLESS_RT_DIR}/bin/ +SERVERLESS_WASMISA=${SERVERLESS_RT_DIR}/compiletime/instr.c USE_MEM=USE_MEM_VM + ifeq ($(USE_MEM),USE_MEM_VM) -AMEMC=${ART_DIR}/compiletime/memory/${MEMC_64} +SERVERLESS_MEMC=${SERVERLESS_RT_DIR}/compiletime/memory/${MEMC_64} endif -WASMISA=${ART_DIR}/compiletime/instr.c - -ABIN_DIR=${ART_DIR}/bin/ -TMP_DIR=tmp/ -