linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>, Thomas Gleixner <tglx@linutronix.de>
Cc: Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 11/33] perf augmented_raw_syscalls: Introduce helper to get the scratch space
Date: Mon, 26 Aug 2019 22:36:12 -0300	[thread overview]
Message-ID: <20190827013634.3173-12-acme@kernel.org> (raw)
In-Reply-To: <20190827013634.3173-1-acme@kernel.org>

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

We need more than the BPF stack can give us to format the
raw_syscalls:sys_enter augmented tracepoint, so we use a PERCPU_ARRAY
map for that, use a helper to shorten the sequence to access that area.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 .../examples/bpf/augmented_raw_syscalls.c     | 32 +++++++++----------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/examples/bpf/augmented_raw_syscalls.c
index 0a8d217d65c7..8fd5ea059903 100644
--- a/tools/perf/examples/bpf/augmented_raw_syscalls.c
+++ b/tools/perf/examples/bpf/augmented_raw_syscalls.c
@@ -78,8 +78,15 @@ struct augmented_args_payload {
 	};
 };
 
+// We need more tmp space than the BPF stack can give us
 bpf_map(augmented_args_tmp, PERCPU_ARRAY, int, struct augmented_args_payload, 1);
 
+static inline struct augmented_args_payload *augmented_args_payload(void)
+{
+	int key = 0;
+	return bpf_map_lookup_elem(&augmented_args_tmp, &key);
+}
+
 static inline
 unsigned int augmented_arg__read_str(struct augmented_arg *augmented_arg, const void *arg, unsigned int arg_len)
 {
@@ -122,8 +129,7 @@ int syscall_unaugmented(struct syscall_enter_args *args)
 SEC("!syscalls:sys_enter_connect")
 int sys_enter_connect(struct syscall_enter_args *args)
 {
-	int key = 0;
-	struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key);
+	struct augmented_args_payload *augmented_args = augmented_args_payload();
 	const void *sockaddr_arg = (const void *)args->args[1];
 	unsigned int socklen = args->args[2];
 	unsigned int len = sizeof(augmented_args->args);
@@ -143,8 +149,7 @@ int sys_enter_connect(struct syscall_enter_args *args)
 SEC("!syscalls:sys_enter_sendto")
 int sys_enter_sendto(struct syscall_enter_args *args)
 {
-	int key = 0;
-	struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key);
+	struct augmented_args_payload *augmented_args = augmented_args_payload();
 	const void *sockaddr_arg = (const void *)args->args[4];
 	unsigned int socklen = args->args[5];
 	unsigned int len = sizeof(augmented_args->args);
@@ -164,8 +169,7 @@ int sys_enter_sendto(struct syscall_enter_args *args)
 SEC("!syscalls:sys_enter_open")
 int sys_enter_open(struct syscall_enter_args *args)
 {
-	int key = 0;
-	struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key);
+	struct augmented_args_payload *augmented_args = augmented_args_payload();
 	const void *filename_arg = (const void *)args->args[0];
 	unsigned int len = sizeof(augmented_args->args);
 
@@ -181,8 +185,7 @@ int sys_enter_open(struct syscall_enter_args *args)
 SEC("!syscalls:sys_enter_openat")
 int sys_enter_openat(struct syscall_enter_args *args)
 {
-	int key = 0;
-	struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key);
+	struct augmented_args_payload *augmented_args = augmented_args_payload();
 	const void *filename_arg = (const void *)args->args[1];
 	unsigned int len = sizeof(augmented_args->args);
 
@@ -198,8 +201,7 @@ int sys_enter_openat(struct syscall_enter_args *args)
 SEC("!syscalls:sys_enter_rename")
 int sys_enter_rename(struct syscall_enter_args *args)
 {
-	int key = 0;
-	struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key);
+	struct augmented_args_payload *augmented_args = augmented_args_payload();
 	const void *oldpath_arg = (const void *)args->args[0],
 		   *newpath_arg = (const void *)args->args[1];
 	unsigned int len = sizeof(augmented_args->args), oldpath_len;
@@ -217,8 +219,7 @@ int sys_enter_rename(struct syscall_enter_args *args)
 SEC("!syscalls:sys_enter_renameat")
 int sys_enter_renameat(struct syscall_enter_args *args)
 {
-	int key = 0;
-	struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key);
+	struct augmented_args_payload *augmented_args = augmented_args_payload();
 	const void *oldpath_arg = (const void *)args->args[1],
 		   *newpath_arg = (const void *)args->args[3];
 	unsigned int len = sizeof(augmented_args->args), oldpath_len;
@@ -248,14 +249,13 @@ int sys_enter(struct syscall_enter_args *args)
 	 */
 	unsigned int len = sizeof(augmented_args->args);
 	struct syscall *syscall;
-	int key = 0;
 
 	if (pid_filter__has(&pids_filtered, getpid()))
 		return 0;
 
-        augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key);
-        if (augmented_args == NULL)
-                return 1;
+	augmented_args = augmented_args_payload();
+	if (augmented_args == NULL)
+		return 1;
 
 	probe_read(&augmented_args->args, sizeof(augmented_args->args), args);
 
