Implement Linux sched_{set|get}affinity
This commit is contained in:
parent
67fcd6abf5
commit
41455b2ed0
|
@ -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
|
||||
|
|
|
@ -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 <sys/cdefs.h>
|
||||
__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 <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/sa.h>
|
||||
#include <sys/syscallargs.h>
|
||||
#include <sys/wait.h>
|
||||
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue