refactor: sandbox state durations

master
Sean McBride 4 years ago
parent c80dfa1db5
commit a5739f338d

@ -99,7 +99,7 @@ sandbox_print_perf(struct sandbox *sandbox)
fprintf(runtime_sandbox_perf_log, "%lu,%s,%d,%s,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%u,%u\n", sandbox->id,
sandbox->module->name, sandbox->module->port, sandbox_state_stringify(sandbox->state),
sandbox->module->relative_deadline, sandbox->total_time, queued_duration,
sandbox->initializing_duration, sandbox->runnable_duration, sandbox->running_duration,
sandbox->blocked_duration, sandbox->returned_duration, runtime_processor_speed_MHz,
sandbox->memory.size);
sandbox->duration_of_state.initializing, sandbox->duration_of_state.runnable,
sandbox->duration_of_state.running, sandbox->duration_of_state.blocked,
sandbox->duration_of_state.returned, runtime_processor_speed_MHz, sandbox->memory.size);
}

@ -28,7 +28,7 @@ sandbox_set_as_blocked(struct sandbox *sandbox, sandbox_state_t last_state)
switch (last_state) {
case SANDBOX_RUNNING: {
sandbox->running_duration += duration_of_last_state;
sandbox->duration_of_state.running += duration_of_last_state;
local_runqueue_delete(sandbox);
break;
}

@ -31,7 +31,7 @@ sandbox_set_as_complete(struct sandbox *sandbox, sandbox_state_t last_state)
switch (last_state) {
case SANDBOX_RETURNED: {
sandbox->timestamp_of.completion = now;
sandbox->returned_duration += duration_of_last_state;
sandbox->duration_of_state.returned += duration_of_last_state;
break;
}
default: {
@ -49,7 +49,7 @@ sandbox_set_as_complete(struct sandbox *sandbox, sandbox_state_t last_state)
runtime_sandbox_total_decrement(last_state);
/* Admissions Control Post Processing */
admissions_info_update(&sandbox->module->admissions_info, sandbox->running_duration);
admissions_info_update(&sandbox->module->admissions_info, sandbox->duration_of_state.running);
admissions_control_subtract(sandbox->admissions_estimate);
/* Terminal State Logging */

@ -36,10 +36,10 @@ sandbox_set_as_error(struct sandbox *sandbox, sandbox_state_t last_state)
switch (last_state) {
case SANDBOX_SET_AS_INITIALIZED:
/* Technically, this is a degenerate sandbox that we generate by hand */
sandbox->initializing_duration += duration_of_last_state;
sandbox->duration_of_state.initializing += duration_of_last_state;
break;
case SANDBOX_RUNNING: {
sandbox->running_duration += duration_of_last_state;
sandbox->duration_of_state.running += duration_of_last_state;
local_runqueue_delete(sandbox);
break;
}

@ -33,7 +33,7 @@ sandbox_set_as_returned(struct sandbox *sandbox, sandbox_state_t last_state)
case SANDBOX_RUNNING: {
sandbox->timestamp_of.response = now;
sandbox->total_time = now - sandbox->timestamp_of.request_arrival;
sandbox->running_duration += duration_of_last_state;
sandbox->duration_of_state.running += duration_of_last_state;
local_runqueue_delete(sandbox);
sandbox_free_linear_memory(sandbox);
break;

@ -31,17 +31,17 @@ sandbox_set_as_runnable(struct sandbox *sandbox, sandbox_state_t last_state)
switch (last_state) {
case SANDBOX_INITIALIZED: {
sandbox->initializing_duration += duration_of_last_state;
sandbox->duration_of_state.initializing += duration_of_last_state;
local_runqueue_add(sandbox);
break;
}
case SANDBOX_BLOCKED: {
sandbox->blocked_duration += duration_of_last_state;
sandbox->duration_of_state.blocked += duration_of_last_state;
local_runqueue_add(sandbox);
break;
}
case SANDBOX_RUNNING: {
sandbox->running_duration += duration_of_last_state;
sandbox->duration_of_state.running += duration_of_last_state;
/* No need to add to runqueue, as already on it */
break;
}
@ -52,7 +52,7 @@ sandbox_set_as_runnable(struct sandbox *sandbox, sandbox_state_t last_state)
}
sandbox->timestamp_of.last_state_change = now;
sandbox->state = SANDBOX_RUNNABLE;
sandbox->state = SANDBOX_RUNNABLE;
/* State Change Bookkeeping */
sandbox_state_log_transition(sandbox->id, last_state, SANDBOX_RUNNABLE);

@ -19,7 +19,7 @@ sandbox_set_as_running(struct sandbox *sandbox, sandbox_state_t last_state)
switch (last_state) {
case SANDBOX_RUNNABLE: {
sandbox->runnable_duration += duration_of_last_state;
sandbox->duration_of_state.runnable += duration_of_last_state;
current_sandbox_set(sandbox);
runtime_worker_threads_deadline[worker_thread_idx] = sandbox->absolute_deadline;
/* Does not handle context switch because the caller knows if we need to use fast or slow switched */

@ -27,6 +27,15 @@ typedef enum
SANDBOX_STATE_COUNT
} sandbox_state_t;
/* Duration of time (in cycles) that the sandbox is in each state */
struct sandbox_state_durations {
uint64_t initializing;
uint64_t runnable;
uint64_t running;
uint64_t blocked;
uint64_t returned;
};
extern const bool sandbox_state_is_terminal[SANDBOX_STATE_COUNT];
extern const char *sandbox_state_labels[SANDBOX_STATE_COUNT];

@ -20,7 +20,7 @@ sandbox_summarize_page_allocations(struct sandbox *sandbox)
FILE *sandbox_page_allocations_log = fopen(sandbox_page_allocations_log_path, "a");
fprintf(sandbox_page_allocations_log, "%lu,%lu,%s,", sandbox->id, sandbox->running_duration,
fprintf(sandbox_page_allocations_log, "%lu,%lu,%s,", sandbox->id, sandbox->duration_of_state.running,
sandbox_state_stringify(sandbox->state));
for (size_t i = 0; i < sandbox->timestamp_of.page_allocations_size; i++)
fprintf(sandbox_page_allocations_log, "%u,", sandbox->timestamp_of.page_allocations[i]);

@ -60,25 +60,16 @@ struct sandbox {
struct sandbox_stack stack;
struct wasm_memory memory;
struct sandbox_timestamps timestamp_of;
/* Duration of time (in cycles) that the sandbox is in each state */
uint64_t initializing_duration;
uint64_t runnable_duration;
uint64_t running_duration;
uint64_t blocked_duration;
uint64_t returned_duration;
/* Scheduling and Temporal State */
struct sandbox_timestamps timestamp_of;
struct sandbox_state_durations duration_of_state;
uint64_t absolute_deadline;
uint64_t total_time; /* From Request to Response */
/*
* Unitless estimate of the instantaneous fraction of system capacity required to run the request
* Calculated by estimated execution time (cycles) * runtime_admissions_granularity / relative deadline (cycles)
*/
uint64_t admissions_estimate;
uint64_t admissions_estimate; /* estimated execution time (cycles) * runtime_admissions_granularity / relative
deadline (cycles) */
uint64_t total_time; /* From Request to Response */
/* System Interface State */
int32_t arguments_offset; /* actual placement of arguments in the sandbox. */
void * arguments; /* arguments from request, must be of module->argument_count size. */
int32_t return_value;

@ -35,7 +35,8 @@ expand_memory(void)
// Cache the runtime of the first N page allocations
if (likely(sandbox->timestamp_of.page_allocations_size < SANDBOX_PAGE_ALLOCATION_TIMESTAMP_COUNT)) {
sandbox->timestamp_of.page_allocations[sandbox->timestamp_of.page_allocations_size++] =
sandbox->running_duration + (uint32_t)(__getcycles() - sandbox->timestamp_of.last_state_change);
sandbox->duration_of_state.running
+ (uint32_t)(__getcycles() - sandbox->timestamp_of.last_state_change);
}
#endif

Loading…
Cancel
Save