Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
emil916 committed Jun 25, 2024
1 parent 1c968ff commit a230ad9
Show file tree
Hide file tree
Showing 2,086 changed files with 4,731 additions and 271 deletions.
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,14 @@
"sledge_abi_symbols.h": "c",
"mutex": "c",
"lock.h": "c",
"route_latency.h": "c"
"route_latency.h": "c",
"wasm_globals.h": "c",
"*.bak": "c",
"sandbox_set_as_initialized.h": "c",
"sandbox_set_as_allocated.h": "c",
"sandbox_total.h": "c",
"system_error": "c",
"metrics_server.h": "c"
},
"files.exclude": {
"**/.git": true,
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ libsledge.clean:
.PHONY: runtime
runtime:
make -C runtime

./rsync.sh

.PHONY: runtime.clean
runtime.clean:
Expand Down
2 changes: 1 addition & 1 deletion applications/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LDFLAGS=-shared -fPIC -Wl,--export-dynamic,--whole-archive -L../libsledge/dist/
# LDFLAGS=-flto -fvisibility=hidden

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

dist:
mkdir -p dist
Expand Down
2 changes: 1 addition & 1 deletion libsledge/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ INCLUDES := -Iinclude/
CFLAGS := -fPIC -O3 -flto -ftls-model=initial-exec

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

# CFI Sanitizer
# CFLAGS+=-fvisibility=default -fsanitize=cfi
Expand Down
1 change: 1 addition & 0 deletions libsledge/include/sledge_abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct sledge_abi__wasm_memory {
uint64_t capacity; /* Size backed by actual pages */
uint64_t max; /* Soft cap in bytes. Defaults to 4GB */
uint8_t *buffer; /* Backing heap allocation. Different lifetime because realloc might move this */
uint64_t id;
};

/* This structure is the runtime representation of the unique state of a module instance
Expand Down
12 changes: 12 additions & 0 deletions libsledge/src/memory_instructions.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ INLINE float
get_f32(uint32_t offset)
{
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);

return *(float *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset];
}
Expand All @@ -26,6 +27,7 @@ INLINE double
get_f64(uint32_t offset)
{
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);

return *(double *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset];
}
Expand All @@ -34,6 +36,7 @@ INLINE int8_t
get_i8(uint32_t offset)
{
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);

return *(int8_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset];
}
Expand All @@ -42,6 +45,7 @@ INLINE int16_t
get_i16(uint32_t offset)
{
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);

return *(int16_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset];
}
Expand All @@ -50,6 +54,7 @@ INLINE int32_t
get_i32(uint32_t offset)
{
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);

return *(int32_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset];
}
Expand All @@ -58,6 +63,7 @@ INLINE int64_t
get_i64(uint32_t offset)
{
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);

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

*(float *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset] = value;
}
Expand All @@ -75,6 +82,7 @@ INLINE void
set_f64(uint32_t offset, double value)
{
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);

*(double *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset] = value;
}
Expand All @@ -83,6 +91,7 @@ INLINE void
set_i8(uint32_t offset, int8_t value)
{
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);

*(int8_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset] = value;
}
Expand All @@ -91,6 +100,7 @@ INLINE void
set_i16(uint32_t offset, int16_t value)
{
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);

*(int16_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset] = value;
}
Expand All @@ -99,6 +109,7 @@ INLINE void
set_i32(uint32_t offset, int32_t value)
{
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);

*(int32_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset] = value;
}
Expand All @@ -107,6 +118,7 @@ INLINE void
set_i64(uint32_t offset, int64_t value)
{
assert(sledge_abi__current_wasm_module_instance.memory.buffer != NULL);
assert(offset < sledge_abi__current_wasm_module_instance.memory.size);

*(int64_t *)&sledge_abi__current_wasm_module_instance.memory.buffer[offset] = value;
}
Expand Down
27 changes: 27 additions & 0 deletions rsync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# rsync -ru --progress --exclude={'res','out.txt','out.dat','err.dat'} ./tests/* [email protected]:/users/emil/sledge-server/tests/
# rsync -ru --progress --exclude={'res','out.txt','out.dat','err.dat'} ./tests/* [email protected]:/users/emil/sledge-client/tests/

# rsync -ru --progress --exclude={'thirdparty','res','err.dat','out*','*.log'} ./tests ./runtime [email protected]:/users/emil/sledge-server/
# rsync -ru --progress --exclude={'res','err.dat','out*','*.log'} ./tests [email protected]:/users/emil/sledge-client/

rsync -ru --progress --exclude={'thirdparty','res-*','err.dat','out*','*.log','input*'} ./tests ./runtime [email protected]:/users/emil/sledge-server/
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/
# 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/
rsync -ru --progress --exclude={'thirdparty','res-*','err.dat','out*','*.log','input*'} ./tests ./runtime [email protected]:/users/emil/sledge-server/
# rsync -ru --progress --exclude={'thirdparty','res-*','err.dat','out*','*.log'} ./tests ./runtime [email protected]:/users/emil/sledge-client/

# If on a network where only 443 is allowed use this (after allowing port forwarding ssh to 443 on the server):
# rsync -ru -e 'ssh -p 443' --progress --exclude={'res','out.txt','out.dat','err.dat'} ./tests/* emil@server:/users/emil/sledge-server/tests/
# rsync -ru -e 'ssh -p 443' --progress --exclude={'res','out.txt','out.dat','err.dat'} ./tests/* emil@client:/users/emil/sledge-client/tests/


# lab-dell (don't forget to provide the private key in the config file inside .ssh folder)
# rsync -ru --progress --exclude={'thirdparty','res-*','err.dat','out*','*.log'} ./tests ./runtime [email protected]:/home/lab/sledge-emil/

# CMU (don't forget to provide the private key in the config file inside .ssh folder)
# rsync -ru --progress --exclude={'thirdparty','res','err.dat','out*','*.log'} ./tests ./runtime [email protected]:/home/gwu/sledge/

# esma
# rsync -ru --progress --exclude={'thirdparty','res-*','err.dat','out*','*.log'} ./tests [email protected]:/home/emil/sledge-client/
8 changes: 5 additions & 3 deletions runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ CFLAGS=-std=c18 -pthread
CFLAGS+=-D_GNU_SOURCE

# Release Flags
CFLAGS+=-O3 -flto
# CFLAGS+=-O3 -flto

# Debugging Flags
# CFLAGS+=-O0 -g3
CFLAGS+=-O0 -g3

# CFI Sanitizer
# CFLAGS+=-fvisibility=default -fsanitize=cfi
Expand All @@ -43,6 +43,7 @@ CFLAGS += -DEXECUTION_HISTOGRAM

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

# Debugging Flags

Expand All @@ -62,6 +63,7 @@ CFLAGS += -DEXECUTION_HISTOGRAM
# Various Informational Logs for Debugging
# CFLAGS += -DLOG_EXECUTION_HISTOGRAM
# CFLAGS += -DLOG_ADMISSIONS_CONTROL
# CFLAGS += -DLOG_TRAFFIC_CONTROL
# CFLAGS += -DLOG_CONTEXT_SWITCHES
# CFLAGS += -DLOG_HTTP_PARSER
# CFLAGS += -DLOG_TENANT_LOADING
Expand All @@ -74,7 +76,7 @@ CFLAGS += -DEXECUTION_HISTOGRAM

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

# This dumps per module *.csv files containing the cycle a sandbox has been in RUNNING when each
# page is allocated. This helps understand the relationship to memory allocation and execution time.
Expand Down
4 changes: 3 additions & 1 deletion runtime/include/arch/x86_64/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ arch_context_restore_fast(mcontext_t *active_context, struct arch_context *sandb
assert(sandbox_context != NULL);

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

assert(sandbox_context->regs[UREG_SP]);
assert(sandbox_context->regs[UREG_IP]);
Expand Down
15 changes: 15 additions & 0 deletions runtime/include/current_sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
extern thread_local struct sandbox *worker_thread_current_sandbox;

void current_sandbox_start(void);
void current_sandbox_exit(void);
void interrupted_sandbox_exit(void);
int sandbox_validate_self_lifetime(struct sandbox *);
void sandbox_kill_self(struct sandbox *);

/**
* Getter for the current sandbox executing on this thread
Expand Down Expand Up @@ -51,16 +55,27 @@ current_sandbox_set(struct sandbox *sandbox)
/* 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 {
assert(sandbox->state == SANDBOX_RUNNABLE || sandbox->state == SANDBOX_PREEMPTED);
// 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);
// else
// 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);
sledge_abi__current_wasm_module_instance.wasi_context = sandbox->wasi_context;
assert(sandbox->memory->abi.capacity > 0);
assert(sandbox->memory->abi.size > 0);
assert(sandbox->memory->abi.max > 0);
memcpy(&sledge_abi__current_wasm_module_instance.abi.memory, &sandbox->memory->abi,
sizeof(struct sledge_abi__wasm_memory));
assert(sledge_abi__current_wasm_module_instance.abi.memory.size == sandbox->memory->abi.size);
assert(sledge_abi__current_wasm_module_instance.abi.memory.id == sandbox->id);
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;

if (!listener_thread_is_running())
runtime_worker_threads_deadline[worker_thread_idx] = sandbox->absolute_deadline;
}
barrier();
}

extern void current_sandbox_sleep();
Expand Down
75 changes: 75 additions & 0 deletions runtime/include/dbf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#pragma once

#include <stdlib.h>
#include "tenant.h"
#include "message.h"

#define DBF_USE_LINKEDLIST
// static const bool USING_AGGREGATED_GLOBAL_DBF = true;

/* Returns pointer back if successful, null otherwise */
// extern void *global_dbf;
extern void **global_virt_worker_dbfs;
extern void *global_worker_dbf;

struct demand_node {
struct ps_list list;
uint64_t abs_deadline;
uint64_t demand;
// uint64_t demand_sum;
// struct sandbox_metadata *sandbox_meta;
struct tenant *tenant;
};

typedef enum dbf_update_mode
{
DBF_CHECK_AND_ADD_DEMAND, /* normal mode for adding new sandbox demands */
DBF_FORCE_ADD_NEW_SANDBOX_DEMAND, /* work-conservation mode*/
DBF_FORCE_ADD_MANUAL_DEMAND, /* work-conservation mode*/
DBF_REDUCE_EXISTING_DEMAND, /* normal mode for reducing existing sandbox demands */
// DBF_CHECK_EXISTING_SANDBOX_EXTRA_DEMAND, /* special case when a sandbox goes over its expected exec */
DBF_DELETE_EXISTING_DEMAND /* normal mode for removing existing sandbox demand */
} dbf_update_mode_t;

typedef int (*dbf_get_worker_idx_fn_t)(void *);
typedef uint64_t (*dbf_get_time_of_oversupply_fn_t)(void *);
typedef void (*dbf_print_fn_t)(void *, uint64_t);
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);
typedef uint64_t (*dbf_get_demand_overgone_its_supply_at_fn_t)(void *, uint64_t, uint64_t, uint64_t);
typedef void (*dbf_free_fn_t)(void *);

