From fa698123dc22fba09054c8869341da314919831a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 18 Sep 2019 22:58:21 -0700 Subject: [PATCH] modules/console: Add bare metal latency as control result. --- modules/console.cc | 113 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 96 insertions(+), 17 deletions(-) diff --git a/modules/console.cc b/modules/console.cc index 7fc5fb030..725f0685d 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -1352,20 +1352,69 @@ console_cmd__ios(opt &out, const string_view &line) return true; } +#ifdef __x86_64__ bool console_cmd__ios__latency(opt &out, const string_view &line) { - auto returned(0UL); - auto executed(0UL); - auto started(0UL); + volatile long long returned, executed, started; + + // control + { + __sync_synchronize(); + asm volatile ("lfence" :::); + started = prof::cycles(); + asm volatile ("lfence" :::); + executed = prof::cycles(); + asm volatile ("lfence" :::); + returned = prof::cycles(); + asm volatile ("lfence" :::); + } + + out + << "bare send: " << (executed - started) << std::endl + << "bare recv: " << (returned - executed) << std::endl + << "bare rtt: " << (returned - started) << std::endl + << std::endl; + + // control + { + __sync_synchronize(); + started = prof::x86::rdtscp(); + asm volatile ("lfence" :::); + executed = prof::x86::rdtscp(); + asm volatile ("lfence" :::); + returned = prof::x86::rdtscp(); + asm volatile ("lfence" :::); + } + + out + << "tscp send: " << (executed - started) << std::endl + << "tscp recv: " << (returned - executed) << std::endl + << "tscp rtt: " << (returned - started) << std::endl + << std::endl; + + // + // ios::dispatch + // { + __sync_synchronize(); + asm volatile ("lfence" :::); started = prof::cycles(); + asm volatile ("lfence" :::); + ios::dispatch(ios::synchronous, [&executed] { + __sync_synchronize(); + asm volatile ("lfence" :::); executed = prof::cycles(); + asm volatile ("lfence" :::); }); + + __sync_synchronize(); + asm volatile ("lfence" :::); returned = prof::cycles(); + asm volatile ("lfence" :::); } out @@ -1374,28 +1423,28 @@ console_cmd__ios__latency(opt &out, const string_view &line) << "disp rtt: " << (returned - started) << std::endl << std::endl; - { - started = prof::cycles(); - ios::post(ios::synchronous, [&executed] - { - executed = prof::cycles(); - }); - returned = prof::cycles(); - } - - out - << "post send: " << (executed - started) << std::endl - << "post recv: " << (returned - executed) << std::endl - << "post rtt: " << (returned - started) << std::endl - << std::endl; + // + // ios::defer + // { + __sync_synchronize(); + asm volatile ("lfence" :::); started = prof::cycles(); + asm volatile ("lfence" :::); + ios::defer(ios::synchronous, [&executed] { + __sync_synchronize(); + asm volatile ("lfence" :::); executed = prof::cycles(); + asm volatile ("lfence" :::); }); + + __sync_synchronize(); + asm volatile ("lfence" :::); returned = prof::cycles(); + asm volatile ("lfence" :::); } out @@ -1404,9 +1453,39 @@ console_cmd__ios__latency(opt &out, const string_view &line) << "defer rtt: " << (returned - started) << std::endl << std::endl; + // + // ios::post + // + + { + __sync_synchronize(); + asm volatile ("lfence" :::); + started = prof::cycles(); + asm volatile ("lfence" :::); + + ios::post(ios::synchronous, [&executed] + { + __sync_synchronize(); + asm volatile ("lfence" :::); + executed = prof::cycles(); + asm volatile ("lfence" :::); + }); + + __sync_synchronize(); + asm volatile ("lfence" :::); + returned = prof::cycles(); + asm volatile ("lfence" :::); + } + + out + << "post send: " << (executed - started) << std::endl + << "post recv: " << (returned - executed) << std::endl + << "post rtt: " << (returned - started) << std::endl + << std::endl; return true; } +#endif // // aio