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/ceph_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 ceph::mutex m
= ceph::make_mutex("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::const_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 auto iter
= b
.cbegin();
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
++) {
249 b
.cbegin(2).copy(6, copy
);
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 creating an iterator and iterating over 10
282 // chunks in a buffer.
283 double buffer_iterator()
286 const char s
[] = "abcdefghijklmnopqrstuvwxyz";
287 bufferptr
ptr(s
, sizeof(s
));
288 for (int i
= 0; i
< 5; i
++) {
293 uint64_t start
= Cycles::rdtsc();
294 for (int i
= 0; i
< count
; i
++) {
295 auto it
= b
.cbegin();
297 sum
+= (static_cast<const char*>(it
.get_current_ptr().c_str()))[it
.get_remaining()-1];
301 uint64_t stop
= Cycles::rdtsc();
303 return Cycles::to_seconds(stop
- start
)/count
;
306 // Implements the CondPingPong test.
308 ceph::mutex mutex
= ceph::make_mutex("CondPingPong::mutex");
309 ceph::condition_variable cond
;
312 const int count
= 10000;
314 class Consumer
: public Thread
{
317 explicit Consumer(CondPingPong
*p
): p(p
) {}
318 void* entry() override
{
325 CondPingPong(): consumer(this) {}
328 consumer
.create("consumer");
329 uint64_t start
= Cycles::rdtsc();
331 uint64_t stop
= Cycles::rdtsc();
333 return Cycles::to_seconds(stop
- start
)/count
;
337 std::unique_lock l
{mutex
};
338 while (cons
< count
) {
339 cond
.wait(l
, [this] { return cons
>= prod
; });
346 std::unique_lock l
{mutex
};
347 while (cons
< count
) {
348 cond
.wait(l
, [this] { return cons
!= prod
; });
355 // Measure the cost of coordinating between threads using a condition variable.
356 double cond_ping_pong()
358 return CondPingPong().run();
361 // Measure the cost of a 32-bit divide. Divides don't take a constant
362 // number of cycles. Values were chosen here semi-randomly to depict a
363 // fairly expensive scenario. Someone with fancy ALU knowledge could
364 // probably pick worse values.
367 #if defined(__i386__) || defined(__x86_64__)
369 uint64_t start
= Cycles::rdtsc();
370 // NB: Expect an x86 processor exception is there's overflow.
371 uint32_t numeratorHi
= 0xa5a5a5a5U
;
372 uint32_t numeratorLo
= 0x55aa55aaU
;
373 uint32_t divisor
= 0xaa55aa55U
;
376 for (int i
= 0; i
< count
; i
++) {
377 __asm__
__volatile__("div %4" :
378 "=a"(quotient
), "=d"(remainder
) :
379 "a"(numeratorLo
), "d"(numeratorHi
), "r"(divisor
) :
382 uint64_t stop
= Cycles::rdtsc();
383 return Cycles::to_seconds(stop
- start
)/count
;
389 // Measure the cost of a 64-bit divide. Divides don't take a constant
390 // number of cycles. Values were chosen here semi-randomly to depict a
391 // fairly expensive scenario. Someone with fancy ALU knowledge could
392 // probably pick worse values.
395 #if defined(__x86_64__) || defined(__amd64__)
397 // NB: Expect an x86 processor exception is there's overflow.
398 uint64_t start
= Cycles::rdtsc();
399 uint64_t numeratorHi
= 0x5a5a5a5a5a5UL
;
400 uint64_t numeratorLo
= 0x55aa55aa55aa55aaUL
;
401 uint64_t divisor
= 0xaa55aa55aa55aa55UL
;
404 for (int i
= 0; i
< count
; i
++) {
405 __asm__
__volatile__("divq %4" :
406 "=a"(quotient
), "=d"(remainder
) :
407 "a"(numeratorLo
), "d"(numeratorHi
), "r"(divisor
) :
410 uint64_t stop
= Cycles::rdtsc();
411 return Cycles::to_seconds(stop
- start
)/count
;
417 // Measure the cost of calling a non-inlined function.
418 double function_call()
422 uint64_t start
= Cycles::rdtsc();
423 for (int i
= 0; i
< count
; i
++) {
424 x
= PerfHelper::plus_one(x
);
426 uint64_t stop
= Cycles::rdtsc();
427 return Cycles::to_seconds(stop
- start
)/count
;
430 // Measure the minimum cost of EventCenter::process_events, when there are no
431 // Pollers and no Timers.
432 double eventcenter_poll()
435 EventCenter
center(g_ceph_context
);
436 center
.init(1000, 0, "posix");
438 uint64_t start
= Cycles::rdtsc();
439 for (int i
= 0; i
< count
; i
++) {
440 center
.process_events(0);
442 uint64_t stop
= Cycles::rdtsc();
443 return Cycles::to_seconds(stop
- start
)/count
;
446 class CenterWorker
: public Thread
{
452 explicit CenterWorker(CephContext
*c
): cct(c
), done(false), center(c
) {
453 center
.init(100, 0, "posix");
459 void* entry() override
{
461 bind_thread_to_cpu(2);
463 center
.process_events(1000);
468 class CountEvent
: public EventCallback
{
469 std::atomic
<int64_t> *count
;
472 explicit CountEvent(std::atomic
<int64_t> *atomic
): count(atomic
) {}
473 void do_request(uint64_t id
) override
{
478 double eventcenter_dispatch()
482 CenterWorker
worker(g_ceph_context
);
483 std::atomic
<int64_t> flag
= { 1 };
484 worker
.create("evt_center_disp");
485 EventCallbackRef
count_event(new CountEvent(&flag
));
487 worker
.center
.dispatch_event_external(count_event
);
488 // Start a new thread and wait for it to ready.
492 uint64_t start
= Cycles::rdtsc();
493 for (int i
= 0; i
< count
; i
++) {
495 worker
.center
.dispatch_event_external(count_event
);
499 uint64_t stop
= Cycles::rdtsc();
502 return Cycles::to_seconds(stop
- start
)/count
;
505 // Measure the cost of copying a given number of bytes with memcpy.
506 double memcpy_shared(size_t size
)
509 char src
[size
], dst
[size
];
511 memset(src
, 0, sizeof(src
));
513 uint64_t start
= Cycles::rdtsc();
514 for (int i
= 0; i
< count
; i
++) {
515 memcpy(dst
, src
, size
);
517 uint64_t stop
= Cycles::rdtsc();
518 return Cycles::to_seconds(stop
- start
)/count
;
523 return memcpy_shared(100);
528 return memcpy_shared(1000);
533 return memcpy_shared(10000);
536 // Benchmark rjenkins hashing performance on cached data.
537 template <int key_length
>
538 double ceph_str_hash_rjenkins()
541 char buf
[key_length
];
543 uint64_t start
= Cycles::rdtsc();
544 for (int i
= 0; i
< count
; i
++)
545 ceph_str_hash(CEPH_STR_HASH_RJENKINS
, buf
, sizeof(buf
));
546 uint64_t stop
= Cycles::rdtsc();
548 return Cycles::to_seconds(stop
- start
)/count
;
551 // Measure the cost of reading the fine-grain cycle counter.
555 uint64_t start
= Cycles::rdtsc();
557 for (int i
= 0; i
< count
; i
++) {
558 total
+= Cycles::rdtsc();
560 uint64_t stop
= Cycles::rdtsc();
561 return Cycles::to_seconds(stop
- start
)/count
;
564 // Measure the cost of the Cycles::to_seconds method.
565 double perf_cycles_to_seconds()
569 uint64_t cycles
= 994261;
570 uint64_t start
= Cycles::rdtsc();
571 for (int i
= 0; i
< count
; i
++) {
572 total
+= Cycles::to_seconds(cycles
);
574 uint64_t stop
= Cycles::rdtsc();
575 // printf("Result: %.4f\n", total/count);
576 return Cycles::to_seconds(stop
- start
)/count
;
579 // Measure the cost of the Cylcles::toNanoseconds method.
580 double perf_cycles_to_nanoseconds()
584 uint64_t cycles
= 994261;
585 uint64_t start
= Cycles::rdtsc();
586 for (int i
= 0; i
< count
; i
++) {
587 total
+= Cycles::to_nanoseconds(cycles
);
589 uint64_t stop
= Cycles::rdtsc();
590 // printf("Result: %lu\n", total/count);
591 return Cycles::to_seconds(stop
- start
)/count
;
597 * Prefetch the cache lines containing [object, object + numBytes) into the
598 * processor's caches.
599 * The best docs for this are in the Intel instruction set reference under
602 * The start of the region of memory to prefetch.
604 * The size of the region of memory to prefetch.
606 static inline void prefetch(const void *object
, uint64_t num_bytes
)
608 uint64_t offset
= reinterpret_cast<uint64_t>(object
) & 0x3fUL
;
609 const char* p
= reinterpret_cast<const char*>(object
) - offset
;
610 for (uint64_t i
= 0; i
< offset
+ num_bytes
; i
+= 64)
611 _mm_prefetch(p
+ i
, _MM_HINT_T0
);
615 // Measure the cost of the prefetch instruction.
616 double perf_prefetch()
619 uint64_t total_ticks
= 0;
623 for (int i
= 0; i
< count
; i
++) {
624 PerfHelper::flush_cache();
625 uint64_t start
= Cycles::rdtsc();
626 prefetch(&buf
[576], 64);
627 prefetch(&buf
[0], 64);
628 prefetch(&buf
[512], 64);
629 prefetch(&buf
[960], 64);
630 prefetch(&buf
[640], 64);
631 prefetch(&buf
[896], 64);
632 prefetch(&buf
[256], 64);
633 prefetch(&buf
[704], 64);
634 prefetch(&buf
[320], 64);
635 prefetch(&buf
[384], 64);
636 prefetch(&buf
[128], 64);
637 prefetch(&buf
[448], 64);
638 prefetch(&buf
[768], 64);
639 prefetch(&buf
[832], 64);
640 prefetch(&buf
[64], 64);
641 prefetch(&buf
[192], 64);
642 uint64_t stop
= Cycles::rdtsc();
643 total_ticks
+= stop
- start
;
645 return Cycles::to_seconds(total_ticks
) / count
/ 16;
651 #if defined(__x86_64__)
653 * This function is used to seralize machine instructions so that no
654 * instructions that appear after it in the current thread can run before any
655 * instructions that appear before it.
657 * It is useful for putting around rdpmc instructions (to pinpoint cache
658 * misses) as well as before rdtsc instructions, to prevent time pollution from
659 * instructions supposed to be executing before the timer starts.
661 static inline void serialize() {
662 uint32_t eax
, ebx
, ecx
, edx
;
663 __asm
volatile("cpuid"
664 : "=a" (eax
), "=b" (ebx
), "=c" (ecx
), "=d" (edx
)
669 // Measure the cost of cpuid
670 double perf_serialize() {
671 #if defined(__x86_64__)
673 uint64_t start
= Cycles::rdtsc();
674 for (int i
= 0; i
< count
; i
++) {
677 uint64_t stop
= Cycles::rdtsc();
678 return Cycles::to_seconds(stop
- start
)/count
;
684 // Measure the cost of an lfence instruction.
689 uint64_t start
= Cycles::rdtsc();
690 for (int i
= 0; i
< count
; i
++) {
691 __asm__
__volatile__("lfence" ::: "memory");
693 uint64_t stop
= Cycles::rdtsc();
694 return Cycles::to_seconds(stop
- start
)/count
;
700 // Measure the cost of an sfence instruction.
705 uint64_t start
= Cycles::rdtsc();
706 for (int i
= 0; i
< count
; i
++) {
707 __asm__
__volatile__("sfence" ::: "memory");
709 uint64_t stop
= Cycles::rdtsc();
710 return Cycles::to_seconds(stop
- start
)/count
;
716 // Measure the cost of acquiring and releasing a SpinLock (assuming the
717 // lock is initially free).
718 double test_spinlock()
722 uint64_t start
= Cycles::rdtsc();
723 for (int i
= 0; i
< count
; i
++) {
727 uint64_t stop
= Cycles::rdtsc();
728 return Cycles::to_seconds(stop
- start
)/count
;
731 // Helper for spawn_thread. This is the main function that the thread executes
732 // (intentionally empty).
733 class ThreadHelper
: public Thread
{
734 void *entry() override
{ return 0; }
737 // Measure the cost of start and joining with a thread.
738 double spawn_thread()
742 uint64_t start
= Cycles::rdtsc();
743 for (int i
= 0; i
< count
; i
++) {
744 thread
.create("thread_helper");
747 uint64_t stop
= Cycles::rdtsc();
748 return Cycles::to_seconds(stop
- start
)/count
;
751 class FakeContext
: public Context
{
753 void finish(int r
) override
{}
756 // Measure the cost of starting and stopping a Dispatch::Timer.
760 ceph::mutex lock
= ceph::make_mutex("perf_timer::lock");
761 SafeTimer
timer(g_ceph_context
, lock
);
762 FakeContext
**c
= new FakeContext
*[count
];
763 for (int i
= 0; i
< count
; i
++) {
764 c
[i
] = new FakeContext();
766 uint64_t start
= Cycles::rdtsc();
767 std::lock_guard l
{lock
};
768 for (int i
= 0; i
< count
; i
++) {
769 if (timer
.add_event_after(12345, c
[i
])) {
770 timer
.cancel_event(c
[i
]);
773 uint64_t stop
= Cycles::rdtsc();
775 return Cycles::to_seconds(stop
- start
)/count
;
778 // Measure the cost of throwing and catching an int. This uses an integer as
779 // the value thrown, which is presumably as fast as possible.
783 uint64_t start
= Cycles::rdtsc();
784 for (int i
= 0; i
< count
; i
++) {
787 } catch (int) { // NOLINT
791 uint64_t stop
= Cycles::rdtsc();
792 return Cycles::to_seconds(stop
- start
)/count
;
795 // Measure the cost of throwing and catching an int from a function call.
796 double throw_int_call()
799 uint64_t start
= Cycles::rdtsc();
800 for (int i
= 0; i
< count
; i
++) {
802 PerfHelper::throw_int();
803 } catch (int) { // NOLINT
807 uint64_t stop
= Cycles::rdtsc();
808 return Cycles::to_seconds(stop
- start
)/count
;
811 // Measure the cost of throwing and catching an Exception. This uses an actual
812 // exception as the value thrown, which may be slower than throwInt.
813 double throw_exception()
816 uint64_t start
= Cycles::rdtsc();
817 for (int i
= 0; i
< count
; i
++) {
819 throw buffer::end_of_buffer();
820 } catch (const buffer::end_of_buffer
&) {
824 uint64_t stop
= Cycles::rdtsc();
825 return Cycles::to_seconds(stop
- start
)/count
;
828 // Measure the cost of throwing and catching an Exception from a function call.
829 double throw_exception_call()
832 uint64_t start
= Cycles::rdtsc();
833 for (int i
= 0; i
< count
; i
++) {
835 PerfHelper::throw_end_of_buffer();
836 } catch (const buffer::end_of_buffer
&) {
840 uint64_t stop
= Cycles::rdtsc();
841 return Cycles::to_seconds(stop
- start
)/count
;
844 // Measure the cost of pushing a new element on a std::vector, copying
845 // from the end to an internal element, and popping the end element.
846 double vector_push_pop()
849 std::vector
<int> vector
;
853 uint64_t start
= Cycles::rdtsc();
854 for (int i
= 0; i
< count
; i
++) {
856 vector
.push_back(i
+1);
857 vector
.push_back(i
+2);
858 vector
[2] = vector
.back();
860 vector
[0] = vector
.back();
862 vector
[1] = vector
.back();
865 uint64_t stop
= Cycles::rdtsc();
866 return Cycles::to_seconds(stop
- start
)/(count
*3);
869 // Measure the cost of ceph_clock_now
870 double perf_ceph_clock_now()
873 uint64_t start
= Cycles::rdtsc();
874 for (int i
= 0; i
< count
; i
++) {
877 uint64_t stop
= Cycles::rdtsc();
878 return Cycles::to_seconds(stop
- start
)/count
;
881 // The following struct and table define each performance test in terms of
882 // a string name and a function that implements the test.
884 const char* name
; // Name of the performance test; this is
885 // what gets typed on the command line to
887 double (*func
)(); // Function that implements the test;
888 // returns the time (in seconds) for each
889 // iteration of that test.
890 const char *description
; // Short description of this test (not more
891 // than about 40 characters, so the entire
892 // test output fits on a single line).
895 {"atomic_int_cmp", atomic_int_cmp
,
896 "atomic_t::compare_and_swap"},
897 {"atomic_int_inc", atomic_int_inc
,
899 {"atomic_int_read", atomic_int_read
,
901 {"atomic_int_set", atomic_int_set
,
903 {"mutex_nonblock", mutex_nonblock
,
904 "Mutex lock/unlock (no blocking)"},
905 {"buffer_basic", buffer_basic
,
906 "buffer create, add one ptr, delete"},
907 {"buffer_encode_decode", buffer_encode_decode
,
908 "buffer create, encode/decode object, delete"},
909 {"buffer_basic_copy", buffer_basic_copy
,
910 "buffer create, copy small block, delete"},
911 {"buffer_copy", buffer_copy
,
912 "copy out 2 small ptrs from buffer"},
913 {"buffer_encode10", buffer_encode
,
914 "buffer encoding 10 structures onto existing ptr"},
915 {"buffer_iterator", buffer_iterator
,
916 "iterate over buffer with 5 ptrs"},
917 {"cond_ping_pong", cond_ping_pong
,
918 "condition variable round-trip"},
920 "32-bit integer division instruction"},
922 "64-bit integer division instruction"},
923 {"function_call", function_call
,
924 "Call a function that has not been inlined"},
925 {"eventcenter_poll", eventcenter_poll
,
926 "EventCenter::process_events (no timers or events)"},
927 {"eventcenter_dispatch", eventcenter_dispatch
,
928 "EventCenter::dispatch_event_external latency"},
929 {"memcpy100", memcpy100
,
930 "Copy 100 bytes with memcpy"},
931 {"memcpy1000", memcpy1000
,
932 "Copy 1000 bytes with memcpy"},
933 {"memcpy10000", memcpy10000
,
934 "Copy 10000 bytes with memcpy"},
935 {"ceph_str_hash_rjenkins", ceph_str_hash_rjenkins
<16>,
936 "rjenkins hash on 16 byte of data"},
937 {"ceph_str_hash_rjenkins", ceph_str_hash_rjenkins
<256>,
938 "rjenkins hash on 256 bytes of data"},
939 {"rdtsc", rdtsc_test
,
940 "Read the fine-grain cycle counter"},
941 {"cycles_to_seconds", perf_cycles_to_seconds
,
942 "Convert a rdtsc result to (double) seconds"},
943 {"cycles_to_seconds", perf_cycles_to_nanoseconds
,
944 "Convert a rdtsc result to (uint64_t) nanoseconds"},
945 {"prefetch", perf_prefetch
,
946 "Prefetch instruction"},
947 {"serialize", perf_serialize
,
948 "serialize instruction"},
950 "Lfence instruction"},
952 "Sfence instruction"},
953 {"spin_lock", test_spinlock
,
954 "Acquire/release SpinLock"},
955 {"spawn_thread", spawn_thread
,
956 "Start and stop a thread"},
957 {"perf_timer", perf_timer
,
958 "Insert and cancel a SafeTimer"},
959 {"throw_int", throw_int
,
961 {"throw_int_call", throw_int_call
,
962 "Throw an int in a function call"},
963 {"throw_exception", throw_exception
,
964 "Throw an Exception"},
965 {"throw_exception_call", throw_exception_call
,
966 "Throw an Exception in a function call"},
967 {"vector_push_pop", vector_push_pop
,
968 "Push and pop a std::vector"},
969 {"ceph_clock_now", perf_ceph_clock_now
,
970 "ceph_clock_now function"},
974 * Runs a particular test and prints a one-line result message.
977 * Describes the test to run.
979 void run_test(TestInfo
& info
)
981 double secs
= info
.func();
982 int width
= printf("%-24s ", info
.name
);
984 width
+= printf(" architecture nonsupport ");
985 } else if (secs
< 1.0e-06) {
986 width
+= printf("%8.2fns", 1e09
*secs
);
987 } else if (secs
< 1.0e-03) {
988 width
+= printf("%8.2fus", 1e06
*secs
);
989 } else if (secs
< 1.0) {
990 width
+= printf("%8.2fms", 1e03
*secs
);
992 width
+= printf("%8.2fs", secs
);
994 printf("%*s %s\n", 32-width
, "", info
.description
);
997 int main(int argc
, char *argv
[])
999 vector
<const char*> args
;
1000 argv_to_vec(argc
, (const char **)argv
, args
);
1002 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
1003 CODE_ENVIRONMENT_UTILITY
,
1004 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE
);
1005 common_init_finish(g_ceph_context
);
1008 bind_thread_to_cpu(3);
1010 // No test names specified; run all tests.
1011 for (size_t i
= 0; i
< sizeof(tests
)/sizeof(TestInfo
); ++i
) {
1015 // Run only the tests that were specified on the command line.
1016 for (int i
= 1; i
< argc
; i
++) {
1017 bool found_test
= false;
1018 for (size_t j
= 0; j
< sizeof(tests
)/sizeof(TestInfo
); ++j
) {
1019 if (strcmp(argv
[i
], tests
[j
].name
) == 0) {
1026 int width
= printf("%-24s ??", argv
[i
]);
1027 printf("%*s No such test\n", 32-width
, "");