Skip to content

Commit fdf75b4

Browse files
committed
feature: added SJF scheduler
added REGRESSION based prediction support
1 parent 4ae8b02 commit fdf75b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+584
-270
lines changed

.vscode/settings.json

+15-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"tenant.h": "c",
117117
"route_config.h": "c",
118118
"http_router.h": "c",
119-
"admissions_info.h": "c",
119+
"execution_histogram.h": "c",
120120
"tcp_server.h": "c",
121121
"stdint.h": "c",
122122
"scheduler_options.h": "c",
@@ -144,7 +144,20 @@
144144
"algorithm": "c",
145145
"stdio.h": "c",
146146
"get_time.h": "c",
147-
"unistd.h": "c"
147+
"unistd.h": "c",
148+
"wasi.h": "c",
149+
"stat.h": "c",
150+
"functional": "c",
151+
"sandbox_state.h": "c",
152+
"ratio": "c",
153+
"tuple": "c",
154+
"type_traits": "c",
155+
"perf_window.h": "c",
156+
"http_route_total.h": "c",
157+
"sledge_abi_symbols.h": "c",
158+
"mutex": "c",
159+
"lock.h": "c",
160+
"route_latency.h": "c"
148161
},
149162
"files.exclude": {
150163
"**/.git": true,

applications/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ all: \
2727
license_plate_detection.install \
2828
resize_image.install \
2929
cnn_face_detection.install \
30+
get_jpeg_resolution.install \
3031
scratch_storage_get.install \
3132
scratch_storage_set.install \
3233
scratch_storage_delete.install \
@@ -109,6 +110,9 @@ license_plate_detection.install: ../runtime/bin/license_plate_detection.wasm.so
109110
.PHONY: cnn_face_detection.install
110111
cnn_face_detection.install: ../runtime/bin/cnn_face_detection.wasm.so
111112

113+
.PHONY: get_jpeg_resolution.install
114+
get_jpeg_resolution.install: ../runtime/bin/get_jpeg_resolution.wasm.so
115+
112116
.PHONY: trap_divzero.install
113117
trap_divzero.install: ../runtime/bin/trap_divzero.wasm.so
114118

awsm

runtime/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ BINARY_NAME=sledgert
3838

3939

4040
# Feature Toggles
41+
CFLAGS += -DEXECUTION_HISTOGRAM
42+
# CFLAGS += -DEXECUTION_REGRESSION
43+
44+
# It is recommended (not mandatory) to enable this flag along with the EXECUTION_HISTOGRAM flag:
4145
# CFLAGS += -DADMISSIONS_CONTROL
4246

4347
# Debugging Flags
@@ -56,6 +60,7 @@ BINARY_NAME=sledgert
5660
# CFLAGS += -DLOG_TO_FILE
5761

5862
# Various Informational Logs for Debugging
63+
# CFLAGS += -DLOG_EXECUTION_HISTOGRAM
5964
# CFLAGS += -DLOG_ADMISSIONS_CONTROL
6065
# CFLAGS += -DLOG_CONTEXT_SWITCHES
6166
# CFLAGS += -DLOG_HTTP_PARSER

runtime/include/admissions_control.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
#pragma once
22

3+
#ifdef ADMISSIONS_CONTROL
4+
35
#include <stdbool.h>
46
#include <stdint.h>
57

6-
#ifdef ADMISSIONS_CONTROL
78
#define ADMISSIONS_CONTROL_GRANULARITY 1000000
89
extern _Atomic uint64_t admissions_control_admitted;
910
extern uint64_t admissions_control_capacity;
10-
#endif
1111

1212
void admissions_control_initialize(void);
1313
void admissions_control_add(uint64_t admissions_estimate);
1414
void admissions_control_subtract(uint64_t admissions_estimate);
1515
uint64_t admissions_control_calculate_estimate(uint64_t estimated_execution, uint64_t relative_deadline);
16-
uint64_t admissions_control_calculate_estimate_us(uint32_t estimated_execution_us, uint32_t relative_deadline_us);
1716
void admissions_control_log_decision(uint64_t admissions_estimate, bool admitted);
1817
uint64_t admissions_control_decide(uint64_t admissions_estimate);
18+
19+
#endif

runtime/include/admissions_info.h

-15
This file was deleted.

runtime/include/current_sandbox.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "current_wasm_module_instance.h"
66
#include "sandbox_types.h"
7+
#include "listener_thread.h"
78

89
/* current sandbox that is active.. */
910
extern thread_local struct sandbox *worker_thread_current_sandbox;
@@ -46,17 +47,19 @@ current_sandbox_set(struct sandbox *sandbox)
4647
/* Private */
4748
.wasi_context = NULL,
4849
};
49-
worker_thread_current_sandbox = NULL;
50-
runtime_worker_threads_deadline[worker_thread_idx] = UINT64_MAX;
50+
worker_thread_current_sandbox = NULL;
51+
/* This is because the event core does not maintain core-assigned deadline */
52+
if (!listener_thread_is_running()) runtime_worker_threads_deadline[worker_thread_idx] = UINT64_MAX;
5153
} else {
5254
sledge_abi__current_wasm_module_instance.wasi_context = sandbox->wasi_context;
5355
memcpy(&sledge_abi__current_wasm_module_instance.abi.memory, &sandbox->memory->abi,
5456
sizeof(struct sledge_abi__wasm_memory));
5557
sledge_abi__current_wasm_module_instance.abi.table = sandbox->module->indirect_table;
5658
wasm_globals_update_if_used(&sandbox->globals, 0,
5759
&sledge_abi__current_wasm_module_instance.abi.wasmg_0);
58-
worker_thread_current_sandbox = sandbox;
59-
runtime_worker_threads_deadline[worker_thread_idx] = sandbox->absolute_deadline;
60+
worker_thread_current_sandbox = sandbox;
61+
if (!listener_thread_is_running())
62+
runtime_worker_threads_deadline[worker_thread_idx] = sandbox->absolute_deadline;
6063
}
6164
}
6265

