Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: added SJF scheduler and Regression based prediction #385

Merged
merged 9 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"tenant.h": "c",
"route_config.h": "c",
"http_router.h": "c",
"admissions_info.h": "c",
"execution_histogram.h": "c",
"tcp_server.h": "c",
"stdint.h": "c",
"scheduler_options.h": "c",
Expand Down Expand Up @@ -144,7 +144,20 @@
"algorithm": "c",
"stdio.h": "c",
"get_time.h": "c",
"unistd.h": "c"
"unistd.h": "c",
"wasi.h": "c",
"stat.h": "c",
"functional": "c",
"sandbox_state.h": "c",
"ratio": "c",
"tuple": "c",
"type_traits": "c",
"perf_window.h": "c",
"http_route_total.h": "c",
"sledge_abi_symbols.h": "c",
"mutex": "c",
"lock.h": "c",
"route_latency.h": "c"
},
"files.exclude": {
"**/.git": true,
Expand Down
4 changes: 4 additions & 0 deletions applications/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ all: \
license_plate_detection.install \
resize_image.install \
cnn_face_detection.install \
get_jpeg_resolution.install \
scratch_storage_get.install \
scratch_storage_set.install \
scratch_storage_delete.install \
Expand Down Expand Up @@ -109,6 +110,9 @@ license_plate_detection.install: ../runtime/bin/license_plate_detection.wasm.so
.PHONY: cnn_face_detection.install
cnn_face_detection.install: ../runtime/bin/cnn_face_detection.wasm.so

.PHONY: get_jpeg_resolution.install
get_jpeg_resolution.install: ../runtime/bin/get_jpeg_resolution.wasm.so

.PHONY: trap_divzero.install
trap_divzero.install: ../runtime/bin/trap_divzero.wasm.so

Expand Down
2 changes: 1 addition & 1 deletion awsm
Submodule awsm updated 1 files
+1 −1 applications/wasm_apps
5 changes: 5 additions & 0 deletions runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ BINARY_NAME=sledgert


# Feature Toggles
CFLAGS += -DEXECUTION_HISTOGRAM
# CFLAGS += -DEXECUTION_REGRESSION

# It is recommended (not mandatory) to enable this flag along with the EXECUTION_HISTOGRAM flag:
# CFLAGS += -DADMISSIONS_CONTROL

# Debugging Flags
Expand All @@ -56,6 +60,7 @@ BINARY_NAME=sledgert
# CFLAGS += -DLOG_TO_FILE

# Various Informational Logs for Debugging
# CFLAGS += -DLOG_EXECUTION_HISTOGRAM
# CFLAGS += -DLOG_ADMISSIONS_CONTROL
# CFLAGS += -DLOG_CONTEXT_SWITCHES
# CFLAGS += -DLOG_HTTP_PARSER
Expand Down
7 changes: 4 additions & 3 deletions runtime/include/admissions_control.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#pragma once

#ifdef ADMISSIONS_CONTROL

#include <stdbool.h>
#include <stdint.h>

#ifdef ADMISSIONS_CONTROL
#define ADMISSIONS_CONTROL_GRANULARITY 1000000
extern _Atomic uint64_t admissions_control_admitted;
extern uint64_t admissions_control_capacity;
#endif

void admissions_control_initialize(void);
void admissions_control_add(uint64_t admissions_estimate);
void admissions_control_subtract(uint64_t admissions_estimate);
uint64_t admissions_control_calculate_estimate(uint64_t estimated_execution, uint64_t relative_deadline);
uint64_t admissions_control_calculate_estimate_us(uint32_t estimated_execution_us, uint32_t relative_deadline_us);
void admissions_control_log_decision(uint64_t admissions_estimate, bool admitted);
uint64_t admissions_control_decide(uint64_t admissions_estimate);

#endif
15 changes: 0 additions & 15 deletions runtime/include/admissions_info.h

This file was deleted.

11 changes: 7 additions & 4 deletions runtime/include/current_sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "current_wasm_module_instance.h"
#include "sandbox_types.h"
#include "listener_thread.h"

/* current sandbox that is active.. */
extern thread_local struct sandbox *worker_thread_current_sandbox;
Expand Down Expand Up @@ -46,17 +47,19 @@ current_sandbox_set(struct sandbox *sandbox)
/* Private */
.wasi_context = NULL,
};
worker_thread_current_sandbox = NULL;
runtime_worker_threads_deadline[worker_thread_idx] = UINT64_MAX;
worker_thread_current_sandbox = NULL;
/* This is because the event core does not maintain core-assigned deadline */
if (!listener_thread_is_running()) runtime_worker_threads_deadline[worker_thread_idx] = UINT64_MAX;
} else {
sledge_abi__current_wasm_module_instance.wasi_context = sandbox->wasi_context;
memcpy(&sledge_abi__current_wasm_module_instance.abi.memory, &sandbox->memory->abi,
sizeof(struct sledge_abi__wasm_memory));
sledge_abi__current_wasm_module_instance.abi.table = sandbox->module->indirect_table;
wasm_globals_update_if_used(&sandbox->globals, 0,
&sledge_abi__current_wasm_module_instance.abi.wasmg_0);
worker_thread_current_sandbox = sandbox;
runtime_worker_threads_deadline[worker_thread_idx] = sandbox->absolute_deadline;
worker_thread_current_sandbox = sandbox;
if (!listener_thread_is_running())
runtime_worker_threads_deadline[worker_thread_idx] = sandbox->absolute_deadline;
}
}

