Merge branch 'master' into writeback-on-block

master
Sean McBride 3 years ago committed by GitHub
commit 859b16d893
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -122,7 +122,8 @@
"scheduler_options.h": "c",
"route_config_parse.h": "c",
"route.h": "c",
"pool.h": "c"
"pool.h": "c",
"local_cleanup_queue.h": "c"
},
"files.exclude": {
"**/.git": true,

@ -0,0 +1,7 @@
#pragma once
#include "sandbox_types.h"
void local_cleanup_queue_add(struct sandbox *sandbox);
void local_cleanup_queue_free();
void local_cleanup_queue_initialize();

@ -1,8 +0,0 @@
#pragma once
#include "ps_list.h"
#include "sandbox_types.h"
void local_completion_queue_add(struct sandbox *sandbox);
void local_completion_queue_free();
void local_completion_queue_initialize();

@ -5,7 +5,6 @@
#include "arch/getcycles.h"
#include "panic.h"
#include "local_completion_queue.h"
#include "sandbox_functions.h"
#include "sandbox_perf_log.h"
#include "sandbox_state.h"
@ -16,7 +15,6 @@
/**
* Transitions a sandbox from the SANDBOX_RETURNED state to the SANDBOX_COMPLETE state.
* Adds the sandbox to the completion queue
* @param sandbox
* @param last_state the state the sandbox is transitioning from. This is expressed as a constant to
* enable the compiler to perform constant propagation optimizations.
@ -61,7 +59,7 @@ sandbox_set_as_complete(struct sandbox *sandbox, sandbox_state_t last_state)
sandbox_state_transition_from_hook(sandbox, last_state);
sandbox_state_transition_to_hook(sandbox, SANDBOX_COMPLETE);
/* Does not add to completion queue until in cooperative scheduler */
/* Does not add to cleanup queue until in cooperative scheduler */
}
static inline void

@ -18,7 +18,7 @@
/**
* Transitions a sandbox to the SANDBOX_ERROR state.
* This can occur during initialization or execution
* Unmaps linear memory, removes from the runqueue (if on it), and adds to the completion queue
* Unmaps linear memory, removes from the runqueue (if on it)
* Because the stack is still in use, freeing the stack is deferred until later
*
* @param sandbox the sandbox erroring out
@ -72,7 +72,7 @@ sandbox_set_as_error(struct sandbox *sandbox, sandbox_state_t last_state)
sandbox_state_transition_from_hook(sandbox, last_state);
sandbox_state_transition_to_hook(sandbox, SANDBOX_ERROR);
/* Does not add to completion queue until in cooperative scheduler */
/* Does not add to cleanup queue until in cooperative scheduler */
}
static inline void

