Skip to content

Commit 11d1484

Browse files
committed
fix: error handling
1 parent fdf75b4 commit 11d1484

File tree

54 files changed

+604
-172
lines changed

Some content is hidden

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

54 files changed

+604
-172
lines changed

runtime/include/http_router.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ http_router_init(http_router_t *router, size_t capacity)
2121

2222
static inline int
2323
http_router_add_route(http_router_t *router, struct route_config *config, struct module *module,
24-
struct module *pre_module)
24+
struct module *module_proprocess)
2525
{
2626
assert(router != NULL);
2727
assert(config != NULL);
@@ -41,8 +41,7 @@ http_router_add_route(http_router_t *router, struct route_config *config, struct
4141

4242
#ifdef EXECUTION_REGRESSION
4343
/* Execution Regression setup */
44-
assert(pre_module);
45-
route.pre_module = pre_module;
44+
route.module_proprocess = module_proprocess;
4645
route.regr_model.bias = config->model_bias / 1000.0;
4746
route.regr_model.scale = config->model_scale / 1000.0;
4847
route.regr_model.num_of_param = config->model_num_of_param;

runtime/include/route.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ struct route {
2121
char *route;
2222
struct http_route_total metrics;
2323
struct module *module;
24-
struct module *pre_module;
2524
/* HTTP State */
2625
uint32_t relative_deadline_us;
2726
uint64_t relative_deadline; /* cycles */
2827
char *response_content_type;
2928
struct execution_histogram execution_histogram;
3029
struct perf_window latency;
30+
struct module *module_proprocess;
3131
struct regression_model regr_model;
3232
};

runtime/include/route_config.h

+67-21
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ enum route_config_member
1212
{
1313
route_config_member_route,
1414
route_config_member_path,
15-
route_config_member_path_premodule,
1615
route_config_member_admissions_percentile,
1716
route_config_member_relative_deadline_us,
17+
route_config_member_path_preprocess,
1818
route_config_member_model_bias,
1919
route_config_member_model_scale,
2020
route_config_member_model_num_of_param,
@@ -27,9 +27,9 @@ enum route_config_member
2727
struct route_config {
2828
char *route;
2929
char *path;
30-
char *path_premodule;
3130
uint8_t admissions_percentile;
3231
uint32_t relative_deadline_us;
32+
char *path_preprocess;
3333
uint32_t model_bias;
3434
uint32_t model_scale;
3535
uint32_t model_num_of_param;
@@ -54,14 +54,16 @@ route_config_print(struct route_config *config)
5454
{
5555
printf("[Route] Route: %s\n", config->route);
5656
printf("[Route] Path: %s\n", config->path);
57-
printf("[Route] Path of Preprocessing Module: %s\n", config->path_premodule);
5857
printf("[Route] Admissions Percentile: %hhu\n", config->admissions_percentile);
5958
printf("[Route] Relative Deadline (us): %u\n", config->relative_deadline_us);
59+
printf("[Route] HTTP Response Content Type: %s\n", config->http_resp_content_type);
60+
#ifdef EXECUTION_HISTOGRAM
61+
printf("[Route] Path of Preprocessing Module: %s\n", config->path_preprocess);
6062
printf("[Route] Model Bias: %u\n", config->model_bias);
6163
printf("[Route] Model Scale: %u\n", config->model_scale);
6264
printf("[Route] Model Num of Parameters: %u\n", config->model_num_of_param);
6365
printf("[Route] Model Betas: [%u, %u]\n", config->model_beta1, config->model_beta2);
64-
printf("[Route] HTTP Response Content Type: %s\n", config->http_resp_content_type);
66+
#endif
6567
}
6668

6769
/**
@@ -73,7 +75,7 @@ static inline int
7375
route_config_validate(struct route_config *config, bool *did_set)
7476
{
7577
if (did_set[route_config_member_route] == false) {
76-
fprintf(stderr, "path field is required\n");
78+
fprintf(stderr, "route field is required\n");
7779
return -1;
7880
}
7981

@@ -82,19 +84,14 @@ route_config_validate(struct route_config *config, bool *did_set)
8284
return -1;
8385
}
8486

85-
if (did_set[route_config_member_path_premodule] == false) {
86-
fprintf(stderr, "path_premodule field is required\n");
87-
return -1;
88-
}
89-
9087
if (did_set[route_config_member_http_resp_content_type] == false) {
9188
debuglog("http_resp_content_type not set, defaulting to text/plain\n");
9289
config->http_resp_content_type = "text/plain";
9390
}
9491

95-
if (scheduler != SCHEDULER_FIFO) {
92+
if (scheduler != SCHEDULER_FIFO && scheduler != SCHEDULER_SJF) {
9693
if (did_set[route_config_member_relative_deadline_us] == false) {
97-
fprintf(stderr, "relative_deadline_us is required\n");
94+
fprintf(stderr, "relative_deadline_us is required for the selected scheduler\n");
9895
return -1;
9996
}
10097

@@ -103,20 +100,69 @@ route_config_validate(struct route_config *config, bool *did_set)
103100
(uint32_t)RUNTIME_RELATIVE_DEADLINE_US_MAX, config->relative_deadline_us);
104101
return -1;
105102
}
103+
}
104+
105+
#ifdef EXECUTION_HISTOGRAM
106+
if (config->admissions_percentile > 99 || config->admissions_percentile < 50) {
107+
fprintf(stderr, "admissions-percentile must be > 50 and <= 99 but was %u, defaulting to 70\n",
108+
config->admissions_percentile);
109+
config->admissions_percentile = 70;
110+
}
111+
#endif
112+
113+
#ifdef EXECUTION_REGRESSION
114+
if (did_set[route_config_member_path_preprocess] == false) {
115+
fprintf(stderr, "model path_preprocess field is required. Put zero if just default preprocessing\n");
116+
return -1;
117+
} else if (strcmp(config->path_preprocess, "0") == 0) {
118+
config->path_preprocess = NULL;
119+
}
120+
121+
if (did_set[route_config_member_model_bias] == false) {
122+
fprintf(stderr, "model bias field is required\n");
123+
return -1;
124+
}
125+
126+
if (did_set[route_config_member_model_scale] == false) {
127+
fprintf(stderr, "model scale field is required\n");
128+
return -1;
129+
}
130+
131+
if (did_set[route_config_member_model_num_of_param] == false) {
132+
fprintf(stderr, "model num_of_param field is required\n");
133+
return -1;
134+
}
135+
136+
if (did_set[route_config_member_model_beta1] == false) {
137+
fprintf(stderr, "model beta1 field is required\n");
138+
return -1;
139+
}
140+
141+
if (did_set[route_config_member_model_beta2] == false) {
142+
fprintf(stderr, "model beta2 field is required. Put zero for just default preprocessing\n");
143+
return -1;
144+
}
106145

107-
#ifdef ADMISSIONS_CONTROL
108-
if (did_set[route_config_member_admissions_percentile] == false) {
109-
fprintf(stderr, "admissions_percentile is required\n");
146+
if (config->model_num_of_param < 1) {
147+
fprintf(stderr, "model num_of_param must be at least 1 (just default preprocessing)\n");
148+
return -1;
149+
} else if (config->model_num_of_param == 1) {
150+
if (config->path_preprocess) {
151+
fprintf(stderr, "model_num_of_param cannot be 1 when using tenant preprocessing\n");
110152
return -1;
111153
}
112-
113-
if (config->admissions_percentile > 99 || config->admissions_percentile < 50) {
114-
fprintf(stderr, "admissions-percentile must be > 50 and <= 99 but was %u\n",
115-
config->admissions_percentile);
154+
if (config->model_beta2 != 0) {
155+
fprintf(stderr, "model beta2 must be zero for just default preprocessing\n");
156+
return -1;
157+
}
158+
} else {
159+
/* For now we just support up to two params */
160+
assert(config->model_num_of_param == 2);
161+
if (config->path_preprocess == NULL) {
162+
fprintf(stderr, "model_num_of_param cannot be more than 1 when just default preprocessing\n");
116163
return -1;
117164
}
118-
#endif
119165
}
120-
166+
#endif
121167
return 0;
122168
}

runtime/include/route_config_parse.h

+12-15
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@
66
#include "json.h"
77
#include "route_config.h"
88

9-
static const char *route_config_json_keys[route_config_member_len] = { "route",
10-
"path",
11-
"path_premodule",
12-
"admissions-percentile",
13-
"relative-deadline-us",
14-
"model-bias",
15-
"model-scale",
16-
"model-num-of-param",
17-
"model-beta1",
18-
"model-beta2",
19-
"http-resp-content-type" };
9+
static const char *route_config_json_keys[route_config_member_len] = {
10+
"route", "path", "admissions-percentile", "relative-deadline-us",
11+
"path_preprocess", "model-bias", "model-scale", "model-num-of-param",
12+
"model-beta1", "model-beta2", "http-resp-content-type"
13+
};
2014

2115
static inline int
2216
route_config_set_key_once(bool *did_set, enum route_config_member member)
@@ -66,11 +60,11 @@ route_config_parse(struct route_config *config, const char *json_buf, jsmntok_t
6660
if (route_config_set_key_once(did_set, route_config_member_path) == -1) return -1;
6761

6862
config->path = strndup(json_buf + tokens[i].start, tokens[i].end - tokens[i].start);
69-
} else if (strcmp(key, route_config_json_keys[route_config_member_path_premodule]) == 0) {
63+
} else if (strcmp(key, route_config_json_keys[route_config_member_path_preprocess]) == 0) {
7064
if (!is_nonempty_string(tokens[i], key)) return -1;
71-
if (route_config_set_key_once(did_set, route_config_member_path_premodule) == -1) return -1;
65+
if (route_config_set_key_once(did_set, route_config_member_path_preprocess) == -1) return -1;
7266

73-
config->path_premodule = strndup(json_buf + tokens[i].start, tokens[i].end - tokens[i].start);
67+
config->path_preprocess = strndup(json_buf + tokens[i].start, tokens[i].end - tokens[i].start);
7468
} else if (strcmp(key, route_config_json_keys[route_config_member_admissions_percentile]) == 0) {
7569
if (!has_valid_type(tokens[i], key, JSMN_PRIMITIVE, json_buf)) return -1;
7670
if (route_config_set_key_once(did_set, route_config_member_admissions_percentile) == -1)
@@ -89,6 +83,9 @@ route_config_parse(struct route_config *config, const char *json_buf, jsmntok_t
8983
route_config_json_keys[route_config_member_relative_deadline_us],
9084
&config->relative_deadline_us);
9185
if (rc < 0) return -1;
86+
} else if (strcmp(key, "expected-execution-us") == 0) {
87+
if (!has_valid_type(tokens[i], key, JSMN_PRIMITIVE, json_buf)) return -1;
88+
printf("The \"expected-execution-us\" field has been deprecated, so no need.\n");
9289
} else if (strcmp(key, route_config_json_keys[route_config_member_model_bias]) == 0) {
9390
if (!has_valid_type(tokens[i], key, JSMN_PRIMITIVE, json_buf)) return -1;
9491
if (route_config_set_key_once(did_set, route_config_member_model_bias) == -1) return -1;
@@ -138,7 +135,7 @@ route_config_parse(struct route_config *config, const char *json_buf, jsmntok_t
138135
tokens[i].end - tokens[i].start);
139136
} else {
140137
fprintf(stderr, "%s is not a valid key\n", key);
141-
// return -1;
138+
return -1;
142139
}
143140
}
144141

runtime/include/tenant_config.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ tenant_config_print(struct tenant_config *config)
4545
{
4646
printf("[Tenant] Name: %s\n", config->name);
4747
printf("[Tenant] Path: %d\n", config->port);
48-
printf("[Tenant] Replenishment Period (us): %u\n", config->replenishment_period_us);
49-
printf("[Tenant] Max Budget (us): %u\n", config->max_budget_us);
48+
if (scheduler == SCHEDULER_MTDS) {
49+
printf("[Tenant] Replenishment Period (us): %u\n", config->replenishment_period_us);
50+
printf("[Tenant] Max Budget (us): %u\n", config->max_budget_us);
51+
}
5052
printf("[Tenant] Routes Size: %zu\n", config->routes_len);
5153
for (int i = 0; i < config->routes_len; i++) { route_config_print(&config->routes[i]); }
5254
}

runtime/include/tenant_config_parse.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ tenant_config_parse(struct tenant_config *config, const char *json_buf, jsmntok_
9696

9797
} else {
9898
fprintf(stderr, "%s is not a valid key\n", key);
99-
// return -1;
99+
return -1;
100100
}
101101
}
102102

