remove epoll from workers (#365)

master
Emil 2 years ago committed by GitHub
parent 7b9b28f5d8
commit beed67cea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -126,7 +126,8 @@
"local_cleanup_queue.h": "c",
"sandbox_state_transition.h": "c",
"http_session_perf_log.h": "c",
"perf_window.h": "c"
"perf_window.h": "c",
"global_request_scheduler_deque.h": "c"
},
"files.exclude": {
"**/.git": true,

@ -22,7 +22,6 @@
#include "sandbox_set_as_running_sys.h"
#include "sandbox_set_as_interrupted.h"
#include "sandbox_set_as_running_user.h"
#include "scheduler_execute_epoll_loop.h"
#include "scheduler_options.h"
@ -313,7 +312,6 @@ scheduler_preemptive_sched(ucontext_t *interrupted_context)
assert(interrupted_context != NULL);
/* Process epoll to make sure that all runnable jobs are considered for execution */
scheduler_execute_epoll_loop();
struct sandbox *interrupted_sandbox = current_sandbox_get();
assert(interrupted_sandbox != NULL);
@ -401,9 +399,6 @@ scheduler_idle_loop()
/* Deferred signals should have been cleared by this point */
assert(deferred_sigalrm == 0);
/* Try to wakeup sleeping sandboxes */
scheduler_execute_epoll_loop();
/* Switch to a sandbox if one is ready to run */
struct sandbox *next_sandbox = scheduler_get_next();
if (next_sandbox != NULL) {
@ -441,9 +436,6 @@ scheduler_cooperative_sched(bool add_to_cleanup_queue)
/* Deferred signals should have been cleared by this point */
assert(deferred_sigalrm == 0);
/* Try to wakeup sleeping sandboxes */
scheduler_execute_epoll_loop();
/* We have not added ourself to the cleanup queue, so we can free */
local_cleanup_queue_free();

@ -1,70 +0,0 @@
#pragma once
#include <assert.h>
#include <errno.h>
#include "http_session.h"
#include "panic.h"
#include "runtime.h"
#include "sandbox_functions.h"
#include "sandbox_set_as_error.h"
#include "sandbox_state.h"
#include "sandbox_types.h"
#include "worker_thread.h"
/**
* Run all outstanding events in the local thread's epoll loop
*/
static inline void
scheduler_execute_epoll_loop(void)
{
while (true) {
struct epoll_event epoll_events[RUNTIME_MAX_EPOLL_EVENTS];
int descriptor_count = epoll_wait(worker_thread_epoll_file_descriptor, epoll_events,
RUNTIME_MAX_EPOLL_EVENTS, 0);
if (descriptor_count < 0) {
if (errno == EINTR) continue;
panic_err();
}
if (descriptor_count == 0) break;
for (int i = 0; i < descriptor_count; i++) {
if (epoll_events[i].events & (EPOLLIN | EPOLLOUT)) {
/* Re-add to runqueue if asleep */
struct sandbox *sandbox = (struct sandbox *)epoll_events[i].data.ptr;
assert(sandbox);
if (sandbox->state == SANDBOX_ASLEEP) { sandbox_wakeup(sandbox); }
} else if (epoll_events[i].events & (EPOLLERR | EPOLLHUP)) {
/* Close socket and set as error on socket error or unexpected client hangup */
struct sandbox *sandbox = (struct sandbox *)epoll_events[i].data.ptr;
int error = 0;
socklen_t errlen = sizeof(error);
getsockopt(epoll_events[i].data.fd, SOL_SOCKET, SO_ERROR, (void *)&error, &errlen);
if (error > 0) {
debuglog("Socket error: %s", strerror(error));
} else if (epoll_events[i].events & EPOLLHUP) {
debuglog("Client Hungup");
} else {
debuglog("Unknown Socket error");
}
switch (sandbox->state) {
case SANDBOX_RETURNED:
case SANDBOX_COMPLETE:
case SANDBOX_ERROR:
panic("Expected to have closed socket");
default:
sandbox_set_as_error(sandbox, sandbox->state);
}
} else {
panic("Mystery epoll event!\n");
};
}
}
}

@ -5,7 +5,6 @@
#include "runtime.h"
extern thread_local struct arch_context worker_thread_base_context;
extern thread_local int worker_thread_epoll_file_descriptor;
extern thread_local int worker_thread_idx;
void *worker_thread_main(void *return_code);

@ -1,23 +0,0 @@
#pragma once
#include "worker_thread.h"
static inline void
worker_thread_epoll_add_sandbox(struct sandbox *sandbox)
{
assert(sandbox != NULL);
/* Freshly allocated sandbox going runnable for first time, so register client socket with epoll */
struct epoll_event accept_evt;
accept_evt.data.ptr = (void *)sandbox;
accept_evt.events = EPOLLIN | EPOLLOUT | EPOLLET;
int rc = epoll_ctl(worker_thread_epoll_file_descriptor, EPOLL_CTL_ADD, sandbox->http->socket, &accept_evt);
if (unlikely(rc < 0)) panic_err();
}
static inline void
worker_thread_epoll_remove_sandbox(struct sandbox *sandbox)
{
assert(sandbox != NULL);
int rc = epoll_ctl(worker_thread_epoll_file_descriptor, EPOLL_CTL_DEL, sandbox->http->socket, NULL);
if (unlikely(rc < 0)) panic_err();
}

@ -13,7 +13,6 @@
#include "scheduler.h"
#include "software_interrupt.h"
#include "wasi.h"
#include "worker_thread_epoll.h"
thread_local struct sandbox *worker_thread_current_sandbox = NULL;
@ -102,7 +101,6 @@ current_sandbox_wasm_trap_handler(int trapno)
}
debuglog("%s", error_message);
worker_thread_epoll_remove_sandbox(sandbox);
current_sandbox_exit();
assert(0);
}
@ -118,8 +116,6 @@ current_sandbox_init()
int rc = 0;
char *error_message = NULL;
worker_thread_epoll_add_sandbox(sandbox);
/* Initialize sandbox memory */
struct module *current_module = sandbox_get_module(sandbox);
module_initialize_memory(current_module);
@ -149,7 +145,6 @@ current_sandbox_init()
err:
debuglog("%s", error_message);
worker_thread_epoll_remove_sandbox(sandbox);
current_sandbox_exit();
return NULL;
}
@ -167,7 +162,6 @@ current_sandbox_fini()
sandbox->total_time = sandbox->timestamp_of.completion - sandbox->timestamp_of.allocation;
assert(sandbox->state == SANDBOX_RUNNING_SYS);
worker_thread_epoll_remove_sandbox(sandbox);
done:
sandbox_set_as_returned(sandbox, SANDBOX_RUNNING_SYS);

@ -22,6 +22,7 @@
#include "listener_thread.h"
#include "panic.h"
#include "runtime.h"
#include "sandbox_perf_log.h"
#include "sandbox_types.h"
#include "scheduler.h"
#include "software_interrupt.h"

@ -22,6 +22,7 @@
#include "sandbox_total.h"
#include "scheduler.h"
#include "software_interrupt.h"
#include "sandbox_perf_log.h"
/***************************
* Shared Process State *

@ -25,8 +25,6 @@
/* context of the runtime thread before running sandboxes or to resume its "main". */
thread_local struct arch_context worker_thread_base_context;
thread_local int worker_thread_epoll_file_descriptor;
/* Used to index into global arguments and deadlines arrays */
thread_local int worker_thread_idx;
@ -64,10 +62,6 @@ worker_thread_main(void *argument)
tenant_timeout_get_priority);
}
/* Initialize epoll */
worker_thread_epoll_file_descriptor = epoll_create1(0);
if (unlikely(worker_thread_epoll_file_descriptor < 0)) panic_err();
software_interrupt_unmask_signal(SIGFPE);
software_interrupt_unmask_signal(SIGSEGV);

Loading…
Cancel
Save