@ -11,6 +11,7 @@
#include "local_runqueue.h"
#include "local_runqueue_minheap.h"
#include "local_runqueue_list.h"
#include "local_cleanup_queue.h"
#include "panic.h"
#include "sandbox_functions.h"
#include "sandbox_types.h"
@ -319,20 +320,20 @@ scheduler_idle_loop()
scheduler_cooperative_switch_to(&worker_thread_base_context, next_sandbox);
}
/* Clear the completion queue */
local_completion_queue_free();
/* Clear the cleanup queue */
local_cleanup_queue_free();
}
}
/**
* @brief Used to cooperative switch sandboxes when a sandbox sleeps or exits
* Because of use-after-free bugs that interfere with our loggers, when a sandbox exits and switches away never to
* return, the boolean add_to_completion_queue needs to be set to true. Otherwise, we will leak sandboxes.
* @param add_to_completion_queue - Indicates that the sandbox should be added to the completion queue before switching
* return, the boolean add_to_cleanup_queue needs to be set to true. Otherwise, we will leak sandboxes.
* @param add_to_cleanup_queue - Indicates that the sandbox should be added to the cleanup queue before switching
* away
*/
static inline void
scheduler_cooperative_sched(bool add_to_completion_queue)
scheduler_cooperative_sched(bool add_to_cleanup_queue)
{
struct sandbox *exiting_sandbox = current_sandbox_get();
assert(exiting_sandbox != NULL);
@ -353,8 +354,8 @@ scheduler_cooperative_sched(bool add_to_completion_queue)
/* Try to wakeup sleeping sandboxes */
scheduler_execute_epoll_loop();
/* We have not added ourself to the completion queue, so we can free */
local_completion_queue_free();
/* We have not added ourself to the cleanup queue, so we can free */
local_cleanup_queue_free();
/* Switch to a sandbox if one is ready to run */
struct sandbox *next_sandbox = scheduler_get_next();
@ -371,7 +372,7 @@ scheduler_cooperative_sched(bool add_to_completion_queue)
// Write back global at idx 0
wasm_globals_set_i64(&exiting_sandbox->globals, 0, sledge_abi__current_wasm_module_instance.abi.wasmg_0, true);
if (add_to_completion_queue) local_completion_queue_add(exiting_sandbox);
if (add_to_cleanup_queue) local_cleanup_queue_add(exiting_sandbox);
/* Do not touch sandbox struct after this point! */
if (next_sandbox != NULL) {

@ -0,0 +1,51 @@
#include <threads.h>
#include "local_cleanup_queue.h"
#include "sandbox_functions.h"
/* Must be the same alignment as sandbox structs because of how the ps_list macros work */
thread_local static struct ps_list_head local_cleanup_queue PAGE_ALIGNED;
void
local_cleanup_queue_initialize()
{
ps_list_head_init(&local_cleanup_queue);
}
static inline bool
local_cleanup_queue_is_empty()
{
return ps_list_head_empty(&local_cleanup_queue);
}
/**
* Adds sandbox to the cleanup queue
* @param sandbox to add to cleanup queue
*/
void
local_cleanup_queue_add(struct sandbox *sandbox)
{
assert(sandbox);
assert(ps_list_singleton_d(sandbox));
ps_list_head_append_d(&local_cleanup_queue, sandbox);
assert(!local_cleanup_queue_is_empty());
}
/**
* @brief Frees all sandboxes in the thread local cleanup queue
* @return void
*/
void
local_cleanup_queue_free()
{
struct sandbox *sandbox_iterator = NULL;
struct sandbox *buffer = NULL;
ps_list_foreach_del_d(&local_cleanup_queue, sandbox_iterator, buffer)
{
ps_list_rem_d(sandbox_iterator);
sandbox_free(sandbox_iterator);
}
}

@ -1,51 +0,0 @@
#include <threads.h>
#include "local_completion_queue.h"
#include "sandbox_functions.h"
/* Must be the same alignment as sandbox structs because of how the ps_list macros work */
thread_local static struct ps_list_head local_completion_queue PAGE_ALIGNED;
void
local_completion_queue_initialize()
{
ps_list_head_init(&local_completion_queue);
}
static inline bool
local_completion_queue_is_empty()
{
return ps_list_head_empty(&local_completion_queue);
}
/**
* Adds sandbox to the completion queue
* @param sandbox to add to completion queue
*/
void
local_completion_queue_add(struct sandbox *sandbox)
{
assert(sandbox);
assert(ps_list_singleton_d(sandbox));
ps_list_head_append_d(&local_completion_queue, sandbox);
assert(!local_completion_queue_is_empty());
}
/**
* @brief Frees all sandboxes in the thread local completion queue
* @return void
*/
void
local_completion_queue_free()
{
struct sandbox *sandbox_iterator = NULL;
struct sandbox *buffer = NULL;
ps_list_foreach_del_d(&local_completion_queue, sandbox_iterator, buffer)
{
ps_list_rem_d(sandbox_iterator);
sandbox_free(sandbox_iterator);
}
}

@ -7,7 +7,7 @@
#include <threads.h>
#include "current_sandbox.h"
#include "local_completion_queue.h"
#include "local_cleanup_queue.h"
#include "local_runqueue.h"
#include "local_runqueue_list.h"
#include "local_runqueue_minheap.h"
@ -52,8 +52,8 @@ worker_thread_main(void *argument)
scheduler_runqueue_initialize();
/* Initialize Completion Queue */
local_completion_queue_initialize();
/* Initialize Cleanup Queue */
local_cleanup_queue_initialize();
/* Initialize epoll */
worker_thread_epoll_file_descriptor = epoll_create1(0);

Loading…
Cancel
Save