// Copyright 2018 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// CPU affinity functionspackage uniximport ()const cpuSetSize = _CPU_SETSIZE / _NCPUBITS// CPUSet represents a CPU affinity mask.typeCPUSet [cpuSetSize]cpuMaskfunc schedAffinity( uintptr, int, *CPUSet) error { , , := RawSyscall(, uintptr(), uintptr(unsafe.Sizeof(*)), uintptr(unsafe.Pointer()))if != 0 {returnerrnoErr() }returnnil}// SchedGetaffinity gets the CPU affinity mask of the thread specified by pid.// If pid is 0 the calling thread is used.func ( int, *CPUSet) error {returnschedAffinity(SYS_SCHED_GETAFFINITY, , )}// SchedSetaffinity sets the CPU affinity mask of the thread specified by pid.// If pid is 0 the calling thread is used.func ( int, *CPUSet) error {returnschedAffinity(SYS_SCHED_SETAFFINITY, , )}// Zero clears the set s, so that it contains no CPUs.func ( *CPUSet) () {clear([:])}// Fill adds all possible CPU bits to the set s. On Linux, [SchedSetaffinity]// will silently ignore any invalid CPU bits in [CPUSet] so this is an// efficient way of resetting the CPU affinity of a process.func ( *CPUSet) () {for := range { [] = ^cpuMask(0) }}func cpuBitsIndex( int) int {return / _NCPUBITS}func cpuBitsMask( int) cpuMask {returncpuMask(1 << (uint() % _NCPUBITS))}// Set adds cpu to the set s.func ( *CPUSet) ( int) { := cpuBitsIndex()if < len() { [] |= cpuBitsMask() }}// Clear removes cpu from the set s.func ( *CPUSet) ( int) { := cpuBitsIndex()if < len() { [] &^= cpuBitsMask() }}// IsSet reports whether cpu is in the set s.func ( *CPUSet) ( int) bool { := cpuBitsIndex()if < len() {return []&cpuBitsMask() != 0 }returnfalse}// Count returns the number of CPUs in the set s.func ( *CPUSet) () int { := 0for , := range { += bits.OnesCount64(uint64()) }return}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.