Skip to content

Commit fd0db10

Browse files
committed
perf trace: Move syscall table id <-> name routines to separate class
We're using libaudit for doing name to id and id to syscall name translations, but that makes 'perf trace' to have to wait for newer libaudit versions supporting recently added syscalls, such as "userfaultfd" at the time of this changeset. We have all the information right there, in the kernel sources, so move this code to a separate place, wrapped behind functions that will progressively use the kernel source files to extract the syscall table for use in 'perf trace'. Cc: Adrian Hunter <[email protected]> Cc: David Ahern <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Wang Nan <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent ba2f22c commit fd0db10

File tree

4 files changed

+71
-13
lines changed

4 files changed

+71
-13
lines changed

tools/perf/builtin-trace.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
#include "trace-event.h"
3535
#include "util/parse-events.h"
3636
#include "util/bpf-loader.h"
37+
#include "syscalltbl.h"
3738

38-
#include <libaudit.h>
39+
#include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */
3940
#include <stdlib.h>
4041
#include <sys/mman.h>
4142
#include <linux/futex.h>
@@ -114,10 +115,7 @@
114115

115116
struct trace {
116117
struct perf_tool tool;
117-
struct {
118-
int machine;
119-
int open_id;
120-
} audit;
118+
struct syscalltbl *sctbl;
121119
struct {
122120
int max;
123121
struct syscall *table;
@@ -163,6 +161,7 @@ struct trace {
163161
bool force;
164162
bool vfs_getname;
165163
int trace_pgfaults;
164+
int open_id;
166165
};
167166

168167
struct tp_field {
@@ -1780,7 +1779,7 @@ static int trace__read_syscall_info(struct trace *trace, int id)
17801779
{
17811780
char tp_name[128];
17821781
struct syscall *sc;
1783-
const char *name = audit_syscall_to_name(id, trace->audit.machine);
1782+
const char *name = syscalltbl__name(trace->sctbl, id);
17841783

17851784
if (name == NULL)
17861785
return -1;
@@ -1855,7 +1854,7 @@ static int trace__validate_ev_qualifier(struct trace *trace)
18551854

18561855
strlist__for_each(pos, trace->ev_qualifier) {
18571856
const char *sc = pos->s;
1858-
int id = audit_name_to_syscall(sc, trace->audit.machine);
1857+
int id = syscalltbl__id(trace->sctbl, sc);
18591858

18601859
if (id < 0) {
18611860
if (err == 0) {
@@ -2137,7 +2136,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
21372136

21382137
ret = perf_evsel__sc_tp_uint(evsel, ret, sample);
21392138

2140-
if (id == trace->audit.open_id && ret >= 0 && ttrace->filename.pending_open) {
2139+
if (id == trace->open_id && ret >= 0 && ttrace->filename.pending_open) {
21412140
trace__set_fd_pathname(thread, ret, ttrace->filename.name);
21422141
ttrace->filename.pending_open = false;
21432142
++trace->stats.vfs_getname;
@@ -3189,10 +3188,6 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
31893188
NULL
31903189
};
31913190
struct trace trace = {
3192-
.audit = {
3193-
.machine = audit_detect_machine(),
3194-
.open_id = audit_name_to_syscall("open", trace.audit.machine),
3195-
},
31963191
.syscalls = {
31973192
. max = -1,
31983193
},
@@ -3267,8 +3262,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
32673262
signal(SIGFPE, sighandler_dump_stack);
32683263

32693264
trace.evlist = perf_evlist__new();
3265+
trace.sctbl = syscalltbl__new();
32703266

3271-
if (trace.evlist == NULL) {
3267+
if (trace.evlist == NULL || trace.sctbl == NULL) {
32723268
pr_err("Not enough memory to run!\n");
32733269
err = -ENOMEM;
32743270
goto out;
@@ -3306,6 +3302,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
33063302
}
33073303
}
33083304

3305+
trace.open_id = syscalltbl__id(trace.sctbl, "open");
3306+
33093307
if (ev_qualifier_str != NULL) {
33103308
const char *s = ev_qualifier_str;
33113309
struct strlist_config slist_config = {

tools/perf/util/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ libperf-y += machine.o
3838
libperf-y += map.o
3939
libperf-y += pstack.o
4040
libperf-y += session.o
41+
libperf-$(CONFIG_AUDIT) += syscalltbl.o
4142
libperf-y += ordered-events.o
4243
libperf-y += comm.o
4344
libperf-y += thread.o

tools/perf/util/syscalltbl.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* System call table mapper
3+
*
4+
* (C) 2016 Arnaldo Carvalho de Melo <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or modify it
7+
* under the terms and conditions of the GNU General Public License,
8+
* version 2, as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13+
* more details.
14+
*/
15+
16+
#include "syscalltbl.h"
17+
#include <string.h>
18+
#include <libaudit.h>
19+
20+
21+
struct syscalltbl *syscalltbl__new(void)
22+
{
23+
struct syscalltbl *tbl = malloc(sizeof(*tbl));
24+
if (tbl) {
25+
tbl->audit_machine = audit_detect_machine();
26+
}
27+
return tbl;
28+
}
29+
30+
void syscalltbl__delete(struct syscalltbl *tbl)
31+
{
32+
free(tbl);
33+
}
34+
35+
const char *syscalltbl__name(const struct syscalltbl *tbl, int id)
36+
{
37+
return audit_syscall_to_name(id, tbl->audit_machine);
38+
}
39+
40+
int syscalltbl__id(struct syscalltbl *tbl, const char *name)
41+
{
42+
return audit_name_to_syscall(name, tbl->audit_machine);
43+
}

tools/perf/util/syscalltbl.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef __PERF_SYSCALLTBL_H
2+
#define __PERF_SYSCALLTBL_H
3+
4+
struct syscalltbl {
5+
union {
6+
int audit_machine;
7+
};
8+
};
9+
10+
struct syscalltbl *syscalltbl__new(void);
11+
void syscalltbl__delete(struct syscalltbl *tbl);
12+
13+
const char *syscalltbl__name(const struct syscalltbl *tbl, int id);
14+
int syscalltbl__id(struct syscalltbl *tbl, const char *name);
15+
16+
#endif /* __PERF_SYSCALLTBL_H */

0 commit comments

Comments
 (0)