runtime/include/tenant_functions.h

+18-15
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,30 @@ tenant_alloc(struct tenant_config *config)
115115

116116
assert(module != NULL);
117117

118-
struct module *pre_module = NULL;
118+
struct module *module_proprocess = NULL;
119119

120120
#ifdef EXECUTION_REGRESSION
121-
pre_module = module_database_find_by_path(&tenant->module_db, config->routes[i].path_premodule);
122-
if (pre_module == NULL) {
123-
/* Ownership of path moves here */
124-
pre_module = module_alloc(config->routes[i].path_premodule, PREPROCESS_MODULE);
125-
if (pre_module != NULL) {
126-
module_database_add(&tenant->module_db, pre_module);
127-
config->routes[i].path_premodule = NULL;
121+
if (config->routes[i].path_preprocess) {
122+
module_proprocess = module_database_find_by_path(&tenant->module_db,
123+
config->routes[i].path_preprocess);
124+
if (module_proprocess == NULL) {
125+
/* Ownership of path moves here */
126+
module_proprocess = module_alloc(config->routes[i].path_preprocess, PREPROCESS_MODULE);
127+
if (module_proprocess != NULL) {
128+
module_database_add(&tenant->module_db, module_proprocess);
129+
config->routes[i].path_preprocess = NULL;
130+
}
131+
} else {
132+
free(config->routes[i].path_preprocess);
133+
config->routes[i].path_preprocess = NULL;
128134
}
129-
} else {
130-
free(config->routes[i].path_premodule);
131-
config->routes[i].path_premodule = NULL;
132-
}
133135

134-
assert(pre_module != NULL);
136+
assert(module_proprocess != NULL);
137+
}
135138
#endif
136139

137140
/* Ownership of config's route and http_resp_content_type move here */
138-
int rc = http_router_add_route(&tenant->router, &config->routes[i], module, pre_module);
141+
int rc = http_router_add_route(&tenant->router, &config->routes[i], module, module_proprocess);
139142
if (unlikely(rc != 0)) {
140143
panic("Tenant %s defined %lu routes, but router failed to grow beyond %lu\n", tenant->name,
141144
config->routes_len, tenant->router.capacity);
@@ -181,4 +184,4 @@ get_next_timeout_of_tenant(uint64_t replenishment_period)
181184
*/
182185
int tenant_listen(struct tenant *tenant);
183186
int listener_thread_register_tenant(struct tenant *tenant);
184-
void tenant_preprocess(struct http_session *session);
187+
void tenant_preprocess(struct http_session *session);

runtime/src/tenant.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ tenant_listen(struct tenant *tenant)
2929
void
3030
tenant_preprocess(struct http_session *session)
3131
{
32+
/* No tenant preprocessing if the wasm module not provided by the tenant */
33+
if (session->route->module_proprocess == NULL) goto done;
3234
const uint64_t start = __getcycles();
3335

3436
/* Tenant Pre-processing - Extract other useful parameters */
35-
struct sandbox *pre_sandbox = sandbox_alloc(session->route->pre_module, session, session->route,
37+
struct sandbox *pre_sandbox = sandbox_alloc(session->route->module_proprocess, session, session->route,
3638
session->tenant, 1);
3739
if (sandbox_prepare_execution_environment(pre_sandbox)) panic("pre_sandbox environment setup failed");
3840
pre_sandbox->state = SANDBOX_RUNNING_SYS;
@@ -62,9 +64,10 @@ tenant_preprocess(struct http_session *session)
6264
sandbox_free_linear_memory(pre_sandbox);
6365
sandbox_free(pre_sandbox);
6466

65-
session->did_preprocessing = true;
66-
6767
const uint64_t end = __getcycles();
6868
session->preprocessing_duration = end - start;
69+
70+
done:
71+
session->did_preprocessing = true;
6972
}
70-
#endif
73+
#endif

tests/CMSIS_5_NN/imageclassification/spec.json

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
{
33
"name": "gwu",
44
"port": 10000,
5-
"replenishment-period-us": 0,
6-
"max-budget-us": 0,
75
"routes": [
86
{
97
"route": "/rand",

tests/TinyEKF/by_iteration/spec.json

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
{
33
"name": "gwu",
44
"port": 10000,
5-
"replenishment-period-us": 0,
6-
"max-budget-us": 0,
75
"routes": [
86
{
97
"route": "/ekf_first_iter",

tests/TinyEKF/one_iteration/spec.json

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
{
33
"name": "gwu",
44
"port": 10000,
5-
"replenishment-period-us": 0,
6-
"max-budget-us": 0,
75
"routes": [
86
{
97
"route": "/ekf",

0 commit comments

Comments
 (0)