鍍金池/ 教程/ Linux/ sched_setaffinity()函數(shù) Unix/Linux
outb()函數(shù) Unix/Linux
getpeername()函數(shù) Unix/Linux
io_setup()函數(shù) Unix/Linux
mknod()函數(shù) Unix/Linux
arch_prctl()函數(shù) Unix/Linux
inotify_add_watch()函數(shù) Unix/Linux
chmod()函數(shù) Unix/Linux
_exit()函數(shù) Unix/Linux
epoll_ctl()函數(shù) Unix/Linux
Unix/Linux系統(tǒng)調(diào)用
futimesat()函數(shù) Unix/Linux
oldolduname()函數(shù) Unix/Linux
sched_rr_get_interval()函數(shù) Unix/Linux
oldstat()函數(shù) Unix/Linux
pselect()函數(shù) Unix/Linux
close()函數(shù) Unix/Linux
add_key()函數(shù) Unix/Linux
clone()函數(shù) Unix/Linux
rename()函數(shù) Unix/Linux
msgop()函數(shù) Unix/Linux
getrlimit()函數(shù) Unix/Linux
linkat()函數(shù) Unix/Linux
ioprio_set()函數(shù) Unix/Linux
insw()函數(shù) Unix/Linux
munlock()函數(shù) Unix/Linux
getgid()函數(shù) Unix/Linux
chdir()函數(shù) Unix/Linux
rmdir()函數(shù) Unix/Linux
ioctl()函數(shù) Unix/Linux
lchown()函數(shù) Unix/Linux
execve()函數(shù) Unix/Linux
epoll_wait()函數(shù) Unix/Linux
fstatat()函數(shù) Unix/Linux
truncate()函數(shù) Unix/Linux
lock()函數(shù) Unix/Linux
outsb()函數(shù) Unix/Linux
chroot()函數(shù) Unix/Linux
kexec_load()函數(shù) Unix/Linux
afs_syscall()函數(shù) Unix/Linux
dup2()函數(shù) Unix/Linux
_newselect()函數(shù) Unix/Linux
inotify_rm_watch()函數(shù) Unix/Linux
recv()函數(shù) Unix/Linux
msgsnd()函數(shù) Unix/Linux
getdtablesize()函數(shù) Unix/Linux
ioperm()函數(shù) Unix/Linux
munmap()函數(shù) Unix/Linux
getpriority()函數(shù) Unix/Linux
sched_get_priority_min()函數(shù) Unix/Linux
outw_p()函數(shù) Unix/Linux
kill()函數(shù) Unix/Linux
lookup_dcookie()函數(shù) Unix/Linux
accept()函數(shù) Unix/Linux
obsolete()函數(shù) Unix/Linux
pread()函數(shù) Unix/Linux
getgroups()函數(shù) Unix/Linux
personality()函數(shù) Unix/Linux
recvfrom()函數(shù) Unix/Linux
putpmsg()函數(shù) Unix/Linux
getgroups()函數(shù) Unix/Linux
remap_file_pages()函數(shù) Unix/Linux
request_key()函數(shù) Unix/Linux
mount()函數(shù) Unix/Linux
sched_setscheduler()函數(shù) Unix/Linux
mkdirat()函數(shù) Unix/Linux
nfsservctl()函數(shù) Unix/Linux
getuid()函數(shù) Unix/Linux
prof()函數(shù) Unix/Linux
exit_group函數(shù) Unix/Linux
io_cancel()函數(shù) Unix/Linux
mmap()函數(shù) Unix/Linux
mremap()函數(shù) Unix/Linux
getitimer()函數(shù) Unix/Linux
unimplemented()函數(shù) Unix/Linux
read()函數(shù) Unix/Linux
inl()函數(shù) Unix/Linux
posix_fadvise()函數(shù) Unix/Linux
open()函數(shù) Unix/Linux
listen()函數(shù) Unix/Linux
io_destroy()函數(shù) Unix/Linux
acct()函數(shù) Unix/Linux
fcntl()函數(shù) Unix/Linux
recvmsg()函數(shù) Unix/Linux
statfs()函數(shù) Unix/Linux
oldlstat()函數(shù) Unix/Linux
outb()函數(shù) Unix/Linux
getpagesize()函數(shù) Unix/Linux
sched_yield()函數(shù) Unix/Linux
outw()函數(shù) Unix/Linux
inw_p()函數(shù) Unix/Linux
setpgid()函數(shù) Unix/Linux
quotactl()函數(shù) Unix/Linux
prctl()函數(shù) Unix/Linux
fattach()函數(shù) Unix/Linux
readahead()函數(shù) Unix/Linux
msgget()函數(shù) Unix/Linux
gethostname()函數(shù) Unix/Linux
semctl()函數(shù) Unix/Linux
munlockall()函數(shù) Unix/Linux
iopl()函數(shù) Unix/Linux
fdetach()函數(shù) Unix/Linux
getuid()函數(shù) Unix/Linux
gettid()函數(shù) Unix/Linux
pwrite()函數(shù) Unix/Linux
isastream()函數(shù) Unix/Linux
get_thread_area()函數(shù) Unix/Linux
mpx()函數(shù) Unix/Linux
io_getevents()函數(shù) Unix/Linux
lstat()函數(shù) Unix/Linux
readv()函數(shù) Unix/Linux
exit()函數(shù) Unix/Linux
inw()函數(shù) Unix/Linux
fchmod()函數(shù) Unix/Linux
mq_getsetattr()函數(shù) Unix/Linux
get_robust_list()函數(shù) Unix/Linux
_llseek()函數(shù) Unix/Linux
gettimeofday()函數(shù) Unix/Linux
nice()函數(shù) Unix/Linux
security()函數(shù) Unix/Linux
sched_get_priority_max()函數(shù) Unix/Linux
outb_p()函數(shù) Unix/Linux
intro()函數(shù) Unix/Linux
alarm()函數(shù) Unix/Linux
putmsg()函數(shù) Unix/Linux
fork()函數(shù) Unix/Linux
getpgrp()函數(shù) Unix/Linux
link()函數(shù) Unix/Linux
getcwd()函數(shù) Unix/Linux
insl()函數(shù) Unix/Linux
getsockname()函數(shù) Unix/Linux
dup()函數(shù) Unix/Linux
connect()函數(shù) Unix/Linux
select()函數(shù) Unix/Linux
futex()函數(shù) Unix/Linux
outsw()函數(shù) Unix/Linux
query_module()函數(shù) Unix/Linux
reboot()函數(shù) Unix/Linux
create_module()函數(shù) Unix/Linux
adjtimex()函數(shù) Unix/Linux
mlock()函數(shù) Unix/Linux
statvfs()函數(shù) Unix/Linux
gtty()函數(shù) Unix/Linux
epoll_create()函數(shù) Unix/Linux
bind()函數(shù) Unix/Linux
inl_p()函數(shù) Unix/Linux
select_tut()函數(shù) Unix/Linux
mincore()函數(shù) Unix/Linux
getresuid()函數(shù) Unix/Linux
getpmsg()函數(shù) Unix/Linux
getcontext()函數(shù) Unix/Linux
killpg()函數(shù) Unix/Linux
olduname()函數(shù) Unix/Linux
openat()函數(shù) Unix/Linux
pause()函數(shù) Unix/Linux
alloc_hugepages()函數(shù) Unix/Linux
ioctl_list()函數(shù) Unix/Linux
readlinkat()函數(shù) Unix/Linux
mprotect()函數(shù) Unix/Linux
getdomainname()函數(shù) Unix/Linux
readlink()函數(shù) Unix/Linux
madvise()函數(shù) Unix/Linux
bdflush()函數(shù) Unix/Linux
ipc()函數(shù) Unix/Linux
ptrace()函數(shù) Unix/Linux
getrusage()函數(shù) Unix/Linux
msync()函數(shù) Unix/Linux
faccessat()函數(shù) Unix/Linux
modify_ldt()函數(shù) Unix/Linux
get_kernel_syms()函數(shù) Unix/Linux
getpid()函數(shù) Unix/Linux
fsync()函數(shù) Unix/Linux
msgctl()函數(shù) Unix/Linux
break未實(shí)現(xiàn) Unix/Linux
sched_setparam()函數(shù) Unix/Linux
fchown()函數(shù) Unix/Linux
cacheflush()函數(shù) Unix/Linux
fdatasync()函數(shù) Unix/Linux
flock()函數(shù) Unix/Linux
pivot_root()函數(shù) Unix/Linux
inotify_init()函數(shù) Unix/Linux
fchmodat()函數(shù) Unix/Linux
keyctl()函數(shù) Unix/Linux
llseek()函數(shù) Unix/Linux
outb()函數(shù) Unix/Linux
pipe()函數(shù) Unix/Linux
io_submit()函數(shù) Unix/Linux
ppoll()函數(shù) Unix/Linux
multiplexer()函數(shù) Unix/Linux
access()函數(shù) Unix/Linux
sched_getparam()函數(shù) Unix/Linux
chown()函數(shù) Unix/Linux
readdir()函數(shù) Unix/Linux
inb_p()函數(shù) Unix/Linux
outsl()函數(shù) Unix/Linux
nanosleep()函數(shù) Unix/Linux
alloc_hugepages()函數(shù) Unix/Linux
sbrk()函數(shù) Unix/Linux
move_pages()函數(shù) Unix/Linux
fchdir()函數(shù) Unix/Linux
renameat()函數(shù) Unix/Linux
getppid()函數(shù) Unix/Linux
getsid()函數(shù) Unix/Linux
oldfstat()函數(shù) Unix/Linux
lseek()函數(shù) Unix/Linux
stat()函數(shù) Unix/Linux
path_resolution()函數(shù) Unix/Linux
getunwind()函數(shù) Unix/Linux
getsockopt()函數(shù) Unix/Linux
mmap2()函數(shù) Unix/Linux
getdents()函數(shù) Unix/Linux
fchownat()函數(shù) Unix/Linux
mkdir()函數(shù) Unix/Linux
perfmonctl()函數(shù) Unix/Linux
open()函數(shù) Unix/Linux
idle()函數(shù) Unix/Linux
poll()函數(shù) Unix/Linux
brk()函數(shù) Unix/Linux
sched_setaffinity()函數(shù) Unix/Linux
mlockall()函數(shù) Unix/Linux

