Bug 1045524 - Make the priority adjustment functions use HAL_LOG() instead of spamming the logcat directly. r=dhylands
authorGabriele Svelto <gsvelto@mozilla.com>
Wed, 30 Jul 2014 17:01:08 +0200
changeset 218981 6ff5cb4b54359d2e017b524e151d530a0111f6e0
parent 218980 92c571f0daf9f348d4301ac81bf9da61a7533d3c
child 218982 0c6d71465f2048bde187bb467d7f1ba47d4bd043
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands
bugs1045524
milestone34.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 1045524 - Make the priority adjustment functions use HAL_LOG() instead of spamming the logcat directly. r=dhylands
hal/Hal.h
hal/gonk/GonkHal.cpp
--- a/hal/Hal.h
+++ b/hal/Hal.h
@@ -44,16 +44,17 @@ namespace mozilla {
 namespace hal {
 
 typedef Observer<void_t> AlarmObserver;
 
 class WindowIdentifier;
 
 extern PRLogModuleInfo *GetHalLog();
 #define HAL_LOG(msg) PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_DEBUG, msg)
+#define HAL_ERR(msg) PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_ERROR, msg)
 
 typedef Observer<int64_t> SystemClockChangeObserver;
 typedef Observer<SystemTimezoneChangeInformation> SystemTimezoneChangeObserver;
 
 } // namespace hal
 
 namespace MOZ_HAL_NAMESPACE {
 
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -64,17 +64,16 @@
 #include "nsThreadUtils.h"
 #include "nsIThread.h"
 #include "nsXULAppAPI.h"
 #include "OrientationObserver.h"
 #include "UeventPoller.h"
 #include "nsIWritablePropertyBag2.h"
 #include <algorithm>
 
-#define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
 #define NsecPerMsec  1000000LL
 #define NsecPerSec   1000000000
 
 // The header linux/oom.h is not available in bionic libc. We
 // redefine some of its constants here.
 
 #ifndef OOM_DISABLE
 #define OOM_DISABLE  (-17)
@@ -1392,39 +1391,39 @@ EnsureKernelLowMemKillerParamsSet()
 }
 
 static void
 SetNiceForPid(int aPid, int aNice)
 {
   errno = 0;
   int origProcPriority = getpriority(PRIO_PROCESS, aPid);
   if (errno) {
-    LOG("Unable to get nice for pid=%d; error %d.  SetNiceForPid bailing.",
-        aPid, errno);
+    HAL_LOG(("Unable to get nice for pid=%d; error %d.  SetNiceForPid bailing.",
+             aPid, errno));
     return;
   }
 
   int rv = setpriority(PRIO_PROCESS, aPid, aNice);
   if (rv) {
-    LOG("Unable to set nice for pid=%d; error %d.  SetNiceForPid bailing.",
-        aPid, errno);
+    HAL_LOG(("Unable to set nice for pid=%d; error %d.  SetNiceForPid bailing.",
+             aPid, errno));
     return;
   }
 
   // On Linux, setpriority(aPid) modifies the priority only of the main
   // thread of that process.  We have to modify the priorities of all of the
   // process's threads as well, so iterate over all the threads and increase
   // each of their priorites by aNice - origProcPriority (and also ensure that
   // none of the tasks has a lower priority than the main thread).
   //
   // This is horribly racy.
 
   DIR* tasksDir = opendir(nsPrintfCString("/proc/%d/task/", aPid).get());
   if (!tasksDir) {
-    LOG("Unable to open /proc/%d/task.  SetNiceForPid bailing.", aPid);
+    HAL_LOG(("Unable to open /proc/%d/task.  SetNiceForPid bailing.", aPid));
     return;
   }
 
   // Be careful not to leak tasksDir; after this point, we must call closedir().
 
   while (struct dirent* de = readdir(tasksDir)) {
     char* endptr = nullptr;
     long tidlong = strtol(de->d_name, &endptr, /* base */ 10);
@@ -1447,19 +1446,19 @@ SetNiceForPid(int aPid, int aNice)
     if (schedPolicy == SCHED_FIFO || schedPolicy == SCHED_RR) {
       continue;
     }
 
     errno = 0;
     // Get and set the task's new priority.
     int origtaskpriority = getpriority(PRIO_PROCESS, tid);
     if (errno) {
-      LOG("Unable to get nice for tid=%d (pid=%d); error %d.  This isn't "
-          "necessarily a problem; it could be a benign race condition.",
-          tid, aPid, errno);
+      HAL_LOG(("Unable to get nice for tid=%d (pid=%d); error %d.  This isn't "
+               "necessarily a problem; it could be a benign race condition.",
+               tid, aPid, errno));
       continue;
     }
 
     int newtaskpriority =
       std::max(origtaskpriority - origProcPriority + aNice, aNice);
 
     // Do not reduce priority of threads already running at priorities greater
     // than normal.  These threads are likely special service threads that need
@@ -1467,25 +1466,25 @@ SetNiceForPid(int aPid, int aNice)
     if (newtaskpriority > origtaskpriority &&
         origtaskpriority < ANDROID_PRIORITY_NORMAL) {
       continue;
     }
 
     rv = setpriority(PRIO_PROCESS, tid, newtaskpriority);
 
     if (rv) {
-      LOG("Unable to set nice for tid=%d (pid=%d); error %d.  This isn't "
-          "necessarily a problem; it could be a benign race condition.",
-          tid, aPid, errno);
+      HAL_LOG(("Unable to set nice for tid=%d (pid=%d); error %d.  This isn't "
+               "necessarily a problem; it could be a benign race condition.",
+               tid, aPid, errno));
       continue;
     }
   }
 
-  LOG("Changed nice for pid %d from %d to %d.",
-      aPid, origProcPriority, aNice);
+  HAL_LOG(("Changed nice for pid %d from %d to %d.",
+           aPid, origProcPriority, aNice));
 
   closedir(tasksDir);
 }
 
 void
 SetProcessPriority(int aPid,
                    ProcessPriority aPriority,
                    ProcessCPUPriority aCPUPriority,
@@ -1509,61 +1508,59 @@ SetProcessPriority(int aPid,
     ProcessPriorityToString(aPriority)).get(), &oomScoreAdj);
 
   RoundOomScoreAdjUpWithBackroundLRU(oomScoreAdj, aBackgroundLRU);
 
   if (NS_SUCCEEDED(rv)) {
     int clampedOomScoreAdj = clamped<int>(oomScoreAdj, OOM_SCORE_ADJ_MIN,
                                                        OOM_SCORE_ADJ_MAX);
     if(clampedOomScoreAdj != oomScoreAdj) {
-      HAL_LOG(("Clamping OOM adjustment for pid %d to %d",
-               aPid, clampedOomScoreAdj));
+      HAL_LOG(("Clamping OOM adjustment for pid %d to %d", aPid,
+               clampedOomScoreAdj));
     } else {
-      HAL_LOG(("Setting OOM adjustment for pid %d to %d",
-               aPid, clampedOomScoreAdj));
+      HAL_LOG(("Setting OOM adjustment for pid %d to %d", aPid,
+               clampedOomScoreAdj));
     }
 
     // We try the newer interface first, and fall back to the older interface
     // on failure.
 
     if (!WriteToFile(nsPrintfCString("/proc/%d/oom_score_adj", aPid).get(),
                      nsPrintfCString("%d", clampedOomScoreAdj).get()))
     {
       int oomAdj = OomAdjOfOomScoreAdj(clampedOomScoreAdj);
 
       WriteToFile(nsPrintfCString("/proc/%d/oom_adj", aPid).get(),
                   nsPrintfCString("%d", oomAdj).get());
     }
   } else {
-    LOG("Unable to read oom_score_adj pref for priority %s; "
-        "are the prefs messed up?",
-        ProcessPriorityToString(aPriority));
+    HAL_ERR(("Unable to read oom_score_adj pref for priority %s; "
+             "are the prefs messed up?", ProcessPriorityToString(aPriority)));
     MOZ_ASSERT(false);
   }
 
   int32_t nice = 0;
 
   if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
     rv = Preferences::GetInt(
       nsPrintfCString("hal.processPriorityManager.gonk.%s.Nice",
                       ProcessPriorityToString(aPriority)).get(),
       &nice);
   } else if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
     rv = Preferences::GetInt("hal.processPriorityManager.gonk.LowCPUNice",
                              &nice);
   } else {
-    LOG("Unable to read niceness pref for priority %s; "
-        "are the prefs messed up?",
-        ProcessPriorityToString(aPriority));
+    HAL_ERR(("Unable to read niceness pref for priority %s; "
+             "are the prefs messed up?", ProcessPriorityToString(aPriority)));
     MOZ_ASSERT(false);
     rv = NS_ERROR_FAILURE;
   }
 
   if (NS_SUCCEEDED(rv)) {
-    LOG("Setting nice for pid %d to %d", aPid, nice);
+    HAL_LOG(("Setting nice for pid %d to %d", aPid, nice));
     SetNiceForPid(aPid, nice);
   }
 }
 
 static bool
 IsValidRealTimePriority(int aValue, int aSchedulePolicy)
 {
   return (aValue >= sched_get_priority_min(aSchedulePolicy)) &&
@@ -1571,47 +1568,48 @@ IsValidRealTimePriority(int aValue, int 
 }
 
 static void
 SetThreadNiceValue(pid_t aTid, ThreadPriority aThreadPriority, int aValue)
 {
   MOZ_ASSERT(aThreadPriority < NUM_THREAD_PRIORITY);
   MOZ_ASSERT(aThreadPriority >= 0);
 
-  LOG("Setting thread %d to priority level %s; nice level %d",
-      aTid, ThreadPriorityToString(aThreadPriority), aValue);
+  HAL_LOG(("Setting thread %d to priority level %s; nice level %d",
+           aTid, ThreadPriorityToString(aThreadPriority), aValue));
   int rv = setpriority(PRIO_PROCESS, aTid, aValue);
 
   if (rv) {
-    LOG("Failed to set thread %d to priority level %s; error %s",
-        aTid, ThreadPriorityToString(aThreadPriority), strerror(errno));
+    HAL_LOG(("Failed to set thread %d to priority level %s; error %s", aTid,
+             ThreadPriorityToString(aThreadPriority), strerror(errno)));
   }
 }
 
 static void
 SetRealTimeThreadPriority(pid_t aTid,
                           ThreadPriority aThreadPriority,
                           int aValue)
 {
   int policy = SCHED_FIFO;
 
   MOZ_ASSERT(aThreadPriority < NUM_THREAD_PRIORITY);
   MOZ_ASSERT(aThreadPriority >= 0);
   MOZ_ASSERT(IsValidRealTimePriority(aValue, policy), "Invalid real time priority");
 
   // Setting real time priorities requires using sched_setscheduler
-  LOG("Setting thread %d to priority level %s; Real Time priority %d, Schedule FIFO",
-      aTid, ThreadPriorityToString(aThreadPriority), aValue);
+  HAL_LOG(("Setting thread %d to priority level %s; Real Time priority %d, "
+           "Schedule FIFO", aTid, ThreadPriorityToString(aThreadPriority),
+           aValue));
   sched_param schedParam;
   schedParam.sched_priority = aValue;
   int rv = sched_setscheduler(aTid, policy, &schedParam);
 
   if (rv) {
-    LOG("Failed to set thread %d to real time priority level %s; error %s",
-        aTid, ThreadPriorityToString(aThreadPriority), strerror(errno));
+    HAL_LOG(("Failed to set thread %d to real time priority level %s; error %s",
+             aTid, ThreadPriorityToString(aThreadPriority), strerror(errno)));
   }
 }
 
 static void
 SetThreadPriority(pid_t aTid, hal::ThreadPriority aThreadPriority)
 {
   // See bug 999115, we can only read preferences on the main thread otherwise
   // we create a race condition in HAL
@@ -1619,17 +1617,18 @@ SetThreadPriority(pid_t aTid, hal::Threa
   MOZ_ASSERT(aThreadPriority >= 0);
 
   const char* threadPriorityStr;
   switch (aThreadPriority) {
     case THREAD_PRIORITY_COMPOSITOR:
       threadPriorityStr = ThreadPriorityToString(aThreadPriority);
       break;
     default:
-      LOG("Unrecognized thread priority %d; Doing nothing", aThreadPriority);
+      HAL_ERR(("Unrecognized thread priority %d; Doing nothing",
+               aThreadPriority));
       return;
   }
 
   int realTimePriority = Preferences::GetInt(
     nsPrintfCString("hal.gonk.%s.rt_priority", threadPriorityStr).get());
 
   if (IsValidRealTimePriority(realTimePriority, SCHED_FIFO)) {
     SetRealTimeThreadPriority(aTid, aThreadPriority, realTimePriority);
@@ -1681,17 +1680,18 @@ SetCurrentThreadPriority(ThreadPriority 
     case THREAD_PRIORITY_COMPOSITOR: {
       pid_t threadId = gettid();
       nsCOMPtr<nsIRunnable> runnable =
         new SetThreadPriorityRunnable(threadId, aThreadPriority);
       NS_DispatchToMainThread(runnable);
       break;
     }
     default:
-      LOG("Unrecognized thread priority %d; Doing nothing", aThreadPriority);
+      HAL_LOG(("Unrecognized thread priority %d; Doing nothing",
+               aThreadPriority));
       return;
   }
 }
 
 void
 FactoryReset(FactoryResetReason& aReason)
 {
   nsCOMPtr<nsIRecoveryService> recoveryService =