Bug 914541 - Assign higher priority for mozapptype=inputmethod. r=fabrice, a=koi+
authorKan-Ru Chen (???) <kanru@kanru.info>
Tue, 24 Sep 2013 16:10:20 +0800
changeset 161376 00c23047048ab2b201d8bd7081910f1412971e6f
parent 161375 6b26687b1b1ed7c3d080721acfb2cdf0bd70bab3
child 161377 06f04002d3fdd48c4310e97e68ad5fd72735e6b7
push id407
push userlsblakk@mozilla.com
push dateTue, 03 Dec 2013 03:32:50 +0000
treeherdermozilla-release@babf8c9ebc52 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice, koi
bugs914541
milestone26.0a2
Bug 914541 - Assign higher priority for mozapptype=inputmethod. r=fabrice, a=koi+
b2g/app/b2g.js
dom/ipc/ContentParent.cpp
dom/ipc/ProcessPriorityManager.cpp
hal/Hal.cpp
hal/HalTypes.h
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -591,28 +591,35 @@ pref("dom.ipc.processPriorityManager.tem
 // Note: The maximum nice value on Linux is 19, but the max value you should
 // use here is 18.  NSPR adds 1 to some threads' nice values, to mark
 // low-priority threads.  If the process priority manager were to renice a
 // process (and all its threads) to 19, all threads would have the same
 // niceness.  Then when we reniced the process to (say) 10, all threads would
 // /still/ have the same niceness; we'd effectively have erased NSPR's thread
 // priorities.
 
+// The kernel can only accept 6 (OomScoreAdjust, KillUnderMB) pairs. But it is
+// okay, kernel will still kill processes with larger OomScoreAdjust first even
+// its OomScoreAdjust don't have a corresponding KillUnderMB.
+
 pref("hal.processPriorityManager.gonk.MASTER.OomScoreAdjust", 0);
 pref("hal.processPriorityManager.gonk.MASTER.KillUnderMB", 4);
 pref("hal.processPriorityManager.gonk.MASTER.Nice", 0);
 
 pref("hal.processPriorityManager.gonk.FOREGROUND_HIGH.OomScoreAdjust", 67);
 pref("hal.processPriorityManager.gonk.FOREGROUND_HIGH.KillUnderMB", 5);
 pref("hal.processPriorityManager.gonk.FOREGROUND_HIGH.Nice", 0);
 
 pref("hal.processPriorityManager.gonk.FOREGROUND.OomScoreAdjust", 134);
 pref("hal.processPriorityManager.gonk.FOREGROUND.KillUnderMB", 6);
 pref("hal.processPriorityManager.gonk.FOREGROUND.Nice", 1);
 
+pref("hal.processPriorityManager.gonk.FOREGROUND_KEYBOARD.OomScoreAdjust", 200);
+pref("hal.processPriorityManager.gonk.FOREGROUND_KEYBOARD.Nice", 1);
+
 pref("hal.processPriorityManager.gonk.BACKGROUND_PERCEIVABLE.OomScoreAdjust", 400);
 pref("hal.processPriorityManager.gonk.BACKGROUND_PERCEIVABLE.KillUnderMB", 7);
 pref("hal.processPriorityManager.gonk.BACKGROUND_PERCEIVABLE.Nice", 7);
 
 pref("hal.processPriorityManager.gonk.BACKGROUND_HOMESCREEN.OomScoreAdjust", 534);
 pref("hal.processPriorityManager.gonk.BACKGROUND_HOMESCREEN.KillUnderMB", 8);
 pref("hal.processPriorityManager.gonk.BACKGROUND_HOMESCREEN.Nice", 18);
 
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -497,24 +497,27 @@ PrivilegesForApp(mozIApplication* aApp)
     }
     return base::PRIVILEGES_DEFAULT;
 }
 
 /*static*/ ProcessPriority
 ContentParent::GetInitialProcessPriority(Element* aFrameElement)
 {
     // Frames with mozapptype == critical which are expecting a system message
-    // get FOREGROUND_HIGH priority.  All other frames get FOREGROUND priority.
+    // get FOREGROUND_HIGH priority.
 
     if (!aFrameElement) {
         return PROCESS_PRIORITY_FOREGROUND;
     }
 
-    if (!aFrameElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mozapptype,
-                                    NS_LITERAL_STRING("critical"), eCaseMatters)) {
+    if (aFrameElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mozapptype,
+                                   NS_LITERAL_STRING("keyboard"), eCaseMatters)) {
+        return PROCESS_PRIORITY_FOREGROUND_KEYBOARD;
+    } else if (!aFrameElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mozapptype,
+                                           NS_LITERAL_STRING("critical"), eCaseMatters)) {
         return PROCESS_PRIORITY_FOREGROUND;
     }
 
     nsCOMPtr<nsIMozBrowserFrame> browserFrame =
         do_QueryInterface(aFrameElement);
     if (!browserFrame) {
         return PROCESS_PRIORITY_FOREGROUND;
     }
