2011-01-12 06:56:53 +08:00
|
|
|
#ifndef __PERF_EVLIST_H
|
|
|
|
#define __PERF_EVLIST_H 1
|
|
|
|
|
2017-06-16 22:39:15 +08:00
|
|
|
#include <linux/compiler.h>
|
2017-04-17 22:39:06 +08:00
|
|
|
#include <linux/kernel.h>
|
2017-02-21 23:35:01 +08:00
|
|
|
#include <linux/refcount.h>
|
2011-01-12 06:56:53 +08:00
|
|
|
#include <linux/list.h>
|
2014-09-04 05:02:59 +08:00
|
|
|
#include <api/fd/array.h>
|
2011-11-04 19:10:59 +08:00
|
|
|
#include <stdio.h>
|
2011-01-13 08:39:13 +08:00
|
|
|
#include "../perf.h"
|
2011-01-15 20:40:59 +08:00
|
|
|
#include "event.h"
|
2012-08-15 03:42:15 +08:00
|
|
|
#include "evsel.h"
|
2011-11-04 19:10:59 +08:00
|
|
|
#include "util.h"
|
2015-04-09 23:53:42 +08:00
|
|
|
#include "auxtrace.h"
|
2017-04-20 02:49:18 +08:00
|
|
|
#include <signal.h>
|
2011-11-09 18:47:15 +08:00
|
|
|
#include <unistd.h>
|
2011-01-12 06:56:53 +08:00
|
|
|
|
2011-01-12 08:30:02 +08:00
|
|
|
struct pollfd;
|
2011-01-30 20:46:46 +08:00
|
|
|
struct thread_map;
|
|
|
|
struct cpu_map;
|
2013-12-20 01:43:45 +08:00
|
|
|
struct record_opts;
|
2011-01-12 08:30:02 +08:00
|
|
|
|
2011-01-13 08:39:13 +08:00
|
|
|
#define PERF_EVLIST__HLIST_BITS 8
|
|
|
|
#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
|
|
|
|
|
2014-09-09 00:26:35 +08:00
|
|
|
/**
|
|
|
|
* struct perf_mmap - perf's ring buffer mmap details
|
|
|
|
*
|
|
|
|
* @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
|
|
|
|
*/
|
2013-02-06 05:12:42 +08:00
|
|
|
struct perf_mmap {
|
|
|
|
void *base;
|
|
|
|
int mask;
|
2016-05-21 00:38:24 +08:00
|
|
|
int fd;
|
2017-02-21 23:35:01 +08:00
|
|
|
refcount_t refcnt;
|
2015-04-07 23:20:37 +08:00
|
|
|
u64 prev;
|
2015-04-09 23:53:42 +08:00
|
|
|
struct auxtrace_mmap auxtrace_mmap;
|
2017-06-16 22:39:15 +08:00
|
|
|
char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
|
2013-02-06 05:12:42 +08:00
|
|
|
};
|
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
static inline size_t
|
|
|
|
perf_mmap__mmap_len(struct perf_mmap *map)
|
|
|
|
{
|
|
|
|
return map->mask + 1 + page_size;
|
|
|
|
}
|
|
|
|
|
2016-07-14 16:34:42 +08:00
|
|
|
/*
|
|
|
|
* State machine of bkw_mmap_state:
|
|
|
|
*
|
|
|
|
* .________________(forbid)_____________.
|
|
|
|
* | V
|
|
|
|
* NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
|
|
|
|
* ^ ^ | ^ |
|
|
|
|
* | |__(forbid)____/ |___(forbid)___/|
|
|
|
|
* | |
|
|
|
|
* \_________________(3)_______________/
|
|
|
|
*
|
|
|
|
* NOTREADY : Backward ring buffers are not ready
|
|
|
|
* RUNNING : Backward ring buffers are recording
|
|
|
|
* DATA_PENDING : We are required to collect data from backward ring buffers
|
|
|
|
* EMPTY : We have collected data from backward ring buffers.
|
|
|
|
*
|
|
|
|
* (0): Setup backward ring buffer
|
|
|
|
* (1): Pause ring buffers for reading
|
|
|
|
* (2): Read from ring buffers
|
|
|
|
* (3): Resume ring buffers for recording
|
|
|
|
*/
|
|
|
|
enum bkw_mmap_state {
|
|
|
|
BKW_MMAP_NOTREADY,
|
|
|
|
BKW_MMAP_RUNNING,
|
|
|
|
BKW_MMAP_DATA_PENDING,
|
|
|
|
BKW_MMAP_EMPTY,
|
|
|
|
};
|
|
|
|
|
2011-01-12 06:56:53 +08:00
|
|
|
struct perf_evlist {
|
|
|
|
struct list_head entries;
|
2011-01-13 08:39:13 +08:00
|
|
|
struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
|
2011-01-12 06:56:53 +08:00
|
|
|
int nr_entries;
|
2013-01-22 17:09:29 +08:00
|
|
|
int nr_groups;
|
perf evlist: Fix per thread mmap setup
The PERF_EVENT_IOC_SET_OUTPUT ioctl was returning -EINVAL when using
--pid when monitoring multithreaded apps, as we can only share a ring
buffer for events on the same thread if not doing per cpu.
Fix it by using per thread ring buffers.
Tested with:
[root@felicio ~]# tuna -t 26131 -CP | nl
1 thread ctxt_switches
2 pid SCHED_ rtpri affinity voluntary nonvoluntary cmd
3 26131 OTHER 0 0,1 10814276 2397830 chromium-browse
4 642 OTHER 0 0,1 14688 0 chromium-browse
5 26148 OTHER 0 0,1 713602 115479 chromium-browse
6 26149 OTHER 0 0,1 801958 2262 chromium-browse
7 26150 OTHER 0 0,1 1271128 248 chromium-browse
8 26151 OTHER 0 0,1 3 0 chromium-browse
9 27049 OTHER 0 0,1 36796 9 chromium-browse
10 618 OTHER 0 0,1 14711 0 chromium-browse
11 661 OTHER 0 0,1 14593 0 chromium-browse
12 29048 OTHER 0 0,1 28125 0 chromium-browse
13 26143 OTHER 0 0,1 2202789 781 chromium-browse
[root@felicio ~]#
So 11 threads under pid 26131, then:
[root@felicio ~]# perf record -F 50000 --pid 26131
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fa4a2538000-7fa4a25b9000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fa4a25b9000-7fa4a263a000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
3 7fa4a263a000-7fa4a26bb000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
4 7fa4a26bb000-7fa4a273c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
5 7fa4a273c000-7fa4a27bd000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
6 7fa4a27bd000-7fa4a283e000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
7 7fa4a283e000-7fa4a28bf000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
8 7fa4a28bf000-7fa4a2940000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
9 7fa4a2940000-7fa4a29c1000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
10 7fa4a29c1000-7fa4a2a42000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
11 7fa4a2a42000-7fa4a2ac3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
11 mmaps, one per thread since we didn't specify any CPU list, so we need one
mmap per thread and:
[root@felicio ~]# perf record -F 50000 --pid 26131
^M
^C[ perf record: Woken up 79 times to write data ]
[ perf record: Captured and wrote 20.614 MB perf.data (~900639 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 371310 26131
2 96516 26148
3 95694 26149
4 95203 26150
5 7291 26143
6 87 27049
7 76 661
8 60 29048
9 47 618
10 43 642
[root@felicio ~]#
Ok, one of the threads, 26151 was quiescent, so no samples there, but all the
others are there.
Then, if I specify one CPU:
[root@felicio ~]# perf record -F 50000 --pid 26131 --cpu 1
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.680 MB perf.data (~29730 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 8444 26131
2 2584 26149
3 2518 26148
4 2324 26150
5 123 26143
6 9 661
7 9 29048
[root@felicio ~]#
This machine has two cores, so fewer threads appeared on the radar, and:
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f484b922000-7f484b9a3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Just one mmap, as now we can use just one per-cpu buffer instead of the
per-thread needed in the previous case.
For global profiling:
[root@felicio ~]# perf record -F 50000 -a
^C[ perf record: Woken up 26 times to write data ]
[ perf record: Captured and wrote 7.128 MB perf.data (~311412 samples) ]
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fb49b435000-7fb49b4b6000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fb49b4b6000-7fb49b537000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
It uses per-cpu buffers.
For just one thread:
[root@felicio ~]# perf record -F 50000 --tid 26148
^C[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.330 MB perf.data (~14426 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 9969 26148
[root@felicio ~]#
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f286a51b000-7f286a59c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Tested-by: David Ahern <dsahern@gmail.com>
Tested-by: Lin Ming <ming.m.lin@intel.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/r/20110426204401.GB1746@ghostprotocols.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-15 20:39:00 +08:00
|
|
|
int nr_mmaps;
|
perf tools: Elliminate alignment holes
perf_evsel:
Before:
/* size: 320, cachelines: 5, members: 35 */
/* sum members: 304, holes: 3, sum holes: 16 */
After:
/* size: 304, cachelines: 5, members: 35 */
/* last cacheline: 48 bytes */
perf_evlist:
Before:
/* size: 2544, cachelines: 40, members: 17 */
/* sum members: 2533, holes: 2, sum holes: 11 */
/* last cacheline: 48 bytes */
After:
/* size: 2536, cachelines: 40, members: 17 */
/* sum members: 2533, holes: 1, sum holes: 3 */
/* last cacheline: 40 bytes */
timechart:
Before:
/* size: 288, cachelines: 5, members: 21 */
/* sum members: 271, holes: 2, sum holes: 10 */
/* padding: 7 */
/* last cacheline: 32 bytes */
After:
/* size: 272, cachelines: 5, members: 21 */
/* sum members: 271, holes: 1, sum holes: 1 */
/* last cacheline: 16 bytes */
thread:
Before:
/* size: 112, cachelines: 2, members: 15 */
/* sum members: 101, holes: 2, sum holes: 11 */
/* last cacheline: 48 bytes */
After:
/* size: 104, cachelines: 2, members: 15 */
/* sum members: 101, holes: 1, sum holes: 3 */
/* last cacheline: 40 bytes */
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-a543w7zjl9yyrg9nkf1teukp@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-05-16 04:29:56 +08:00
|
|
|
bool overwrite;
|
2015-06-18 03:40:26 +08:00
|
|
|
bool enabled;
|
2015-09-08 15:58:52 +08:00
|
|
|
bool has_user_cpus;
|
2013-09-01 18:36:12 +08:00
|
|
|
size_t mmap_len;
|
2013-08-27 16:23:09 +08:00
|
|
|
int id_pos;
|
|
|
|
int is_pos;
|
|
|
|
u64 combined_sample_type;
|
2016-07-14 16:34:42 +08:00
|
|
|
enum bkw_mmap_state bkw_mmap_state;
|
2011-11-09 18:47:15 +08:00
|
|
|
struct {
|
|
|
|
int cork_fd;
|
|
|
|
pid_t pid;
|
|
|
|
} workload;
|
2014-09-04 05:02:59 +08:00
|
|
|
struct fdarray pollfd;
|
2011-01-13 08:39:13 +08:00
|
|
|
struct perf_mmap *mmap;
|
2016-07-14 16:34:39 +08:00
|
|
|
struct perf_mmap *backward_mmap;
|
2011-01-30 21:59:43 +08:00
|
|
|
struct thread_map *threads;
|
|
|
|
struct cpu_map *cpus;
|
2011-10-06 06:11:32 +08:00
|
|
|
struct perf_evsel *selected;
|
2015-02-15 01:50:11 +08:00
|
|
|
struct events_stats stats;
|
2015-08-28 17:48:05 +08:00
|
|
|
struct perf_env *env;
|
2011-01-12 06:56:53 +08:00
|
|
|
};
|
|
|
|
|
perf tools: Save some loops using perf_evlist__id2evsel
Since we already ask for PERF_SAMPLE_ID and use it to quickly find the
associated evsel, add handler func + data to struct perf_evsel to avoid
using chains of if(strcmp(event_name)) and also to avoid all the linear
list searches via trace_event_find.
To demonstrate the technique convert 'perf sched' to it:
# perf sched record sleep 5m
And then:
Performance counter stats for '/tmp/oldperf sched lat':
646.929438 task-clock # 0.999 CPUs utilized
9 context-switches # 0.000 M/sec
0 CPU-migrations # 0.000 M/sec
20,901 page-faults # 0.032 M/sec
1,290,144,450 cycles # 1.994 GHz
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
1,606,158,439 instructions # 1.24 insns per cycle
339,088,395 branches # 524.151 M/sec
4,550,735 branch-misses # 1.34% of all branches
0.647524759 seconds time elapsed
Versus:
Performance counter stats for 'perf sched lat':
473.564691 task-clock # 0.999 CPUs utilized
9 context-switches # 0.000 M/sec
0 CPU-migrations # 0.000 M/sec
20,903 page-faults # 0.044 M/sec
944,367,984 cycles # 1.994 GHz
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
1,442,385,571 instructions # 1.53 insns per cycle
308,383,106 branches # 651.195 M/sec
4,481,784 branch-misses # 1.45% of all branches
0.474215751 seconds time elapsed
[root@emilia ~]#
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-1kbzpl74lwi6lavpqke2u2p3@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-11-29 03:57:40 +08:00
|
|
|
struct perf_evsel_str_handler {
|
|
|
|
const char *name;
|
|
|
|
void *handler;
|
|
|
|
};
|
|
|
|
|
2013-03-11 15:43:12 +08:00
|
|
|
struct perf_evlist *perf_evlist__new(void);
|
2013-09-01 18:36:14 +08:00
|
|
|
struct perf_evlist *perf_evlist__new_default(void);
|
2016-01-08 00:14:56 +08:00
|
|
|
struct perf_evlist *perf_evlist__new_dummy(void);
|
2011-01-30 21:59:43 +08:00
|
|
|
void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
|
|
|
|
struct thread_map *threads);
|
2011-01-19 07:41:45 +08:00
|
|
|
void perf_evlist__exit(struct perf_evlist *evlist);
|
2011-01-12 06:56:53 +08:00
|
|
|
void perf_evlist__delete(struct perf_evlist *evlist);
|
|
|
|
|
|
|
|
void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry);
|
2015-09-25 21:15:53 +08:00
|
|
|
void perf_evlist__remove(struct perf_evlist *evlist, struct perf_evsel *evsel);
|
2017-07-04 00:10:20 +08:00
|
|
|
|
|
|
|
int __perf_evlist__add_default(struct perf_evlist *evlist, bool precise);
|
|
|
|
|
|
|
|
static inline int perf_evlist__add_default(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
return __perf_evlist__add_default(evlist, true);
|
|
|
|
}
|
|
|
|
|
perf stat: Initialize default events wrt exclude_{guest,host}
When no event is specified the tools use perf_evlist__add_default(), that will
call event_attr_init to initialize the KVM exclusion bits.
When the change was made to the tools so that by default guest samples would be
excluded, the changes were made just to the parsing routines and to
perf_evlist__add_default(), not to perf_evlist__add_attrs, that is used so far
just by perf stat to add multiple events, according to the level of detail
specified.
Recently the tools were changed to reconstruct the event name from all the
details in perf_event_attr, not just from .type and .config, but taking into
account all the feature bits (.exclude_{guest,host,user,kernel,etc},
.precise_ip, etc).
That is when we noticed that the default for perf stat wasn't the one for the
rest of the tools, i.e. the .exclude_guest bit wasn't being set.
I.e. the default, that doesn't call event_attr_init was showing the :HG
modifier:
$ perf stat usleep 1
Performance counter stats for 'usleep 1':
0.942119 task-clock # 0.454 CPUs utilized
1 context-switches # 0.001 M/sec
0 CPU-migrations # 0.000 K/sec
126 page-faults # 0.134 M/sec
693,193 cycles:HG # 0.736 GHz [40.11%]
407,461 stalled-cycles-frontend:HG # 58.78% frontend cycles idle [72.29%]
365,403 stalled-cycles-backend:HG # 52.71% backend cycles idle
465,982 instructions:HG # 0.67 insns per cycle
# 0.87 stalled cycles per insn
89,760 branches:HG # 95.275 M/sec
6,178 branch-misses:HG # 6.88% of all branches
0.002077228 seconds time elapsed
While if one explicitely specifies the same events, which will make the parsing code
to be called and thus event_attr_init is called:
$ perf stat -e task-clock,context-switches,migrations,page-faults,cycles,stalled-cycles-frontend,stalled-cycles-backend,instructions,branches,branch-misses usleep 1
Performance counter stats for 'usleep 1':
1.040349 task-clock # 0.500 CPUs utilized
2 context-switches # 0.002 M/sec
0 CPU-migrations # 0.000 K/sec
127 page-faults # 0.122 M/sec
587,966 cycles # 0.565 GHz [13.18%]
459,167 stalled-cycles-frontend # 78.09% frontend cycles idle
390,249 stalled-cycles-backend # 66.37% backend cycles idle
504,006 instructions # 0.86 insns per cycle
# 0.91 stalled cycles per insn
96,455 branches # 92.714 M/sec
6,522 branch-misses # 6.76% of all branches [96.12%]
0.002078681 seconds time elapsed
Fix it by introducing a perf_evlist__add_default_attrs method that will call
evlist_attr_init in all the perf_event_attr entries before adding the events.
Reported-by: Ingo Molnar <mingo@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-4eysr236r0pgiyum9epwxw7s@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-05-31 00:53:54 +08:00
|
|
|
int __perf_evlist__add_default_attrs(struct perf_evlist *evlist,
|
|
|
|
struct perf_event_attr *attrs, size_t nr_attrs);
|
2012-10-03 22:50:55 +08:00
|
|
|
|
perf stat: Initialize default events wrt exclude_{guest,host}
When no event is specified the tools use perf_evlist__add_default(), that will
call event_attr_init to initialize the KVM exclusion bits.
When the change was made to the tools so that by default guest samples would be
excluded, the changes were made just to the parsing routines and to
perf_evlist__add_default(), not to perf_evlist__add_attrs, that is used so far
just by perf stat to add multiple events, according to the level of detail
specified.
Recently the tools were changed to reconstruct the event name from all the
details in perf_event_attr, not just from .type and .config, but taking into
account all the feature bits (.exclude_{guest,host,user,kernel,etc},
.precise_ip, etc).
That is when we noticed that the default for perf stat wasn't the one for the
rest of the tools, i.e. the .exclude_guest bit wasn't being set.
I.e. the default, that doesn't call event_attr_init was showing the :HG
modifier:
$ perf stat usleep 1
Performance counter stats for 'usleep 1':
0.942119 task-clock # 0.454 CPUs utilized
1 context-switches # 0.001 M/sec
0 CPU-migrations # 0.000 K/sec
126 page-faults # 0.134 M/sec
693,193 cycles:HG # 0.736 GHz [40.11%]
407,461 stalled-cycles-frontend:HG # 58.78% frontend cycles idle [72.29%]
365,403 stalled-cycles-backend:HG # 52.71% backend cycles idle
465,982 instructions:HG # 0.67 insns per cycle
# 0.87 stalled cycles per insn
89,760 branches:HG # 95.275 M/sec
6,178 branch-misses:HG # 6.88% of all branches
0.002077228 seconds time elapsed
While if one explicitely specifies the same events, which will make the parsing code
to be called and thus event_attr_init is called:
$ perf stat -e task-clock,context-switches,migrations,page-faults,cycles,stalled-cycles-frontend,stalled-cycles-backend,instructions,branches,branch-misses usleep 1
Performance counter stats for 'usleep 1':
1.040349 task-clock # 0.500 CPUs utilized
2 context-switches # 0.002 M/sec
0 CPU-migrations # 0.000 K/sec
127 page-faults # 0.122 M/sec
587,966 cycles # 0.565 GHz [13.18%]
459,167 stalled-cycles-frontend # 78.09% frontend cycles idle
390,249 stalled-cycles-backend # 66.37% backend cycles idle
504,006 instructions # 0.86 insns per cycle
# 0.91 stalled cycles per insn
96,455 branches # 92.714 M/sec
6,522 branch-misses # 6.76% of all branches [96.12%]
0.002078681 seconds time elapsed
Fix it by introducing a perf_evlist__add_default_attrs method that will call
evlist_attr_init in all the perf_event_attr entries before adding the events.
Reported-by: Ingo Molnar <mingo@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-4eysr236r0pgiyum9epwxw7s@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-05-31 00:53:54 +08:00
|
|
|
#define perf_evlist__add_default_attrs(evlist, array) \
|
|
|
|
__perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
|
2011-01-12 06:56:53 +08:00
|
|
|
|
2016-01-08 00:14:56 +08:00
|
|
|
int perf_evlist__add_dummy(struct perf_evlist *evlist);
|
|
|
|
|
2012-10-03 22:40:22 +08:00
|
|
|
int perf_evlist__add_newtp(struct perf_evlist *evlist,
|
|
|
|
const char *sys, const char *name, void *handler);
|
|
|
|
|
2016-04-12 05:37:45 +08:00
|
|
|
void __perf_evlist__set_sample_bit(struct perf_evlist *evlist,
|
|
|
|
enum perf_event_sample_format bit);
|
|
|
|
void __perf_evlist__reset_sample_bit(struct perf_evlist *evlist,
|
|
|
|
enum perf_event_sample_format bit);
|
|
|
|
|
|
|
|
#define perf_evlist__set_sample_bit(evlist, bit) \
|
|
|
|
__perf_evlist__set_sample_bit(evlist, PERF_SAMPLE_##bit)
|
|
|
|
|
|
|
|
#define perf_evlist__reset_sample_bit(evlist, bit) \
|
|
|
|
__perf_evlist__reset_sample_bit(evlist, PERF_SAMPLE_##bit)
|
|
|
|
|
2012-09-27 02:07:39 +08:00
|
|
|
int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter);
|
2015-02-22 02:09:55 +08:00
|
|
|
int perf_evlist__set_filter_pid(struct perf_evlist *evlist, pid_t pid);
|
2015-02-22 03:33:47 +08:00
|
|
|
int perf_evlist__set_filter_pids(struct perf_evlist *evlist, size_t npids, pid_t *pids);
|
2012-09-27 02:07:39 +08:00
|
|
|
|
2012-06-28 00:08:42 +08:00
|
|
|
struct perf_evsel *
|
|
|
|
perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id);
|
|
|
|
|
2013-08-29 12:29:51 +08:00
|
|
|
struct perf_evsel *
|
|
|
|
perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist,
|
|
|
|
const char *name);
|
|
|
|
|
2011-03-10 22:15:54 +08:00
|
|
|
void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel,
|
|
|
|
int cpu, int thread, u64 id);
|
2015-11-05 22:40:49 +08:00
|
|
|
int perf_evlist__id_add_fd(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel,
|
|
|
|
int cpu, int thread, int fd);
|
2011-03-05 09:29:39 +08:00
|
|
|
|
2014-08-19 03:44:06 +08:00
|
|
|
int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd);
|
|
|
|
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
|
2014-08-13 10:04:11 +08:00
|
|
|
int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask);
|
|
|
|
|
2014-08-19 04:25:59 +08:00
|
|
|
int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
|
|
|
|
|
2011-01-13 08:39:13 +08:00
|
|
|
struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);
|
2015-09-25 21:15:52 +08:00
|
|
|
struct perf_evsel *perf_evlist__id2evsel_strict(struct perf_evlist *evlist,
|
|
|
|
u64 id);
|
2011-01-13 08:39:13 +08:00
|
|
|
|
2012-10-11 20:10:35 +08:00
|
|
|
struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);
|
|
|
|
|
2016-07-14 16:34:42 +08:00
|
|
|
void perf_evlist__toggle_bkw_mmap(struct perf_evlist *evlist, enum bkw_mmap_state state);
|
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
union perf_event *perf_mmap__read_forward(struct perf_mmap *map, bool check_messup);
|
|
|
|
union perf_event *perf_mmap__read_backward(struct perf_mmap *map);
|
|
|
|
|
|
|
|
void perf_mmap__read_catchup(struct perf_mmap *md);
|
|
|
|
void perf_mmap__consume(struct perf_mmap *md, bool overwrite);
|
|
|
|
|
2013-11-06 02:32:36 +08:00
|
|
|
union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx);
|
2011-01-15 20:40:59 +08:00
|
|
|
|
2016-05-25 21:44:50 +08:00
|
|
|
union perf_event *perf_evlist__mmap_read_forward(struct perf_evlist *evlist,
|
|
|
|
int idx);
|
2016-05-09 09:47:50 +08:00
|
|
|
union perf_event *perf_evlist__mmap_read_backward(struct perf_evlist *evlist,
|
|
|
|
int idx);
|
|
|
|
void perf_evlist__mmap_read_catchup(struct perf_evlist *evlist, int idx);
|
|
|
|
|
2013-10-24 15:43:33 +08:00
|
|
|
void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx);
|
|
|
|
|
perf tools: Enable grouping logic for parsed events
This patch adds a functionality that allows to create event groups
based on the way they are specified on the command line. Adding
functionality to the '{}' group syntax introduced in earlier patch.
The current '--group/-g' option behaviour remains intact. If you
specify it for record/stat/top command, all the specified events
become members of a single group with the first event as a group
leader.
With the new '{}' group syntax you can create group like:
# perf record -e '{cycles,faults}' ls
resulting in single event group containing 'cycles' and 'faults'
events, with cycles event as group leader.
All groups are created with regards to threads and cpus. Thus
recording an event group within a 2 threads on server with
4 CPUs will create 8 separate groups.
Examples (first event in brackets is group leader):
# 1 group (cpu-clock,task-clock)
perf record --group -e cpu-clock,task-clock ls
perf record -e '{cpu-clock,task-clock}' ls
# 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
perf record -e '{cpu-clock,task-clock},{minor-faults,major-faults}' ls
# 1 group (cpu-clock,task-clock,minor-faults,major-faults)
perf record --group -e cpu-clock,task-clock -e minor-faults,major-faults ls
perf record -e '{cpu-clock,task-clock,minor-faults,major-faults}' ls
# 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
perf record -e '{cpu-clock,task-clock} -e '{minor-faults,major-faults}' \
-e instructions ls
# 1 group
# (cpu-clock,task-clock,minor-faults,major-faults,instructions)
perf record --group -e cpu-clock,task-clock \
-e minor-faults,major-faults -e instructions ls perf record -e
'{cpu-clock,task-clock,minor-faults,major-faults,instructions}' ls
It's possible to use standard event modifier for a group, which spans
over all events in the group and updates each event modifier settings,
for example:
# perf record -r '{faults:k,cache-references}:p'
resulting in ':kp' modifier being used for 'faults' and ':p' modifier
being used for 'cache-references' event.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ulrich Drepper <drepper@gmail.com>
Link: http://lkml.kernel.org/n/tip-ho42u0wcr8mn1otkalqi13qp@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-08-08 18:22:36 +08:00
|
|
|
int perf_evlist__open(struct perf_evlist *evlist);
|
2013-03-15 13:48:48 +08:00
|
|
|
void perf_evlist__close(struct perf_evlist *evlist);
|
2011-10-25 20:42:19 +08:00
|
|
|
|
2016-04-12 05:15:29 +08:00
|
|
|
struct callchain_param;
|
|
|
|
|
2013-08-27 16:23:09 +08:00
|
|
|
void perf_evlist__set_id_pos(struct perf_evlist *evlist);
|
|
|
|
bool perf_can_sample_identifier(void);
|
2015-07-21 17:44:04 +08:00
|
|
|
bool perf_can_record_switch_events(void);
|
2015-08-13 17:40:56 +08:00
|
|
|
bool perf_can_record_cpu_wide(void);
|
2016-04-12 05:15:29 +08:00
|
|
|
void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts,
|
|
|
|
struct callchain_param *callchain);
|
2013-12-20 01:43:45 +08:00
|
|
|
int record_opts__config(struct record_opts *opts);
|
2011-11-09 00:41:57 +08:00
|
|
|
|
2011-11-09 18:47:15 +08:00
|
|
|
int perf_evlist__prepare_workload(struct perf_evlist *evlist,
|
2013-11-13 03:46:16 +08:00
|
|
|
struct target *target,
|
2013-03-11 15:43:17 +08:00
|
|
|
const char *argv[], bool pipe_output,
|
2014-01-04 01:56:49 +08:00
|
|
|
void (*exec_error)(int signo, siginfo_t *info,
|
|
|
|
void *ucontext));
|
2011-11-09 18:47:15 +08:00
|
|
|
int perf_evlist__start_workload(struct perf_evlist *evlist);
|
|
|
|
|
2014-10-17 23:16:00 +08:00
|
|
|
struct option;
|
|
|
|
|
2015-04-09 23:53:46 +08:00
|
|
|
int __perf_evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str);
|
2013-09-01 18:36:12 +08:00
|
|
|
int perf_evlist__parse_mmap_pages(const struct option *opt,
|
|
|
|
const char *str,
|
|
|
|
int unset);
|
|
|
|
|
2016-04-16 04:46:31 +08:00
|
|
|
unsigned long perf_event_mlock_kb_in_pages(void);
|
|
|
|
|
2015-04-09 23:53:42 +08:00
|
|
|
int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
|
|
|
|
bool overwrite, unsigned int auxtrace_pages,
|
|
|
|
bool auxtrace_overwrite);
|
2011-11-09 19:10:47 +08:00
|
|
|
int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
|
|
|
|
bool overwrite);
|
2011-01-30 21:59:43 +08:00
|
|
|
void perf_evlist__munmap(struct perf_evlist *evlist);
|
|
|
|
|
2017-01-09 17:51:59 +08:00
|
|
|
size_t perf_evlist__mmap_size(unsigned long pages);
|
|
|
|
|
2011-07-25 22:06:19 +08:00
|
|
|
void perf_evlist__disable(struct perf_evlist *evlist);
|
2011-08-26 00:17:55 +08:00
|
|
|
void perf_evlist__enable(struct perf_evlist *evlist);
|
2015-06-18 03:40:26 +08:00
|
|
|
void perf_evlist__toggle_enable(struct perf_evlist *evlist);
|
2011-07-25 22:06:19 +08:00
|
|
|
|
2014-07-31 14:00:56 +08:00
|
|
|
int perf_evlist__enable_event_idx(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel, int idx);
|
2013-09-01 02:50:53 +08:00
|
|
|
|
2011-10-06 06:11:32 +08:00
|
|
|
void perf_evlist__set_selected(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel);
|
|
|
|
|
2015-09-08 15:58:51 +08:00
|
|
|
void perf_evlist__set_maps(struct perf_evlist *evlist, struct cpu_map *cpus,
|
|
|
|
struct thread_map *threads);
|
2013-11-13 03:46:16 +08:00
|
|
|
int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target);
|
2015-03-25 06:23:47 +08:00
|
|
|
int perf_evlist__apply_filters(struct perf_evlist *evlist, struct perf_evsel **err_evsel);
|
2011-01-30 20:46:46 +08:00
|
|
|
|
2012-08-15 03:35:48 +08:00
|
|
|
void __perf_evlist__set_leader(struct list_head *list);
|
|
|
|
void perf_evlist__set_leader(struct perf_evlist *evlist);
|
|
|
|
|
2012-10-10 23:38:13 +08:00
|
|
|
u64 perf_evlist__read_format(struct perf_evlist *evlist);
|
2013-08-27 16:23:09 +08:00
|
|
|
u64 __perf_evlist__combined_sample_type(struct perf_evlist *evlist);
|
|
|
|
u64 perf_evlist__combined_sample_type(struct perf_evlist *evlist);
|
2015-07-18 23:24:47 +08:00
|
|
|
u64 perf_evlist__combined_branch_type(struct perf_evlist *evlist);
|
2012-08-15 03:42:15 +08:00
|
|
|
bool perf_evlist__sample_id_all(struct perf_evlist *evlist);
|
|
|
|
u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist);
|
2011-05-21 23:49:00 +08:00
|
|
|
|
2012-08-02 23:23:46 +08:00
|
|
|
int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event,
|
2012-09-26 23:48:18 +08:00
|
|
|
struct perf_sample *sample);
|
2012-08-02 22:42:57 +08:00
|
|
|
|
2012-08-15 03:42:15 +08:00
|
|
|
bool perf_evlist__valid_sample_type(struct perf_evlist *evlist);
|
|
|
|
bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist);
|
2012-10-10 23:38:13 +08:00
|
|
|
bool perf_evlist__valid_read_format(struct perf_evlist *evlist);
|
2012-01-27 22:34:20 +08:00
|
|
|
|
|
|
|
void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
|
2015-09-08 15:58:53 +08:00
|
|
|
struct list_head *list);
|
2012-08-15 03:42:15 +08:00
|
|
|
|
2017-07-21 13:11:57 +08:00
|
|
|
static inline bool perf_evlist__empty(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
return list_empty(&evlist->entries);
|
|
|
|
}
|
|
|
|
|
2012-08-15 03:42:15 +08:00
|
|
|
static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
return list_entry(evlist->entries.next, struct perf_evsel, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
return list_entry(evlist->entries.prev, struct perf_evsel, node);
|
|
|
|
}
|
2012-09-07 01:54:11 +08:00
|
|
|
|
|
|
|
size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp);
|
2013-02-06 05:12:42 +08:00
|
|
|
|
perf trace: Improve messages related to /proc/sys/kernel/perf_event_paranoid
kernel/events/core.c has:
/*
* perf event paranoia level:
* -1 - not paranoid at all
* 0 - disallow raw tracepoint access for unpriv
* 1 - disallow cpu events for unpriv
* 2 - disallow kernel profiling for unpriv
*/
int sysctl_perf_event_paranoid __read_mostly = 1;
So, with the default being 1, a non-root user can trace his stuff:
[acme@zoo ~]$ cat /proc/sys/kernel/perf_event_paranoid
1
[acme@zoo ~]$ yes > /dev/null &
[1] 15338
[acme@zoo ~]$ trace -p 15338 | head -5
0.005 ( 0.005 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.045 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.085 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.125 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.165 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
[acme@zoo ~]$
[acme@zoo ~]$ trace --duration 1 sleep 1
1002.148 (1001.218 ms): nanosleep(rqtp: 0x7fff46c79250 ) = 0
[acme@zoo ~]$
[acme@zoo ~]$ trace -- usleep 1 | tail -5
0.905 ( 0.002 ms): brk( ) = 0x1c82000
0.910 ( 0.003 ms): brk(brk: 0x1ca3000 ) = 0x1ca3000
0.913 ( 0.001 ms): brk( ) = 0x1ca3000
0.990 ( 0.059 ms): nanosleep(rqtp: 0x7fffe31a3280 ) = 0
0.995 ( 0.000 ms): exit_group(
[acme@zoo ~]$
But can't do system wide tracing:
[acme@zoo ~]$ trace
Error: Operation not permitted.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 1.
[acme@zoo ~]$
[acme@zoo ~]$ trace --cpu 0
Error: Operation not permitted.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 1.
[acme@zoo ~]$
If the paranoid level is >= 2, i.e. turn this perf stuff off for !root users:
[acme@zoo ~]$ sudo sh -c 'echo 2 > /proc/sys/kernel/perf_event_paranoid'
[acme@zoo ~]$ cat /proc/sys/kernel/perf_event_paranoid
2
[acme@zoo ~]$
[acme@zoo ~]$ trace usleep 1
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
[acme@zoo ~]$ trace
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
[acme@zoo ~]$ trace --cpu 1
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
If the user manages to get what he/she wants, convincing root not
to be paranoid at all...
[root@zoo ~]# echo -1 > /proc/sys/kernel/perf_event_paranoid
[root@zoo ~]# cat /proc/sys/kernel/perf_event_paranoid
-1
[root@zoo ~]#
[acme@zoo ~]$ ps -eo user,pid,comm | grep Xorg
root 729 Xorg
[acme@zoo ~]$
[acme@zoo ~]$ trace -a --duration 0.001 -e \!select,ioctl,writev | grep Xorg | head -5
23.143 ( 0.003 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
23.152 ( 0.004 ms): Xorg/729 read(fd: 31, buf: 0x2544af0, count: 4096 ) = 8
23.161 ( 0.002 ms): Xorg/729 read(fd: 31, buf: 0x2544af0, count: 4096 ) = -1 EAGAIN Resource temporarily unavailable
23.175 ( 0.002 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
23.235 ( 0.002 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
[acme@zoo ~]$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-di28olfwd28rvkox7v3hqhu1@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-10-18 04:38:29 +08:00
|
|
|
int perf_evlist__strerror_open(struct perf_evlist *evlist, int err, char *buf, size_t size);
|
2014-12-12 05:03:01 +08:00
|
|
|
int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size);
|
2013-10-17 23:07:58 +08:00
|
|
|
|
2015-04-07 23:20:37 +08:00
|
|
|
static inline u64 perf_mmap__read_head(struct perf_mmap *mm)
|
2013-02-06 05:12:42 +08:00
|
|
|
{
|
|
|
|
struct perf_event_mmap_page *pc = mm->base;
|
2015-04-07 23:20:37 +08:00
|
|
|
u64 head = ACCESS_ONCE(pc->data_head);
|
2013-02-06 05:12:42 +08:00
|
|
|
rmb();
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
2015-04-07 23:20:37 +08:00
|
|
|
static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
|
2013-02-06 05:12:42 +08:00
|
|
|
{
|
|
|
|
struct perf_event_mmap_page *pc = md->base;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ensure all reads are done before we write the tail out.
|
|
|
|
*/
|
2013-10-30 18:42:46 +08:00
|
|
|
mb();
|
2013-02-06 05:12:42 +08:00
|
|
|
pc->data_tail = tail;
|
|
|
|
}
|
|
|
|
|
2013-12-11 20:36:29 +08:00
|
|
|
bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str);
|
2013-12-11 20:36:35 +08:00
|
|
|
void perf_evlist__to_front(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *move_evsel);
|
|
|
|
|
2014-01-10 21:37:27 +08:00
|
|
|
/**
|
2016-06-23 22:26:15 +08:00
|
|
|
* __evlist__for_each_entry - iterate thru all the evsels
|
2014-01-10 21:37:27 +08:00
|
|
|
* @list: list_head instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
2016-06-23 22:26:15 +08:00
|
|
|
#define __evlist__for_each_entry(list, evsel) \
|
2014-01-10 21:37:27 +08:00
|
|
|
list_for_each_entry(evsel, list, node)
|
|
|
|
|
|
|
|
/**
|
2016-06-23 22:26:15 +08:00
|
|
|
* evlist__for_each_entry - iterate thru all the evsels
|
2014-01-10 21:37:27 +08:00
|
|
|
* @evlist: evlist instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
2016-06-23 22:26:15 +08:00
|
|
|
#define evlist__for_each_entry(evlist, evsel) \
|
|
|
|
__evlist__for_each_entry(&(evlist)->entries, evsel)
|
2014-01-10 21:37:27 +08:00
|
|
|
|
|
|
|
/**
|
2016-06-23 22:26:15 +08:00
|
|
|
* __evlist__for_each_entry_continue - continue iteration thru all the evsels
|
2014-01-10 21:37:27 +08:00
|
|
|
* @list: list_head instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
2016-06-23 22:26:15 +08:00
|
|
|
#define __evlist__for_each_entry_continue(list, evsel) \
|
2014-01-10 21:37:27 +08:00
|
|
|
list_for_each_entry_continue(evsel, list, node)
|
|
|
|
|
|
|
|
/**
|
2016-06-23 22:26:15 +08:00
|
|
|
* evlist__for_each_entry_continue - continue iteration thru all the evsels
|
2014-01-10 21:37:27 +08:00
|
|
|
* @evlist: evlist instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
2016-06-23 22:26:15 +08:00
|
|
|
#define evlist__for_each_entry_continue(evlist, evsel) \
|
|
|
|
__evlist__for_each_entry_continue(&(evlist)->entries, evsel)
|
2014-01-10 21:37:27 +08:00
|
|
|
|
|
|
|
/**
|
2016-06-23 22:26:15 +08:00
|
|
|
* __evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
|
2014-01-10 21:37:27 +08:00
|
|
|
* @list: list_head instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
2016-06-23 22:26:15 +08:00
|
|
|
#define __evlist__for_each_entry_reverse(list, evsel) \
|
2014-01-10 21:37:27 +08:00
|
|
|
list_for_each_entry_reverse(evsel, list, node)
|
|
|
|
|
|
|
|
/**
|
2016-06-23 22:26:15 +08:00
|
|
|
* evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
|
2014-01-10 21:37:27 +08:00
|
|
|
* @evlist: evlist instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
2016-06-23 22:26:15 +08:00
|
|
|
#define evlist__for_each_entry_reverse(evlist, evsel) \
|
|
|
|
__evlist__for_each_entry_reverse(&(evlist)->entries, evsel)
|
2014-01-10 21:37:27 +08:00
|
|
|
|
|
|
|
/**
|
2016-06-23 22:26:15 +08:00
|
|
|
* __evlist__for_each_entry_safe - safely iterate thru all the evsels
|
2014-01-10 21:37:27 +08:00
|
|
|
* @list: list_head instance to iterate
|
|
|
|
* @tmp: struct evsel temp iterator
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
2016-06-23 22:26:15 +08:00
|
|
|
#define __evlist__for_each_entry_safe(list, tmp, evsel) \
|
2014-01-10 21:37:27 +08:00
|
|
|
list_for_each_entry_safe(evsel, tmp, list, node)
|
|
|
|
|
|
|
|
/**
|
2016-06-23 22:26:15 +08:00
|
|
|
* evlist__for_each_entry_safe - safely iterate thru all the evsels
|
2014-01-10 21:37:27 +08:00
|
|
|
* @evlist: evlist instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
* @tmp: struct evsel temp iterator
|
|
|
|
*/
|
2016-06-23 22:26:15 +08:00
|
|
|
#define evlist__for_each_entry_safe(evlist, tmp, evsel) \
|
|
|
|
__evlist__for_each_entry_safe(&(evlist)->entries, tmp, evsel)
|
2013-12-11 20:36:29 +08:00
|
|
|
|
2014-07-31 14:00:52 +08:00
|
|
|
void perf_evlist__set_tracking_event(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *tracking_evsel);
|
2015-10-06 02:06:04 +08:00
|
|
|
|
|
|
|
void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr);
|
perf tools: Enable passing event to BPF object
A new syntax is added to the parser so that the user can access
predefined perf events in BPF objects.
After this patch, BPF programs for perf are finally able to utilize
bpf_perf_event_read() introduced in commit 35578d798400 ("bpf: Implement
function bpf_perf_event_read() that get the selected hardware PMU
counter").
Test result:
# cat test_bpf_map_2.c
/************************ BEGIN **************************/
#include <uapi/linux/bpf.h>
#define SEC(NAME) __attribute__((section(NAME), used))
struct bpf_map_def {
unsigned int type;
unsigned int key_size;
unsigned int value_size;
unsigned int max_entries;
};
static int (*trace_printk)(const char *fmt, int fmt_size, ...) =
(void *)BPF_FUNC_trace_printk;
static int (*get_smp_processor_id)(void) =
(void *)BPF_FUNC_get_smp_processor_id;
static int (*perf_event_read)(struct bpf_map_def *, int) =
(void *)BPF_FUNC_perf_event_read;
struct bpf_map_def SEC("maps") pmu_map = {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(int),
.max_entries = __NR_CPUS__,
};
SEC("func_write=sys_write")
int func_write(void *ctx)
{
unsigned long long val;
char fmt[] = "sys_write: pmu=%llu\n";
val = perf_event_read(&pmu_map, get_smp_processor_id());
trace_printk(fmt, sizeof(fmt), val);
return 0;
}
SEC("func_write_return=sys_write%return")
int func_write_return(void *ctx)
{
unsigned long long val = 0;
char fmt[] = "sys_write_return: pmu=%llu\n";
val = perf_event_read(&pmu_map, get_smp_processor_id());
trace_printk(fmt, sizeof(fmt), val);
return 0;
}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = LINUX_VERSION_CODE;
/************************* END ***************************/
Normal case:
# echo "" > /sys/kernel/debug/tracing/trace
# perf record -i -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=cycles/' ls /
[SNIP]
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.013 MB perf.data (7 samples) ]
# cat /sys/kernel/debug/tracing/trace | grep ls
ls-17066 [000] d... 938449.863301: : sys_write: pmu=1157327
ls-17066 [000] dN.. 938449.863342: : sys_write_return: pmu=1225218
ls-17066 [000] d... 938449.863349: : sys_write: pmu=1241922
ls-17066 [000] dN.. 938449.863369: : sys_write_return: pmu=1267445
Normal case (system wide):
# echo "" > /sys/kernel/debug/tracing/trace
# perf record -i -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=cycles/' -a
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.811 MB perf.data (120 samples) ]
# cat /sys/kernel/debug/tracing/trace | grep -v '18446744073709551594' | grep -v perf | head -n 20
[SNIP]
# TASK-PID CPU# |||| TIMESTAMP FUNCTION
# | | | |||| | |
gmain-30828 [002] d... 2740551.068992: : sys_write: pmu=84373
gmain-30828 [002] d... 2740551.068992: : sys_write_return: pmu=87696
gmain-30828 [002] d... 2740551.068996: : sys_write: pmu=100658
gmain-30828 [002] d... 2740551.068997: : sys_write_return: pmu=102572
Error case 1:
# perf record -e './test_bpf_map_2.c' ls /
[SNIP]
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.014 MB perf.data ]
# cat /sys/kernel/debug/tracing/trace | grep ls
ls-17115 [007] d... 2724279.665625: : sys_write: pmu=18446744073709551614
ls-17115 [007] dN.. 2724279.665651: : sys_write_return: pmu=18446744073709551614
ls-17115 [007] d... 2724279.665658: : sys_write: pmu=18446744073709551614
ls-17115 [007] dN.. 2724279.665677: : sys_write_return: pmu=18446744073709551614
(18446744073709551614 is 0xfffffffffffffffe (-2))
Error case 2:
# perf record -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=evt/' -a
event syntax error: '..ps:pmu_map.event=evt/'
\___ Event not found for map setting
Hint: Valid config terms:
map:[<arraymap>].value=[value]
map:[<eventmap>].event=[event]
[SNIP]
Error case 3:
# ls /proc/2348/task/
2348 2505 2506 2507 2508
# perf record -i -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=cycles/' -p 2348
ERROR: Apply config to BPF failed: Cannot set event to BPF map in multi-thread tracing
Error case 4:
# perf record -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=cycles/' ls /
ERROR: Apply config to BPF failed: Doesn't support inherit event (Hint: use -i to turn off inherit)
Error case 5:
# perf record -i -e raw_syscalls:sys_enter -e './test_bpf_map_2.c/map:pmu_map.event=raw_syscalls:sys_enter/' ls
ERROR: Apply config to BPF failed: Can only put raw, hardware and BPF output event into a BPF map
Error case 6:
# perf record -i -e './test_bpf_map_2.c/map:pmu_map.event=123/' ls /
event syntax error: '.._map.event=123/'
\___ Incorrect value type for map
[SNIP]
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Cody P Schafer <dev@codyps.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
Cc: Kirill Smelkov <kirr@nexedi.com>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1456132275-98875-7-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-02-22 17:10:33 +08:00
|
|
|
|
|
|
|
struct perf_evsel *
|
|
|
|
perf_evlist__find_evsel_by_str(struct perf_evlist *evlist, const char *str);
|
2016-07-10 19:07:53 +08:00
|
|
|
|
|
|
|
struct perf_evsel *perf_evlist__event2evsel(struct perf_evlist *evlist,
|
|
|
|
union perf_event *event);
|
2011-01-12 06:56:53 +08:00
|
|
|
#endif /* __PERF_EVLIST_H */
|