Skip to content

Commit a230ad9

Browse files
committed
temp
1 parent 1c968ff commit a230ad9

File tree

2,086 files changed

+4731
-271
lines changed

Some content is hidden

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

2,086 files changed

+4731
-271
lines changed

.vscode/settings.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,14 @@
157157
"sledge_abi_symbols.h": "c",
158158
"mutex": "c",
159159
"lock.h": "c",
160-
"route_latency.h": "c"
160+
"route_latency.h": "c",
161+
"wasm_globals.h": "c",
162+
"*.bak": "c",
163+
"sandbox_set_as_initialized.h": "c",
164+
"sandbox_set_as_allocated.h": "c",
165+
"sandbox_total.h": "c",
166+
"system_error": "c",
167+
"metrics_server.h": "c"
161168
},
162169
"files.exclude": {
163170
"**/.git": true,

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ libsledge.clean:
3535
.PHONY: runtime
3636
runtime:
3737
make -C runtime
38-
38+
./rsync.sh
3939

4040
.PHONY: runtime.clean
4141
runtime.clean:

applications/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LDFLAGS=-shared -fPIC -Wl,--export-dynamic,--whole-archive -L../libsledge/dist/
1212
# LDFLAGS=-flto -fvisibility=hidden
1313

1414
# Strips out calls to assert() and disables debuglog
15-
CFLAGS+=-DNDEBUG
15+
# CFLAGS+=-DNDEBUG
1616

1717
dist:
1818
mkdir -p dist

libsledge/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ INCLUDES := -Iinclude/
55
CFLAGS := -fPIC -O3 -flto -ftls-model=initial-exec
66

77
# Strips out calls to assert() and disables debuglog
8-
CFLAGS+=-DNDEBUG
8+
# CFLAGS+=-DNDEBUG
99

1010
# CFI Sanitizer
1111
# CFLAGS+=-fvisibility=default -fsanitize=cfi

libsledge/include/sledge_abi.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct sledge_abi__wasm_memory {
2828
uint64_t capacity; /* Size backed by actual pages */
2929
uint64_t max; /* Soft cap in bytes. Defaults to 4GB */
3030
uint8_t *buffer; /* Backing heap allocation. Different lifetime because realloc might move this */
31+
uint64_t id;
3132
};
3233

3334
/* This structure is the runtime representation of the unique state of a module instance

libsledge/src/memory_instructions.c

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ INLINE float
1818
get_f32(uint32_t offset)
1919
{
2020
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
21+
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);
2122

2223
return *(float *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset];
2324
}
@@ -26,6 +27,7 @@ INLINE double
2627
get_f64(uint32_t offset)
2728
{
2829
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
30+
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);
2931

3032
return *(double *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset];
3133
}
@@ -34,6 +36,7 @@ INLINE int8_t
3436
get_i8(uint32_t offset)
3537
{
3638
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
39+
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);
3740

3841
return *(int8_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset];
3942
}
@@ -42,6 +45,7 @@ INLINE int16_t
4245
get_i16(uint32_t offset)
4346
{
4447
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
48+
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);
4549

4650
return *(int16_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset];
4751
}
@@ -50,6 +54,7 @@ INLINE int32_t
5054
get_i32(uint32_t offset)
5155
{
5256
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
57+
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);
5358

5459
return *(int32_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset];
5560
}
@@ -58,6 +63,7 @@ INLINE int64_t
5863
get_i64(uint32_t offset)
5964
{
6065
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
66+
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);
6167

6268
return *(int64_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset];
6369
}
@@ -67,6 +73,7 @@ INLINE void
6773
set_f32(uint32_t offset, float value)
6874
{
6975
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
76+
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);
7077

7178
*(float *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset] = value;
7279
}
@@ -75,6 +82,7 @@ INLINE void
7582
set_f64(uint32_t offset, double value)
7683
{
7784
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
85+
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);
7886

7987
*(double *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset] = value;
8088
}
@@ -83,6 +91,7 @@ INLINE void
8391
set_i8(uint32_t offset, int8_t value)
8492
{
8593
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
94+
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);
8695

8796
*(int8_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset] = value;
8897
}
@@ -91,6 +100,7 @@ INLINE void
91100
set_i16(uint32_t offset, int16_t value)
92101
{
93102
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
103+
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);
94104

95105
*(int16_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset] = value;
96106
}
@@ -99,6 +109,7 @@ INLINE void
99109
set_i32(uint32_t offset, int32_t value)
100110
{
101111
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
112+
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);
102113

103114
*(int32_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset] = value;
104115
}
@@ -107,6 +118,7 @@ INLINE void
107118
set_i64(uint32_t offset, int64_t value)
108119
{
109120
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
121+
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);
110122

111123
*(int64_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset] = value;
112124
}

rsync.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# rsync -ru --progress --exclude={'res','out.txt','out.dat','err.dat'} ./tests/* [email protected]:/users/emil/sledge-server/tests/
4+
# rsync -ru --progress --exclude={'res','out.txt','out.dat','err.dat'} ./tests/* [email protected]:/users/emil/sledge-client/tests/
5+
6+
# rsync -ru --progress --exclude={'thirdparty','res','err.dat','out*','*.log'} ./tests ./runtime [email protected]:/users/emil/sledge-server/
7+
# rsync -ru --progress --exclude={'res','err.dat','out*','*.log'} ./tests [email protected]:/users/emil/sledge-client/
8+
9+
rsync -ru --progress --exclude={'thirdparty','res-*','err.dat','out*','*.log','input*'} ./tests ./runtime [email protected]:/users/emil/sledge-server/
10+
rsync -ru --progress --exclude={'thirdparty','res-*','err.dat','out*','*.log','mt-juan/input-cnn','mt-emil/input-cnn'} ./tests ./runtime [email protected]:/users/emil/sledge-client/
11+
# rsync -ru --progress --exclude={'thirdparty','res-*','err.dat','out*','*.log','mt-juan/input-cnn','mt-emil/input-cnn'} ./tests ./runtime [email protected]:/users/emil/sledge-client/
12+
rsync -ru --progress --exclude={'thirdparty','res-*','err.dat','out*','*.log','input*'} ./tests ./runtime [email protected]:/users/emil/sledge-server/
13+
# rsync -ru --progress --exclude={'thirdparty','res-*','err.dat','out*','*.log'} ./tests ./runtime [email protected]:/users/emil/sledge-client/
14+
15+
# If on a network where only 443 is allowed use this (after allowing port forwarding ssh to 443 on the server):
16+
# rsync -ru -e 'ssh -p 443' --progress --exclude={'res','out.txt','out.dat','err.dat'} ./tests/* emil@server:/users/emil/sledge-server/tests/
17+
# rsync -ru -e 'ssh -p 443' --progress --exclude={'res','out.txt','out.dat','err.dat'} ./tests/* emil@client:/users/emil/sledge-client/tests/
18+
19+
20+
# lab-dell (don't forget to provide the private key in the config file inside .ssh folder)
21+
# rsync -ru --progress --exclude={'thirdparty','res-*','err.dat','out*','*.log'} ./tests ./runtime [email protected]:/home/lab/sledge-emil/
22+
23+
# CMU (don't forget to provide the private key in the config file inside .ssh folder)
24+
# rsync -ru --progress --exclude={'thirdparty','res','err.dat','out*','*.log'} ./tests ./runtime [email protected]:/home/gwu/sledge/
25+
26+
# esma
27+
# rsync -ru --progress --exclude={'thirdparty','res-*','err.dat','out*','*.log'} ./tests [email protected]:/home/emil/sledge-client/

runtime/Makefile

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ CFLAGS=-std=c18 -pthread
1414
CFLAGS+=-D_GNU_SOURCE
1515

1616
# Release Flags
17-
CFLAGS+=-O3 -flto
17+
# CFLAGS+=-O3 -flto
1818

1919
# Debugging Flags
20-
# CFLAGS+=-O0 -g3
20+
CFLAGS+=-O0 -g3
2121

2222
# CFI Sanitizer
2323
# CFLAGS+=-fvisibility=default -fsanitize=cfi
@@ -43,6 +43,7 @@ CFLAGS += -DEXECUTION_HISTOGRAM
4343

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

4748
# Debugging Flags
4849

@@ -62,6 +63,7 @@ CFLAGS += -DEXECUTION_HISTOGRAM
6263
# Various Informational Logs for Debugging
6364
# CFLAGS += -DLOG_EXECUTION_HISTOGRAM
6465
# CFLAGS += -DLOG_ADMISSIONS_CONTROL
66+
# CFLAGS += -DLOG_TRAFFIC_CONTROL
6567
# CFLAGS += -DLOG_CONTEXT_SWITCHES
6668
# CFLAGS += -DLOG_HTTP_PARSER
6769
# CFLAGS += -DLOG_TENANT_LOADING
@@ -74,7 +76,7 @@ CFLAGS += -DEXECUTION_HISTOGRAM
7476

7577
# This adds an array of sandbox states to all sandbox structs and appends states at each transition
7678
# The history trucates when the number of elements equal SANDBOX_STATE_HISTORY_CAPACITY
77-
# CFLAGS += -DLOG_STATE_CHANGES
79+
CFLAGS += -DLOG_STATE_CHANGES
7880

7981
# This dumps per module *.csv files containing the cycle a sandbox has been in RUNNING when each
8082
# page is allocated. This helps understand the relationship to memory allocation and execution time.

runtime/include/arch/x86_64/context.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ arch_context_restore_fast(mcontext_t *active_context, struct arch_context *sandb
5656
assert(sandbox_context != NULL);
5757

5858
/* Assumption: Base Context is only ever used by arch_context_switch */
59-
assert(sandbox_context != &worker_thread_base_context);
59+
// assert(sandbox_context != &worker_thread_base_context);
60+
/* Assumption: Not switching to the same context */
61+
assert(active_context != &sandbox_context->mctx);
6062

6163
assert(sandbox_context->regs[UREG_SP]);
6264
assert(sandbox_context->regs[UREG_IP]);

runtime/include/current_sandbox.h

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
extern thread_local struct sandbox *worker_thread_current_sandbox;
1111

1212
void current_sandbox_start(void);
13+
void current_sandbox_exit(void);
14+
void interrupted_sandbox_exit(void);
15+
int sandbox_validate_self_lifetime(struct sandbox *);
16+
void sandbox_kill_self(struct sandbox *);
1317

1418
/**
1519
* Getter for the current sandbox executing on this thread
@@ -51,16 +55,27 @@ current_sandbox_set(struct sandbox *sandbox)
5155
/* This is because the event core does not maintain core-assigned deadline */
5256
if (!listener_thread_is_running()) runtime_worker_threads_deadline[worker_thread_idx] = UINT64_MAX;
5357
} else {
58+
assert(sandbox->state == SANDBOX_RUNNABLE || sandbox->state == SANDBOX_PREEMPTED);
59+
// if(sandbox->state == SANDBOX_PREEMPTED && sandbox->original_owner_worker_idx != worker_thread_idx) printf("SAND_id: %lu, WASM_id: %lu, wrk: %d\n", sandbox->id, sledge_abi__current_wasm_module_instance.abi.memory.id, worker_thread_idx);
60+
// else
61+
// printf("Else SAND_id: %lu, WASM_id: %lu, wrk: %d, orig_wrk %d\n", sandbox->id, sledge_abi__current_wasm_module_instance.abi.memory.id, worker_thread_idx, sandbox->original_owner_worker_idx);
5462
sledge_abi__current_wasm_module_instance.wasi_context = sandbox->wasi_context;
63+
assert(sandbox->memory->abi.capacity > 0);
64+
assert(sandbox->memory->abi.size > 0);
65+
assert(sandbox->memory->abi.max > 0);
5566
memcpy(&sledge_abi__current_wasm_module_instance.abi.memory, &sandbox->memory->abi,
5667
sizeof(struct sledge_abi__wasm_memory));
68+
assert(sledge_abi__current_wasm_module_instance.abi.memory.size == sandbox->memory->abi.size);
69+
assert(sledge_abi__current_wasm_module_instance.abi.memory.id == sandbox->id);
5770
sledge_abi__current_wasm_module_instance.abi.table = sandbox->module->indirect_table;
5871
wasm_globals_update_if_used(&sandbox->globals, 0,
5972
&sledge_abi__current_wasm_module_instance.abi.wasmg_0);
6073
worker_thread_current_sandbox = sandbox;
74+
6175
if (!listener_thread_is_running())
6276
runtime_worker_threads_deadline[worker_thread_idx] = sandbox->absolute_deadline;
6377
}
78+
barrier();
6479
}
6580

