From 2b6317436d2035ce98331906aaaca87e6026c9c8 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Fri, 5 May 2017 11:16:59 -0700 Subject: [PATCH] Correctly set minimum priority on nodes. It looks like libbinder has always set the minimum priority for a node to 0x7f (127). This is an invalid value as far as the kernel is concerned, since the current driver only accepts positive nice values (0..19). The effect of using 0xf7 is that the nice value was clamped to MAX_NICE (19) - so effectively the kernel never raised the priority based on the min_priority setting of a node. Correct this by just using MAX_NICE directly. Additionally, a recent change removed the use of the gDisableBackgroundScheduling flag, which system_server used to make sure that incoming transactions were not executed at a lower priority. That behavior is actually still desired, so this change sets the min_priorirty value to 0 for processes that have requested background scheduling to be disabled. The effect of that is that all transactions into those nodes will be executed with a priority of at least nice 0 (and potentially higher, depending on the priority of the caller). Bug: 37677242 Test: verified /d/binder output Change-Id: I7cbfd309d04cbd052f868fbfe0930529ff21a48a --- libs/binder/IPCThreadState.cpp | 5 +++++ libs/binder/Parcel.cpp | 9 ++++++++- libs/binder/include/binder/IPCThreadState.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index d0cd8f2f22..e8329613ab 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -338,6 +338,11 @@ void IPCThreadState::disableBackgroundScheduling(bool disable) gDisableBackgroundScheduling = disable; } +bool IPCThreadState::backgroundSchedulingDisabled() +{ + return gDisableBackgroundScheduling; +} + sp IPCThreadState::process() { return mProcess; diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 39bb078fd1..aec8f107a3 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -211,7 +211,14 @@ status_t flatten_binder(const sp& /*proc*/, { flat_binder_object obj; - obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS; + if (IPCThreadState::self()->backgroundSchedulingDisabled()) { + /* minimum priority for all nodes is nice 0 */ + obj.flags = FLAT_BINDER_FLAG_ACCEPTS_FDS; + } else { + /* minimum priority for all nodes is MAX_NICE(19) */ + obj.flags = 0x13 | FLAT_BINDER_FLAG_ACCEPTS_FDS; + } + if (binder != NULL) { IBinder *local = binder->localBinder(); if (!local) { diff --git a/libs/binder/include/binder/IPCThreadState.h b/libs/binder/include/binder/IPCThreadState.h index 7b826d6dcd..245607e74e 100644 --- a/libs/binder/include/binder/IPCThreadState.h +++ b/libs/binder/include/binder/IPCThreadState.h @@ -83,6 +83,7 @@ public: // in to it but doesn't want to acquire locks in its services while in // the background. static void disableBackgroundScheduling(bool disable); + bool backgroundSchedulingDisabled(); // Call blocks until the number of executing binder threads is less than // the maximum number of binder threads threads allowed for this process. -- 2.11.0