Skip to content

Commit edeb3b3

Browse files
committed
libct/intelrdt: faster init if rdt is unsupported
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 <[email protected]>
1 parent 6c6b14e commit edeb3b3

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

libcontainer/intelrdt/intelrdt.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"sync"
1313

1414
"github.com/moby/sys/mountinfo"
15+
"golang.org/x/sys/unix"
16+
1517
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
1618
"github.com/opencontainers/runc/libcontainer/configs"
1719
)
@@ -193,21 +195,21 @@ var (
193195
// For Intel RDT initialization
194196
initOnce sync.Once
195197

196-
errNotFound = errors.New("Intel RDT resctrl mount point not found")
198+
errNotFound = errors.New("Intel RDT not available")
197199
)
198200

199201
// Check if Intel RDT sub-features are enabled in featuresInit()
200202
func featuresInit() {
201203
initOnce.Do(func() {
202-
// 1. Check if hardware and kernel support Intel RDT sub-features
203-
flagsSet, err := parseCpuInfoFile("/proc/cpuinfo")
204+
// 1. Check if Intel RDT "resource control" filesystem is available.
205+
// The user guarantees to mount the filesystem.
206+
root, err := Root()
204207
if err != nil {
205208
return
206209
}
207210

208-
// 2. Check if Intel RDT "resource control" filesystem is available.
209-
// The user guarantees to mount the filesystem.
210-
root, err := Root()
211+
// 2. Check if hardware and kernel support Intel RDT sub-features.
212+
flagsSet, err := parseCpuInfoFile("/proc/cpuinfo")
211213
if err != nil {
212214
return
213215
}
@@ -283,6 +285,12 @@ var (
283285
// Root returns the Intel RDT "resource control" filesystem mount point.
284286
func Root() (string, error) {
285287
rootOnce.Do(func() {
288+
// If resctrl is available, kernel creates this directory.
289+
if unix.Access("/sys/fs/resctrl", unix.F_OK) != nil {
290+
intelRdtRootErr = errNotFound
291+
return
292+
}
293+
286294
root, err := findIntelRdtMountpointDir()
287295
if err != nil {
288296
intelRdtRootErr = err

0 commit comments

Comments
 (0)