6681
extern void current_sandbox_sleep();

runtime/include/dbf.h

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#pragma once
2+
3+
#include <stdlib.h>
4+
#include "tenant.h"
5+
#include "message.h"
6+
7+
#define DBF_USE_LINKEDLIST
8+
// static const bool USING_AGGREGATED_GLOBAL_DBF = true;
9+
10+
/* Returns pointer back if successful, null otherwise */
11+
// extern void *global_dbf;
12+
extern void **global_virt_worker_dbfs;
13+
extern void *global_worker_dbf;
14+
15+
struct demand_node {
16+
struct ps_list list;
17+
uint64_t abs_deadline;
18+
uint64_t demand;
19+
// uint64_t demand_sum;
20+
// struct sandbox_metadata *sandbox_meta;
21+
struct tenant *tenant;
22+
};
23+
24+
typedef enum dbf_update_mode
25+
{
26+
DBF_CHECK_AND_ADD_DEMAND, /* normal mode for adding new sandbox demands */
27+
DBF_FORCE_ADD_NEW_SANDBOX_DEMAND, /* work-conservation mode*/
28+
DBF_FORCE_ADD_MANUAL_DEMAND, /* work-conservation mode*/
29+
DBF_REDUCE_EXISTING_DEMAND, /* normal mode for reducing existing sandbox demands */
30+
// DBF_CHECK_EXISTING_SANDBOX_EXTRA_DEMAND, /* special case when a sandbox goes over its expected exec */
31+
DBF_DELETE_EXISTING_DEMAND /* normal mode for removing existing sandbox demand */
32+
} dbf_update_mode_t;
33+
34+
typedef int (*dbf_get_worker_idx_fn_t)(void *);
35+
typedef uint64_t (*dbf_get_time_of_oversupply_fn_t)(void *);
36+
typedef void (*dbf_print_fn_t)(void *, uint64_t);
37+
typedef bool (*dbf_try_update_demand_fn_t)(void *, uint64_t, uint64_t, uint64_t, uint64_t, dbf_update_mode_t, void *, struct sandbox_metadata *sandbox_meta);
38+
typedef uint64_t (*dbf_get_demand_overgone_its_supply_at_fn_t)(void *, uint64_t, uint64_t, uint64_t);
39+
typedef void (*dbf_free_fn_t)(void *);
40+
41+
struct dbf_config {
42+
dbf_get_worker_idx_fn_t get_worker_idx_fn;
43+
// dbf_get_max_relative_dl_fn_t get_max_relative_dl_fn;
44+
dbf_get_time_of_oversupply_fn_t get_time_of_oversupply_fn;
45+
dbf_print_fn_t print_fn;
46+
// dbf_grow_fn_t grow_fn;
47+
dbf_try_update_demand_fn_t try_update_demand_fn;
48+
dbf_get_demand_overgone_its_supply_at_fn_t get_demand_overgone_its_supply_at_fn;
49+
dbf_free_fn_t free_fn;
50+
};
51+
52+
int dbf_get_worker_idx(void *);
53+
// uint64_t dbf_get_max_relative_dl(void *);
54+
uint64_t dbf_get_time_of_oversupply(void *);
55+
void dbf_print(void *, uint64_t);
56+
// void *dbf_grow(void *, uint64_t);
57+
bool dbf_try_update_demand(void *, uint64_t, uint64_t, uint64_t, uint64_t, dbf_update_mode_t, void *, struct sandbox_metadata *sandbox_meta);
58+
uint64_t dbf_get_demand_overgone_its_supply_at(void *, uint64_t, uint64_t, uint64_t);
59+
void dbf_free(void *);
60+
61+
void dbf_plug_functions(struct dbf_config *config);
62+
63+
void *dbf_list_initialize(uint32_t, uint8_t, int, struct tenant *);
64+
void *dbf_array_initialize(uint32_t, uint8_t, int, struct tenant *);
65+
void *dbf_initialize(uint32_t num_of_workers, uint8_t reservation_percentile, int worker_idx, struct tenant *tenant);
66+
67+
68+
bool
69+
dbf_list_try_add_new_demand(void *dbf_raw, uint64_t start_time, uint64_t abs_deadline, uint64_t adjustment, struct sandbox_metadata *sm);
70+
71+
void
72+
dbf_list_force_add_extra_slack(void *dbf_raw, struct sandbox_metadata *sm, uint64_t adjustment);
73+
74+
void
75+
dbf_list_reduce_demand(struct sandbox_metadata *sm, uint64_t adjustment, bool delete_node);