runtime/include/execution_histogram.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include "perf_window_t.h"
4+
5+
struct execution_histogram {
6+
struct perf_window perf_window;
7+
uint8_t percentile; /* 50 - 99 */
8+
int control_index; /* Precomputed Lookup index when perf_window is full */
9+
uint64_t estimated_execution; /* cycles */
10+
};
11+
12+
void execution_histogram_initialize(struct execution_histogram *execution_histogram, uint8_t percentile,
13+
uint64_t expected_execution);
14+
void execution_histogram_update(struct execution_histogram *execution_histogram, uint64_t execution_duration);
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#ifdef EXECUTION_REGRESSION
4+
5+
#include <stdint.h>
6+
#include "http_session.h"
7+
8+
static inline uint64_t
9+
get_regression_prediction(struct http_session *session)
10+
{
11+
/* Default Pre-processing - Extract payload size */
12+
const int payload_size = session->http_request.body_length;
13+
14+
const double regression_params[2] = { payload_size, session->param2 };
15+
16+
/* Regression */
17+
const struct regression_model model = session->route->regr_model;
18+
const uint64_t prediction = (regression_params[0] / model.scale * model.beta1
19+
+ regression_params[1] / model.scale * model.beta2)
20+
+ model.bias;
21+
22+
return prediction;
23+
}
24+
25+
#endif

runtime/include/http_router.h

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#pragma once
22

33
#include <stdlib.h>
4-
#include <string.h>
5-
64
#include "http.h"
75
#include "module.h"
86
#include "route_latency.h"
@@ -22,7 +20,8 @@ http_router_init(http_router_t *router, size_t capacity)
2220
}
2321

