Repository navigation
fix(cpu/linux): sort processors by ID - #477
Merged
Merged
Conversation
processorsGet collects processors in a map keyed by physical package ID and builds the returned slice by ranging over it. Go randomises map iteration order, so on a multi-package host successive calls on the same hardware could return Info.Processors in different orders. Sort the result by ID. Fixes jaypipes#476 Signed-off-by: Krzysztof Cieplucha <krisiasty@gmail.com>
jaypipes
approved these changes
Sep 26, 2026
jaypipes
left a comment
Owner
There was a problem hiding this comment.
Great stuff, @krisiasty, thank you for your contribution! :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #476.
processorsGetcollects processors inmap[int]*Processorkeyed byphysical_package_idand builds the returned slice by ranging over that map. Go randomises map iteration order, so on a host with more than one package, successiveghw.CPU()calls on unchanged hardware can returnInfo.Processorsin different orders. This sorts the result byIDbefore returning.TestProcessorsSortedByIDbuilds a synthetic chroot, in the same way asTestCPUModelFromDeviceTree. It has four logical processors that alternate between packages 1 and 0, so neither directory order nor map order matches ID order. The test callscpu.New50 times and checks that the order is[0 1]every time.The test compiles and passes
go vetfor linux (GOOS=linux). I have not run it locally, because I have no Linux machine at hand, so CI here is its first run.