shirou / gopsutil

psutil for golang
Other
10.6k stars 1.59k forks source link

/proc/cpuinfo on ARM processors includes Hardware field #881

Open tmm1 opened 4 years ago

tmm1 commented 4 years ago

On most ARM cpus, there is no Vendor or Family or Model fields in /proc/cpuinfo. The data gathered by gopsutil is very minimal:

{"cpu":0,"vendorId":"","family":"","model":"","stepping":0,"physicalId":"","coreId":"0","cores":1,"mofelName":"AArch64 Processor rev 4 (aarch64)","mhz":1512,"cacheSize":0,"flags":null,"microcode":""}

However, there are some extra fields at the end of cpuinfo not currently parsed including Hardware:

Processor       : AArch64 Processor rev 4 (aarch64)
processor       : 0
processor       : 1
processor       : 2
processor       : 3
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 wp half thumb fastmult vfp edsp neon vfpv3 tlsi vfpv4 idiva idivt 
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

Hardware        : Amlogic
Serial          : beca79021141185f
AmLogic Serial  : 210d740041443cd1828b454f6133c990

I would like to add support for this. Should I put the value of Hardware into one of the existing fields, or add a new field?

cc @Lomanic

Lomanic commented 4 years ago

That looks a great info to retrieve as in this case VendorID, Family and ModelName are empty, but information isn't standardized, on my phone this field is set to Qualcomm Technologies, Inc MSM8953 and I don't have Serial nor AmLogic Serial fields.

So we can't just blindly set VendorID to this value for example. I'm inclined to set ModelName to this value, but I would like more samples from other vendors.

At least we can safely set VendorID to "Amlogic" if there is an AmLogic Serial field present.

tmm1 commented 4 years ago

I only found one device with AmLogic Serial, and four others only say Hardware: Amlogic

tmm1 commented 4 years ago

Here's another one:

/ # cat /proc/cpuinfo
proot info: vpid 11: pid 3753
processor   : 0
model name  : ARMv7 Processor rev 1 (v7l)
BogoMIPS    : 34.37
Features    : half thumb fastmult vfp edsp vfpv3 vfpv3d16 tls idivt
CPU implementer : 0x56
CPU architecture: 7
CPU variant : 0x1
CPU part    : 0x581
CPU revision    : 1

Hardware    : Marvell Armada 370/XP (Device Tree)
Revision    : 0000
Serial      : 0000000000000000

So atleast two vendors are using this Hardware field. I think we should add support for it.

tmm1 commented 4 years ago

I found more samples for you:

Linux raspberrypi 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l GNU/Linux

processor : 0
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4

processor : 1
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4

processor : 2
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4

processor : 3
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4

Hardware : BCM2709
Revision : a22082
Serial : 000000000db98e4e
processor : 0
model name : ARMv7 Processor rev 1 (v7l)
BogoMIPS : 1594.16
Features : swp half thumb fastmult vfp edsp neon vfpv3 tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x4
CPU part : 0xc09
CPU revision : 1

processor : 1
model name : ARMv7 Processor rev 1 (v7l)
BogoMIPS : 1594.16
Features : swp half thumb fastmult vfp edsp neon vfpv3 tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x4
CPU part : 0xc09
CPU revision : 1

Hardware : Marvell Armada 375 (Device Tree)
Revision : 0000
Serial : 0000000000000000
Processor : ARMv7 Processor rev 1 (v7l)
processor : 0
BogoMIPS : 1299.25

processor : 1
BogoMIPS : 1292.69

Features : swp half thumb fastmult vfp edsp neon vfpv3 tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x2
CPU part : 0xc09
CPU revision : 1

Hardware : Comcerto 2000 EVM
Revision : 0001
Serial : 0000000000000000
processor : 0
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 2793.47
Features : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x2
CPU part : 0xc0f
CPU revision : 4

