1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /* Copyright (c) 2015 Haomai Wang <haomaiwang@gmail.com>
4 * Copyright (c) 2011-2014 Stanford University
5 * Copyright (c) 2011 Facebook
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 // This program contains a collection of low-level performance measurements
21 // for Ceph, which can be run either individually or altogether. These
22 // tests measure performance in a single stand-alone process, not in a cluster
23 // with multiple servers. Invoke the program like this:
25 // Perf test1 test2 ...
27 // test1 and test2 are the names of individual performance measurements to
28 // run. If no test names are provided then all of the performance tests
32 // * Write a function that implements the test. Use existing test functions
33 // as a guideline, and be sure to generate output in the same form as
35 // * Create a new entry for the test in the #tests table.
41 #include <xmmintrin.h>
44 #include "include/buffer.h"
45 #include "include/encoding.h"
46 #include "include/ceph_hash.h"
47 #include "include/Spinlock.h"
48 #include "common/ceph_argparse.h"
49 #include "common/Cycles.h"
50 #include "common/Cond.h"
51 #include "common/Mutex.h"
52 #include "common/Thread.h"
53 #include "common/Timer.h"
54 #include "msg/async/Event.h"
55 #include "global/global_init.h"
57 #include "test/perf_helper.h"
64 * Ask the operating system to pin the current thread to a given CPU.
67 * Indicates the desired CPU and hyperthread; low order 2 bits
68 * specify CPU, next bit specifies hyperthread.
70 void bind_thread_to_cpu(int cpu)
76 sched_setaffinity(0, sizeof(set), &set);
81 * This function just discards its argument. It's used to make it
82 * appear that data is used, so that the compiler won't optimize
83 * away the code we're trying to measure.
86 * Pointer to arbitrary value; it's discarded.
88 void discard(void* value) {
89 int x = *reinterpret_cast<int*>(value);
90 if (x == 0x43924776) {
91 printf("Value was 0x%x\n", x);
95 //----------------------------------------------------------------------
96 // Test functions start here
97 //----------------------------------------------------------------------
99 // Measure the cost of atomic compare-and-swap
100 double atomic_int_cmp()
103 std::atomic<unsigned> value = { 11 };
104 unsigned int test = 11;
105 uint64_t start = Cycles::rdtsc();
106 for (int i = 0; i < count; i++) {
107 value.compare_exchange_strong(test, test+2);
110 uint64_t stop = Cycles::rdtsc();
111 // printf("Final value: %d\n", value.load());
112 return Cycles::to_seconds(stop - start)/count;
115 // Measure the cost of incrementing an atomic
116 double atomic_int_inc()
119 std::atomic<int64_t> value = { 11 };
120 uint64_t start = Cycles::rdtsc();
121 for (int i = 0; i < count; i++) {
124 uint64_t stop = Cycles::rdtsc();
125 // printf("Final value: %d\n", value.load());
126 return Cycles::to_seconds(stop - start)/count;
129 // Measure the cost of reading an atomic
130 double atomic_int_read()
133 std::atomic<int64_t> value = { 11 };
135 uint64_t start = Cycles::rdtsc();
136 for (int i = 0; i < count; i++) {
139 uint64_t stop = Cycles::rdtsc();
140 // printf("Total: %d\n", total);
141 return Cycles::to_seconds(stop - start)/count;
144 // Measure the cost of storing a new value in an atomic
145 double atomic_int_set()
148 std::atomic<int64_t> value = { 11 };
149 uint64_t start = Cycles::rdtsc();
150 for (int i = 0; i < count; i++) {
153 uint64_t stop = Cycles::rdtsc();
154 return Cycles::to_seconds(stop - start)/count;
157 // Measure the cost of acquiring and releasing a mutex in the
158 // fast case where the mutex is free.
159 double mutex_nonblock()
162 Mutex m("mutex_nonblock::m");
163 uint64_t start = Cycles::rdtsc();
164 for (int i = 0; i < count; i++) {
168 uint64_t stop = Cycles::rdtsc();
169 return Cycles::to_seconds(stop - start)/count;
172 // Measure the cost of allocating and deallocating a buffer, plus
173 // appending (logically) one ptr.
174 double buffer_basic()
177 uint64_t start = Cycles::rdtsc();
178 bufferptr ptr("abcdefg", 7);
179 for (int i = 0; i < count; i++) {
183 uint64_t stop = Cycles::rdtsc();
184 return Cycles::to_seconds(stop - start)/count;
188 int a = 1, b = 2, c = 3, d = 4;
189 void encode(bufferlist &bl) const {
190 ENCODE_START(1, 1, bl);
197 void decode(bufferlist::iterator &bl) {
206 WRITE_CLASS_ENCODER(DummyBlock)
208 // Measure the cost of encoding and decoding a buffer, plus
209 // allocating space for one chunk.
210 double buffer_encode_decode()
213 uint64_t start = Cycles::rdtsc();
214 for (int i = 0; i < count; i++) {
216 DummyBlock dummy_block;
217 ::encode(dummy_block, b);
218 bufferlist::iterator iter = b.begin();
219 ::decode(dummy_block, iter);
221 uint64_t stop = Cycles::rdtsc();
222 return Cycles::to_seconds(stop - start)/count;
225 // Measure the cost of allocating and deallocating a buffer, plus
226 // copying in a small block.
227 double buffer_basic_copy()
230 uint64_t start = Cycles::rdtsc();
231 for (int i = 0; i < count; i++) {
233 b.append("abcdefg", 6);
235 uint64_t stop = Cycles::rdtsc();
236 return Cycles::to_seconds(stop - start)/count;
239 // Measure the cost of making a copy of parts of two ptrs.
244 b.append("abcde", 5);
245 b.append("01234", 5);
247 uint64_t start = Cycles::rdtsc();
248 for (int i = 0; i < count; i++) {
251 uint64_t stop = Cycles::rdtsc();
252 return Cycles::to_seconds(stop - start)/count;
255 // Measure the cost of allocating new space by extending the
257 double buffer_encode()
261 for (int i = 0; i < count; i++) {
263 DummyBlock dummy_block;
264 ::encode(dummy_block, b);
265 uint64_t start = Cycles::rdtsc();
266 ::encode(dummy_block, b);
267 ::encode(dummy_block, b);
268 ::encode(dummy_block, b);
269 ::encode(dummy_block, b);
270 ::encode(dummy_block, b);
271 ::encode(dummy_block, b);
272 ::encode(dummy_block, b);
273 ::encode(dummy_block, b);
274 ::encode(dummy_block, b);
275 ::encode(dummy_block, b);
276 total += Cycles::rdtsc() - start;
278 return Cycles::to_seconds(total)/(count*10);
281 // Measure the cost of retrieving an object from the beginning of a buffer.
282 double buffer_get_contiguous()
287 b.append((char*)&value, sizeof(value));
289 uint64_t start = Cycles::rdtsc();
290 for (int i = 0; i < count; i++) {
291 sum += *reinterpret_cast<int*>(b.get_contiguous(0, sizeof(value)));
293 uint64_t stop = Cycles::rdtsc();
294 return Cycles::to_seconds(stop - start)/count;
297 // Measure the cost of creating an iterator and iterating over 10
298 // chunks in a buffer.
299 double buffer_iterator()
302 const char s[] = "abcdefghijklmnopqrstuvwxyz";
303 bufferptr ptr(s, sizeof(s));
304 for (int i = 0; i < 5; i++) {
309 uint64_t start = Cycles::rdtsc();
310 for (int i = 0; i < count; i++) {
311 bufferlist::iterator it = b.begin();
313 sum += (static_cast<const char*>(it.get_current_ptr().c_str()))[it.get_remaining()-1];
317 uint64_t stop = Cycles::rdtsc();
319 return Cycles::to_seconds(stop - start)/count;
322 // Implements the CondPingPong test.
330 class Consumer : public Thread {
333 explicit Consumer(CondPingPong *p): p(p) {}
334 void* entry() override {
341 CondPingPong(): mutex("CondPingPong::mutex"), prod(0), cons(0), count(10000), consumer(this) {}
344 consumer.create("consumer");
345 uint64_t start = Cycles::rdtsc();
347 uint64_t stop = Cycles::rdtsc();
349 return Cycles::to_seconds(stop - start)/count;
353 Mutex::Locker l(mutex);
354 while (cons < count) {
363 Mutex::Locker l(mutex);
364 while (cons < count) {
373 // Measure the cost of coordinating between threads using a condition variable.
374 double cond_ping_pong()
376 return CondPingPong().run();
379 // Measure the cost of a 32-bit divide. Divides don't take a constant
380 // number of cycles. Values were chosen here semi-randomly to depict a
381 // fairly expensive scenario. Someone with fancy ALU knowledge could
382 // probably pick worse values.
385 #if defined(__i386__) || defined(__x86_64__)
387 uint64_t start = Cycles::rdtsc();
388 // NB: Expect an x86 processor exception is there's overflow.
389 uint32_t numeratorHi = 0xa5a5a5a5U;
390 uint32_t numeratorLo = 0x55aa55aaU;
391 uint32_t divisor = 0xaa55aa55U;
394 for (int i = 0; i < count; i++) {
395 __asm__ __volatile__("div %4" :
396 "=a"(quotient), "=d"(remainder) :
397 "a"(numeratorLo), "d"(numeratorHi), "r"(divisor) :
400 uint64_t stop = Cycles::rdtsc();
401 return Cycles::to_seconds(stop - start)/count;
407 // Measure the cost of a 64-bit divide. Divides don't take a constant
408 // number of cycles. Values were chosen here semi-randomly to depict a
409 // fairly expensive scenario. Someone with fancy ALU knowledge could
410 // probably pick worse values.
413 #if defined(__x86_64__) || defined(__amd64__)
415 // NB: Expect an x86 processor exception is there's overflow.
416 uint64_t start = Cycles::rdtsc();
417 uint64_t numeratorHi = 0x5a5a5a5a5a5UL;
418 uint64_t numeratorLo = 0x55aa55aa55aa55aaUL;
419 uint64_t divisor = 0xaa55aa55aa55aa55UL;
422 for (int i = 0; i < count; i++) {
423 __asm__ __volatile__("divq %4" :
424 "=a"(quotient), "=d"(remainder) :
425 "a"(numeratorLo), "d"(numeratorHi), "r"(divisor) :
428 uint64_t stop = Cycles::rdtsc();
429 return Cycles::to_seconds(stop - start)/count;
435 // Measure the cost of calling a non-inlined function.
436 double function_call()
440 uint64_t start = Cycles::rdtsc();
441 for (int i = 0; i < count; i++) {
442 x = PerfHelper::plus_one(x);
444 uint64_t stop = Cycles::rdtsc();
445 return Cycles::to_seconds(stop - start)/count;
448 // Measure the minimum cost of EventCenter::process_events, when there are no
449 // Pollers and no Timers.
450 double eventcenter_poll()
453 EventCenter center(g_ceph_context);
454 center.init(1000, 0, "posix");
456 uint64_t start = Cycles::rdtsc();
457 for (int i = 0; i < count; i++) {
458 center.process_events(0);
460 uint64_t stop = Cycles::rdtsc();
461 return Cycles::to_seconds(stop - start)/count;
464 class CenterWorker : public Thread {
470 explicit CenterWorker(CephContext *c): cct(c), done(false), center(c) {
471 center.init(100, 0, "posix");
477 void* entry() override {
479 bind_thread_to_cpu(2);
481 center.process_events(1000);
486 class CountEvent: public EventCallback {
487 std::atomic<int64_t> *count;
490 explicit CountEvent(std::atomic<int64_t> *atomic): count(atomic) {}
491 void do_request(int id) override {
496 double eventcenter_dispatch()
500 CenterWorker worker(g_ceph_context);
501 std::atomic<int64_t> flag = { 1 };
502 worker.create("evt_center_disp");
503 EventCallbackRef count_event(new CountEvent(&flag));
505 worker.center.dispatch_event_external(count_event);
506 // Start a new thread and wait for it to ready.
510 uint64_t start = Cycles::rdtsc();
511 for (int i = 0; i < count; i++) {
513 worker.center.dispatch_event_external(count_event);
517 uint64_t stop = Cycles::rdtsc();
520 return Cycles::to_seconds(stop - start)/count;
523 // Measure the cost of copying a given number of bytes with memcpy.
524 double memcpy_shared(size_t size)
527 char src[size], dst[size];
529 memset(src, 0, sizeof(src));
531 uint64_t start = Cycles::rdtsc();
532 for (int i = 0; i < count; i++) {
533 memcpy(dst, src, size);
535 uint64_t stop = Cycles::rdtsc();
536 return Cycles::to_seconds(stop - start)/count;
541 return memcpy_shared(100);
546 return memcpy_shared(1000);
551 return memcpy_shared(10000);
554 // Benchmark rjenkins hashing performance on cached data.
555 template <int key_length>
556 double ceph_str_hash_rjenkins()
559 char buf[key_length];
561 uint64_t start = Cycles::rdtsc();
562 for (int i = 0; i < count; i++)
563 ceph_str_hash(CEPH_STR_HASH_RJENKINS, buf, sizeof(buf));
564 uint64_t stop = Cycles::rdtsc();
566 return Cycles::to_seconds(stop - start)/count;
569 // Measure the cost of reading the fine-grain cycle counter.
573 uint64_t start = Cycles::rdtsc();
575 for (int i = 0; i < count; i++) {
576 total += Cycles::rdtsc();
578 uint64_t stop = Cycles::rdtsc();
579 return Cycles::to_seconds(stop - start)/count;
582 // Measure the cost of the Cycles::to_seconds method.
583 double perf_cycles_to_seconds()
587 uint64_t cycles = 994261;
588 uint64_t start = Cycles::rdtsc();
589 for (int i = 0; i < count; i++) {
590 total += Cycles::to_seconds(cycles);
592 uint64_t stop = Cycles::rdtsc();
593 // printf("Result: %.4f\n", total/count);
594 return Cycles::to_seconds(stop - start)/count;
597 // Measure the cost of the Cylcles::toNanoseconds method.
598 double perf_cycles_to_nanoseconds()
602 uint64_t cycles = 994261;
603 uint64_t start = Cycles::rdtsc();
604 for (int i = 0; i < count; i++) {
605 total += Cycles::to_nanoseconds(cycles);
607 uint64_t stop = Cycles::rdtsc();
608 // printf("Result: %lu\n", total/count);
609 return Cycles::to_seconds(stop - start)/count;
615 * Prefetch the cache lines containing [object, object + numBytes) into the
616 * processor's caches.
617 * The best docs for this are in the Intel instruction set reference under
620 * The start of the region of memory to prefetch.
622 * The size of the region of memory to prefetch.
624 static inline void prefetch(const void *object, uint64_t num_bytes)
626 uint64_t offset = reinterpret_cast<uint64_t>(object) & 0x3fUL;
627 const char* p = reinterpret_cast<const char*>(object) - offset;
628 for (uint64_t i = 0; i < offset + num_bytes; i += 64)
629 _mm_prefetch(p + i, _MM_HINT_T0);
633 // Measure the cost of the prefetch instruction.
634 double perf_prefetch()
637 uint64_t total_ticks = 0;
640 uint64_t start, stop;
642 for (int i = 0; i < count; i++) {
643 PerfHelper::flush_cache();
644 start = Cycles::rdtsc();
645 prefetch(&buf[576], 64);
646 prefetch(&buf[0], 64);
647 prefetch(&buf[512], 64);
648 prefetch(&buf[960], 64);
649 prefetch(&buf[640], 64);
650 prefetch(&buf[896], 64);
651 prefetch(&buf[256], 64);
652 prefetch(&buf[704], 64);
653 prefetch(&buf[320], 64);
654 prefetch(&buf[384], 64);
655 prefetch(&buf[128], 64);
656 prefetch(&buf[448], 64);
657 prefetch(&buf[768], 64);
658 prefetch(&buf[832], 64);
659 prefetch(&buf[64], 64);
660 prefetch(&buf[192], 64);
661 stop = Cycles::rdtsc();
662 total_ticks += stop - start;
664 return Cycles::to_seconds(total_ticks) / count / 16;
670 #if defined(__x86_64__)
672 * This function is used to seralize machine instructions so that no
673 * instructions that appear after it in the current thread can run before any
674 * instructions that appear before it.
676 * It is useful for putting around rdpmc instructions (to pinpoint cache
677 * misses) as well as before rdtsc instructions, to prevent time pollution from
678 * instructions supposed to be executing before the timer starts.
680 static inline void serialize() {
681 uint32_t eax, ebx, ecx, edx;
682 __asm volatile("cpuid"
683 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
688 // Measure the cost of cpuid
689 double perf_serialize() {
690 #if defined(__x86_64__)
692 uint64_t start = Cycles::rdtsc();
693 for (int i = 0; i < count; i++) {
696 uint64_t stop = Cycles::rdtsc();
697 return Cycles::to_seconds(stop - start)/count;
703 // Measure the cost of an lfence instruction.
708 uint64_t start = Cycles::rdtsc();
709 for (int i = 0; i < count; i++) {
710 __asm__ __volatile__("lfence" ::: "memory");
712 uint64_t stop = Cycles::rdtsc();
713 return Cycles::to_seconds(stop - start)/count;
719 // Measure the cost of an sfence instruction.
724 uint64_t start = Cycles::rdtsc();
725 for (int i = 0; i < count; i++) {
726 __asm__ __volatile__("sfence" ::: "memory");
728 uint64_t stop = Cycles::rdtsc();
729 return Cycles::to_seconds(stop - start)/count;
735 // Measure the cost of acquiring and releasing a SpinLock (assuming the
736 // lock is initially free).
737 double test_spinlock()
741 uint64_t start = Cycles::rdtsc();
742 for (int i = 0; i < count; i++) {
746 uint64_t stop = Cycles::rdtsc();
747 return Cycles::to_seconds(stop - start)/count;
750 // Helper for spawn_thread. This is the main function that the thread executes
751 // (intentionally empty).
752 class ThreadHelper : public Thread {
753 void *entry() override { return 0; }
756 // Measure the cost of start and joining with a thread.
757 double spawn_thread()
761 uint64_t start = Cycles::rdtsc();
762 for (int i = 0; i < count; i++) {
763 thread.create("thread_helper");
766 uint64_t stop = Cycles::rdtsc();
767 return Cycles::to_seconds(stop - start)/count;
770 class FakeContext : public Context {
772 void finish(int r) override {}
775 // Measure the cost of starting and stopping a Dispatch::Timer.
779 Mutex lock("perf_timer::lock");
780 SafeTimer timer(g_ceph_context, lock);
781 FakeContext **c = new FakeContext*[count];
782 for (int i = 0; i < count; i++) {
783 c[i] = new FakeContext();
785 uint64_t start = Cycles::rdtsc();
786 Mutex::Locker l(lock);
787 for (int i = 0; i < count; i++) {
788 if (timer.add_event_after(12345, c[i])) {
789 timer.cancel_event(c[i]);
792 uint64_t stop = Cycles::rdtsc();
794 return Cycles::to_seconds(stop - start)/count;
797 // Measure the cost of throwing and catching an int. This uses an integer as
798 // the value thrown, which is presumably as fast as possible.
802 uint64_t start = Cycles::rdtsc();
803 for (int i = 0; i < count; i++) {
806 } catch (int) { // NOLINT
810 uint64_t stop = Cycles::rdtsc();
811 return Cycles::to_seconds(stop - start)/count;
814 // Measure the cost of throwing and catching an int from a function call.
815 double throw_int_call()
818 uint64_t start = Cycles::rdtsc();
819 for (int i = 0; i < count; i++) {
821 PerfHelper::throw_int();
822 } catch (int) { // NOLINT
826 uint64_t stop = Cycles::rdtsc();
827 return Cycles::to_seconds(stop - start)/count;
830 // Measure the cost of throwing and catching an Exception. This uses an actual
831 // exception as the value thrown, which may be slower than throwInt.
832 double throw_exception()
835 uint64_t start = Cycles::rdtsc();
836 for (int i = 0; i < count; i++) {
838 throw buffer::end_of_buffer();
839 } catch (const buffer::end_of_buffer&) {
843 uint64_t stop = Cycles::rdtsc();
844 return Cycles::to_seconds(stop - start)/count;
847 // Measure the cost of throwing and catching an Exception from a function call.
848 double throw_exception_call()
851 uint64_t start = Cycles::rdtsc();
852 for (int i = 0; i < count; i++) {
854 PerfHelper::throw_end_of_buffer();
855 } catch (const buffer::end_of_buffer&) {
859 uint64_t stop = Cycles::rdtsc();
860 return Cycles::to_seconds(stop - start)/count;
863 // Measure the cost of pushing a new element on a std::vector, copying
864 // from the end to an internal element, and popping the end element.
865 double vector_push_pop()
868 std::vector<int> vector;
872 uint64_t start = Cycles::rdtsc();
873 for (int i = 0; i < count; i++) {
875 vector.push_back(i+1);
876 vector.push_back(i+2);
877 vector[2] = vector.back();
879 vector[0] = vector.back();
881 vector[1] = vector.back();
884 uint64_t stop = Cycles::rdtsc();
885 return Cycles::to_seconds(stop - start)/(count*3);
888 // Measure the cost of ceph_clock_now
889 double perf_ceph_clock_now()
892 uint64_t start = Cycles::rdtsc();
893 for (int i = 0; i < count; i++) {
896 uint64_t stop = Cycles::rdtsc();
897 return Cycles::to_seconds(stop - start)/count;
900 // The following struct and table define each performance test in terms of
901 // a string name and a function that implements the test.
903 const char* name; // Name of the performance test; this is
904 // what gets typed on the command line to
906 double (*func)(); // Function that implements the test;
907 // returns the time (in seconds) for each
908 // iteration of that test.
909 const char *description; // Short description of this test (not more
910 // than about 40 characters, so the entire
911 // test output fits on a single line).
914 {"atomic_int_cmp", atomic_int_cmp,
915 "atomic_t::compare_and_swap"},
916 {"atomic_int_inc", atomic_int_inc,
918 {"atomic_int_read", atomic_int_read,
920 {"atomic_int_set", atomic_int_set,
922 {"mutex_nonblock", mutex_nonblock,
923 "Mutex lock/unlock (no blocking)"},
924 {"buffer_basic", buffer_basic,
925 "buffer create, add one ptr, delete"},
926 {"buffer_encode_decode", buffer_encode_decode,
927 "buffer create, encode/decode object, delete"},
928 {"buffer_basic_copy", buffer_basic_copy,
929 "buffer create, copy small block, delete"},
930 {"buffer_copy", buffer_copy,
931 "copy out 2 small ptrs from buffer"},
932 {"buffer_encode10", buffer_encode,
933 "buffer encoding 10 structures onto existing ptr"},
934 {"buffer_get_contiguous", buffer_get_contiguous,
935 "Buffer::get_contiguous"},
936 {"buffer_iterator", buffer_iterator,
937 "iterate over buffer with 5 ptrs"},
938 {"cond_ping_pong", cond_ping_pong,
939 "condition variable round-trip"},
941 "32-bit integer division instruction"},
943 "64-bit integer division instruction"},
944 {"function_call", function_call,
945 "Call a function that has not been inlined"},
946 {"eventcenter_poll", eventcenter_poll,
947 "EventCenter::process_events (no timers or events)"},
948 {"eventcenter_dispatch", eventcenter_dispatch,
949 "EventCenter::dispatch_event_external latency"},
950 {"memcpy100", memcpy100,
951 "Copy 100 bytes with memcpy"},
952 {"memcpy1000", memcpy1000,
953 "Copy 1000 bytes with memcpy"},
954 {"memcpy10000", memcpy10000,
955 "Copy 10000 bytes with memcpy"},
956 {"ceph_str_hash_rjenkins", ceph_str_hash_rjenkins<16>,
957 "rjenkins hash on 16 byte of data"},
958 {"ceph_str_hash_rjenkins", ceph_str_hash_rjenkins<256>,
959 "rjenkins hash on 256 bytes of data"},
960 {"rdtsc", rdtsc_test,
961 "Read the fine-grain cycle counter"},
962 {"cycles_to_seconds", perf_cycles_to_seconds,
963 "Convert a rdtsc result to (double) seconds"},
964 {"cycles_to_seconds", perf_cycles_to_nanoseconds,
965 "Convert a rdtsc result to (uint64_t) nanoseconds"},
966 {"prefetch", perf_prefetch,
967 "Prefetch instruction"},
968 {"serialize", perf_serialize,
969 "serialize instruction"},
971 "Lfence instruction"},
973 "Sfence instruction"},
974 {"spin_lock", test_spinlock,
975 "Acquire/release SpinLock"},
976 {"spawn_thread", spawn_thread,
977 "Start and stop a thread"},
978 {"perf_timer", perf_timer,
979 "Insert and cancel a SafeTimer"},
980 {"throw_int", throw_int,
982 {"throw_int_call", throw_int_call,
983 "Throw an int in a function call"},
984 {"throw_exception", throw_exception,
985 "Throw an Exception"},
986 {"throw_exception_call", throw_exception_call,
987 "Throw an Exception in a function call"},
988 {"vector_push_pop", vector_push_pop,
989 "Push and pop a std::vector"},
990 {"ceph_clock_now", perf_ceph_clock_now,
991 "ceph_clock_now function"},
995 * Runs a particular test and prints a one-line result message.
998 * Describes the test to run.
1000 void run_test(TestInfo& info)
1002 double secs = info.func();
1003 int width = printf("%-24s ", info.name);
1005 width += printf(" architecture nonsupport ");
1006 } else if (secs < 1.0e-06) {
1007 width += printf("%8.2fns", 1e09*secs);
1008 } else if (secs < 1.0e-03) {
1009 width += printf("%8.2fus", 1e06*secs);
1010 } else if (secs < 1.0) {
1011 width += printf("%8.2fms", 1e03*secs);
1013 width += printf("%8.2fs", secs);
1015 printf("%*s %s\n", 32-width, "", info.description);
1018 int main(int argc, char *argv[])
1020 vector<const char*> args;
1021 argv_to_vec(argc, (const char **)argv, args);
1023 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
1024 CODE_ENVIRONMENT_UTILITY, 0);
1025 common_init_finish(g_ceph_context);
1028 bind_thread_to_cpu(3);
1030 // No test names specified; run all tests.
1031 for (size_t i = 0; i < sizeof(tests)/sizeof(TestInfo); ++i) {
1035 // Run only the tests that were specified on the command line.
1036 for (int i = 1; i < argc; i++) {
1037 bool found_test = false;
1038 for (size_t j = 0; j < sizeof(tests)/sizeof(TestInfo); ++j) {
1039 if (strcmp(argv[i], tests[j].name) == 0) {
1046 int width = printf("%-24s ??", argv[i]);
1047 printf("%*s No such test\n", 32-width, "");