Bug 633986 Pref nice value, default to 1 on Android r=dougt a=blocking-fennec
authorBenjamin Stover <bstover@mozilla.com>
Mon, 14 Feb 2011 14:34:46 -0800
changeset 62533 4c2962ad0a9d688daa00ba3e2cbe2be264182c39
parent 62532 0fd8793db7f37dbf6ed7e5936b311f91e4db8745
child 62534 525db94bf558ca556573ee82004d1ba69be3365e
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersdougt, blocking-fennec
bugs633986
milestone2.0b12pre
Bug 633986 Pref nice value, default to 1 on Android r=dougt a=blocking-fennec
dom/ipc/ContentChild.cpp
dom/ipc/ContentParent.cpp
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -83,24 +83,16 @@
 
 #include "nsIGeolocationProvider.h"
 
 #ifdef MOZ_PERMISSIONS
 #include "nsPermission.h"
 #include "nsPermissionManager.h"
 #endif
 
-#if defined(ANDROID) || defined(LINUX)
-#include <sys/time.h>
-#include <sys/resource.h>
-// TODO: For other platforms that support setpriority, figure out
-//       appropriate values of niceness
-static const int kRelativeNiceness = 10;
-#endif
-
 #include "nsAccelerometer.h"
 
 #if defined(ANDROID)
 #include "APKOpen.h"
 #endif
 
 using namespace mozilla::ipc;
 using namespace mozilla::net;
@@ -228,28 +220,16 @@ ContentChild::Init(MessageLoop* aIOLoop,
 
 #ifdef MOZ_X11
     // Do this after initializing GDK, or GDK will install its own handler.
     XRE_InstallX11ErrorHandler();
 #endif
 
     NS_ASSERTION(!sSingleton, "only one ContentChild per child");
 
-#if defined(ANDROID) || defined(LINUX)
-    // XXX We change the behavior of Linux child processes here. That
-    // means that, not just in Fennec, but also in Firefox, once it has
-    // child processes, those will be niced. IOW, Firefox with child processes
-    // will have different performance profiles on Linux than other
-    // platforms. This may alter Talos results and so forth.
-    char* relativeNicenessStr = getenv("MOZ_CHILD_PROCESS_RELATIVE_NICENESS");
-    setpriority(PRIO_PROCESS, 0, getpriority(PRIO_PROCESS, 0) +
-            (relativeNicenessStr ? atoi(relativeNicenessStr) :
-             kRelativeNiceness));
-#endif
-
     Open(aChannel, aParentHandle, aIOLoop);
     sSingleton = this;
 
 #if defined(ANDROID)
     PCrashReporterChild* crashreporter = SendPCrashReporterConstructor();
     InfallibleTArray<Mapping> mappings;
     const struct mapping_info *info = getLibraryMapping();
     while (info->name) {
@@ -410,17 +390,17 @@ ContentChild::RecvRegisterChrome(const I
 
 bool
 ContentChild::RecvSetOffline(const PRBool& offline)
 {
   nsCOMPtr<nsIIOService> io (do_GetIOService());
   NS_ASSERTION(io, "IO Service can not be null");
 
   io->SetOffline(offline);
-    
+
   return true;
 }
 
 void
 ContentChild::ActorDestroy(ActorDestroyReason why)
 {
     if (AbnormalShutdown == why) {
         NS_WARNING("shutting down early because of crash!");
@@ -430,17 +410,17 @@ ContentChild::ActorDestroy(ActorDestroyR
 #ifndef DEBUG
     // In release builds, there's no point in the content process
     // going through the full XPCOM shutdown path, because it doesn't
     // keep persistent state.
     QuickExit();
 #endif
 
     mAlertObservers.Clear();
-    
+
     nsCOMPtr<nsIConsoleService> svc(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
     if (svc) {
         svc->UnregisterListener(mConsoleListener);
         mConsoleListener->mChild = nsnull;
     }
 
     XRE_ShutdownChildProcess();
 }
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -65,16 +65,21 @@
 #include "nsIAlertsService.h"
 #include "nsToolkitCompsCID.h"
 #include "nsIDOMGeoGeolocation.h"
 #include "nsIConsoleService.h"
 #include "nsIScriptError.h"
 #include "nsConsoleMessage.h"
 #include "AudioParent.h"
 
+#if defined(ANDROID) || defined(LINUX)
+#include <sys/time.h>
+#include <sys/resource.h>
+#endif
+
 #ifdef MOZ_PERMISSIONS
 #include "nsPermissionManager.h"
 #endif
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsICrashReporter.h"
 #include "nsExceptionHandler.h"
 #endif
@@ -140,16 +145,36 @@ void
 ContentParent::OnChannelConnected(int32 pid)
 {
     ProcessHandle handle;
     if (!base::OpenPrivilegedProcessHandle(pid, &handle)) {
         NS_WARNING("Can't open handle to child process.");
     }
     else {
         SetOtherProcess(handle);
+
+#if defined(ANDROID) || defined(LINUX)
+        EnsurePrefService();
+        nsCOMPtr<nsIPrefBranch> branch;
+        branch = do_QueryInterface(mPrefService);
+
+        // Check nice preference
+        PRInt32 nice = 0;
+        branch->GetIntPref("dom.ipc.content.nice", &nice);
+
+        // Environment variable overrides preference
+        char* relativeNicenessStr = getenv("MOZ_CHILD_PROCESS_RELATIVE_NICENESS");
+        if (relativeNicenessStr) {
+            nice = atoi(relativeNicenessStr);
+        }
+
+        if (nice != 0) {
+            setpriority(PRIO_PROCESS, pid, getpriority(PRIO_PROCESS, pid) + nice);
+        }
+#endif
     }
 }
 
 namespace {
 void
 DelayedDeleteSubprocess(GeckoChildProcessHost* aSubprocess)
 {
     XRE_GetIOMessageLoop()