--- a/dom/ipc/ProcessPriorityManager.cpp
+++ b/dom/ipc/ProcessPriorityManager.cpp
@@ -861,17 +861,19 @@ ParticularProcessPriorityManager::Comput
   for (uint32_t i = 0; i < browsers.Length(); i++) {
     if (static_cast<TabParent*>(browsers[i])->IsVisible()) {
       isVisible = true;
       break;
     }
   }
 
   if (isVisible) {
-    return PROCESS_PRIORITY_FOREGROUND;
+    return HasAppType("keyboard") ?
+      PROCESS_PRIORITY_FOREGROUND_KEYBOARD :
+      PROCESS_PRIORITY_FOREGROUND;
   }
 
   if ((mHoldsCPUWakeLock || mHoldsHighPriorityWakeLock) &&
       IsExpectingSystemMessage()) {
     return PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE;
   }
 
   AudioChannelService* service = AudioChannelService::GetAudioChannelService();
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -863,16 +863,18 @@ ProcessPriorityToString(ProcessPriority 
 {
   switch (aPriority) {
   case PROCESS_PRIORITY_MASTER:
     return "MASTER";
   case PROCESS_PRIORITY_FOREGROUND_HIGH:
     return "FOREGROUND_HIGH";
   case PROCESS_PRIORITY_FOREGROUND:
     return "FOREGROUND";
+  case PROCESS_PRIORITY_FOREGROUND_KEYBOARD:
+    return "FOREGROUND_KEYBOARD";
   case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE:
     return "BACKGROUND_PERCEIVABLE";
   case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN:
     return "BACKGROUND_HOMESCREEN";
   case PROCESS_PRIORITY_BACKGROUND:
     return "BACKGROUND";
   case PROCESS_PRIORITY_UNKNOWN:
     return "UNKNOWN";
@@ -909,16 +911,23 @@ ProcessPriorityToString(ProcessPriority 
     }
   case PROCESS_PRIORITY_FOREGROUND:
     if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
       return "FOREGROUND:CPU_NORMAL";
     }
     if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
       return "FOREGROUND:CPU_LOW";
     }
+  case PROCESS_PRIORITY_FOREGROUND_KEYBOARD:
+    if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
+      return "FOREGROUND_KEYBOARD:CPU_NORMAL";
+    }
+    if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
+      return "FOREGROUND_KEYBOARD:CPU_LOW";
+    }
   case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE:
     if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
       return "BACKGROUND_PERCEIVABLE:CPU_NORMAL";
     }
     if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
       return "BACKGROUND_PERCEIVABLE:CPU_LOW";
     }
   case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN:
--- a/hal/HalTypes.h
+++ b/hal/HalTypes.h
@@ -78,16 +78,17 @@ typedef Observer<SwitchEvent> SwitchObse
 
 // Note that we rely on the order of this enum's entries.  Higher priorities
 // should have larger int values.
 enum ProcessPriority {
   PROCESS_PRIORITY_UNKNOWN = -1,
   PROCESS_PRIORITY_BACKGROUND,
   PROCESS_PRIORITY_BACKGROUND_HOMESCREEN,
   PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE,
+  PROCESS_PRIORITY_FOREGROUND_KEYBOARD,
   // Any priority greater than or equal to FOREGROUND is considered
   // "foreground" for the purposes of priority testing, for example
   // CurrentProcessIsForeground().
   PROCESS_PRIORITY_FOREGROUND,
   PROCESS_PRIORITY_FOREGROUND_HIGH,
   PROCESS_PRIORITY_MASTER,
   NUM_PROCESS_PRIORITY
 };