-- 
2.21.0

  parent reply	other threads:[~2019-08-27  1:36 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-27  1:36 [GIT PULL] perf/core improvements and fixes Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 01/33] perf cpumap: No need to include perf.h, ditch it Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 02/33] perf stat: Remove needless headers from stat.h Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 03/33] perf record: Move record_opts and other record decls out of perf.h Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 04/33] perf cacheline: Move cacheline related routines to separate files Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 05/33] perf srcline: Add missing srcline.h header to files needing its defs Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 06/33] perf sort: Remove needless headers from sort.h, provide fwd struct decls Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 07/33] perf tests: Fixes hang in zstd compression test by changing the source of random data Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 08/33] perf trace beauty ioctl: Fix off-by-one error in cmd->string table Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 09/33] perf augmented_raw_syscalls: Rename augmented_filename to augmented_arg Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 10/33] perf augmented_raw_syscalls: Postpone tmp map lookup to after pid_filter Arnaldo Carvalho de Melo
2019-08-27  1:36 ` Arnaldo Carvalho de Melo [this message]
2019-08-27  1:36 ` [PATCH 12/33] perf augmented_raw_syscalls: Reduce perf_event_output() boilerplate Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 13/33] perf tools: Remove duplicate headers Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 14/33] perf report: Use timestamp__scnprintf_nsec() for time sort key Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 15/33] perf report: Fix --ns time sort key output Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 16/33] perf script: Fix memory leaks in list_scripts() Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 17/33] libperf: Add PERF_RECORD_MMAP 'struct mmap_event' to perf/event.h Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 18/33] libperf: Add PERF_RECORD_MMAP2 'struct mmap2_event' " Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 19/33] libperf: Add PERF_RECORD_COMM 'struct comm_event' " Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 20/33] libperf: Add PERF_RECORD_NAMESPACES 'struct namespaces_event' " Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 21/33] libperf: Add PERF_RECORD_FORK 'struct fork_event' " Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 22/33] libperf: Add PERF_RECORD_LOST 'struct lost_event' " Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 23/33] libperf: Add PERF_RECORD_LOST_SAMPLES 'struct lost_samples_event' " Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 24/33] libperf: Add PERF_RECORD_READ 'struct read_event' " Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 25/33] libperf: Add PERF_RECORD_THROTTLE 'struct throttle_event' " Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 26/33] libperf: Add PERF_RECORD_KSYMBOL 'struct ksymbol_event' " Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 27/33] libperf: Add PERF_RECORD_BPF_EVENT 'struct bpf_event' " Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 28/33] libperf: Add PERF_RECORD_SAMPLE 'struct sample_event' " Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 29/33] libperf: Rename the PERF_RECORD_ structs to have a "perf" suffix Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 30/33] perf tools: Rename perf_event::ksymbol_event to perf_event::ksymbol Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 31/33] perf tools: Rename perf_event::bpf_event to perf_event::bpf Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 32/33] perf tool: Rename perf_tool::bpf_event to bpf Arnaldo Carvalho de Melo
2019-08-27  1:36 ` [PATCH 33/33] perf evsel: Rename perf_missing_features::bpf_event to ::bpf Arnaldo Carvalho de Melo
2019-08-27  8:24 ` [GIT PULL] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190827013634.3173-12-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).