Skip to content

Commit

Permalink
rebase with master
Browse files Browse the repository at this point in the history
  • Loading branch information
emil916 committed Jun 12, 2024
2 parents 9a41842 + 693e633 commit 1c968ff
Show file tree
Hide file tree
Showing 175 changed files with 1,454 additions and 1,360 deletions.
10 changes: 4 additions & 6 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
BasedOnStyle: Mozilla
IndentWidth: 8
Language: Cpp
Expand All @@ -10,10 +9,10 @@ AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignTrailingComments: true

AllowShortBlocksOnASingleLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true

AlwaysBreakAfterReturnType: AllDefinitions
Expand All @@ -38,7 +37,7 @@ BreakBeforeBinaryOperators: NonAssignment

ColumnLimit: 120

Cpp11BracedListStyle: false
Cpp11BracedListStyle: true

IndentCaseLabels: false
IndentWrappedFunctionNames: false
Expand All @@ -47,10 +46,9 @@ KeepEmptyLinesAtTheStartOfBlocks: false

MaxEmptyLinesToKeep: 2

DerivePointerAlignment: false
PointerAlignment: Right

SortIncludes: false
SortIncludes: true

SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

env:
LLVM_VERSION: 13
WASI_SDK_URL: https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz
WASI_SDK_VERSION: 12
WASI_SDK_PATH: /opt/wasi-sdk
LANG: C.UTF-8
LANGUAGE: C.UTF-8
Expand All @@ -18,10 +18,10 @@ jobs:
- name: Apt Update
run: sudo apt-get update
- uses: actions/checkout@v2
- name: Install LLVM
- name: Install Clang Format
run: |
sudo ./install_llvm.sh $LLVM_VERSION
- name: Clang Format
- name: Run Clang Format
run: ./format.sh -d
test:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -62,6 +62,7 @@ jobs:
echo "/root/.cargo/bin:$PATH" >> $GITHUB_PATH
- name: Get wasi-sdk
run: |
WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK_VERSION/wasi-sdk-$WASI_SDK_VERSION.0-linux.tar.gz
wget $WASI_SDK_URL -O wasi-sdk.tar.gz
mkdir -p $WASI_SDK_PATH
tar xvfz wasi-sdk.tar.gz --strip-components=1 -C $WASI_SDK_PATH
Expand Down
17 changes: 15 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"tenant.h": "c",
"route_config.h": "c",
"http_router.h": "c",
"admissions_info.h": "c",
"execution_histogram.h": "c",
"tcp_server.h": "c",
"stdint.h": "c",
"scheduler_options.h": "c",
Expand Down Expand Up @@ -144,7 +144,20 @@
"algorithm": "c",
"stdio.h": "c",
"get_time.h": "c",
"unistd.h": "c"
"unistd.h": "c",
"wasi.h": "c",
"stat.h": "c",
"functional": "c",
"sandbox_state.h": "c",
"ratio": "c",
"tuple": "c",
"type_traits": "c",
"perf_window.h": "c",
"http_route_total.h": "c",
"sledge_abi_symbols.h": "c",
"mutex": "c",
"lock.h": "c",
"route_latency.h": "c"
},
"files.exclude": {
"**/.git": true,
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile.x86_64
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# using ubuntu 20 docker image
FROM ubuntu:focal

ENV LLVM_VERSION=13
ENV WASI_SDK_VERSION=12

ARG DEBIAN_FRONTEND=noninteractive
ARG HEY_URL=https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64
ARG WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk_12.0_amd64.deb
ARG WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK_VERSION/wasi-sdk_$WASI_SDK_VERSION.0_amd64.deb
ARG SHFMT_URL=https://github.com/mvdan/sh/releases/download/v3.2.4/shfmt_v3.2.4_linux_amd64
ARG SHELLCHECK_URL=https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz

Expand Down Expand Up @@ -74,12 +77,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
vim \
wabt

ENV LLVM_VERSION=12
ADD install_llvm.sh /sledge/install_llvm.sh
RUN ./sledge/install_llvm.sh $LLVM_VERSION

# WASI-SDK
RUN curl -sS -L -O $WASI_SDK_URL && dpkg -i wasi-sdk_12.0_amd64.deb && rm -f wasi-sdk_12.0_amd64.deb
RUN curl -sS -L -O $WASI_SDK_URL && dpkg -i wasi-sdk_$WASI_SDK_VERSION.0_amd64.deb && rm -f wasi-sdk_$WASI_SDK_VERSION.0_amd64.deb
ENV WASI_SDK_PATH=/opt/wasi-sdk

# Create non-root user and add to sudoers
Expand Down
11 changes: 5 additions & 6 deletions applications/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ all: \
license_plate_detection.install \
resize_image.install \
cnn_face_detection.install \
scratch_storage_get.install \
scratch_storage_set.install \
scratch_storage_delete.install \
scratch_storage_upsert.install \
get_jpeg_resolution.install \

.PHONY: clean
clean:
@make -C wasm_apps clean
@make -C scratch_storage clean
@rm -rf dist
@rm -rf ../runtime/bin/*.so

Expand Down Expand Up @@ -69,7 +65,7 @@ dist/%.bc: ./wasm_apps/dist/%.wasm dist
${AWSMCC} ${AWSMFLAGS} $< -o $@

dist/%.ll: dist/%.bc
llvm-dis-12 $< -o $@
llvm-dis $< -o $@

dist/%.wasm.so: dist/%.bc
${CC} ${CFLAGS} ${LDFLAGS} $^ -o $@
Expand Down Expand Up @@ -109,6 +105,9 @@ license_plate_detection.install: ../runtime/bin/license_plate_detection.wasm.so
.PHONY: cnn_face_detection.install
cnn_face_detection.install: ../runtime/bin/cnn_face_detection.wasm.so

.PHONY: get_jpeg_resolution.install
get_jpeg_resolution.install: ../runtime/bin/get_jpeg_resolution.wasm.so

.PHONY: trap_divzero.install
trap_divzero.install: ../runtime/bin/trap_divzero.wasm.so

Expand Down
2 changes: 1 addition & 1 deletion awsm
Submodule awsm updated 70 files
+17 −17 .clang-format
+17 −9 .github/workflows/main.yaml
+2 −2 README.md
+2 −2 applications/Makefile
+1 −1 applications/wasm_apps
+1 −1 code_benches/app_tinycrypt/Makefile
+1 −1 code_benches/custom_binarytrees/Makefile
+4 −2 code_benches/run.py
+8 −4 example_code/basic.c
+61 −51 example_code/binarytrees.c
+17 −13 example_code/control_bug.c
+5 −3 example_code/dummy.c
+7 −7 example_code/environ/environ.c
+6 −6 example_code/for_loops.c
+20 −12 example_code/function_pointers.c
+5 −3 example_code/libc_link.c
+4 −2 example_code/long_double.c
+4 −4 example_code/main.c
+43 −42 example_code/mandelbrot.c
+13 −11 example_code/mutual_recursion.c
+93 −94 example_code/nested_loop.c
+6 −4 example_code/printing.c
+4 −2 example_code/weird.c
+62 −33 format.sh
+16 −8 install_deb.sh
+3 −2 runtime/cortex_m_glue/hello.ld
+970 −939 runtime/cortex_m_glue/math.c
+344 −345 runtime/cortex_m_glue/math2.c
+323 −320 runtime/cortex_m_glue/math3.c
+207 −208 runtime/cortex_m_glue/math4.c
+669 −689 runtime/cortex_m_glue/printf.c
+6 −6 runtime/cortex_m_glue/printf.h
+12 −6 runtime/cortex_m_glue/qemu_pid.c
+7 −5 runtime/cortex_m_glue/qemu_putchar.c
+310 −305 runtime/cortex_m_glue/sections.ld
+962 −914 runtime/libc/cortex_m_backing.c
+98 −68 runtime/libc/env.c
+456 −393 runtime/libc/wasi/include/wasi_backing.h
+22 −18 runtime/libc/wasi/include/wasi_impl.h
+226 −192 runtime/libc/wasi/include/wasi_serdes.h
+250 −250 runtime/libc/wasi/include/wasi_spec.h
+2 −2 runtime/libc/wasi/wasi_backing.c
+664 −536 runtime/libc/wasi/wasi_impl_minimal.c
+267 −186 runtime/libc/wasi/wasi_impl_uvwasi.c
+28 −26 runtime/libc/wasi/wasi_main.c
+503 −426 runtime/libc/wasmception_backing.c
+59 −43 runtime/memory/64bit_nix.c
+41 −27 runtime/memory/cortex_m.c
+41 −27 runtime/memory/cortex_m_no_protection.c
+41 −29 runtime/memory/cortex_m_spt.c
+38 −24 runtime/memory/cortex_m_wrapping.c
+37 −23 runtime/memory/generic.c
+35 −23 runtime/memory/mpx.c
+34 −20 runtime/memory/no_protection.c
+97 −73 runtime/memory/segmented.c
+32 −29 runtime/runtime.c
+45 −43 runtime/runtime.h
+79 −73 runtime/runtime_so.c
+245 −170 runtime/wasm_instructions/common.c
+82 −56 runtime/wasm_instructions/memory/64bit_nix.c
+94 −68 runtime/wasm_instructions/memory/cortex_m.c
+77 −51 runtime/wasm_instructions/memory/cortex_m_no_protection.c
+164 −134 runtime/wasm_instructions/memory/cortex_m_spt.c
+77 −51 runtime/wasm_instructions/memory/cortex_m_wrapping.c
+93 −67 runtime/wasm_instructions/memory/generic.c
+104 −76 runtime/wasm_instructions/memory/mpx.c
+77 −51 runtime/wasm_instructions/memory/no_protection.c
+62 −36 runtime/wasm_instructions/memory/segmented.c
+1 −1 tests/wasi/Makefile
+1 −1 tests/wat/Makefile
14 changes: 8 additions & 6 deletions format.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash

LLVM_VERSION=13

validate() {
utility="clang-format-13"
utility="clang-format"
utility_version="$("$utility" --version 2> /dev/null)" || {
echo "$utility not found in path!"
exit 1
Expand All @@ -11,7 +13,7 @@ validate() {
declare -i major=0
declare -i minor=0
declare -i patch=0
declare -i required_major=13
declare -i required_major=$LLVM_VERSION
declare -i required_minor=0
declare -i required_patch=0

Expand Down Expand Up @@ -43,14 +45,14 @@ help() {

dry_run() {
find runtime \
\( -path "runtime/thirdparty" -o -path "applications/gocr" -o -path "applications/TinyEKF" -o -path "applications/CMSIS_5_NN" -o -path "applications/sod" -o -path "applications/**/thirdparty" \) -prune -false -o \
-type f \( -iname \*.h -o -iname \*.c -o -iname \*.s \) -print \
| xargs clang-format -Werror -n -ferror-limit=0
\( -path "runtime/thirdparty" \) -prune -false -o \
-type f \( -iname \*.h -o -iname \*.c -o -iname \*.s \) -print0 \
| xargs --null clang-format -Werror -n -ferror-limit=1
}

