From 97186d9be095dcc1f5f3393dc4c6e09d47fe510f Mon Sep 17 00:00:00 2001 From: Juhyung Park Date: Mon, 8 Jul 2024 22:21:06 +0900 Subject: [PATCH] ota_extractor: parallelize partition extractions Each sub-partition will be extracted in a separate thread. A simple test of Nothing Phone 2's series of OTA extractions (2.0.1 -> 2.0.1a -> 2.0.2 -> 2.0.2a -> 2.0.3 -> 2.0.4 -> 2.5.1 -> 2.5.1a -> 2.5.2 -> 2.5.3 -> 2.5.5 -> 2.5.6 -> 2.6.0, 5.1 GiB in total) in AMD Ryzen Threadripper 7980X gives a speed boost of 2.55x. [Before] Percent of CPU this job got: 102% Elapsed (wall clock) time (h:mm:ss or m:ss): 15:57.80 [After] Percent of CPU this job got: 258% Elapsed (wall clock) time (h:mm:ss or m:ss): 6:15.34 Change-Id: I2dc9ada91ea773f1daeb1a4e7e101f25fb03be07 Signed-off-by: Juhyung Park --- aosp/ota_extractor.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/aosp/ota_extractor.cc b/aosp/ota_extractor.cc index 059267f9..82d8f5d4 100644 --- a/aosp/ota_extractor.cc +++ b/aosp/ota_extractor.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -197,9 +198,17 @@ bool ExtractImagesFromOTA(const DeltaArchiveManifest& manifest, const size_t data_begin = metadata.GetMetadataSize() + metadata.GetMetadataSignatureSize() + payload_offset; + std::vector> futures; + for (const auto& partition : manifest.partitions()) { - ExtractImageFromPartitions(manifest, partition, data_begin, payload_fd, - input_dir, output_dir, partitions); + futures.push_back( + std::async(std::launch::async, + ExtractImageFromPartitions, manifest, partition, data_begin, payload_fd, + input_dir, output_dir, partitions) + ); + } + for (auto& fut : futures) { + fut.get(); } return true; }