Allow setting a minimum scheduler policy for a service.
The binder kernel driver supports priority inheritance
at a node (service)-basis, that makes sure all transactions
into that service are executed at a specified minimum
scheduler policy and priority.
This change allows users of HIDL interfaces to set
such a policy for their interface.
Bug: 37293077
Test: verified min_prio in /d/binder output
Change-Id: If72dd8322381246832b460c386dda44fbd225757
diff --git a/transport/HidlTransportSupport.cpp b/transport/HidlTransportSupport.cpp
index a5ec8e2..ea2e32c 100644
--- a/transport/HidlTransportSupport.cpp
+++ b/transport/HidlTransportSupport.cpp
@@ -14,7 +14,6 @@
* limitations under the License.
*/
#include <hidl/HidlTransportSupport.h>
-
#include <hidl/HidlBinderSupport.h>
namespace android {
@@ -29,5 +28,30 @@
joinBinderRpcThreadpool();
}
+bool setMinSchedulerPolicy(const sp<::android::hidl::base::V1_0::IBase>& service,
+ int policy, int priority) {
+ if (service->isRemote()) {
+ ALOGE("Can't set scheduler policy on remote service.");
+ return false;
+ }
+
+ if (policy != SCHED_NORMAL && policy != SCHED_FIFO && policy != SCHED_RR) {
+ ALOGE("Invalid scheduler policy %d", policy);
+ return false;
+ }
+
+ if (policy == SCHED_NORMAL && (priority < -20 || priority > 19)) {
+ ALOGE("Invalid priority for SCHED_NORMAL: %d", priority);
+ return false;
+ } else if (priority < 1 || priority > 99) {
+ ALOGE("Invalid priority for real-time policy: %d", priority);
+ return false;
+ }
+
+ details::gServicePrioMap.set(service, { policy, priority });
+
+ return true;
}
-}
\ No newline at end of file
+
+}
+}