#+title: Benchmarks URCU #+date: [2024-10-18 Fri 12:18] #+filetags: :urcu: #+identifier: 20241018T121818 * Program #+begin_src c #define _LGPL_SOURCE #define URCU_DEREFERENCE_USE_VOLATILE #include #include #include struct foo { long x; }; volatile long flag; static void do_stuff(long x) { flag = x; } struct foo *foo; __attribute__((noinline)) static void func() { struct foo *a, *b; a = rcu_dereference(foo); do_stuff(a->x); b = rcu_dereference(foo); if (cmm_ptr_eq(a, b)) { do_stuff(b->x); } } int main(int argc, char *argv[]) { struct foo fuz; foo = &fuz; cmm_barrier(); assert(2 == argc); long loop = atoll(argv[1]); for (long k = 0; k < loop; ++k) { func(); } return 0; } #+end_src * v0.14.1 #+begin_src asm 0000000000000860 : 860: 90000100 adrp x0, 20000 <__libc_start_main@GLIBC_2.34> 864: 91012002 add x2, x0, #0x48 868: f9402401 ldr x1, [x0, #72] 86c: f9400023 ldr x3, [x1] 870: f9000443 str x3, [x2, #8] 874: f9402400 ldr x0, [x0, #72] 878: eb00003f cmp x1, x0 87c: 54000040 b.eq 884 // b.none 880: d65f03c0 ret 884: f9400020 ldr x0, [x1] 888: f9000440 str x0, [x2, #8] 88c: d65f03c0 ret #+end_src Performance counter stats for './a.out 1000000000': 4,214.47 msec task-clock # 0.999 CPUs utilized 14 context-switches # 3.322 /sec 0 cpu-migrations # 0.000 /sec 44 page-faults # 10.440 /sec 8,015,627,017 cycles # 1.902 GHz 15,008,330,513 instructions # 1.87 insn per cycle branches 26,607 branch-misses 4.217609351 seconds time elapsed 4.213169000 seconds user 0.004001000 seconds sys * Proposal ** Volatile access #+begin_src asm 0000000000000860 : 860: 90000101 adrp x1, 20000 <__libc_start_main@GLIBC_2.34> 864: 91012022 add x2, x1, #0x48 868: f9402420 ldr x0, [x1, #72] 86c: f9400003 ldr x3, [x0] 870: f9000443 str x3, [x2, #8] 874: f9402423 ldr x3, [x1, #72] 878: aa0303e1 mov x1, x3 87c: eb01001f cmp x0, x1 880: 54000040 b.eq 888 // b.none 884: d65f03c0 ret 888: f9400060 ldr x0, [x3] 88c: f9000440 str x0, [x2, #8] 890: d65f03c0 ret #+end_src Performance counter stats for './a.out 1000000000': 4,733.47 msec task-clock # 0.999 CPUs utilized 18 context-switches # 3.803 /sec 0 cpu-migrations # 0.000 /sec 42 page-faults # 8.873 /sec 9,020,349,576 cycles # 1.906 GHz 16,009,538,541 instructions # 1.77 insn per cycle branches 29,834 branch-misses 4.736255910 seconds time elapsed 4.731968000 seconds user 0.003999000 seconds sys ** Atomic builtins #+begin_src asm 0000000000000860 : 860: 90000101 adrp x1, 20000 <__libc_start_main@GLIBC_2.34> 864: 91012021 add x1, x1, #0x48 868: c8dffc20 ldar x0, [x1] 86c: f9400002 ldr x2, [x0] 870: f9000422 str x2, [x1, #8] 874: c8dffc23 ldar x3, [x1] 878: aa0303e2 mov x2, x3 87c: eb00005f cmp x2, x0 880: 54000040 b.eq 888 // b.none 884: d65f03c0 ret 888: f9400060 ldr x0, [x3] 88c: f9000420 str x0, [x1, #8] 890: d65f03c0 ret #+end_src Performance counter stats for './a.out 1000000000': 22,062.47 msec task-clock # 1.000 CPUs utilized 17 context-switches # 0.771 /sec 0 cpu-migrations # 0.000 /sec 43 page-faults # 1.949 /sec 42,157,489,783 cycles # 1.911 GHz 16,039,077,935 instructions # 0.38 insn per cycle branches 76,727 branch-misses 22.065725405 seconds time elapsed 22.061101000 seconds user 0.004000000 seconds sys * Summary Aarch64 Cortex-A57 | Variant | Time [s] | Cycles | Instructions | Branch misses | |-----------------+-------------+---------------+----------------+---------------| | Baseline | 4.217609351 | 8 015 627 017 | 15 008 330 513 | 26 607 | |-----------------+-------------+---------------+----------------+---------------| | Volatile access | +10.95 % | +11.14 % | +6.25 % | +10.81 % | | Atomic builtins | +423.18 % | +425.94 % | +6.87 % | +188.37 % |