From owner-svn-src-all@FreeBSD.ORG Mon Oct 20 11:15:58 2008 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 38F3D106566B; Mon, 20 Oct 2008 11:15:58 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 25EE38FC0A; Mon, 20 Oct 2008 11:15:58 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9KBFwoi069541; Mon, 20 Oct 2008 11:15:58 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9KBFvoE069538; Mon, 20 Oct 2008 11:15:57 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <200810201115.m9KBFvoE069538@svn.freebsd.org> From: Konstantin Belousov Date: Mon, 20 Oct 2008 11:15:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184075 - in stable/7/sys: . amd64/linux32 compat/linux i386/linux X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Oct 2008 11:15:58 -0000 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 #include #include +#include #include @@ -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); }