diff --git a/sys/compat/linux/arch/amd64/syscalls.master b/sys/compat/linux/arch/amd64/syscalls.master index 2356d321a1dc..06739f8a0fed 100644 --- a/sys/compat/linux/arch/amd64/syscalls.master +++ b/sys/compat/linux/arch/amd64/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.7 2005/11/04 16:51:56 manu Exp $ + $NetBSD: syscalls.master,v 1.8 2005/11/05 08:06:58 manu Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -356,8 +356,10 @@ 202 STD { int linux_sys_futex(int *uaddr, int op, int val, \ const struct timespec *timeout, int *uaddr2, \ int val3); } -203 UNIMPL sched_setaffinity -204 UNIMPL sched_getaffinity +203 STD { int linux_sys_sched_setaffinity(pid_t pid, \ + unsigned int len, unsigned long *mask); } +204 STD { int linux_sys_sched_getaffinity(pid_t pid, \ + unsigned int len, unsigned long *mask); } 205 UNIMPL set_thread_area 206 UNIMPL io_setup 207 UNIMPL io_destroy diff --git a/sys/compat/linux/common/linux_sched.c b/sys/compat/linux/common/linux_sched.c index 5c30781a317e..aa64dce1011d 100644 --- a/sys/compat/linux/common/linux_sched.c +++ b/sys/compat/linux/common/linux_sched.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_sched.c,v 1.21 2005/11/05 00:47:26 manu Exp $ */ +/* $NetBSD: linux_sched.c,v 1.22 2005/11/05 08:06:58 manu Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -42,12 +42,14 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.21 2005/11/05 00:47:26 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.22 2005/11/05 08:06:58 manu Exp $"); #include #include #include #include +#include +#include #include #include #include @@ -445,3 +447,80 @@ linux_sys_gettid(l, v, retval) return 0; } #endif /* LINUX_NPTL */ + +int +linux_sys_sched_getaffinity(l, v, retval) + struct lwp *l; + void *v; + register_t *retval; +{ + struct linux_sys_sched_getaffinity_args /* { + syscallarg(pid_t) pid; + syscallarg(unsigned int) len; + syscallarg(unsigned long *) mask; + } */ *uap = v; + int error; + int ret; + int ncpu; + int name[2]; + size_t sz; + char *data; + int *retp; + + if (SCARG(uap, mask) == NULL) + return EINVAL; + + if (SCARG(uap, len) < sizeof(int)) + return EINVAL; + + if (pfind(SCARG(uap, pid)) == NULL) + return ESRCH; + + /* + * return the actual number of CPU, tag all of them as available + * The result is a mask, the first CPU being in the least significant + * bit. + */ + name[0] = CTL_HW; + name[1] = HW_NCPU; + sz = sizeof(ncpu); + + if ((error = old_sysctl(&name[0], 2, &ncpu, &sz, NULL, 0, NULL)) != 0) + return error; + + ret = (1 << ncpu) - 1; + + data = malloc(SCARG(uap, len), M_TEMP, M_WAITOK|M_ZERO); + retp = (int *)&data[SCARG(uap, len) - sizeof(ret)]; + *retp = ret; + + if ((error = copyout(data, SCARG(uap, mask), SCARG(uap, len))) != 0) + return error; + + free(data, M_TEMP); + + return 0; + +} + +int +linux_sys_sched_setaffinity(l, v, retval) + struct lwp *l; + void *v; + register_t *retval; +{ + struct linux_sys_sched_setaffinity_args /* { + syscallarg(pid_t) pid; + syscallarg(unsigned int) len; + syscallarg(unsigned long *) mask; + } */ *uap = v; + + if (pfind(SCARG(uap, pid)) == NULL) + return ESRCH; + + /* Let's ignore it */ +#ifdef DEBUG_LINUX + printf("linux_sys_sched_setaffinity\n"); +#endif + return 0; +};