processor : 1
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 2793.47
Features : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x2
CPU part : 0xc0f
CPU revision : 4

Hardware : AnnapurnaLabs Alpine (Device Tree)
Revision : 0000
Serial : 0000000000000000
Linux Everest 3.2.40 #7321 SMP Wed Mar 23 11:47:17 CST 2016 armv7l GNU/Linux synology_armada375_ds115
Processor : ARMv7 Processor rev 1 (v7l)
processor : 0
BogoMIPS : 1594.16

processor : 1
BogoMIPS : 1594.16

Features : swp half thumb fastmult vfp edsp neon vfpv3 tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x4
CPU part : 0xc09
CPU revision : 1

Hardware : Marvell Armada-375 Board
Revision : 0000
Serial : 0000000000000000
Processor : Marvell PJ4Bv7 Processor rev 2 (v7l)
processor : 0
BogoMIPS : 1196.85

processor : 1
BogoMIPS : 1196.85

processor : 2
BogoMIPS : 1196.85

Features : swp half thumb fastmult vfp edsp vfpv3 tls
CPU implementer : 0x56
CPU architecture: 7
CPU variant : 0x2
CPU part : 0x584
CPU revision : 2

Hardware : Marvell Armada XP Development Board
Revision : 0000
Serial : 0000000000000000
Linux Qbert 3.4.6 #1 Tue Jan 19 11:45:35 CST 2016 armv5tel unknown
[~] # cat /proc/cpuinfo
Processor name : Feroceon 88F6281 rev 1 (v5l) @ 1.2 GHz
BogoMIPS : 1196.85
Features : swp half thumb fastmult edsp
CPU implementer : 0x56
CPU architecture: 5TE
CPU variant : 0x2
CPU part : 0x131
CPU revision : 1

Hardware : Feroceon-KW ARM
Revision : 0000
Serial : 0000000000000000
root@ReadyNAS:~# cat /proc/cpuinfo
Processor : Feroceon 88FR131 rev 1 (v5l)
BogoMIPS : 1599.07
Features : swp half thumb fastmult edsp
CPU implementer : 0x56
CPU architecture: 5TE
CPU variant : 0x2
CPU part : 0x131
CPU revision : 1

Hardware : Feroceon-KW
Revision : 0000
Serial : 0000000000000000
Lomanic commented 4 years ago

Thanks for these samples, could you please edit your message so it's easier to see where they begin/end? Was confused for a moment as I was seeing numerous Hardware fields for what I thought was the same file.

From what I see, it confirms that setting the ModelName field to the value of the Hardware field (if not already set) is meaningful.

I won't be able to implement this soon as I will be on holidays for 7 days starting this Saturday.

tmm1 commented 4 years ago

Hmm, each one is in a separate code block. I see white space between each block on the github website.

Since you agree I can try to make a PR.

Lomanic commented 4 years ago

Oops, it was my mobile client (Octodroid) that didn't visually separate the different sections.

Thanks in advance if you submit a PR.

tmm1 commented 4 years ago

From RPI4:

processor       : 0
BogoMIPS        : 108.00
Features        : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3

Hardware        : BCM2835
Revision        : b03112
Serial          : 100000000f5870bd
Model           : Raspberry Pi 4 Model B Rev 1.2
Lomanic commented 3 years ago

I worked on this issue in the following branch https://github.com/Lomanic/gopsutil/tree/issue881 (WIP, will have to rewrite history).

If you check cpu_test_linux.go in the mocked CPUInfo test, you will see how it would be returned for my test cases. I don't find it really coherent to return in this example Marvell Armada 375 (Device Tree) as Model while on an Intel cpu the descriptive name is in ModelName.

Because of this I was thinking about assigning Marvell Armada 375 (Device Tree) to ModelName and ARMv7 Processor rev 1 (v7l) to Model instead, but this is quite breaking backward compatibility, and I'm not so sure if the Hardware field is present in all arm cpuinfo files.