shirou / gopsutil

psutil for golang
Other
10.42k stars 1.57k forks source link

On arm64 machines, cpu.Info returns "mhz": 0 #1323

Open santosh opened 2 years ago

santosh commented 2 years ago

Describe the bug I am working on an application which has to deal with compute capacity of the host system. I am using gopsutil to get the capacity.

It works fine on amd64 machines. But when I tested on arm64 machine, the mhz field was 0.

To Reproduce

package main

import (
        "fmt"
        "github.com/shirou/gopsutil/cpu"
)

func main() {
        cores, _ := cpu.Info()

        for i := 0; i < len(cores); i++ {
                fmt.Println(cores[i].Mhz)
        }
}

Expected behavior On an arbitrary amd64 machine, I get output similar to this:

2199.998
2199.998

On an arm64 machine, I get this:

0
0

Environment (please complete the following information):

$ cat /etc/os-release 
PRETTY_NAME="Ubuntu 22.04 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

$ uname -a
Linux ip-10-2-1-38 5.15.0-1014-aws #18-Ubuntu SMP Wed Jun 15 20:06:08 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

Additional context

I am testing it on Ubuntu 22.04, but I have also tested the same thing on Ubuntu 18.04 and 20.04.

shirou commented 2 years ago

Could you tell us /proc/cpuinfo content? We want to know cpu MHz line exists and the content of that line.

santosh commented 2 years ago

@shirou No, there is no such line with MHz.

ubuntu@ip-10-2-1-38:~$ cat /proc/cpuinfo 
processor       : 0
BogoMIPS        : 243.75
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp ssbs
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x3
CPU part        : 0xd0c
CPU revision    : 1

processor       : 1
BogoMIPS        : 243.75
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp ssbs
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x3
CPU part        : 0xd0c
CPU revision    : 1

However, output of dmidecode has the info:

ubuntu@ip-10-2-1-38:~$ sudo dmidecode | grep MHz
        Max Speed: 2500 MHz
        Current Speed: 2500 MHz
Lomanic commented 2 years ago

Adding a fallback to dmidecode to get cpu frequencies was previously discussed in https://github.com/shirou/gopsutil/issues/282#issuecomment-287474911

It has too many drawbacks in my opinion to be valuable to add it as a fallback.