diff options
Diffstat (limited to 'libc-top-half/musl/src/sched')
-rw-r--r-- | libc-top-half/musl/src/sched/affinity.c | 33 | ||||
-rw-r--r-- | libc-top-half/musl/src/sched/sched_cpucount.c | 11 | ||||
-rw-r--r-- | libc-top-half/musl/src/sched/sched_get_priority_max.c | 12 | ||||
-rw-r--r-- | libc-top-half/musl/src/sched/sched_getcpu.c | 42 | ||||
-rw-r--r-- | libc-top-half/musl/src/sched/sched_getparam.c | 8 | ||||
-rw-r--r-- | libc-top-half/musl/src/sched/sched_getscheduler.c | 8 | ||||
-rw-r--r-- | libc-top-half/musl/src/sched/sched_rr_get_interval.c | 21 | ||||
-rw-r--r-- | libc-top-half/musl/src/sched/sched_setparam.c | 8 | ||||
-rw-r--r-- | libc-top-half/musl/src/sched/sched_setscheduler.c | 8 | ||||
-rw-r--r-- | libc-top-half/musl/src/sched/sched_yield.c | 7 |
10 files changed, 158 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/sched/affinity.c b/libc-top-half/musl/src/sched/affinity.c new file mode 100644 index 0000000..948ece4 --- /dev/null +++ b/libc-top-half/musl/src/sched/affinity.c @@ -0,0 +1,33 @@ +#define _GNU_SOURCE +#include <sched.h> +#include <string.h> +#include "pthread_impl.h" +#include "syscall.h" + +int sched_setaffinity(pid_t tid, size_t size, const cpu_set_t *set) +{ + return syscall(SYS_sched_setaffinity, tid, size, set); +} + +int pthread_setaffinity_np(pthread_t td, size_t size, const cpu_set_t *set) +{ + return -__syscall(SYS_sched_setaffinity, td->tid, size, set); +} + +static int do_getaffinity(pid_t tid, size_t size, cpu_set_t *set) +{ + long ret = __syscall(SYS_sched_getaffinity, tid, size, set); + if (ret < 0) return ret; + if (ret < size) memset((char *)set+ret, 0, size-ret); + return 0; +} + +int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set) +{ + return __syscall_ret(do_getaffinity(tid, size, set)); +} + +int pthread_getaffinity_np(pthread_t td, size_t size, cpu_set_t *set) +{ + return -do_getaffinity(td->tid, size, set); +} diff --git a/libc-top-half/musl/src/sched/sched_cpucount.c b/libc-top-half/musl/src/sched/sched_cpucount.c new file mode 100644 index 0000000..94aa259 --- /dev/null +++ b/libc-top-half/musl/src/sched/sched_cpucount.c @@ -0,0 +1,11 @@ +#define _GNU_SOURCE +#include <sched.h> + +int __sched_cpucount(size_t size, const cpu_set_t *set) +{ + size_t i, j, cnt=0; + const unsigned char *p = (const void *)set; + for (i=0; i<size; i++) for (j=0; j<8; j++) + if (p[i] & (1<<j)) cnt++; + return cnt; +} diff --git a/libc-top-half/musl/src/sched/sched_get_priority_max.c b/libc-top-half/musl/src/sched/sched_get_priority_max.c new file mode 100644 index 0000000..30ae510 --- /dev/null +++ b/libc-top-half/musl/src/sched/sched_get_priority_max.c @@ -0,0 +1,12 @@ +#include <sched.h> +#include "syscall.h" + +int sched_get_priority_max(int policy) +{ + return syscall(SYS_sched_get_priority_max, policy); +} + +int sched_get_priority_min(int policy) +{ + return syscall(SYS_sched_get_priority_min, policy); +} diff --git a/libc-top-half/musl/src/sched/sched_getcpu.c b/libc-top-half/musl/src/sched/sched_getcpu.c new file mode 100644 index 0000000..4ec5eaf --- /dev/null +++ b/libc-top-half/musl/src/sched/sched_getcpu.c @@ -0,0 +1,42 @@ +#define _GNU_SOURCE +#include <errno.h> +#include <sched.h> +#include "syscall.h" +#include "atomic.h" + +#ifdef VDSO_GETCPU_SYM + +static void *volatile vdso_func; + +typedef long (*getcpu_f)(unsigned *, unsigned *, void *); + +static long getcpu_init(unsigned *cpu, unsigned *node, void *unused) +{ + void *p = __vdsosym(VDSO_GETCPU_VER, VDSO_GETCPU_SYM); + getcpu_f f = (getcpu_f)p; + a_cas_p(&vdso_func, (void *)getcpu_init, p); + return f ? f(cpu, node, unused) : -ENOSYS; +} + +static void *volatile vdso_func = (void *)getcpu_init; + +#endif + +int sched_getcpu(void) +{ + int r; + unsigned cpu; + +#ifdef VDSO_GETCPU_SYM + getcpu_f f = (getcpu_f)vdso_func; + if (f) { + r = f(&cpu, 0, 0); + if (!r) return cpu; + if (r != -ENOSYS) return __syscall_ret(r); + } +#endif + + r = __syscall(SYS_getcpu, &cpu, 0, 0); + if (!r) return cpu; + return __syscall_ret(r); +} diff --git a/libc-top-half/musl/src/sched/sched_getparam.c b/libc-top-half/musl/src/sched/sched_getparam.c new file mode 100644 index 0000000..76f10e4 --- /dev/null +++ b/libc-top-half/musl/src/sched/sched_getparam.c @@ -0,0 +1,8 @@ +#include <sched.h> +#include <errno.h> +#include "syscall.h" + +int sched_getparam(pid_t pid, struct sched_param *param) +{ + return __syscall_ret(-ENOSYS); +} diff --git a/libc-top-half/musl/src/sched/sched_getscheduler.c b/libc-top-half/musl/src/sched/sched_getscheduler.c new file mode 100644 index 0000000..394e508 --- /dev/null +++ b/libc-top-half/musl/src/sched/sched_getscheduler.c @@ -0,0 +1,8 @@ +#include <sched.h> +#include <errno.h> +#include "syscall.h" + +int sched_getscheduler(pid_t pid) +{ + return __syscall_ret(-ENOSYS); +} diff --git a/libc-top-half/musl/src/sched/sched_rr_get_interval.c b/libc-top-half/musl/src/sched/sched_rr_get_interval.c new file mode 100644 index 0000000..33a3d1a --- /dev/null +++ b/libc-top-half/musl/src/sched/sched_rr_get_interval.c @@ -0,0 +1,21 @@ +#include <sched.h> +#include "syscall.h" + +int sched_rr_get_interval(pid_t pid, struct timespec *ts) +{ +#ifdef SYS_sched_rr_get_interval_time64 + /* On a 32-bit arch, use the old syscall if it exists. */ + if (SYS_sched_rr_get_interval != SYS_sched_rr_get_interval_time64) { + long ts32[2]; + int r = __syscall(SYS_sched_rr_get_interval, pid, ts32); + if (!r) { + ts->tv_sec = ts32[0]; + ts->tv_nsec = ts32[1]; + } + return __syscall_ret(r); + } +#endif + /* If reaching this point, it's a 64-bit arch or time64-only + * 32-bit arch and we can get result directly into timespec. */ + return syscall(SYS_sched_rr_get_interval, pid, ts); +} diff --git a/libc-top-half/musl/src/sched/sched_setparam.c b/libc-top-half/musl/src/sched/sched_setparam.c new file mode 100644 index 0000000..18623ee --- /dev/null +++ b/libc-top-half/musl/src/sched/sched_setparam.c @@ -0,0 +1,8 @@ +#include <sched.h> +#include <errno.h> +#include "syscall.h" + +int sched_setparam(pid_t pid, const struct sched_param *param) +{ + return __syscall_ret(-ENOSYS); +} diff --git a/libc-top-half/musl/src/sched/sched_setscheduler.c b/libc-top-half/musl/src/sched/sched_setscheduler.c new file mode 100644 index 0000000..4435f21 --- /dev/null +++ b/libc-top-half/musl/src/sched/sched_setscheduler.c @@ -0,0 +1,8 @@ +#include <sched.h> +#include <errno.h> +#include "syscall.h" + +int sched_setscheduler(pid_t pid, int sched, const struct sched_param *param) +{ + return __syscall_ret(-ENOSYS); +} diff --git a/libc-top-half/musl/src/sched/sched_yield.c b/libc-top-half/musl/src/sched/sched_yield.c new file mode 100644 index 0000000..ee6f0e7 --- /dev/null +++ b/libc-top-half/musl/src/sched/sched_yield.c @@ -0,0 +1,7 @@ +#include <sched.h> +#include "syscall.h" + +int sched_yield() +{ + return syscall(SYS_sched_yield); +} |