Fixed the Dynamic read of the Number of CPU Cores (#261)

* Fixed the Dynamic read of the Number of CPU Cores
Closes #260

* removed a commented line

* small changes per Sean's review

* Accomadate Gabe's comments:
- Validate runtime_worker_threads array before usage
- final cleanup
master
Emil 4 years ago committed by GitHub
parent 7640cd5fb6
commit 9778db645a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,9 +5,6 @@ $(error Unsupported Architecture. Supports x86_64 and aarch64, found $(ARCH))
endif
endif
TOTAL_CORES := $(shell getconf _NPROCESSORS_CONF)
PAGE_SIZE := $(shell getconf PAGESIZE)
# Compiler Settings
CC=clang
CC_OPTIONS = -O3 -flto -g -pthread -D_GNU_SOURCE
@ -81,8 +78,6 @@ BINARY_NAME=sledgert
# Sets a flag equal to the processor architecture
CFLAGS += -D${ARCH}
CFLAGS += -DNCORES=${TOTAL_CORES}
CFLAGS += -DPAGE_SIZE=$(PAGE_SIZE)
# Sandboxes running on Sledge always use WebAssembly linear memory
CFLAGS += -DUSE_MEM_VM

@ -1,6 +1,6 @@
{
"active": true,
"name": "resize",
"name": "ekf",
"path": "ekf_wasm.so",
"port": 10000,
"expected-execution-us": 5000,

@ -18,7 +18,7 @@ validate_dependencies awk hey jq
# Please keep the element ordered alphabetically!
# declare -a workloads=(cifar10 ekf gocr lpd resize)
declare -a workloads=(cifar10 gocr lpd resize)
declare -a workloads=(cifar10 ekf gocr lpd resize)
declare -a multiples=(1.5 2.0 3.0 4.0)
declare -ri percentile=50
@ -27,8 +27,8 @@ profile() {
local -r results_directory="$2"
# ekf
# hey -disable-compression -disable-keepalive -disable-redirects -n 256 -c 1 -cpus 1 -t 0 -o csv -m GET -D "./ekf/initial_state.dat" "http://${hostname}:10000" > /dev/null
# printf "[ekf: OK]\n"
hey -disable-compression -disable-keepalive -disable-redirects -n 256 -c 1 -cpus 1 -t 0 -o csv -m GET -D "./ekf/initial_state.dat" "http://${hostname}:10000" > /dev/null
printf "[ekf: OK]\n"
# Resize
hey -disable-compression -disable-keepalive -disable-redirects -n 256 -c 1 -cpus 1 -t 0 -o csv -m GET -D "./resize/shrinking_man_large.jpg" "http://${hostname}:10001" > /dev/null

@ -8,15 +8,6 @@
#include "likely.h"
#include "types.h"
#ifndef NCORES
#warning "NCORES not defined in Makefile. Defaulting to 2"
#define NCORES 2
#endif
#if NCORES == 1
#error "RUNTIME MINIMUM REQUIREMENT IS 2 CORES"
#endif
#define RUNTIME_EXPECTED_EXECUTION_US_MAX 3600000000
#define RUNTIME_HTTP_REQUEST_SIZE_MAX 100000000 /* 100 MB */
#define RUNTIME_HTTP_RESPONSE_SIZE_MAX 100000000 /* 100 MB */
@ -26,7 +17,6 @@
#define RUNTIME_MAX_WORKER_COUNT 32 /* Static buffer size for per-worker globals */
#define RUNTIME_READ_WRITE_VECTOR_LENGTH 16
#define RUNTIME_RELATIVE_DEADLINE_US_MAX 3600000000 /* One Hour. Fits in uint32_t */
#define RUNTIME_WORKER_THREAD_CORE_COUNT (NCORES > 1 ? NCORES - 1 : NCORES)
enum RUNTIME_SIGALRM_HANDLER
{
@ -39,10 +29,10 @@ extern uint32_t runtime_processor_speed_MHz;
extern uint32_t runtime_quantum_us;
extern FILE * runtime_sandbox_perf_log;
extern enum RUNTIME_SIGALRM_HANDLER runtime_sigalrm_handler;
extern pthread_t runtime_worker_threads[];
extern pthread_t * runtime_worker_threads;
extern uint32_t runtime_worker_threads_count;
extern int runtime_worker_threads_argument[RUNTIME_WORKER_THREAD_CORE_COUNT];
extern uint64_t runtime_worker_threads_deadline[RUNTIME_WORKER_THREAD_CORE_COUNT];
extern int * runtime_worker_threads_argument;
extern uint64_t * runtime_worker_threads_deadline;
extern void runtime_initialize(void);
extern void runtime_set_pthread_prio(pthread_t thread, unsigned int nice);

@ -18,7 +18,7 @@
***********/
extern _Atomic __thread volatile sig_atomic_t software_interrupt_deferred_sigalrm;
extern _Atomic volatile sig_atomic_t software_interrupt_deferred_sigalrm_max[RUNTIME_WORKER_THREAD_CORE_COUNT];
extern _Atomic volatile sig_atomic_t * software_interrupt_deferred_sigalrm_max;
/*************************
* Public Static Inlines *
@ -82,3 +82,4 @@ void software_interrupt_arm_timer(void);
void software_interrupt_disarm_timer(void);
void software_interrupt_set_interval_duration(uint64_t cycles);
void software_interrupt_deferred_sigalrm_max_print(void);
void software_interrupt_cleanup();

@ -4,9 +4,7 @@
#include <stdio.h>
#ifndef PAGE_SIZE
#define PAGE_SIZE (unsigned long)(1 << 12)
#endif
/* For this family of macros, do NOT pass zero as the pow2 */
#define round_to_pow2(x, pow2) (((unsigned long)(x)) & (~((pow2)-1)))

@ -30,6 +30,7 @@ listener_thread_initialize(void)
/* Setup epoll */
listener_thread_epoll_file_descriptor = epoll_create1(0);
printf("~~~~~~~~~~~~~~~Listener FD: %p \n", &listener_thread_epoll_file_descriptor);
assert(listener_thread_epoll_file_descriptor >= 0);
int ret = pthread_create(&listener_thread_id, NULL, listener_thread_main, NULL);

@ -61,7 +61,7 @@ runtime_allocate_available_cores()
/* Find the number of processors currently online */
runtime_total_online_processors = sysconf(_SC_NPROCESSORS_ONLN);
printf("\tCore Count: %u\n", runtime_total_online_processors);
printf("\tCore Count (Online): %u\n", runtime_total_online_processors);
/* If more than two cores are available, leave core 0 free to run OS tasks */
if (runtime_total_online_processors > 2) {
@ -259,10 +259,7 @@ log_compiletime_config()
printf("\tArchitecture: %s\n", "x86_64");
#endif
int ncores = NCORES;
printf("\tTotal Cores: %d\n", ncores);
int page_size = PAGE_SIZE;
printf("\tPage Size: %d\n", page_size);
printf("\tPage Size: %lu\n", PAGE_SIZE);
#ifdef LOG_HTTP_PARSER
printf("\tLog HTTP Parser: Enabled\n");
@ -346,8 +343,6 @@ main(int argc, char **argv)
printf("Runtime Environment:\n");
memset(runtime_worker_threads, 0, sizeof(pthread_t) * RUNTIME_WORKER_THREAD_CORE_COUNT);
runtime_processor_speed_MHz = runtime_get_processor_speed_MHz();
if (unlikely(runtime_processor_speed_MHz == 0)) panic("Failed to detect processor speed\n");

@ -28,10 +28,10 @@
* Shared Process State *
**************************/
pthread_t runtime_worker_threads[RUNTIME_WORKER_THREAD_CORE_COUNT];
int runtime_worker_threads_argument[RUNTIME_WORKER_THREAD_CORE_COUNT] = { 0 };
pthread_t *runtime_worker_threads;
int * runtime_worker_threads_argument;
/* The active deadline of the sandbox running on each worker thread */
uint64_t runtime_worker_threads_deadline[RUNTIME_WORKER_THREAD_CORE_COUNT] = { UINT64_MAX };
uint64_t *runtime_worker_threads_deadline;
/******************************************
* Shared Process / Listener Thread Logic *
@ -42,7 +42,12 @@ runtime_cleanup()
{
if (runtime_sandbox_perf_log != NULL) fflush(runtime_sandbox_perf_log);
if (runtime_worker_threads_deadline) free(runtime_worker_threads_deadline);
if (runtime_worker_threads_argument) free(runtime_worker_threads_argument);
if (runtime_worker_threads) free(runtime_worker_threads);
software_interrupt_deferred_sigalrm_max_print();
software_interrupt_cleanup();
exit(EXIT_SUCCESS);
}
@ -91,6 +96,11 @@ runtime_set_resource_limits_to_max()
void
runtime_initialize(void)
{
runtime_worker_threads = calloc(runtime_worker_threads_count, sizeof(pthread_t));
runtime_worker_threads_argument = calloc(runtime_worker_threads_count, sizeof(int));
runtime_worker_threads_deadline = malloc(runtime_worker_threads_count * sizeof(uint64_t));
memset(runtime_worker_threads_deadline, UINT8_MAX, runtime_worker_threads_count * sizeof(uint64_t));
http_total_init();
sandbox_request_count_initialize();
sandbox_count_initialize();

@ -37,7 +37,7 @@ __thread _Atomic static volatile sig_atomic_t software_interrupt_SIGUSR_count
__thread _Atomic volatile sig_atomic_t software_interrupt_deferred_sigalrm = 0;
__thread _Atomic volatile sig_atomic_t software_interrupt_signal_depth = 0;
_Atomic volatile sig_atomic_t software_interrupt_deferred_sigalrm_max[RUNTIME_WORKER_THREAD_CORE_COUNT] = { 0 };
_Atomic volatile sig_atomic_t *software_interrupt_deferred_sigalrm_max;
void
software_interrupt_deferred_sigalrm_max_print()
@ -49,16 +49,23 @@ software_interrupt_deferred_sigalrm_max_print()
fflush(stdout);
}
void
software_interrupt_cleanup()
{
if (software_interrupt_deferred_sigalrm_max) free((void *)software_interrupt_deferred_sigalrm_max);
}
/***************************************
* Externs
**************************************/
extern pthread_t runtime_worker_threads[];
extern pthread_t *runtime_worker_threads;
/**************************
* Private Static Inlines *
*************************/
/**
* A POSIX signal is delivered to only one thread.
* This function broadcasts the sigalarm signal to all other worker threads
@ -70,11 +77,11 @@ sigalrm_propagate_workers(siginfo_t *signal_info)
if (signal_info->si_code == SI_KERNEL) {
atomic_fetch_add(&software_interrupt_SIGALRM_kernel_count, 1);
for (int i = 0; i < runtime_worker_threads_count; i++) {
if (pthread_self() == runtime_worker_threads[i]) continue;
/* All threads should have been initialized */
assert(runtime_worker_threads[i] != 0);
if (pthread_self() == runtime_worker_threads[i]) continue;
/* If using EDF, conditionally send signals. If not, broadcast */
switch (runtime_sigalrm_handler) {
case RUNTIME_SIGALRM_HANDLER_TRIAGED: {
@ -256,6 +263,8 @@ software_interrupt_initialize(void)
exit(1);
}
}
software_interrupt_deferred_sigalrm_max = calloc(runtime_worker_threads_count, sizeof(_Atomic(sig_atomic_t)));
}
void

@ -57,6 +57,7 @@ worker_thread_main(void *argument)
/* Initialize epoll */
worker_thread_epoll_file_descriptor = epoll_create1(0);
printf("~~~~~~~~~~~~~~~Worker FD: %p \n", &worker_thread_epoll_file_descriptor);
if (unlikely(worker_thread_epoll_file_descriptor < 0)) panic_err();
/* Unmask signals, unless the runtime has disabled preemption */

Loading…
Cancel
Save