Skip to content

Conversation

@pgier
Copy link
Collaborator

@pgier pgier commented Jan 20, 2020

This adds basic handling of reading /proc/cpuinfo for ARM, PPC, and
s390x.
Fixes #256

@pgier pgier force-pushed the cpuinfo-multi-platform branch from 7d614e8 to 0c0164d Compare January 21, 2020 13:17
}
field := strings.SplitN(line, ": ", 2)
switch strings.TrimSpace(field[0]) {
case "processor":

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we want to parse the "clock" field in the cpu info for cpu MHz like for x86 ?

@pgier pgier force-pushed the cpuinfo-multi-platform branch from 0c0164d to 970247d Compare January 21, 2020 16:05
@pgier
Copy link
Collaborator Author

pgier commented Jan 21, 2020

@Prashanth684 thanks for the feedback! I've added support for CPUMHz on both PPC and s390x.

@pgier pgier force-pushed the cpuinfo-multi-platform branch from 970247d to b8c92ac Compare January 21, 2020 16:17
@Prashanth684
Copy link

@Prashanth684 thanks for the feedback! I've added support for CPUMHz on both PPC and s390x.

no problem. thanks for this!

@Prashanth684
Copy link

lgtm

@discordianfish
Copy link
Member

Looks good to me in general but I'm wondering if we should rather use build flags to determine the expected format. Or is there a use case where a x64 system would read a arm cpuinfo?

@pgier
Copy link
Collaborator Author

pgier commented Feb 26, 2020

@discordianfish I did it this way originally because I was thinking that might be able to handle platforms that weren't accounted for, and it seemed easier to test this way. But I think you are right that build flags would be better.

@discordianfish
Copy link
Member

@pgier kk, awaiting your changes :)

@pgier
Copy link
Collaborator Author

pgier commented Mar 24, 2020

@discordianfish I experimented a bit with separate files and build flags for the different arches, but I don't have an easy way to test the various platforms. I'm wondering if we should just leave this as is since none of the code is really platform dependent, it only depends on the different text file formats. WDYT?

@pgier pgier force-pushed the cpuinfo-multi-platform branch from b8c92ac to 0e7d0a6 Compare March 25, 2020 00:09
@discordianfish
Copy link
Member

discordianfish commented Apr 8, 2020

@pgier Hrm I don't like this implicit runtime detection. I'd say we should either use build flags or add functions for each platform and leave it to the caller to invoke the right one for the platform.

But what was the problem with separate files and build flags? Just the tests? Maybe we could keep the functions but use platform specific files with build flags that implement the correct function for the platform, e.g:

cpuinfo_amd64.go:

var parseCPUInfo = parseCPUInfoX86

...and then you can still test all functions on x86.

@pgier pgier force-pushed the cpuinfo-multi-platform branch 2 times, most recently from 3107043 to e547684 Compare May 1, 2020 17:02
@pgier
Copy link
Collaborator Author

pgier commented May 1, 2020

@discordianfish Thanks for the suggestions, sorry it took so long to get this updated! Please take another look.

@discordianfish
Copy link
Member

Not sure we need and want to maintain the detection code. All this would work without it, right? We just need to run parseCPUInfo which is set in the platform specific files.
I'm not strictly against it, but I don't really see where this would be useful. I can't think of a case where I would like to parse a foreign cpuinfo.

pgier added 2 commits May 4, 2020 17:25
This adds basic handling of reading /proc/cpuinfo for ARM, PPC, and
s390x.

Signed-off-by: Paul Gier <[email protected]>
Use go build contraints to link the appropriate parsing function
for the each arch.

Signed-off-by: Paul Gier <[email protected]>
@pgier pgier force-pushed the cpuinfo-multi-platform branch from e547684 to e43c1ed Compare May 4, 2020 22:25
CPU detection is now done using compiler tags, so the manual
detection is no longer needed.

Signed-off-by: Paul Gier <[email protected]>
@pgier pgier force-pushed the cpuinfo-multi-platform branch from e43c1ed to acd173f Compare May 4, 2020 22:28
@pgier
Copy link
Collaborator Author

