feat: add prio logic

main
Sean McBride 4 years ago
parent 644d49a3c2
commit 13c511a679

@ -40,35 +40,26 @@ enum RUNTIME_SIGALRM_HANDLER
RUNTIME_SIGALRM_HANDLER_TRIAGED = 1
};
extern bool runtime_preemption_enabled;
/*
* Assumption: All cores are the same speed
* See runtime_get_processor_speed_MHz for further details
*/
extern uint32_t runtime_processor_speed_MHz;
extern uint32_t runtime_quantum_us;
/* Optional path to a file to log sandbox perf metrics */
extern FILE *runtime_sandbox_perf_log;
extern bool runtime_preemption_enabled;
extern uint32_t runtime_processor_speed_MHz;
extern uint32_t runtime_quantum_us;
extern FILE * runtime_sandbox_perf_log;
extern enum RUNTIME_SCHEDULER runtime_scheduler;
extern enum RUNTIME_SIGALRM_HANDLER runtime_sigalrm_handler;
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];
/* Count of worker threads and array of their pthread identifiers */
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 void runtime_initialize(void);
extern void runtime_set_pthread_prio(pthread_t thread, unsigned int nice);
extern void runtime_set_resource_limits_to_max();
/* External Symbols */
extern void alloc_linear_memory(void);
extern void expand_memory(void);
INLINE char *get_function_from_table(uint32_t idx, uint32_t type_id);
INLINE char *get_memory_ptr_for_runtime(uint32_t offset, uint32_t bounds_check);
extern void runtime_initialize(void);
extern void runtime_set_resource_limits_to_max();
extern void stub_init(int32_t offset);
static inline char *

@ -1,8 +1,14 @@
#include <arpa/inet.h>
#include <assert.h>
#include <signal.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <pthread.h>
#include "admissions_control.h"
#include "arch/context.h"
@ -110,3 +116,77 @@ runtime_initialize(void)
http_parser_settings_initialize();
admissions_control_initialize();
}
static void
runtime_call_getrlimit(int id, char *name)
{
struct rlimit rl;
if (getrlimit(id, &rl)) {
perror("getrlimit: ");
exit(-1);
}
}
static void
runtime_call_setrlimit(int id, rlim_t c, rlim_t m)
{
struct rlimit rl;
rl.rlim_cur = c;
rl.rlim_max = m;
if (setrlimit(id, &rl)) {
perror("getrlimit: ");
exit(-1);
}
}
void
runtime_pthread_prio(pthread_t thread, unsigned int nice)
{
struct sched_param sp;
int policy;
call_getrlimit(RLIMIT_CPU, "CPU");
call_getrlimit(RLIMIT_RTTIME, "RTTIME");
call_getrlimit(RLIMIT_RTPRIO, "RTPRIO");
call_setrlimit(RLIMIT_RTPRIO, RLIM_INFINITY, RLIM_INFINITY);
call_getrlimit(RLIMIT_RTPRIO, "RTPRIO");
call_getrlimit(RLIMIT_NICE, "NICE");
if (pthread_getschedparam(thread, &policy, &sp) < 0) { perror("pth_getparam: "); }
sp.sched_priority = sched_get_priority_max(SCHED_RR) - nice;
if (pthread_setschedparam(thread, SCHED_RR, &sp) < 0) {
perror("pth_setparam: ");
exit(-1);
}
if (pthread_getschedparam(thread, &policy, &sp) < 0) { perror("getparam: "); }
assert(sp.sched_priority == sched_get_priority_max(SCHED_RR) - nice);
return;
}
void
runtime_set_prio(unsigned int nice)
{
struct sched_param sp;
call_getrlimit(RLIMIT_CPU, "CPU");
call_getrlimit(RLIMIT_RTTIME, "RTTIME");
call_getrlimit(RLIMIT_RTPRIO, "RTPRIO");
call_setrlimit(RLIMIT_RTPRIO, RLIM_INFINITY, RLIM_INFINITY);
call_getrlimit(RLIMIT_RTPRIO, "RTPRIO");
call_getrlimit(RLIMIT_NICE, "NICE");
if (sched_getparam(0, &sp) < 0) { perror("getparam: "); }
sp.sched_priority = sched_get_priority_max(SCHED_RR) - nice;
if (sched_setscheduler(0, SCHED_RR, &sp) < 0) {
perror("setscheduler: ");
exit(-1);
}
if (sched_getparam(0, &sp) < 0) { perror("getparam: "); }
assert(sp.sched_priority == sched_get_priority_max(SCHED_RR) - nice);
return;
}

Loading…
Cancel
Save