diff --git a/runtime/Makefile b/runtime/Makefile index 3b119ac..c6ee952 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -7,7 +7,7 @@ endif # Compiler Settings CC=clang -CC_OPTIONS = -O3 -flto -g -pthread -D_GNU_SOURCE +CC_OPTIONS = -O3 -flto -g -pthread -D_GNU_SOURCE -std=c18 # CC_OPTIONS for Debugging # CC_OPTIONS = -O0 -g -pthread -D_GNU_SOURCE diff --git a/runtime/include/arch/aarch64/context.h b/runtime/include/arch/aarch64/context.h index 8c85b4a..57b5775 100644 --- a/runtime/include/arch/aarch64/context.h +++ b/runtime/include/arch/aarch64/context.h @@ -79,33 +79,33 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) reg_t *a_registers = a->regs, *b_registers = b->regs; assert(a_registers && b_registers); - asm volatile("mov x0, sp\n\t" - "adr x1, reset%=\n\t" - "str x1, [%[a], 8]\n\t" - "str x0, [%[a]]\n\t" - "mov x0, #1\n\t" - "str x0, [%[av]]\n\t" - "ldr x1, [%[bv]]\n\t" - "sub x1, x1, #2\n\t" - "cbz x1, slow%=\n\t" - "ldr x0, [%[b]]\n\t" - "ldr x1, [%[b], 8]\n\t" - "mov sp, x0\n\t" - "br x1\n\t" - "slow%=:\n\t" - "br %[slowpath]\n\t" - ".align 8\n\t" - "reset%=:\n\t" - "mov x1, #3\n\t" - "str x1, [%[bv]]\n\t" - ".align 8\n\t" - "exit%=:\n\t" - : - : [a] "r"(a_registers), [b] "r"(b_registers), [av] "r"(&a->variant), [bv] "r"(&b->variant), - [slowpath] "r"(&arch_context_restore_preempted) - : "memory", "cc", "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", - "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", "x24", "d8", "d9", - "d10", "d11", "d12", "d13", "d14", "d15"); + __asm__ volatile("mov x0, sp\n\t" + "adr x1, reset%=\n\t" + "str x1, [%[a], 8]\n\t" + "str x0, [%[a]]\n\t" + "mov x0, #1\n\t" + "str x0, [%[av]]\n\t" + "ldr x1, [%[bv]]\n\t" + "sub x1, x1, #2\n\t" + "cbz x1, slow%=\n\t" + "ldr x0, [%[b]]\n\t" + "ldr x1, [%[b], 8]\n\t" + "mov sp, x0\n\t" + "br x1\n\t" + "slow%=:\n\t" + "br %[slowpath]\n\t" + ".align 8\n\t" + "reset%=:\n\t" + "mov x1, #3\n\t" + "str x1, [%[bv]]\n\t" + ".align 8\n\t" + "exit%=:\n\t" + : + : [a] "r"(a_registers), [b] "r"(b_registers), [av] "r"(&a->variant), [bv] "r"(&b->variant), + [slowpath] "r"(&arch_context_restore_preempted) + : "memory", "cc", "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", + "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", "x24", + "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15"); return 0; } diff --git a/runtime/include/arch/common.h b/runtime/include/arch/common.h index 0f4148f..0f4d194 100644 --- a/runtime/include/arch/common.h +++ b/runtime/include/arch/common.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -30,4 +31,4 @@ */ /* Cannot be inlined because called in assembly */ -void __attribute__((noinline)) __attribute__((noreturn)) arch_context_restore_preempted(void); +noreturn void __attribute__((noinline)) arch_context_restore_preempted(void); diff --git a/runtime/include/arch/x86_64/context.h b/runtime/include/arch/x86_64/context.h index 4867a3c..20ea223 100644 --- a/runtime/include/arch/x86_64/context.h +++ b/runtime/include/arch/x86_64/context.h @@ -31,14 +31,14 @@ arch_context_init(struct arch_context *actx, reg_t ip, reg_t sp) * to push the stack pointer sp to the top of its own stack. * This acts as the base pointer */ - asm volatile("movq %%rsp, %%rbx\n\t" /* Temporarily save pointer of active stack to B */ - "movq %%rax, %%rsp\n\t" /* Set active stack to stack pointer in A(C variable sp) */ - "pushq %%rax\n\t" /* Push A register (C variable sp) onto the stack at sp */ - "movq %%rsp, %%rax\n\t" /* Write the incremented stack pointer to A(C variable sp) */ - "movq %%rbx, %%rsp\n\t" /* Restore original stack saved in B */ - : "=a"(sp) - : "a"(sp) - : "memory", "cc", "rbx"); + __asm__ volatile("movq %%rsp, %%rbx\n\t" /* Temporarily save pointer of active stack to B */ + "movq %%rax, %%rsp\n\t" /* Set active stack to stack pointer in A(C variable sp) */ + "pushq %%rax\n\t" /* Push A register (C variable sp) onto the stack at sp */ + "movq %%rsp, %%rax\n\t" /* Write the incremented stack pointer to A(C variable sp) */ + "movq %%rbx, %%rsp\n\t" /* Restore original stack saved in B */ + : "=a"(sp) + : "a"(sp) + : "memory", "cc", "rbx"); } // FIXME: Is the klobber list correct? Issue #129 // : "memory", "cc", "rbx", "rsi", "rdi"); @@ -109,7 +109,7 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) reg_t *a_registers = a->regs, *b_registers = b->regs; assert(a_registers && b_registers); - asm volatile( + __asm__ volatile( /* Create a new stack frame */ "pushq %%rbp\n\t" /* stack[stack_len++] = base_pointer */ "movq %%rsp, %%rbp\n\t" /* base_pointer = stack_pointer. Start new Frame */ diff --git a/runtime/include/current_sandbox.h b/runtime/include/current_sandbox.h index 4090ffd..b365d26 100644 --- a/runtime/include/current_sandbox.h +++ b/runtime/include/current_sandbox.h @@ -1,11 +1,13 @@ #pragma once +#include + #include "sandbox_types.h" /* current sandbox that is active.. */ -extern __thread struct sandbox *worker_thread_current_sandbox; +extern thread_local struct sandbox *worker_thread_current_sandbox; -extern __thread struct sandbox_context_cache local_sandbox_context_cache; +extern thread_local struct sandbox_context_cache local_sandbox_context_cache; void current_sandbox_start(void); diff --git a/runtime/include/generic_thread.h b/runtime/include/generic_thread.h index 9840660..5069d9f 100644 --- a/runtime/include/generic_thread.h +++ b/runtime/include/generic_thread.h @@ -1,10 +1,11 @@ #pragma once #include +#include -extern __thread uint64_t generic_thread_lock_duration; -extern __thread uint64_t generic_thread_lock_longest; -extern __thread uint64_t generic_thread_start_timestamp; +extern thread_local uint64_t generic_thread_lock_duration; +extern thread_local uint64_t generic_thread_lock_longest; +extern thread_local uint64_t generic_thread_start_timestamp; void generic_thread_dump_lock_overhead(void); void generic_thread_initialize(void); diff --git a/runtime/include/listener_thread.h b/runtime/include/listener_thread.h index 91a28dd..dca1894 100644 --- a/runtime/include/listener_thread.h +++ b/runtime/include/listener_thread.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "generic_thread.h" #include "module.h" @@ -9,9 +10,9 @@ extern pthread_t listener_thread_id; -void listener_thread_initialize(void); -__attribute__((noreturn)) void *listener_thread_main(void *dummy); -int listener_thread_register_module(struct module *mod); +void listener_thread_initialize(void); +noreturn void *listener_thread_main(void *dummy); +int listener_thread_register_module(struct module *mod); /** * Used to determine if running in the context of a listener thread diff --git a/runtime/include/software_interrupt.h b/runtime/include/software_interrupt.h index ec61185..684e340 100644 --- a/runtime/include/software_interrupt.h +++ b/runtime/include/software_interrupt.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "debuglog.h" #include "runtime.h" @@ -17,8 +18,8 @@ * Externs * ***********/ -extern _Atomic __thread volatile sig_atomic_t software_interrupt_deferred_sigalrm; -extern _Atomic volatile sig_atomic_t * software_interrupt_deferred_sigalrm_max; +extern _Atomic thread_local volatile sig_atomic_t software_interrupt_deferred_sigalrm; +extern _Atomic volatile sig_atomic_t * software_interrupt_deferred_sigalrm_max; /************************* * Public Static Inlines * diff --git a/runtime/include/types.h b/runtime/include/types.h index d49100b..a5c7c51 100644 --- a/runtime/include/types.h +++ b/runtime/include/types.h @@ -2,6 +2,7 @@ #include #include +#include #include "wasm_types.h" @@ -33,4 +34,4 @@ struct sandbox_context_cache { struct indirect_table_entry *module_indirect_table; }; -extern __thread struct sandbox_context_cache local_sandbox_context_cache; +extern thread_local struct sandbox_context_cache local_sandbox_context_cache; diff --git a/runtime/include/worker_thread.h b/runtime/include/worker_thread.h index 516acff..0ed7010 100644 --- a/runtime/include/worker_thread.h +++ b/runtime/include/worker_thread.h @@ -1,11 +1,13 @@ #pragma once +#include + #include "generic_thread.h" #include "runtime.h" -extern __thread struct arch_context worker_thread_base_context; -extern __thread int worker_thread_epoll_file_descriptor; -extern __thread int worker_thread_idx; +extern thread_local struct arch_context worker_thread_base_context; +extern thread_local int worker_thread_epoll_file_descriptor; +extern thread_local int worker_thread_idx; void *worker_thread_main(void *return_code); diff --git a/runtime/src/arch/aarch64/env.c b/runtime/src/arch/aarch64/env.c index 9d5ade1..8e9b23e 100644 --- a/runtime/src/arch/aarch64/env.c +++ b/runtime/src/arch/aarch64/env.c @@ -6,7 +6,7 @@ unsigned long long int __getcycles(void) { unsigned long long virtual_timer_value; - asm volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value)); + __asm__ volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value)); return virtual_timer_value; } diff --git a/runtime/src/arch_context.c b/runtime/src/arch_context.c index c20ff12..c359927 100644 --- a/runtime/src/arch_context.c +++ b/runtime/src/arch_context.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "panic.h" @@ -11,7 +12,7 @@ * then update the registers we should return to, then sigreturn (by returning from the handler). This returns to the * control flow restored from the mcontext */ -void __attribute__((noinline)) __attribute__((noreturn)) arch_context_restore_preempted(void) +noreturn void __attribute__((noinline)) arch_context_restore_preempted(void) { pthread_kill(pthread_self(), SIGUSR1); panic("Unexpectedly reached code after sending self SIGUSR1\n"); diff --git a/runtime/src/current_sandbox.c b/runtime/src/current_sandbox.c index 1b9a21c..a116c90 100644 --- a/runtime/src/current_sandbox.c +++ b/runtime/src/current_sandbox.c @@ -1,3 +1,5 @@ +#include + #include "current_sandbox.h" #include "sandbox_functions.h" #include "sandbox_receive_request.h" @@ -8,9 +10,9 @@ #include "scheduler.h" #include "software_interrupt.h" -__thread struct sandbox *worker_thread_current_sandbox = NULL; +thread_local struct sandbox *worker_thread_current_sandbox = NULL; -__thread struct sandbox_context_cache local_sandbox_context_cache = { +thread_local struct sandbox_context_cache local_sandbox_context_cache = { .memory = { .start = NULL, .size = 0, diff --git a/runtime/src/generic_thread.c b/runtime/src/generic_thread.c index 52153ea..af065b5 100644 --- a/runtime/src/generic_thread.c +++ b/runtime/src/generic_thread.c @@ -1,13 +1,14 @@ #include +#include #include "arch/getcycles.h" #include "debuglog.h" /* Implemented by listener and workers */ -__thread uint64_t generic_thread_lock_duration = 0; -__thread uint64_t generic_thread_lock_longest = 0; -__thread uint64_t generic_thread_start_timestamp = 0; +thread_local uint64_t generic_thread_lock_duration = 0; +thread_local uint64_t generic_thread_lock_longest = 0; +thread_local uint64_t generic_thread_start_timestamp = 0; void generic_thread_initialize() diff --git a/runtime/src/global_request_scheduler.c b/runtime/src/global_request_scheduler.c index e852832..f88e4e9 100644 --- a/runtime/src/global_request_scheduler.c +++ b/runtime/src/global_request_scheduler.c @@ -1,20 +1,22 @@ +#include + #include "global_request_scheduler.h" #include "panic.h" /* Default uninitialized implementations of the polymorphic interface */ -__attribute__((noreturn)) static struct sandbox_request * +noreturn static struct sandbox_request * uninitialized_add(void *arg) { panic("Global Request Scheduler Add was called before initialization\n"); } -__attribute__((noreturn)) static int +noreturn static int uninitialized_remove(struct sandbox_request **arg) { panic("Global Request Scheduler Remove was called before initialization\n"); } -__attribute__((noreturn)) static uint64_t +noreturn static uint64_t uninitialized_peek() { panic("Global Request Scheduler Peek was called before initialization\n"); diff --git a/runtime/src/listener_thread.c b/runtime/src/listener_thread.c index 8f56387..5491b1d 100644 --- a/runtime/src/listener_thread.c +++ b/runtime/src/listener_thread.c @@ -73,7 +73,7 @@ listener_thread_register_module(struct module *mod) * listener_thread_epoll_file_descriptor - the epoll file descriptor * */ -__attribute__((noreturn)) void * +noreturn void * listener_thread_main(void *dummy) { struct epoll_event epoll_events[RUNTIME_MAX_EPOLL_EVENTS]; diff --git a/runtime/src/local_completion_queue.c b/runtime/src/local_completion_queue.c index 31dd4b1..0dda8e3 100644 --- a/runtime/src/local_completion_queue.c +++ b/runtime/src/local_completion_queue.c @@ -1,7 +1,9 @@ +#include + #include "local_completion_queue.h" #include "sandbox_functions.h" -__thread static struct ps_list_head local_completion_queue; +thread_local static struct ps_list_head local_completion_queue; void diff --git a/runtime/src/local_runqueue.c b/runtime/src/local_runqueue.c index b87f66e..6e12f20 100644 --- a/runtime/src/local_runqueue.c +++ b/runtime/src/local_runqueue.c @@ -2,13 +2,14 @@ #ifdef LOG_LOCAL_RUNQUEUE #include #endif +#include #include "local_runqueue.h" static struct local_runqueue_config local_runqueue; #ifdef LOG_LOCAL_RUNQUEUE -__thread uint32_t local_runqueue_count = 0; +thread_local uint32_t local_runqueue_count = 0; #endif /* Initializes a concrete implementation of the sandbox request scheduler interface */ diff --git a/runtime/src/local_runqueue_list.c b/runtime/src/local_runqueue_list.c index 8fe9b9a..5c25ff2 100644 --- a/runtime/src/local_runqueue_list.c +++ b/runtime/src/local_runqueue_list.c @@ -1,3 +1,5 @@ +#include + #include "client_socket.h" #include "current_sandbox.h" #include "global_request_scheduler.h" @@ -5,7 +7,7 @@ #include "local_runqueue.h" #include "sandbox_functions.h" -__thread static struct ps_list_head local_runqueue_list; +thread_local static struct ps_list_head local_runqueue_list; bool local_runqueue_list_is_empty() diff --git a/runtime/src/local_runqueue_minheap.c b/runtime/src/local_runqueue_minheap.c index 7b3ae84..ad3803f 100644 --- a/runtime/src/local_runqueue_minheap.c +++ b/runtime/src/local_runqueue_minheap.c @@ -1,4 +1,5 @@ #include +#include #include "arch/context.h" #include "client_socket.h" @@ -12,7 +13,7 @@ #include "sandbox_functions.h" #include "runtime.h" -__thread static struct priority_queue *local_runqueue_minheap; +thread_local static struct priority_queue *local_runqueue_minheap; /** * Checks if the run queue is empty diff --git a/runtime/src/software_interrupt.c b/runtime/src/software_interrupt.c index 6b2d2a6..d996d34 100644 --- a/runtime/src/software_interrupt.c +++ b/runtime/src/software_interrupt.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -31,11 +32,11 @@ static uint64_t software_interrupt_interval_duration_in_cycles; * Thread Globals * *****************/ -__thread _Atomic static volatile sig_atomic_t software_interrupt_SIGALRM_kernel_count = 0; -__thread _Atomic static volatile sig_atomic_t software_interrupt_SIGALRM_thread_count = 0; -__thread _Atomic static volatile sig_atomic_t software_interrupt_SIGUSR_count = 0; -__thread _Atomic volatile sig_atomic_t software_interrupt_deferred_sigalrm = 0; -__thread _Atomic volatile sig_atomic_t software_interrupt_signal_depth = 0; +thread_local _Atomic static volatile sig_atomic_t software_interrupt_SIGALRM_kernel_count = 0; +thread_local _Atomic static volatile sig_atomic_t software_interrupt_SIGALRM_thread_count = 0; +thread_local _Atomic static volatile sig_atomic_t software_interrupt_SIGUSR_count = 0; +thread_local _Atomic volatile sig_atomic_t software_interrupt_deferred_sigalrm = 0; +thread_local _Atomic volatile sig_atomic_t software_interrupt_signal_depth = 0; _Atomic volatile sig_atomic_t *software_interrupt_deferred_sigalrm_max; diff --git a/runtime/src/worker_thread.c b/runtime/src/worker_thread.c index b7a3257..9f9ff1b 100644 --- a/runtime/src/worker_thread.c +++ b/runtime/src/worker_thread.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "current_sandbox.h" #include "local_completion_queue.h" @@ -21,12 +22,12 @@ **************************/ /* context of the runtime thread before running sandboxes or to resume its "main". */ -__thread struct arch_context worker_thread_base_context; +thread_local struct arch_context worker_thread_base_context; -__thread int worker_thread_epoll_file_descriptor; +thread_local int worker_thread_epoll_file_descriptor; /* Used to index into global arguments and deadlines arrays */ -__thread int worker_thread_idx; +thread_local int worker_thread_idx; /*********************** * Worker Thread Logic *