|
1 | 1 | package intelrdt |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "bufio" |
5 | 4 | "bytes" |
6 | 5 | "errors" |
7 | 6 | "fmt" |
@@ -201,45 +200,33 @@ func featuresInit() { |
201 | 200 | return |
202 | 201 | } |
203 | 202 |
|
204 | | - // 2. Check if hardware and kernel support Intel RDT sub-features. |
205 | | - flagsSet, err := parseCpuInfoFile("/proc/cpuinfo") |
206 | | - if err != nil { |
207 | | - return |
208 | | - } |
209 | | - |
210 | | - // 3. Double check if Intel RDT sub-features are available in |
211 | | - // "resource control" filesystem. Intel RDT sub-features can be |
| 203 | + // 2. Check if Intel RDT sub-features are available in "resource |
| 204 | + // control" filesystem. Intel RDT sub-features can be |
212 | 205 | // selectively disabled or enabled by kernel command line |
213 | 206 | // (e.g., rdt=!l3cat,mba) in 4.14 and newer kernel |
214 | | - if flagsSet.CAT { |
215 | | - if _, err := os.Stat(filepath.Join(root, "info", "L3")); err == nil { |
216 | | - catEnabled = true |
217 | | - } |
| 207 | + if _, err := os.Stat(filepath.Join(root, "info", "L3")); err == nil { |
| 208 | + catEnabled = true |
218 | 209 | } |
219 | 210 | if mbaScEnabled { |
220 | | - // We confirm MBA Software Controller is enabled in step 2, |
| 211 | + // We confirm MBA Software Controller is enabled in step 1, |
221 | 212 | // MBA should be enabled because MBA Software Controller |
222 | 213 | // depends on MBA |
223 | 214 | mbaEnabled = true |
224 | | - } else if flagsSet.MBA { |
225 | | - if _, err := os.Stat(filepath.Join(root, "info", "MB")); err == nil { |
226 | | - mbaEnabled = true |
227 | | - } |
| 215 | + } else if _, err := os.Stat(filepath.Join(root, "info", "MB")); err == nil { |
| 216 | + mbaEnabled = true |
228 | 217 | } |
229 | | - if flagsSet.MBMTotal || flagsSet.MBMLocal || flagsSet.CMT { |
230 | | - if _, err := os.Stat(filepath.Join(root, "info", "L3_MON")); err != nil { |
231 | | - return |
232 | | - } |
233 | | - enabledMonFeatures, err = getMonFeatures(root) |
234 | | - if err != nil { |
235 | | - return |
236 | | - } |
237 | | - if enabledMonFeatures.mbmTotalBytes || enabledMonFeatures.mbmLocalBytes { |
238 | | - mbmEnabled = true |
239 | | - } |
240 | | - if enabledMonFeatures.llcOccupancy { |
241 | | - cmtEnabled = true |
242 | | - } |
| 218 | + if _, err := os.Stat(filepath.Join(root, "info", "L3_MON")); err != nil { |
| 219 | + return |
| 220 | + } |
| 221 | + enabledMonFeatures, err = getMonFeatures(root) |
| 222 | + if err != nil { |
| 223 | + return |
| 224 | + } |
| 225 | + if enabledMonFeatures.mbmTotalBytes || enabledMonFeatures.mbmLocalBytes { |
| 226 | + mbmEnabled = true |
| 227 | + } |
| 228 | + if enabledMonFeatures.llcOccupancy { |
| 229 | + cmtEnabled = true |
243 | 230 | } |
244 | 231 | }) |
245 | 232 | } |
@@ -298,58 +285,6 @@ func Root() (string, error) { |
298 | 285 | return intelRdtRoot, intelRdtRootErr |
299 | 286 | } |
300 | 287 |
|
301 | | -type cpuInfoFlags struct { |
302 | | - CAT bool // Cache Allocation Technology |
303 | | - MBA bool // Memory Bandwidth Allocation |
304 | | - |
305 | | - // Memory Bandwidth Monitoring related. |
306 | | - MBMTotal bool |
307 | | - MBMLocal bool |
308 | | - |
309 | | - CMT bool // Cache Monitoring Technology |
310 | | -} |
311 | | - |
312 | | -func parseCpuInfoFile(path string) (cpuInfoFlags, error) { |
313 | | - infoFlags := cpuInfoFlags{} |
314 | | - |
315 | | - f, err := os.Open(path) |
316 | | - if err != nil { |
317 | | - return infoFlags, err |
318 | | - } |
319 | | - defer f.Close() |
320 | | - |
321 | | - s := bufio.NewScanner(f) |
322 | | - for s.Scan() { |
323 | | - line := s.Text() |
324 | | - |
325 | | - // Search "cat_l3" and "mba" flags in first "flags" line |
326 | | - if strings.HasPrefix(line, "flags") { |
327 | | - flags := strings.Split(line, " ") |
328 | | - // "cat_l3" flag for CAT and "mba" flag for MBA |
329 | | - for _, flag := range flags { |
330 | | - switch flag { |
331 | | - case "cat_l3": |
332 | | - infoFlags.CAT = true |
333 | | - case "mba": |
334 | | - infoFlags.MBA = true |
335 | | - case "cqm_mbm_total": |
336 | | - infoFlags.MBMTotal = true |
337 | | - case "cqm_mbm_local": |
338 | | - infoFlags.MBMLocal = true |
339 | | - case "cqm_occup_llc": |
340 | | - infoFlags.CMT = true |
341 | | - } |
342 | | - } |
343 | | - return infoFlags, nil |
344 | | - } |
345 | | - } |
346 | | - if err := s.Err(); err != nil { |
347 | | - return infoFlags, err |
348 | | - } |
349 | | - |
350 | | - return infoFlags, nil |
351 | | -} |
352 | | - |
353 | 288 | // Gets a single uint64 value from the specified file. |
354 | 289 | func getIntelRdtParamUint(path, file string) (uint64, error) { |
355 | 290 | fileName := filepath.Join(path, file) |
|
0 commit comments