From 5ba1b8ec436c193c1935d752cc9d5367182ff241 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 2 Dec 2021 20:51:44 -0800 Subject: [PATCH] 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 (cherry picked from commit edeb3b376c5cc763d7afd4c6a63d6e70f8f9992c) Signed-off-by: Kir Kolyshkin --- libcontainer/intelrdt/intelrdt.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libcontainer/intelrdt/intelrdt.go b/libcontainer/intelrdt/intelrdt.go index 0797c82f2..27cc18f68 100644 --- a/libcontainer/intelrdt/intelrdt.go +++ b/libcontainer/intelrdt/intelrdt.go @@ -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" ) @@ -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 } @@ -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