solve partial builing and running issues for ARM machines

solve_arm_building_and_running_issue_part1
xiaosuGW 3 years ago
parent 44d04f213a
commit fe88b14c6f

@ -4,7 +4,6 @@
#include <assert.h> #include <assert.h>
#include "arch/common.h" #include "arch/common.h"
#include "current_sandbox.h"
#define ARCH_SIG_JMP_OFF 0x100 /* Based on code generated! */ #define ARCH_SIG_JMP_OFF 0x100 /* Based on code generated! */
@ -46,25 +45,22 @@ arch_context_switch(struct arch_context *a, struct arch_context *b)
/* /*
* Assumption: In the case of a slow context switch, the caller * Assumption: In the case of a slow context switch, the caller
* set current_sandbox to the sandbox containing the target context * set current_sandbox to the sandbox containing the target context
* Temporally comment because it will cause compilation error
*/ */
if (b->variant == ARCH_CONTEXT_VARIANT_SLOW) { /*if (b->variant == ARCH_CONTEXT_VARIANT_SLOW) {
struct sandbox *current = current_sandbox_get(); struct sandbox *current = current_sandbox_get();
assert(current != NULL && b == &current->ctxt); assert(current != NULL && b == &current->ctxt);
} }*/
#endif #endif
/* if both a and b are NULL, there is no state change */ /* if both a and b are NULL, there is no state change */
assert(a != NULL || b != NULL); assert(a != NULL && b != NULL);
/* Assumption: The caller does not switch to itself */ /* Assumption: The caller does not switch to itself */
assert(a != b); assert(a != b);
/* Set any NULLs to worker_thread_base_context to resume execution of main */
if (a == NULL) a = &worker_thread_base_context;
if (b == NULL) b = &worker_thread_base_context;
/* A Transition {Unused, Running} -> Fast */ /* A Transition {Unused, Running} -> Fast */
assert(a->variant == ARCH_CONTEXT_VARIANT_UNUSED || a->variant == ARCH_CONTEXT_VARIANT_RUNNING); assert(a->variant == ARCH_CONTEXT_VARIANT_RUNNING);
/* B Transition {Fast, Slow} -> Running */ /* B Transition {Fast, Slow} -> Running */
assert(b->variant == ARCH_CONTEXT_VARIANT_FAST || b->variant == ARCH_CONTEXT_VARIANT_SLOW); assert(b->variant == ARCH_CONTEXT_VARIANT_FAST || b->variant == ARCH_CONTEXT_VARIANT_SLOW);
@ -87,6 +83,8 @@ arch_context_switch(struct arch_context *a, struct arch_context *b)
"ldr x1, [%[bv]]\n\t" "ldr x1, [%[bv]]\n\t"
"sub x1, x1, #2\n\t" "sub x1, x1, #2\n\t"
"cbz x1, slow%=\n\t" "cbz x1, slow%=\n\t"
"mov x3, #3\n\t"
"str x3, [%[bv]]\n\t" /* b->variant = ARCH_CONTEXT_VARIANT_RUNNING; */
"ldr x0, [%[b]]\n\t" "ldr x0, [%[b]]\n\t"
"ldr x1, [%[b], 8]\n\t" "ldr x1, [%[b], 8]\n\t"
"mov sp, x0\n\t" "mov sp, x0\n\t"
@ -95,8 +93,6 @@ arch_context_switch(struct arch_context *a, struct arch_context *b)
"br %[slowpath]\n\t" "br %[slowpath]\n\t"
".align 8\n\t" ".align 8\n\t"
"reset%=:\n\t" "reset%=:\n\t"
"mov x1, #3\n\t"
"str x1, [%[bv]]\n\t"
".align 8\n\t" ".align 8\n\t"
"exit%=:\n\t" "exit%=:\n\t"
: :
@ -109,6 +105,35 @@ arch_context_switch(struct arch_context *a, struct arch_context *b)
return 0; return 0;
} }
/**
* Load a new sandbox that preempted an existing sandbox, restoring only the
* instruction pointer and stack pointer registers.
* @param active_context - the context of the current worker thread
* @param sandbox_context - the context that we want to restore
*/
static inline void
arch_context_restore_fast(mcontext_t *active_context, struct arch_context *sandbox_context)
{
assert(active_context != NULL);
assert(sandbox_context != NULL);
/* Assumption: Base Context is only ever used by arch_context_switch */
assert(sandbox_context != &worker_thread_base_context);
assert(sandbox_context->regs[UREG_SP]);
assert(sandbox_context->regs[UREG_IP]);
/* Transitioning from Fast -> 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_SP];
//active_context->gregs[REG_RIP] = sandbox_context->regs[UREG_IP];
active_context->sp = sandbox_context->regs[UREG_SP];
active_context->pc = sandbox_context->regs[UREG_IP];
}
#else #else
#warning "Neither AARCH64 nor aarch64 was defined, but aarch64/context.h was included!" #warning "Neither AARCH64 nor aarch64 was defined, but aarch64/context.h was included!"
#endif #endif

@ -34,7 +34,7 @@ sandbox_set_as_initialized(struct sandbox *sandbox, sandbox_state_t last_state)
} }
/* State Change Bookkeeping */ /* State Change Bookkeeping */
assert(now > sandbox->timestamp_of.last_state_change); assert(now >= sandbox->timestamp_of.last_state_change);
sandbox->duration_of_state[last_state] += (now - sandbox->timestamp_of.last_state_change); sandbox->duration_of_state[last_state] += (now - sandbox->timestamp_of.last_state_change);
sandbox->timestamp_of.last_state_change = now; sandbox->timestamp_of.last_state_change = now;
sandbox_state_history_append(&sandbox->state_history, SANDBOX_INITIALIZED); sandbox_state_history_append(&sandbox->state_history, SANDBOX_INITIALIZED);

@ -102,6 +102,7 @@ runtime_get_processor_speed_MHz(void)
{ {
uint32_t return_value; uint32_t return_value;
/* TODO: Find another way to get the cpu speed for ARM machines, this only works for Intel machines */
FILE *cmd = popen("grep '^cpu MHz' /proc/cpuinfo | head -n 1 | awk '{print $4}'", "r"); FILE *cmd = popen("grep '^cpu MHz' /proc/cpuinfo | head -n 1 | awk '{print $4}'", "r");
if (unlikely(cmd == NULL)) goto err; if (unlikely(cmd == NULL)) goto err;

Loading…
Cancel
Save