sched_setaffinity()函數(shù) Unix/Linux

sched_setaffinity, sched_getaffinity, CPU_CLR, CPU_ISSET, CPU_SET, CPU_ZERO - 設(shè)置和獲取一個(gè)進(jìn)程的CPU關(guān)聯(lián)掩碼

內(nèi)容簡(jiǎn)介

int sched_setaffinity(pid_t pid, unsigned int cpusetsize, cpu_set_t *mask);

int sched_getaffinity(pid_t pid, unsigned int cpusetsize, cpu_set_t *mask);

void CPU_CLR(int cpu, cpu_set_t *set); int CPU_ISSET(int cpu, cpu_set_t *set); void CPU_SET(int cpu, cpu_set_t *set); void CPU_ZERO(cpu_set_t *set);
#include <sched.h> 

描述

A process’s CPU affinity mask determines the set of CPUs on which it is eligible to run. On a multiprocessor system, setting the CPU affinity mask can be used to obtain performance benefits. For example, by dedicating one CPU to a particular process (i.e., setting the affinity mask of that process to specify a single CPU, and setting the affinity mask of all other processes to exclude that CPU), it is possible to ensure maximum execution speed for that process. Restricting a process to run on a single CPU also prevents the performance cost caused by the cache invalidation that occurs when a process ceases to execute on one CPU and then recommences execution on a different CPU.

