From 71a210eec63a9987af147f4c68ecc16f19b8667b Mon Sep 17 00:00:00 2001 From: Ankit Goyal Date: Tue, 5 Oct 2021 18:27:19 +0800 Subject: Maximize the priority of gralloc allocator thread Bug: 201933520 Test: Boot to home Change-Id: I125493e6b06436e4daac73c208cd5ca5ab4b68bd --- gralloc4/service/4.x/Android.bp | 4 ++++ gralloc4/service/4.x/service.cpp | 27 ++++++++++++++++++++++----- gralloc4/src/4.x/GrallocAllocator.cpp | 10 ++-------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/gralloc4/service/4.x/Android.bp b/gralloc4/service/4.x/Android.bp index de06942..5bd81bc 100644 --- a/gralloc4/service/4.x/Android.bp +++ b/gralloc4/service/4.x/Android.bp @@ -29,8 +29,12 @@ cc_binary { init_rc: [ "android.hardware.graphics.allocator@4.0-service.rc", ], + header_libs: [ + "libgralloc_headers", + ], shared_libs: [ "android.hardware.graphics.allocator@4.0", + "android.hardware.graphics.allocator@4.0-impl", "libhidlbase", "liblog", "libutils", diff --git a/gralloc4/service/4.x/service.cpp b/gralloc4/service/4.x/service.cpp index bd28407..d540086 100644 --- a/gralloc4/service/4.x/service.cpp +++ b/gralloc4/service/4.x/service.cpp @@ -16,13 +16,30 @@ */ #define LOG_TAG "android.hardware.graphics.allocator@4.0-service" -#include +#include +#include +#include -#include +#include "4.x/GrallocAllocator.h" -using android::hardware::defaultPassthroughServiceImplementation; -using android::hardware::graphics::allocator::V4_0::IAllocator; +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::hardware::setMinSchedulerPolicy; +using arm::allocator::GrallocAllocator; int main() { - return defaultPassthroughServiceImplementation(/*maxThreads*/ 4); + android::sp service = new GrallocAllocator(); + configureRpcThreadpool(4, true /* callerWillJoin */); + + if (!setMinSchedulerPolicy(service, SCHED_NORMAL, -20)) { + ALOGW("Cannot bump allocator priority"); + } + + if (service->registerAsService() != android::OK) { + ALOGE("Cannot register allocator service"); + return -EINVAL; + } + + joinRpcThreadpool(); + return 0; } diff --git a/gralloc4/src/4.x/GrallocAllocator.cpp b/gralloc4/src/4.x/GrallocAllocator.cpp index 4e074b5..0ac81fd 100644 --- a/gralloc4/src/4.x/GrallocAllocator.cpp +++ b/gralloc4/src/4.x/GrallocAllocator.cpp @@ -40,6 +40,8 @@ unsigned long callingPid() { GrallocAllocator::GrallocAllocator() { + MALI_GRALLOC_LOGV("Arm Module IAllocator %d.%d, pid = %d ppid = %d", GRALLOC_VERSION_MAJOR, + (HIDL_ALLOCATOR_VERSION_SCALED - (GRALLOC_VERSION_MAJOR * 100)) / 10, getpid(), getppid()); } GrallocAllocator::~GrallocAllocator() @@ -64,11 +66,3 @@ Return GrallocAllocator::allocate(const BufferDescriptor &descriptor, uint } // namespace allocator } // namespace arm - -extern "C" IAllocator *HIDL_FETCH_IAllocator(const char * /* name */) -{ - MALI_GRALLOC_LOGV("Arm Module IAllocator %d.%d, pid = %d ppid = %d", GRALLOC_VERSION_MAJOR, - (HIDL_ALLOCATOR_VERSION_SCALED - (GRALLOC_VERSION_MAJOR * 100)) / 10, getpid(), getppid()); - - return new arm::allocator::GrallocAllocator(); -} -- cgit v1.2.3