lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20210926021611.2312331-1-jinshan.xiong@gmail.com>
Date:   Sat, 25 Sep 2021 19:15:25 -0700
From:   Jinshan Xiong <jinshan.xiong@...il.com>
To:     jolsa@...hat.com
Cc:     Jinshan Xiong <jinshan.xiong@...il.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Namhyung Kim <namhyung@...nel.org>,
        linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] tools/lib/perf: add a flag to specify cgroup fd

This patch adds an API perf_thread_map__set_flags() so that we can use
it to pass down a flag to specific cgroup fd in sys_perf_event_open().

This API can be used in the following way:
    int cgroup_fd = open("/sys/fs/cgroup/perf_event", O_RDONLY);
    struct thread_map *threadmap = perf_thread_map__new_dummy();
    perf_thread_map__set_pid(threadmap, 0, cgroup_fd);
    perf_thread_map__set_flags(threadmap, 0, PERF_FLAG_PID_CGROUP);

Therefore, we can only collect perf events in a specific docker
container.

Signed-off-by: Jinshan Xiong <jinshan.xiong@...il.com>
---
 tools/lib/perf/evsel.c                      | 3 ++-
 tools/lib/perf/include/internal/threadmap.h | 1 +
 tools/lib/perf/include/perf/threadmap.h     | 1 +
 tools/lib/perf/threadmap.c                  | 5 +++++
 4 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
index 8441e3e1aaac..67f86513a816 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -153,7 +153,8 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
 
 			fd = sys_perf_event_open(&evsel->attr,
 						 threads->map[thread].pid,
-						 cpus->map[cpu], group_fd, 0);
+						 cpus->map[cpu], group_fd,
+						 threads->map[thread].flags);
 
 			if (fd < 0)
 				return -errno;
diff --git a/tools/lib/perf/include/internal/threadmap.h b/tools/lib/perf/include/internal/threadmap.h
index df748baf9eda..5d7bd6968563 100644
--- a/tools/lib/perf/include/internal/threadmap.h
+++ b/tools/lib/perf/include/internal/threadmap.h
@@ -8,6 +8,7 @@
 
 struct thread_map_data {
 	pid_t	 pid;
+	int	 flags;
 	char	*comm;
 };
 
diff --git a/tools/lib/perf/include/perf/threadmap.h b/tools/lib/perf/include/perf/threadmap.h
index a7c50de8d010..5fea1a403e28 100644
--- a/tools/lib/perf/include/perf/threadmap.h
+++ b/tools/lib/perf/include/perf/threadmap.h
@@ -10,6 +10,7 @@ struct perf_thread_map;
 LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void);
 
 LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid);
+LIBPERF_API void perf_thread_map__set_flags(struct perf_thread_map *map, int thread, int flags);
 LIBPERF_API char *perf_thread_map__comm(struct perf_thread_map *map, int thread);
 LIBPERF_API int perf_thread_map__nr(struct perf_thread_map *threads);
 LIBPERF_API pid_t perf_thread_map__pid(struct perf_thread_map *map, int thread);
diff --git a/tools/lib/perf/threadmap.c b/tools/lib/perf/threadmap.c
index e92c368b0a6c..3b8ec4f944b9 100644
--- a/tools/lib/perf/threadmap.c
+++ b/tools/lib/perf/threadmap.c
@@ -37,6 +37,11 @@ void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid
 	map->map[thread].pid = pid;
 }
 
+void perf_thread_map__set_flags(struct perf_thread_map *map, int thread, int flags)
+{
+	map->map[thread].flags = flags;
+}
+
 char *perf_thread_map__comm(struct perf_thread_map *map, int thread)
 {
 	return map->map[thread].comm;
-- 
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