binderRpcBenchmark: test more data sizes
Data on Pixel 3.
Tests suffixes:
.../0 is KERNEL
.../1 is RPC
...
------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
------------------------------------------------------------------------------------
BM_pingTransaction/0 34506 ns 15936 ns 44173
BM_pingTransaction/1 44578 ns 23682 ns 29419
BM_repeatTwoPageString/0 268895 ns 133951 ns 5542
BM_repeatTwoPageString/1 273066 ns 136871 ns 4060
BM_throughputForTransportAndBytes/0/64 41647 ns 20978 ns 31161
BM_throughputForTransportAndBytes/1/64 50865 ns 26653 ns 27674
BM_throughputForTransportAndBytes/0/1024 45359 ns 22866 ns 36708
BM_throughputForTransportAndBytes/1/1024 58353 ns 30732 ns 24405
BM_throughputForTransportAndBytes/0/2048 42337 ns 21340 ns 31918
BM_throughputForTransportAndBytes/1/2048 54608 ns 28429 ns 26312
BM_throughputForTransportAndBytes/0/4096 48556 ns 24274 ns 36713
BM_throughputForTransportAndBytes/1/4096 63926 ns 33302 ns 21678
BM_throughputForTransportAndBytes/0/8182 61992 ns 30967 ns 31588
BM_throughputForTransportAndBytes/1/8182 76709 ns 39386 ns 16124
BM_throughputForTransportAndBytes/0/16364 59111 ns 27146 ns 21538
BM_throughputForTransportAndBytes/1/16364 99768 ns 51025 ns 14223
BM_throughputForTransportAndBytes/0/32728 81425 ns 36794 ns 19077
BM_throughputForTransportAndBytes/1/32728 145483 ns 69133 ns 10000
BM_throughputForTransportAndBytes/0/65535 250483 ns 121279 ns 5994
BM_throughputForTransportAndBytes/1/65535 436443 ns 210857 ns 4502
BM_throughputForTransportAndBytes/0/65536 242461 ns 117834 ns 9015
BM_throughputForTransportAndBytes/1/65536 412841 ns 199778 ns 3333
BM_throughputForTransportAndBytes/0/65537 348937 ns 158662 ns 5700
BM_throughputForTransportAndBytes/1/65537 485328 ns 219897 ns 3345
BM_repeatBinder/0 149947 ns 81256 ns 7093
BM_repeatBinder/1 142770 ns 77031 ns 7460
Future considerations:
- what about other socket types (not UDS)
- control for binder scheduling hints
- more optimizations in libbinder
Bug: 182940634
Test: binderRpcBenchmark (results above)
Change-Id: I0db9a95d9336b6f943da9efe59ef7736a65f90e4
diff --git a/libs/binder/tests/binderRpcBenchmark.cpp b/libs/binder/tests/binderRpcBenchmark.cpp
index 5f4a7b5..aeda03b 100644
--- a/libs/binder/tests/binderRpcBenchmark.cpp
+++ b/libs/binder/tests/binderRpcBenchmark.cpp
@@ -50,8 +50,12 @@
*out = str;
return Status::ok();
}
- Status repeatBinder(const sp<IBinder>& str, sp<IBinder>* out) override {
- *out = str;
+ Status repeatBinder(const sp<IBinder>& binder, sp<IBinder>* out) override {
+ *out = binder;
+ return Status::ok();
+ }
+ Status repeatBytes(const std::vector<uint8_t>& bytes, std::vector<uint8_t>* out) override {
+ *out = bytes;
return Status::ok();
}
};
@@ -61,12 +65,11 @@
RPC,
};
-static void EachTransport(benchmark::internal::Benchmark* b) {
+static const std::initializer_list<int64_t> kTransportList = {
#ifdef __BIONIC__
- b->Args({Transport::KERNEL});
+ Transport::KERNEL,
#endif
- b->Args({Transport::RPC});
-}
+ Transport::RPC};
static sp<RpcSession> gSession = RpcSession::make();
#ifdef __BIONIC__
@@ -96,9 +99,9 @@
CHECK_EQ(OK, binder->pingBinder());
}
}
-BENCHMARK(BM_pingTransaction)->Apply(EachTransport);
+BENCHMARK(BM_pingTransaction)->ArgsProduct({kTransportList});
-void BM_repeatString(benchmark::State& state) {
+void BM_repeatTwoPageString(benchmark::State& state) {
sp<IBinder> binder = getBinderForOptions(state);
sp<IBinderRpcBenchmark> iface = interface_cast<IBinderRpcBenchmark>(binder);
@@ -125,7 +128,27 @@
CHECK(ret.isOk()) << ret;
}
}
-BENCHMARK(BM_repeatString)->Apply(EachTransport);
+BENCHMARK(BM_repeatTwoPageString)->ArgsProduct({kTransportList});
+
+void BM_throughputForTransportAndBytes(benchmark::State& state) {
+ sp<IBinder> binder = getBinderForOptions(state);
+ sp<IBinderRpcBenchmark> iface = interface_cast<IBinderRpcBenchmark>(binder);
+ CHECK(iface != nullptr);
+
+ std::vector<uint8_t> bytes = std::vector<uint8_t>(state.range(1));
+ for (size_t i = 0; i < bytes.size(); i++) {
+ bytes[i] = i % 256;
+ }
+
+ while (state.KeepRunning()) {
+ std::vector<uint8_t> out;
+ Status ret = iface->repeatBytes(bytes, &out);
+ CHECK(ret.isOk()) << ret;
+ }
+}
+BENCHMARK(BM_throughputForTransportAndBytes)
+ ->ArgsProduct({kTransportList,
+ {64, 1024, 2048, 4096, 8182, 16364, 32728, 65535, 65536, 65537}});
void BM_repeatBinder(benchmark::State& state) {
sp<IBinder> binder = gSession->getRootObject();
@@ -142,7 +165,7 @@
CHECK(ret.isOk()) << ret;
}
}
-BENCHMARK(BM_repeatBinder)->Apply(EachTransport);
+BENCHMARK(BM_repeatBinder)->ArgsProduct({kTransportList});
int main(int argc, char** argv) {
::benchmark::Initialize(&argc, argv);
@@ -152,8 +175,8 @@
(void)unlink(addr.c_str());
std::cerr << "Tests suffixes:" << std::endl;
- std::cerr << "\t\\" << Transport::KERNEL << " is KERNEL" << std::endl;
- std::cerr << "\t\\" << Transport::RPC << " is RPC" << std::endl;
+ std::cerr << "\t.../" << Transport::KERNEL << " is KERNEL" << std::endl;
+ std::cerr << "\t.../" << Transport::RPC << " is RPC" << std::endl;
if (0 == fork()) {
prctl(PR_SET_PDEATHSIG, SIGHUP); // racey, okay