Skip to content

Make Linux version parsing from uname more robust - #279

Closed
mgree wants to merge 1 commit into
psf:mainfrom
mgree:main
Closed

mgree wants to merge 1 commit into
psf:mainfrom
mgree:main

Conversation

@mgree

@mgree mgree commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Debian 13 (trixie, released in 2025) switched its uname output to something like 6.12.x+deb13-amd64, which puts +deb13 before the first -, which breaks the old parsing code.

This PR moves the parsing code to a function, makes it more robust, and adds a regression test (which is maybe skippable if you don't need the belt-and-suspenders approach).

I noticed this because pyperf show failed on my laptop. I got:

Unit irqbalance.service could not be found.
Show the system configuration

System state
============

CPU: use 12 logical CPUs: 0-11
Perf event: Maximum sample rate: 100000 per second
ASLR: Full randomization
CPU Frequency: 0-3,6-9=min=800 MHz, max=4800 MHz; 4-5,10-11=min=800 MHz, max=4900 MHz
IRQ affinity: Default IRQ affinity: CPU 0-11
IRQ affinity: IRQ affinity: IRQ 0-17,19,27,35,120-132,147-148,160,168,176-177,193,206-209=CPU 0-11; IRQ 149,195=CPU 1; IRQ 150,201=CPU 7; IRQ 151,197=CPU 3; IRQ 152,203=CPU 9; IRQ 153,198=CPU 4; IRQ 154,204=CPU 10; IRQ 155,199=CPU 5; IRQ 156,205=CPU 11; IRQ 157,196=CPU 2; IRQ 158,202=CPU 8; IRQ 159,194=CPU 0; IRQ 192,200=CPU 6
Power supply: the power cable is plugged
CPU scaling governor: 0-11=powersave
Turbo Boost (intel_pstate): Turbo Boost enabled

Advices
=======

Perf event: Set max sample rate to 1
CPU scaling governor: Use CPU scaling governor 'performance'
Turbo Boost (intel_pstate): Disable Turbo Boost to get more reliable CPU frequency

Errors
======

Linux scheduler: Failed to get the Linux version: release='7.3.4+deb14-amd64'

Run "python -m pyperf system tune" to tune the system configuration to run benchmarks

With the fix, I get:

Unit irqbalance.service could not be found.
Show the system configuration

System state
============

CPU: use 12 logical CPUs: 0-11
Perf event: Maximum sample rate: 100000 per second
ASLR: Full randomization
Linux scheduler: No CPU is isolated
CPU Frequency: 0-3,6-9=min=800 MHz, max=4800 MHz; 4-5,10-11=min=800 MHz, max=4900 MHz
IRQ affinity: Default IRQ affinity: CPU 0-11
IRQ affinity: IRQ affinity: IRQ 0-17,19,27,35,120-132,147-148,160,168,176-177,193,206-209=CPU 0-11; IRQ 149,195=CPU 1; IRQ 150,201=CPU 7; IRQ 151,197=CPU 3; IRQ 152,203=CPU 9; IRQ 153,198=CPU 4; IRQ 154,204=CPU 10; IRQ 155,199=CPU 5; IRQ 156,205=CPU 11; IRQ 157,196=CPU 2; IRQ 158,202=CPU 8; IRQ 159,194=CPU 0; IRQ 192,200=CPU 6
Power supply: the power cable is plugged
CPU scaling governor: 0-11=powersave
Turbo Boost (intel_pstate): Turbo Boost enabled

Advices
=======

Perf event: Set max sample rate to 1
Linux scheduler: Use isolcpus=<cpu list> kernel parameter to isolate CPUs
Linux scheduler: Use rcu_nocbs=<cpu list> kernel parameter (with isolcpus) to not schedule RCU on isolated CPUs
CPU scaling governor: Use CPU scaling governor 'performance'
Turbo Boost (intel_pstate): Disable Turbo Boost to get more reliable CPU frequency

Run "python -m pyperf system tune" to tune the system configuration to run benchmarks

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@corona10: Do you think that it's worth it to bother with supporting Linux kernel older than 3.8?

Comment thread pyperf/_system.py
version_txt = release.split('-', 1)[0]
self.linux_version = tuple(map(int, version_txt.split('.')))
except ValueError:
self.linux_version = parse_linux_version(release)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

linux_version is only needed to check if the running Linux kernel is Linux 3.8 or newer. Linux 3.8 was released 13 years ago. Maybe we can just remove the test and makes the assumption that the current Linux is more recent than that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's moderately convenient to my usecase to have pyperf system show capture the Linux kernel version for my benchmark records, but I also support not making pointless checks. I'm sure some older kernels are out there, but I'm dubious they're running a contemporary pyperf.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's moderately convenient to my usecase to have pyperf system show capture the Linux kernel version for my benchmark records

Would you mind to elaborate? Currently, os.uname()[2] is only logged if parsing the Linux fails (your issue). On success, self.linux_version is not logged.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

linux_version is only needed to check if the running Linux kernel is Linux 3.8 or newer. Linux 3.8 was released 13 years ago. Maybe we can just remove the test and makes the assumption that the current Linux is more recent than that.

We can drop the check.

Linux 3.7 was EOL in March 2013.

https://en.wikipedia.org/wiki/Linux_kernel_version_history

That's around the time Python 2.6 and 3.1 went EOL.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's moderately convenient to my usecase to have pyperf system show capture the Linux kernel version for my benchmark records

Would you mind to elaborate? Currently, os.uname()[2] is only logged if parsing the Linux fails (your issue). On success, self.linux_version is not logged.

Ah: shows how much experience I have with pyperf! There's no need to keep it from my end, then---my benchmarking will get that information elsewhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to put up a "take out the version" check PR, but y'all seem to have this well in hand. Feel free to close this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you want to open a new PR to drop this Linux version check?

If you want to log os.uname(), you should look at pyperf/_collect_metadata.py, but it should be done in a separated PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, thing, if it saves you trouble! I'll put up those two later this evening.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#281 drops the version check. Apparently the Linux kernel version will show up in the platform metadata already, so no second PR (I don't need full uname, just the version). Thanks!

@mgree mgree closed this Nov 23, 2026
@mgree mgree mentioned this pull request Nov 23, 2026
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.

3 participants