runtime/include/global_request_scheduler.h

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <stdint.h>
44

55
#include "sandbox_types.h"
6+
#include "sandbox_functions.h"
67

78
/* Returns pointer back if successful, null otherwise */
89
typedef struct sandbox *(*global_request_scheduler_add_fn_t)(struct sandbox *);
@@ -18,8 +19,13 @@ struct global_request_scheduler_config {
1819
};
1920

2021

21-
void global_request_scheduler_initialize(struct global_request_scheduler_config *config);
22-
struct sandbox *global_request_scheduler_add(struct sandbox *);
23-
int global_request_scheduler_remove(struct sandbox **);
24-
int global_request_scheduler_remove_if_earlier(struct sandbox **, uint64_t targed_deadline);
25-
uint64_t global_request_scheduler_peek(void);
22+
void global_request_scheduler_initialize(struct global_request_scheduler_config *config);
23+
struct sandbox *global_request_scheduler_add(struct sandbox *);
24+
int global_request_scheduler_remove(struct sandbox **);
25+
int global_request_scheduler_remove_if_earlier(struct sandbox **, uint64_t targed_deadline);
26+
uint64_t global_request_scheduler_peek(void);
27+
void global_request_scheduler_update_highest_priority(const void *element);
28+
struct sandbox_metadata global_request_scheduler_peek_metadata();
29+
// struct sandbox_metadata global_request_scheduler_peek_metadata_must_lock(const uint64_t now, struct sandbox *);
30+
void global_default_update_highest_priority(const void *element);
31+
struct sandbox_metadata global_default_peek_metadata();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include "global_request_scheduler.h"
4+
5+
void global_request_scheduler_mtdbf_initialize();

0 commit comments

Comments
 (0)