@@ -130,7 +130,7 @@ var (
130130 intelRdtRootLock sync.Mutex
131131
132132 // The flag to indicate if Intel RDT is supported
133- isIntelRdtEnabled bool
133+ isEnabled bool
134134)
135135
136136type intelRdtData struct {
@@ -139,6 +139,21 @@ type intelRdtData struct {
139139 pid int
140140}
141141
142+ // Check if Intel RDT is enabled in init()
143+ func init () {
144+ // 1. Check if hardware and kernel support Intel RDT/CAT feature
145+ // "cat_l3" flag is set if supported
146+ isFlagSet , err := parseCpuInfoFile ("/proc/cpuinfo" )
147+ if ! isFlagSet || err != nil {
148+ isEnabled = false
149+ return
150+ }
151+
152+ // 2. Check if Intel RDT "resource control" filesystem is mounted
153+ // The user guarantees to mount the filesystem
154+ isEnabled = isIntelRdtMounted ()
155+ }
156+
142157// Return the mount point path of Intel RDT "resource control" filesysem
143158func findIntelRdtMountpointDir () (string , error ) {
144159 f , err := os .Open ("/proc/self/mountinfo" )
@@ -369,24 +384,8 @@ func WriteIntelRdtTasks(dir string, pid int) error {
369384}
370385
371386// Check if Intel RDT is enabled
372- func IsIntelRdtEnabled () bool {
373- // We have checked the flag before
374- if isIntelRdtEnabled {
375- return true
376- }
377-
378- // 1. Check if hardware and kernel support Intel RDT/CAT feature
379- // "cat_l3" flag is set if supported
380- isFlagSet , err := parseCpuInfoFile ("/proc/cpuinfo" )
381- if ! isFlagSet || err != nil {
382- isIntelRdtEnabled = false
383- return false
384- }
385-
386- // 2. Check if Intel RDT "resource control" filesystem is mounted
387- // The user guarantees to mount the filesystem
388- isIntelRdtEnabled = isIntelRdtMounted ()
389- return isIntelRdtEnabled
387+ func IsEnabled () bool {
388+ return isEnabled
390389}
391390
392391// Get the 'container_id' path in Intel RDT "resource control" filesystem
0 commit comments