mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
virtcontainers: use resource control for setting CPU affinity
Let's abstract the CPU affinity, instead of calling linux only code from sandbox. Fixes: #6044 Signed-off-by: Eric Ernst <eric_ernst@apple.com>
This commit is contained in:
parent
f137048be3
commit
e3d3b72fa2
@ -44,7 +44,6 @@ import (
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// sandboxTracingTags defines tags for the trace span
|
||||
@ -2540,19 +2539,14 @@ func (s *Sandbox) checkVCPUsPinning(ctx context.Context) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// if equal, we can now start vCPU threads pinning
|
||||
i := 0
|
||||
for _, tid := range vCPUThreadsMap.vcpus {
|
||||
unixCPUSet := unix.CPUSet{}
|
||||
unixCPUSet.Set(cpuSetSlice[i])
|
||||
if err := unix.SchedSetaffinity(tid, &unixCPUSet); err != nil {
|
||||
// if equal, we can use vCPU thread pinning
|
||||
for i, tid := range vCPUThreadsMap.vcpus {
|
||||
if err := resCtrl.SetThreadAffinity(tid, cpuSetSlice[i:i+1]); err != nil {
|
||||
if err := s.resetVCPUsPinning(ctx, vCPUThreadsMap, cpuSetSlice); err != nil {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("failed to set vcpu thread %d affinity to cpu %d: %v", tid, cpuSetSlice[i], err)
|
||||
}
|
||||
i++
|
||||
}
|
||||
s.isVCPUsPinningOn = true
|
||||
return nil
|
||||
@ -2560,13 +2554,9 @@ func (s *Sandbox) checkVCPUsPinning(ctx context.Context) error {
|
||||
|
||||
// resetVCPUsPinning cancels current pinning and restores default random vCPU threads scheduling
|
||||
func (s *Sandbox) resetVCPUsPinning(ctx context.Context, vCPUThreadsMap VcpuThreadIDs, cpuSetSlice []int) error {
|
||||
unixCPUSet := unix.CPUSet{}
|
||||
for cpuId := range cpuSetSlice {
|
||||
unixCPUSet.Set(cpuId)
|
||||
}
|
||||
for _, tid := range vCPUThreadsMap.vcpus {
|
||||
if err := unix.SchedSetaffinity(tid, &unixCPUSet); err != nil {
|
||||
return fmt.Errorf("failed to reset vcpu thread %d affinity to default mode: %v", tid, err)
|
||||
if err := resCtrl.SetThreadAffinity(tid, cpuSetSlice); err != nil {
|
||||
return fmt.Errorf("failed to reset vcpu thread %d affinity: %v", tid, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user