Expand Down
14 changes: 14 additions & 0 deletions runtime/include/execution_histogram.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include "perf_window_t.h"

struct execution_histogram {
struct perf_window perf_window;
uint8_t percentile; /* 50 - 99 */
int control_index; /* Precomputed Lookup index when perf_window is full */
uint64_t estimated_execution; /* cycles */
};

void execution_histogram_initialize(struct execution_histogram *execution_histogram, uint8_t percentile,
uint64_t expected_execution);
void execution_histogram_update(struct execution_histogram *execution_histogram, uint64_t execution_duration);
25 changes: 25 additions & 0 deletions runtime/include/execution_regression.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#ifdef EXECUTION_REGRESSION

#include <stdint.h>
#include "http_session.h"

static inline uint64_t
get_regression_prediction(struct http_session *session)
{
/* Default Pre-processing - Extract payload size */
const int payload_size = session->http_request.body_length;

const double regression_params[2] = { payload_size, session->param2 };

/* Regression */
const struct regression_model model = session->route->regr_model;
const uint64_t prediction = (regression_params[0] / model.scale * model.beta1
emil916 marked this conversation as resolved.
Show resolved Hide resolved
+ regression_params[1] / model.scale * model.beta2)
+ model.bias;

return prediction;
}

#endif
29 changes: 22 additions & 7 deletions runtime/include/http_router.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#pragma once

#include <stdlib.h>
#include <string.h>

#include "http.h"
#include "module.h"
#include "route_latency.h"
Expand All @@ -22,7 +20,8 @@ http_router_init(http_router_t *router, size_t capacity)
}

