refactor: more semantic names

master
Sean McBride 3 years ago
parent 7ccf845389
commit 7e85bb4c59

@ -36,23 +36,23 @@
* Writes sandbox_context to active_context
* active_context was saved to the stack by a signal handler
* @param active_context - the context of the current worker thread
* @param sandbox_context - the context that we want to restore
* @param context_to_restore - the context that we want to restore
*/
static inline void
arch_mcontext_restore(mcontext_t *active_context, struct arch_context *sandbox_context)
arch_context_restore_slow(mcontext_t *active_context, struct arch_context *context_to_restore)
{
assert(active_context != NULL);
assert(sandbox_context != NULL);
assert(context_to_restore != NULL);
/* Assumption: Base Context is only ever used by arch_context_switch */
assert(sandbox_context != &worker_thread_base_context);
assert(context_to_restore != &worker_thread_base_context);
/* Transitioning from Slow -> Running */
assert(sandbox_context->variant == ARCH_CONTEXT_VARIANT_SLOW);
sandbox_context->variant = ARCH_CONTEXT_VARIANT_RUNNING;
assert(context_to_restore->variant == ARCH_CONTEXT_VARIANT_SLOW);
context_to_restore->variant = ARCH_CONTEXT_VARIANT_RUNNING;
/* Restore mcontext */
memcpy(active_context, &sandbox_context->mctx, sizeof(mcontext_t));
memcpy(active_context, &context_to_restore->mctx, sizeof(mcontext_t));
}
@ -62,7 +62,7 @@ arch_mcontext_restore(mcontext_t *active_context, struct arch_context *sandbox_c
* @param active_context - source
*/
static inline void
arch_mcontext_save(struct arch_context *sandbox_context, const mcontext_t *active_context)
arch_context_save_slow(struct arch_context *sandbox_context, const mcontext_t *active_context)
{
assert(sandbox_context != NULL);
assert(active_context != NULL);

@ -52,7 +52,7 @@ arch_context_init(struct arch_context *actx, reg_t ip, reg_t sp)
* @param sandbox_context - the context that we want to restore
*/
static inline void
arch_context_restore_new(mcontext_t *active_context, struct arch_context *sandbox_context)
arch_context_restore_fast(mcontext_t *active_context, struct arch_context *sandbox_context)
{
assert(active_context != NULL);
assert(sandbox_context != NULL);

@ -144,12 +144,13 @@ scheduler_runqueue_initialize()
/**
* Called by the SIGALRM handler after a quantum
* Assumes the caller validates that there is something to preempt
* @param user_context - The context of our user-level Worker thread
* @param interrupted_context - The context of our user-level Worker thread
* @returns the sandbox that the scheduler chose to run
*/
static inline void
scheduler_preempt(ucontext_t *user_context)
static inline struct sandbox *
scheduler_preempt(ucontext_t *interrupted_context)
{
assert(user_context != NULL);
assert(interrupted_context != NULL);
/* Process epoll to make sure that all runnable jobs are considered for execution */
worker_thread_execute_epoll_loop();
@ -163,7 +164,7 @@ scheduler_preempt(ucontext_t *user_context)
assert(next != NULL);
/* If current equals next, no switch is necessary, so resume execution */
if (current == next) return;
if (current == next) return current;
#ifdef LOG_PREEMPTION
debuglog("Preempting sandbox %lu to run sandbox %lu\n", current->id, next->id);
@ -173,7 +174,7 @@ scheduler_preempt(ucontext_t *user_context)
/* How do I switch back to "user running" when this is resumed? */
sandbox_set_as_preempted(current, SANDBOX_RUNNING_KERNEL);
arch_mcontext_save(&current->ctxt, &user_context->uc_mcontext);
arch_context_save_slow(&current->ctxt, &interrupted_context->uc_mcontext);
/* Update current_sandbox to the next sandbox */
// assert(next->state == SANDBOX_RUNNABLE);
@ -182,7 +183,7 @@ scheduler_preempt(ucontext_t *user_context)
case ARCH_CONTEXT_VARIANT_FAST: {
assert(next->state == SANDBOX_RUNNABLE);
sandbox_set_as_running_kernel(next, SANDBOX_RUNNABLE);
arch_context_restore_new(&user_context->uc_mcontext, &next->ctxt);
arch_context_restore_fast(&interrupted_context->uc_mcontext, &next->ctxt);
break;
}
case ARCH_CONTEXT_VARIANT_SLOW: {
@ -203,7 +204,7 @@ scheduler_preempt(ucontext_t *user_context)
*/
assert(scheduler != SCHEDULER_EDF);
assert(next->state == SANDBOX_PREEMPTED);
arch_mcontext_restore(&user_context->uc_mcontext, &next->ctxt);
arch_context_restore_slow(&interrupted_context->uc_mcontext, &next->ctxt);
sandbox_set_as_running_kernel(next, SANDBOX_PREEMPTED);
break;
}
@ -212,6 +213,8 @@ scheduler_preempt(ucontext_t *user_context)
arch_context_variant_print(next->ctxt.variant));
}
}
return next;
}
static inline char *

@ -127,10 +127,10 @@ software_interrupt_validate_worker()
* SIGUSR1 restores a preempted sandbox
* @param signal_type
* @param signal_info data structure containing signal info
* @param user_context_raw void* to a user_context struct
* @param interrupted_context_raw void* to a interrupted_context struct
*/
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 *interrupted_context_raw)
{
/* Only workers should receive signals */
assert(!listener_thread_is_running());
@ -143,8 +143,8 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void
assert(software_interrupt_signal_depth == 0);
atomic_fetch_add(&software_interrupt_signal_depth, 1);
ucontext_t * user_context = (ucontext_t *)user_context_raw;
struct sandbox *current_sandbox = current_sandbox_get();
ucontext_t * interrupted_context = (ucontext_t *)interrupted_context_raw;
struct sandbox *current_sandbox = current_sandbox_get();
switch (signal_type) {
case SIGALRM: {
@ -161,8 +161,7 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void
if (preemptable) {
atomic_store(&software_interrupt_deferred_sigalrm, 0);
scheduler_preempt(user_context);
current_sandbox = current_sandbox_get();
current_sandbox = scheduler_preempt(interrupted_context);
} else {
atomic_fetch_add(&software_interrupt_deferred_sigalrm, 1);
}
@ -178,7 +177,9 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void
debuglog("Restoring sandbox: %lu, Stack %llu\n", current_sandbox->id,
current_sandbox->ctxt.mctx.gregs[REG_RSP]);
#endif
arch_mcontext_restore(&user_context->uc_mcontext, &current_sandbox->ctxt);
/* Overwrites the interrupted context with the context of the worker thread's current sandbox */
/* It is the responsibility of the caller to invoke current_sandbox_set before triggering the SIGUSR1 */
arch_context_restore_slow(&interrupted_context->uc_mcontext, &current_sandbox->ctxt);
goto done;
}
default: {

Loading…
Cancel
Save