Skip to content

uucore: only honour the last glibc.cpu.hwcaps setting, case-sensitively - #14844

Merged
sylvestre merged 1 commit into
uutils:mainfrom
ChihweiLHBird:zhiwei/fix-hwcaps-tunable-parsing
Oct 3, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
ChihweiLHBird:zhiwei/fix-hwcaps-tunable-parsing

Conversation

@ChihweiLHBird

@ChihweiLHBird ChihweiLHBird commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This work was a regression fix in some local work for #14805, but I think it's clearer to split it out.

GLIBC_TUNABLES=glibc.cpu.hwcaps=-NAME,... is how a user tells glibc, GNU cksum/wc and uutils to stop using a CPU feature. uutils read it more loosely than GNU: it upper-cased names, trimmed whitespace around them, and merged every glibc.cpu.hwcaps= setting instead of keeping the last one. Strings that GNU ignores therefore made wc and cksum fall back to slower paths.

This PR makes the parser read the variable the way GNU does: names are case-sensitive, a name is the whole token, and when the tunable is set more than once only the last setting counts. Leading whitespace before a setting name or a token is still accepted, as GNU accepts it (glibc itself is stricter there). One unit test per rule.

Examples (x86-64 with AVX2; only the avx2 line of the --debug output is shown)

Lower-case name: GNU compares names byte for byte, so -avx2 disables nothing.

$ GLIBC_TUNABLES=glibc.cpu.hwcaps=-avx2 cksum --debug /dev/null

Before:

avx2 support not detected

After, same as GNU:

using avx2 hardware support

Tunable set twice: only the last glibc.cpu.hwcaps= counts, so AVX2 stays enabled.

$ GLIBC_TUNABLES=glibc.cpu.hwcaps=-AVX2:glibc.cpu.hwcaps=-AVX512F cksum --debug /dev/null

Before:

avx2 support not detected

After, same as GNU:

using avx2 hardware support

Trailing space: the name is the whole token, so AVX2 does not match AVX2.

$ GLIBC_TUNABLES='glibc.cpu.hwcaps=-AVX2 ' cksum --debug /dev/null

Before:

avx2 support not detected

After, same as GNU:

using avx2 hardware support

The same parser drives wc's SIMD selection, so wc was dropping to its scalar byte counter on the same inputs. Well-formed inputs such as glibc.cpu.hwcaps=-AVX2 behave exactly as before.

@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/fix-hwcaps-tunable-parsing branch from 691fd91 to 30b1591 Compare September 24, 2026 05:44
@ChihweiLHBird
ChihweiLHBird marked this pull request as ready for review September 24, 2026 05:49
@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/fix-hwcaps-tunable-parsing branch from 30b1591 to 5efa89e Compare September 24, 2026 05:52
@codspeed

codspeed Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 46.81%

❌ 1 regressed benchmark
✅ 390 untouched benchmarks
⏩ 54 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation three_39_bit_primes 371.5 ms 698.4 ms -46.81%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ChihweiLHBird:zhiwei/fix-hwcaps-tunable-parsing (63026b3) with main (c1883e1)2

Open in CodSpeed

Footnotes

  1. 54 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (c0d5e57) during the generation of this report, so c1883e1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)

Comment thread src/uucore/src/lib/features/hardware.rs Outdated
Comment thread src/uucore/src/lib/features/hardware.rs
Comment thread src/uucore/src/lib/features/hardware.rs
@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/fix-hwcaps-tunable-parsing branch from 5efa89e to 73be728 Compare September 24, 2026 16:17
Comment thread tests/by-util/test_cksum.rs Outdated
@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/fix-hwcaps-tunable-parsing branch 2 times, most recently from fd203e9 to 145840b Compare September 24, 2026 23:45
@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/fix-hwcaps-tunable-parsing branch 3 times, most recently from 82f5c14 to 4d4f267 Compare September 27, 2026 19:31
@ChihweiLHBird

Copy link
Copy Markdown
Contributor Author

Merging this PR will degrade performance by 8.57%

⚡ 2 improved benchmarks ❌ 1 regressed benchmark ✅ 386 untouched benchmarks ⏩ 54 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation three_39_bit_primes 544.2 ms 880.2 ms -38.17%
⚡ Simulation five_38_bit_primes 1.8 s 1.6 s +13.56%
⚡ Simulation thirteen_39_bit_primes 9.4 s 8.7 s +8.86%
Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.

Comparing ChihweiLHBird:zhiwei/fix-hwcaps-tunable-parsing (4d4f267) with main (caa6334)

Open in CodSpeed

Footnotes

  1. 54 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

I think this is a false positive. I don't think the change touched any of these failed performance tests.

Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/fix-hwcaps-tunable-parsing branch from 4d4f267 to 63026b3 Compare September 28, 2026 19:28
@sylvestre
sylvestre merged commit 6b79fdc into uutils:main Oct 3, 2026
187 of 188 checks passed
@ChihweiLHBird
ChihweiLHBird deleted the zhiwei/fix-hwcaps-tunable-parsing branch October 4, 2026 02:14
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.

2 participants