From c820535d6864137e158df46d0903c6f44a97ca31 Mon Sep 17 00:00:00 2001 From: Bjoern Brandenburg Date: Wed, 16 Dec 2015 13:33:21 +0100 Subject: Switch syscalls to use new LITMUS^RT ioctl() interface This change should be transparent to clients of the library. --- Makefile | 1 + include/internal.h | 2 ++ include/litmus.h | 3 +++ src/kernel_iface.c | 25 ++++++++++++++++++++----- src/syscalls.c | 38 ++++++++++++++++++++++++++------------ 5 files changed, 52 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 4742fd2..36bebb3 100644 --- a/Makefile +++ b/Makefile @@ -166,6 +166,7 @@ arch/${include-${ARCH}}/include/generated/uapi/asm/%.h: \ litmus-headers = \ include/litmus/rt_param.h \ + include/litmus/ctrlpage.h \ include/litmus/fpmath.h \ include/litmus/unistd_32.h \ include/litmus/unistd_64.h diff --git a/include/internal.h b/include/internal.h index 354f7dc..ee420ad 100644 --- a/include/internal.h +++ b/include/internal.h @@ -26,5 +26,7 @@ /* I/O convenience function */ ssize_t read_file(const char* fname, void* buf, size_t maxlen); +long litmus_syscall(litmus_syscall_id_t syscall, unsigned long arg); + #endif diff --git a/include/litmus.h b/include/litmus.h index 2c5d4df..adec0ee 100644 --- a/include/litmus.h +++ b/include/litmus.h @@ -35,6 +35,9 @@ extern "C" { * and control_page structures. */ #include "litmus/rt_param.h" +#define __user +#include "litmus/ctrlpage.h" +#undef __user #include "asm/cycles.h" /* for null_call() */ diff --git a/src/kernel_iface.c b/src/kernel_iface.c index c21f9b6..538a821 100644 --- a/src/kernel_iface.c +++ b/src/kernel_iface.c @@ -1,6 +1,8 @@ #include #include /* for O_RDWR */ +#include #include +#include #include /* for sched_yield() */ @@ -22,6 +24,7 @@ static int map_file(const char* filename, void **addr, size_t size) if (size > 0) { fd = open(filename, O_RDWR); + error = fd; if (fd >= 0) { *addr = mmap(NULL, size, PROT_READ | PROT_WRITE, @@ -29,9 +32,7 @@ static int map_file(const char* filename, void **addr, size_t size) fd, 0); if (*addr == MAP_FAILED) error = -1; - close(fd); - } else - error = fd; + } } else *addr = NULL; return error; @@ -81,6 +82,7 @@ int get_nr_ts_release_waiters(void) /* thread-local pointer to control page */ static __thread struct control_page *ctrl_page; +static __thread int ctrl_fd; int init_kernel_iface(void) { @@ -105,16 +107,19 @@ int init_kernel_iface(void) BUILD_BUG_ON(offsetof(struct control_page, job_index) != LITMUS_CP_OFFSET_JOB_INDEX); - err = map_file(LITMUS_CTRL_DEVICE, &mapped_at, CTRL_PAGES * page_size); + ctrl_fd = map_file(LITMUS_CTRL_DEVICE, &mapped_at, CTRL_PAGES * page_size); /* Assign ctrl_page indirectly to avoid GCC warnings about aliasing * related to type pruning. */ ctrl_page = mapped_at; - if (err) { + if (ctrl_fd < 0) { fprintf(stderr, "%s: cannot open LITMUS^RT control page (%m)\n", __FUNCTION__); + err = ctrl_fd; + } else { + err = 0; } return err; @@ -159,3 +164,13 @@ struct control_page* get_ctrl_page(void) return NULL; } +long litmus_syscall(litmus_syscall_id_t syscall, unsigned long arg) +{ + if (likely(ctrl_page != NULL) || init_kernel_iface() == 0) + { + return ioctl(ctrl_fd, syscall, arg); + } else { + errno = ENOSYS; + return -1; + } +} diff --git a/src/syscalls.c b/src/syscalls.c index 2f0d5c4..d26de3a 100644 --- a/src/syscalls.c +++ b/src/syscalls.c @@ -20,37 +20,48 @@ pid_t gettid(void) int set_rt_task_param(pid_t pid, struct rt_task *param) { - return syscall(__NR_set_rt_task_param, pid, param); + union litmus_syscall_args args; + args.get_set_task_param.pid = pid; + args.get_set_task_param.param = param; + return litmus_syscall(LRT_set_rt_task_param, (unsigned long) &args); } int get_rt_task_param(pid_t pid, struct rt_task *param) { - return syscall(__NR_get_rt_task_param, pid, param); + union litmus_syscall_args args; + args.get_set_task_param.pid = pid; + args.get_set_task_param.param = param; + return litmus_syscall(LRT_get_rt_task_param, (unsigned long) &args); } int sleep_next_period(void) { - return syscall(__NR_complete_job); + return litmus_syscall(LRT_complete_job, 0); } int od_openx(int fd, obj_type_t type, int obj_id, void *config) { - return syscall(__NR_od_open, fd, type, obj_id, config); + union litmus_syscall_args args; + args.od_open.fd = fd; + args.od_open.obj_type = type; + args.od_open.obj_id = obj_id; + args.od_open.config = config; + return litmus_syscall(LRT_od_open, (unsigned long) &args); } int od_close(int od) { - return syscall(__NR_od_close, od); + return litmus_syscall(LRT_od_close, od); } int litmus_lock(int od) { - return syscall(__NR_litmus_lock, od); + return litmus_syscall(LRT_litmus_lock, od); } int litmus_unlock(int od) { - return syscall(__NR_litmus_unlock, od); + return litmus_syscall(LRT_litmus_unlock, od); } int get_job_no(unsigned int *job_no) @@ -66,27 +77,30 @@ int get_job_no(unsigned int *job_no) int wait_for_job_release(unsigned int job_no) { - return syscall(__NR_wait_for_job_release, job_no); + return litmus_syscall(LRT_wait_for_job_release, job_no); } int wait_for_ts_release(void) { - return syscall(__NR_wait_for_ts_release); + return litmus_syscall(LRT_wait_for_ts_release, 0); } int release_ts(lt_t *delay) { - return syscall(__NR_release_ts, delay); + return litmus_syscall(LRT_release_ts, (unsigned long) delay); } int null_call(cycles_t *timestamp) { - return syscall(__NR_null_call, timestamp); + return litmus_syscall(LRT_null_call, (unsigned long) timestamp); } int get_current_budget( lt_t *expended, lt_t *remaining) { - return syscall(__NR_get_current_budget, expended, remaining); + union litmus_syscall_args args; + args.get_current_budget.expended = expended; + args.get_current_budget.remaining = remaining; + return litmus_syscall(LRT_get_current_budget, (unsigned long) &args); } -- cgit v1.2.2