Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf trace: Handle legacy syscalls tracepoints

Currently the code skips the first field with the expectation that it is 'nr'.
But older kernels do not have the 'nr' field:

field:int nr; offset:8; size:4; signed:1;

Change perf-trace to drop the field if it exists after parsing the format file.

This fixes the off-by-one problem with older kernels (e.g., RHEL6). e.g,
perf-trace shows this for write:

1.515 ( 0.006 ms): dd/4245 write(buf: 2</dev/pts/0>, count: 140733837536224 ) = 26

where 2 is really the fd, the huge number is really the buf address, etc. With
this patch you get the more appropriate:

1.813 ( 0.003 ms): dd/6330 write(fd: 2</dev/pts/0>, buf: 0x7fff22fc81f0, count: 25) = 25

Based-on-a-patch-by: David Ahern <dsahern@gmail.com>
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-gvpdave4u2yq2jnzbcdznpvf@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+14 -4
+14 -4
tools/perf/builtin-trace.c
··· 1135 1135 1136 1136 struct syscall { 1137 1137 struct event_format *tp_format; 1138 + int nr_args; 1139 + struct format_field *args; 1138 1140 const char *name; 1139 1141 bool filtered; 1140 1142 bool is_exit; ··· 1444 1442 struct format_field *field; 1445 1443 int idx = 0; 1446 1444 1447 - sc->arg_scnprintf = calloc(sc->tp_format->format.nr_fields - 1, sizeof(void *)); 1445 + sc->arg_scnprintf = calloc(sc->nr_args, sizeof(void *)); 1448 1446 if (sc->arg_scnprintf == NULL) 1449 1447 return -1; 1450 1448 1451 1449 if (sc->fmt) 1452 1450 sc->arg_parm = sc->fmt->arg_parm; 1453 1451 1454 - for (field = sc->tp_format->format.fields->next; field; field = field->next) { 1452 + for (field = sc->args; field; field = field->next) { 1455 1453 if (sc->fmt && sc->fmt->arg_scnprintf[idx]) 1456 1454 sc->arg_scnprintf[idx] = sc->fmt->arg_scnprintf[idx]; 1457 1455 else if (field->flags & FIELD_IS_POINTER) ··· 1517 1515 if (sc->tp_format == NULL) 1518 1516 return -1; 1519 1517 1518 + sc->args = sc->tp_format->format.fields; 1519 + sc->nr_args = sc->tp_format->format.nr_fields; 1520 + /* drop nr field - not relevant here; does not exist on older kernels */ 1521 + if (sc->args && strcmp(sc->args->name, "nr") == 0) { 1522 + sc->args = sc->args->next; 1523 + --sc->nr_args; 1524 + } 1525 + 1520 1526 sc->is_exit = !strcmp(name, "exit_group") || !strcmp(name, "exit"); 1521 1527 1522 1528 return syscall__set_arg_fmts(sc); ··· 1547 1537 unsigned char *p; 1548 1538 unsigned long val; 1549 1539 1550 - if (sc->tp_format != NULL) { 1540 + if (sc->args != NULL) { 1551 1541 struct format_field *field; 1552 1542 u8 bit = 1; 1553 1543 struct syscall_arg arg = { ··· 1557 1547 .thread = thread, 1558 1548 }; 1559 1549 1560 - for (field = sc->tp_format->format.fields->next; field; 1550 + for (field = sc->args; field; 1561 1551 field = field->next, ++arg.idx, bit <<= 1) { 1562 1552 if (arg.mask & bit) 1563 1553 continue;