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)
| 390 | // Preconditions: mask.Size() == |
| 391 | // sched.CPUSetSize(t.Kernel().ApplicationCores()). |
| 392 | func (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. |
| 422 | func (t *Task) CPU() int32 { |
no test coverage detected