static inline int
http_router_add_route(http_router_t *router, struct route_config *config, struct module *module)
http_router_add_route(http_router_t *router, struct route_config *config, struct module *module,
struct module *module_proprocess)
{
assert(router != NULL);
assert(config != NULL);
Expand All @@ -40,10 +39,26 @@ http_router_add_route(http_router_t *router, struct route_config *config, struct
route_latency_init(&route.latency);
http_route_total_init(&route.metrics);

/* Admissions Control */
uint64_t expected_execution = (uint64_t)config->expected_execution_us * runtime_processor_speed_MHz;
admissions_info_initialize(&route.admissions_info, config->admissions_percentile, expected_execution,
route.relative_deadline);
#ifdef EXECUTION_REGRESSION
/* Execution Regression setup */
route.module_proprocess = module_proprocess;
route.regr_model.bias = config->model_bias / 1000.0;
route.regr_model.scale = config->model_scale / 1000.0;
route.regr_model.num_of_param = config->model_num_of_param;
route.regr_model.beta1 = config->model_beta1 / 1000.0;
route.regr_model.beta2 = config->model_beta2 / 1000.0;
#endif

const uint64_t expected_execution = route.relative_deadline / 2;
#ifdef ADMISSIONS_CONTROL
/* Addmissions Control setup */
route.execution_histogram.estimated_execution = expected_execution;
#endif

#ifdef EXECUTION_HISTOGRAM
/* Execution Histogram setup */
execution_histogram_initialize(&route.execution_histogram, config->admissions_percentile, expected_execution);
#endif

int rc = vec_route_t_push(router, route);
if (unlikely(rc == -1)) { return -1; }
Expand Down
3 changes: 3 additions & 0 deletions runtime/include/http_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ struct http_session {
uint64_t request_downloaded_timestamp;
uint64_t response_takeoff_timestamp;
uint64_t response_sent_timestamp;
bool did_preprocessing;
uint64_t preprocessing_duration;
double param2;
emil916 marked this conversation as resolved.
Show resolved Hide resolved
};

extern void http_session_perf_log_print_entry(struct http_session *http_session);
Expand Down
4 changes: 2 additions & 2 deletions runtime/include/http_session_perf_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ static inline void
http_session_perf_log_print_header()
{
if (http_session_perf_log == NULL) { perror("http_session perf log"); }
fprintf(http_session_perf_log,
"tenant,route,state,header_len,resp_body_len,receive_duration,sent_duration,total_lifetime,proc_MHz\n");
fprintf(http_session_perf_log, "tenant,route,state,header_len,resp_body_len,receive_duration,sent_duration,"
"total_lifetime,preprocessing,proc_MHz\n");
}

static inline void
Expand Down
29 changes: 13 additions & 16 deletions runtime/include/module.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
#pragma once

#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>

#include "admissions_control.h"
#include "admissions_info.h"
#include "current_wasm_module_instance.h"
#include "panic.h"
#include "pool.h"
#include "sledge_abi_symbols.h"
#include "tcp_server.h"
#include "types.h"
#include "sledge_abi_symbols.h"
#include "wasm_stack.h"
#include "wasm_memory.h"
#include "wasm_table.h"

extern thread_local int worker_thread_idx;

Expand All @@ -28,9 +17,15 @@ struct module_pool {
struct wasm_stack_pool stack;
} CACHE_PAD_ALIGNED;

enum module_type
{
APP_MODULE,
PREPROCESS_MODULE
};
struct module {
char *path;
uint32_t stack_size; /* a specification? */
char *path;
uint32_t stack_size; /* a specification? */
enum module_type type;

/* Handle and ABI Symbols for *.so file */
struct sledge_abi_symbols abi;
Expand All @@ -41,12 +36,13 @@ struct module {
struct module_pool *pools;
} CACHE_PAD_ALIGNED;


/********************************
* Public Methods from module.c *
*******************************/

void module_free(struct module *module);
struct module *module_alloc(char *path);
struct module *module_alloc(char *path, enum module_type type);

/*************************
* Public Static Inlines *
Expand Down Expand Up @@ -115,7 +111,8 @@ module_alloc_table(struct module *module)
static inline void
module_initialize_pools(struct module *module)
{
for (int i = 0; i < runtime_worker_threads_count; i++) {
/* Create only a single pool for the preprocessing module, since it is executed only by the event core. */
for (int i = 0; i < (module->type == APP_MODULE ? runtime_worker_threads_count : 1); i++) {
wasm_memory_pool_init(&module->pools[i].memory, false);
wasm_stack_pool_init(&module->pools[i].stack, false);
}
Expand All @@ -124,7 +121,7 @@ module_initialize_pools(struct module *module)
static inline void
module_deinitialize_pools(struct module *module)
{
for (int i = 0; i < runtime_worker_threads_count; i++) {
for (int i = 0; i < (module->type == APP_MODULE ? runtime_worker_threads_count : 1); i++) {
emil916 marked this conversation as resolved.
Show resolved Hide resolved
wasm_memory_pool_deinit(&module->pools[i].memory);
wasm_stack_pool_deinit(&module->pools[i].stack);
}
Expand Down
22 changes: 16 additions & 6 deletions runtime/include/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@
#include <stdint.h>
#include <stddef.h>

#include "admissions_info.h"
#include "execution_histogram.h"
#include "module.h"
#include "http_route_total.h"
#include "perf_window.h"

struct regression_model {
double bias;
double scale;
uint32_t num_of_param;
double beta1;
double beta2;
};

/* Assumption: entrypoint is always _start. This should be enhanced later */
struct route {
char *route;
struct http_route_total metrics;
struct module *module;
/* HTTP State */
uint32_t relative_deadline_us;
uint64_t relative_deadline; /* cycles */
char *response_content_type;
struct admissions_info admissions_info;
struct perf_window latency;
uint32_t relative_deadline_us;
uint64_t relative_deadline; /* cycles */
char *response_content_type;
struct execution_histogram execution_histogram;
struct perf_window latency;
struct module *module_proprocess;
struct regression_model regr_model;
};
Loading
Loading