format() {
find runtime \
\( -path "runtime/thirdparty" -o -path "applications/gocr" -o -path "applications/TinyEKF" -o -path "applications/CMSIS_5_NN" -o -path "applications/sod" -o -path "applications/**/thirdparty" \) -prune -false -o \
\( -path "runtime/thirdparty" \) -prune -false -o \
-type f \( -iname \*.h -o -iname \*.c -o -iname \*.s \) -print0 \
| xargs --null clang-format -i
}
Expand Down
10 changes: 6 additions & 4 deletions install_deb.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/bin/bash

LLVM_VERSION=12
# Note, wasi-sdk versions do NOT match llvm versions, e.g. wasi-sdk-12 actually uses llvm-11
LLVM_VERSION=13
WASI_SDK_VERSION=12

ARCH=$(uname -p)
ARCH=$(uname -m)

if [[ $ARCH = "x86_64" ]]; then
SHFMT_URL=https://github.com/mvdan/sh/releases/download/v3.4.3/shfmt_v3.4.3_linux_amd64
WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk_12.0_amd64.deb
WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK_VERSION/wasi-sdk_$WASI_SDK_VERSION.0_amd64.deb
elif [[ $ARCH = "aarch64" ]]; then
SHFMT_URL=https://github.com/patrickvane/shfmt/releases/download/master/shfmt_linux_arm
echo "ARM64 support is still a work in progress!"
Expand Down Expand Up @@ -64,7 +66,7 @@ wget $SHFMT_URL -O shfmt && chmod +x shfmt && sudo mv shfmt /usr/local/bin/shfmt

