Skip to content

Commit d185f2a

Browse files
olsajiriKernel Patches Daemon
authored andcommitted
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

File tree

1 file changed

+17
-0
lines changed
  • tools/testing/selftests/bpf

1 file changed

+17
-0
lines changed

tools/testing/selftests/bpf/usdt.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,16 @@ struct usdt_sema { volatile unsigned short active; };
312312
#ifndef USDT_NOP
313313
#if defined(__ia64__) || defined(__s390__) || defined(__s390x__)
314314
#define USDT_NOP nop 0
315+
#elif defined(__x86_64__)
316+
#define USDT_NOP .byte 0x90, 0x0f, 0x1f, 0x44, 0x00, 0x0 /* nop, nop5 */
315317
#else
316318
#define USDT_NOP nop
317319
#endif
320+
#else
321+
/*
322+
* User define its own nop instruction, do not emit extra note data.
323+
*/
324+
#define __usdt_asm_extra
318325
#endif /* USDT_NOP */
319326

320327
/*
@@ -403,6 +410,15 @@ struct usdt_sema { volatile unsigned short active; };
403410
__asm__ __volatile__ ("" :: "m" (sema));
404411
#endif
405412

413+
#ifndef __usdt_asm_extra
414+
#ifdef __x86_64__
415+
#define __usdt_asm_extra \
416+
__usdt_asm1( .ascii "\0")
417+
#else
418+
#define __usdt_asm_extra
419+
#endif
420+
#endif
421+
406422
/* main USDT definition (nop and .note.stapsdt metadata) */
407423
#define __usdt_probe(group, name, sema_def, sema, ...) do { \
408424
sema_def(sema) \
@@ -420,6 +436,7 @@ struct usdt_sema { volatile unsigned short active; };
420436
__usdt_asm_strz(name) \
421437
__usdt_asm_args(__VA_ARGS__) \
422438
__usdt_asm1( .ascii "\0") \
439+
__usdt_asm_extra \
423440
__usdt_asm1(994: .balign 4) \
424441
__usdt_asm1( .popsection) \
425442
__usdt_asm1(.ifndef _.stapsdt.base) \

0 commit comments

Comments
 (0)