mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 20:24:31 +00:00
resource-control: add helper function for setting CPU affinity
Let's abstract the CPU affinity Fixes: #6044 Signed-off-by: Eric Ernst <eric_ernst@apple.com>
This commit is contained in:
parent
c6b7f69040
commit
f137048be3
10
src/runtime/pkg/resourcecontrol/utils_darwin.go
Normal file
10
src/runtime/pkg/resourcecontrol/utils_darwin.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (c) 2023 Apple Inc.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
package resourcecontrol
|
||||||
|
|
||||||
|
func SetThreadAffinity(threadID int, cpuSetSlice []int) error {
|
||||||
|
return nil
|
||||||
|
}
|
@ -15,6 +15,7 @@ import (
|
|||||||
systemdDbus "github.com/coreos/go-systemd/v22/dbus"
|
systemdDbus "github.com/coreos/go-systemd/v22/dbus"
|
||||||
"github.com/godbus/dbus/v5"
|
"github.com/godbus/dbus/v5"
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
|
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultResourceControllerID runtime-determined location in the cgroups hierarchy.
|
// DefaultResourceControllerID runtime-determined location in the cgroups hierarchy.
|
||||||
@ -141,3 +142,17 @@ func getSliceAndUnit(cgroupPath string) (string, string, error) {
|
|||||||
|
|
||||||
return "", "", fmt.Errorf("Path: %s is not valid systemd's cgroups path", cgroupPath)
|
return "", "", fmt.Errorf("Path: %s is not valid systemd's cgroups path", cgroupPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetThreadAffinity(threadID int, cpuSetSlice []int) error {
|
||||||
|
unixCPUSet := unix.CPUSet{}
|
||||||
|
|
||||||
|
for cpuId := range cpuSetSlice {
|
||||||
|
unixCPUSet.Set(cpuId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := unix.SchedSetaffinity(threadID, &unixCPUSet); err != nil {
|
||||||
|
return fmt.Errorf("failed to set vcpu thread %d affinity to cpu %d: %v", threadID, cpuSetSlice, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user