sudo ./install_llvm.sh $LLVM_VERSION

curl -sS -L -O $WASI_SDK_URL && sudo dpkg -i wasi-sdk_12.0_amd64.deb && rm -f wasi-sdk_12.0_amd64.deb
curl -sS -L -O $WASI_SDK_URL && sudo dpkg -i wasi-sdk_$WASI_SDK_VERSION.0_amd64.deb && rm -f wasi-sdk_$WASI_SDK_VERSION.0_amd64.deb

if [ -z "${WASI_SDK_PATH}" ]; then
export WASI_SDK_PATH=/opt/wasi-sdk
Expand Down
26 changes: 13 additions & 13 deletions install_llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ echo "Installing LLVM $LLVM_VERSION"
# Script Installs clang, lldb, lld, and clangd
curl --proto '=https' --tlsv1.2 -sSf https://apt.llvm.org/llvm.sh | bash -s -- "$LLVM_VERSION"

# Installing "libc++-xx-dev" automagically installs "libc++1-xx", "libunwind-xx" and "libunwind-xx-dev"
apt-get install -y --no-install-recommends \
"libc++-$LLVM_VERSION-dev" \
"libc++abi-$LLVM_VERSION-dev" \
"libc++1-$LLVM_VERSION" \
"libunwind-$LLVM_VERSION" \
"libunwind-$LLVM_VERSION-dev" \
"clang-tools-$LLVM_VERSION" \
"clang-tidy-$LLVM_VERSION" \
"clang-format-$LLVM_VERSION"

