Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1373770

[PATCH 15/19] perf trace: Move syscall table id <-> name routines to separate class

From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 15/19] perf trace: Move syscall table id <-> name routines to separate class
Date 2016-04-07 23:10 +0200
Message-ID <rlplG-1qw-29@gated-at.bofh.it> (permalink)
References <rlpbX-16R-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Arnaldo Carvalho de Melo <acme@redhat.com>

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 <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-i38opd09ow25mmyrvfwnbvkj@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-trace.c   | 24 +++++++++++-------------
 tools/perf/util/Build        |  1 +
 tools/perf/util/syscalltbl.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/syscalltbl.h | 16 ++++++++++++++++
 4 files changed, 71 insertions(+), 13 deletions(-)
 create mode 100644 tools/perf/util/syscalltbl.c
 create mode 100644 tools/perf/util/syscalltbl.h

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 8440e2b92c6c..11290b57ce04 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -34,8 +34,9 @@
 #include "trace-event.h"
 #include "util/parse-events.h"
 #include "util/bpf-loader.h"
+#include "syscalltbl.h"
 
-#include <libaudit.h>
+#include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */
 #include <stdlib.h>
 #include <sys/mman.h>
 #include <linux/futex.h>
@@ -114,10 +115,7 @@
 
 struct trace {
 	struct perf_tool	tool;
-	struct {
-		int		machine;
-		int		open_id;
-	}			audit;
+	struct syscalltbl	*sctbl;
 	struct {
 		int		max;
 		struct syscall  *table;
@@ -163,6 +161,7 @@ struct trace {
 	bool			force;
 	bool			vfs_getname;
 	int			trace_pgfaults;
+	int			open_id;
 };
 
 struct tp_field {
@@ -1780,7 +1779,7 @@ static int trace__read_syscall_info(struct trace *trace, int id)
 {
 	char tp_name[128];
 	struct syscall *sc;
-	const char *name = audit_syscall_to_name(id, trace->audit.machine);
+	const char *name = syscalltbl__name(trace->sctbl, id);
 
 	if (name == NULL)
 		return -1;
@@ -1855,7 +1854,7 @@ static int trace__validate_ev_qualifier(struct trace *trace)
 
 	strlist__for_each(pos, trace->ev_qualifier) {
 		const char *sc = pos->s;
-		int id = audit_name_to_syscall(sc, trace->audit.machine);
+		int id = syscalltbl__id(trace->sctbl, sc);
 
 		if (id < 0) {
 			if (err == 0) {
@@ -2137,7 +2136,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
 
 	ret = perf_evsel__sc_tp_uint(evsel, ret, sample);
 
-	if (id == trace->audit.open_id && ret >= 0 && ttrace->filename.pending_open) {
+	if (id == trace->open_id && ret >= 0 && ttrace->filename.pending_open) {
 		trace__set_fd_pathname(thread, ret, ttrace->filename.name);
 		ttrace->filename.pending_open = false;
 		++trace->stats.vfs_getname;
@@ -3189,10 +3188,6 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 		NULL
 	};
 	struct trace trace = {
-		.audit = {
-			.machine = audit_detect_machine(),
-			.open_id = audit_name_to_syscall("open", trace.audit.machine),
-		},
 		.syscalls = {
 			. max = -1,
 		},
@@ -3267,8 +3262,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 	signal(SIGFPE, sighandler_dump_stack);
 
 	trace.evlist = perf_evlist__new();
+	trace.sctbl = syscalltbl__new();
 
-	if (trace.evlist == NULL) {
+	if (trace.evlist == NULL || trace.sctbl == NULL) {
 		pr_err("Not enough memory to run!\n");
 		err = -ENOMEM;
 		goto out;
@@ -3306,6 +3302,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 		}
 	}
 
+	trace.open_id = syscalltbl__id(trace.sctbl, "open");
+
 	if (ev_qualifier_str != NULL) {
 		const char *s = ev_qualifier_str;
 		struct strlist_config slist_config = {
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 85ceff357769..3443646d8da3 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -38,6 +38,7 @@ libperf-y += machine.o
 libperf-y += map.o
 libperf-y += pstack.o
 libperf-y += session.o
+libperf-$(CONFIG_AUDIT) += syscalltbl.o
 libperf-y += ordered-events.o
 libperf-y += comm.o
 libperf-y += thread.o
diff --git a/tools/perf/util/syscalltbl.c b/tools/perf/util/syscalltbl.c
new file mode 100644
index 000000000000..1f13e57412eb
--- /dev/null
+++ b/tools/perf/util/syscalltbl.c
@@ -0,0 +1,43 @@
+/*
+ * System call table mapper
+ *
+ * (C) 2016 Arnaldo Carvalho de Melo <acme@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include "syscalltbl.h"
+#include <string.h>
+#include <libaudit.h>
+
+
+struct syscalltbl *syscalltbl__new(void)
+{
+	struct syscalltbl *tbl = malloc(sizeof(*tbl));
+	if (tbl) {
+		tbl->audit_machine = audit_detect_machine();
+	}
+	return tbl;
+}
+
+void syscalltbl__delete(struct syscalltbl *tbl)
+{
+	free(tbl);
+}
+
+const char *syscalltbl__name(const struct syscalltbl *tbl, int id)
+{
+	return audit_syscall_to_name(id, tbl->audit_machine);
+}
+
+int syscalltbl__id(struct syscalltbl *tbl, const char *name)
+{
+	return audit_name_to_syscall(name, tbl->audit_machine);
+}
diff --git a/tools/perf/util/syscalltbl.h b/tools/perf/util/syscalltbl.h
new file mode 100644
index 000000000000..9dee73c2e082
--- /dev/null
+++ b/tools/perf/util/syscalltbl.h
@@ -0,0 +1,16 @@
+#ifndef __PERF_SYSCALLTBL_H
+#define __PERF_SYSCALLTBL_H
+
+struct syscalltbl {
+	union {
+		int audit_machine;
+	};
+};
+
+struct syscalltbl *syscalltbl__new(void);
+void syscalltbl__delete(struct syscalltbl *tbl);
+
+const char *syscalltbl__name(const struct syscalltbl *tbl, int id);
+int syscalltbl__id(struct syscalltbl *tbl, const char *name);
+
+#endif /* __PERF_SYSCALLTBL_H */
-- 
2.5.5

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL 00/19] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:00 +0200
  [PATCH 04/19] perf tools: Remove superfluous ARCH Makefile includes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:00 +0200
  [PATCH 18/19] perf symbols: Record text offset in dso to calculate objdump address Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:00 +0200
  [PATCH 08/19] perf trace: Infrastructure to show COMM strings for syscalls returning PIDs Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:00 +0200
  [PATCH 01/19] perf config: Fix build with older toolchain. Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 11/19] perf tools: Introduce trim function Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 03/19] perf script perl: Do error checking on new backtrace routine Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 06/19] perf trace: Beautify sched_setscheduler 'policy' argument Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 07/19] perf trace: Beautify wait4/waitid 'options' argument Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 09/19] perf trace: Beautify set_tid_address, getpid, getppid return values Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 15/19] perf trace: Move syscall table id <-> name routines to separate class Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 14/19] perf trace: Beautify mode_t arguments Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 12/19] perf tools: Add dedicated unwind addr_space member into thread struct Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 13/19] perf script: Process event update events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 16/19] perf tools: Allow generating per-arch syscall table arrays Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 05/19] perf list: Document event specifications better Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 02/19] perf probe: Check if dwarf_getlocations() is available Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 10/19] perf trace: Beautify pid_t arguments Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  Re: [GIT PULL 00/19] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-08 15:20 +0200
    Re: [GIT PULL 00/19] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2016-04-13 09:00 +0200

csiph-web