Commit d185f2a
selftests/bpf: Emit nop,nop5 instructions for x86_64 usdt probe
We can currently optimize uprobes on top of nop5 instructions,
so application can define USDT_NOP to nop5 and use USDT macro
to define optimized usdt probes.
This works fine on new kernels, but could have performance penalty
on older kernels, that do not have the support to optimize and to
emulate nop5 instruction.
execution of the usdt probe on top of nop:
- nop -> trigger usdt -> emulate nop -> continue
execution of the usdt probe on top of nop5:
- nop5 -> trigger usdt -> single step nop5 -> continue
Note the 'single step nop5' as the source of performance regression.
To workaround that we change the USDT macro to emit nop,nop5 for
the probe (instead of default nop) and make record of that in
USDT record (more on that below).
This can be detected by application (libbpf) and it can place the
uprobe either on nop or nop5 based on the optimization support in
the kernel.
We make record of using the nop,nop5 instructions in the USDT ELF
note data.
Current elf note format is as follows:
namesz (4B) | descsz (4B) | type (4B) | name | desc
And current usdt record (with "stapsdt" name) placed in the note's
desc data look like:
loc_addr | 8 bytes
base_addr | 8 bytes
sema_addr | 8 bytes
provider | zero terminated string
name | zero terminated string
args | zero terminated string
None of the tested parsers (bpftrace-bcc, libbpf) checked that the args
zero terminated byte is the actual end of the 'desc' data. As Andrii
suggested we could use this and place extra zero byte right there as an
indication for the parser we use the nop,nop5 instructions.
It's bit tricky, but the other way would be to introduce new elf note type
or note name and change all existing parsers to recognize it. With the change
above the existing parsers would still recognize such usdt probes.
Note we do not emit this extra byte if app defined its own nop through
USDT_NOP macro.
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>1 parent b0a5b86 commit d185f2a
1 file changed
+17
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
312 | 312 | | |
313 | 313 | | |
314 | 314 | | |
| 315 | + | |
| 316 | + | |
315 | 317 | | |
316 | 318 | | |
317 | 319 | | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
318 | 325 | | |
319 | 326 | | |
320 | 327 | | |
| |||
403 | 410 | | |
404 | 411 | | |
405 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
406 | 422 | | |
407 | 423 | | |
408 | 424 | | |
| |||
420 | 436 | | |
421 | 437 | | |
422 | 438 | | |
| 439 | + | |
423 | 440 | | |
424 | 441 | | |
425 | 442 | | |
| |||
0 commit comments