aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--include/internal.h2
-rw-r--r--include/litmus.h3
-rw-r--r--src/kernel_iface.c25
-rw-r--r--src/syscalls.c38
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: \
166 166
167litmus-headers = \ 167litmus-headers = \
168 include/litmus/rt_param.h \ 168 include/litmus/rt_param.h \
169 include/litmus/ctrlpage.h \
169 include/litmus/fpmath.h \ 170 include/litmus/fpmath.h \
170 include/litmus/unistd_32.h \ 171 include/litmus/unistd_32.h \
171 include/litmus/unistd_64.h 172 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 @@
26/* I/O convenience function */ 26/* I/O convenience function */
27ssize_t read_file(const char* fname, void* buf, size_t maxlen); 27ssize_t read_file(const char* fname, void* buf, size_t maxlen);
28 28
29long litmus_syscall(litmus_syscall_id_t syscall, unsigned long arg);
30
29#endif 31#endif
30 32
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" {
35 * and control_page structures. 35 * and control_page structures.
36 */ 36 */
37#include "litmus/rt_param.h" 37#include "litmus/rt_param.h"
38#define __user
39#include "litmus/ctrlpage.h"
40#undef __user
38 41
39#include "asm/cycles.h" /* for null_call() */ 42#include "asm/cycles.h" /* for null_call() */
40 43
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 @@
1#include <sys/mman.h> 1#include <sys/mman.h>
2#include <sys/fcntl.h> /* for O_RDWR */ 2#include <sys/fcntl.h> /* for O_RDWR */
3#include <sys/ioctl.h>
3#include <sys/unistd.h> 4#include <sys/unistd.h>
5#include <errno.h>
4#include <sched.h> /* for sched_yield() */ 6#include <sched.h> /* for sched_yield() */
5 7
6 8
@@ -22,6 +24,7 @@ static int map_file(const char* filename, void **addr, size_t size)
22 24
23 if (size > 0) { 25 if (size > 0) {
24 fd = open(filename, O_RDWR); 26 fd = open(filename, O_RDWR);
27 error = fd;
25 if (fd >= 0) { 28 if (fd >= 0) {
26 *addr = mmap(NULL, size, 29 *addr = mmap(NULL, size,
27 PROT_READ | PROT_WRITE, 30 PROT_READ | PROT_WRITE,
@@ -29,9 +32,7 @@ static int map_file(const char* filename, void **addr, size_t size)
29 fd, 0); 32 fd, 0);
30 if (*addr == MAP_FAILED) 33 if (*addr == MAP_FAILED)
31 error = -1; 34 error = -1;
32 close(fd); 35 }
33 } else
34 error = fd;
35 } else 36 } else
36 *addr = NULL; 37 *addr = NULL;
37 return error; 38 return error;
@@ -81,6 +82,7 @@ int get_nr_ts_release_waiters(void)
81 82
82/* thread-local pointer to control page */ 83/* thread-local pointer to control page */
83static __thread struct control_page *ctrl_page; 84static __thread struct control_page *ctrl_page;
85static __thread int ctrl_fd;
84 86
85int init_kernel_iface(void) 87int init_kernel_iface(void)
86{ 88{
@@ -105,16 +107,19 @@ int init_kernel_iface(void)
105 BUILD_BUG_ON(offsetof(struct control_page, job_index) 107 BUILD_BUG_ON(offsetof(struct control_page, job_index)
106 != LITMUS_CP_OFFSET_JOB_INDEX); 108 != LITMUS_CP_OFFSET_JOB_INDEX);
107 109
108 err = map_file(LITMUS_CTRL_DEVICE, &mapped_at, CTRL_PAGES * page_size); 110 ctrl_fd = map_file(LITMUS_CTRL_DEVICE, &mapped_at, CTRL_PAGES * page_size);
109 111
110 /* Assign ctrl_page indirectly to avoid GCC warnings about aliasing 112 /* Assign ctrl_page indirectly to avoid GCC warnings about aliasing
111 * related to type pruning. 113 * related to type pruning.
112 */ 114 */
113 ctrl_page = mapped_at; 115 ctrl_page = mapped_at;
114 116
115 if (err) { 117 if (ctrl_fd < 0) {
116 fprintf(stderr, "%s: cannot open LITMUS^RT control page (%m)\n", 118 fprintf(stderr, "%s: cannot open LITMUS^RT control page (%m)\n",
117 __FUNCTION__); 119 __FUNCTION__);
120 err = ctrl_fd;
121 } else {
122 err = 0;
118 } 123 }
119 124
120 return err; 125 return err;
@@ -159,3 +164,13 @@ struct control_page* get_ctrl_page(void)
159 return NULL; 164 return NULL;
160} 165}
161 166
167long litmus_syscall(litmus_syscall_id_t syscall, unsigned long arg)
168{
169 if (likely(ctrl_page != NULL) || init_kernel_iface() == 0)
170 {
171 return ioctl(ctrl_fd, syscall, arg);
172 } else {
173 errno = ENOSYS;
174 return -1;
175 }
176}
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)
20 20
21int set_rt_task_param(pid_t pid, struct rt_task *param) 21int set_rt_task_param(pid_t pid, struct rt_task *param)
22{ 22{
23 return syscall(__NR_set_rt_task_param, pid, param); 23 union litmus_syscall_args args;
24 args.get_set_task_param.pid = pid;
25 args.get_set_task_param.param = param;
26 return litmus_syscall(LRT_set_rt_task_param, (unsigned long) &args);
24} 27}
25 28
26int get_rt_task_param(pid_t pid, struct rt_task *param) 29int get_rt_task_param(pid_t pid, struct rt_task *param)
27{ 30{
28 return syscall(__NR_get_rt_task_param, pid, param); 31 union litmus_syscall_args args;
32 args.get_set_task_param.pid = pid;
33 args.get_set_task_param.param = param;
34 return litmus_syscall(LRT_get_rt_task_param, (unsigned long) &args);
29} 35}
30 36
31int sleep_next_period(void) 37int sleep_next_period(void)
32{ 38{
33 return syscall(__NR_complete_job); 39 return litmus_syscall(LRT_complete_job, 0);
34} 40}
35 41
36int od_openx(int fd, obj_type_t type, int obj_id, void *config) 42int od_openx(int fd, obj_type_t type, int obj_id, void *config)
37{ 43{
38 return syscall(__NR_od_open, fd, type, obj_id, config); 44 union litmus_syscall_args args;
45 args.od_open.fd = fd;
46 args.od_open.obj_type = type;
47 args.od_open.obj_id = obj_id;
48 args.od_open.config = config;
49 return litmus_syscall(LRT_od_open, (unsigned long) &args);
39} 50}
40 51
41int od_close(int od) 52int od_close(int od)
42{ 53{
43 return syscall(__NR_od_close, od); 54 return litmus_syscall(LRT_od_close, od);
44} 55}
45 56
46int litmus_lock(int od) 57int litmus_lock(int od)
47{ 58{
48 return syscall(__NR_litmus_lock, od); 59 return litmus_syscall(LRT_litmus_lock, od);
49} 60}
50 61
51int litmus_unlock(int od) 62int litmus_unlock(int od)
52{ 63{
53 return syscall(__NR_litmus_unlock, od); 64 return litmus_syscall(LRT_litmus_unlock, od);
54} 65}
55 66
56int get_job_no(unsigned int *job_no) 67int get_job_no(unsigned int *job_no)
@@ -66,27 +77,30 @@ int get_job_no(unsigned int *job_no)
66 77
67int wait_for_job_release(unsigned int job_no) 78int wait_for_job_release(unsigned int job_no)
68{ 79{
69 return syscall(__NR_wait_for_job_release, job_no); 80 return litmus_syscall(LRT_wait_for_job_release, job_no);
70} 81}
71 82
72int wait_for_ts_release(void) 83int wait_for_ts_release(void)
73{ 84{
74 return syscall(__NR_wait_for_ts_release); 85 return litmus_syscall(LRT_wait_for_ts_release, 0);
75} 86}
76 87
77int release_ts(lt_t *delay) 88int release_ts(lt_t *delay)
78{ 89{
79 return syscall(__NR_release_ts, delay); 90 return litmus_syscall(LRT_release_ts, (unsigned long) delay);
80} 91}
81 92
82int null_call(cycles_t *timestamp) 93int null_call(cycles_t *timestamp)
83{ 94{
84 return syscall(__NR_null_call, timestamp); 95 return litmus_syscall(LRT_null_call, (unsigned long) timestamp);
85} 96}
86 97
87int get_current_budget( 98int get_current_budget(
88 lt_t *expended, 99 lt_t *expended,
89 lt_t *remaining) 100 lt_t *remaining)
90{ 101{
91 return syscall(__NR_get_current_budget, expended, remaining); 102 union litmus_syscall_args args;
103 args.get_current_budget.expended = expended;
104 args.get_current_budget.remaining = remaining;
105 return litmus_syscall(LRT_get_current_budget, (unsigned long) &args);
92} 106}