mozilla-pgo.patch
branchfirefox115
changeset 1190 2a24a948b5cf
parent 1184 1c3d3217d679
equal deleted inserted replaced
1189:ba0c97b018a6 1190:2a24a948b5cf
     1 # HG changeset patch
     1 # HG changeset patch
     2 # User Wolfgang Rosenauer <wr@rosenauer.org>
     2 # User Wolfgang Rosenauer <wr@rosenauer.org>
     3 # Parent  d6f551c7b3dc20bb47526e06c44646fd159f3dd1
     3 # Parent  9959fe2a13a39cbeb98ca1bef2e21caba16717bd
     4 
     4 
     5 diff --git a/build/moz.configure/lto-pgo.configure b/build/moz.configure/lto-pgo.configure
     5 Index: firefox-115.0/build/moz.configure/lto-pgo.configure
     6 --- a/build/moz.configure/lto-pgo.configure
     6 ===================================================================
     7 +++ b/build/moz.configure/lto-pgo.configure
     7 --- firefox-115.0.orig/build/moz.configure/lto-pgo.configure
     8 @@ -242,34 +242,34 @@ def lto(
     8 +++ firefox-115.0/build/moz.configure/lto-pgo.configure
     9              "configure."
     9 @@ -251,8 +251,8 @@ def lto(
    10          )
       
    11  
       
    12      if c_compiler.type == "clang":
       
    13          if value == "full":
       
    14              cflags.append("-flto")
    10              cflags.append("-flto")
    15              ldflags.append("-flto")
    11              ldflags.append("-flto")
    16          else:
    12          else:
    17 -            cflags.append("-flto=thin")
    13 -            cflags.append("-flto=thin")
    18 -            ldflags.append("-flto=thin")
    14 -            ldflags.append("-flto=thin")
    19 +            cflags.append("-flto")
    15 +            cflags.append("-flto")
    20 +            ldflags.append("-flto")
    16 +            ldflags.append("-flto")
    21  
    17  
    22          if target.os == "Android" and value == "cross":
    18          if target.os == "Android" and "cross" in values:
    23              # Work around https://github.com/rust-lang/rust/issues/90088
    19              # Work around https://github.com/rust-lang/rust/issues/90088
    24              # by enabling the highest level of SSE the rust targets default
    20 @@ -268,7 +268,7 @@ def lto(
    25              # to.
    21          if "full" in values:
    26              # https://github.com/rust-lang/rust/blob/bdfcb88e8b6203ccb46a2fb6649979b773efc8ac/compiler/rustc_target/src/spec/i686_linux_android.rs#L13
       
    27              # https://github.com/rust-lang/rust/blob/8d1083e319841624f64400e1524805a40d725439/compiler/rustc_target/src/spec/x86_64_linux_android.rs#L7
       
    28              if target.cpu == "x86":
       
    29                  ldflags.append("-Wl,-plugin-opt=-mattr=+ssse3")
       
    30              elif target.cpu == "x86_64":
       
    31                  ldflags.append("-Wl,-plugin-opt=-mattr=+sse4.2")
       
    32      elif c_compiler.type == "clang-cl":
       
    33          if value == "full":
       
    34              cflags.append("-flto")
    22              cflags.append("-flto")
    35          else:
    23          else:
    36 -            cflags.append("-flto=thin")
    24 -            cflags.append("-flto=thin")
    37 +            cflags.append("-flto")
    25 +            cflags.append("-flto")
    38          # With clang-cl, -flto can only be used with -c or -fuse-ld=lld.
    26          # With clang-cl, -flto can only be used with -c or -fuse-ld=lld.
    39          # AC_TRY_LINKs during configure don't have -c, so pass -fuse-ld=lld.
    27          # AC_TRY_LINKs during configure don't have -c, so pass -fuse-ld=lld.
    40          cflags.append("-fuse-ld=lld")
    28          cflags.append("-fuse-ld=lld")
    41  
    29 Index: firefox-115.0/build/pgo/profileserver.py
    42          # Explicitly set the CPU to optimize for so the linker doesn't
    30 ===================================================================
    43          # choose a poor default.  Rust compilation by default uses the
    31 --- firefox-115.0.orig/build/pgo/profileserver.py
    44          # pentium4 CPU on x86:
    32 +++ firefox-115.0/build/pgo/profileserver.py
    45          #
    33 @@ -11,7 +11,7 @@ import subprocess
    46 diff --git a/build/pgo/profileserver.py b/build/pgo/profileserver.py
       
    47 --- a/build/pgo/profileserver.py
       
    48 +++ b/build/pgo/profileserver.py
       
    49 @@ -6,17 +6,17 @@
       
    50  
       
    51  import glob
       
    52  import json
       
    53  import os
       
    54  import subprocess
       
    55  import sys
    34  import sys
    56  
    35  
    57  import mozcrash
    36  import mozcrash
    58 -from mozbuild.base import BinaryNotFoundException, MozbuildObject
    37 -from mozbuild.base import BinaryNotFoundException, MozbuildObject
    59 +from mozbuild.base import BinaryNotFoundException, MozbuildObject, BuildEnvironmentNotFoundException
    38 +from mozbuild.base import BinaryNotFoundException, MozbuildObject, BuildEnvironmentNotFoundException
    60  from mozfile import TemporaryDirectory
    39  from mozfile import TemporaryDirectory
    61  from mozhttpd import MozHttpd
    40  from mozhttpd import MozHttpd
    62  from mozprofile import FirefoxProfile, Preferences
    41  from mozprofile import FirefoxProfile, Preferences
    63  from mozprofile.permissions import ServerLocations
    42 @@ -87,9 +87,22 @@ if __name__ == "__main__":
    64  from mozrunner import CLI, FirefoxRunner
       
    65  from six import string_types
       
    66  
       
    67  PORT = 8888
       
    68 @@ -82,19 +82,32 @@ if __name__ == "__main__":
       
    69          docroot=os.path.join(build.topsrcdir, "build", "pgo"),
       
    70          path_mappings=path_mappings,
       
    71      )
       
    72      httpd.start(block=False)
       
    73  
       
    74      locations = ServerLocations()
    43      locations = ServerLocations()
    75      locations.add_host(host="127.0.0.1", port=PORT, options="primary,privileged")
    44      locations.add_host(host="127.0.0.1", port=PORT, options="primary,privileged")
    76  
    45  
    77 -    old_profraw_files = glob.glob("*.profraw")
    46 -    old_profraw_files = glob.glob("*.profraw")
    78 -    for f in old_profraw_files:
    47 -    for f in old_profraw_files:
    94 +        for f in old_profraw_files:
    63 +        for f in old_profraw_files:
    95 +            os.remove(f)
    64 +            os.remove(f)
    96  
    65  
    97      with TemporaryDirectory() as profilePath:
    66      with TemporaryDirectory() as profilePath:
    98          # TODO: refactor this into mozprofile
    67          # TODO: refactor this into mozprofile
    99          profile_data_dir = os.path.join(build.topsrcdir, "testing", "profiles")
    68 @@ -213,6 +226,10 @@ if __name__ == "__main__":
   100          with open(os.path.join(profile_data_dir, "profiles.json"), "r") as fh:
       
   101              base_profiles = json.load(fh)["profileserver"]
       
   102  
       
   103          prefpaths = [
       
   104 @@ -208,16 +221,20 @@ if __name__ == "__main__":
       
   105  
       
   106          # Try to move the crash reports to the artifacts even if Firefox appears
       
   107          # to exit successfully, in case there's a crash that doesn't set the
       
   108          # return code to non-zero for some reason.
       
   109          if get_crashreports(profilePath, name="Firefox exited successfully?") != 0:
       
   110              print("Firefox exited successfully, but produced a crashreport")
    69              print("Firefox exited successfully, but produced a crashreport")
   111              sys.exit(1)
    70              sys.exit(1)
   112  
    71  
   113 +        print('Copying profile data....')
    72 +        print('Copying profile data....')
   114 +        os.system('pwd');
    73 +        os.system('pwd');
   115 +        os.system('tar cf profdata.tar.gz `find . -name "*.gcda"`; cd ..; tar xf instrumented/profdata.tar.gz;');
    74 +        os.system('tar cf profdata.tar.gz `find . -name "*.gcda"`; cd ..; tar xf instrumented/profdata.tar.gz;');
   116 +
    75 +
   117          llvm_profdata = env.get("LLVM_PROFDATA")
    76          llvm_profdata = env.get("LLVM_PROFDATA")
   118          if llvm_profdata:
    77          if llvm_profdata:
   119              profraw_files = glob.glob("*.profraw")
    78              profraw_files = glob.glob("*.profraw")
   120              if not profraw_files:
    79 Index: firefox-115.0/build/unix/mozconfig.unix
   121                  print(
    80 ===================================================================
   122                      "Could not find profraw files in the current directory: %s"
    81 --- firefox-115.0.orig/build/unix/mozconfig.unix
   123                      % os.getcwd()
    82 +++ firefox-115.0/build/unix/mozconfig.unix
   124                  )
    83 @@ -4,6 +4,15 @@ if [ -n "$FORCE_GCC" ]; then
   125 diff --git a/build/unix/mozconfig.unix b/build/unix/mozconfig.unix
       
   126 --- a/build/unix/mozconfig.unix
       
   127 +++ b/build/unix/mozconfig.unix
       
   128 @@ -1,14 +1,23 @@
       
   129  . "$topsrcdir/build/mozconfig.common"
       
   130  
       
   131  if [ -n "$FORCE_GCC" ]; then
       
   132      CC="$MOZ_FETCHES_DIR/gcc/bin/gcc"
    84      CC="$MOZ_FETCHES_DIR/gcc/bin/gcc"
   133      CXX="$MOZ_FETCHES_DIR/gcc/bin/g++"
    85      CXX="$MOZ_FETCHES_DIR/gcc/bin/g++"
   134  
    86  
   135 +    if [ -n "$MOZ_PGO" ]; then
    87 +    if [ -n "$MOZ_PGO" ]; then
   136 +       if [ -z "$USE_ARTIFACT" ]; then
    88 +       if [ -z "$USE_ARTIFACT" ]; then
   142 +    fi
    94 +    fi
   143 +
    95 +
   144      # We want to make sure we use binutils and other binaries in the tooltool
    96      # We want to make sure we use binutils and other binaries in the tooltool
   145      # package.
    97      # package.
   146      mk_add_options "export PATH=$MOZ_FETCHES_DIR/gcc/bin:$MOZ_FETCHES_DIR/binutils/bin:$PATH"
    98      mk_add_options "export PATH=$MOZ_FETCHES_DIR/gcc/bin:$MOZ_FETCHES_DIR/binutils/bin:$PATH"
   147  else
    99 Index: firefox-115.0/extensions/spellcheck/src/moz.build
   148      # For some builds we don't want to have Clang based static-analysis activated
   100 ===================================================================
   149      if [ -z "$DISABLE_CLANG_PLUGIN" ]; then
   101 --- firefox-115.0.orig/extensions/spellcheck/src/moz.build
   150          export ENABLE_CLANG_PLUGIN=1
   102 +++ firefox-115.0/extensions/spellcheck/src/moz.build
   151      fi
   103 @@ -28,3 +28,5 @@ EXPORTS.mozilla += [
   152 diff --git a/extensions/spellcheck/src/moz.build b/extensions/spellcheck/src/moz.build
       
   153 --- a/extensions/spellcheck/src/moz.build
       
   154 +++ b/extensions/spellcheck/src/moz.build
       
   155 @@ -23,8 +23,10 @@ LOCAL_INCLUDES += [
       
   156      "../hunspell/glue",
       
   157      "../hunspell/src",
       
   158      "/dom/base",
       
   159  ]
       
   160  EXPORTS.mozilla += [
       
   161      "mozInlineSpellChecker.h",
   104      "mozInlineSpellChecker.h",
   162      "mozSpellChecker.h",
   105      "mozSpellChecker.h",
   163  ]
   106  ]
   164 +
   107 +
   165 +CXXFLAGS += ['-fno-devirtualize']
   108 +CXXFLAGS += ['-fno-devirtualize']
   166 diff --git a/toolkit/components/terminator/nsTerminator.cpp b/toolkit/components/terminator/nsTerminator.cpp
   109 Index: firefox-115.0/toolkit/components/terminator/nsTerminator.cpp
   167 --- a/toolkit/components/terminator/nsTerminator.cpp
   110 ===================================================================
   168 +++ b/toolkit/components/terminator/nsTerminator.cpp
   111 --- firefox-115.0.orig/toolkit/components/terminator/nsTerminator.cpp
   169 @@ -455,16 +455,21 @@ void nsTerminator::StartWatchdog() {
   112 +++ firefox-115.0/toolkit/components/terminator/nsTerminator.cpp
   170        // Defend against overflow
   113 @@ -460,6 +460,11 @@ void nsTerminator::StartWatchdog() {
   171        crashAfterMS = INT32_MAX;
       
   172      } else {
       
   173        crashAfterMS *= scaleUp;
       
   174      }
       
   175    }
   114    }
   176  #endif
   115  #endif
   177  
   116  
   178 +  // Disable watchdog for PGO train builds - writting profile information at
   117 +  // Disable watchdog for PGO train builds - writting profile information at
   179 +  // exit may take time and it is better to make build hang rather than
   118 +  // exit may take time and it is better to make build hang rather than
   181 +  crashAfterMS = INT32_MAX;
   120 +  crashAfterMS = INT32_MAX;
   182 +
   121 +
   183    UniquePtr<Options> options(new Options());
   122    UniquePtr<Options> options(new Options());
   184    // crashAfterTicks is guaranteed to be > 0 as
   123    // crashAfterTicks is guaranteed to be > 0 as
   185    // crashAfterMS >= ADDITIONAL_WAIT_BEFORE_CRASH_MS >> HEARTBEAT_INTERVAL_MS
   124    // crashAfterMS >= ADDITIONAL_WAIT_BEFORE_CRASH_MS >> HEARTBEAT_INTERVAL_MS
   186    options->crashAfterTicks = crashAfterMS / HEARTBEAT_INTERVAL_MS;
       
   187  
       
   188    DebugOnly<PRThread*> watchdogThread =
       
   189        CreateSystemThread(RunWatchdog, options.release());
       
   190    MOZ_ASSERT(watchdogThread);