A CPU affinity mask is represented by the cpu_set_t structure, a "CPU set", pointed to by mask. Four macros are provided to manipulate CPU sets. CPU_ZERO() clears a set.CPU_SET() and CPU_CLR() respectively add and remove a given CPU from a set.CPU_ISSET() tests to see if a CPU is part of the set; this is useful aftersched_getaffinity() returns. The first available CPU on the system corresponds to a cpuvalue of 0, the next CPU corresponds to a cpu value of 1, and so on. The constantCPU_SETSIZE (1024) specifies a value one greater than the maximum CPU number that can be stored in a CPU set.

sched_setaffinity() sets the CPU affinity mask of the process whose ID is pid to the value specified by mask. If pid is zero, then the calling process is used. The argumentcpusetsize is the length (in bytes) of the data pointed to by mask. Normally this argument would be specified as sizeof(cpu_set_t).

If the process specified by pid is not currently running on one of the CPUs specified inmask, then that process is migrated to one of the CPUs specified in mask.

sched_getaffinity() writes the affinity mask of the process whose ID is pid into thecpu_set_t structure pointed to by mask. The cpusetsize argument specifies the size (in bytes) of mask. If pid is zero, then the mask of the calling process is returned.

返回值

On success, sched_setaffinity() and sched_getaffinity() return 0. On error, -1 is returned, and errno is set appropriately.

錯(cuò)誤

標(biāo)簽 描述
EFAULT A supplied memory address was invalid.
EINVAL The affinity bitmask mask contains no processors that are physically on the system, or cpusetsize is smaller than the size of the affinity mask used by the kernel.
EPERM The calling process does not have appropriate privileges. The process calling sched_setaffinity() needs an effective user ID equal to the user ID or effective user ID of the process identified by pid, or it must possess the CAP_SYS_NICE capability.
ESRCH The process whose ID is pid could not be found.

遵循于

這些系統(tǒng)調(diào)用是Linux特有的。

注意

The affinity mask is actually a per-thread attribute that can be adjusted independently for each of the threads in a thread group. The value returned from a call to gettid(2) can be passed in the argument pid.

A child created via fork(2) inherits its parent’s CPU affinity mask. The affinity mask is preserved across an execve(2).

This manual page describes the glibc interface for the CPU affinity calls. The actual system call interface is slightly different, with the mask being typed as unsigned long *, reflecting that the fact that the underlying implementation of CPU sets is a simple bitmask. On success, the raw sched_getaffinity() system call returns the size (in bytes) of the cpumask_t data type that is used internally by the kernel to represent the CPU set bitmask.

HISTORY

The CPU affinity system calls were introduced in Linux kernel 2.5.8. The library interfaces were introduced in glibc 2.3. Initially, the glibc interfaces included a cpusetsize argument. In glibc 2.3.2, the cpusetsize argument was removed, but this argument was restored in glibc 2.3.4.

另請(qǐng)參閱

sched_setscheduler(2) has a description of the Linux scheduling scheme.