From 66b20d20c094a9b456865c1e3fd8ecc5dd7d282f Mon Sep 17 00:00:00 2001 From: xiaosuGW Date: Wed, 6 Oct 2021 12:08:34 -0400 Subject: [PATCH] add workload counter for each worker thread --- runtime/include/local_runqueue.h | 2 ++ runtime/include/sandbox_receive_request.h | 6 +++--- runtime/include/sandbox_set_as_error.h | 1 + runtime/include/sandbox_set_as_returned.h | 1 + runtime/include/sandbox_set_as_runnable.h | 1 + runtime/include/sandbox_set_as_running.h | 6 +++--- runtime/include/scheduler.h | 6 +++--- runtime/src/current_sandbox.c | 6 +++--- runtime/src/local_runqueue.c | 17 +++++++++++++++++ runtime/src/worker_thread.c | 6 +++--- 10 files changed, 37 insertions(+), 15 deletions(-) diff --git a/runtime/include/local_runqueue.h b/runtime/include/local_runqueue.h index 432eea1..ce7ea89 100644 --- a/runtime/include/local_runqueue.h +++ b/runtime/include/local_runqueue.h @@ -22,3 +22,5 @@ void local_runqueue_delete(struct sandbox *); bool local_runqueue_is_empty(); struct sandbox *local_runqueue_get_next(); void local_runqueue_initialize(struct local_runqueue_config *config); +void local_workload_add(); +void local_workload_complete(); diff --git a/runtime/include/sandbox_receive_request.h b/runtime/include/sandbox_receive_request.h index 91cd6fe..f53a859 100644 --- a/runtime/include/sandbox_receive_request.h +++ b/runtime/include/sandbox_receive_request.h @@ -46,9 +46,9 @@ sandbox_receive_request(struct sandbox *sandbox) if (recved < 0) { if (errno == EAGAIN) { - uint64_t block_time = __getcycles() - system_start_timestamp; - mem_log("time %lu blocked, request id:%d name %s obj=%p remaining slack %lu\n", block_time, - sandbox->id, sandbox->module->name, sandbox, sandbox->remaining_slack); + //uint64_t block_time = __getcycles() - system_start_timestamp; + //mem_log("time %lu blocked, request id:%d name %s obj=%p remaining slack %lu\n", block_time, + // sandbox->id, sandbox->module->name, sandbox, sandbox->remaining_slack); scheduler_block(); continue; } else { diff --git a/runtime/include/sandbox_set_as_error.h b/runtime/include/sandbox_set_as_error.h index de77797..68ed22c 100644 --- a/runtime/include/sandbox_set_as_error.h +++ b/runtime/include/sandbox_set_as_error.h @@ -41,6 +41,7 @@ sandbox_set_as_error(struct sandbox *sandbox, sandbox_state_t last_state) case SANDBOX_RUNNING: { sandbox->running_duration += duration_of_last_state; local_runqueue_delete(sandbox); + local_workload_complete(); break; } default: { diff --git a/runtime/include/sandbox_set_as_returned.h b/runtime/include/sandbox_set_as_returned.h index bc0c277..7d4f4c0 100644 --- a/runtime/include/sandbox_set_as_returned.h +++ b/runtime/include/sandbox_set_as_returned.h @@ -35,6 +35,7 @@ sandbox_set_as_returned(struct sandbox *sandbox, sandbox_state_t last_state) sandbox->total_time = now - sandbox->enqueue_timestamp; sandbox->running_duration += duration_of_last_state; local_runqueue_delete(sandbox); + local_workload_complete(); sandbox_free_linear_memory(sandbox); break; } diff --git a/runtime/include/sandbox_set_as_runnable.h b/runtime/include/sandbox_set_as_runnable.h index be8b6c3..270a557 100644 --- a/runtime/include/sandbox_set_as_runnable.h +++ b/runtime/include/sandbox_set_as_runnable.h @@ -33,6 +33,7 @@ sandbox_set_as_runnable(struct sandbox *sandbox, sandbox_state_t last_state) case SANDBOX_INITIALIZED: { sandbox->initializing_duration += duration_of_last_state; local_runqueue_add(sandbox); + local_workload_add(); break; } case SANDBOX_BLOCKED: { diff --git a/runtime/include/sandbox_set_as_running.h b/runtime/include/sandbox_set_as_running.h index 4fb5e3c..b8637af 100644 --- a/runtime/include/sandbox_set_as_running.h +++ b/runtime/include/sandbox_set_as_running.h @@ -21,9 +21,9 @@ sandbox_set_as_running(struct sandbox *sandbox, sandbox_state_t last_state) switch (last_state) { case SANDBOX_RUNNABLE: { - uint64_t start_execution = now - system_start_timestamp; - uint64_t last = sandbox->last_update_timestamp; - uint64_t last_rs = sandbox->remaining_slack; + //uint64_t start_execution = now - system_start_timestamp; + //uint64_t last = sandbox->last_update_timestamp; + //uint64_t last_rs = sandbox->remaining_slack; sandbox->remaining_slack -= (now - sandbox->last_update_timestamp); sandbox->last_update_timestamp = now; sandbox->runnable_duration += duration_of_last_state; diff --git a/runtime/include/scheduler.h b/runtime/include/scheduler.h index 0e5ee5e..145ac25 100644 --- a/runtime/include/scheduler.h +++ b/runtime/include/scheduler.h @@ -84,9 +84,9 @@ scheduler_srsf_get_next() if (global_remaining_slack < local_remaining_slack) { if (global_request_scheduler_remove_if_earlier(&request, local_remaining_slack) == 0) { - uint64_t pop_time = __getcycles() - system_start_timestamp; - mem_log("time %lu remove from GQ, request id:%d name %s remaining slack %lu\n", pop_time, - request->id, request->module->name, request->remaining_slack); + //uint64_t pop_time = __getcycles() - system_start_timestamp; + //mem_log("time %lu remove from GQ, request id:%d name %s remaining slack %lu\n", pop_time, + // request->id, request->module->name, request->remaining_slack); assert(request != NULL); struct sandbox *global = sandbox_allocate(request); diff --git a/runtime/src/current_sandbox.c b/runtime/src/current_sandbox.c index fc90eec..d7a74f1 100644 --- a/runtime/src/current_sandbox.c +++ b/runtime/src/current_sandbox.c @@ -123,9 +123,9 @@ current_sandbox_start(void) memcpy(pre_func_output, sandbox->request_response_data + sandbox->request_length, output_length); uint64_t enqueue_timestamp = __getcycles(); - uint64_t current_rs = enqueue_timestamp - system_start_timestamp; - mem_log("time %lu request id:%d executing, name:%s remaining slack %lu\n", current_rs, - sandbox->id, sandbox->module->name, sandbox->remaining_slack); + //uint64_t current_rs = enqueue_timestamp - system_start_timestamp; + //mem_log("time %lu request id:%d executing, name:%s remaining slack %lu\n", current_rs, + // sandbox->id, sandbox->module->name, sandbox->remaining_slack); struct sandbox_request *sandbox_request = sandbox_request_allocate(next_module, false, sandbox->request_length, next_module->name, sandbox->client_socket_descriptor, diff --git a/runtime/src/local_runqueue.c b/runtime/src/local_runqueue.c index b87f66e..0e69d54 100644 --- a/runtime/src/local_runqueue.c +++ b/runtime/src/local_runqueue.c @@ -11,6 +11,7 @@ static struct local_runqueue_config local_runqueue; __thread uint32_t local_runqueue_count = 0; #endif +__thread uint32_t local_workload_count = 0; /* Initializes a concrete implementation of the sandbox request scheduler interface */ void local_runqueue_initialize(struct local_runqueue_config *config) @@ -67,3 +68,19 @@ local_runqueue_get_next() assert(local_runqueue.get_next_fn != NULL); return local_runqueue.get_next_fn(); }; + +/** + * The worker thread gets a new request, add the workload counter by 1 + */ +void +local_workload_add() { + local_workload_count++; +} + +/** + * One request is complete on the worker thread, and decrease the workload counter by 1 + */ +void +local_workload_complete() { + local_workload_count--; +} diff --git a/runtime/src/worker_thread.c b/runtime/src/worker_thread.c index bcf09ab..222624c 100644 --- a/runtime/src/worker_thread.c +++ b/runtime/src/worker_thread.c @@ -85,9 +85,9 @@ worker_thread_main(void *argument) next_sandbox = scheduler_get_next(); if (next_sandbox != NULL) { - uint64_t start_execution = __getcycles() - system_start_timestamp; - mem_log("time %lu pop from GQ, request id:%d name %s obj=%p remaining slack %lu last_update_time %lu \n", start_execution, - next_sandbox->id, next_sandbox->module->name, next_sandbox, next_sandbox->remaining_slack, next_sandbox->last_update_timestamp); + //uint64_t start_execution = __getcycles() - system_start_timestamp; + //mem_log("time %lu pop from GQ, request id:%d name %s obj=%p remaining slack %lu last_update_time %lu \n", start_execution, + // next_sandbox->id, next_sandbox->module->name, next_sandbox, next_sandbox->remaining_slack, next_sandbox->last_update_timestamp); scheduler_switch_to(next_sandbox); }