From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Clark Williams <williams@redhat.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Adrian Hunter <adrian.hunter@intel.com>,
David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Wang Nan <wangnan0@huawei.com>
Subject: [PATCH 07/28] perf augmented_syscalls: Use pid_filter
Date: Thu, 22 Nov 2018 00:35:50 -0300 [thread overview]
Message-ID: <20181122033611.15890-8-acme@kernel.org> (raw)
In-Reply-To: <20181122033611.15890-1-acme@kernel.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Just to test filtering a bunch of pids, now its time to go and get that
hooked up in 'perf trace', right after we load the bpf program, if we
find a "pids_filtered" map defined, we'll populate it with the filtered
pids.
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: https://lkml.kernel.org/n/tip-1i9s27wqqdhafk3fappow84x@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/examples/bpf/augmented_raw_syscalls.c | 34 ++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/examples/bpf/augmented_raw_syscalls.c
index 7d729319618c..5fed1eff889d 100644
--- a/tools/perf/examples/bpf/augmented_raw_syscalls.c
+++ b/tools/perf/examples/bpf/augmented_raw_syscalls.c
@@ -16,6 +16,7 @@
#include <stdio.h>
#include <unistd.h>
+#include <pid_filter.h>
/* bpf-output associated map */
struct bpf_map SEC("maps") __augmented_syscalls__ = {
@@ -48,6 +49,29 @@ struct augmented_filename {
#define SYS_POLL 7
#define SYS_OPENAT 257
+pid_filter(pids_filtered);
+
+static void pid_filter__init(void)
+{
+ /*
+ * Filter a bunch of pids: gnome-shell, kvm, firefox threads,
+ * avahi-daemon, etc, just for testing as we go along.
+ *
+ * These will come from 'perf trace --filter-pids' in a explicit way
+ * and also it will filter out itself, to avoid the feedback loop:
+ * syscalls 'perf trace' does gets caught, reported, causing new
+ * syscalls to get emitted, rinse repeat forever.
+ */
+ if (pid_filter__add(&pids_filtered, 2971))
+ return; /* pid_filter__init() was already called, bail out */
+ pid_filter__add(&pids_filtered, 20016);
+ pid_filter__add(&pids_filtered, 12018);
+ pid_filter__add(&pids_filtered, 2310);
+ pid_filter__add(&pids_filtered, 3759);
+ pid_filter__add(&pids_filtered, 25978);
+ pid_filter__add(&pids_filtered, 883);
+}
+
SEC("raw_syscalls:sys_enter")
int sys_enter(struct syscall_enter_args *args)
{
@@ -57,8 +81,14 @@ int sys_enter(struct syscall_enter_args *args)
} augmented_args;
unsigned int len = sizeof(augmented_args);
const void *filename_arg = NULL;
+ /*
+ * We still don't have a "main()" called first and only once
+ * call it always, it will exit as soon as it realizes the
+ * first hard coded filtered pid was already added.
+ */
+ pid_filter__init();
- if (getpid() == 2971)
+ if (pid_filter__has(&pids_filtered, getpid()))
return 0;
probe_read(&augmented_args.args, sizeof(augmented_args.args), args);
@@ -132,7 +162,7 @@ int sys_enter(struct syscall_enter_args *args)
SEC("raw_syscalls:sys_exit")
int sys_exit(struct syscall_exit_args *args)
{
- return getpid() != 2971;
+ return !pid_filter__has(&pids_filtered, getpid());
}
license(GPL);
--
2.14.5
next prev parent reply other threads:[~2018-11-22 3:35 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-22 3:35 [GIT PULL 00/28] perf/core improvements and fixes Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 01/28] perf bpf: Add unistd.h to the headers accessible to bpf proggies Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 02/28] perf augmented_syscalls: Filter on a hard coded pid Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 03/28] perf augmented_syscalls: Remove needless linux/socket.h include Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 04/28] perf bpf: Add defines for map insertion/lookup Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 05/28] perf bpf: Add simple pid_filter class accessible to BPF proggies Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 06/28] perf augmented_syscalls: Drop 'write', 'poll' for testing without self pid filter Arnaldo Carvalho de Melo
2018-11-22 3:35 ` Arnaldo Carvalho de Melo [this message]
2018-11-22 3:35 ` [PATCH 08/28] perf evlist: Rename perf_evlist__set_filter* to perf_evlist__set_tp_filter* Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 09/28] perf trace: Add "_from_option" suffix to trace__set_filter() Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 10/28] perf trace: See if there is a map named "filtered_pids" Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 11/28] perf trace: Fill in BPF "filtered_pids" map when present Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 12/28] perf augmented_syscalls: Remove example hardcoded set of filtered pids Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 13/28] Revert "perf augmented_syscalls: Drop 'write', 'poll' for testing without self pid filter" Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 14/28] perf script: Add newline after uregs output Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 15/28] perf bpf: Reduce the hardcoded .max_entries for pid_maps Arnaldo Carvalho de Melo
2018-11-22 3:35 ` [PATCH 16/28] perf script: Share code and output format for uregs and iregs output Arnaldo Carvalho de Melo
2018-11-22 3:36 ` [PATCH 17/28] perf bench: Move HAVE_PTHREAD_ATTR_SETAFFINITY_NP into bench.h Arnaldo Carvalho de Melo
2018-11-22 3:36 ` [PATCH 18/28] tools build feature: Check if eventfd() is available Arnaldo Carvalho de Melo
2018-11-22 3:36 ` [PATCH 19/28] perf bench: Add epoll parallel epoll_wait benchmark Arnaldo Carvalho de Melo
2024-07-29 11:53 ` Like Xu
2018-11-22 3:36 ` [PATCH 20/28] perf bench: Add epoll_ctl(2) benchmark Arnaldo Carvalho de Melo
2018-11-22 3:36 ` [PATCH 21/28] perf tools: Add Hygon Dhyana support Arnaldo Carvalho de Melo
2018-11-22 3:36 ` [PATCH 22/28] perf pmu: Suppress potential format-truncation warning Arnaldo Carvalho de Melo
2018-11-22 3:36 ` [PATCH 23/28] perf stat: Use perf_evsel__is_clocki() for clock events Arnaldo Carvalho de Melo
2018-11-22 3:36 ` [PATCH 24/28] perf vendor events: Add stepping in CPUID string for x86 Arnaldo Carvalho de Melo
2018-11-22 3:36 ` [PATCH 26/28] perf jvmti: Separate jvmti cmlr check Arnaldo Carvalho de Melo
2018-11-22 3:36 ` [PATCH 27/28] perf symbols: Fix slowness due to -ffunction-section Arnaldo Carvalho de Melo
2018-11-22 3:36 ` [PATCH 28/28] perf pmu: Move *_cpuid_str() weak functions to header.c Arnaldo Carvalho de Melo
2018-11-22 6:54 ` [GIT PULL 00/28] 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=20181122033611.15890-8-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=dsahern@gmail.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=wangnan0@huawei.com \
--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).