Date: Mon, 20 Oct 2008 11:15:57 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org Subject: svn commit: r184075 - in stable/7/sys: . amd64/linux32 compat/linux i386/linux Message-ID: <200810201115.m9KBFvoE069538@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Mon Oct 20 11:15:57 2008 New Revision: 184075 URL: http://svn.freebsd.org/changeset/base/184075 Log: MFC r177257 (by rdivacky): Implement sched_setaffinity and get_setaffinity using real cpu affinity setting primitives. MFC r177604 (by ru): Fix build. MFC r183612: Use FreeBSD size of cpuset_t for bitmap size parameter and return EINVAL if length of user space bitmap less than our size of cpuset_t. Approved by: re (kensmith) Modified: stable/7/sys/ (props changed) stable/7/sys/amd64/linux32/syscalls.master stable/7/sys/compat/linux/linux_misc.c stable/7/sys/i386/linux/syscalls.master Modified: stable/7/sys/amd64/linux32/syscalls.master ============================================================================== --- stable/7/sys/amd64/linux32/syscalls.master Mon Oct 20 10:11:33 2008 (r184074) +++ stable/7/sys/amd64/linux32/syscalls.master Mon Oct 20 11:15:57 2008 (r184075) @@ -407,7 +407,8 @@ 239 AUE_SENDFILE UNIMPL linux_sendfile64 240 AUE_NULL STD { int linux_sys_futex(void *uaddr, int op, int val, \ struct l_timespec *timeout, void *uaddr2, int val3); } -241 AUE_NULL UNIMPL linux_sched_setaffinity +241 AUE_NULL STD { int linux_sched_setaffinity(l_pid_t pid, l_uint len, \ + l_ulong *user_mask_ptr); } 242 AUE_NULL STD { int linux_sched_getaffinity(l_pid_t pid, l_uint len, \ l_ulong *user_mask_ptr); } 243 AUE_NULL STD { int linux_set_thread_area(struct l_user_desc *desc); } Modified: stable/7/sys/compat/linux/linux_misc.c ============================================================================== --- stable/7/sys/compat/linux/linux_misc.c Mon Oct 20 10:11:33 2008 (r184074) +++ stable/7/sys/compat/linux/linux_misc.c Mon Oct 20 11:15:57 2008 (r184075) @@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$"); #include <sys/vmmeter.h> #include <sys/vnode.h> #include <sys/wait.h> +#include <sys/cpuset.h> #include <security/mac/mac_framework.h> @@ -1730,22 +1731,57 @@ linux_prctl(struct thread *td, struct li } /* - * XXX: fake one.. waiting for real implementation of affinity mask. + * Get affinity of a process. */ int linux_sched_getaffinity(struct thread *td, struct linux_sched_getaffinity_args *args) { int error; - cpumask_t i = ~0; + struct cpuset_getaffinity_args cga; - if (args->len < sizeof(cpumask_t)) +#ifdef DEBUG + if (ldebug(sched_getaffinity)) + printf(ARGS(sched_getaffinity, "%d, %d, *"), args->pid, + args->len); +#endif + if (args->len < sizeof(cpuset_t)) return (EINVAL); - error = copyout(&i, args->user_mask_ptr, sizeof(cpumask_t)); - if (error) - return (EFAULT); + cga.level = CPU_LEVEL_WHICH; + cga.which = CPU_WHICH_PID; + cga.id = args->pid; + cga.cpusetsize = sizeof(cpuset_t); + cga.mask = (cpuset_t *) args->user_mask_ptr; - td->td_retval[0] = sizeof(cpumask_t); - return (0); + if ((error = cpuset_getaffinity(td, &cga)) == 0) + td->td_retval[0] = sizeof(cpuset_t); + + return (error); +} + +/* + * Set affinity of a process. + */ +int +linux_sched_setaffinity(struct thread *td, + struct linux_sched_setaffinity_args *args) +{ + struct cpuset_setaffinity_args csa; + +#ifdef DEBUG + if (ldebug(sched_setaffinity)) + printf(ARGS(sched_setaffinity, "%d, %d, *"), args->pid, + args->len); +#endif + if (args->len < sizeof(cpuset_t)) + return (EINVAL); + + csa.level = CPU_LEVEL_WHICH; + csa.which = CPU_WHICH_PID; + csa.id = args->pid; + csa.cpusetsize = sizeof(cpuset_t); + csa.mask = (cpuset_t *) args->user_mask_ptr; + + return (cpuset_setaffinity(td, &csa)); } Modified: stable/7/sys/i386/linux/syscalls.master ============================================================================== --- stable/7/sys/i386/linux/syscalls.master Mon Oct 20 10:11:33 2008 (r184074) +++ stable/7/sys/i386/linux/syscalls.master Mon Oct 20 11:15:57 2008 (r184075) @@ -409,7 +409,8 @@ 239 AUE_SENDFILE UNIMPL linux_sendfile64 240 AUE_NULL STD { int linux_sys_futex(void *uaddr, int op, int val, \ struct l_timespec *timeout, void *uaddr2, int val3); } -241 AUE_NULL UNIMPL linux_sched_setaffinity +241 AUE_NULL STD { int linux_sched_setaffinity(l_pid_t pid, l_uint len, \ + l_ulong *user_mask_ptr); } 242 AUE_NULL STD { int linux_sched_getaffinity(l_pid_t pid, l_uint len, \ l_ulong *user_mask_ptr); } 243 AUE_NULL STD { int linux_set_thread_area(struct l_user_desc *desc); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200810201115.m9KBFvoE069538>