From db560090e4dcf19aa0909a27da473c4ac704af88 Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Tue, 28 May 2024 18:25:12 -0700 Subject: [PATCH 1/2] libsnapshot: set thread priority Read merge thread + worker thread priority from build configurations. In the case of low memory devices, a lower priority will reduce CPU utilization post OTA reboot. Test: th Change-Id: I812fccf2ca805d9686a837774e1770a2eebf979a --- .../libsnapshot/snapuserd/user-space-merge/merge_worker.cpp | 4 +++- .../libsnapshot/snapuserd/user-space-merge/read_worker.cpp | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/merge_worker.cpp b/fs_mgr/libsnapshot/snapuserd/user-space-merge/merge_worker.cpp index bd7eaca74..0f4674ced 100644 --- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/merge_worker.cpp +++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/merge_worker.cpp @@ -577,8 +577,10 @@ bool MergeWorker::Run() { SNAP_LOG(ERROR) << "Merge terminated early..."; return true; } + auto merge_thread_priority = android::base::GetUintProperty( + "ro.virtual_ab.merge_thread_priority", ANDROID_PRIORITY_BACKGROUND); - if (!SetThreadPriority(ANDROID_PRIORITY_BACKGROUND)) { + if (!SetThreadPriority(merge_thread_priority)) { SNAP_PLOG(ERROR) << "Failed to set thread priority"; } diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/read_worker.cpp b/fs_mgr/libsnapshot/snapuserd/user-space-merge/read_worker.cpp index d40b6d11d..35a162199 100644 --- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/read_worker.cpp +++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/read_worker.cpp @@ -17,8 +17,10 @@ #include #include +#include "android-base/properties.h" #include "read_worker.h" #include "snapuserd_core.h" +#include "user-space-merge/worker.h" #include "utility.h" namespace android { @@ -259,8 +261,10 @@ bool ReadWorker::Run() { SNAP_LOG(INFO) << "Processing snapshot I/O requests...."; pthread_setname_np(pthread_self(), "ReadWorker"); + auto worker_thread_priority = android::base::GetUintProperty( + "ro.virtual_ab.worker_thread_priority", ANDROID_PRIORITY_NORMAL); - if (!SetThreadPriority(ANDROID_PRIORITY_NORMAL)) { + if (!SetThreadPriority(worker_thread_priority)) { SNAP_PLOG(ERROR) << "Failed to set thread priority"; } From 28801377a5d09fce686edbd81c1d5e4d9f698e5e Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Wed, 29 May 2024 10:44:09 -0700 Subject: [PATCH 2/2] libsnapshot: configure threshold size Test: th Change-Id: Iba59fdc3e1188dd343314d129806d2c4c94aa8c5 --- .../user-space-merge/snapuserd_verify.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_verify.cpp b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_verify.cpp index 681734080..957c6a8a7 100644 --- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_verify.cpp +++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_verify.cpp @@ -20,6 +20,7 @@ #include #include +#include "android-base/properties.h" #include "snapuserd_core.h" namespace android { @@ -104,7 +105,9 @@ bool UpdateVerify::VerifyBlocks(const std::string& partition_name, } loff_t file_offset = offset; - const uint64_t read_sz = kBlockSizeVerify; + auto verify_block_size = android::base::GetUintProperty("ro.virtual_ab.verify_block_size", + kBlockSizeVerify); + const uint64_t read_sz = verify_block_size; void* addr; ssize_t page_size = getpagesize(); @@ -130,7 +133,7 @@ bool UpdateVerify::VerifyBlocks(const std::string& partition_name, } bytes_read += to_read; - file_offset += (skip_blocks * kBlockSizeVerify); + file_offset += (skip_blocks * verify_block_size); if (file_offset >= dev_sz) { break; } @@ -184,7 +187,9 @@ bool UpdateVerify::VerifyPartition(const std::string& partition_name, * latency. */ int num_threads = kMinThreadsToVerify; - if (dev_sz > kThresholdSize) { + auto verify_threshold_size = android::base::GetUintProperty( + "ro.virtual_ab.verify_threshold_size", kThresholdSize); + if (dev_sz > verify_threshold_size) { num_threads = kMaxThreadsToVerify; } @@ -192,11 +197,13 @@ bool UpdateVerify::VerifyPartition(const std::string& partition_name, off_t start_offset = 0; const int skip_blocks = num_threads; + auto verify_block_size = + android::base::GetUintProperty("ro.virtual_ab.verify_block_size", kBlockSizeVerify); while (num_threads) { threads.emplace_back(std::async(std::launch::async, &UpdateVerify::VerifyBlocks, this, partition_name, dm_block_device, start_offset, skip_blocks, dev_sz)); - start_offset += kBlockSizeVerify; + start_offset += verify_block_size; num_threads -= 1; if (start_offset >= dev_sz) { break;