mozilla-pgo.patch
branchfirefox84
changeset 1152 4cfe46c9a944
child 1154 71a92b4d0527
equal deleted inserted replaced
1151:8df86bf11fc1 1152:4cfe46c9a944
       
     1 # HG changeset patch
       
     2 # User Wolfgang Rosenauer <wr@rosenauer.org>
       
     3 # Parent  431962e810598b34327620fb99e06768e9a29c38
       
     4 
       
     5 diff --git a/build/moz.configure/lto-pgo.configure b/build/moz.configure/lto-pgo.configure
       
     6 --- a/build/moz.configure/lto-pgo.configure
       
     7 +++ b/build/moz.configure/lto-pgo.configure
       
     8 @@ -223,23 +223,23 @@ def lto(value, c_compiler, ld64_known_go
       
     9                  "configure."
       
    10              )
       
    11  
       
    12          if c_compiler.type == "clang":
       
    13              if len(value) and value[0].lower() == "full":
       
    14                  cflags.append("-flto")
       
    15                  ldflags.append("-flto")
       
    16              else:
       
    17 -                cflags.append("-flto=thin")
       
    18 -                ldflags.append("-flto=thin")
       
    19 +                cflags.append("-flto")
       
    20 +                ldflags.append("-flto")
       
    21          elif c_compiler.type == "clang-cl":
       
    22              if len(value) and value[0].lower() == "full":
       
    23                  cflags.append("-flto")
       
    24              else:
       
    25 -                cflags.append("-flto=thin")
       
    26 +                cflags.append("-flto")
       
    27              # With clang-cl, -flto can only be used with -c or -fuse-ld=lld.
       
    28              # AC_TRY_LINKs during configure don't have -c, so pass -fuse-ld=lld.
       
    29              cflags.append("-fuse-ld=lld")
       
    30  
       
    31              # Explicitly set the CPU to optimize for so the linker doesn't
       
    32              # choose a poor default.  Rust compilation by default uses the
       
    33              # pentium4 CPU on x86:
       
    34              #
       
    35 @@ -263,17 +263,17 @@ def lto(value, c_compiler, ld64_known_go
       
    36                  ldflags.append("-mllvm:-mcpu=x86-64")
       
    37              # We do not need special flags for arm64.  Hooray for fixed-length
       
    38              # instruction sets.
       
    39          else:
       
    40              num_cores = multiprocessing.cpu_count()
       
    41              if len(value) and value[0].lower() == "full":
       
    42                  cflags.append("-flto")
       
    43              else:
       
    44 -                cflags.append("-flto=thin")
       
    45 +                cflags.append("-flto")
       
    46              cflags.append("-flifetime-dse=1")
       
    47  
       
    48              ldflags.append("-flto=%s" % num_cores)
       
    49              ldflags.append("-flifetime-dse=1")
       
    50  
       
    51          # Tell LTO not to inline functions above a certain size, to mitigate
       
    52          # binary size growth while still getting good performance.
       
    53          # (For hot functions, PGO will put a multiplier on this limit.)
       
    54 diff --git a/build/pgo/profileserver.py b/build/pgo/profileserver.py
       
    55 --- a/build/pgo/profileserver.py
       
    56 +++ b/build/pgo/profileserver.py
       
    57 @@ -6,17 +6,17 @@
       
    58  
       
    59  import json
       
    60  import os
       
    61  import sys
       
    62  import glob
       
    63  import subprocess
       
    64  
       
    65  import mozcrash
       
    66 -from mozbuild.base import MozbuildObject, BinaryNotFoundException
       
    67 +from mozbuild.base import MozbuildObject, BinaryNotFoundException, BuildEnvironmentNotFoundException
       
    68  from mozfile import TemporaryDirectory
       
    69  from mozhttpd import MozHttpd
       
    70  from mozprofile import FirefoxProfile, Preferences
       
    71  from mozprofile.permissions import ServerLocations
       
    72  from mozrunner import FirefoxRunner, CLI
       
    73  from six import string_types
       
    74  
       
    75  PORT = 8888
       
    76 @@ -82,19 +82,32 @@ if __name__ == "__main__":
       
    77          docroot=os.path.join(build.topsrcdir, "build", "pgo"),
       
    78          path_mappings=path_mappings,
       
    79      )
       
    80      httpd.start(block=False)
       
    81  
       
    82      locations = ServerLocations()
       
    83      locations.add_host(host="127.0.0.1", port=PORT, options="primary,privileged")
       
    84  
       
    85 -    old_profraw_files = glob.glob("*.profraw")
       
    86 -    for f in old_profraw_files:
       
    87 -        os.remove(f)
       
    88 +    using_gcc = False
       
    89 +    try:
       
    90 +        if build.config_environment.substs.get('CC_TYPE') == 'gcc':
       
    91 +            using_gcc = True
       
    92 +    except BuildEnvironmentNotFoundException:
       
    93 +        pass
       
    94 +
       
    95 +    if using_gcc:
       
    96 +        for dirpath, _, filenames in os.walk('.'):
       
    97 +            for f in filenames:
       
    98 +                if f.endswith('.gcda'):
       
    99 +                    os.remove(os.path.join(dirpath, f))
       
   100 +    else:
       
   101 +        old_profraw_files = glob.glob('*.profraw')
       
   102 +        for f in old_profraw_files:
       
   103 +            os.remove(f)
       
   104  
       
   105      with TemporaryDirectory() as profilePath:
       
   106          # TODO: refactor this into mozprofile
       
   107          profile_data_dir = os.path.join(build.topsrcdir, "testing", "profiles")
       
   108          with open(os.path.join(profile_data_dir, "profiles.json"), "r") as fh:
       
   109              base_profiles = json.load(fh)["profileserver"]
       
   110  
       
   111          prefpaths = [
       
   112 @@ -207,16 +220,20 @@ if __name__ == "__main__":
       
   113  
       
   114          # Try to move the crash reports to the artifacts even if Firefox appears
       
   115          # to exit successfully, in case there's a crash that doesn't set the
       
   116          # return code to non-zero for some reason.
       
   117          if get_crashreports(profilePath, name="Firefox exited successfully?") != 0:
       
   118              print("Firefox exited successfully, but produced a crashreport")
       
   119              sys.exit(1)
       
   120  
       
   121 +        print('Copying profile data....')
       
   122 +        os.system('pwd');
       
   123 +        os.system('tar cf profdata.tar.gz `find . -name "*.gcda"`; cd ..; tar xf instrumented/profdata.tar.gz;');
       
   124 +
       
   125          llvm_profdata = env.get("LLVM_PROFDATA")
       
   126          if llvm_profdata:
       
   127              profraw_files = glob.glob("*.profraw")
       
   128              if not profraw_files:
       
   129                  print(
       
   130                      "Could not find profraw files in the current directory: %s"
       
   131                      % os.getcwd()
       
   132                  )
       
   133 diff --git a/build/unix/mozconfig.unix b/build/unix/mozconfig.unix
       
   134 --- a/build/unix/mozconfig.unix
       
   135 +++ b/build/unix/mozconfig.unix
       
   136 @@ -1,16 +1,25 @@
       
   137  . "$topsrcdir/build/mozconfig.common"
       
   138  
       
   139  TOOLTOOL_DIR=${TOOLTOOL_DIR:-$topsrcdir}
       
   140  
       
   141  if [ -n "$FORCE_GCC" ]; then
       
   142      CC="$MOZ_FETCHES_DIR/gcc/bin/gcc"
       
   143      CXX="$MOZ_FETCHES_DIR/gcc/bin/g++"
       
   144  
       
   145 +    if [ -n "$MOZ_PGO" ]; then
       
   146 +        if [ -z "$USE_ARTIFACT" ]; then
       
   147 +            ac_add_options --enable-lto
       
   148 +        fi
       
   149 +        export AR="$topsrcdir/gcc/bin/gcc-ar"
       
   150 +        export NM="$topsrcdir/gcc/bin/gcc-nm"
       
   151 +        export RANLIB="$topsrcdir/gcc/bin/gcc-ranlib"
       
   152 +    fi
       
   153 +
       
   154      # We want to make sure we use binutils and other binaries in the tooltool
       
   155      # package.
       
   156      mk_add_options "export PATH=$MOZ_FETCHES_DIR/gcc/bin:$PATH"
       
   157      ac_add_options --with-clang-path=$MOZ_FETCHES_DIR/clang/bin/clang
       
   158  else
       
   159      CC="$MOZ_FETCHES_DIR/clang/bin/clang"
       
   160      CXX="$MOZ_FETCHES_DIR/clang/bin/clang++"
       
   161  
       
   162 diff --git a/extensions/spellcheck/src/moz.build b/extensions/spellcheck/src/moz.build
       
   163 --- a/extensions/spellcheck/src/moz.build
       
   164 +++ b/extensions/spellcheck/src/moz.build
       
   165 @@ -26,8 +26,10 @@ LOCAL_INCLUDES += [
       
   166  ]
       
   167  EXPORTS.mozilla += [
       
   168      "mozInlineSpellChecker.h",
       
   169      "mozSpellChecker.h",
       
   170  ]
       
   171  
       
   172  if CONFIG["CC_TYPE"] in ("clang", "gcc"):
       
   173      CXXFLAGS += ["-Wno-error=shadow"]
       
   174 +
       
   175 +CXXFLAGS += ['-fno-devirtualize']
       
   176 diff --git a/python/mozbuild/mozbuild/build_commands.py b/python/mozbuild/mozbuild/build_commands.py
       
   177 --- a/python/mozbuild/mozbuild/build_commands.py
       
   178 +++ b/python/mozbuild/mozbuild/build_commands.py
       
   179 @@ -121,19 +121,18 @@ class Build(MachCommandBase):
       
   180                  silent=not verbose,
       
   181                  ensure_exit_code=False,
       
   182                  append_env=append_env,
       
   183              )
       
   184              if status != 0:
       
   185                  return status
       
   186  
       
   187              pgo_env = os.environ.copy()
       
   188 -            pgo_env["LLVM_PROFDATA"] = instr.config_environment.substs.get(
       
   189 -                "LLVM_PROFDATA"
       
   190 -            )
       
   191 +            if instr.config_environment.substs.get('CC_TYPE') != 'gcc':
       
   192 +                pgo_env["LLVM_PROFDATA"] = instr.config_environment.substs.get("LLVM_PROFDATA")
       
   193              pgo_env["JARLOG_FILE"] = mozpath.join(orig_topobjdir, "jarlog/en-US.log")
       
   194              pgo_cmd = [
       
   195                  instr.virtualenv_manager.python_path,
       
   196                  mozpath.join(self.topsrcdir, "build/pgo/profileserver.py"),
       
   197              ]
       
   198              subprocess.check_call(
       
   199                  pgo_cmd, cwd=instr.topobjdir, env=ensure_subprocess_env(pgo_env)
       
   200              )
       
   201 diff --git a/toolkit/components/terminator/nsTerminator.cpp b/toolkit/components/terminator/nsTerminator.cpp
       
   202 --- a/toolkit/components/terminator/nsTerminator.cpp
       
   203 +++ b/toolkit/components/terminator/nsTerminator.cpp
       
   204 @@ -413,16 +413,21 @@ void nsTerminator::StartWatchdog() {
       
   205        // Defend against overflow
       
   206        crashAfterMS = INT32_MAX;
       
   207      } else {
       
   208        crashAfterMS *= scaleUp;
       
   209      }
       
   210    }
       
   211  #endif
       
   212  
       
   213 +  // Disable watchdog for PGO train builds - writting profile information at
       
   214 +  // exit may take time and it is better to make build hang rather than
       
   215 +  // silently produce poorly performing binary.
       
   216 +  crashAfterMS = INT32_MAX;
       
   217 +
       
   218    UniquePtr<Options> options(new Options());
       
   219    const PRIntervalTime ticksDuration = PR_MillisecondsToInterval(1000);
       
   220    options->crashAfterTicks = crashAfterMS / ticksDuration;
       
   221    // Handle systems where ticksDuration is greater than crashAfterMS.
       
   222    if (options->crashAfterTicks == 0) {
       
   223      options->crashAfterTicks = crashAfterMS / 1000;
       
   224    }
       
   225