lscpu: fix panic when physical_package_id is -1 - #622
Open
mmclinton wants to merge 1 commit into
Open
Conversation
The kernel falls back to -1 in /sys/devices/system/cpu/cpuN/topology/physical_package_id when the architecture does not expose physical package information: https://www.kernel.org/doc/html/latest/admin-guide/cputopology.html Issue uutils#495 reports exactly this on ppc64, where parsing the value as usize made lscpu panic. Parse it as i64 instead, so unknown ids collapse into a single socket bucket, matching the Socket(s): 1 that util-linux lscpu is observed to report there. Fixes uutils#495
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 #495
lscpupanics withParseIntError { kind: InvalidDigit }atsysfs.rs:57on machines where/sys/devices/system/cpu/cpuN/topology/physical_package_idcontains-1.-1is the kernel's documented fallback forphysical_package_idwhen the architecture does not define the corresponding topology macro (observed on ppc64 in #495): https://www.kernel.org/doc/html/latest/admin-guide/cputopology.htmlThe code parsed the value as
usize, so the fallback value failed to parse and theunwrap()panicked. This PR parses it asi64instead.pkg_idis only used for a distinct-count insocket_count(), so-1needs no special-casing: all-unknown ids collapse into a single socket bucket, which matches what util-linuxlscpuis observed to report (Socket(s): 1) under the same conditions.core_idis left asusize: the kernel's documented fallback for it is0, not-1.Testing
-1over everyphysical_package_idin a mount namespace (unshare -Urm); after the fix the same setup exits 0 and reportsSocket(s): 1, the same topology values util-linuxlscpuprints there.socket_count()/core_count()with unknown (-1) package ids.