chore: de-dunder software_interrupt

master
Sean McBride 5 years ago
parent fefd80d6a9
commit a771b78a92

@ -9,16 +9,16 @@
* Externs * Externs
***************************************/ ***************************************/
extern __thread volatile sig_atomic_t software_interrupt__is_disabled; extern __thread volatile sig_atomic_t software_interrupt_is_disabled;
/*************************************** /***************************************
* Public Static Inlines * Public Static Inlines
***************************************/ ***************************************/
static inline void static inline void
software_interrupt__disable(void) software_interrupt_disable(void)
{ {
while (__sync_bool_compare_and_swap(&software_interrupt__is_disabled, 0, 1) == false) while (__sync_bool_compare_and_swap(&software_interrupt_is_disabled, 0, 1) == false)
; ;
} }
@ -27,18 +27,18 @@ software_interrupt__disable(void)
* Enables signals * Enables signals
*/ */
static inline void static inline void
software_interrupt__enable(void) software_interrupt_enable(void)
{ {
if (__sync_bool_compare_and_swap(&software_interrupt__is_disabled, 1, 0) == false) assert(0); if (__sync_bool_compare_and_swap(&software_interrupt_is_disabled, 1, 0) == false) assert(0);
} }
/** /**
* @returns boolean if signals are enabled * @returns boolean if signals are enabled
*/ */
static inline int static inline int
software_interrupt__is_enabled(void) software_interrupt_is_enabled(void)
{ {
return (software_interrupt__is_disabled == 0); return (software_interrupt_is_disabled == 0);
} }
/** /**
@ -47,7 +47,7 @@ software_interrupt__is_enabled(void)
* @return 0 on success. Exits program otherwise * @return 0 on success. Exits program otherwise
**/ **/
static inline int static inline int
software_interrupt__mask_signal(int signal) software_interrupt_mask_signal(int signal)
{ {
sigset_t set; sigset_t set;
int return_code; int return_code;
@ -72,7 +72,7 @@ software_interrupt__mask_signal(int signal)
* @return 0 on success. Exits program otherwise * @return 0 on success. Exits program otherwise
**/ **/
static inline int static inline int
software_interrupt__unmask_signal(int signal) software_interrupt_unmask_signal(int signal)
{ {
sigset_t set; sigset_t set;
int return_code; int return_code;
@ -95,8 +95,8 @@ software_interrupt__unmask_signal(int signal)
* Exports from module.c * Exports from module.c
***************************************/ ***************************************/
void software_interrupt__initialize(void); void software_interrupt_initialize(void);
void software_interrupt__arm_timer(void); void software_interrupt_arm_timer(void);
void software_interrupt__disarm_timer(void); void software_interrupt_disarm_timer(void);
#endif /* SFRT_SOFTWARE_INTERRUPT_H */ #endif /* SFRT_SOFTWARE_INTERRUPT_H */

@ -53,8 +53,8 @@ runtime_initialize(void)
deque_init_sandbox(runtime_global_deque, RUNTIME__MAX_SANDBOX_REQUEST_COUNT); deque_init_sandbox(runtime_global_deque, RUNTIME__MAX_SANDBOX_REQUEST_COUNT);
// Mask Signals // Mask Signals
software_interrupt__mask_signal(SIGUSR1); software_interrupt_mask_signal(SIGUSR1);
software_interrupt__mask_signal(SIGALRM); software_interrupt_mask_signal(SIGALRM);
// Initialize http_parser_settings global // Initialize http_parser_settings global
http_parser_settings_initialize(&runtime_http_parser_settings); http_parser_settings_initialize(&runtime_http_parser_settings);
@ -137,8 +137,8 @@ listener_thread_initialize(void)
ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cs); ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cs);
assert(ret == 0); assert(ret == 0);
software_interrupt__initialize(); software_interrupt_initialize();
software_interrupt__arm_timer(); software_interrupt_arm_timer();
} }
/*************************** /***************************
@ -179,7 +179,7 @@ static inline void
worker_thread__switch_to_sandbox(struct sandbox *next_sandbox) worker_thread__switch_to_sandbox(struct sandbox *next_sandbox)
{ {
arch_context_t *next_register_context = next_sandbox == NULL ? NULL : &next_sandbox->ctxt; arch_context_t *next_register_context = next_sandbox == NULL ? NULL : &next_sandbox->ctxt;
software_interrupt__disable(); software_interrupt_disable();
struct sandbox *current_sandbox = current_sandbox_get(); struct sandbox *current_sandbox = current_sandbox_get();
arch_context_t *current_register_context = current_sandbox == NULL ? NULL : &current_sandbox->ctxt; arch_context_t *current_register_context = current_sandbox == NULL ? NULL : &current_sandbox->ctxt;
current_sandbox_set(next_sandbox); current_sandbox_set(next_sandbox);
@ -188,7 +188,7 @@ worker_thread__switch_to_sandbox(struct sandbox *next_sandbox)
worker_thread__push_sandbox_to_completion_queue(current_sandbox); worker_thread__push_sandbox_to_completion_queue(current_sandbox);
worker_thread__next_context = next_register_context; worker_thread__next_context = next_register_context;
arch_context_switch(current_register_context, next_register_context); arch_context_switch(current_register_context, next_register_context);
software_interrupt__enable(); software_interrupt_enable();
} }
/** /**
@ -198,7 +198,7 @@ worker_thread__switch_to_sandbox(struct sandbox *next_sandbox)
void void
worker_thread__wakeup_sandbox(sandbox_t *sandbox) worker_thread__wakeup_sandbox(sandbox_t *sandbox)
{ {
software_interrupt__disable(); software_interrupt_disable();
debuglog("[%p: %s]\n", sandbox, sandbox->module->name); debuglog("[%p: %s]\n", sandbox, sandbox->module->name);
if (sandbox->state != BLOCKED) goto done; if (sandbox->state != BLOCKED) goto done;
assert(sandbox->state == BLOCKED); assert(sandbox->state == BLOCKED);
@ -206,7 +206,7 @@ worker_thread__wakeup_sandbox(sandbox_t *sandbox)
sandbox->state = RUNNABLE; sandbox->state = RUNNABLE;
ps_list_head_append_d(&worker_thread__run_queue, sandbox); ps_list_head_append_d(&worker_thread__run_queue, sandbox);
done: done:
software_interrupt__enable(); software_interrupt_enable();
} }
@ -218,14 +218,14 @@ void
worker_thread__block_current_sandbox(void) worker_thread__block_current_sandbox(void)
{ {
assert(worker_thread__is_in_callback == 0); assert(worker_thread__is_in_callback == 0);
software_interrupt__disable(); software_interrupt_disable();
struct sandbox *current_sandbox = current_sandbox_get(); struct sandbox *current_sandbox = current_sandbox_get();
ps_list_rem_d(current_sandbox); ps_list_rem_d(current_sandbox);
current_sandbox->state = BLOCKED; current_sandbox->state = BLOCKED;
struct sandbox *next_sandbox = worker_thread__get_next_sandbox(0); struct sandbox *next_sandbox = worker_thread__get_next_sandbox(0);
debuglog("[%p: %next_sandbox, %p: %next_sandbox]\n", current_sandbox, current_sandbox->module->name, debuglog("[%p: %next_sandbox, %p: %next_sandbox]\n", current_sandbox, current_sandbox->module->name,
next_sandbox, next_sandbox ? next_sandbox->module->name : ""); next_sandbox, next_sandbox ? next_sandbox->module->name : "");
software_interrupt__enable(); software_interrupt_enable();
worker_thread__switch_to_sandbox(next_sandbox); worker_thread__switch_to_sandbox(next_sandbox);
} }
@ -406,9 +406,9 @@ worker_thread__execute_runtime_maintenance_and_get_next_sandbox(void)
if (!worker_thread__is_in_callback) worker_thread__execute_libuv_event_loop(); if (!worker_thread__is_in_callback) worker_thread__execute_libuv_event_loop();
// Get and return the sandbox at the head of the thread local runqueue // Get and return the sandbox at the head of the thread local runqueue
software_interrupt__disable(); software_interrupt_disable();
struct sandbox *sandbox = worker_thread__get_next_sandbox(0); struct sandbox *sandbox = worker_thread__get_next_sandbox(0);
software_interrupt__enable(); software_interrupt_enable();
assert(sandbox == NULL || sandbox->state == RUNNABLE); assert(sandbox == NULL || sandbox->state == RUNNABLE);
return sandbox; return sandbox;
} }
@ -425,11 +425,11 @@ worker_thread__main(void *return_code)
ps_list_head_init(&worker_thread__run_queue); ps_list_head_init(&worker_thread__run_queue);
ps_list_head_init(&worker_thread__completion_queue); ps_list_head_init(&worker_thread__completion_queue);
software_interrupt__is_disabled = 0; software_interrupt_is_disabled = 0;
worker_thread__next_context = NULL; worker_thread__next_context = NULL;
#ifndef PREEMPT_DISABLE #ifndef PREEMPT_DISABLE
software_interrupt__unmask_signal(SIGALRM); software_interrupt_unmask_signal(SIGALRM);
software_interrupt__unmask_signal(SIGUSR1); software_interrupt_unmask_signal(SIGUSR1);
#endif #endif
uv_loop_init(&worker_thread__uvio_handle); uv_loop_init(&worker_thread__uvio_handle);
worker_thread__is_in_callback = 0; worker_thread__is_in_callback = 0;
@ -457,13 +457,13 @@ worker_thread__exit_current_sandbox(void)
{ {
struct sandbox *current_sandbox = current_sandbox_get(); struct sandbox *current_sandbox = current_sandbox_get();
assert(current_sandbox); assert(current_sandbox);
software_interrupt__disable(); software_interrupt_disable();
worker_thread__pop_sandbox_from_run_queue(current_sandbox); worker_thread__pop_sandbox_from_run_queue(current_sandbox);
current_sandbox->state = RETURNED; current_sandbox->state = RETURNED;
struct sandbox *next_sandbox = worker_thread__get_next_sandbox(0); struct sandbox *next_sandbox = worker_thread__get_next_sandbox(0);
assert(next_sandbox != current_sandbox); assert(next_sandbox != current_sandbox);
software_interrupt__enable(); software_interrupt_enable();
// free resources from "main function execution", as stack still in use. // free resources from "main function execution", as stack still in use.
// unmap linear memory only! // unmap linear memory only!
munmap(current_sandbox->linear_memory_start, SBOX_MAX_MEM + PAGE_SIZE); munmap(current_sandbox->linear_memory_start, SBOX_MAX_MEM + PAGE_SIZE);

@ -181,10 +181,10 @@ current_sandbox_main(void)
// FIXME: is this right? this is the first time this sandbox is running.. so it wont // FIXME: is this right? this is the first time this sandbox is running.. so it wont
// return to worker_thread__switch_to_sandbox() api.. // return to worker_thread__switch_to_sandbox() api..
// we'd potentially do what we'd in worker_thread__switch_to_sandbox() api here for cleanup.. // we'd potentially do what we'd in worker_thread__switch_to_sandbox() api here for cleanup..
if (!software_interrupt__is_enabled()) { if (!software_interrupt_is_enabled()) {
arch_context_init(&current_sandbox->ctxt, 0, 0); arch_context_init(&current_sandbox->ctxt, 0, 0);
worker_thread__next_context = NULL; worker_thread__next_context = NULL;
software_interrupt__enable(); software_interrupt_enable();
} }
struct module *current_module = sandbox_get_module(current_sandbox); struct module *current_module = sandbox_get_module(current_sandbox);
int argument_count = module_get_argument_count(current_module); int argument_count = module_get_argument_count(current_module);

@ -18,15 +18,15 @@
* Process Globals * Process Globals
***************************************/ ***************************************/
static const int software_interrupt__supported_signals[] = { SIGALRM, SIGUSR1 }; static const int software_interrupt_supported_signals[] = { SIGALRM, SIGUSR1 };
/*************************************** /***************************************
* Thread Globals * Thread Globals
***************************************/ ***************************************/
__thread static volatile sig_atomic_t software_interrupt__SIGALRM_count = 0; __thread static volatile sig_atomic_t software_interrupt_SIGALRM_count = 0;
__thread static volatile sig_atomic_t software_interrupt__SIGUSR_count = 0; __thread static volatile sig_atomic_t software_interrupt_SIGUSR_count = 0;
__thread volatile sig_atomic_t software_interrupt__is_disabled = 0; __thread volatile sig_atomic_t software_interrupt_is_disabled = 0;
/*************************************** /***************************************
* Externs * Externs
@ -38,8 +38,8 @@ extern pthread_t runtime_worker_threads[];
* Private Static Inlines * Private Static Inlines
***************************************/ ***************************************/
static inline void software_interrupt__handle_signals(int signal_type, siginfo_t *signal_info, void *user_context_raw); static inline void software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void *user_context_raw);
static inline void software_interrupt__schedule_alarm(void *user_context_raw); static inline void software_interrupt_schedule_alarm(void *user_context_raw);
/** /**
* The handler function for Software Interrupts (signals) * The handler function for Software Interrupts (signals)
@ -50,7 +50,7 @@ static inline void software_interrupt__schedule_alarm(void *user_context_raw);
* @param user_context_raw void* to a user_context struct * @param user_context_raw void* to a user_context struct
**/ **/
static inline void static inline void
software_interrupt__handle_signals(int signal_type, siginfo_t *signal_info, void *user_context_raw) software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void *user_context_raw)
{ {
#ifdef PREEMPT_DISABLE #ifdef PREEMPT_DISABLE
assert(0); assert(0);
@ -75,33 +75,33 @@ software_interrupt__handle_signals(int signal_type, siginfo_t *signal_info, void
} else { } else {
assert(signal_info->si_code == SI_TKILL); assert(signal_info->si_code == SI_TKILL);
} }
// debuglog("alrm:%d\n", software_interrupt__SIGALRM_count); // debuglog("alrm:%d\n", software_interrupt_SIGALRM_count);
software_interrupt__SIGALRM_count++; software_interrupt_SIGALRM_count++;
// software_interrupt__supported_signals per-core.. // software_interrupt_supported_signals per-core..
if (curr && curr->state == RETURNED) return; if (curr && curr->state == RETURNED) return;
if (worker_thread__next_context) return; if (worker_thread__next_context) return;
if (!software_interrupt__is_enabled()) return; if (!software_interrupt_is_enabled()) return;
software_interrupt__schedule_alarm(user_context_raw); software_interrupt_schedule_alarm(user_context_raw);
break; break;
} }
case SIGUSR1: { case SIGUSR1: {
// make sure sigalrm doesn't mess this up if nested.. // make sure sigalrm doesn't mess this up if nested..
assert(!software_interrupt__is_enabled()); assert(!software_interrupt_is_enabled());
/* we set current before calling pthread_kill! */ /* we set current before calling pthread_kill! */
assert(worker_thread__next_context && (&curr->ctxt == worker_thread__next_context)); assert(worker_thread__next_context && (&curr->ctxt == worker_thread__next_context));
assert(signal_info->si_code == SI_TKILL); assert(signal_info->si_code == SI_TKILL);
// debuglog("usr1:%d\n", software_interrupt__SIGUSR_count); // debuglog("usr1:%d\n", software_interrupt_SIGUSR_count);
software_interrupt__SIGUSR_count++; software_interrupt_SIGUSR_count++;
// do not save current sandbox.. it is in co-operative switch.. // do not save current sandbox.. it is in co-operative switch..
// pick the next from "worker_thread__next_context".. // pick the next from "worker_thread__next_context"..
// assert its "sp" to be zero in regs.. // assert its "sp" to be zero in regs..
// memcpy from next context.. // memcpy from next context..
arch_mcontext_restore(&user_context->uc_mcontext, &curr->ctxt); arch_mcontext_restore(&user_context->uc_mcontext, &curr->ctxt);
worker_thread__next_context = NULL; worker_thread__next_context = NULL;
software_interrupt__enable(); software_interrupt_enable();
break; break;
} }
default: default:
@ -115,9 +115,9 @@ software_interrupt__handle_signals(int signal_type, siginfo_t *signal_info, void
* @param user_context_raw void* to a user_context struct * @param user_context_raw void* to a user_context struct
**/ **/
static inline void static inline void
software_interrupt__schedule_alarm(void *user_context_raw) software_interrupt_schedule_alarm(void *user_context_raw)
{ {
software_interrupt__disable(); // no nesting! software_interrupt_disable(); // no nesting!
struct sandbox *curr = current_sandbox_get(); struct sandbox *curr = current_sandbox_get();
ucontext_t * user_context = (ucontext_t *)user_context_raw; ucontext_t * user_context = (ucontext_t *)user_context_raw;
@ -142,7 +142,7 @@ software_interrupt__schedule_alarm(void *user_context_raw)
// worker_thread__next_context = NULL; // worker_thread__next_context = NULL;
done: done:
software_interrupt__enable(); software_interrupt_enable();
skip: skip:
return; return;
} }
@ -155,7 +155,7 @@ skip:
* Arms the Interval Timer to start in 10ms and then trigger a SIGALRM every 5ms * Arms the Interval Timer to start in 10ms and then trigger a SIGALRM every 5ms
**/ **/
void void
software_interrupt__arm_timer(void) software_interrupt_arm_timer(void)
{ {
#ifndef PREEMPT_DISABLE #ifndef PREEMPT_DISABLE
struct itimerval interval_timer; struct itimerval interval_timer;
@ -176,7 +176,7 @@ software_interrupt__arm_timer(void)
* Disarm the Interval Timer * Disarm the Interval Timer
**/ **/
void void
software_interrupt__disarm_timer(void) software_interrupt_disarm_timer(void)
{ {
struct itimerval interval_timer; struct itimerval interval_timer;
@ -197,17 +197,17 @@ software_interrupt__disarm_timer(void)
* Register sonftint_handler to execute on SIGALRM and SIGUSR1 * Register sonftint_handler to execute on SIGALRM and SIGUSR1
**/ **/
void void
software_interrupt__initialize(void) software_interrupt_initialize(void)
{ {
struct sigaction signal_action; struct sigaction signal_action;
memset(&signal_action, 0, sizeof(struct sigaction)); memset(&signal_action, 0, sizeof(struct sigaction));
signal_action.sa_sigaction = software_interrupt__handle_signals; signal_action.sa_sigaction = software_interrupt_handle_signals;
signal_action.sa_flags = SA_SIGINFO | SA_RESTART; signal_action.sa_flags = SA_SIGINFO | SA_RESTART;
for (int i = 0; for (int i = 0;
i < (sizeof(software_interrupt__supported_signals) / sizeof(software_interrupt__supported_signals[0])); i < (sizeof(software_interrupt_supported_signals) / sizeof(software_interrupt_supported_signals[0]));
i++) { i++) {
int return_code = sigaction(software_interrupt__supported_signals[i], &signal_action, NULL); int return_code = sigaction(software_interrupt_supported_signals[i], &signal_action, NULL);
if (return_code) { if (return_code) {
perror("sigaction"); perror("sigaction");
exit(1); exit(1);

Loading…
Cancel
Save