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

Lines changed: 15 additions & 2 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 0 additions & 15 deletions
This file was deleted.

runtime/include/current_sandbox.h

Lines changed: 7 additions & 4 deletions
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

Lines changed: 14 additions & 0 deletions
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);
Lines changed: 25 additions & 0 deletions
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

Lines changed: 23 additions & 7 deletions
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; }

0 commit comments

Comments
 (0)