Merge pull request #991 from Lomanic/issue849-newer-api

[cpu][linux] Get logical cores in Counts() with non-deprecated kernel API first
pull/994/head
shirou 5 years ago committed by GitHub
commit 7e5409b131
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -313,9 +313,14 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
return ret, nil return ret, nil
} }
// physical cores // physical cores
// https://github.com/giampaolo/psutil/blob/122174a10b75c9beebe15f6c07dcf3afbe3b120d/psutil/_pslinux.py#L621-L629 // https://github.com/giampaolo/psutil/blob/8415355c8badc9c94418b19bdf26e622f06f0cce/psutil/_pslinux.py#L615-L628
var threadSiblingsLists = make(map[string]bool) var threadSiblingsLists = make(map[string]bool)
if files, err := filepath.Glob(common.HostSys("devices/system/cpu/cpu[0-9]*/topology/thread_siblings_list")); err == nil { // These 2 files are the same but */core_cpus_list is newer while */thread_siblings_list is deprecated and may disappear in the future.
// https://www.kernel.org/doc/Documentation/admin-guide/cputopology.rst
// https://github.com/giampaolo/psutil/pull/1727#issuecomment-707624964
// https://lkml.org/lkml/2019/2/26/41
for _, glob := range []string{"devices/system/cpu/cpu[0-9]*/topology/core_cpus_list", "devices/system/cpu/cpu[0-9]*/topology/thread_siblings_list"} {
if files, err := filepath.Glob(common.HostSys(glob)); err == nil {
for _, file := range files { for _, file := range files {
lines, err := common.ReadLines(file) lines, err := common.ReadLines(file)
if err != nil || len(lines) != 1 { if err != nil || len(lines) != 1 {
@ -328,6 +333,7 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
return ret, nil return ret, nil
} }
} }
}
// https://github.com/giampaolo/psutil/blob/122174a10b75c9beebe15f6c07dcf3afbe3b120d/psutil/_pslinux.py#L631-L652 // https://github.com/giampaolo/psutil/blob/122174a10b75c9beebe15f6c07dcf3afbe3b120d/psutil/_pslinux.py#L631-L652
filename := common.HostProc("cpuinfo") filename := common.HostProc("cpuinfo")
lines, err := common.ReadLines(filename) lines, err := common.ReadLines(filename)

@ -313,9 +313,14 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
return ret, nil return ret, nil
} }
// physical cores // physical cores
// https://github.com/giampaolo/psutil/blob/122174a10b75c9beebe15f6c07dcf3afbe3b120d/psutil/_pslinux.py#L621-L629 // https://github.com/giampaolo/psutil/blob/8415355c8badc9c94418b19bdf26e622f06f0cce/psutil/_pslinux.py#L615-L628
var threadSiblingsLists = make(map[string]bool) var threadSiblingsLists = make(map[string]bool)
if files, err := filepath.Glob(common.HostSys("devices/system/cpu/cpu[0-9]*/topology/thread_siblings_list")); err == nil { // These 2 files are the same but */core_cpus_list is newer while */thread_siblings_list is deprecated and may disappear in the future.
// https://www.kernel.org/doc/Documentation/admin-guide/cputopology.rst
// https://github.com/giampaolo/psutil/pull/1727#issuecomment-707624964
// https://lkml.org/lkml/2019/2/26/41
for _, glob := range []string{"devices/system/cpu/cpu[0-9]*/topology/core_cpus_list", "devices/system/cpu/cpu[0-9]*/topology/thread_siblings_list"} {
if files, err := filepath.Glob(common.HostSys(glob)); err == nil {
for _, file := range files { for _, file := range files {
lines, err := common.ReadLines(file) lines, err := common.ReadLines(file)
if err != nil || len(lines) != 1 { if err != nil || len(lines) != 1 {
@ -328,6 +333,7 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
return ret, nil return ret, nil
} }
} }
}
// https://github.com/giampaolo/psutil/blob/122174a10b75c9beebe15f6c07dcf3afbe3b120d/psutil/_pslinux.py#L631-L652 // https://github.com/giampaolo/psutil/blob/122174a10b75c9beebe15f6c07dcf3afbe3b120d/psutil/_pslinux.py#L631-L652
filename := common.HostProc("cpuinfo") filename := common.HostProc("cpuinfo")
lines, err := common.ReadLines(filename) lines, err := common.ReadLines(filename)

Loading…
Cancel
Save