2422
static inline int
25-
http_router_add_route(http_router_t *router, struct route_config *config, struct module *module)
23+
http_router_add_route(http_router_t *router, struct route_config *config, struct module *module,
24+
struct module *pre_module)
2625
{
2726
assert(router != NULL);
2827
assert(config != NULL);
@@ -40,10 +39,27 @@ http_router_add_route(http_router_t *router, struct route_config *config, struct
4039
route_latency_init(&route.latency);
4140
http_route_total_init(&route.metrics);
4241

43-
/* Admissions Control */
44-
uint64_t expected_execution = (uint64_t)config->expected_execution_us * runtime_processor_speed_MHz;
45-
admissions_info_initialize(&route.admissions_info, config->admissions_percentile, expected_execution,
46-
route.relative_deadline);
42+
#ifdef EXECUTION_REGRESSION
43+
/* Execution Regression setup */
44+
assert(pre_module);
45+
route.pre_module = pre_module;
46+
route.regr_model.bias = config->model_bias / 1000.0;
47+
route.regr_model.scale = config->model_scale / 1000.0;
48+
route.regr_model.num_of_param = config->model_num_of_param;
49+
route.regr_model.beta1 = config->model_beta1 / 1000.0;
50+
route.regr_model.beta2 = config->model_beta2 / 1000.0;
51+
#endif
52+
53+
const uint64_t expected_execution = route.relative_deadline / 2;
54+
#ifdef ADMISSIONS_CONTROL
55+
/* Addmissions Control setup */
56+
route.execution_histogram.estimated_execution = expected_execution;
57+
#endif
58+
59+
#ifdef EXECUTION_HISTOGRAM
60+
/* Execution Histogram setup */
61+
execution_histogram_initialize(&route.execution_histogram, config->admissions_percentile, expected_execution);
62+
#endif
4763

4864
int rc = vec_route_t_push(router, route);
4965
if (unlikely(rc == -1)) { return -1; }

runtime/include/http_session.h

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ struct http_session {
5757
uint64_t request_downloaded_timestamp;
5858
uint64_t response_takeoff_timestamp;
5959
uint64_t response_sent_timestamp;
60+
bool did_preprocessing;
61+
uint64_t preprocessing_duration;
62+
double param2;
6063
};
6164

6265
extern void http_session_perf_log_print_entry(struct http_session *http_session);

runtime/include/http_session_perf_log.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ static inline void
1515
http_session_perf_log_print_header()
1616
{
1717
if (http_session_perf_log == NULL) { perror("http_session perf log"); }
18-
fprintf(http_session_perf_log,
19-
"tenant,route,state,header_len,resp_body_len,receive_duration,sent_duration,total_lifetime,proc_MHz\n");
18+
fprintf(http_session_perf_log, "tenant,route,state,header_len,resp_body_len,receive_duration,sent_duration,"
19+
"total_lifetime,preprocessing,proc_MHz\n");
2020
}
2121

2222
static inline void

runtime/include/module.h

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
#pragma once
22

3-
#include <string.h>
4-
#include <sys/socket.h>
5-
#include <sys/types.h>
6-
#include <netdb.h>
7-
8-
#include "admissions_control.h"
9-
#include "admissions_info.h"
103
#include "current_wasm_module_instance.h"
11-
#include "panic.h"
124
#include "pool.h"
13-
#include "sledge_abi_symbols.h"
14-
#include "tcp_server.h"
155
#include "types.h"
166
#include "sledge_abi_symbols.h"
177
#include "wasm_stack.h"
188
#include "wasm_memory.h"
19-
#include "wasm_table.h"
209

2110
extern thread_local int worker_thread_idx;
2211

@@ -28,9 +17,15 @@ struct module_pool {
2817
struct wasm_stack_pool stack;
2918
} CACHE_PAD_ALIGNED;
3019

20+
enum module_type
21+
{
22+
APP_MODULE,
23+
PREPROCESS_MODULE
24+
};
3125
struct module {
32-
char *path;
33-
uint32_t stack_size; /* a specification? */
26+
char *path;
27+
uint32_t stack_size; /* a specification? */
28+
enum module_type type;
3429

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

39+
4440
/********************************
4541
* Public Methods from module.c *
4642
*******************************/
4743

4844
void module_free(struct module *module);
49-
struct module *module_alloc(char *path);
45+
struct module *module_alloc(char *path, enum module_type type);
5046

5147
/*************************
5248
* Public Static Inlines *
@@ -115,7 +111,8 @@ module_alloc_table(struct module *module)
115111
static inline void
116112
module_initialize_pools(struct module *module)
117113
{
118-
for (int i = 0; i < runtime_worker_threads_count; i++) {
114+
/* Create only a single pool for the preprocessing module, since it is executed only by the event core. */
115+
for (int i = 0; i < (module->type == APP_MODULE ? runtime_worker_threads_count : 1); i++) {
119116
wasm_memory_pool_init(&module->pools[i].memory, false);
120117
wasm_stack_pool_init(&module->pools[i].stack, false);
121118
}
@@ -124,7 +121,7 @@ module_initialize_pools(struct module *module)
124121
static inline void
125122
module_deinitialize_pools(struct module *module)
126123
{
127-
for (int i = 0; i < runtime_worker_threads_count; i++) {
124+
for (int i = 0; i < (module->type == APP_MODULE ? runtime_worker_threads_count : 1); i++) {
128125
wasm_memory_pool_deinit(&module->pools[i].memory);
129126
wasm_stack_pool_deinit(&module->pools[i].stack);
130127
}

runtime/include/route.h

+16-6
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@
33
#include <stdint.h>
44
#include <stddef.h>
55

6-
#include "admissions_info.h"
6+
#include "execution_histogram.h"
77
#include "module.h"
88
#include "http_route_total.h"
99
#include "perf_window.h"
1010

11+
struct regression_model {
12+
double bias;
13+
double scale;
14+
uint32_t num_of_param;
15+
double beta1;
16+
double beta2;
17+
};
18+
1119
/* Assumption: entrypoint is always _start. This should be enhanced later */
1220
struct route {
1321
char *route;
1422
struct http_route_total metrics;
1523
struct module *module;
24+
struct module *pre_module;
1625
/* HTTP State */
17-
uint32_t relative_deadline_us;
18-
uint64_t relative_deadline; /* cycles */
19-
char *response_content_type;
20-
struct admissions_info admissions_info;
21-
struct perf_window latency;
26+
uint32_t relative_deadline_us;
27+
uint64_t relative_deadline; /* cycles */
28+
char *response_content_type;
29+
struct execution_histogram execution_histogram;
30+
struct perf_window latency;
31+
struct regression_model regr_model;
2232
};

0 commit comments

Comments
 (0)