Skip to content

Instantly share code, notes, and snippets.

@classilla
Last active April 8, 2024 14:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save classilla/1202f8d467749c029325278a87a068c8 to your computer and use it in GitHub Desktop.
Save classilla/1202f8d467749c029325278a87a068c8 to your computer and use it in GitHub Desktop.
PGO fixes and livability improvements for LTO in Firefox on ppc64le Linux. Read web page first! -- https://www.talospace.com/2024/03/firefox-124-on-power.html
diff -r ac0e1ee8218f build/moz.configure/lto-pgo.configure
--- a/build/moz.configure/lto-pgo.configure Tue Feb 20 13:51:00 2024 +0000
+++ b/build/moz.configure/lto-pgo.configure Sat Feb 24 22:47:17 2024 -0800
@@ -2,17 +2,17 @@
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# PGO
# ==============================================================
llvm_profdata = check_prog(
- "LLVM_PROFDATA", ["llvm-profdata"], allow_missing=True, paths=clang_search_path
+ "LLVM_PROFDATA", ["llvm-profdata-dont-even-think-about-it"], allow_missing=True, paths=clang_search_path
)
@depends_if(llvm_profdata)
@checking("whether llvm-profdata supports 'order' subcommand")
def llvm_profdata_order(profdata):
retcode, _, _ = get_cmd_output(profdata, "order", "--help")
return retcode == 0
@@ -128,17 +128,17 @@
@imports("multiprocessing")
def pgo_flags(
compiler, linker, target, profdata, orderfile, target_is_windows, pgo_temporal
):
if compiler.type == "gcc":
return namespace(
gen_cflags=["-fprofile-generate"],
gen_ldflags=["-fprofile-generate"],
- use_cflags=["-fprofile-use", "-fprofile-correction", "-Wcoverage-mismatch"],
+ use_cflags=["-fprofile-use", "-fprofile-correction", "-Wno-coverage-mismatch"],
use_ldflags=["-fprofile-use"],
)
if compiler.type in ("clang-cl", "clang"):
prefix = ""
if compiler.type == "clang-cl":
prefix = "/clang:"
gen_ldflags = None
diff -r ac0e1ee8218f build/pgo/profileserver.py
--- a/build/pgo/profileserver.py Tue Feb 20 13:51:00 2024 +0000
+++ b/build/pgo/profileserver.py Sat Feb 24 22:47:17 2024 -0800
@@ -93,19 +93,32 @@
),
path_mappings=path_mappings,
)
sp3_httpd.start(block=False)
print("started SP3 server on port 8000")
locations = ServerLocations()
locations.add_host(host="127.0.0.1", port=PORT, options="primary,privileged")
- old_profraw_files = glob.glob("*.profraw")
- for f in old_profraw_files:
- os.remove(f)
+ using_gcc = False
+ try:
+ if build.config_environment.substs.get('CC_TYPE') == 'gcc':
+ using_gcc = True
+ except BuildEnvironmentNotFoundException:
+ pass
+
+ if using_gcc:
+ for dirpath, _, filenames in os.walk('.'):
+ for f in filenames:
+ if f.endswith('.gcda'):
+ os.remove(os.path.join(dirpath, f))
+ else:
+ old_profraw_files = glob.glob('*.profraw')
+ for f in old_profraw_files:
+ os.remove(f)
with TemporaryDirectory() as profilePath:
# TODO: refactor this into mozprofile
profile_data_dir = os.path.join(build.topsrcdir, "testing", "profiles")
with open(os.path.join(profile_data_dir, "profiles.json"), "r") as fh:
base_profiles = json.load(fh)["profileserver"]
prefpaths = [
@@ -222,16 +235,20 @@
# Try to move the crash reports to the artifacts even if Firefox appears
# to exit successfully, in case there's a crash that doesn't set the
# return code to non-zero for some reason.
if get_crashreports(profilePath, name="Firefox exited successfully?") != 0:
print("Firefox exited successfully, but produced a crashreport")
sys.exit(1)
+ print('Copying profile data....')
+ os.system('pwd');
+ os.system('tar cf profdata.tar.gz `find . -name "*.gcda"`; cd ..; tar xf instrumented/profdata.tar.gz;');
+
llvm_profdata = env.get("LLVM_PROFDATA")
if llvm_profdata:
profraw_files = glob.glob("*.profraw")
if not profraw_files:
print(
"Could not find profraw files in the current directory: %s"
% os.getcwd()
)
diff -r ac0e1ee8218f toolkit/components/terminator/nsTerminator.cpp
--- a/toolkit/components/terminator/nsTerminator.cpp Tue Feb 20 13:51:00 2024 +0000
+++ b/toolkit/components/terminator/nsTerminator.cpp Sat Feb 24 22:47:17 2024 -0800
@@ -455,16 +455,21 @@
// Defend against overflow
crashAfterMS = INT32_MAX;
} else {
crashAfterMS *= scaleUp;
}
}
#endif
+ // Disable watchdog for PGO train builds - writting profile information at
+ // exit may take time and it is better to make build hang rather than
+ // silently produce poorly performing binary.
+ crashAfterMS = INT32_MAX;
+
UniquePtr<Options> options(new Options());
// crashAfterTicks is guaranteed to be > 0 as
// crashAfterMS >= ADDITIONAL_WAIT_BEFORE_CRASH_MS >> HEARTBEAT_INTERVAL_MS
options->crashAfterTicks = crashAfterMS / HEARTBEAT_INTERVAL_MS;
DebugOnly<PRThread*> watchdogThread =
CreateSystemThread(RunWatchdog, options.release());
MOZ_ASSERT(watchdogThread);
@kth5
Copy link

kth5 commented Sep 4, 2023

Seems to be handcrafted since there's a duplicate line:

[firefox-117.0]$ patch -Np1 -i firefox-pgo.diff
patching file build/moz.configure/lto-pgo.configure
patch: **** malformed patch at line 5: @@ -81,17 +81,17 @@

@classilla
Copy link
Author

Thanks, edited

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