Skip to content
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

llvmPackages.bolt: add experimental bolt hook #375435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RossComputerGuy
Copy link
Member

Things done

Experimental concept, this adds a hook which calls bolt on the installed binaries. The idea is this will optimize the installed binaries. We'll test with just hello however all packages can be tried by enabling useBolt when specifying the cross platform.

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: stdenv Standard environment 6.topic: lib The Nixpkgs function library 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related labels Jan 21, 2025
@RossComputerGuy RossComputerGuy force-pushed the feat/llvm-bolt-hook branch 2 times, most recently from 1b7ad73 to 27d0f64 Compare January 21, 2025 06:14
@RossComputerGuy RossComputerGuy force-pushed the feat/llvm-bolt-hook branch 2 times, most recently from fd1b9b5 to 6554b12 Compare January 21, 2025 06:37
@RossComputerGuy RossComputerGuy force-pushed the feat/llvm-bolt-hook branch 2 times, most recently from 0ba380f to e1a994c Compare January 21, 2025 07:19
@@ -211,6 +211,20 @@ let
};
};

pkgsBolt = nixpkgsFun {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need this? I'm not sure every possible thing you can set on a platform needs its own package set, and I especially don't think we need Hydra to build every single-change stdenv.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can drop it before merging but for the purposes of testing this PR, I added it in.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this sort of thing is useful to have. For what it's worth. I don't think its existence needs to promise that it will work, much the same as for pkgsStatic and friends as well. It is quite powerful to have a simple name for this thing to reach for from the shell.

Copy link
Member

Choose a reason for hiding this comment

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

The problem is that these things also make it way too easy to use them within Nixpkgs, and then we end up with a layering violation where a single package is going through a whole distinct package set out of convenience.

But that's a general problem that needs to be solved, by making these inaccessible from within Nixpkgs while still being a convenience layer on top, so if this is really useful it can stay. I think there's no justification for building this set on Hydra, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is that these things also make it way too easy to use them within Nixpkgs, and then we end up with a layering violation where a single package is going through a whole distinct package set out of convenience.

We can add in a config option similar to the aliases one which enables the subsets. Then have it disabled in Hydra / CI.

But that's a general problem that needs to be solved, by making these inaccessible from within Nixpkgs while still being a convenience layer on top, so if this is really useful it can stay. I think there's no justification for building this set on Hydra, though.

I kinda agree but its also good to ensure things work.

Copy link
Member

Choose a reason for hiding this comment

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

That relies on somebody actively monitoring that on Hydra indefinitely, which has not historically happened for this sort of thing. Hydra isn't really a great system for "ensuring things work" due to the lack of notifications.

Copy link
Member

Choose a reason for hiding this comment

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

The problem is that these things also make it way too easy to use them within Nixpkgs, and then we end up with a layering violation where a single package is going through a whole distinct package set out of convenience.

We can add in a config option similar to the aliases one which enables the subsets. Then have it disabled in Hydra / CI.

Oh that's not a bad idea!

@RossComputerGuy
Copy link
Member Author

hello with gcc - 77kb binary size:

0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 1584maxresident)k
4520inputs+0outputs (12major+81minor)pagefaults 0swaps

hello with llvm - 49kb binary size:

0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 2640maxresident)k
0inputs+0outputs (0major+95minor)pagefaults 0swaps

hello with llvm + bolt - 4MB binary size:

0.00user 0.00system 0:00.00elapsed 16%CPU (0avgtext+0avgdata 1568maxresident)k
5192inputs+0outputs (19major+91minor)pagefaults 0swaps

@RossComputerGuy RossComputerGuy marked this pull request as ready for review January 22, 2025 05:32
@RossComputerGuy RossComputerGuy force-pushed the feat/llvm-bolt-hook branch 3 times, most recently from 95d1bb5 to 3772b12 Compare January 22, 2025 06:55
if ! isELF "$i"; then continue; fi
if ! @readelf@ --program-headers "$i" | grep -q LOAD; then continue; fi

llvm-bolt "$i" -o $(dirname "$i")/.bolt-$(basename "$i") "${boltFlags[@]-}"
Copy link
Contributor

Choose a reason for hiding this comment

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

So far as I understand, for bolt to be able to meaningfully optimize it needs profile data; do you have any plans to have a mechanism to provide that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I just am not sure how to integrate that yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

One problem with profile data is that it has a habit of being non-determinstic. For example, even if you collect profile data through a determistic mechanism, and run it on a workload which is functionally determinstic (such as clang), what controls the bits of the profile is the control flow repeatability inside the workload. See for example the discussion of applying PGO to clang. https://discourse.llvm.org/t/pgo-profile-reproducibility/82861/6.

It is possible to get around this problem to produce a repeatable profile by collecting multiple profiles and figuring out what is common between them (and then making a script that eliminates the non-common parts from the profile), but it is likely quite a bit of effort to make it happen. In particular if things like 'what inode does this include directory have' factor into the computation; since that is something that will vary from one machine to another.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: lib The Nixpkgs function library 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 6.topic: stdenv Standard environment 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants