Merge release-20191114.0-14-g26b3341 (automated)

This commit is contained in:
gVisor bot 2019-11-18 22:58:57 +00:00
commit 34cd8270b2
1 changed files with 3 additions and 18 deletions

View File

@ -25,6 +25,7 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/abi/linux"
"gvisor.dev/gvisor/pkg/sentry/hostcpu"
) )
// maskPool contains reusable CPU masks for setting affinity. Unfortunately, // maskPool contains reusable CPU masks for setting affinity. Unfortunately,
@ -49,20 +50,6 @@ func unmaskAllSignals() syscall.Errno {
return errno return errno
} }
// getCPU gets the current CPU.
//
// Precondition: the current runtime thread should be locked.
func getCPU() (uint32, error) {
var cpu uintptr
if _, _, errno := syscall.RawSyscall(
unix.SYS_GETCPU,
uintptr(unsafe.Pointer(&cpu)),
0, 0); errno != 0 {
return 0, errno
}
return uint32(cpu), nil
}
// setCPU sets the CPU affinity. // setCPU sets the CPU affinity.
func (t *thread) setCPU(cpu uint32) error { func (t *thread) setCPU(cpu uint32) error {
mask := maskPool.Get().([]uintptr) mask := maskPool.Get().([]uintptr)
@ -93,10 +80,8 @@ func (t *thread) setCPU(cpu uint32) error {
// //
// Precondition: the current runtime thread should be locked. // Precondition: the current runtime thread should be locked.
func (t *thread) bind() { func (t *thread) bind() {
currentCPU, err := getCPU() currentCPU := hostcpu.GetCPU()
if err != nil {
return
}
if oldCPU := atomic.SwapUint32(&t.cpu, currentCPU); oldCPU != currentCPU { if oldCPU := atomic.SwapUint32(&t.cpu, currentCPU); oldCPU != currentCPU {
// Set the affinity on the thread and save the CPU for next // Set the affinity on the thread and save the CPU for next
// round; we don't expect CPUs to bounce around too frequently. // round; we don't expect CPUs to bounce around too frequently.