Merge "fs_mgr: fix fs_mgr avb_keys parsing problem"
diff --git a/adb/benchmark_device.py b/adb/benchmark_device.py
index e56ef5a..4d0cf49 100755
--- a/adb/benchmark_device.py
+++ b/adb/benchmark_device.py
@@ -17,6 +17,8 @@
import os
import statistics
+import subprocess
+import tempfile
import time
import adb
@@ -56,6 +58,41 @@
msg = "%s: %d runs: median %.2f MiB/s, mean %.2f MiB/s, stddev: %.2f MiB/s"
print(msg % (name, len(speeds), median, mean, stddev))
+def benchmark_sink(device=None, size_mb=100):
+ if device == None:
+ device = adb.get_device()
+
+ speeds = list()
+ cmd = device.adb_cmd + ["raw", "sink:%d" % (size_mb * 1024 * 1024)]
+
+ with tempfile.TemporaryFile() as tmpfile:
+ tmpfile.truncate(size_mb * 1024 * 1024)
+
+ for _ in range(0, 10):
+ tmpfile.seek(0)
+ begin = time.time()
+ subprocess.check_call(cmd, stdin=tmpfile)
+ end = time.time()
+ speeds.append(size_mb / float(end - begin))
+
+ analyze("sink %dMiB" % size_mb, speeds)
+
+def benchmark_source(device=None, size_mb=100):
+ if device == None:
+ device = adb.get_device()
+
+ speeds = list()
+ cmd = device.adb_cmd + ["raw", "source:%d" % (size_mb * 1024 * 1024)]
+
+ with open(os.devnull, 'w') as devnull:
+ for _ in range(0, 10):
+ begin = time.time()
+ subprocess.check_call(cmd, stdout=devnull)
+ end = time.time()
+ speeds.append(size_mb / float(end - begin))
+
+ analyze("source %dMiB" % size_mb, speeds)
+
def benchmark_push(device=None, file_size_mb=100):
if device == None:
device = adb.get_device()
@@ -110,6 +147,8 @@
def main():
device = adb.get_device()
unlock(device)
+ benchmark_sink(device)
+ benchmark_source(device)
benchmark_push(device)
benchmark_pull(device)
diff --git a/adb/daemon/usb.cpp b/adb/daemon/usb.cpp
index f0e2861..598f2cd 100644
--- a/adb/daemon/usb.cpp
+++ b/adb/daemon/usb.cpp
@@ -29,6 +29,7 @@
#include <linux/usb/functionfs.h>
#include <sys/eventfd.h>
+#include <algorithm>
#include <array>
#include <future>
#include <memory>
@@ -56,10 +57,11 @@
// We can't find out whether we have support for AIO on ffs endpoints until we submit a read.
static std::optional<bool> gFfsAioSupported;
-static constexpr size_t kUsbReadQueueDepth = 16;
-static constexpr size_t kUsbReadSize = 16384;
+static constexpr size_t kUsbReadQueueDepth = 32;
+static constexpr size_t kUsbReadSize = 8 * PAGE_SIZE;
-static constexpr size_t kUsbWriteQueueDepth = 16;
+static constexpr size_t kUsbWriteQueueDepth = 32;
+static constexpr size_t kUsbWriteSize = 8 * PAGE_SIZE;
static const char* to_string(enum usb_functionfs_event_type type) {
switch (type) {
@@ -115,7 +117,7 @@
struct IoBlock {
bool pending;
struct iocb control;
- Block payload;
+ std::shared_ptr<Block> payload;
TransferId id() const { return TransferId::from_value(control.aio_data); }
};
@@ -207,8 +209,20 @@
std::lock_guard<std::mutex> lock(write_mutex_);
write_requests_.push_back(CreateWriteBlock(std::move(header), next_write_id_++));
if (!packet->payload.empty()) {
- write_requests_.push_back(
- CreateWriteBlock(std::move(packet->payload), next_write_id_++));
+ // The kernel attempts to allocate a contiguous block of memory for each write,
+ // which can fail if the write is large and the kernel heap is fragmented.
+ // Split large writes into smaller chunks to avoid this.
+ std::shared_ptr<Block> payload = std::make_shared<Block>(std::move(packet->payload));
+ size_t offset = 0;
+ size_t len = payload->size();
+
+ while (len > 0) {
+ size_t write_size = std::min(kUsbWriteSize, len);
+ write_requests_.push_back(
+ CreateWriteBlock(payload, offset, write_size, next_write_id_++));
+ len -= write_size;
+ offset += write_size;
+ }
}
SubmitWrites();
return true;
@@ -246,7 +260,6 @@
// until it dies, and then report failure to the transport via HandleError, which will
// eventually result in the transport being destroyed, which will result in UsbFfsConnection
// being destroyed, which unblocks the open thread and restarts this entire process.
- static constexpr int kInterruptionSignal = SIGUSR1;
static std::once_flag handler_once;
std::call_once(handler_once, []() { signal(kInterruptionSignal, [](int) {}); });
@@ -272,6 +285,7 @@
} else if (rc == 0) {
// Something in the kernel presumably went wrong.
// Close our endpoints, wait for a bit, and then try again.
+ StopWorker();
aio_context_.reset();
read_fd_.reset();
write_fd_.reset();
@@ -297,7 +311,7 @@
switch (event.type) {
case FUNCTIONFS_BIND:
- CHECK(!started) << "received FUNCTIONFS_ENABLE while already bound?";
+ CHECK(!bound) << "received FUNCTIONFS_BIND while already bound?";
bound = true;
break;
@@ -313,28 +327,7 @@
}
}
- pthread_t worker_thread_handle = worker_thread_.native_handle();
- while (true) {
- int rc = pthread_kill(worker_thread_handle, kInterruptionSignal);
- if (rc != 0) {
- LOG(ERROR) << "failed to send interruption signal to worker: " << strerror(rc);
- break;
- }
-
- std::this_thread::sleep_for(100ms);
-
- rc = pthread_kill(worker_thread_handle, 0);
- if (rc == 0) {
- continue;
- } else if (rc == ESRCH) {
- break;
- } else {
- LOG(ERROR) << "failed to send interruption signal to worker: " << strerror(rc);
- }
- }
-
- worker_thread_.join();
-
+ StopWorker();
aio_context_.reset();
read_fd_.reset();
write_fd_.reset();
@@ -365,12 +358,36 @@
});
}
+ void StopWorker() {
+ pthread_t worker_thread_handle = worker_thread_.native_handle();
+ while (true) {
+ int rc = pthread_kill(worker_thread_handle, kInterruptionSignal);
+ if (rc != 0) {
+ LOG(ERROR) << "failed to send interruption signal to worker: " << strerror(rc);
+ break;
+ }
+
+ std::this_thread::sleep_for(100ms);
+
+ rc = pthread_kill(worker_thread_handle, 0);
+ if (rc == 0) {
+ continue;
+ } else if (rc == ESRCH) {
+ break;
+ } else {
+ LOG(ERROR) << "failed to send interruption signal to worker: " << strerror(rc);
+ }
+ }
+
+ worker_thread_.join();
+ }
+
void PrepareReadBlock(IoBlock* block, uint64_t id) {
block->pending = false;
- block->payload.resize(kUsbReadSize);
+ block->payload = std::make_shared<Block>(kUsbReadSize);
block->control.aio_data = static_cast<uint64_t>(TransferId::read(id));
- block->control.aio_buf = reinterpret_cast<uintptr_t>(block->payload.data());
- block->control.aio_nbytes = block->payload.size();
+ block->control.aio_buf = reinterpret_cast<uintptr_t>(block->payload->data());
+ block->control.aio_nbytes = block->payload->size();
}
IoBlock CreateReadBlock(uint64_t id) {
@@ -421,7 +438,7 @@
uint64_t read_idx = id.id % kUsbReadQueueDepth;
IoBlock* block = &read_requests_[read_idx];
block->pending = false;
- block->payload.resize(size);
+ block->payload->resize(size);
// Notification for completed reads can be received out of order.
if (block->id().id != needed_read_id_) {
@@ -442,16 +459,16 @@
}
void ProcessRead(IoBlock* block) {
- if (!block->payload.empty()) {
+ if (!block->payload->empty()) {
if (!incoming_header_.has_value()) {
- CHECK_EQ(sizeof(amessage), block->payload.size());
+ CHECK_EQ(sizeof(amessage), block->payload->size());
amessage msg;
- memcpy(&msg, block->payload.data(), sizeof(amessage));
+ memcpy(&msg, block->payload->data(), sizeof(amessage));
LOG(DEBUG) << "USB read:" << dump_header(&msg);
incoming_header_ = msg;
} else {
size_t bytes_left = incoming_header_->data_length - incoming_payload_.size();
- Block payload = std::move(block->payload);
+ Block payload = std::move(*block->payload);
CHECK_LE(payload.size(), bytes_left);
incoming_payload_.append(std::make_unique<Block>(std::move(payload)));
}
@@ -506,7 +523,8 @@
SubmitWrites();
}
- std::unique_ptr<IoBlock> CreateWriteBlock(Block payload, uint64_t id) {
+ std::unique_ptr<IoBlock> CreateWriteBlock(std::shared_ptr<Block> payload, size_t offset,
+ size_t len, uint64_t id) {
auto block = std::make_unique<IoBlock>();
block->payload = std::move(payload);
block->control.aio_data = static_cast<uint64_t>(TransferId::write(id));
@@ -514,14 +532,20 @@
block->control.aio_lio_opcode = IOCB_CMD_PWRITE;
block->control.aio_reqprio = 0;
block->control.aio_fildes = write_fd_.get();
- block->control.aio_buf = reinterpret_cast<uintptr_t>(block->payload.data());
- block->control.aio_nbytes = block->payload.size();
+ block->control.aio_buf = reinterpret_cast<uintptr_t>(block->payload->data() + offset);
+ block->control.aio_nbytes = len;
block->control.aio_offset = 0;
block->control.aio_flags = IOCB_FLAG_RESFD;
block->control.aio_resfd = worker_event_fd_.get();
return block;
}
+ std::unique_ptr<IoBlock> CreateWriteBlock(Block payload, uint64_t id) {
+ std::shared_ptr<Block> block = std::make_shared<Block>(std::move(payload));
+ size_t len = block->size();
+ return CreateWriteBlock(std::move(block), 0, len, id);
+ }
+
void SubmitWrites() REQUIRES(write_mutex_) {
if (writes_submitted_ == kUsbWriteQueueDepth) {
return;
@@ -594,6 +618,8 @@
std::deque<std::unique_ptr<IoBlock>> write_requests_ GUARDED_BY(write_mutex_);
size_t next_write_id_ GUARDED_BY(write_mutex_) = 0;
size_t writes_submitted_ GUARDED_BY(write_mutex_) = 0;
+
+ static constexpr int kInterruptionSignal = SIGUSR1;
};
void usb_init_legacy();
diff --git a/fastboot/fastboot_driver.cpp b/fastboot/fastboot_driver.cpp
index 65a5247..fea0a77 100644
--- a/fastboot/fastboot_driver.cpp
+++ b/fastboot/fastboot_driver.cpp
@@ -403,7 +403,7 @@
RetCode FastBootDriver::HandleResponse(std::string* response, std::vector<std::string>* info,
int* dsize) {
char status[FB_RESPONSE_SZ + 1];
- auto start = std::chrono::system_clock::now();
+ auto start = std::chrono::steady_clock::now();
auto set_response = [response](std::string s) {
if (response) *response = std::move(s);
@@ -414,7 +414,7 @@
// erase response
set_response("");
- while ((std::chrono::system_clock::now() - start) < std::chrono::seconds(RESP_TIMEOUT)) {
+ while ((std::chrono::steady_clock::now() - start) < std::chrono::seconds(RESP_TIMEOUT)) {
int r = transport_->Read(status, FB_RESPONSE_SZ);
if (r < 0) {
error_ = ErrnoStr("Status read failed");
@@ -427,6 +427,11 @@
std::string tmp = input.substr(strlen("INFO"));
info_(tmp);
add_info(std::move(tmp));
+ // We may receive one or more INFO packets during long operations,
+ // e.g. flash/erase if they are back by slow media like NAND/NOR
+ // flash. In that case, reset the timer since it's not a real
+ // timeout.
+ start = std::chrono::steady_clock::now();
} else if (android::base::StartsWith(input, "OKAY")) {
set_response(input.substr(strlen("OKAY")));
return SUCCESS;
diff --git a/fs_mgr/libfs_avb/avb_util.cpp b/fs_mgr/libfs_avb/avb_util.cpp
index 7d89902..f4e4d4e 100644
--- a/fs_mgr/libfs_avb/avb_util.cpp
+++ b/fs_mgr/libfs_avb/avb_util.cpp
@@ -326,7 +326,7 @@
return false;
}
-bool ValidatePublicKeyBlob(const std::string key_blob_to_validate,
+bool ValidatePublicKeyBlob(const std::string& key_blob_to_validate,
const std::vector<std::string>& allowed_key_paths) {
std::string allowed_key_blob;
if (key_blob_to_validate.empty()) {
diff --git a/fs_mgr/libfs_avb/avb_util.h b/fs_mgr/libfs_avb/avb_util.h
index 986a69a..09c786a 100644
--- a/fs_mgr/libfs_avb/avb_util.h
+++ b/fs_mgr/libfs_avb/avb_util.h
@@ -80,7 +80,7 @@
bool ValidatePublicKeyBlob(const uint8_t* key, size_t length, const std::string& expected_key_blob);
-bool ValidatePublicKeyBlob(const std::string key_blob_to_validate,
+bool ValidatePublicKeyBlob(const std::string& key_blob_to_validate,
const std::vector<std::string>& expected_key_paths);
// Detects if whether a partition contains a rollback image.
diff --git a/libprocessgroup/profiles/task_profiles.json b/libprocessgroup/profiles/task_profiles.json
index 985720f..74a39cd 100644
--- a/libprocessgroup/profiles/task_profiles.json
+++ b/libprocessgroup/profiles/task_profiles.json
@@ -56,10 +56,10 @@
"Profiles": [
{
"Name": "HighEnergySaving",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "schedtune",
"Path": "background"
@@ -69,10 +69,10 @@
},
{
"Name": "NormalPerformance",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "schedtune",
"Path": ""
@@ -82,10 +82,10 @@
},
{
"Name": "HighPerformance",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "schedtune",
"Path": "foreground"
@@ -95,10 +95,10 @@
},
{
"Name": "MaxPerformance",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "schedtune",
"Path": "top-app"
@@ -108,10 +108,10 @@
},
{
"Name": "RealtimePerformance",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "schedtune",
"Path": "rt"
@@ -122,26 +122,26 @@
{
"Name": "CpuPolicySpread",
- "Actions" : [
+ "Actions": [
{
- "Name" : "SetAttribute",
- "Params" :
+ "Name": "SetAttribute",
+ "Params":
{
- "Name" : "STunePreferIdle",
- "Value" : "1"
+ "Name": "STunePreferIdle",
+ "Value": "1"
}
}
]
},
{
"Name": "CpuPolicyPack",
- "Actions" : [
+ "Actions": [
{
- "Name" : "SetAttribute",
- "Params" :
+ "Name": "SetAttribute",
+ "Params":
{
- "Name" : "STunePreferIdle",
- "Value" : "0"
+ "Name": "STunePreferIdle",
+ "Value": "0"
}
}
]
@@ -149,10 +149,10 @@
{
"Name": "VrKernelCapacity",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": ""
@@ -162,10 +162,10 @@
},
{
"Name": "VrServiceCapacityLow",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": "system/background"
@@ -175,10 +175,10 @@
},
{
"Name": "VrServiceCapacityNormal",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": "system"
@@ -188,10 +188,10 @@
},
{
"Name": "VrServiceCapacityHigh",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": "system/performance"
@@ -201,10 +201,10 @@
},
{
"Name": "VrProcessCapacityLow",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": "application/background"
@@ -214,10 +214,10 @@
},
{
"Name": "VrProcessCapacityNormal",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": "application"
@@ -227,10 +227,10 @@
},
{
"Name": "VrProcessCapacityHigh",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": "application/performance"
@@ -241,10 +241,10 @@
{
"Name": "ProcessCapacityLow",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": "background"
@@ -254,10 +254,10 @@
},
{
"Name": "ProcessCapacityNormal",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": ""
@@ -267,10 +267,10 @@
},
{
"Name": "ProcessCapacityHigh",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": "foreground"
@@ -280,10 +280,10 @@
},
{
"Name": "ProcessCapacityMax",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": "top-app"
@@ -294,10 +294,10 @@
{
"Name": "ServiceCapacityLow",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": "system-background"
@@ -307,10 +307,10 @@
},
{
"Name": "ServiceCapacityRestricted",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": "restricted"
@@ -321,10 +321,10 @@
{
"Name": "CameraServiceCapacity",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "cpuset",
"Path": "camera-daemon"
@@ -335,10 +335,10 @@
{
"Name": "LowIoPriority",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "blkio",
"Path": "background"
@@ -348,10 +348,10 @@
},
{
"Name": "NormalIoPriority",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "blkio",
"Path": ""
@@ -361,10 +361,10 @@
},
{
"Name": "HighIoPriority",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "blkio",
"Path": ""
@@ -374,10 +374,10 @@
},
{
"Name": "MaxIoPriority",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "blkio",
"Path": ""
@@ -388,10 +388,10 @@
{
"Name": "TimerSlackHigh",
- "Actions" : [
+ "Actions": [
{
- "Name" : "SetTimerSlack",
- "Params" :
+ "Name": "SetTimerSlack",
+ "Params":
{
"Slack": "40000000"
}
@@ -400,10 +400,10 @@
},
{
"Name": "TimerSlackNormal",
- "Actions" : [
+ "Actions": [
{
- "Name" : "SetTimerSlack",
- "Params" :
+ "Name": "SetTimerSlack",
+ "Params":
{
"Slack": "50000"
}
@@ -413,26 +413,26 @@
{
"Name": "PerfBoost",
- "Actions" : [
+ "Actions": [
{
- "Name" : "SetClamps",
- "Params" :
+ "Name": "SetClamps",
+ "Params":
{
- "Boost" : "50%",
- "Clamp" : "0"
+ "Boost": "50%",
+ "Clamp": "0"
}
}
]
},
{
"Name": "PerfClamp",
- "Actions" : [
+ "Actions": [
{
- "Name" : "SetClamps",
- "Params" :
+ "Name": "SetClamps",
+ "Params":
{
- "Boost" : "0",
- "Clamp" : "30%"
+ "Boost": "0",
+ "Clamp": "30%"
}
}
]
@@ -440,21 +440,21 @@
{
"Name": "LowMemoryUsage",
- "Actions" : [
+ "Actions": [
{
- "Name" : "SetAttribute",
- "Params" :
+ "Name": "SetAttribute",
+ "Params":
{
- "Name" : "MemSoftLimit",
- "Value" : "16MB"
+ "Name": "MemSoftLimit",
+ "Value": "16MB"
}
},
{
- "Name" : "SetAttribute",
- "Params" :
+ "Name": "SetAttribute",
+ "Params":
{
- "Name" : "MemSwappiness",
- "Value" : "150"
+ "Name": "MemSwappiness",
+ "Value": "150"
}
}
@@ -462,31 +462,31 @@
},
{
"Name": "HighMemoryUsage",
- "Actions" : [
+ "Actions": [
{
- "Name" : "SetAttribute",
- "Params" :
+ "Name": "SetAttribute",
+ "Params":
{
- "Name" : "MemSoftLimit",
- "Value" : "512MB"
+ "Name": "MemSoftLimit",
+ "Value": "512MB"
}
},
{
- "Name" : "SetAttribute",
- "Params" :
+ "Name": "SetAttribute",
+ "Params":
{
- "Name" : "MemSwappiness",
- "Value" : "100"
+ "Name": "MemSwappiness",
+ "Value": "100"
}
}
]
},
{
"Name": "SystemMemoryProcess",
- "Actions" : [
+ "Actions": [
{
- "Name" : "JoinCgroup",
- "Params" :
+ "Name": "JoinCgroup",
+ "Params":
{
"Controller": "memory",
"Path": "system"