sudo update-alternatives --remove-all clang-format
sudo update-alternatives --remove-all clang
sudo update-alternatives --remove-all clang++
sudo update-alternatives --remove-all llvm-config
sudo update-alternatives --remove-all llvm-objdump
sudo update-alternatives --remove-all llvm-objdump
sudo update-alternatives --remove-all clang-tidy
update-alternatives --remove-all wasm-ld
update-alternatives --remove-all llvm-config
update-alternatives --remove-all llvm-objdump
update-alternatives --remove-all llvm-dis
update-alternatives --remove-all clang-format
update-alternatives --remove-all clang
update-alternatives --remove-all clang++
update-alternatives --remove-all clang-tidy

update-alternatives --install /usr/bin/wasm-ld wasm-ld "/usr/bin/wasm-ld-$LLVM_VERSION" 100
update-alternatives --install /usr/bin/llvm-config llvm-config "/usr/bin/llvm-config-$LLVM_VERSION" 100
update-alternatives --install /usr/bin/llvm-objdump llvm-objdump "/usr/bin/llvm-objdump-$LLVM_VERSION" 100
update-alternatives --install /usr/bin/llvm-dis llvm-dis /usr/bin/llvm-dis-$LLVM_VERSION 100
update-alternatives --install /usr/bin/clang-format clang-format "/usr/bin/clang-format-$LLVM_VERSION" 100
update-alternatives --install /usr/bin/clang clang "/usr/bin/clang-$LLVM_VERSION" 100
update-alternatives --install /usr/bin/clang++ clang++ "/usr/bin/clang++-$LLVM_VERSION" 100
update-alternatives --install /usr/bin/llvm-config llvm-config "/usr/bin/llvm-config-$LLVM_VERSION" 100
update-alternatives --install /usr/bin/llvm-objdump llvm-objdump "/usr/bin/llvm-objdump-$LLVM_VERSION" 100
update-alternatives --install /usr/bin/clang-tidy clang-tidy "/usr/bin/clang-tidy-$LLVM_VERSION" 100
update-alternatives --install /usr/bin/wasm-ld wasm-ld "/usr/bin/wasm-ld-$LLVM_VERSION" 100
5 changes: 5 additions & 0 deletions runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ BINARY_NAME=sledgert


# Feature Toggles
CFLAGS += -DEXECUTION_HISTOGRAM
# CFLAGS += -DEXECUTION_REGRESSION

# It is recommended (not mandatory) to enable this flag along with the EXECUTION_HISTOGRAM flag:
# CFLAGS += -DADMISSIONS_CONTROL

# Debugging Flags
Expand All @@ -56,6 +60,7 @@ BINARY_NAME=sledgert
# CFLAGS += -DLOG_TO_FILE

# Various Informational Logs for Debugging
# CFLAGS += -DLOG_EXECUTION_HISTOGRAM
# CFLAGS += -DLOG_ADMISSIONS_CONTROL
# CFLAGS += -DLOG_CONTEXT_SWITCHES
# CFLAGS += -DLOG_HTTP_PARSER
Expand Down
7 changes: 4 additions & 3 deletions runtime/include/admissions_control.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#pragma once

#ifdef ADMISSIONS_CONTROL

#include <stdbool.h>
#include <stdint.h>

#ifdef ADMISSIONS_CONTROL
#define ADMISSIONS_CONTROL_GRANULARITY 1000000
extern _Atomic uint64_t admissions_control_admitted;
extern uint64_t admissions_control_capacity;
#endif

void admissions_control_initialize(void);
void admissions_control_add(uint64_t admissions_estimate);
void admissions_control_subtract(uint64_t admissions_estimate);
uint64_t admissions_control_calculate_estimate(uint64_t estimated_execution, uint64_t relative_deadline);
uint64_t admissions_control_calculate_estimate_us(uint32_t estimated_execution_us, uint32_t relative_deadline_us);
void admissions_control_log_decision(uint64_t admissions_estimate, bool admitted);
uint64_t admissions_control_decide(uint64_t admissions_estimate);

#endif
15 changes: 0 additions & 15 deletions runtime/include/admissions_info.h

This file was deleted.

2 changes: 1 addition & 1 deletion runtime/include/arch/arch_context_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <setjmp.h>
#include <ucontext.h>

#include "arch/arch_context_variant_t.h"
#include "arch/reg_t.h"
#include "arch/ureg_t.h"
#include "arch/arch_context_variant_t.h"

struct arch_context {
arch_context_variant_t variant;
Expand Down
1 change: 1 addition & 0 deletions runtime/include/auto_buf.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "likely.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
Loading

0 comments on commit 1c968ff

Please sign in to comment.