Skip to content

Commit

Permalink
libct/intelrdt: faster init if rdt is unsupported
Browse files Browse the repository at this point in the history
In a (quite common) case RDT is not supported by the kernel/hardware,
it does not make sense to parse /proc/cpuinfo and /proc/self/mountinfo,
and yet the current code does it (on every runc exec, for example).

Fortunately, there is a quick way to check whether RDT is available --
if so, kernel creates /sys/fs/resctrl directory. Check its existence,
and skip all the other initialization if it's not present.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Dec 3, 2021
1 parent 6c6b14e commit edeb3b3
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions libcontainer/intelrdt/intelrdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"sync"

"github.com/moby/sys/mountinfo"
"golang.org/x/sys/unix"

"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
"github.com/opencontainers/runc/libcontainer/configs"
)
Expand Down Expand Up @@ -193,21 +195,21 @@ var (
// For Intel RDT initialization
initOnce sync.Once

errNotFound = errors.New("Intel RDT resctrl mount point not found")
errNotFound = errors.New("Intel RDT not available")
)

// Check if Intel RDT sub-features are enabled in featuresInit()
func featuresInit() {
initOnce.Do(func() {
// 1. Check if hardware and kernel support Intel RDT sub-features
flagsSet, err := parseCpuInfoFile("/proc/cpuinfo")
// 1. Check if Intel RDT "resource control" filesystem is available.
// The user guarantees to mount the filesystem.
root, err := Root()
if err != nil {
return
}

// 2. Check if Intel RDT "resource control" filesystem is available.
// The user guarantees to mount the filesystem.
root, err := Root()
// 2. Check if hardware and kernel support Intel RDT sub-features.
flagsSet, err := parseCpuInfoFile("/proc/cpuinfo")
if err != nil {
return
}
Expand Down Expand Up @@ -283,6 +285,12 @@ var (
// Root returns the Intel RDT "resource control" filesystem mount point.
func Root() (string, error) {
rootOnce.Do(func() {
// If resctrl is available, kernel creates this directory.
if unix.Access("/sys/fs/resctrl", unix.F_OK) != nil {
intelRdtRootErr = errNotFound
return
}

root, err := findIntelRdtMountpointDir()
if err != nil {
intelRdtRootErr = err
Expand Down

0 comments on commit edeb3b3

Please sign in to comment.