mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-16 15:34:48 +08:00
ab6c79b819
If we execute 'perf stat --per-thread' with non-root account (even set kernel.perf_event_paranoid = -1 yet), it reports the error: jinyao@skl:~$ perf stat --per-thread Error: You may not have permission to collect system-wide stats. Consider tweaking /proc/sys/kernel/perf_event_paranoid, which controls use of the performance events system by unprivileged users (without CAP_SYS_ADMIN). The current value is 2: -1: Allow use of (almost) all events by all users Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK >= 0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN Disallow raw tracepoint access by users without CAP_SYS_ADMIN >= 1: Disallow CPU event access by users without CAP_SYS_ADMIN >= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN To make this setting permanent, edit /etc/sysctl.conf too, e.g.: kernel.perf_event_paranoid = -1 Perhaps the ptrace rule doesn't allow to trace some processes. But anyway the global --per-thread mode had better ignore such errors and continue working on other threads. This patch will record the index of error thread in perf_evsel__open() and remove this thread before retrying. For example (run with non-root, kernel.perf_event_paranoid isn't set): jinyao@skl:~$ perf stat --per-thread ^C Performance counter stats for 'system wide': vmstat-3458 6.171984 cpu-clock:u (msec) # 0.000 CPUs utilized perf-3670 0.515599 cpu-clock:u (msec) # 0.000 CPUs utilized vmstat-3458 1,163,643 cycles:u # 0.189 GHz perf-3670 40,881 cycles:u # 0.079 GHz vmstat-3458 1,410,238 instructions:u # 1.21 insn per cycle perf-3670 3,536 instructions:u # 0.09 insn per cycle vmstat-3458 288,937 branches:u # 46.814 M/sec perf-3670 936 branches:u # 1.815 M/sec vmstat-3458 15,195 branch-misses:u # 5.26% of all branches perf-3670 76 branch-misses:u # 8.12% of all branches 12.651675247 seconds time elapsed Signed-off-by: Jin Yao <yao.jin@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Kan Liang <kan.liang@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1516117388-10120-1-git-send-email-yao.jin@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
66 lines
1.7 KiB
C
66 lines
1.7 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __PERF_THREAD_MAP_H
|
|
#define __PERF_THREAD_MAP_H
|
|
|
|
#include <sys/types.h>
|
|
#include <stdio.h>
|
|
#include <linux/refcount.h>
|
|
|
|
struct thread_map_data {
|
|
pid_t pid;
|
|
char *comm;
|
|
};
|
|
|
|
struct thread_map {
|
|
refcount_t refcnt;
|
|
int nr;
|
|
int err_thread;
|
|
struct thread_map_data map[];
|
|
};
|
|
|
|
struct thread_map_event;
|
|
|
|
struct thread_map *thread_map__new_dummy(void);
|
|
struct thread_map *thread_map__new_by_pid(pid_t pid);
|
|
struct thread_map *thread_map__new_by_tid(pid_t tid);
|
|
struct thread_map *thread_map__new_by_uid(uid_t uid);
|
|
struct thread_map *thread_map__new_all_cpus(void);
|
|
struct thread_map *thread_map__new(pid_t pid, pid_t tid, uid_t uid);
|
|
struct thread_map *thread_map__new_event(struct thread_map_event *event);
|
|
|
|
struct thread_map *thread_map__get(struct thread_map *map);
|
|
void thread_map__put(struct thread_map *map);
|
|
|
|
struct thread_map *thread_map__new_str(const char *pid,
|
|
const char *tid, uid_t uid, bool all_threads);
|
|
|
|
struct thread_map *thread_map__new_by_tid_str(const char *tid_str);
|
|
|
|
size_t thread_map__fprintf(struct thread_map *threads, FILE *fp);
|
|
|
|
static inline int thread_map__nr(struct thread_map *threads)
|
|
{
|
|
return threads ? threads->nr : 1;
|
|
}
|
|
|
|
static inline pid_t thread_map__pid(struct thread_map *map, int thread)
|
|
{
|
|
return map->map[thread].pid;
|
|
}
|
|
|
|
static inline void
|
|
thread_map__set_pid(struct thread_map *map, int thread, pid_t pid)
|
|
{
|
|
map->map[thread].pid = pid;
|
|
}
|
|
|
|
static inline char *thread_map__comm(struct thread_map *map, int thread)
|
|
{
|
|
return map->map[thread].comm;
|
|
}
|
|
|
|
void thread_map__read_comms(struct thread_map *threads);
|
|
bool thread_map__has(struct thread_map *threads, pid_t pid);
|
|
int thread_map__remove(struct thread_map *threads, int idx);
|
|
#endif /* __PERF_THREAD_MAP_H */
|