From 3aba285862cd14f04d0c28b3b3a91b9500c6628b Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Wed, 22 Jul 2020 16:24:52 -0400 Subject: [PATCH] refactor: namespace to arch_context_variant --- runtime/include/arch/aarch64/context.h | 14 +++++++------- runtime/include/arch/common.h | 26 +++++++++++++------------- runtime/include/arch/context.h | 9 +++++---- runtime/include/arch/x86_64/context.h | 22 +++++++++++----------- runtime/src/software_interrupt.c | 2 +- runtime/src/worker_thread.c | 8 ++++---- 6 files changed, 41 insertions(+), 40 deletions(-) diff --git a/runtime/include/arch/aarch64/context.h b/runtime/include/arch/aarch64/context.h index ba5f17b..839483a 100644 --- a/runtime/include/arch/aarch64/context.h +++ b/runtime/include/arch/aarch64/context.h @@ -18,9 +18,9 @@ arch_context_init(struct arch_context *actx, reg_t ip, reg_t sp) assert(actx != NULL); if (ip == 0 && sp == 0) { - actx->variant = arch_context_unused; + actx->variant = arch_context_variant_unused; } else { - actx->variant = arch_context_fast; + actx->variant = arch_context_variant_fast; } actx->regs[ureg_rsp] = sp; @@ -47,8 +47,8 @@ arch_context_restore(mcontext_t *active_context, struct arch_context *sandbox_co assert(sandbox_context->pc); /* Transitioning from Fast -> Running */ - assert(sandbox_context->variant == arch_context_fast); - sandbox_context->variant = arch_context_running; + assert(sandbox_context->variant == arch_context_variant_fast); + sandbox_context->variant = arch_context_variant_running; active_context->sp = sandbox_context->regs[ureg_rsp]; active_context->pc = sandbox_context->regs[ureg_rip] + ARCH_SIG_JMP_OFF; @@ -79,13 +79,13 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) if (b == NULL) b = &worker_thread_base_context; /* A Transition {Unused, Running} -> Fast */ - assert(a->variant == arch_context_unused || a->variant == arch_context_running); + assert(a->variant == arch_context_variant_unused || a->variant == arch_context_variant_running); /* B Transition {Fast, Slow} -> Running */ - assert(b->variant == arch_context_fast || b->variant == arch_context_slow); + assert(b->variant == arch_context_variant_fast || b->variant == arch_context_variant_slow); /* Assumption: Fastpath state is well formed */ - if (b->variant == arch_context_fast) { + if (b->variant == arch_context_variant_fast) { assert(b->regs[ureg_rip] != 0); assert(b->regs[ureg_rsp] != 0); } diff --git a/runtime/include/arch/common.h b/runtime/include/arch/common.h index 124efa5..3c349d0 100644 --- a/runtime/include/arch/common.h +++ b/runtime/include/arch/common.h @@ -30,23 +30,23 @@ typedef enum /* The enum is compared directly in assembly, so maintain integral values! */ typedef enum { - arch_context_unused = 0, /* Has not have saved a context */ - arch_context_fast = 1, /* Saved a fastpath context */ - arch_context_slow = 2, /* Saved a slowpath context */ - arch_context_running = 3 /* Context is executing and content is out of date */ -} arch_context_t; + arch_context_variant_unused = 0, /* Has not have saved a context */ + arch_context_variant_fast = 1, /* Saved a fastpath context */ + arch_context_variant_slow = 2, /* Saved a slowpath context */ + arch_context_variant_running = 3 /* Context is executing and content is out of date */ +} arch_context_variant_t; static inline char * -arch_context_print(arch_context_t context) +arch_context_variant_print(arch_context_variant_t context) { switch (context) { - case arch_context_unused: + case arch_context_variant_unused: return "Unused"; - case arch_context_fast: + case arch_context_variant_fast: return "Fast"; - case arch_context_slow: + case arch_context_variant_slow: return "Slow"; - case arch_context_running: + case arch_context_variant_running: return "Running"; default: panic("Encountered unexpected arch_context variant\n"); @@ -55,9 +55,9 @@ arch_context_print(arch_context_t context) struct arch_context { - arch_context_t variant; - reg_t regs[ureg_count]; - mcontext_t mctx; + arch_context_variant_t variant; + reg_t regs[ureg_count]; + mcontext_t mctx; }; /* diff --git a/runtime/include/arch/context.h b/runtime/include/arch/context.h index 0d1a03f..7a4dbf5 100644 --- a/runtime/include/arch/context.h +++ b/runtime/include/arch/context.h @@ -48,8 +48,8 @@ arch_mcontext_restore(mcontext_t *active_context, struct arch_context *sandbox_c assert(sandbox_context != &worker_thread_base_context); /* Transitioning from Slow -> Running */ - assert(sandbox_context->variant == arch_context_slow); - sandbox_context->variant = arch_context_running; + assert(sandbox_context->variant == arch_context_variant_slow); + sandbox_context->variant = arch_context_variant_running; /* Restore mcontext */ memcpy(active_context, &sandbox_context->mctx, sizeof(mcontext_t)); @@ -74,8 +74,9 @@ arch_mcontext_save(struct arch_context *sandbox_context, const mcontext_t *activ assert(sandbox_context != &worker_thread_base_context); /* Transitioning from {Unused, Running} -> Slow */ - assert(sandbox_context->variant == arch_context_unused || sandbox_context->variant == arch_context_running); - sandbox_context->variant = arch_context_slow; + assert(sandbox_context->variant == arch_context_variant_unused + || sandbox_context->variant == arch_context_variant_running); + sandbox_context->variant = arch_context_variant_slow; /* Copy mcontext */ memcpy(&sandbox_context->mctx, active_context, sizeof(mcontext_t)); diff --git a/runtime/include/arch/x86_64/context.h b/runtime/include/arch/x86_64/context.h index 2c52b51..8e1eec0 100644 --- a/runtime/include/arch/x86_64/context.h +++ b/runtime/include/arch/x86_64/context.h @@ -16,9 +16,9 @@ static void __attribute__((noinline)) arch_context_init(struct arch_context *act assert(actx != NULL); if (ip == 0 && sp == 0) { - actx->variant = arch_context_unused; + actx->variant = arch_context_variant_unused; } else { - actx->variant = arch_context_fast; + actx->variant = arch_context_variant_fast; } if (sp) { @@ -64,8 +64,8 @@ arch_context_restore(mcontext_t *active_context, struct arch_context *sandbox_co assert(sandbox_context->regs[ureg_rip]); /* Transitioning from Fast -> Running */ - assert(sandbox_context->variant == arch_context_fast); - sandbox_context->variant = arch_context_running; + assert(sandbox_context->variant == arch_context_variant_fast); + sandbox_context->variant = arch_context_variant_running; active_context->gregs[REG_RSP] = sandbox_context->regs[ureg_rsp]; active_context->gregs[REG_RIP] = sandbox_context->regs[ureg_rip] + ARCH_SIG_JMP_OFF; @@ -96,13 +96,13 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) if (b == NULL) b = &worker_thread_base_context; /* A Transition {Unused, Running} -> Fast */ - assert(a->variant == arch_context_unused || a->variant == arch_context_running); + assert(a->variant == arch_context_variant_unused || a->variant == arch_context_variant_running); /* B Transition {Fast, Slow} -> Running */ - assert(b->variant == arch_context_fast || b->variant == arch_context_slow); + assert(b->variant == arch_context_variant_fast || b->variant == arch_context_variant_slow); /* Assumption: Fastpath state is well formed */ - if (b->variant == arch_context_fast) { + if (b->variant == arch_context_variant_fast) { assert(b->regs[ureg_rip] != 0); assert(b->regs[ureg_rsp] != 0); } @@ -122,7 +122,7 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) */ "movq $2f, 8(%%rax)\n\t" /* Write the address of label 2 to context a's IP. */ "movq %%rsp, (%%rax)\n\t" /* a_registers[0] (stack_pointer) = stack_pointer */ - "movq $1, (%%rcx)\n\t" /* a->variant = arch_context_fast; */ + "movq $1, (%%rcx)\n\t" /* a->variant = arch_context_variant_fast; */ /* * Execute a fastpath or slowpath context switch based on context B's variant @@ -130,7 +130,7 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) * If slow (mcontext-based), jump to label 1 to restore via a signal handler * Otherwise, fall through and execute fast path. */ - "cmpq $2, (%%rdx)\n\t" /* if (b->variant == arch_context_slow); */ + "cmpq $2, (%%rdx)\n\t" /* if (b->variant == arch_context_variant_slow); */ "je 1f\n\t" /* goto 1; restore the existing sandbox using mcontext */ /* @@ -147,7 +147,7 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) /* * Slow Path - * If the variant is arch_context_slow, that means the sandbox was preempted and we need to + * If the variant is arch_context_variant_slow, that means the sandbox was preempted and we need to * fallback to a full mcontext-based context switch. We do this by invoking * arch_context_restore_preempted, which fires a SIGUSR1 signal. The SIGUSR1 signal handler * executes the mcontext-based context switch. @@ -163,7 +163,7 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) * The sandbox either resumes at label 2 or 3 depending on if an offset of 8 is used. */ "2:\n\t" - "movq $3, (%%rdx)\n\t" /* b->variant = arch_context_running; */ + "movq $3, (%%rdx)\n\t" /* b->variant = arch_context_variant_running; */ ".align 8\n\t" /* This label is used in conjunction with a static offset */ diff --git a/runtime/src/software_interrupt.c b/runtime/src/software_interrupt.c index a8abf80..93d60f5 100644 --- a/runtime/src/software_interrupt.c +++ b/runtime/src/software_interrupt.c @@ -121,7 +121,7 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void assert(current_sandbox); /* Extra checks to verify that preemption properly set context state */ - assert(current_sandbox->ctxt.variant == arch_context_slow); + assert(current_sandbox->ctxt.variant == arch_context_variant_slow); software_interrupt_SIGUSR_count++; debuglog("usr1:%d\n", software_interrupt_SIGUSR_count); diff --git a/runtime/src/worker_thread.c b/runtime/src/worker_thread.c index e61ee5b..3fd445e 100644 --- a/runtime/src/worker_thread.c +++ b/runtime/src/worker_thread.c @@ -55,8 +55,8 @@ worker_thread_switch_to_sandbox(struct sandbox *next_sandbox) /* Switching from "Base Context" */ debuglog("Base Context (%s) > Sandbox %lu (%s)\n", - arch_context_print(worker_thread_base_context.variant), - next_sandbox->request_arrival_timestamp, arch_context_print(next_context->variant)); + arch_context_variant_print(worker_thread_base_context.variant), + next_sandbox->request_arrival_timestamp, arch_context_variant_print(next_context->variant)); current_sandbox_set(next_sandbox); @@ -97,8 +97,8 @@ worker_thread_switch_to_base_context() current_sandbox_set(NULL); debuglog("Sandbox %lu (%s) > Base Context (%s)\n", current_sandbox->request_arrival_timestamp, - arch_context_print(current_sandbox->ctxt.variant), - arch_context_print(worker_thread_base_context.variant)); + arch_context_variant_print(current_sandbox->ctxt.variant), + arch_context_variant_print(worker_thread_base_context.variant)); arch_context_switch(¤t_sandbox->ctxt, &worker_thread_base_context);