blob: db6f14f5898830c9a6a72164533f87f08b8f26c0 [file] [log] [blame] [view]
Rasika Navarangefebe77182024-05-07 16:49:191# Orderfile
2
Egor Paskob16121d2024-06-11 17:50:493An orderfile is a list of symbols that defines an ordering of functions. One can
4make a static linker, such as LLD, respect this ordering when generating a
5binary.
6
7Reordering code this way can improve startup performance by fetching machine
8code to memory more efficiently, since it requires fetching fewer pages from
9disk, and a big part of the I/O work is done sequentially by the readahead.
10
11Code reordering can also improve memory usage by keeping the used code in a
12smaller number of memory pages. It can also reduce TLB and L1i cache misses by
13placing functions commonly called together closely in memory.
Rasika Navarangee8a00a72024-05-09 13:39:4114
Rasika Navarangefebe77182024-05-07 16:49:1915## Generating Orderfiles Manually
16
Rasika Navarangee8a00a72024-05-09 13:39:4117To generate an orderfile you can run the `orderfile_generator_backend.py`
18script. You will need an Android device connected with
19[adb](https://developer.android.com/tools/adb) to generate the orderfile as the
20generation pipeline will need to run benchmarks on a device.
Rasika Navarangefebe77182024-05-07 16:49:1921
22Example:
23```
24tools/cygprofile/orderfile_generator_backend.py --target-arch=arm64 --use-remoteexec
25```
26
Rasika Navarangee8a00a72024-05-09 13:39:4127You can specify the architecture (arm or arm64) with `--target-arch`. For quick
28local testing you can use `--streamline-for-debugging`. To build using Reclient,
29use `--use-remoteexec` (Googlers only). There are several other options you can
30use to configure/debug the orderfile generation. Use the `-h` option to view the
31various options.
Rasika Navarangefebe77182024-05-07 16:49:1932
Rasika Navarange6ae2078b2024-05-09 16:13:3033NB: If your checkout is non-internal you must use the `--public` option.
34
Rasika Navarangee8a00a72024-05-09 13:39:4135To build Chrome with a locally generated orderfile, use the
36`chrome_orderfile_path=<path_to_orderfile>` GN arg.
37
Tushar Agarwal6f0dc3a2024-05-22 15:33:0138## Orderfile Performance Testing
39
40Orderfiles can be tested using
41[Pinpoint](https://chromium.googlesource.com/chromium/src/+/main/docs/speed/perf_trybots.md).
42To do this, please create and upload a Gerrit change overriding the value of
43[`chrome_orderfile_path`](https://source.chromium.org/chromium/chromium/src/+/main:build/config/compiler/BUILD.gn;l=217-223;drc=3a829695d83990141babd25dee7f2f94c005cae4)
44to, for instance, `//path/to/my_orderfile` (relative to `src`), where
45`my_orderfile` is the orderfile that needs to be evaluated. The orderfile should
46be added to the local branch and uploaded to Gerrit along with
47`build/config/compiler/BUILD.gn`. This Gerrit change can then be used as an
48"experiment patch" for a Pinpoint try job.
49
Egor Pasko04c833b72024-06-19 14:30:3950## Triaging Performance Regressions
51
52Occasionally, an orderfile roll will cause performance problems on perfbots.
53This typically triggers an alert in the form of a bug report, which contains a
54group of related regressions like the one shown
55[here](https://crbug.com/344654892).
56
57In such cases it is important to keep in mind that effectiveness of the
58orderfile is coupled with using a recent PGO profile when building the native
59code. As a result some orderfile improvements (or effective no-ops) register as
60regressions on perfbots using non-PGO builds, which is the most common perfbot
61configuration.
62
63If a new regression does not include alerts from the
64[android-pixel6-perf-pgo](https://ci.chromium.org/ui/p/chrome/builders/luci.chrome.ci/android-pixel6-perf-pgo)
65(the only Android PGO perfbot as of 2024-06) then the first thing to check is to
66query the same benchmark+metric combinations for the PGO bot. If the graphs
67demonstrate no regression, feel free to close the issue as WontFix(Intended
68Behavior). However, not all benchmarks are exercised on the PGO bot
69continuously. If there is no PGO coverage for a particular benchmark+metric
70combination, this combination can be checked on Pinpoint with the right perfbot
71choice ([example](https://crbug.com/344665295)).
72
73Finally, the PGO+orderfile coupling exists only on arm64. Most speed
74optimization efforts on Android are focused on this configuration. On arm32 the
75most important orderfile optimization is for reducing memory used by machine
76code. Only one benchmark measures it: `system_health.memory_mobile`.
77
Rasika Navarangee8a00a72024-05-09 13:39:4178## Orderfile Pipeline
79
80The `orderfile_generator_backend.py` script runs several key steps:
81
821. **Build and install Chrome with orderfile instrumentation.** This uses the
Egor Paskob16121d2024-06-11 17:50:4983[`-finstrument-function-entry-bare`](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-finstrument-function-entry-bare)
84Clang command line option to insert instrumentation for function entry. The
85build will be generated in `out/arm_instrumented_out/` or
86`out/arm64_instrumented_out`, depending on the CPU architecture (instruction
87set).
Rasika Navarangee8a00a72024-05-09 13:39:4188
Rasika Navarangee8a00a72024-05-09 13:39:41892. **Run the benchmarks and collect profiles.** These benchmarks can be found
90in [orderfile.py](../tools/perf/contrib/orderfile/orderfile.py). These profiles
91are a list of function offsets into the binary that were called during execution
92of the benchmarks.
93
Peter Wena0204d522024-08-19 22:58:58943. **Cluster the symbols from the profiles to generate the orderfile.**
Rasika Navarangee8a00a72024-05-09 13:39:4195The offsets are processed and merged using a
96[clustering](../tools/cygprofile/cluster.py) algorithm to produce an orderfile.
97
Peter Wena0204d522024-08-19 22:58:58984. **Run benchmarks on the final orderfile.** We run some benchmarks to compare
Rasika Navarangee8a00a72024-05-09 13:39:4199the performance with/without the orderfile. You can supply the `--no-benchmark`
Egor Paskob16121d2024-06-11 17:50:49100flag to skip this step.