2011-01-30 19:46:46 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
|
|
|
|
*
|
|
|
|
* Parts came from builtin-{top,stat,record}.c, see those files for further
|
|
|
|
* copyright notes.
|
|
|
|
*
|
|
|
|
* Released under the GPL v2. (and only v2, not any later version)
|
|
|
|
*/
|
2011-11-05 17:41:51 +07:00
|
|
|
#include "util.h"
|
2014-12-12 04:03:01 +07:00
|
|
|
#include <api/fs/fs.h>
|
2011-01-12 07:30:02 +07:00
|
|
|
#include <poll.h>
|
2011-01-30 19:46:46 +07:00
|
|
|
#include "cpumap.h"
|
|
|
|
#include "thread_map.h"
|
2012-04-26 12:15:22 +07:00
|
|
|
#include "target.h"
|
2011-01-12 05:56:53 +07:00
|
|
|
#include "evlist.h"
|
|
|
|
#include "evsel.h"
|
2013-08-14 19:48:24 +07:00
|
|
|
#include "debug.h"
|
2011-11-09 17:47:15 +07:00
|
|
|
#include <unistd.h>
|
2011-01-12 05:56:53 +07:00
|
|
|
|
2011-11-04 18:10:59 +07:00
|
|
|
#include "parse-events.h"
|
2013-09-01 17:36:12 +07:00
|
|
|
#include "parse-options.h"
|
2011-11-04 18:10:59 +07:00
|
|
|
|
2011-01-30 19:46:46 +07:00
|
|
|
#include <sys/mman.h>
|
|
|
|
|
2011-01-13 07:39:13 +07:00
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/hash.h>
|
2014-12-16 02:04:11 +07:00
|
|
|
#include <linux/log2.h>
|
2015-09-07 15:38:06 +07:00
|
|
|
#include <linux/err.h>
|
2011-01-13 07:39:13 +07:00
|
|
|
|
2014-09-08 21:27:49 +07:00
|
|
|
static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx);
|
|
|
|
static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx);
|
|
|
|
|
2011-01-30 19:46:46 +07:00
|
|
|
#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
|
2011-03-10 21:15:54 +07:00
|
|
|
#define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
|
2011-01-30 19:46:46 +07:00
|
|
|
|
2011-01-30 20:59:43 +07:00
|
|
|
void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
|
|
|
|
struct thread_map *threads)
|
2011-01-19 06:41:45 +07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < PERF_EVLIST__HLIST_SIZE; ++i)
|
|
|
|
INIT_HLIST_HEAD(&evlist->heads[i]);
|
|
|
|
INIT_LIST_HEAD(&evlist->entries);
|
2011-01-30 20:59:43 +07:00
|
|
|
perf_evlist__set_maps(evlist, cpus, threads);
|
2014-09-04 04:02:59 +07:00
|
|
|
fdarray__init(&evlist->pollfd, 64);
|
2011-11-09 17:47:15 +07:00
|
|
|
evlist->workload.pid = -1;
|
2011-01-19 06:41:45 +07:00
|
|
|
}
|
|
|
|
|
2013-03-11 14:43:12 +07:00
|
|
|
struct perf_evlist *perf_evlist__new(void)
|
2011-01-12 05:56:53 +07:00
|
|
|
{
|
|
|
|
struct perf_evlist *evlist = zalloc(sizeof(*evlist));
|
|
|
|
|
2011-01-19 06:41:45 +07:00
|
|
|
if (evlist != NULL)
|
2013-03-11 14:43:12 +07:00
|
|
|
perf_evlist__init(evlist, NULL, NULL);
|
2011-01-12 05:56:53 +07:00
|
|
|
|
|
|
|
return evlist;
|
|
|
|
}
|
|
|
|
|
2013-09-01 17:36:14 +07:00
|
|
|
struct perf_evlist *perf_evlist__new_default(void)
|
|
|
|
{
|
|
|
|
struct perf_evlist *evlist = perf_evlist__new();
|
|
|
|
|
|
|
|
if (evlist && perf_evlist__add_default(evlist)) {
|
|
|
|
perf_evlist__delete(evlist);
|
|
|
|
evlist = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return evlist;
|
|
|
|
}
|
|
|
|
|
2013-08-27 15:23:09 +07:00
|
|
|
/**
|
|
|
|
* perf_evlist__set_id_pos - set the positions of event ids.
|
|
|
|
* @evlist: selected event list
|
|
|
|
*
|
|
|
|
* Events with compatible sample types all have the same id_pos
|
|
|
|
* and is_pos. For convenience, put a copy on evlist.
|
|
|
|
*/
|
|
|
|
void perf_evlist__set_id_pos(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *first = perf_evlist__first(evlist);
|
|
|
|
|
|
|
|
evlist->id_pos = first->id_pos;
|
|
|
|
evlist->is_pos = first->is_pos;
|
|
|
|
}
|
|
|
|
|
2013-09-07 02:40:11 +07:00
|
|
|
static void perf_evlist__update_id_pos(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, evsel)
|
2013-09-07 02:40:11 +07:00
|
|
|
perf_evsel__calc_id_pos(evsel);
|
|
|
|
|
|
|
|
perf_evlist__set_id_pos(evlist);
|
|
|
|
}
|
|
|
|
|
2011-01-12 05:56:53 +07:00
|
|
|
static void perf_evlist__purge(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *pos, *n;
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each_safe(evlist, n, pos) {
|
2011-01-12 05:56:53 +07:00
|
|
|
list_del_init(&pos->node);
|
2015-08-27 19:07:40 +07:00
|
|
|
pos->evlist = NULL;
|
2011-01-12 05:56:53 +07:00
|
|
|
perf_evsel__delete(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
evlist->nr_entries = 0;
|
|
|
|
}
|
|
|
|
|
2011-01-19 06:41:45 +07:00
|
|
|
void perf_evlist__exit(struct perf_evlist *evlist)
|
2011-01-12 05:56:53 +07:00
|
|
|
{
|
2013-12-27 03:41:15 +07:00
|
|
|
zfree(&evlist->mmap);
|
2014-09-04 04:02:59 +07:00
|
|
|
fdarray__exit(&evlist->pollfd);
|
2011-01-19 06:41:45 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void perf_evlist__delete(struct perf_evlist *evlist)
|
|
|
|
{
|
2014-01-04 03:25:49 +07:00
|
|
|
perf_evlist__munmap(evlist);
|
2014-01-04 02:54:12 +07:00
|
|
|
perf_evlist__close(evlist);
|
2015-06-23 05:36:04 +07:00
|
|
|
cpu_map__put(evlist->cpus);
|
2015-06-23 05:36:05 +07:00
|
|
|
thread_map__put(evlist->threads);
|
2014-01-04 01:56:06 +07:00
|
|
|
evlist->cpus = NULL;
|
|
|
|
evlist->threads = NULL;
|
2011-01-19 06:41:45 +07:00
|
|
|
perf_evlist__purge(evlist);
|
|
|
|
perf_evlist__exit(evlist);
|
2011-01-12 05:56:53 +07:00
|
|
|
free(evlist);
|
|
|
|
}
|
|
|
|
|
2015-09-08 14:58:58 +07:00
|
|
|
static void __perf_evlist__propagate_maps(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We already have cpus for evsel (via PMU sysfs) so
|
|
|
|
* keep it, if there's no target cpu list defined.
|
|
|
|
*/
|
|
|
|
if (!evsel->own_cpus || evlist->has_user_cpus) {
|
|
|
|
cpu_map__put(evsel->cpus);
|
|
|
|
evsel->cpus = cpu_map__get(evlist->cpus);
|
|
|
|
} else if (evsel->cpus != evsel->own_cpus) {
|
|
|
|
cpu_map__put(evsel->cpus);
|
|
|
|
evsel->cpus = cpu_map__get(evsel->own_cpus);
|
|
|
|
}
|
|
|
|
|
|
|
|
thread_map__put(evsel->threads);
|
|
|
|
evsel->threads = thread_map__get(evlist->threads);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void perf_evlist__propagate_maps(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
|
|
|
evlist__for_each(evlist, evsel)
|
|
|
|
__perf_evlist__propagate_maps(evlist, evsel);
|
|
|
|
}
|
|
|
|
|
2011-01-12 05:56:53 +07:00
|
|
|
void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)
|
|
|
|
{
|
2015-08-27 19:07:40 +07:00
|
|
|
entry->evlist = evlist;
|
2011-01-12 05:56:53 +07:00
|
|
|
list_add_tail(&entry->node, &evlist->entries);
|
2013-11-08 02:41:19 +07:00
|
|
|
entry->idx = evlist->nr_entries;
|
2014-07-31 13:00:52 +07:00
|
|
|
entry->tracking = !entry->idx;
|
2013-11-08 02:41:19 +07:00
|
|
|
|
2013-08-27 15:23:09 +07:00
|
|
|
if (!evlist->nr_entries++)
|
|
|
|
perf_evlist__set_id_pos(evlist);
|
2015-09-08 14:58:59 +07:00
|
|
|
|
|
|
|
__perf_evlist__propagate_maps(evlist, entry);
|
2011-01-12 05:56:53 +07:00
|
|
|
}
|
|
|
|
|
2015-09-25 20:15:53 +07:00
|
|
|
void perf_evlist__remove(struct perf_evlist *evlist, struct perf_evsel *evsel)
|
|
|
|
{
|
|
|
|
evsel->evlist = NULL;
|
|
|
|
list_del_init(&evsel->node);
|
|
|
|
evlist->nr_entries -= 1;
|
|
|
|
}
|
|
|
|
|
2012-01-27 21:34:20 +07:00
|
|
|
void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
|
2015-09-08 14:58:53 +07:00
|
|
|
struct list_head *list)
|
2011-11-04 18:10:59 +07:00
|
|
|
{
|
2015-09-08 14:58:53 +07:00
|
|
|
struct perf_evsel *evsel, *temp;
|
2013-08-27 15:23:09 +07:00
|
|
|
|
2015-09-08 14:58:53 +07:00
|
|
|
__evlist__for_each_safe(list, temp, evsel) {
|
|
|
|
list_del_init(&evsel->node);
|
|
|
|
perf_evlist__add(evlist, evsel);
|
|
|
|
}
|
2011-11-04 18:10:59 +07:00
|
|
|
}
|
|
|
|
|
2012-08-15 02:35:48 +07:00
|
|
|
void __perf_evlist__set_leader(struct list_head *list)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel, *leader;
|
|
|
|
|
|
|
|
leader = list_entry(list->next, struct perf_evsel, node);
|
2013-01-22 16:09:29 +07:00
|
|
|
evsel = list_entry(list->prev, struct perf_evsel, node);
|
|
|
|
|
|
|
|
leader->nr_members = evsel->idx - leader->idx + 1;
|
2012-08-15 02:35:48 +07:00
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
__evlist__for_each(list, evsel) {
|
2013-01-31 19:54:37 +07:00
|
|
|
evsel->leader = leader;
|
2012-08-15 02:35:48 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void perf_evlist__set_leader(struct perf_evlist *evlist)
|
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 17:22:36 +07:00
|
|
|
{
|
2013-01-22 16:09:29 +07:00
|
|
|
if (evlist->nr_entries) {
|
|
|
|
evlist->nr_groups = evlist->nr_entries > 1 ? 1 : 0;
|
2012-08-15 02:35:48 +07:00
|
|
|
__perf_evlist__set_leader(&evlist->entries);
|
2013-01-22 16:09:29 +07:00
|
|
|
}
|
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 17:22:36 +07:00
|
|
|
}
|
|
|
|
|
perf tools: By default use the most precise "cycles" hw counter available
If the user doesn't specify any event, try the most precise "cycles"
available, i.e. start by "cycles:ppp" and go on removing "p" till it
works.
E.g.
$ perf record usleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.017 MB perf.data (11 samples) ]
$ perf evlist
cycles:pp
$ perf evlist -v
cycles:pp: size: 112, { sample_period, sample_freq }: 4000, sample_type:
IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1,
enable_on_exec: 1, task: 1, precise_ip: 2, sample_id_all: 1,
exclude_guest: 1, mmap2: 1, comm_exec: 1
$ grep 'model name' /proc/cpuinfo | head -1
model name : Intel(R) Core(TM) i7-3667U CPU @ 2.00GHz
$
When 'cycles' appears explicitely is specified this will not be tried,
i.e. the user has full control of the level of precision to be used:
$ perf record -e cycles usleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.016 MB perf.data (9 samples) ]
$ perf evlist
cycles
$ perf evlist -v
cycles: size: 112, { sample_period, sample_freq }: 4000, sample_type:
IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1,
enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2:
1, comm_exec: 1
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Chandler Carruth <chandlerc@gmail.com>
Cc: David Ahern <dsahern@gmail.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>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://www.youtube.com/watch?v=nXaxk27zwlk
Link: http://lkml.kernel.org/n/tip-b1ywebmt22pi78vjxau01wth@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-10-01 03:49:49 +07:00
|
|
|
static void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr)
|
|
|
|
{
|
|
|
|
attr->precise_ip = 3;
|
|
|
|
|
|
|
|
while (attr->precise_ip != 0) {
|
|
|
|
int fd = sys_perf_event_open(attr, 0, -1, -1, 0);
|
|
|
|
if (fd != -1) {
|
|
|
|
close(fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
--attr->precise_ip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-12 05:56:53 +07:00
|
|
|
int perf_evlist__add_default(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_event_attr attr = {
|
|
|
|
.type = PERF_TYPE_HARDWARE,
|
|
|
|
.config = PERF_COUNT_HW_CPU_CYCLES,
|
|
|
|
};
|
2012-01-04 23:54:20 +07:00
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
|
|
|
event_attr_init(&attr);
|
2011-01-12 05:56:53 +07:00
|
|
|
|
perf tools: By default use the most precise "cycles" hw counter available
If the user doesn't specify any event, try the most precise "cycles"
available, i.e. start by "cycles:ppp" and go on removing "p" till it
works.
E.g.
$ perf record usleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.017 MB perf.data (11 samples) ]
$ perf evlist
cycles:pp
$ perf evlist -v
cycles:pp: size: 112, { sample_period, sample_freq }: 4000, sample_type:
IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1,
enable_on_exec: 1, task: 1, precise_ip: 2, sample_id_all: 1,
exclude_guest: 1, mmap2: 1, comm_exec: 1
$ grep 'model name' /proc/cpuinfo | head -1
model name : Intel(R) Core(TM) i7-3667U CPU @ 2.00GHz
$
When 'cycles' appears explicitely is specified this will not be tried,
i.e. the user has full control of the level of precision to be used:
$ perf record -e cycles usleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.016 MB perf.data (9 samples) ]
$ perf evlist
cycles
$ perf evlist -v
cycles: size: 112, { sample_period, sample_freq }: 4000, sample_type:
IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1,
enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2:
1, comm_exec: 1
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Chandler Carruth <chandlerc@gmail.com>
Cc: David Ahern <dsahern@gmail.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>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://www.youtube.com/watch?v=nXaxk27zwlk
Link: http://lkml.kernel.org/n/tip-b1ywebmt22pi78vjxau01wth@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-10-01 03:49:49 +07:00
|
|
|
perf_event_attr__set_max_precise_ip(&attr);
|
|
|
|
|
2013-11-08 02:41:19 +07:00
|
|
|
evsel = perf_evsel__new(&attr);
|
2011-01-12 05:56:53 +07:00
|
|
|
if (evsel == NULL)
|
2011-06-07 23:19:36 +07:00
|
|
|
goto error;
|
|
|
|
|
perf tools: By default use the most precise "cycles" hw counter available
If the user doesn't specify any event, try the most precise "cycles"
available, i.e. start by "cycles:ppp" and go on removing "p" till it
works.
E.g.
$ perf record usleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.017 MB perf.data (11 samples) ]
$ perf evlist
cycles:pp
$ perf evlist -v
cycles:pp: size: 112, { sample_period, sample_freq }: 4000, sample_type:
IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1,
enable_on_exec: 1, task: 1, precise_ip: 2, sample_id_all: 1,
exclude_guest: 1, mmap2: 1, comm_exec: 1
$ grep 'model name' /proc/cpuinfo | head -1
model name : Intel(R) Core(TM) i7-3667U CPU @ 2.00GHz
$
When 'cycles' appears explicitely is specified this will not be tried,
i.e. the user has full control of the level of precision to be used:
$ perf record -e cycles usleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.016 MB perf.data (9 samples) ]
$ perf evlist
cycles
$ perf evlist -v
cycles: size: 112, { sample_period, sample_freq }: 4000, sample_type:
IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1,
enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2:
1, comm_exec: 1
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Chandler Carruth <chandlerc@gmail.com>
Cc: David Ahern <dsahern@gmail.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>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://www.youtube.com/watch?v=nXaxk27zwlk
Link: http://lkml.kernel.org/n/tip-b1ywebmt22pi78vjxau01wth@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-10-01 03:49:49 +07:00
|
|
|
/* use asprintf() because free(evsel) assumes name is allocated */
|
|
|
|
if (asprintf(&evsel->name, "cycles%.*s",
|
|
|
|
attr.precise_ip ? attr.precise_ip + 1 : 0, ":ppp") < 0)
|
2011-06-07 23:19:36 +07:00
|
|
|
goto error_free;
|
2011-01-12 05:56:53 +07:00
|
|
|
|
|
|
|
perf_evlist__add(evlist, evsel);
|
|
|
|
return 0;
|
2011-06-07 23:19:36 +07:00
|
|
|
error_free:
|
|
|
|
perf_evsel__delete(evsel);
|
|
|
|
error:
|
|
|
|
return -ENOMEM;
|
2011-01-12 05:56:53 +07:00
|
|
|
}
|
2011-01-12 07:30:02 +07:00
|
|
|
|
2012-10-03 21:50:55 +07:00
|
|
|
static int perf_evlist__add_attrs(struct perf_evlist *evlist,
|
|
|
|
struct perf_event_attr *attrs, size_t nr_attrs)
|
2011-11-04 18:10:59 +07:00
|
|
|
{
|
|
|
|
struct perf_evsel *evsel, *n;
|
|
|
|
LIST_HEAD(head);
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_attrs; i++) {
|
2013-11-08 02:41:19 +07:00
|
|
|
evsel = perf_evsel__new_idx(attrs + i, evlist->nr_entries + i);
|
2011-11-04 18:10:59 +07:00
|
|
|
if (evsel == NULL)
|
|
|
|
goto out_delete_partial_list;
|
|
|
|
list_add_tail(&evsel->node, &head);
|
|
|
|
}
|
|
|
|
|
2015-09-08 14:58:53 +07:00
|
|
|
perf_evlist__splice_list_tail(evlist, &head);
|
2011-11-04 18:10:59 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_delete_partial_list:
|
2014-01-10 20:37:27 +07:00
|
|
|
__evlist__for_each_safe(&head, n, evsel)
|
2011-11-04 18:10:59 +07:00
|
|
|
perf_evsel__delete(evsel);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
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-30 23:53:54 +07:00
|
|
|
int __perf_evlist__add_default_attrs(struct perf_evlist *evlist,
|
|
|
|
struct perf_event_attr *attrs, size_t nr_attrs)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_attrs; i++)
|
|
|
|
event_attr_init(attrs + i);
|
|
|
|
|
|
|
|
return perf_evlist__add_attrs(evlist, attrs, nr_attrs);
|
|
|
|
}
|
|
|
|
|
2012-06-27 23:08:42 +07:00
|
|
|
struct perf_evsel *
|
|
|
|
perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id)
|
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 02:57:40 +07:00
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, evsel) {
|
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 02:57:40 +07:00
|
|
|
if (evsel->attr.type == PERF_TYPE_TRACEPOINT &&
|
|
|
|
(int)evsel->attr.config == id)
|
|
|
|
return evsel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-29 11:29:51 +07:00
|
|
|
struct perf_evsel *
|
|
|
|
perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, evsel) {
|
2013-08-29 11:29:51 +07:00
|
|
|
if ((evsel->attr.type == PERF_TYPE_TRACEPOINT) &&
|
|
|
|
(strcmp(evsel->name, name) == 0))
|
|
|
|
return evsel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-03 21:40:22 +07:00
|
|
|
int perf_evlist__add_newtp(struct perf_evlist *evlist,
|
|
|
|
const char *sys, const char *name, void *handler)
|
|
|
|
{
|
2013-11-08 02:41:19 +07:00
|
|
|
struct perf_evsel *evsel = perf_evsel__newtp(sys, name);
|
2012-10-03 21:40:22 +07:00
|
|
|
|
2015-09-07 15:38:06 +07:00
|
|
|
if (IS_ERR(evsel))
|
2012-10-03 21:40:22 +07:00
|
|
|
return -1;
|
|
|
|
|
2013-11-06 20:17:38 +07:00
|
|
|
evsel->handler = handler;
|
2012-10-03 21:40:22 +07:00
|
|
|
perf_evlist__add(evlist, evsel);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-31 13:00:51 +07:00
|
|
|
static int perf_evlist__nr_threads(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel)
|
|
|
|
{
|
|
|
|
if (evsel->system_wide)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return thread_map__nr(evlist->threads);
|
|
|
|
}
|
|
|
|
|
2011-07-25 21:06:19 +07:00
|
|
|
void perf_evlist__disable(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
int cpu, thread;
|
|
|
|
struct perf_evsel *pos;
|
2013-03-11 14:43:14 +07:00
|
|
|
int nr_cpus = cpu_map__nr(evlist->cpus);
|
2014-07-31 13:00:51 +07:00
|
|
|
int nr_threads;
|
2011-07-25 21:06:19 +07:00
|
|
|
|
2013-03-11 14:43:14 +07:00
|
|
|
for (cpu = 0; cpu < nr_cpus; cpu++) {
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, pos) {
|
2013-09-01 01:50:53 +07:00
|
|
|
if (!perf_evsel__is_group_leader(pos) || !pos->fd)
|
2012-11-13 00:34:03 +07:00
|
|
|
continue;
|
2014-07-31 13:00:51 +07:00
|
|
|
nr_threads = perf_evlist__nr_threads(evlist, pos);
|
2013-03-11 14:43:14 +07:00
|
|
|
for (thread = 0; thread < nr_threads; thread++)
|
2012-05-31 12:51:46 +07:00
|
|
|
ioctl(FD(pos, cpu, thread),
|
|
|
|
PERF_EVENT_IOC_DISABLE, 0);
|
2011-07-25 21:06:19 +07:00
|
|
|
}
|
|
|
|
}
|
2015-06-18 02:40:26 +07:00
|
|
|
|
|
|
|
evlist->enabled = false;
|
2011-07-25 21:06:19 +07:00
|
|
|
}
|
|
|
|
|
2011-08-25 23:17:55 +07:00
|
|
|
void perf_evlist__enable(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
int cpu, thread;
|
|
|
|
struct perf_evsel *pos;
|
2013-03-11 14:43:14 +07:00
|
|
|
int nr_cpus = cpu_map__nr(evlist->cpus);
|
2014-07-31 13:00:51 +07:00
|
|
|
int nr_threads;
|
2011-08-25 23:17:55 +07:00
|
|
|
|
2013-03-11 14:43:14 +07:00
|
|
|
for (cpu = 0; cpu < nr_cpus; cpu++) {
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, pos) {
|
2013-09-01 01:50:53 +07:00
|
|
|
if (!perf_evsel__is_group_leader(pos) || !pos->fd)
|
2012-11-13 00:34:03 +07:00
|
|
|
continue;
|
2014-07-31 13:00:51 +07:00
|
|
|
nr_threads = perf_evlist__nr_threads(evlist, pos);
|
2013-03-11 14:43:14 +07:00
|
|
|
for (thread = 0; thread < nr_threads; thread++)
|
2012-05-31 12:51:46 +07:00
|
|
|
ioctl(FD(pos, cpu, thread),
|
|
|
|
PERF_EVENT_IOC_ENABLE, 0);
|
2011-08-25 23:17:55 +07:00
|
|
|
}
|
|
|
|
}
|
2015-06-18 02:40:26 +07:00
|
|
|
|
|
|
|
evlist->enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void perf_evlist__toggle_enable(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
(evlist->enabled ? perf_evlist__disable : perf_evlist__enable)(evlist);
|
2011-08-25 23:17:55 +07:00
|
|
|
}
|
|
|
|
|
2013-09-01 01:50:53 +07:00
|
|
|
int perf_evlist__disable_event(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel)
|
|
|
|
{
|
|
|
|
int cpu, thread, err;
|
2014-07-31 13:00:51 +07:00
|
|
|
int nr_cpus = cpu_map__nr(evlist->cpus);
|
|
|
|
int nr_threads = perf_evlist__nr_threads(evlist, evsel);
|
2013-09-01 01:50:53 +07:00
|
|
|
|
|
|
|
if (!evsel->fd)
|
|
|
|
return 0;
|
|
|
|
|
2014-07-31 13:00:51 +07:00
|
|
|
for (cpu = 0; cpu < nr_cpus; cpu++) {
|
|
|
|
for (thread = 0; thread < nr_threads; thread++) {
|
2013-09-01 01:50:53 +07:00
|
|
|
err = ioctl(FD(evsel, cpu, thread),
|
|
|
|
PERF_EVENT_IOC_DISABLE, 0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int perf_evlist__enable_event(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel)
|
|
|
|
{
|
|
|
|
int cpu, thread, err;
|
2014-07-31 13:00:51 +07:00
|
|
|
int nr_cpus = cpu_map__nr(evlist->cpus);
|
|
|
|
int nr_threads = perf_evlist__nr_threads(evlist, evsel);
|
2013-09-01 01:50:53 +07:00
|
|
|
|
|
|
|
if (!evsel->fd)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-07-31 13:00:51 +07:00
|
|
|
for (cpu = 0; cpu < nr_cpus; cpu++) {
|
|
|
|
for (thread = 0; thread < nr_threads; thread++) {
|
2013-09-01 01:50:53 +07:00
|
|
|
err = ioctl(FD(evsel, cpu, thread),
|
|
|
|
PERF_EVENT_IOC_ENABLE, 0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-31 13:00:56 +07:00
|
|
|
static int perf_evlist__enable_event_cpu(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel, int cpu)
|
|
|
|
{
|
|
|
|
int thread, err;
|
|
|
|
int nr_threads = perf_evlist__nr_threads(evlist, evsel);
|
|
|
|
|
|
|
|
if (!evsel->fd)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (thread = 0; thread < nr_threads; thread++) {
|
|
|
|
err = ioctl(FD(evsel, cpu, thread),
|
|
|
|
PERF_EVENT_IOC_ENABLE, 0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int perf_evlist__enable_event_thread(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel,
|
|
|
|
int thread)
|
|
|
|
{
|
|
|
|
int cpu, err;
|
|
|
|
int nr_cpus = cpu_map__nr(evlist->cpus);
|
|
|
|
|
|
|
|
if (!evsel->fd)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (cpu = 0; cpu < nr_cpus; cpu++) {
|
|
|
|
err = ioctl(FD(evsel, cpu, thread), PERF_EVENT_IOC_ENABLE, 0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int perf_evlist__enable_event_idx(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel, int idx)
|
|
|
|
{
|
|
|
|
bool per_cpu_mmaps = !cpu_map__empty(evlist->cpus);
|
|
|
|
|
|
|
|
if (per_cpu_mmaps)
|
|
|
|
return perf_evlist__enable_event_cpu(evlist, evsel, idx);
|
|
|
|
else
|
|
|
|
return perf_evlist__enable_event_thread(evlist, evsel, idx);
|
|
|
|
}
|
|
|
|
|
2014-08-19 02:44:06 +07:00
|
|
|
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
|
2011-01-12 07:30:02 +07:00
|
|
|
{
|
2013-03-11 14:43:14 +07:00
|
|
|
int nr_cpus = cpu_map__nr(evlist->cpus);
|
|
|
|
int nr_threads = thread_map__nr(evlist->threads);
|
2014-07-31 13:00:51 +07:00
|
|
|
int nfds = 0;
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
2014-10-29 20:31:54 +07:00
|
|
|
evlist__for_each(evlist, evsel) {
|
2014-07-31 13:00:51 +07:00
|
|
|
if (evsel->system_wide)
|
|
|
|
nfds += nr_cpus;
|
|
|
|
else
|
|
|
|
nfds += nr_cpus * nr_threads;
|
|
|
|
}
|
|
|
|
|
2014-09-04 04:02:59 +07:00
|
|
|
if (fdarray__available_entries(&evlist->pollfd) < nfds &&
|
|
|
|
fdarray__grow(&evlist->pollfd, nfds) < 0)
|
2014-08-19 02:44:06 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
2011-01-12 07:30:02 +07:00
|
|
|
}
|
2011-01-13 02:03:24 +07:00
|
|
|
|
2014-09-08 21:27:49 +07:00
|
|
|
static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx)
|
|
|
|
{
|
|
|
|
int pos = fdarray__add(&evlist->pollfd, fd, POLLIN | POLLERR | POLLHUP);
|
|
|
|
/*
|
|
|
|
* Save the idx so that when we filter out fds POLLHUP'ed we can
|
|
|
|
* close the associated evlist->mmap[] entry.
|
|
|
|
*/
|
|
|
|
if (pos >= 0) {
|
|
|
|
evlist->pollfd.priv[pos].idx = idx;
|
|
|
|
|
|
|
|
fcntl(fd, F_SETFL, O_NONBLOCK);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2014-08-19 02:44:06 +07:00
|
|
|
int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
|
2011-01-13 02:03:24 +07:00
|
|
|
{
|
2014-09-08 21:27:49 +07:00
|
|
|
return __perf_evlist__add_pollfd(evlist, fd, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd)
|
|
|
|
{
|
|
|
|
struct perf_evlist *evlist = container_of(fda, struct perf_evlist, pollfd);
|
2014-09-04 04:02:59 +07:00
|
|
|
|
2014-09-08 21:27:49 +07:00
|
|
|
perf_evlist__mmap_put(evlist, fda->priv[fd].idx);
|
2011-01-13 02:03:24 +07:00
|
|
|
}
|
2011-01-13 07:39:13 +07:00
|
|
|
|
2014-08-13 09:04:11 +07:00
|
|
|
int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask)
|
|
|
|
{
|
2014-09-08 21:27:49 +07:00
|
|
|
return fdarray__filter(&evlist->pollfd, revents_and_mask,
|
|
|
|
perf_evlist__munmap_filtered);
|
2014-08-13 09:04:11 +07:00
|
|
|
}
|
|
|
|
|
2014-08-19 03:25:59 +07:00
|
|
|
int perf_evlist__poll(struct perf_evlist *evlist, int timeout)
|
|
|
|
{
|
2014-09-04 04:02:59 +07:00
|
|
|
return fdarray__poll(&evlist->pollfd, timeout);
|
2014-08-19 03:25:59 +07:00
|
|
|
}
|
|
|
|
|
2011-03-10 21:15:54 +07:00
|
|
|
static void perf_evlist__id_hash(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel,
|
|
|
|
int cpu, int thread, u64 id)
|
2011-03-05 08:29:39 +07:00
|
|
|
{
|
|
|
|
int hash;
|
|
|
|
struct perf_sample_id *sid = SID(evsel, cpu, thread);
|
|
|
|
|
|
|
|
sid->id = id;
|
|
|
|
sid->evsel = evsel;
|
|
|
|
hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS);
|
|
|
|
hlist_add_head(&sid->node, &evlist->heads[hash]);
|
|
|
|
}
|
|
|
|
|
2011-03-10 21:15:54 +07:00
|
|
|
void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel,
|
|
|
|
int cpu, int thread, u64 id)
|
|
|
|
{
|
|
|
|
perf_evlist__id_hash(evlist, evsel, cpu, thread, id);
|
|
|
|
evsel->id[evsel->ids++] = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int perf_evlist__id_add_fd(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel,
|
|
|
|
int cpu, int thread, int fd)
|
2011-01-30 19:46:46 +07:00
|
|
|
{
|
|
|
|
u64 read_data[4] = { 0, };
|
2011-03-05 08:29:39 +07:00
|
|
|
int id_idx = 1; /* The first entry is the counter value */
|
2012-04-05 00:32:27 +07:00
|
|
|
u64 id;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ioctl(fd, PERF_EVENT_IOC_ID, &id);
|
|
|
|
if (!ret)
|
|
|
|
goto add;
|
|
|
|
|
|
|
|
if (errno != ENOTTY)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Legacy way to get event id.. All hail to old kernels! */
|
2011-01-30 19:46:46 +07:00
|
|
|
|
2012-10-12 18:02:21 +07:00
|
|
|
/*
|
|
|
|
* This way does not work with group format read, so bail
|
|
|
|
* out in that case.
|
|
|
|
*/
|
|
|
|
if (perf_evlist__read_format(evlist) & PERF_FORMAT_GROUP)
|
|
|
|
return -1;
|
|
|
|
|
2011-01-30 19:46:46 +07:00
|
|
|
if (!(evsel->attr.read_format & PERF_FORMAT_ID) ||
|
|
|
|
read(fd, &read_data, sizeof(read_data)) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
|
|
|
|
++id_idx;
|
|
|
|
if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
|
|
|
|
++id_idx;
|
|
|
|
|
2012-04-05 00:32:27 +07:00
|
|
|
id = read_data[id_idx];
|
|
|
|
|
|
|
|
add:
|
|
|
|
perf_evlist__id_add(evlist, evsel, cpu, thread, id);
|
2011-01-30 19:46:46 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-27 20:49:22 +07:00
|
|
|
static void perf_evlist__set_sid_idx(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel, int idx, int cpu,
|
|
|
|
int thread)
|
|
|
|
{
|
|
|
|
struct perf_sample_id *sid = SID(evsel, cpu, thread);
|
|
|
|
sid->idx = idx;
|
|
|
|
if (evlist->cpus && cpu >= 0)
|
|
|
|
sid->cpu = evlist->cpus->map[cpu];
|
|
|
|
else
|
|
|
|
sid->cpu = -1;
|
|
|
|
if (!evsel->system_wide && evlist->threads && thread >= 0)
|
2015-06-23 05:36:02 +07:00
|
|
|
sid->tid = thread_map__pid(evlist->threads, thread);
|
2014-10-27 20:49:22 +07:00
|
|
|
else
|
|
|
|
sid->tid = -1;
|
|
|
|
}
|
|
|
|
|
2012-10-11 19:10:35 +07:00
|
|
|
struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id)
|
2011-01-13 07:39:13 +07:00
|
|
|
{
|
|
|
|
struct hlist_head *head;
|
|
|
|
struct perf_sample_id *sid;
|
|
|
|
int hash;
|
|
|
|
|
|
|
|
hash = hash_64(id, PERF_EVLIST__HLIST_BITS);
|
|
|
|
head = &evlist->heads[hash];
|
|
|
|
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 08:06:00 +07:00
|
|
|
hlist_for_each_entry(sid, head, node)
|
2011-01-13 07:39:13 +07:00
|
|
|
if (sid->id == id)
|
2012-10-11 19:10:35 +07:00
|
|
|
return sid;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
|
|
|
|
{
|
|
|
|
struct perf_sample_id *sid;
|
|
|
|
|
2015-08-20 15:26:45 +07:00
|
|
|
if (evlist->nr_entries == 1 || !id)
|
2012-10-11 19:10:35 +07:00
|
|
|
return perf_evlist__first(evlist);
|
|
|
|
|
|
|
|
sid = perf_evlist__id2sid(evlist, id);
|
|
|
|
if (sid)
|
|
|
|
return sid->evsel;
|
2012-02-20 08:47:26 +07:00
|
|
|
|
|
|
|
if (!perf_evlist__sample_id_all(evlist))
|
2012-08-15 02:42:15 +07:00
|
|
|
return perf_evlist__first(evlist);
|
2012-02-20 08:47:26 +07:00
|
|
|
|
2011-01-13 07:39:13 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-15 19:40:59 +07:00
|
|
|
|
2015-09-25 20:15:52 +07:00
|
|
|
struct perf_evsel *perf_evlist__id2evsel_strict(struct perf_evlist *evlist,
|
|
|
|
u64 id)
|
|
|
|
{
|
|
|
|
struct perf_sample_id *sid;
|
|
|
|
|
|
|
|
if (!id)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sid = perf_evlist__id2sid(evlist, id);
|
|
|
|
if (sid)
|
|
|
|
return sid->evsel;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-27 15:23:09 +07:00
|
|
|
static int perf_evlist__event2id(struct perf_evlist *evlist,
|
|
|
|
union perf_event *event, u64 *id)
|
|
|
|
{
|
|
|
|
const u64 *array = event->sample.array;
|
|
|
|
ssize_t n;
|
|
|
|
|
|
|
|
n = (event->header.size - sizeof(event->header)) >> 3;
|
|
|
|
|
|
|
|
if (event->header.type == PERF_RECORD_SAMPLE) {
|
|
|
|
if (evlist->id_pos >= n)
|
|
|
|
return -1;
|
|
|
|
*id = array[evlist->id_pos];
|
|
|
|
} else {
|
|
|
|
if (evlist->is_pos > n)
|
|
|
|
return -1;
|
|
|
|
n -= evlist->is_pos;
|
|
|
|
*id = array[n];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct perf_evsel *perf_evlist__event2evsel(struct perf_evlist *evlist,
|
|
|
|
union perf_event *event)
|
|
|
|
{
|
2013-09-05 03:18:17 +07:00
|
|
|
struct perf_evsel *first = perf_evlist__first(evlist);
|
2013-08-27 15:23:09 +07:00
|
|
|
struct hlist_head *head;
|
|
|
|
struct perf_sample_id *sid;
|
|
|
|
int hash;
|
|
|
|
u64 id;
|
|
|
|
|
|
|
|
if (evlist->nr_entries == 1)
|
2013-09-05 03:18:17 +07:00
|
|
|
return first;
|
|
|
|
|
|
|
|
if (!first->attr.sample_id_all &&
|
|
|
|
event->header.type != PERF_RECORD_SAMPLE)
|
|
|
|
return first;
|
2013-08-27 15:23:09 +07:00
|
|
|
|
|
|
|
if (perf_evlist__event2id(evlist, event, &id))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Synthesized events have an id of zero */
|
|
|
|
if (!id)
|
2013-09-05 03:18:17 +07:00
|
|
|
return first;
|
2013-08-27 15:23:09 +07:00
|
|
|
|
|
|
|
hash = hash_64(id, PERF_EVLIST__HLIST_BITS);
|
|
|
|
head = &evlist->heads[hash];
|
|
|
|
|
|
|
|
hlist_for_each_entry(sid, head, node) {
|
|
|
|
if (sid->id == id)
|
|
|
|
return sid->evsel;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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 19:39:00 +07:00
|
|
|
union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
|
2011-01-15 19:40:59 +07:00
|
|
|
{
|
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 19:39:00 +07:00
|
|
|
struct perf_mmap *md = &evlist->mmap[idx];
|
perf trace: Fix race condition at the end of started workloads
I get following crash on multiple systems and across several releases
(at least since v3.18).
Core was generated by `/tmp/perf trace sleep 0.2 '.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 perf_mmap__read_head (mm=0x3fff9bf30070) at util/evlist.h:195
195 u64 head = ACCESS_ONCE(pc->data_head);
(gdb) bt
#0 perf_mmap__read_head (mm=0x3fff9bf30070) at util/evlist.h:195
#1 perf_evlist__mmap_read (evlist=0x10027f11910, idx=<optimized out>)
at util/evlist.c:637
#2 0x000000001003ce4c in trace__run (argv=<optimized out>,
argc=<optimized out>, trace=0x3fffd7b28288) at builtin-trace.c:2259
#3 cmd_trace (argc=<optimized out>, argv=<optimized out>,
prefix=<optimized out>) at builtin-trace.c:2799
#4 0x00000000100657b8 in run_builtin (p=0x10176798 <commands+480>, argc=3,
argv=0x3fffd7b2b550) at perf.c:370
#5 0x00000000100063e8 in handle_internal_command (argv=0x3fffd7b2b550, argc=3)
at perf.c:429
#6 run_argv (argv=0x3fffd7b2af70, argcp=0x3fffd7b2af7c) at perf.c:473
#7 main (argc=3, argv=0x3fffd7b2b550) at perf.c:588
The problem seems to be a race condition, when the application has just
exited. Some/all fds associated with the perf-events (tracepoints) go
into a POLLHUP/ POLLERR state and the mmap region associated with those
events are unmapped (in perf_evlist__filter_pollfd()).
But we go back and do a perf_evlist__mmap_read() which assumes that the
mmaps are still valid and we hit the crash.
If the mapping for an event is released, its refcnt is 0 (and ->base
is NULL), so ensure we have non-zero refcount before accessing the map.
Note that perf-record has a similar logic but unlike perf-trace, the
record__mmap_read_all() checks the evlist->mmap[i].base before accessing
the map.
Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Li Zhang <zhlcindy@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/20150612060003.GA19913@us.ibm.com
[ Fixed it up to use atomic_read() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-06-12 12:28:36 +07:00
|
|
|
u64 head;
|
2015-04-07 22:20:37 +07:00
|
|
|
u64 old = md->prev;
|
2011-01-15 19:40:59 +07:00
|
|
|
unsigned char *data = md->base + page_size;
|
2011-01-29 23:01:45 +07:00
|
|
|
union perf_event *event = NULL;
|
2011-01-15 19:40:59 +07:00
|
|
|
|
perf trace: Fix race condition at the end of started workloads
I get following crash on multiple systems and across several releases
(at least since v3.18).
Core was generated by `/tmp/perf trace sleep 0.2 '.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 perf_mmap__read_head (mm=0x3fff9bf30070) at util/evlist.h:195
195 u64 head = ACCESS_ONCE(pc->data_head);
(gdb) bt
#0 perf_mmap__read_head (mm=0x3fff9bf30070) at util/evlist.h:195
#1 perf_evlist__mmap_read (evlist=0x10027f11910, idx=<optimized out>)
at util/evlist.c:637
#2 0x000000001003ce4c in trace__run (argv=<optimized out>,
argc=<optimized out>, trace=0x3fffd7b28288) at builtin-trace.c:2259
#3 cmd_trace (argc=<optimized out>, argv=<optimized out>,
prefix=<optimized out>) at builtin-trace.c:2799
#4 0x00000000100657b8 in run_builtin (p=0x10176798 <commands+480>, argc=3,
argv=0x3fffd7b2b550) at perf.c:370
#5 0x00000000100063e8 in handle_internal_command (argv=0x3fffd7b2b550, argc=3)
at perf.c:429
#6 run_argv (argv=0x3fffd7b2af70, argcp=0x3fffd7b2af7c) at perf.c:473
#7 main (argc=3, argv=0x3fffd7b2b550) at perf.c:588
The problem seems to be a race condition, when the application has just
exited. Some/all fds associated with the perf-events (tracepoints) go
into a POLLHUP/ POLLERR state and the mmap region associated with those
events are unmapped (in perf_evlist__filter_pollfd()).
But we go back and do a perf_evlist__mmap_read() which assumes that the
mmaps are still valid and we hit the crash.
If the mapping for an event is released, its refcnt is 0 (and ->base
is NULL), so ensure we have non-zero refcount before accessing the map.
Note that perf-record has a similar logic but unlike perf-trace, the
record__mmap_read_all() checks the evlist->mmap[i].base before accessing
the map.
Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Li Zhang <zhlcindy@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/20150612060003.GA19913@us.ibm.com
[ Fixed it up to use atomic_read() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-06-12 12:28:36 +07:00
|
|
|
/*
|
|
|
|
* Check if event was unmapped due to a POLLHUP/POLLERR.
|
|
|
|
*/
|
|
|
|
if (!atomic_read(&md->refcnt))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
head = perf_mmap__read_head(md);
|
2011-01-29 18:08:13 +07:00
|
|
|
if (evlist->overwrite) {
|
2011-01-15 19:40:59 +07:00
|
|
|
/*
|
2011-01-29 18:08:13 +07:00
|
|
|
* If we're further behind than half the buffer, there's a chance
|
|
|
|
* the writer will bite our tail and mess up the samples under us.
|
|
|
|
*
|
|
|
|
* If we somehow ended up ahead of the head, we got messed up.
|
|
|
|
*
|
|
|
|
* In either case, truncate and restart at head.
|
2011-01-15 19:40:59 +07:00
|
|
|
*/
|
2011-01-29 18:08:13 +07:00
|
|
|
int diff = head - old;
|
|
|
|
if (diff > md->mask / 2 || diff < 0) {
|
|
|
|
fprintf(stderr, "WARNING: failed to keep up with mmap data.\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* head points to a known good entry, start there.
|
|
|
|
*/
|
|
|
|
old = head;
|
|
|
|
}
|
2011-01-15 19:40:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (old != head) {
|
|
|
|
size_t size;
|
|
|
|
|
2011-01-29 23:01:45 +07:00
|
|
|
event = (union perf_event *)&data[old & md->mask];
|
2011-01-15 19:40:59 +07:00
|
|
|
size = event->header.size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Event straddles the mmap boundary -- header should always
|
|
|
|
* be inside due to u64 alignment of output.
|
|
|
|
*/
|
|
|
|
if ((old & md->mask) + size != ((old + size) & md->mask)) {
|
|
|
|
unsigned int offset = old;
|
|
|
|
unsigned int len = min(sizeof(*event), size), cpy;
|
2013-10-02 20:46:39 +07:00
|
|
|
void *dst = md->event_copy;
|
2011-01-15 19:40:59 +07:00
|
|
|
|
|
|
|
do {
|
|
|
|
cpy = min(md->mask + 1 - (offset & md->mask), len);
|
|
|
|
memcpy(dst, &data[offset & md->mask], cpy);
|
|
|
|
offset += cpy;
|
|
|
|
dst += cpy;
|
|
|
|
len -= cpy;
|
|
|
|
} while (len);
|
|
|
|
|
2013-10-02 20:46:39 +07:00
|
|
|
event = (union perf_event *) md->event_copy;
|
2011-01-15 19:40:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
old += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
md->prev = old;
|
2011-01-29 18:08:13 +07:00
|
|
|
|
2011-01-15 19:40:59 +07:00
|
|
|
return event;
|
|
|
|
}
|
2011-01-30 19:46:46 +07:00
|
|
|
|
2014-09-08 23:26:35 +07:00
|
|
|
static bool perf_mmap__empty(struct perf_mmap *md)
|
|
|
|
{
|
2015-04-25 02:29:43 +07:00
|
|
|
return perf_mmap__read_head(md) == md->prev && !md->auxtrace_mmap.base;
|
2014-09-08 23:26:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void perf_evlist__mmap_get(struct perf_evlist *evlist, int idx)
|
|
|
|
{
|
2015-05-16 01:45:16 +07:00
|
|
|
atomic_inc(&evlist->mmap[idx].refcnt);
|
2014-09-08 23:26:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx)
|
|
|
|
{
|
2015-05-16 01:45:16 +07:00
|
|
|
BUG_ON(atomic_read(&evlist->mmap[idx].refcnt) == 0);
|
2014-09-08 23:26:35 +07:00
|
|
|
|
2015-05-16 01:45:16 +07:00
|
|
|
if (atomic_dec_and_test(&evlist->mmap[idx].refcnt))
|
2014-09-08 23:26:35 +07:00
|
|
|
__perf_evlist__munmap(evlist, idx);
|
|
|
|
}
|
|
|
|
|
2013-10-24 14:43:33 +07:00
|
|
|
void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx)
|
|
|
|
{
|
2014-09-08 23:26:35 +07:00
|
|
|
struct perf_mmap *md = &evlist->mmap[idx];
|
|
|
|
|
2013-10-24 14:43:33 +07:00
|
|
|
if (!evlist->overwrite) {
|
2015-04-07 22:20:37 +07:00
|
|
|
u64 old = md->prev;
|
2013-10-24 14:43:33 +07:00
|
|
|
|
|
|
|
perf_mmap__write_tail(md, old);
|
|
|
|
}
|
2014-09-08 23:26:35 +07:00
|
|
|
|
2015-05-16 01:45:16 +07:00
|
|
|
if (atomic_read(&md->refcnt) == 1 && perf_mmap__empty(md))
|
2014-09-08 23:26:35 +07:00
|
|
|
perf_evlist__mmap_put(evlist, idx);
|
2013-10-24 14:43:33 +07:00
|
|
|
}
|
|
|
|
|
2015-04-09 22:53:42 +07:00
|
|
|
int __weak auxtrace_mmap__mmap(struct auxtrace_mmap *mm __maybe_unused,
|
|
|
|
struct auxtrace_mmap_params *mp __maybe_unused,
|
|
|
|
void *userpg __maybe_unused,
|
|
|
|
int fd __maybe_unused)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __weak auxtrace_mmap__munmap(struct auxtrace_mmap *mm __maybe_unused)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void __weak auxtrace_mmap_params__init(
|
|
|
|
struct auxtrace_mmap_params *mp __maybe_unused,
|
|
|
|
off_t auxtrace_offset __maybe_unused,
|
|
|
|
unsigned int auxtrace_pages __maybe_unused,
|
|
|
|
bool auxtrace_overwrite __maybe_unused)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void __weak auxtrace_mmap_params__set_idx(
|
|
|
|
struct auxtrace_mmap_params *mp __maybe_unused,
|
|
|
|
struct perf_evlist *evlist __maybe_unused,
|
|
|
|
int idx __maybe_unused,
|
|
|
|
bool per_cpu __maybe_unused)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-04 20:20:26 +07:00
|
|
|
static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx)
|
|
|
|
{
|
|
|
|
if (evlist->mmap[idx].base != NULL) {
|
|
|
|
munmap(evlist->mmap[idx].base, evlist->mmap_len);
|
|
|
|
evlist->mmap[idx].base = NULL;
|
2015-05-16 01:45:16 +07:00
|
|
|
atomic_set(&evlist->mmap[idx].refcnt, 0);
|
2013-07-04 20:20:26 +07:00
|
|
|
}
|
2015-04-09 22:53:42 +07:00
|
|
|
auxtrace_mmap__munmap(&evlist->mmap[idx].auxtrace_mmap);
|
2013-07-04 20:20:26 +07:00
|
|
|
}
|
|
|
|
|
2011-01-30 20:59:43 +07:00
|
|
|
void perf_evlist__munmap(struct perf_evlist *evlist)
|
2011-01-30 19:46:46 +07:00
|
|
|
{
|
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 19:39:00 +07:00
|
|
|
int i;
|
2011-01-30 19:46:46 +07:00
|
|
|
|
2014-01-04 03:25:49 +07:00
|
|
|
if (evlist->mmap == NULL)
|
|
|
|
return;
|
|
|
|
|
2013-07-04 20:20:26 +07:00
|
|
|
for (i = 0; i < evlist->nr_mmaps; i++)
|
|
|
|
__perf_evlist__munmap(evlist, i);
|
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 19:39:00 +07:00
|
|
|
|
2013-12-27 03:41:15 +07:00
|
|
|
zfree(&evlist->mmap);
|
2011-01-30 19:46:46 +07:00
|
|
|
}
|
|
|
|
|
2011-11-29 17:05:52 +07:00
|
|
|
static int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
|
2011-01-30 19:46:46 +07:00
|
|
|
{
|
2012-09-26 22:41:14 +07:00
|
|
|
evlist->nr_mmaps = cpu_map__nr(evlist->cpus);
|
2013-05-23 07:42:38 +07:00
|
|
|
if (cpu_map__empty(evlist->cpus))
|
2013-03-11 14:43:14 +07:00
|
|
|
evlist->nr_mmaps = thread_map__nr(evlist->threads);
|
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 19:39:00 +07:00
|
|
|
evlist->mmap = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
|
2011-01-30 19:46:46 +07:00
|
|
|
return evlist->mmap != NULL ? 0 : -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2014-07-14 17:02:52 +07:00
|
|
|
struct mmap_params {
|
|
|
|
int prot;
|
|
|
|
int mask;
|
2015-04-09 22:53:42 +07:00
|
|
|
struct auxtrace_mmap_params auxtrace_mp;
|
2014-07-14 17:02:52 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __perf_evlist__mmap(struct perf_evlist *evlist, int idx,
|
|
|
|
struct mmap_params *mp, int fd)
|
2011-01-30 19:46:46 +07:00
|
|
|
{
|
2014-09-08 23:26:35 +07:00
|
|
|
/*
|
|
|
|
* The last one will be done at perf_evlist__mmap_consume(), so that we
|
|
|
|
* make sure we don't prevent tools from consuming every last event in
|
|
|
|
* the ring buffer.
|
|
|
|
*
|
|
|
|
* I.e. we can get the POLLHUP meaning that the fd doesn't exist
|
|
|
|
* anymore, but the last events for it are still in the ring buffer,
|
|
|
|
* waiting to be consumed.
|
|
|
|
*
|
|
|
|
* Tools can chose to ignore this at their own discretion, but the
|
|
|
|
* evlist layer can't just drop it when filtering events in
|
|
|
|
* perf_evlist__filter_pollfd().
|
|
|
|
*/
|
2015-05-16 01:45:16 +07:00
|
|
|
atomic_set(&evlist->mmap[idx].refcnt, 2);
|
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 19:39:00 +07:00
|
|
|
evlist->mmap[idx].prev = 0;
|
2014-07-14 17:02:52 +07:00
|
|
|
evlist->mmap[idx].mask = mp->mask;
|
|
|
|
evlist->mmap[idx].base = mmap(NULL, evlist->mmap_len, mp->prot,
|
2011-01-30 19:46:46 +07:00
|
|
|
MAP_SHARED, fd, 0);
|
2011-12-19 20:39:30 +07:00
|
|
|
if (evlist->mmap[idx].base == MAP_FAILED) {
|
2013-11-01 20:51:33 +07:00
|
|
|
pr_debug2("failed to mmap perf event ring buffer, error %d\n",
|
|
|
|
errno);
|
2011-12-19 20:39:30 +07:00
|
|
|
evlist->mmap[idx].base = NULL;
|
2011-01-30 19:46:46 +07:00
|
|
|
return -1;
|
2011-12-19 20:39:30 +07:00
|
|
|
}
|
2014-08-19 02:44:06 +07:00
|
|
|
|
2015-04-09 22:53:42 +07:00
|
|
|
if (auxtrace_mmap__mmap(&evlist->mmap[idx].auxtrace_mmap,
|
|
|
|
&mp->auxtrace_mp, evlist->mmap[idx].base, fd))
|
|
|
|
return -1;
|
|
|
|
|
2011-01-30 19:46:46 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-18 19:29:13 +07:00
|
|
|
static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
|
2014-07-14 17:02:52 +07:00
|
|
|
struct mmap_params *mp, int cpu,
|
|
|
|
int thread, int *output)
|
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 19:39:00 +07:00
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
2013-10-18 19:29:13 +07:00
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, evsel) {
|
2014-07-31 13:00:51 +07:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (evsel->system_wide && thread)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fd = FD(evsel, cpu, thread);
|
2013-10-18 19:29:13 +07:00
|
|
|
|
|
|
|
if (*output == -1) {
|
|
|
|
*output = fd;
|
2014-07-14 17:02:52 +07:00
|
|
|
if (__perf_evlist__mmap(evlist, idx, mp, *output) < 0)
|
2013-10-18 19:29:13 +07:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
|
|
|
|
return -1;
|
2014-09-08 23:26:35 +07:00
|
|
|
|
|
|
|
perf_evlist__mmap_get(evlist, idx);
|
2013-10-18 19:29:13 +07:00
|
|
|
}
|
|
|
|
|
2014-11-11 21:16:39 +07:00
|
|
|
/*
|
|
|
|
* The system_wide flag causes a selected event to be opened
|
|
|
|
* always without a pid. Consequently it will never get a
|
|
|
|
* POLLHUP, but it is used for tracking in combination with
|
|
|
|
* other events, so it should not need to be polled anyway.
|
|
|
|
* Therefore don't add it for polling.
|
|
|
|
*/
|
|
|
|
if (!evsel->system_wide &&
|
|
|
|
__perf_evlist__add_pollfd(evlist, fd, idx) < 0) {
|
2014-09-08 23:26:35 +07:00
|
|
|
perf_evlist__mmap_put(evlist, idx);
|
2014-08-19 02:44:06 +07:00
|
|
|
return -1;
|
2014-09-08 23:26:35 +07:00
|
|
|
}
|
2014-09-08 22:55:12 +07:00
|
|
|
|
2014-10-27 20:49:22 +07:00
|
|
|
if (evsel->attr.read_format & PERF_FORMAT_ID) {
|
|
|
|
if (perf_evlist__id_add_fd(evlist, evsel, cpu, thread,
|
|
|
|
fd) < 0)
|
|
|
|
return -1;
|
|
|
|
perf_evlist__set_sid_idx(evlist, evsel, idx, cpu,
|
|
|
|
thread);
|
|
|
|
}
|
2013-10-18 19:29:13 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-14 17:02:52 +07:00
|
|
|
static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist,
|
|
|
|
struct mmap_params *mp)
|
2013-10-18 19:29:13 +07:00
|
|
|
{
|
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 19:39:00 +07:00
|
|
|
int cpu, thread;
|
2013-03-11 14:43:14 +07:00
|
|
|
int nr_cpus = cpu_map__nr(evlist->cpus);
|
|
|
|
int nr_threads = thread_map__nr(evlist->threads);
|
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 19:39:00 +07:00
|
|
|
|
2013-08-14 19:48:24 +07:00
|
|
|
pr_debug2("perf event ring buffer mmapped per cpu\n");
|
2013-03-11 14:43:14 +07:00
|
|
|
for (cpu = 0; cpu < nr_cpus; cpu++) {
|
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 19:39:00 +07:00
|
|
|
int output = -1;
|
|
|
|
|
2015-04-09 22:53:42 +07:00
|
|
|
auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, cpu,
|
|
|
|
true);
|
|
|
|
|
2013-03-11 14:43:14 +07:00
|
|
|
for (thread = 0; thread < nr_threads; thread++) {
|
2014-07-14 17:02:52 +07:00
|
|
|
if (perf_evlist__mmap_per_evsel(evlist, cpu, mp, cpu,
|
|
|
|
thread, &output))
|
2013-10-18 19:29:13 +07:00
|
|
|
goto out_unmap;
|
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 19:39:00 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_unmap:
|
2013-07-04 20:20:26 +07:00
|
|
|
for (cpu = 0; cpu < nr_cpus; cpu++)
|
|
|
|
__perf_evlist__munmap(evlist, cpu);
|
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 19:39:00 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-07-14 17:02:52 +07:00
|
|
|
static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist,
|
|
|
|
struct mmap_params *mp)
|
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 19:39:00 +07:00
|
|
|
{
|
|
|
|
int thread;
|
2013-03-11 14:43:14 +07:00
|
|
|
int nr_threads = thread_map__nr(evlist->threads);
|
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 19:39:00 +07:00
|
|
|
|
2013-08-14 19:48:24 +07:00
|
|
|
pr_debug2("perf event ring buffer mmapped per thread\n");
|
2013-03-11 14:43:14 +07:00
|
|
|
for (thread = 0; thread < nr_threads; thread++) {
|
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 19:39:00 +07:00
|
|
|
int output = -1;
|
|
|
|
|
2015-04-09 22:53:42 +07:00
|
|
|
auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, thread,
|
|
|
|
false);
|
|
|
|
|
2014-07-14 17:02:52 +07:00
|
|
|
if (perf_evlist__mmap_per_evsel(evlist, thread, mp, 0, thread,
|
|
|
|
&output))
|
2013-10-18 19:29:13 +07:00
|
|
|
goto out_unmap;
|
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 19:39:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_unmap:
|
2013-07-04 20:20:26 +07:00
|
|
|
for (thread = 0; thread < nr_threads; thread++)
|
|
|
|
__perf_evlist__munmap(evlist, thread);
|
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 19:39:00 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-01 17:36:12 +07:00
|
|
|
static size_t perf_evlist__mmap_size(unsigned long pages)
|
|
|
|
{
|
2014-12-13 03:46:45 +07:00
|
|
|
if (pages == UINT_MAX) {
|
|
|
|
int max;
|
|
|
|
|
|
|
|
if (sysctl__read_int("kernel/perf_event_mlock_kb", &max) < 0) {
|
|
|
|
/*
|
|
|
|
* Pick a once upon a time good value, i.e. things look
|
|
|
|
* strange since we can't read a sysctl value, but lets not
|
|
|
|
* die yet...
|
|
|
|
*/
|
|
|
|
max = 512;
|
|
|
|
} else {
|
|
|
|
max -= (page_size / 1024);
|
|
|
|
}
|
|
|
|
|
|
|
|
pages = (max * 1024) / page_size;
|
2014-12-16 22:19:00 +07:00
|
|
|
if (!is_power_of_2(pages))
|
|
|
|
pages = rounddown_pow_of_two(pages);
|
2014-12-13 03:46:45 +07:00
|
|
|
} else if (!is_power_of_2(pages))
|
2013-09-01 17:36:12 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return (pages + 1) * page_size;
|
|
|
|
}
|
|
|
|
|
2013-11-12 21:46:55 +07:00
|
|
|
static long parse_pages_arg(const char *str, unsigned long min,
|
|
|
|
unsigned long max)
|
2013-09-01 17:36:12 +07:00
|
|
|
{
|
2013-10-22 14:34:18 +07:00
|
|
|
unsigned long pages, val;
|
2013-09-01 17:36:13 +07:00
|
|
|
static struct parse_tag tags[] = {
|
|
|
|
{ .tag = 'B', .mult = 1 },
|
|
|
|
{ .tag = 'K', .mult = 1 << 10 },
|
|
|
|
{ .tag = 'M', .mult = 1 << 20 },
|
|
|
|
{ .tag = 'G', .mult = 1 << 30 },
|
|
|
|
{ .tag = 0 },
|
|
|
|
};
|
2013-09-01 17:36:12 +07:00
|
|
|
|
2013-11-12 21:46:53 +07:00
|
|
|
if (str == NULL)
|
2013-11-12 21:46:55 +07:00
|
|
|
return -EINVAL;
|
2013-11-12 21:46:53 +07:00
|
|
|
|
2013-09-01 17:36:13 +07:00
|
|
|
val = parse_tag_value(str, tags);
|
2013-10-22 14:34:18 +07:00
|
|
|
if (val != (unsigned long) -1) {
|
2013-09-01 17:36:13 +07:00
|
|
|
/* we got file size value */
|
|
|
|
pages = PERF_ALIGN(val, page_size) / page_size;
|
|
|
|
} else {
|
|
|
|
/* we got pages count value */
|
|
|
|
char *eptr;
|
|
|
|
pages = strtoul(str, &eptr, 10);
|
2013-11-12 21:46:55 +07:00
|
|
|
if (*eptr != '\0')
|
|
|
|
return -EINVAL;
|
2013-09-01 17:36:12 +07:00
|
|
|
}
|
|
|
|
|
2013-12-09 20:18:37 +07:00
|
|
|
if (pages == 0 && min == 0) {
|
2013-11-12 21:46:55 +07:00
|
|
|
/* leave number of pages at 0 */
|
2013-12-09 20:18:39 +07:00
|
|
|
} else if (!is_power_of_2(pages)) {
|
2013-11-12 21:46:55 +07:00
|
|
|
/* round pages up to next power of 2 */
|
2014-12-16 23:24:41 +07:00
|
|
|
pages = roundup_pow_of_two(pages);
|
2013-12-09 20:18:39 +07:00
|
|
|
if (!pages)
|
|
|
|
return -EINVAL;
|
2013-11-12 21:46:54 +07:00
|
|
|
pr_info("rounding mmap pages size to %lu bytes (%lu pages)\n",
|
|
|
|
pages * page_size, pages);
|
2013-10-22 14:34:18 +07:00
|
|
|
}
|
|
|
|
|
2013-11-12 21:46:55 +07:00
|
|
|
if (pages > max)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return pages;
|
|
|
|
}
|
|
|
|
|
2015-04-09 22:53:46 +07:00
|
|
|
int __perf_evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str)
|
2013-11-12 21:46:55 +07:00
|
|
|
{
|
|
|
|
unsigned long max = UINT_MAX;
|
|
|
|
long pages;
|
|
|
|
|
2013-12-09 20:18:38 +07:00
|
|
|
if (max > SIZE_MAX / page_size)
|
2013-11-12 21:46:55 +07:00
|
|
|
max = SIZE_MAX / page_size;
|
|
|
|
|
|
|
|
pages = parse_pages_arg(str, 1, max);
|
|
|
|
if (pages < 0) {
|
|
|
|
pr_err("Invalid argument for --mmap_pages/-m\n");
|
2013-09-01 17:36:12 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*mmap_pages = pages;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-09 22:53:46 +07:00
|
|
|
int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
|
|
|
|
int unset __maybe_unused)
|
|
|
|
{
|
|
|
|
return __perf_evlist__parse_mmap_pages(opt->value, str);
|
|
|
|
}
|
|
|
|
|
2013-10-18 19:29:12 +07:00
|
|
|
/**
|
2015-04-09 22:53:42 +07:00
|
|
|
* perf_evlist__mmap_ex - Create mmaps to receive events.
|
2013-10-18 19:29:12 +07:00
|
|
|
* @evlist: list of events
|
|
|
|
* @pages: map length in pages
|
|
|
|
* @overwrite: overwrite older events?
|
2015-04-09 22:53:42 +07:00
|
|
|
* @auxtrace_pages - auxtrace map length in pages
|
|
|
|
* @auxtrace_overwrite - overwrite older auxtrace data?
|
2011-01-30 19:46:46 +07:00
|
|
|
*
|
2013-10-18 19:29:12 +07:00
|
|
|
* If @overwrite is %false the user needs to signal event consumption using
|
|
|
|
* perf_mmap__write_tail(). Using perf_evlist__mmap_read() does this
|
|
|
|
* automatically.
|
2011-01-30 20:59:43 +07:00
|
|
|
*
|
2015-04-09 22:53:42 +07:00
|
|
|
* Similarly, if @auxtrace_overwrite is %false the user needs to signal data
|
|
|
|
* consumption using auxtrace_mmap__write_tail().
|
|
|
|
*
|
2013-10-18 19:29:12 +07:00
|
|
|
* Return: %0 on success, negative error code otherwise.
|
2011-01-30 19:46:46 +07:00
|
|
|
*/
|
2015-04-09 22:53:42 +07:00
|
|
|
int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
|
|
|
|
bool overwrite, unsigned int auxtrace_pages,
|
|
|
|
bool auxtrace_overwrite)
|
2011-01-30 19:46:46 +07:00
|
|
|
{
|
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 19:39:00 +07:00
|
|
|
struct perf_evsel *evsel;
|
2011-01-30 20:59:43 +07:00
|
|
|
const struct cpu_map *cpus = evlist->cpus;
|
|
|
|
const struct thread_map *threads = evlist->threads;
|
2014-07-14 17:02:52 +07:00
|
|
|
struct mmap_params mp = {
|
|
|
|
.prot = PROT_READ | (overwrite ? 0 : PROT_WRITE),
|
|
|
|
};
|
2011-11-09 18:10:47 +07:00
|
|
|
|
2011-01-30 20:59:43 +07:00
|
|
|
if (evlist->mmap == NULL && perf_evlist__alloc_mmap(evlist) < 0)
|
2011-01-30 19:46:46 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2014-09-04 04:02:59 +07:00
|
|
|
if (evlist->pollfd.entries == NULL && perf_evlist__alloc_pollfd(evlist) < 0)
|
2011-01-30 19:46:46 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
evlist->overwrite = overwrite;
|
2013-09-01 17:36:12 +07:00
|
|
|
evlist->mmap_len = perf_evlist__mmap_size(pages);
|
2013-10-18 19:29:07 +07:00
|
|
|
pr_debug("mmap size %zuB\n", evlist->mmap_len);
|
2014-07-14 17:02:52 +07:00
|
|
|
mp.mask = evlist->mmap_len - page_size - 1;
|
2011-01-30 19:46:46 +07:00
|
|
|
|
2015-04-09 22:53:42 +07:00
|
|
|
auxtrace_mmap_params__init(&mp.auxtrace_mp, evlist->mmap_len,
|
|
|
|
auxtrace_pages, auxtrace_overwrite);
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, evsel) {
|
2011-01-30 19:46:46 +07:00
|
|
|
if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
|
2011-03-10 21:15:54 +07:00
|
|
|
evsel->sample_id == NULL &&
|
2012-09-26 22:41:14 +07:00
|
|
|
perf_evsel__alloc_id(evsel, cpu_map__nr(cpus), threads->nr) < 0)
|
2011-01-30 19:46:46 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-05-23 07:42:38 +07:00
|
|
|
if (cpu_map__empty(cpus))
|
2014-07-14 17:02:52 +07:00
|
|
|
return perf_evlist__mmap_per_thread(evlist, &mp);
|
2011-01-30 19:46:46 +07:00
|
|
|
|
2014-07-14 17:02:52 +07:00
|
|
|
return perf_evlist__mmap_per_cpu(evlist, &mp);
|
2011-01-30 19:46:46 +07:00
|
|
|
}
|
2011-01-30 20:59:43 +07:00
|
|
|
|
2015-04-09 22:53:42 +07:00
|
|
|
int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
|
|
|
|
bool overwrite)
|
|
|
|
{
|
|
|
|
return perf_evlist__mmap_ex(evlist, pages, overwrite, 0, false);
|
|
|
|
}
|
|
|
|
|
2013-11-13 02:46:16 +07:00
|
|
|
int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
|
2011-01-30 20:59:43 +07:00
|
|
|
{
|
2015-09-08 14:58:57 +07:00
|
|
|
struct cpu_map *cpus;
|
|
|
|
struct thread_map *threads;
|
2011-01-30 20:59:43 +07:00
|
|
|
|
2015-09-08 14:58:57 +07:00
|
|
|
threads = thread_map__new_str(target->pid, target->tid, target->uid);
|
2011-01-30 20:59:43 +07:00
|
|
|
|
2015-09-08 14:58:57 +07:00
|
|
|
if (!threads)
|
2011-01-30 20:59:43 +07:00
|
|
|
return -1;
|
|
|
|
|
2013-12-05 05:56:40 +07:00
|
|
|
if (target__uses_dummy_map(target))
|
2015-09-08 14:58:57 +07:00
|
|
|
cpus = cpu_map__dummy_new();
|
2012-05-16 16:45:48 +07:00
|
|
|
else
|
2015-09-08 14:58:57 +07:00
|
|
|
cpus = cpu_map__new(target->cpu_list);
|
2011-01-30 20:59:43 +07:00
|
|
|
|
2015-09-08 14:58:57 +07:00
|
|
|
if (!cpus)
|
2011-01-30 20:59:43 +07:00
|
|
|
goto out_delete_threads;
|
|
|
|
|
2015-09-08 14:58:52 +07:00
|
|
|
evlist->has_user_cpus = !!target->cpu_list;
|
|
|
|
|
2015-09-08 14:58:57 +07:00
|
|
|
perf_evlist__set_maps(evlist, cpus, threads);
|
2015-09-08 14:58:51 +07:00
|
|
|
|
|
|
|
return 0;
|
2011-01-30 20:59:43 +07:00
|
|
|
|
|
|
|
out_delete_threads:
|
2015-09-08 14:58:57 +07:00
|
|
|
thread_map__put(threads);
|
2011-01-30 20:59:43 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-09-08 14:58:51 +07:00
|
|
|
void perf_evlist__set_maps(struct perf_evlist *evlist, struct cpu_map *cpus,
|
|
|
|
struct thread_map *threads)
|
2015-07-21 19:31:30 +07:00
|
|
|
{
|
2015-09-08 14:58:56 +07:00
|
|
|
/*
|
|
|
|
* Allow for the possibility that one or another of the maps isn't being
|
|
|
|
* changed i.e. don't put it. Note we are assuming the maps that are
|
|
|
|
* being applied are brand new and evlist is taking ownership of the
|
|
|
|
* original reference count of 1. If that is not the case it is up to
|
|
|
|
* the caller to increase the reference count.
|
|
|
|
*/
|
|
|
|
if (cpus != evlist->cpus) {
|
2015-07-21 19:31:30 +07:00
|
|
|
cpu_map__put(evlist->cpus);
|
2015-09-08 14:58:56 +07:00
|
|
|
evlist->cpus = cpus;
|
|
|
|
}
|
2015-07-21 19:31:30 +07:00
|
|
|
|
2015-09-08 14:58:56 +07:00
|
|
|
if (threads != evlist->threads) {
|
2015-07-21 19:31:30 +07:00
|
|
|
thread_map__put(evlist->threads);
|
2015-09-08 14:58:56 +07:00
|
|
|
evlist->threads = threads;
|
|
|
|
}
|
2015-07-21 19:31:30 +07:00
|
|
|
|
2015-09-08 14:58:52 +07:00
|
|
|
perf_evlist__propagate_maps(evlist);
|
2015-07-21 19:31:30 +07:00
|
|
|
}
|
|
|
|
|
2015-03-25 05:23:47 +07:00
|
|
|
int perf_evlist__apply_filters(struct perf_evlist *evlist, struct perf_evsel **err_evsel)
|
2011-02-26 10:51:54 +07:00
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
2012-09-27 01:07:39 +07:00
|
|
|
int err = 0;
|
|
|
|
const int ncpus = cpu_map__nr(evlist->cpus),
|
2013-03-11 14:43:14 +07:00
|
|
|
nthreads = thread_map__nr(evlist->threads);
|
2011-02-26 10:51:54 +07:00
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, evsel) {
|
2012-09-27 01:07:39 +07:00
|
|
|
if (evsel->filter == NULL)
|
2011-02-26 10:51:54 +07:00
|
|
|
continue;
|
2012-09-27 01:07:39 +07:00
|
|
|
|
2015-08-21 13:23:14 +07:00
|
|
|
/*
|
|
|
|
* filters only work for tracepoint event, which doesn't have cpu limit.
|
|
|
|
* So evlist and evsel should always be same.
|
|
|
|
*/
|
perf evsel: Rename set_filter to apply_filter
We need to be able to go on constructing a complex filter in multiple
stages, since we can only set one filter per event.
For instance, we need to be able, in 'perf trace' to filter by the
'common_pid' field all the time, if only for the tracer itself, to
avoid a feedback loop, and, in addition, we may want to filter the
raw_syscalls:sys_{enter,exit} events by its 'id' filter, when using
'perf trace -e open,close' or 'perf trace -e !open,close', i.e. when
we are interested in just a subset of syscalls or when we are not
interested in it.
So we will have:
perf_evsel__set_filter(evsel, char *filter)
Replaces whatever is in evsel->filter.
perf_evsel__append_filter(evsel, const char *op, char *filter)
Appends, using op ("&&" or "||") with what is in evsel->filter.
perf_evsel__apply_filter(evsel, filter):
That actually applies a filter, be it the one being
constructed in evsel->filter, or any other, for tools
with more specific ways to build the filter, issuing
the appropriate ioctl for all the evsel fds.
The same changes will be made to the evlist__{set,apply} variants to
keep everything consistent.
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-2s5z9xtpnc2lwio3cv5x0jek@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-07-04 01:53:49 +07:00
|
|
|
err = perf_evsel__apply_filter(evsel, ncpus, nthreads, evsel->filter);
|
2015-03-25 05:23:47 +07:00
|
|
|
if (err) {
|
|
|
|
*err_evsel = evsel;
|
2012-09-27 01:07:39 +07:00
|
|
|
break;
|
2015-03-25 05:23:47 +07:00
|
|
|
}
|
2011-02-26 10:51:54 +07:00
|
|
|
}
|
|
|
|
|
2012-09-27 01:07:39 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
int err = 0;
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, evsel) {
|
perf evlist: Make perf_evlist__set_filter use perf_evsel__set_filter
Instead of calling perf_evsel__apply_filter straight away, so that
we can, in the next patches, expand the filter with more conditions
before actually calling the ioctl to pass the end result filter to
the kernel.
Now we need to call perf_evlist__apply_filters() after the filter
is completely setup, i.e. do the ioctl calls.
The perf_evlist__apply_filters() method was already in place, because
that is the model for the other tools that receives filters in the
command line: go on setting then in the evsel->filter and only at
the end, after parsing the whole command line, apply them.
We get, as a bonus, a more expressive message that states which
event, if any, failed to have the filter applied to, with an
error message stating what happened.
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-f429pgz75ryz7tpe6v74etre@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-07-04 03:42:03 +07:00
|
|
|
err = perf_evsel__set_filter(evsel, filter);
|
2012-09-27 01:07:39 +07:00
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2011-02-26 10:51:54 +07:00
|
|
|
}
|
2011-05-21 22:49:00 +07:00
|
|
|
|
2015-02-22 02:33:47 +07:00
|
|
|
int perf_evlist__set_filter_pids(struct perf_evlist *evlist, size_t npids, pid_t *pids)
|
2015-02-22 01:09:55 +07:00
|
|
|
{
|
|
|
|
char *filter;
|
2015-02-22 02:33:47 +07:00
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
2015-02-22 01:09:55 +07:00
|
|
|
|
2015-02-22 02:33:47 +07:00
|
|
|
for (i = 0; i < npids; ++i) {
|
|
|
|
if (i == 0) {
|
|
|
|
if (asprintf(&filter, "common_pid != %d", pids[i]) < 0)
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if (asprintf(&tmp, "%s && common_pid != %d", filter, pids[i]) < 0)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
free(filter);
|
|
|
|
filter = tmp;
|
|
|
|
}
|
|
|
|
}
|
2015-02-22 01:09:55 +07:00
|
|
|
|
|
|
|
ret = perf_evlist__set_filter(evlist, filter);
|
2015-02-22 02:33:47 +07:00
|
|
|
out_free:
|
2015-02-22 01:09:55 +07:00
|
|
|
free(filter);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-22 02:33:47 +07:00
|
|
|
int perf_evlist__set_filter_pid(struct perf_evlist *evlist, pid_t pid)
|
|
|
|
{
|
|
|
|
return perf_evlist__set_filter_pids(evlist, 1, &pid);
|
|
|
|
}
|
|
|
|
|
2012-08-15 02:42:15 +07:00
|
|
|
bool perf_evlist__valid_sample_type(struct perf_evlist *evlist)
|
2011-05-21 22:49:00 +07:00
|
|
|
{
|
2013-08-27 15:23:09 +07:00
|
|
|
struct perf_evsel *pos;
|
2011-06-02 21:04:54 +07:00
|
|
|
|
2013-08-27 15:23:09 +07:00
|
|
|
if (evlist->nr_entries == 1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (evlist->id_pos < 0 || evlist->is_pos < 0)
|
|
|
|
return false;
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, pos) {
|
2013-08-27 15:23:09 +07:00
|
|
|
if (pos->id_pos != evlist->id_pos ||
|
|
|
|
pos->is_pos != evlist->is_pos)
|
2011-06-02 21:04:54 +07:00
|
|
|
return false;
|
2011-05-21 22:49:00 +07:00
|
|
|
}
|
|
|
|
|
2011-06-02 21:04:54 +07:00
|
|
|
return true;
|
2011-05-21 22:49:00 +07:00
|
|
|
}
|
|
|
|
|
2013-08-27 15:23:09 +07:00
|
|
|
u64 __perf_evlist__combined_sample_type(struct perf_evlist *evlist)
|
2011-06-02 21:04:54 +07:00
|
|
|
{
|
2013-08-27 15:23:09 +07:00
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
|
|
|
if (evlist->combined_sample_type)
|
|
|
|
return evlist->combined_sample_type;
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, evsel)
|
2013-08-27 15:23:09 +07:00
|
|
|
evlist->combined_sample_type |= evsel->attr.sample_type;
|
|
|
|
|
|
|
|
return evlist->combined_sample_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 perf_evlist__combined_sample_type(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
evlist->combined_sample_type = 0;
|
|
|
|
return __perf_evlist__combined_sample_type(evlist);
|
2011-06-02 21:04:54 +07:00
|
|
|
}
|
|
|
|
|
2015-07-18 22:24:47 +07:00
|
|
|
u64 perf_evlist__combined_branch_type(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
u64 branch_type = 0;
|
|
|
|
|
|
|
|
evlist__for_each(evlist, evsel)
|
|
|
|
branch_type |= evsel->attr.branch_sample_type;
|
|
|
|
return branch_type;
|
|
|
|
}
|
|
|
|
|
2012-10-10 22:38:13 +07:00
|
|
|
bool perf_evlist__valid_read_format(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *first = perf_evlist__first(evlist), *pos = first;
|
|
|
|
u64 read_format = first->attr.read_format;
|
|
|
|
u64 sample_type = first->attr.sample_type;
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, pos) {
|
2012-10-10 22:38:13 +07:00
|
|
|
if (read_format != pos->attr.read_format)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PERF_SAMPLE_READ imples PERF_FORMAT_ID. */
|
|
|
|
if ((sample_type & PERF_SAMPLE_READ) &&
|
|
|
|
!(read_format & PERF_FORMAT_ID)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 perf_evlist__read_format(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *first = perf_evlist__first(evlist);
|
|
|
|
return first->attr.read_format;
|
|
|
|
}
|
|
|
|
|
2012-08-15 02:42:15 +07:00
|
|
|
u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist)
|
2011-11-12 07:28:50 +07:00
|
|
|
{
|
2012-08-15 02:42:15 +07:00
|
|
|
struct perf_evsel *first = perf_evlist__first(evlist);
|
2011-11-12 07:28:50 +07:00
|
|
|
struct perf_sample *data;
|
|
|
|
u64 sample_type;
|
|
|
|
u16 size = 0;
|
|
|
|
|
|
|
|
if (!first->attr.sample_id_all)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sample_type = first->attr.sample_type;
|
|
|
|
|
|
|
|
if (sample_type & PERF_SAMPLE_TID)
|
|
|
|
size += sizeof(data->tid) * 2;
|
|
|
|
|
|
|
|
if (sample_type & PERF_SAMPLE_TIME)
|
|
|
|
size += sizeof(data->time);
|
|
|
|
|
|
|
|
if (sample_type & PERF_SAMPLE_ID)
|
|
|
|
size += sizeof(data->id);
|
|
|
|
|
|
|
|
if (sample_type & PERF_SAMPLE_STREAM_ID)
|
|
|
|
size += sizeof(data->stream_id);
|
|
|
|
|
|
|
|
if (sample_type & PERF_SAMPLE_CPU)
|
|
|
|
size += sizeof(data->cpu) * 2;
|
2013-08-27 15:23:09 +07:00
|
|
|
|
|
|
|
if (sample_type & PERF_SAMPLE_IDENTIFIER)
|
|
|
|
size += sizeof(data->id);
|
2011-11-12 07:28:50 +07:00
|
|
|
out:
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2012-08-15 02:42:15 +07:00
|
|
|
bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist)
|
2011-05-21 22:49:00 +07:00
|
|
|
{
|
2012-08-15 02:42:15 +07:00
|
|
|
struct perf_evsel *first = perf_evlist__first(evlist), *pos = first;
|
2011-06-02 21:04:54 +07:00
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each_continue(evlist, pos) {
|
2011-06-02 21:04:54 +07:00
|
|
|
if (first->attr.sample_id_all != pos->attr.sample_id_all)
|
|
|
|
return false;
|
2011-05-21 22:49:00 +07:00
|
|
|
}
|
|
|
|
|
2011-06-02 21:04:54 +07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-15 02:42:15 +07:00
|
|
|
bool perf_evlist__sample_id_all(struct perf_evlist *evlist)
|
2011-06-02 21:04:54 +07:00
|
|
|
{
|
2012-08-15 02:42:15 +07:00
|
|
|
struct perf_evsel *first = perf_evlist__first(evlist);
|
2011-06-02 21:04:54 +07:00
|
|
|
return first->attr.sample_id_all;
|
2011-05-21 22:49:00 +07:00
|
|
|
}
|
2011-10-06 05:11:32 +07:00
|
|
|
|
|
|
|
void perf_evlist__set_selected(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel)
|
|
|
|
{
|
|
|
|
evlist->selected = evsel;
|
|
|
|
}
|
2011-10-25 19:42:19 +07:00
|
|
|
|
2013-03-15 12:48:48 +07:00
|
|
|
void perf_evlist__close(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
int ncpus = cpu_map__nr(evlist->cpus);
|
|
|
|
int nthreads = thread_map__nr(evlist->threads);
|
2014-01-17 22:34:06 +07:00
|
|
|
int n;
|
2013-03-15 12:48:48 +07:00
|
|
|
|
2014-01-17 22:34:06 +07:00
|
|
|
evlist__for_each_reverse(evlist, evsel) {
|
|
|
|
n = evsel->cpus ? evsel->cpus->nr : ncpus;
|
|
|
|
perf_evsel__close(evsel, n, nthreads);
|
|
|
|
}
|
2013-03-15 12:48:48 +07:00
|
|
|
}
|
|
|
|
|
2014-10-11 01:55:15 +07:00
|
|
|
static int perf_evlist__create_syswide_maps(struct perf_evlist *evlist)
|
|
|
|
{
|
2015-09-08 14:59:00 +07:00
|
|
|
struct cpu_map *cpus;
|
|
|
|
struct thread_map *threads;
|
2014-10-11 01:55:15 +07:00
|
|
|
int err = -ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try reading /sys/devices/system/cpu/online to get
|
|
|
|
* an all cpus map.
|
|
|
|
*
|
|
|
|
* FIXME: -ENOMEM is the best we can do here, the cpu_map
|
|
|
|
* code needs an overhaul to properly forward the
|
|
|
|
* error, and we may not want to do that fallback to a
|
|
|
|
* default cpu identity map :-\
|
|
|
|
*/
|
2015-09-08 14:59:00 +07:00
|
|
|
cpus = cpu_map__new(NULL);
|
|
|
|
if (!cpus)
|
2014-10-11 01:55:15 +07:00
|
|
|
goto out;
|
|
|
|
|
2015-09-08 14:59:00 +07:00
|
|
|
threads = thread_map__new_dummy();
|
|
|
|
if (!threads)
|
|
|
|
goto out_put;
|
2014-10-11 01:55:15 +07:00
|
|
|
|
2015-09-08 14:59:00 +07:00
|
|
|
perf_evlist__set_maps(evlist, cpus, threads);
|
2014-10-11 01:55:15 +07:00
|
|
|
out:
|
|
|
|
return err;
|
2015-09-08 14:59:00 +07:00
|
|
|
out_put:
|
|
|
|
cpu_map__put(cpus);
|
2014-10-11 01:55:15 +07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
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 17:22:36 +07:00
|
|
|
int perf_evlist__open(struct perf_evlist *evlist)
|
2011-10-25 19:42:19 +07:00
|
|
|
{
|
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 17:22:36 +07:00
|
|
|
struct perf_evsel *evsel;
|
2013-03-15 12:48:48 +07:00
|
|
|
int err;
|
2011-10-25 19:42:19 +07:00
|
|
|
|
2014-10-11 01:55:15 +07:00
|
|
|
/*
|
|
|
|
* Default: one fd per CPU, all threads, aka systemwide
|
|
|
|
* as sys_perf_event_open(cpu = -1, thread = -1) is EINVAL
|
|
|
|
*/
|
|
|
|
if (evlist->threads == NULL && evlist->cpus == NULL) {
|
|
|
|
err = perf_evlist__create_syswide_maps(evlist);
|
|
|
|
if (err < 0)
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2013-09-07 02:40:11 +07:00
|
|
|
perf_evlist__update_id_pos(evlist);
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, evsel) {
|
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 17:22:36 +07:00
|
|
|
err = perf_evsel__open(evsel, evlist->cpus, evlist->threads);
|
2011-10-25 19:42:19 +07:00
|
|
|
if (err < 0)
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out_err:
|
2013-03-15 12:48:48 +07:00
|
|
|
perf_evlist__close(evlist);
|
2012-02-23 10:13:36 +07:00
|
|
|
errno = -err;
|
2011-10-25 19:42:19 +07:00
|
|
|
return err;
|
|
|
|
}
|
2011-11-09 17:47:15 +07:00
|
|
|
|
2013-11-13 02:46:16 +07:00
|
|
|
int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *target,
|
2013-03-11 14:43:17 +07:00
|
|
|
const char *argv[], bool pipe_output,
|
2014-01-04 00:56:49 +07:00
|
|
|
void (*exec_error)(int signo, siginfo_t *info, void *ucontext))
|
2011-11-09 17:47:15 +07:00
|
|
|
{
|
|
|
|
int child_ready_pipe[2], go_pipe[2];
|
|
|
|
char bf;
|
|
|
|
|
|
|
|
if (pipe(child_ready_pipe) < 0) {
|
|
|
|
perror("failed to create 'ready' pipe");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pipe(go_pipe) < 0) {
|
|
|
|
perror("failed to create 'go' pipe");
|
|
|
|
goto out_close_ready_pipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
evlist->workload.pid = fork();
|
|
|
|
if (evlist->workload.pid < 0) {
|
|
|
|
perror("failed to fork");
|
|
|
|
goto out_close_pipes;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!evlist->workload.pid) {
|
2014-07-28 22:39:50 +07:00
|
|
|
int ret;
|
|
|
|
|
2013-03-11 14:43:16 +07:00
|
|
|
if (pipe_output)
|
2011-11-09 17:47:15 +07:00
|
|
|
dup2(2, 1);
|
|
|
|
|
2013-05-26 06:50:39 +07:00
|
|
|
signal(SIGTERM, SIG_DFL);
|
|
|
|
|
2011-11-09 17:47:15 +07:00
|
|
|
close(child_ready_pipe[0]);
|
|
|
|
close(go_pipe[1]);
|
|
|
|
fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the parent we're ready to go
|
|
|
|
*/
|
|
|
|
close(child_ready_pipe[1]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait until the parent tells us to go.
|
|
|
|
*/
|
2014-07-28 22:39:50 +07:00
|
|
|
ret = read(go_pipe[0], &bf, 1);
|
|
|
|
/*
|
|
|
|
* The parent will ask for the execvp() to be performed by
|
|
|
|
* writing exactly one byte, in workload.cork_fd, usually via
|
|
|
|
* perf_evlist__start_workload().
|
|
|
|
*
|
2015-02-03 23:29:05 +07:00
|
|
|
* For cancelling the workload without actually running it,
|
2014-07-28 22:39:50 +07:00
|
|
|
* the parent will just close workload.cork_fd, without writing
|
|
|
|
* anything, i.e. read will return zero and we just exit()
|
|
|
|
* here.
|
|
|
|
*/
|
|
|
|
if (ret != 1) {
|
|
|
|
if (ret == -1)
|
|
|
|
perror("unable to read pipe");
|
|
|
|
exit(ret);
|
|
|
|
}
|
2011-11-09 17:47:15 +07:00
|
|
|
|
|
|
|
execvp(argv[0], (char **)argv);
|
|
|
|
|
2014-01-04 00:56:49 +07:00
|
|
|
if (exec_error) {
|
2014-01-03 01:11:25 +07:00
|
|
|
union sigval val;
|
|
|
|
|
|
|
|
val.sival_int = errno;
|
|
|
|
if (sigqueue(getppid(), SIGUSR1, val))
|
|
|
|
perror(argv[0]);
|
|
|
|
} else
|
|
|
|
perror(argv[0]);
|
2011-11-09 17:47:15 +07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2014-01-04 00:56:49 +07:00
|
|
|
if (exec_error) {
|
|
|
|
struct sigaction act = {
|
|
|
|
.sa_flags = SA_SIGINFO,
|
|
|
|
.sa_sigaction = exec_error,
|
|
|
|
};
|
|
|
|
sigaction(SIGUSR1, &act, NULL);
|
|
|
|
}
|
|
|
|
|
2014-10-11 00:29:49 +07:00
|
|
|
if (target__none(target)) {
|
|
|
|
if (evlist->threads == NULL) {
|
|
|
|
fprintf(stderr, "FATAL: evlist->threads need to be set at this point (%s:%d).\n",
|
|
|
|
__func__, __LINE__);
|
|
|
|
goto out_close_pipes;
|
|
|
|
}
|
2015-06-23 05:36:02 +07:00
|
|
|
thread_map__set_pid(evlist->threads, 0, evlist->workload.pid);
|
2014-10-11 00:29:49 +07:00
|
|
|
}
|
2011-11-09 17:47:15 +07:00
|
|
|
|
|
|
|
close(child_ready_pipe[1]);
|
|
|
|
close(go_pipe[0]);
|
|
|
|
/*
|
|
|
|
* wait for child to settle
|
|
|
|
*/
|
|
|
|
if (read(child_ready_pipe[0], &bf, 1) == -1) {
|
|
|
|
perror("unable to read pipe");
|
|
|
|
goto out_close_pipes;
|
|
|
|
}
|
|
|
|
|
2013-06-26 14:14:15 +07:00
|
|
|
fcntl(go_pipe[1], F_SETFD, FD_CLOEXEC);
|
2011-11-09 17:47:15 +07:00
|
|
|
evlist->workload.cork_fd = go_pipe[1];
|
|
|
|
close(child_ready_pipe[0]);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_close_pipes:
|
|
|
|
close(go_pipe[0]);
|
|
|
|
close(go_pipe[1]);
|
|
|
|
out_close_ready_pipe:
|
|
|
|
close(child_ready_pipe[0]);
|
|
|
|
close(child_ready_pipe[1]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int perf_evlist__start_workload(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
if (evlist->workload.cork_fd > 0) {
|
2013-07-03 02:27:21 +07:00
|
|
|
char bf = 0;
|
2013-06-26 14:14:15 +07:00
|
|
|
int ret;
|
2011-11-09 17:47:15 +07:00
|
|
|
/*
|
|
|
|
* Remove the cork, let it rip!
|
|
|
|
*/
|
2013-06-26 14:14:15 +07:00
|
|
|
ret = write(evlist->workload.cork_fd, &bf, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
perror("enable to write to pipe");
|
|
|
|
|
|
|
|
close(evlist->workload.cork_fd);
|
|
|
|
return ret;
|
2011-11-09 17:47:15 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-08-02 21:42:57 +07:00
|
|
|
|
2012-08-02 22:23:46 +07:00
|
|
|
int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event,
|
2012-09-26 22:48:18 +07:00
|
|
|
struct perf_sample *sample)
|
2012-08-02 21:42:57 +07:00
|
|
|
{
|
2013-08-27 15:23:09 +07:00
|
|
|
struct perf_evsel *evsel = perf_evlist__event2evsel(evlist, event);
|
|
|
|
|
|
|
|
if (!evsel)
|
|
|
|
return -EFAULT;
|
2012-09-26 22:48:18 +07:00
|
|
|
return perf_evsel__parse_sample(evsel, event, sample);
|
2012-08-02 21:42:57 +07:00
|
|
|
}
|
2012-09-07 00:54:11 +07:00
|
|
|
|
|
|
|
size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
size_t printed = 0;
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each(evlist, evsel) {
|
2012-09-07 00:54:11 +07:00
|
|
|
printed += fprintf(fp, "%s%s", evsel->idx ? ", " : "",
|
|
|
|
perf_evsel__name(evsel));
|
|
|
|
}
|
|
|
|
|
2013-11-13 13:24:24 +07:00
|
|
|
return printed + fprintf(fp, "\n");
|
2012-09-07 00:54:11 +07:00
|
|
|
}
|
2013-10-17 22:07:58 +07: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 03:38:29 +07:00
|
|
|
int perf_evlist__strerror_open(struct perf_evlist *evlist __maybe_unused,
|
|
|
|
int err, char *buf, size_t size)
|
|
|
|
{
|
|
|
|
int printed, value;
|
2014-08-14 09:22:36 +07:00
|
|
|
char sbuf[STRERR_BUFSIZE], *emsg = strerror_r(err, sbuf, sizeof(sbuf));
|
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 03:38:29 +07:00
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
case EACCES:
|
|
|
|
case EPERM:
|
|
|
|
printed = scnprintf(buf, size,
|
|
|
|
"Error:\t%s.\n"
|
|
|
|
"Hint:\tCheck /proc/sys/kernel/perf_event_paranoid setting.", emsg);
|
|
|
|
|
2013-12-11 19:36:23 +07:00
|
|
|
value = perf_event_paranoid();
|
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 03:38:29 +07:00
|
|
|
|
|
|
|
printed += scnprintf(buf + printed, size - printed, "\nHint:\t");
|
|
|
|
|
|
|
|
if (value >= 2) {
|
|
|
|
printed += scnprintf(buf + printed, size - printed,
|
|
|
|
"For your workloads it needs to be <= 1\nHint:\t");
|
|
|
|
}
|
|
|
|
printed += scnprintf(buf + printed, size - printed,
|
2014-06-11 03:18:54 +07:00
|
|
|
"For system wide tracing it needs to be set to -1.\n");
|
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 03:38:29 +07:00
|
|
|
|
|
|
|
printed += scnprintf(buf + printed, size - printed,
|
2014-06-11 03:18:54 +07:00
|
|
|
"Hint:\tTry: 'sudo sh -c \"echo -1 > /proc/sys/kernel/perf_event_paranoid\"'\n"
|
|
|
|
"Hint:\tThe current value is %d.", value);
|
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 03:38:29 +07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
scnprintf(buf, size, "%s", emsg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-11 19:36:35 +07:00
|
|
|
|
2014-12-12 04:03:01 +07:00
|
|
|
int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size)
|
|
|
|
{
|
|
|
|
char sbuf[STRERR_BUFSIZE], *emsg = strerror_r(err, sbuf, sizeof(sbuf));
|
2014-12-13 02:25:33 +07:00
|
|
|
int pages_attempted = evlist->mmap_len / 1024, pages_max_per_user, printed = 0;
|
2014-12-12 04:03:01 +07:00
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
case EPERM:
|
2014-12-13 01:59:51 +07:00
|
|
|
sysctl__read_int("kernel/perf_event_mlock_kb", &pages_max_per_user);
|
2014-12-13 02:25:33 +07:00
|
|
|
printed += scnprintf(buf + printed, size - printed,
|
|
|
|
"Error:\t%s.\n"
|
2014-12-12 04:03:01 +07:00
|
|
|
"Hint:\tCheck /proc/sys/kernel/perf_event_mlock_kb (%d kB) setting.\n"
|
2014-12-13 02:25:33 +07:00
|
|
|
"Hint:\tTried using %zd kB.\n",
|
2014-12-13 01:59:51 +07:00
|
|
|
emsg, pages_max_per_user, pages_attempted);
|
2014-12-13 02:25:33 +07:00
|
|
|
|
|
|
|
if (pages_attempted >= pages_max_per_user) {
|
|
|
|
printed += scnprintf(buf + printed, size - printed,
|
|
|
|
"Hint:\tTry 'sudo sh -c \"echo %d > /proc/sys/kernel/perf_event_mlock_kb\"', or\n",
|
|
|
|
pages_max_per_user + pages_attempted);
|
|
|
|
}
|
|
|
|
|
|
|
|
printed += scnprintf(buf + printed, size - printed,
|
|
|
|
"Hint:\tTry using a smaller -m/--mmap-pages value.");
|
2014-12-12 04:03:01 +07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
scnprintf(buf, size, "%s", emsg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-11 19:36:35 +07:00
|
|
|
void perf_evlist__to_front(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *move_evsel)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel, *n;
|
|
|
|
LIST_HEAD(move);
|
|
|
|
|
|
|
|
if (move_evsel == perf_evlist__first(evlist))
|
|
|
|
return;
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
evlist__for_each_safe(evlist, n, evsel) {
|
2013-12-11 19:36:35 +07:00
|
|
|
if (evsel->leader == move_evsel->leader)
|
|
|
|
list_move_tail(&evsel->node, &move);
|
|
|
|
}
|
|
|
|
|
|
|
|
list_splice(&move, &evlist->entries);
|
|
|
|
}
|
2014-07-31 13:00:52 +07:00
|
|
|
|
|
|
|
void perf_evlist__set_tracking_event(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *tracking_evsel)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
|
|
|
if (tracking_evsel->tracking)
|
|
|
|
return;
|
|
|
|
|
|
|
|
evlist__for_each(evlist, evsel) {
|
|
|
|
if (evsel != tracking_evsel)
|
|
|
|
evsel->tracking = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tracking_evsel->tracking = true;
|
|
|
|
}
|