pgier commented May 4, 2020

@discordianfish ok, I have removed the format detection code.

@discordianfish discordianfish requested a review from SuperQ May 5, 2020 10:36
Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@discordianfish discordianfish merged commit 2e4c1a5 into prometheus:master May 5, 2020
@mfraioli
Copy link

mfraioli commented May 6, 2020

Hey guys, I'm trying to build some code which apparently pulls in this procfs project as a dependency, and it started failing yesterday on ppc and s390 with this error:

+ go get github.com/uber/jaeger-lib/metrics/prometheus
# github.com/prometheus/procfs
golib/src/github.com/prometheus/procfs/cpuinfo.go:71:9: undefined: parseCPUInfo

The actual go build command fails in the same way.

I assume it's related to this change. I see that parseCPUInfo is a function variable that is set in a platform-specific file to point to the platform-specific function, but I"m not clear on how the appropriate file is supposed to be included. Somehow it needs to know to use cpuinfo_ppc64.go on ppc, etc. How is this meant to be specified? Thanks!

@mfraioli
Copy link

mfraioli commented May 6, 2020

On 390 there is a slightly different error:

+ go get github.com/prometheus/client_golang/prometheus/promhttp
# github.com/prometheus/procfs
golib/src/github.com/prometheus/procfs/cpuinfo.go:71:2: not enough arguments to return
golib/src/github.com/prometheus/procfs/cpuinfo_s390x.go:19:20: undefined: parseCPUInfoS390x

This seems to be a simple typo in cpuinfo_s390x.go. It specifies the function name as parseCPUInfoS390x but it should be parseCPUInfoS390X (upper case X at the end).

For the ppc problem, the issue may be with the build constraints in cpuinfo_ppc64.go:

// +build linux
// +build ppc64,ppc64le

The Go doc on build constraints says:

A build constraint is evaluated as the OR of space-separated options. Each option evaluates as the AND of its comma-separated terms.

So that means this will only be included if both ppc64 AND ppc64le are set, but I believe only one or the other will ever be true.

@mfraioli
Copy link

mfraioli commented May 6, 2020

With

// +build ppc64,ppc64le

corrected to:

// +build ppc64 ppc64le

it still doesn't work, because go build filters by the filename as well. Since I am using ppc64le, the file cpuinfo_ppc64.go gets left out. If I rename it to cpuinfo_ppc64le.go then it works. So probably it needs to be two separate files, one for each platform.

@pgier
Copy link
Collaborator Author

pgier commented May 6, 2020

@mfraioli thanks so much for reporting this! I created #288 which hopefully fixes the issues. Can you give that one a quick look?

discordianfish pushed a commit that referenced this pull request May 11, 2020
PR #257 added basic multiplatform support for cpuinfo.

Due to this change, this library does not compile on 32-bit ARM CPUs, e.g. the armv7l in a Raspberry Pi 3b. I think this PR should solve this problem.

Signed-off-by: Tobias Gies <[email protected]>
remijouannet pushed a commit to remijouannet/procfs that referenced this pull request Oct 20, 2022
* multiplatform support for cpuinfo

This adds basic handling of reading /proc/cpuinfo for ARM, PPC, and
s390x.

Signed-off-by: Paul Gier <[email protected]>

* use build constraints to detect current platform

Use go build contraints to link the appropriate parsing function
for the each arch.

Signed-off-by: Paul Gier <[email protected]>

* remove cpuinfo format detection

CPU detection is now done using compiler tags, so the manual
detection is no longer needed.

Signed-off-by: Paul Gier <[email protected]>
remijouannet pushed a commit to remijouannet/procfs that referenced this pull request Oct 20, 2022
PR prometheus#257 added basic multiplatform support for cpuinfo.

Due to this change, this library does not compile on 32-bit ARM CPUs, e.g. the armv7l in a Raspberry Pi 3b. I think this PR should solve this problem.

Signed-off-by: Tobias Gies <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/proc/cpuinfo parsing crashes on s390x

5 participants