Use shared_cpu_map instead of shared_cpu_list to get cache hierarchy.
This commit is contained in:
parent
f9c6329af0
commit
9f9f8ad983
@ -19,6 +19,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -143,6 +144,33 @@ func (self *realSysFs) GetCaches(id int) ([]os.FileInfo, error) {
|
|||||||
return ioutil.ReadDir(cpuPath)
|
return ioutil.ReadDir(cpuPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bitCount(i uint64) (count int) {
|
||||||
|
for i != 0 {
|
||||||
|
if i&1 == 1 {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
i >>= 1
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCpuCount(cache string) (count int, err error) {
|
||||||
|
out, err := ioutil.ReadFile(path.Join(cache, "/shared_cpu_map"))
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
masks := strings.Split(string(out), ",")
|
||||||
|
for _, mask := range masks {
|
||||||
|
// convert hex string to uint64
|
||||||
|
m, err := strconv.ParseUint(strings.TrimSpace(mask), 16, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("failed to parse cpu map %q: %v", string(out), err)
|
||||||
|
}
|
||||||
|
count += bitCount(m)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (self *realSysFs) GetCacheInfo(id int, name string) (CacheInfo, error) {
|
func (self *realSysFs) GetCacheInfo(id int, name string) (CacheInfo, error) {
|
||||||
cachePath := fmt.Sprintf("%s%d/cache/%s", cacheDir, id, name)
|
cachePath := fmt.Sprintf("%s%d/cache/%s", cacheDir, id, name)
|
||||||
out, err := ioutil.ReadFile(path.Join(cachePath, "/size"))
|
out, err := ioutil.ReadFile(path.Join(cachePath, "/size"))
|
||||||
@ -171,15 +199,14 @@ func (self *realSysFs) GetCacheInfo(id int, name string) (CacheInfo, error) {
|
|||||||
return CacheInfo{}, err
|
return CacheInfo{}, err
|
||||||
}
|
}
|
||||||
cacheType := strings.TrimSpace(string(out))
|
cacheType := strings.TrimSpace(string(out))
|
||||||
out, err = ioutil.ReadFile(path.Join(cachePath, "/shared_cpu_list"))
|
cpuCount, err := getCpuCount(cachePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CacheInfo{}, err
|
return CacheInfo{}, err
|
||||||
}
|
}
|
||||||
cpus := strings.Split(string(out), ",")
|
|
||||||
return CacheInfo{
|
return CacheInfo{
|
||||||
Size: size,
|
Size: size,
|
||||||
Level: level,
|
Level: level,
|
||||||
Type: cacheType,
|
Type: cacheType,
|
||||||
Cpus: len(cpus),
|
Cpus: cpuCount,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user