-
Notifications
You must be signed in to change notification settings - Fork 357
multiplatform support for cpuinfo #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multiplatform support for cpuinfo #257
Conversation
7d614e8 to
0c0164d
Compare
| } | ||
| field := strings.SplitN(line, ": ", 2) | ||
| switch strings.TrimSpace(field[0]) { | ||
| case "processor": |
There was a problem hiding this comment.
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 ?
0c0164d to
970247d
Compare
|
@Prashanth684 thanks for the feedback! I've added support for CPUMHz on both PPC and s390x. |
970247d to
b8c92ac
Compare
no problem. thanks for this! |
|
lgtm |
|
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? |
|
@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. |
|
@pgier kk, awaiting your changes :) |
|
@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? |
b8c92ac to
0e7d0a6
Compare
|
@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: ...and then you can still test all functions on x86. |
3107043 to
e547684
Compare
|
@discordianfish Thanks for the suggestions, sorry it took so long to get this updated! Please take another look. |
|
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. |
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]>
e547684 to
e43c1ed
Compare
CPU detection is now done using compiler tags, so the manual detection is no longer needed. Signed-off-by: Paul Gier <[email protected]>
e43c1ed to
acd173f
Compare
|
@discordianfish ok, I have removed the format detection code. |
SuperQ
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
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: The actual 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 |
|
On 390 there is a slightly different error: This seems to be a simple typo in For the ppc problem, the issue may be with the build constraints in The Go doc on build constraints says:
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. |
|
With corrected to: it still doesn't work, because |
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]>
* 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]>
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]>
This adds basic handling of reading /proc/cpuinfo for ARM, PPC, and
s390x.
Fixes #256