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

[FR] ndk-build support for order file generation #1913

Open
DanAlbert opened this issue Aug 3, 2023 · 8 comments
Open

[FR] ndk-build support for order file generation #1913

DanAlbert opened this issue Aug 3, 2023 · 8 comments

Comments

@DanAlbert
Copy link
Member

Description

Order files (much like PGO) need to be handled in steps of build instrumented -> run -> rebuild. Order files have some annoying requirements like not using -O0 and other flag juggling as well. We could add a LOCAL_ORDERFILE and NDK_GENERATE_ORDER_FILES (the second being a command line option) to make that workflow a bit more obvious.

@smeenai
Copy link

smeenai commented Aug 23, 2023

How is the NDK generating order files? At Meta, we introduced a lightweight IR PRO instrumentation mode specifically for mobile and an order file generation mode algorithm aimed at minimizing page faults: https://reviews.llvm.org/D147812. That might be interesting for the NDK as well.

@DanAlbert
Copy link
Member Author

@appujee

@appujee
Copy link
Collaborator

appujee commented Aug 24, 2023

How is the NDK generating order files? At Meta, we introduced a lightweight IR PRO instrumentation mode specifically for mobile and

Yeah, we are using the -forder-file-instrumentation to generate order file. Apart from that we have scripts to:

  • generate order file from the profraw files
  • clean the order file
  • validate order file
  • merge N order files (will be upstreamed soon)

The scripts (except for merging order files) and the documentation, and developer guide (with example use cases) have been upstreamed to ndk repository. See:

an order file generation mode algorithm aimed at minimizing page faults: https://reviews.llvm.org/D147812. That might be interesting for the NDK as well.

This is interesting, i'm seeing this for the first time but it seems to be doing something similar to what we have for merging order files. It seems the time complexity of this implementation might be affecting build times? I haven't looked in detail but we have something that converges very fast.

We have a script that implements a linear time algorithm to merge the order files. Maybe our implementation has a few more things that could be helpful in implementing in llvm-profdata, I'll update more once everything is upstreamed.

@smeenai
Copy link

smeenai commented Aug 24, 2023

IIRC -forder-file-instrumentation is older and has higher binary size overhead than lightweight IR PGO. I'll ask Ellis (who contributed lightweight PGO) to comment here though.

@appujee
Copy link
Collaborator

appujee commented Aug 24, 2023

just finished reading: https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068. Is there a plan to deprecate the -forder-file-instrumentation ?

If we have a way to merge multiple profraw files (with orderfile data), everything on our end should still keep working (with whatever replaces the -forder-file-instrumentation) otherwise we'll need to update the scripts a little bit. As our goal is to collect order file from different app launch instances (across multiple device classes), we'll have a variety of profraw files in a general case.

@ellishg
Copy link

ellishg commented Aug 24, 2023

I would like to deprecate -forder-file-instrumentation, but I didn't know how widespread its usage was. Temporal Profiling supports the same functionality but with better integration with existing tools and you won't need the mapping file (-orderfile-write-mapping=). If you incorporate Lightweight Instrumentation then the binary size overhead is also improved. I would also like to support function order optimizations simply by passing in the profile via -fprofile-use instead of --symbol-ordering-file=, but I don't have an explicit plan for that yet.

Temporal Profiling can merge traces from multiple profraw files, but you might need to set -max-temporal-profile-trace-length and -temporal-profile-trace-reservoir-size if you have many (>100) raw profiles. llvm-profdata order will converge quickly to give you a single function order.

I would be interested to know if Temporal Profiling works out for your use case. Let me know if you have any questions.

@appujee
Copy link
Collaborator

appujee commented Aug 28, 2023

It makes sense to support both order file collection modes. The advantage with using -forder-file-instrumentation is that older toolchains can also use it but in the long term we'll be in a better position if we support temporal profiling.

@appujee
Copy link
Collaborator

appujee commented Jan 10, 2024

Update: https://android-developers.googleblog.com/2023/11/orderfiles-in-android.html has the details of our implementation along with links to scripts and documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants