Bug 1394710 - Set process priority class on Windows r=aklotz
☠☠ backed out by be3f6d08fb17 ☠ ☠
authorDoug Thayer <dothayer@mozilla.com>
Fri, 08 Jun 2018 14:54:11 -0700
changeset 482288 73ed615358542b987c2c2a8d0730adf0b915a0f6
parent 482287 10159cf474be93602fb0e21adbdd56c8cddd43e6
child 482289 be3f6d08fb1715837b86d49c82efe6f776b3247a
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1394710
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1394710 - Set process priority class on Windows r=aklotz Fairly straightforward. Using an idle priority class for background, which mirrors what I am observing of Chromium in Process Explorer. MozReview-Commit-ID: 2mimYN7aJOy
hal/moz.build
hal/windows/WindowsProcessPriority.cpp
--- a/hal/moz.build
+++ b/hal/moz.build
@@ -33,77 +33,82 @@ SOURCES += [
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
     LOCAL_INCLUDES += [
         '/widget/android',
     ]
     UNIFIED_SOURCES += [
         'android/AndroidSensor.cpp',
+        'fallback/FallbackProcessPriority.cpp',
     ]
     # AndroidHal.cpp cannot be built in unified mode because it relies on HalImpl.h.
     SOURCES += [
         'android/AndroidHal.cpp',
     ]
 elif CONFIG['OS_TARGET'] == 'Linux':
     UNIFIED_SOURCES += [
         'fallback/FallbackScreenConfiguration.cpp',
         'fallback/FallbackSensor.cpp',
         'fallback/FallbackVibration.cpp',
+        'fallback/FallbackProcessPriority.cpp',
     ]
     if CONFIG['MOZ_ENABLE_DBUS']:
         UNIFIED_SOURCES += [
             'linux/UPowerClient.cpp',
         ]
     else:
         UNIFIED_SOURCES += [
             'fallback/FallbackBattery.cpp',
         ]
 elif CONFIG['OS_TARGET'] == 'WINNT':
     UNIFIED_SOURCES += [
         'fallback/FallbackScreenConfiguration.cpp',
         'fallback/FallbackVibration.cpp',
+        'windows/WindowsProcessPriority.cpp',
         'windows/WindowsSensor.cpp',
     ]
     # WindowsBattery.cpp cannot be built in unified mode because it relies on HalImpl.h.
     SOURCES += [
         'windows/WindowsBattery.cpp',
     ]
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     UNIFIED_SOURCES += [
         'cocoa/CocoaBattery.cpp',
         'fallback/FallbackScreenConfiguration.cpp',
         'fallback/FallbackVibration.cpp',
+        'fallback/FallbackProcessPriority.cpp',
     ]
 elif CONFIG['OS_TARGET'] in ('OpenBSD', 'NetBSD', 'FreeBSD', 'DragonFly'):
     UNIFIED_SOURCES += [
         'fallback/FallbackScreenConfiguration.cpp',
         'fallback/FallbackSensor.cpp',
         'fallback/FallbackVibration.cpp',
+        'fallback/FallbackProcessPriority.cpp',
     ]
     if CONFIG['MOZ_ENABLE_DBUS']:
         UNIFIED_SOURCES += [
             'linux/UPowerClient.cpp',
         ]
     else:
         UNIFIED_SOURCES += [
             'fallback/FallbackBattery.cpp',
         ]
 else:
     UNIFIED_SOURCES += [
         'fallback/FallbackBattery.cpp',
         'fallback/FallbackScreenConfiguration.cpp',
         'fallback/FallbackSensor.cpp',
         'fallback/FallbackVibration.cpp',
+        'fallback/FallbackProcessPriority.cpp',
     ]
 
 # Fallbacks for backends no longer implemented.
 UNIFIED_SOURCES += [
     'fallback/FallbackDiskSpaceWatcher.cpp',
-    'fallback/FallbackProcessPriority.cpp',
 ]
 
 # Fallbacks for backends implemented on Android only.
 if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android':
     UNIFIED_SOURCES += [
         'fallback/FallbackNetwork.cpp',
     ]
 
new file mode 100644
--- /dev/null
+++ b/hal/windows/WindowsProcessPriority.cpp
@@ -0,0 +1,43 @@
+/* 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/. */
+
+#include "Hal.h"
+#include "HalLog.h"
+
+#include <Windows.h>
+
+using namespace mozilla::hal;
+
+namespace mozilla {
+namespace hal_impl {
+
+bool
+SetProcessPrioritySupported()
+{
+  return true;
+}
+
+void
+SetProcessPriority(int aPid, ProcessPriority aPriority)
+{
+  HAL_LOG("WindowsProcessPriority - SetProcessPriority(%d, %s)\n",
+          aPid, ProcessPriorityToString(aPriority));
+
+  HANDLE hProcess = ::OpenProcess(PROCESS_SET_INFORMATION, false, aPid);
+  if (hProcess) {
+    DWORD priority = NORMAL_PRIORITY_CLASS;
+    if (aPriority == PROCESS_PRIORITY_BACKGROUND ||
+        aPriority == PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE) {
+      priority = IDLE_PRIORITY_CLASS;
+    }
+    ::SetPriorityClass(hProcess, priority);
+    ::CloseHandle(hProcess);
+  }
+
+  HAL_LOG("WindowsProcessPriority - priority set to %d for pid %d\n",
+          aPriority, aPid);
+}
+
+} // namespace hal_impl
+} // namespace mozilla