From fb92cd3c22980e6ee6574be193f8ec993d19b2bf Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Mon, 17 Jul 2023 20:29:46 +0000 Subject: [PATCH] storageproxyd: Start binder thread pool The Trusty storage proxy requires that the suspend service is started to acquire a wakelock for UFS RPMB operations. Without the binder thread pool running, starting this service results in at least a 1s polling delay. This change ensures that we start the thread pool before handling any RPMB operations, so acquiring the wakelock will complete as soon as the service is ready without needing to poll once per second. Test: m storageproxyd Test: Artificially delay suspend_service to check if we poll Bug: 281951047 Change-Id: I1a4cdd48d57201b0cf9c24523d22e5bdbcea376a --- trusty/storage/proxy/Android.bp | 1 + trusty/storage/proxy/proxy.c | 10 ++++++++++ trusty/storage/proxy/rpmb.c | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/trusty/storage/proxy/Android.bp b/trusty/storage/proxy/Android.bp index 2e97ee0fe..e362b8b97 100644 --- a/trusty/storage/proxy/Android.bp +++ b/trusty/storage/proxy/Android.bp @@ -33,6 +33,7 @@ cc_binary { shared_libs: [ "libbase", + "libbinder_ndk", "libcutils", "liblog", "libhardware_legacy", diff --git a/trusty/storage/proxy/proxy.c b/trusty/storage/proxy/proxy.c index c89c5b6fd..3b744ec94 100644 --- a/trusty/storage/proxy/proxy.c +++ b/trusty/storage/proxy/proxy.c @@ -24,6 +24,7 @@ #include #include +#include #include #include "checkpoint_handling.h" @@ -238,6 +239,15 @@ int main(int argc, char* argv[]) { /* parse arguments */ parse_args(argc, argv); + /* + * Start binder threadpool. At least one extra binder thread is needed to + * connect to the wakelock service without relying on polling. If we poll on + * the main thread we end up pausing for at least 1s even if the service + * starts faster. + */ + ABinderProcess_setThreadPoolMaxThreadCount(1); + ABinderProcess_startThreadPool(); + /* initialize secure storage directory */ rc = storage_init(ss_data_root); if (rc < 0) return EXIT_FAILURE; diff --git a/trusty/storage/proxy/rpmb.c b/trusty/storage/proxy/rpmb.c index 22a85a72b..1f5d10796 100644 --- a/trusty/storage/proxy/rpmb.c +++ b/trusty/storage/proxy/rpmb.c @@ -399,6 +399,14 @@ static int send_ufs_rpmb_req(int sg_fd, const struct storage_rpmb_send_req* req, bool is_request_write = req->reliable_write_size > 0; + /* + * Internally this call connects to the suspend service, which will cause + * this service to start if not already running. If the binder thread pool + * has not been started at this point, this call will block and poll for the + * service every 1s. We need to make sure the thread pool is started to + * receive an async notification that the service is started to avoid + * blocking (see main). + */ wl_rc = acquire_wake_lock(PARTIAL_WAKE_LOCK, UFS_WAKE_LOCK_NAME); if (wl_rc < 0) { ALOGE("%s: failed to acquire wakelock: %d, %s\n", __func__, wl_rc, strerror(errno));