MCPcopy
hub / github.com/google/gvisor / SetCPUMask

Method SetCPUMask

pkg/sentry/kernel/task_sched.go:392–419  ·  view source on GitHub ↗

SetCPUMask sets t's allowed CPU mask based on mask. It takes ownership of mask. Preconditions: mask.Size() == sched.CPUSetSize(t.Kernel().ApplicationCores()).

(mask sched.CPUSet)

Source from the content-addressed store, hash-verified

390// Preconditions: mask.Size() ==
391// sched.CPUSetSize(t.Kernel().ApplicationCores()).
392func (t *Task) SetCPUMask(mask sched.CPUSet) error {
393 if want := sched.CPUSetSize(t.k.applicationCores); mask.Size() != want {
394 panic(fmt.Sprintf("Invalid CPUSet %v (expected %d bytes)", mask, want))
395 }
396
397 // Remove CPUs in mask above Kernel.applicationCores.
398 mask.ClearAbove(t.k.applicationCores)
399
400 // Ensure that at least 1 CPU is still allowed.
401 if mask.NumCPUs() == 0 {
402 return linuxerr.EINVAL
403 }
404
405 if t.k.useHostCores || t.k.Platform.HasCPUNumbers() {
406 // No-op; pretend the mask was immediately changed back.
407 return nil
408 }
409
410 t.tg.pidns.owner.mu.RLock()
411 rootTID := t.tg.pidns.owner.Root.tids[t]
412 t.tg.pidns.owner.mu.RUnlock()
413
414 t.mu.Lock()
415 defer t.mu.Unlock()
416 t.allowedCPUMask = mask
417 t.cpu.Store(assignCPU(mask, rootTID))
418 return nil
419}
420
421// CPU returns the cpu id for a given task.
422func (t *Task) CPU() int32 {

Callers 1

SchedSetaffinityFunction · 0.95

Calls 11

CPUSetSizeFunction · 0.92
assignCPUFunction · 0.85
ClearAboveMethod · 0.80
SizeMethod · 0.65
NumCPUsMethod · 0.65
HasCPUNumbersMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65
StoreMethod · 0.65
RLockMethod · 0.45
RUnlockMethod · 0.45

Tested by

no test coverage detected