diff options
| author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2015-12-16 07:33:21 -0500 |
|---|---|---|
| committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2015-12-18 03:43:48 -0500 |
| commit | c820535d6864137e158df46d0903c6f44a97ca31 (patch) | |
| tree | 9149f2c4b11242be423dd2ce95e114dc5bd5e190 /src | |
| parent | 69ddb96d06d0890df5f291dde7d829000f062a48 (diff) | |
Switch syscalls to use new LITMUS^RT ioctl() interface
This change should be transparent to clients of the library.
Diffstat (limited to 'src')
| -rw-r--r-- | src/kernel_iface.c | 25 | ||||
| -rw-r--r-- | src/syscalls.c | 38 |
2 files changed, 46 insertions, 17 deletions
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 */ |
| 83 | static __thread struct control_page *ctrl_page; | 84 | static __thread struct control_page *ctrl_page; |
| 85 | static __thread int ctrl_fd; | ||
| 84 | 86 | ||
| 85 | int init_kernel_iface(void) | 87 | int 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 | ||
| 167 | long 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 | ||
| 21 | int set_rt_task_param(pid_t pid, struct rt_task *param) | 21 | int 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 | ||
| 26 | int get_rt_task_param(pid_t pid, struct rt_task *param) | 29 | int 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 | ||
| 31 | int sleep_next_period(void) | 37 | int sleep_next_period(void) |
| 32 | { | 38 | { |
| 33 | return syscall(__NR_complete_job); | 39 | return litmus_syscall(LRT_complete_job, 0); |
| 34 | } | 40 | } |
| 35 | 41 | ||
| 36 | int od_openx(int fd, obj_type_t type, int obj_id, void *config) | 42 | int 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 | ||
| 41 | int od_close(int od) | 52 | int 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 | ||
| 46 | int litmus_lock(int od) | 57 | int 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 | ||
| 51 | int litmus_unlock(int od) | 62 | int 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 | ||
| 56 | int get_job_no(unsigned int *job_no) | 67 | int get_job_no(unsigned int *job_no) |
| @@ -66,27 +77,30 @@ int get_job_no(unsigned int *job_no) | |||
| 66 | 77 | ||
| 67 | int wait_for_job_release(unsigned int job_no) | 78 | int 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 | ||
| 72 | int wait_for_ts_release(void) | 83 | int 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 | ||
| 77 | int release_ts(lt_t *delay) | 88 | int 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 | ||
| 82 | int null_call(cycles_t *timestamp) | 93 | int 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 | ||
| 87 | int get_current_budget( | 98 | int 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 | } |
