суббота, 4 декабря 2021 г.

overhead of eBPF JIT

Lets try to estimate overhead of JIT compiler

I wrote simple perl script - it just counts redundant bytes for several cases:

  • pair mov reg, rbp/add reg, imm (total length 7 bytes) can be replaced with lea reg, [rbp-imm] which is only 4 bytes
  • pair mov reg, imm/add reg,imm can be replaced with just loading of right address so second instruction can be removed
  • add reg, 1/sub reg, 1 (length 4 bytes) can be replaced to inc/dec reg (which has length 3 bytes)
etc etc
Results
total: 105374 odd 4528 4.3%
other samples shows similar overhead - between 4.3 and 5.2%

of course lots of code like
 mov eax, 0x1
 cmp r14, 0x2
 jnz 0xc05674ab
 xor eax, eax
c05674ab:
 ...
 leave
 ret

can be replaced with something like:
xor eax, eax
cmp r14, 0x2
setnz al

but it matters only in big IP filters
Unfortunately that's not all - we can see lots of repeated code like

mov [r13+0x58], bl
mov [r13+0x57], bl
...
mov [r13+0x39], bl

but this is big questions to LLVM eBPF backend

Комментариев нет:

Отправить комментарий