struct dbf_config {
dbf_get_worker_idx_fn_t get_worker_idx_fn;
// dbf_get_max_relative_dl_fn_t get_max_relative_dl_fn;
dbf_get_time_of_oversupply_fn_t get_time_of_oversupply_fn;
dbf_print_fn_t print_fn;
// dbf_grow_fn_t grow_fn;
dbf_try_update_demand_fn_t try_update_demand_fn;
dbf_get_demand_overgone_its_supply_at_fn_t get_demand_overgone_its_supply_at_fn;
dbf_free_fn_t free_fn;
};

int dbf_get_worker_idx(void *);
// uint64_t dbf_get_max_relative_dl(void *);
uint64_t dbf_get_time_of_oversupply(void *);
void dbf_print(void *, uint64_t);
// void *dbf_grow(void *, uint64_t);
bool dbf_try_update_demand(void *, uint64_t, uint64_t, uint64_t, uint64_t, dbf_update_mode_t, void *, struct sandbox_metadata *sandbox_meta);
uint64_t dbf_get_demand_overgone_its_supply_at(void *, uint64_t, uint64_t, uint64_t);
void dbf_free(void *);

void dbf_plug_functions(struct dbf_config *config);

void *dbf_list_initialize(uint32_t, uint8_t, int, struct tenant *);
void *dbf_array_initialize(uint32_t, uint8_t, int, struct tenant *);
void *dbf_initialize(uint32_t num_of_workers, uint8_t reservation_percentile, int worker_idx, struct tenant *tenant);


