From aede9897df492e7dd550f581e49d9151b36fcea8 Mon Sep 17 00:00:00 2001 From: Riley Andrews Date: Mon, 8 Jun 2015 23:36:34 -0700 Subject: [PATCH] Lower the priority of the threads in logd/logcat. (cherry pick from commit d98f4e8af5076e6a9dbd4ddc2c375cb7bcda8cd8) sched_batch implies only a penalty to latency in scheduling, but does not imply that the process will be given less cpu time. Increase the nice level to 10 to prioritize it below ui threads. Bug: 21696721 Change-Id: I075af059dc755402f7df9b0d7a66cca921ff04b2 --- logcat/logcat.cpp | 6 ++++++ logd/main.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp index 736e02eaa..e598bb810 100644 --- a/logcat/logcat.cpp +++ b/logcat/logcat.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,7 @@ #include #include #include +#include #define DEFAULT_MAX_ROTATED_LOGS 4 @@ -221,6 +223,10 @@ static void setupOutput() fprintf(stderr, "failed to set to batch scheduler\n"); } + if (setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_BACKGROUND) < 0) { + fprintf(stderr, "failed set to priority\n"); + } + g_outFD = openLogFile (g_outputFileName); if (g_outFD < 0) { diff --git a/logd/main.cpp b/logd/main.cpp index 805cbe64b..a876c99cb 100644 --- a/logd/main.cpp +++ b/logd/main.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,7 @@ #include #include #include +#include #include "CommandListener.h" #include "LogBuffer.h" @@ -91,6 +93,10 @@ static int drop_privs() { return -1; } + if (setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_BACKGROUND) < 0) { + return -1; + } + if (prctl(PR_SET_KEEPCAPS, 1) < 0) { return -1; } @@ -156,6 +162,7 @@ static LogBuffer *logBuf = NULL; static void *reinit_thread_start(void * /*obj*/) { prctl(PR_SET_NAME, "logd.daemon"); set_sched_policy(0, SP_BACKGROUND); + setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_BACKGROUND); setgid(AID_SYSTEM); setuid(AID_SYSTEM);