From 721ac4d35013f189087ab256f18d2289b512c775 Mon Sep 17 00:00:00 2001 From: Yurii Zubrytskyi Date: Mon, 13 Apr 2020 11:34:32 -0700 Subject: [PATCH] [incfs] Correctly wait for async .so's extraction StorageID for an installation changes as we go from a staging directory to the final one. That's why the only correct way of waiting for the extraction to complete is by the whole MountID, even if later it would cause the call to wait on all instances of the app. + measure the waiting timing Bug: 153513507 Test: adb install megacity.apk Change-Id: I83558f155867ae5503719ecb63d591fc969c3995 --- services/incremental/IncrementalService.cpp | 32 +++++++++++++++++---- services/incremental/IncrementalService.h | 4 +-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp index 695b68bf71cb0..149dfa6be6c4c 100644 --- a/services/incremental/IncrementalService.cpp +++ b/services/incremental/IncrementalService.cpp @@ -1279,7 +1279,7 @@ bool IncrementalService::configureNativeBinaries(StorageId storage, std::string_ { std::lock_guard lock(mJobMutex); if (mRunning) { - auto& existingJobs = mJobQueue[storage]; + auto& existingJobs = mJobQueue[ifs->mountId]; if (existingJobs.empty()) { existingJobs = std::move(jobQueue); } else { @@ -1369,12 +1369,32 @@ void IncrementalService::extractZipFile(const IfsMountPtr& ifs, ZipArchiveHandle } bool IncrementalService::waitForNativeBinariesExtraction(StorageId storage) { + struct WaitPrinter { + const Clock::time_point startTs = Clock::now(); + ~WaitPrinter() noexcept { + if (sEnablePerfLogging) { + const auto endTs = Clock::now(); + LOG(INFO) << "incfs: waitForNativeBinariesExtraction() complete in " + << elapsedMcs(startTs, endTs) << "mcs"; + } + } + } waitPrinter; + + MountId mount; + { + auto ifs = getIfs(storage); + if (!ifs) { + return true; + } + mount = ifs->mountId; + } + std::unique_lock lock(mJobMutex); - mJobCondition.wait(lock, [this, storage] { + mJobCondition.wait(lock, [this, mount] { return !mRunning || - (mPendingJobsStorage != storage && mJobQueue.find(storage) == mJobQueue.end()); + (mPendingJobsMount != mount && mJobQueue.find(mount) == mJobQueue.end()); }); - return mPendingJobsStorage != storage && mJobQueue.find(storage) == mJobQueue.end(); + return mRunning; } void IncrementalService::runJobProcessing() { @@ -1386,7 +1406,7 @@ void IncrementalService::runJobProcessing() { } auto it = mJobQueue.begin(); - mPendingJobsStorage = it->first; + mPendingJobsMount = it->first; auto queue = std::move(it->second); mJobQueue.erase(it); lock.unlock(); @@ -1396,7 +1416,7 @@ void IncrementalService::runJobProcessing() { } lock.lock(); - mPendingJobsStorage = kInvalidStorageId; + mPendingJobsMount = kInvalidStorageId; lock.unlock(); mJobCondition.notify_all(); } diff --git a/services/incremental/IncrementalService.h b/services/incremental/IncrementalService.h index e7705df633d12..c016bab067be7 100644 --- a/services/incremental/IncrementalService.h +++ b/services/incremental/IncrementalService.h @@ -308,8 +308,8 @@ private: StorageId mNextId = 0; using Job = std::function; - std::unordered_map> mJobQueue; - StorageId mPendingJobsStorage = kInvalidStorageId; + std::unordered_map> mJobQueue; + MountId mPendingJobsMount = kInvalidStorageId; std::condition_variable mJobCondition; std::mutex mJobMutex; std::thread mJobProcessor;