bool
dbf_list_try_add_new_demand(void *dbf_raw, uint64_t start_time, uint64_t abs_deadline, uint64_t adjustment, struct sandbox_metadata *sm);

void
dbf_list_force_add_extra_slack(void *dbf_raw, struct sandbox_metadata *sm, uint64_t adjustment);

void
dbf_list_reduce_demand(struct sandbox_metadata *sm, uint64_t adjustment, bool delete_node);
16 changes: 11 additions & 5 deletions runtime/include/global_request_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdint.h>

#include "sandbox_types.h"
#include "sandbox_functions.h"

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


void global_request_scheduler_initialize(struct global_request_scheduler_config *config);
struct sandbox *global_request_scheduler_add(struct sandbox *);
int global_request_scheduler_remove(struct sandbox **);
int global_request_scheduler_remove_if_earlier(struct sandbox **, uint64_t targed_deadline);
uint64_t global_request_scheduler_peek(void);
void global_request_scheduler_initialize(struct global_request_scheduler_config *config);
struct sandbox *global_request_scheduler_add(struct sandbox *);
int global_request_scheduler_remove(struct sandbox **);
int global_request_scheduler_remove_if_earlier(struct sandbox **, uint64_t targed_deadline);
uint64_t global_request_scheduler_peek(void);
void global_request_scheduler_update_highest_priority(const void *element);
struct sandbox_metadata global_request_scheduler_peek_metadata();
// struct sandbox_metadata global_request_scheduler_peek_metadata_must_lock(const uint64_t now, struct sandbox *);
void global_default_update_highest_priority(const void *element);
struct sandbox_metadata global_default_peek_metadata();
5 changes: 5 additions & 0 deletions runtime/include/global_request_scheduler_mtdbf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include "global_request_scheduler.h"

void global_request_scheduler_mtdbf_initialize();
Loading

0 comments on commit a230ad9

Please sign in to comment.