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