2011-01-30 20:46:46 +08: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 18:41:51 +08:00
|
|
|
#include "util.h"
|
2014-12-12 05:03:01 +08:00
|
|
|
#include <api/fs/fs.h>
|
2017-04-18 21:46:11 +08:00
|
|
|
#include <errno.h>
|
2017-04-18 02:23:08 +08:00
|
|
|
#include <inttypes.h>
|
2011-01-12 08:30:02 +08:00
|
|
|
#include <poll.h>
|
2011-01-30 20:46:46 +08:00
|
|
|
#include "cpumap.h"
|
|
|
|
#include "thread_map.h"
|
2012-04-26 13:15:22 +08:00
|
|
|
#include "target.h"
|
2011-01-12 06:56:53 +08:00
|
|
|
#include "evlist.h"
|
|
|
|
#include "evsel.h"
|
2013-08-14 20:48:24 +08:00
|
|
|
#include "debug.h"
|
2016-07-14 16:34:42 +08:00
|
|
|
#include "asm/bug.h"
|
2011-11-09 18:47:15 +08:00
|
|
|
#include <unistd.h>
|
2011-01-12 06:56:53 +08:00
|
|
|
|
2011-11-04 19:10:59 +08:00
|
|
|
#include "parse-events.h"
|
2015-12-15 23:39:39 +08:00
|
|
|
#include <subcmd/parse-options.h>
|
2011-11-04 19:10:59 +08:00
|
|
|
|
2011-01-30 20:46:46 +08:00
|
|
|
#include <sys/mman.h>
|
|
|
|
|
2011-01-13 08:39:13 +08:00
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/hash.h>
|
2014-12-16 03:04:11 +08:00
|
|
|
#include <linux/log2.h>
|
2015-09-07 16:38:06 +08:00
|
|
|
#include <linux/err.h>
|
2011-01-13 08:39:13 +08:00
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
static void perf_mmap__munmap(struct perf_mmap *map);
|
2016-07-14 16:34:37 +08:00
|
|
|
static void perf_mmap__put(struct perf_mmap *map);
|
2014-09-08 22:27:49 +08:00
|
|
|
|
2011-01-30 20:46:46 +08:00
|
|
|
#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
|
2011-03-10 22:15:54 +08:00
|
|
|
#define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
|
2011-01-30 20:46:46 +08:00
|
|
|
|
2011-01-30 21:59:43 +08:00
|
|
|
void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
|
|
|
|
struct thread_map *threads)
|
2011-01-19 07:41:45 +08:00
|
|
|
{
|
|
|
|
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 21:59:43 +08:00
|
|
|
perf_evlist__set_maps(evlist, cpus, threads);
|
2014-09-04 05:02:59 +08:00
|
|
|
fdarray__init(&evlist->pollfd, 64);
|
2011-11-09 18:47:15 +08:00
|
|
|
evlist->workload.pid = -1;
|
2016-07-14 16:34:42 +08:00
|
|
|
evlist->bkw_mmap_state = BKW_MMAP_NOTREADY;
|
2011-01-19 07:41:45 +08:00
|
|
|
}
|
|
|
|
|
2013-03-11 15:43:12 +08:00
|
|
|
struct perf_evlist *perf_evlist__new(void)
|
2011-01-12 06:56:53 +08:00
|
|
|
{
|
|
|
|
struct perf_evlist *evlist = zalloc(sizeof(*evlist));
|
|
|
|
|
2011-01-19 07:41:45 +08:00
|
|
|
if (evlist != NULL)
|
2013-03-11 15:43:12 +08:00
|
|
|
perf_evlist__init(evlist, NULL, NULL);
|
2011-01-12 06:56:53 +08:00
|
|
|
|
|
|
|
return evlist;
|
|
|
|
}
|
|
|
|
|
2013-09-01 18:36:14 +08: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;
|
|
|
|
}
|
|
|
|
|
2016-01-08 00:14:56 +08:00
|
|
|
struct perf_evlist *perf_evlist__new_dummy(void)
|
|
|
|
{
|
|
|
|
struct perf_evlist *evlist = perf_evlist__new();
|
|
|
|
|
|
|
|
if (evlist && perf_evlist__add_dummy(evlist)) {
|
|
|
|
perf_evlist__delete(evlist);
|
|
|
|
evlist = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return evlist;
|
|
|
|
}
|
|
|
|
|
2013-08-27 16:23:09 +08: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 03:40:11 +08:00
|
|
|
static void perf_evlist__update_id_pos(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel)
|
2013-09-07 03:40:11 +08:00
|
|
|
perf_evsel__calc_id_pos(evsel);
|
|
|
|
|
|
|
|
perf_evlist__set_id_pos(evlist);
|
|
|
|
}
|
|
|
|
|
2011-01-12 06:56:53 +08:00
|
|
|
static void perf_evlist__purge(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *pos, *n;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry_safe(evlist, n, pos) {
|
2011-01-12 06:56:53 +08:00
|
|
|
list_del_init(&pos->node);
|
2015-08-27 20:07:40 +08:00
|
|
|
pos->evlist = NULL;
|
2011-01-12 06:56:53 +08:00
|
|
|
perf_evsel__delete(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
evlist->nr_entries = 0;
|
|
|
|
}
|
|
|
|
|
2011-01-19 07:41:45 +08:00
|
|
|
void perf_evlist__exit(struct perf_evlist *evlist)
|
2011-01-12 06:56:53 +08:00
|
|
|
{
|
2013-12-27 04:41:15 +08:00
|
|
|
zfree(&evlist->mmap);
|
2016-07-14 16:34:39 +08:00
|
|
|
zfree(&evlist->backward_mmap);
|
2014-09-04 05:02:59 +08:00
|
|
|
fdarray__exit(&evlist->pollfd);
|
2011-01-19 07:41:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void perf_evlist__delete(struct perf_evlist *evlist)
|
|
|
|
{
|
2016-06-22 05:15:45 +08:00
|
|
|
if (evlist == NULL)
|
|
|
|
return;
|
|
|
|
|
2014-01-04 04:25:49 +08:00
|
|
|
perf_evlist__munmap(evlist);
|
2014-01-04 03:54:12 +08:00
|
|
|
perf_evlist__close(evlist);
|
2015-06-23 06:36:04 +08:00
|
|
|
cpu_map__put(evlist->cpus);
|
2015-06-23 06:36:05 +08:00
|
|
|
thread_map__put(evlist->threads);
|
2014-01-04 02:56:06 +08:00
|
|
|
evlist->cpus = NULL;
|
|
|
|
evlist->threads = NULL;
|
2011-01-19 07:41:45 +08:00
|
|
|
perf_evlist__purge(evlist);
|
|
|
|
perf_evlist__exit(evlist);
|
2011-01-12 06:56:53 +08:00
|
|
|
free(evlist);
|
|
|
|
}
|
|
|
|
|
2015-09-08 15:58:58 +08: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;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel)
|
2015-09-08 15:58:58 +08:00
|
|
|
__perf_evlist__propagate_maps(evlist, evsel);
|
|
|
|
}
|
|
|
|
|
2011-01-12 06:56:53 +08:00
|
|
|
void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)
|
|
|
|
{
|
2015-08-27 20:07:40 +08:00
|
|
|
entry->evlist = evlist;
|
2011-01-12 06:56:53 +08:00
|
|
|
list_add_tail(&entry->node, &evlist->entries);
|
2013-11-08 03:41:19 +08:00
|
|
|
entry->idx = evlist->nr_entries;
|
2014-07-31 14:00:52 +08:00
|
|
|
entry->tracking = !entry->idx;
|
2013-11-08 03:41:19 +08:00
|
|
|
|
2013-08-27 16:23:09 +08:00
|
|
|
if (!evlist->nr_entries++)
|
|
|
|
perf_evlist__set_id_pos(evlist);
|
2015-09-08 15:58:59 +08:00
|
|
|
|
|
|
|
__perf_evlist__propagate_maps(evlist, entry);
|
2011-01-12 06:56:53 +08:00
|
|
|
}
|
|
|
|
|
2015-09-25 21:15:53 +08: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 22:34:20 +08:00
|
|
|
void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
|
2015-09-08 15:58:53 +08:00
|
|
|
struct list_head *list)
|
2011-11-04 19:10:59 +08:00
|
|
|
{
|
2015-09-08 15:58:53 +08:00
|
|
|
struct perf_evsel *evsel, *temp;
|
2013-08-27 16:23:09 +08:00
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
__evlist__for_each_entry_safe(list, temp, evsel) {
|
2015-09-08 15:58:53 +08:00
|
|
|
list_del_init(&evsel->node);
|
|
|
|
perf_evlist__add(evlist, evsel);
|
|
|
|
}
|
2011-11-04 19:10:59 +08:00
|
|
|
}
|
|
|
|
|
2012-08-15 03:35:48 +08: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 17:09:29 +08:00
|
|
|
evsel = list_entry(list->prev, struct perf_evsel, node);
|
|
|
|
|
|
|
|
leader->nr_members = evsel->idx - leader->idx + 1;
|
2012-08-15 03:35:48 +08:00
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
__evlist__for_each_entry(list, evsel) {
|
2013-01-31 20:54:37 +08:00
|
|
|
evsel->leader = leader;
|
2012-08-15 03:35:48 +08: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 18:22:36 +08:00
|
|
|
{
|
2013-01-22 17:09:29 +08:00
|
|
|
if (evlist->nr_entries) {
|
|
|
|
evlist->nr_groups = evlist->nr_entries > 1 ? 1 : 0;
|
2012-08-15 03:35:48 +08:00
|
|
|
__perf_evlist__set_leader(&evlist->entries);
|
2013-01-22 17:09:29 +08: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 18:22:36 +08:00
|
|
|
}
|
|
|
|
|
2015-10-06 02:06:04 +08:00
|
|
|
void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr)
|
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 04:49:49 +08:00
|
|
|
{
|
|
|
|
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 06:56:53 +08:00
|
|
|
int perf_evlist__add_default(struct perf_evlist *evlist)
|
|
|
|
{
|
2016-07-29 05:33:20 +08:00
|
|
|
struct perf_evsel *evsel = perf_evsel__new_cycles();
|
2012-01-05 00:54:20 +08:00
|
|
|
|
2011-01-12 06:56:53 +08:00
|
|
|
if (evsel == NULL)
|
2016-07-29 05:33:20 +08:00
|
|
|
return -ENOMEM;
|
2011-01-12 06:56:53 +08:00
|
|
|
|
|
|
|
perf_evlist__add(evlist, evsel);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-01-12 08:30:02 +08:00
|
|
|
|
2016-01-08 00:14:56 +08:00
|
|
|
int perf_evlist__add_dummy(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_event_attr attr = {
|
|
|
|
.type = PERF_TYPE_SOFTWARE,
|
|
|
|
.config = PERF_COUNT_SW_DUMMY,
|
|
|
|
.size = sizeof(attr), /* to capture ABI version */
|
|
|
|
};
|
|
|
|
struct perf_evsel *evsel = perf_evsel__new(&attr);
|
|
|
|
|
|
|
|
if (evsel == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
perf_evlist__add(evlist, evsel);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-03 22:50:55 +08:00
|
|
|
static int perf_evlist__add_attrs(struct perf_evlist *evlist,
|
|
|
|
struct perf_event_attr *attrs, size_t nr_attrs)
|
2011-11-04 19:10:59 +08:00
|
|
|
{
|
|
|
|
struct perf_evsel *evsel, *n;
|
|
|
|
LIST_HEAD(head);
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_attrs; i++) {
|
2013-11-08 03:41:19 +08:00
|
|
|
evsel = perf_evsel__new_idx(attrs + i, evlist->nr_entries + i);
|
2011-11-04 19:10:59 +08:00
|
|
|
if (evsel == NULL)
|
|
|
|
goto out_delete_partial_list;
|
|
|
|
list_add_tail(&evsel->node, &head);
|
|
|
|
}
|
|
|
|
|
2015-09-08 15:58:53 +08:00
|
|
|
perf_evlist__splice_list_tail(evlist, &head);
|
2011-11-04 19:10:59 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_delete_partial_list:
|
2016-06-23 22:26:15 +08:00
|
|
|
__evlist__for_each_entry_safe(&head, n, evsel)
|
2011-11-04 19:10:59 +08: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-31 00:53:54 +08:00
|
|
|
int __perf_evlist__add_default_attrs(struct perf_evlist *evlist,
|
|
|
|
struct perf_event_attr *attrs, size_t nr_attrs)
|
|
|
|
{
|
|
|
|
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-28 00:08:42 +08: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 03:57:40 +08:00
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(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 03:57:40 +08:00
|
|
|
if (evsel->attr.type == PERF_TYPE_TRACEPOINT &&
|
|
|
|
(int)evsel->attr.config == id)
|
|
|
|
return evsel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-29 12:29:51 +08:00
|
|
|
struct perf_evsel *
|
|
|
|
perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
2013-08-29 12:29:51 +08:00
|
|
|
if ((evsel->attr.type == PERF_TYPE_TRACEPOINT) &&
|
|
|
|
(strcmp(evsel->name, name) == 0))
|
|
|
|
return evsel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-03 22:40:22 +08:00
|
|
|
int perf_evlist__add_newtp(struct perf_evlist *evlist,
|
|
|
|
const char *sys, const char *name, void *handler)
|
|
|
|
{
|
2013-11-08 03:41:19 +08:00
|
|
|
struct perf_evsel *evsel = perf_evsel__newtp(sys, name);
|
2012-10-03 22:40:22 +08:00
|
|
|
|
2015-09-07 16:38:06 +08:00
|
|
|
if (IS_ERR(evsel))
|
2012-10-03 22:40:22 +08:00
|
|
|
return -1;
|
|
|
|
|
2013-11-06 21:17:38 +08:00
|
|
|
evsel->handler = handler;
|
2012-10-03 22:40:22 +08:00
|
|
|
perf_evlist__add(evlist, evsel);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-31 14:00:51 +08: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 22:06:19 +08:00
|
|
|
void perf_evlist__disable(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *pos;
|
2015-12-03 17:06:42 +08:00
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, pos) {
|
2015-12-03 17:06:42 +08:00
|
|
|
if (!perf_evsel__is_group_leader(pos) || !pos->fd)
|
|
|
|
continue;
|
|
|
|
perf_evsel__disable(pos);
|
2011-07-25 22:06:19 +08:00
|
|
|
}
|
2015-06-18 03:40:26 +08:00
|
|
|
|
|
|
|
evlist->enabled = false;
|
2011-07-25 22:06:19 +08:00
|
|
|
}
|
|
|
|
|
2011-08-26 00:17:55 +08:00
|
|
|
void perf_evlist__enable(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *pos;
|
2015-12-03 17:06:42 +08:00
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, pos) {
|
2015-12-03 17:06:42 +08:00
|
|
|
if (!perf_evsel__is_group_leader(pos) || !pos->fd)
|
|
|
|
continue;
|
|
|
|
perf_evsel__enable(pos);
|
2011-08-26 00:17:55 +08:00
|
|
|
}
|
2015-06-18 03:40:26 +08:00
|
|
|
|
|
|
|
evlist->enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void perf_evlist__toggle_enable(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
(evlist->enabled ? perf_evlist__disable : perf_evlist__enable)(evlist);
|
2011-08-26 00:17:55 +08:00
|
|
|
}
|
|
|
|
|
2014-07-31 14:00:56 +08:00
|
|
|
static int perf_evlist__enable_event_cpu(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel, int cpu)
|
|
|
|
{
|
2016-10-03 22:07:24 +08:00
|
|
|
int thread;
|
2014-07-31 14:00:56 +08:00
|
|
|
int nr_threads = perf_evlist__nr_threads(evlist, evsel);
|
|
|
|
|
|
|
|
if (!evsel->fd)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (thread = 0; thread < nr_threads; thread++) {
|
2016-10-03 22:07:24 +08:00
|
|
|
int err = ioctl(FD(evsel, cpu, thread), PERF_EVENT_IOC_ENABLE, 0);
|
2014-07-31 14:00:56 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int perf_evlist__enable_event_thread(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel,
|
|
|
|
int thread)
|
|
|
|
{
|
2016-10-03 22:07:24 +08:00
|
|
|
int cpu;
|
2014-07-31 14:00:56 +08:00
|
|
|
int nr_cpus = cpu_map__nr(evlist->cpus);
|
|
|
|
|
|
|
|
if (!evsel->fd)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (cpu = 0; cpu < nr_cpus; cpu++) {
|
2016-10-03 22:07:24 +08:00
|
|
|
int err = ioctl(FD(evsel, cpu, thread), PERF_EVENT_IOC_ENABLE, 0);
|
2014-07-31 14:00:56 +08:00
|
|
|
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 03:44:06 +08:00
|
|
|
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
|
2011-01-12 08:30:02 +08:00
|
|
|
{
|
2013-03-11 15:43:14 +08:00
|
|
|
int nr_cpus = cpu_map__nr(evlist->cpus);
|
|
|
|
int nr_threads = thread_map__nr(evlist->threads);
|
2014-07-31 14:00:51 +08:00
|
|
|
int nfds = 0;
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
2014-07-31 14:00:51 +08:00
|
|
|
if (evsel->system_wide)
|
|
|
|
nfds += nr_cpus;
|
|
|
|
else
|
|
|
|
nfds += nr_cpus * nr_threads;
|
|
|
|
}
|
|
|
|
|
2014-09-04 05:02:59 +08:00
|
|
|
if (fdarray__available_entries(&evlist->pollfd) < nfds &&
|
|
|
|
fdarray__grow(&evlist->pollfd, nfds) < 0)
|
2014-08-19 03:44:06 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
2011-01-12 08:30:02 +08:00
|
|
|
}
|
2011-01-13 03:03:24 +08:00
|
|
|
|
2016-07-14 16:34:37 +08:00
|
|
|
static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
|
|
|
|
struct perf_mmap *map, short revent)
|
2014-09-08 22:27:49 +08:00
|
|
|
{
|
2016-05-24 10:28:59 +08:00
|
|
|
int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
|
2014-09-08 22:27:49 +08:00
|
|
|
/*
|
|
|
|
* Save the idx so that when we filter out fds POLLHUP'ed we can
|
|
|
|
* close the associated evlist->mmap[] entry.
|
|
|
|
*/
|
|
|
|
if (pos >= 0) {
|
2016-07-14 16:34:37 +08:00
|
|
|
evlist->pollfd.priv[pos].ptr = map;
|
2014-09-08 22:27:49 +08:00
|
|
|
|
|
|
|
fcntl(fd, F_SETFL, O_NONBLOCK);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2014-08-19 03:44:06 +08:00
|
|
|
int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
|
2011-01-13 03:03:24 +08:00
|
|
|
{
|
2016-07-14 16:34:37 +08:00
|
|
|
return __perf_evlist__add_pollfd(evlist, fd, NULL, POLLIN);
|
2014-09-08 22:27:49 +08:00
|
|
|
}
|
|
|
|
|
2016-05-25 21:44:57 +08:00
|
|
|
static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
|
|
|
|
void *arg __maybe_unused)
|
2014-09-08 22:27:49 +08:00
|
|
|
{
|
2016-07-14 16:34:37 +08:00
|
|
|
struct perf_mmap *map = fda->priv[fd].ptr;
|
2014-09-04 05:02:59 +08:00
|
|
|
|
2016-07-14 16:34:37 +08:00
|
|
|
if (map)
|
|
|
|
perf_mmap__put(map);
|
2011-01-13 03:03:24 +08:00
|
|
|
}
|
2011-01-13 08:39:13 +08:00
|
|
|
|
2014-08-13 10:04:11 +08:00
|
|
|
int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask)
|
|
|
|
{
|
2014-09-08 22:27:49 +08:00
|
|
|
return fdarray__filter(&evlist->pollfd, revents_and_mask,
|
2016-05-25 21:44:57 +08:00
|
|
|
perf_evlist__munmap_filtered, NULL);
|
2014-08-13 10:04:11 +08:00
|
|
|
}
|
|
|
|
|
2014-08-19 04:25:59 +08:00
|
|
|
int perf_evlist__poll(struct perf_evlist *evlist, int timeout)
|
|
|
|
{
|
2014-09-04 05:02:59 +08:00
|
|
|
return fdarray__poll(&evlist->pollfd, timeout);
|
2014-08-19 04:25:59 +08:00
|
|
|
}
|
|
|
|
|
2011-03-10 22:15:54 +08:00
|
|
|
static void perf_evlist__id_hash(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel,
|
|
|
|
int cpu, int thread, u64 id)
|
2011-03-05 09:29:39 +08: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 22:15:54 +08: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;
|
|
|
|
}
|
|
|
|
|
2015-11-05 22:40:49 +08:00
|
|
|
int perf_evlist__id_add_fd(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel,
|
|
|
|
int cpu, int thread, int fd)
|
2011-01-30 20:46:46 +08:00
|
|
|
{
|
|
|
|
u64 read_data[4] = { 0, };
|
2011-03-05 09:29:39 +08:00
|
|
|
int id_idx = 1; /* The first entry is the counter value */
|
2012-04-05 01:32:27 +08: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 20:46:46 +08:00
|
|
|
|
2012-10-12 19:02:21 +08: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 20:46:46 +08: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 01:32:27 +08:00
|
|
|
id = read_data[id_idx];
|
|
|
|
|
|
|
|
add:
|
|
|
|
perf_evlist__id_add(evlist, evsel, cpu, thread, id);
|
2011-01-30 20:46:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-27 21:49:22 +08: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 06:36:02 +08:00
|
|
|
sid->tid = thread_map__pid(evlist->threads, thread);
|
2014-10-27 21:49:22 +08:00
|
|
|
else
|
|
|
|
sid->tid = -1;
|
|
|
|
}
|
|
|
|
|
2012-10-11 20:10:35 +08:00
|
|
|
struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id)
|
2011-01-13 08:39:13 +08: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 09:06:00 +08:00
|
|
|
hlist_for_each_entry(sid, head, node)
|
2011-01-13 08:39:13 +08:00
|
|
|
if (sid->id == id)
|
2012-10-11 20:10:35 +08: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 16:26:45 +08:00
|
|
|
if (evlist->nr_entries == 1 || !id)
|
2012-10-11 20:10:35 +08:00
|
|
|
return perf_evlist__first(evlist);
|
|
|
|
|
|
|
|
sid = perf_evlist__id2sid(evlist, id);
|
|
|
|
if (sid)
|
|
|
|
return sid->evsel;
|
2012-02-20 09:47:26 +08:00
|
|
|
|
|
|
|
if (!perf_evlist__sample_id_all(evlist))
|
2012-08-15 03:42:15 +08:00
|
|
|
return perf_evlist__first(evlist);
|
2012-02-20 09:47:26 +08:00
|
|
|
|
2011-01-13 08:39:13 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-15 20:40:59 +08:00
|
|
|
|
2015-09-25 21:15:52 +08: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 16:23:09 +08: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;
|
|
|
|
}
|
|
|
|
|
2016-07-10 19:07:53 +08:00
|
|
|
struct perf_evsel *perf_evlist__event2evsel(struct perf_evlist *evlist,
|
|
|
|
union perf_event *event)
|
2013-08-27 16:23:09 +08:00
|
|
|
{
|
2013-09-05 04:18:17 +08:00
|
|
|
struct perf_evsel *first = perf_evlist__first(evlist);
|
2013-08-27 16:23:09 +08:00
|
|
|
struct hlist_head *head;
|
|
|
|
struct perf_sample_id *sid;
|
|
|
|
int hash;
|
|
|
|
u64 id;
|
|
|
|
|
|
|
|
if (evlist->nr_entries == 1)
|
2013-09-05 04:18:17 +08:00
|
|
|
return first;
|
|
|
|
|
|
|
|
if (!first->attr.sample_id_all &&
|
|
|
|
event->header.type != PERF_RECORD_SAMPLE)
|
|
|
|
return first;
|
2013-08-27 16:23:09 +08:00
|
|
|
|
|
|
|
if (perf_evlist__event2id(evlist, event, &id))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Synthesized events have an id of zero */
|
|
|
|
if (!id)
|
2013-09-05 04:18:17 +08:00
|
|
|
return first;
|
2013-08-27 16:23:09 +08: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;
|
|
|
|
}
|
|
|
|
|
2016-05-23 15:13:38 +08:00
|
|
|
static int perf_evlist__set_paused(struct perf_evlist *evlist, bool value)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2016-07-14 16:34:40 +08:00
|
|
|
if (!evlist->backward_mmap)
|
|
|
|
return 0;
|
|
|
|
|
2016-05-23 15:13:38 +08:00
|
|
|
for (i = 0; i < evlist->nr_mmaps; i++) {
|
2016-07-14 16:34:40 +08:00
|
|
|
int fd = evlist->backward_mmap[i].fd;
|
2016-05-23 15:13:38 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
continue;
|
|
|
|
err = ioctl(fd, PERF_EVENT_IOC_PAUSE_OUTPUT, value ? 1 : 0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-14 16:34:44 +08:00
|
|
|
static int perf_evlist__pause(struct perf_evlist *evlist)
|
2016-05-23 15:13:38 +08:00
|
|
|
{
|
|
|
|
return perf_evlist__set_paused(evlist, true);
|
|
|
|
}
|
|
|
|
|
2016-07-14 16:34:44 +08:00
|
|
|
static int perf_evlist__resume(struct perf_evlist *evlist)
|
2016-05-23 15:13:38 +08:00
|
|
|
{
|
|
|
|
return perf_evlist__set_paused(evlist, false);
|
|
|
|
}
|
|
|
|
|
2016-04-27 10:19:21 +08:00
|
|
|
/* When check_messup is true, 'end' must points to a good entry */
|
2016-04-27 10:19:20 +08:00
|
|
|
static union perf_event *
|
2016-04-27 10:19:21 +08:00
|
|
|
perf_mmap__read(struct perf_mmap *md, bool check_messup, u64 start,
|
|
|
|
u64 end, u64 *prev)
|
2011-01-15 20:40:59 +08:00
|
|
|
{
|
|
|
|
unsigned char *data = md->base + page_size;
|
2011-01-30 00:01:45 +08:00
|
|
|
union perf_event *event = NULL;
|
2016-04-27 10:19:21 +08:00
|
|
|
int diff = end - start;
|
2011-01-15 20:40:59 +08:00
|
|
|
|
2016-04-27 10:19:21 +08:00
|
|
|
if (check_messup) {
|
2011-01-15 20:40:59 +08:00
|
|
|
/*
|
2011-01-29 19:08:13 +08: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.
|
|
|
|
*
|
2016-04-27 10:19:21 +08:00
|
|
|
* If we somehow ended up ahead of the 'end', we got messed up.
|
2011-01-29 19:08:13 +08:00
|
|
|
*
|
2016-04-27 10:19:21 +08:00
|
|
|
* In either case, truncate and restart at 'end'.
|
2011-01-15 20:40:59 +08:00
|
|
|
*/
|
2011-01-29 19:08:13 +08:00
|
|
|
if (diff > md->mask / 2 || diff < 0) {
|
|
|
|
fprintf(stderr, "WARNING: failed to keep up with mmap data.\n");
|
|
|
|
|
|
|
|
/*
|
2016-04-27 10:19:21 +08:00
|
|
|
* 'end' points to a known good entry, start there.
|
2011-01-29 19:08:13 +08:00
|
|
|
*/
|
2016-04-27 10:19:21 +08:00
|
|
|
start = end;
|
2016-04-26 10:28:54 +08:00
|
|
|
diff = 0;
|
2011-01-29 19:08:13 +08:00
|
|
|
}
|
2011-01-15 20:40:59 +08:00
|
|
|
}
|
|
|
|
|
2016-04-26 10:28:54 +08:00
|
|
|
if (diff >= (int)sizeof(event->header)) {
|
2011-01-15 20:40:59 +08:00
|
|
|
size_t size;
|
|
|
|
|
2016-04-27 10:19:21 +08:00
|
|
|
event = (union perf_event *)&data[start & md->mask];
|
2011-01-15 20:40:59 +08:00
|
|
|
size = event->header.size;
|
|
|
|
|
2016-04-26 10:28:54 +08:00
|
|
|
if (size < sizeof(event->header) || diff < (int)size) {
|
|
|
|
event = NULL;
|
|
|
|
goto broken_event;
|
|
|
|
}
|
|
|
|
|
2011-01-15 20:40:59 +08:00
|
|
|
/*
|
|
|
|
* Event straddles the mmap boundary -- header should always
|
|
|
|
* be inside due to u64 alignment of output.
|
|
|
|
*/
|
2016-04-27 10:19:21 +08:00
|
|
|
if ((start & md->mask) + size != ((start + size) & md->mask)) {
|
|
|
|
unsigned int offset = start;
|
2011-01-15 20:40:59 +08:00
|
|
|
unsigned int len = min(sizeof(*event), size), cpy;
|
2013-10-02 21:46:39 +08:00
|
|
|
void *dst = md->event_copy;
|
2011-01-15 20:40:59 +08: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 21:46:39 +08:00
|
|
|
event = (union perf_event *) md->event_copy;
|
2011-01-15 20:40:59 +08:00
|
|
|
}
|
|
|
|
|
2016-04-27 10:19:21 +08:00
|
|
|
start += size;
|
2011-01-15 20:40:59 +08:00
|
|
|
}
|
|
|
|
|
2016-04-26 10:28:54 +08:00
|
|
|
broken_event:
|
2016-04-27 10:19:20 +08:00
|
|
|
if (prev)
|
2016-04-27 10:19:21 +08:00
|
|
|
*prev = start;
|
2011-01-29 19:08:13 +08:00
|
|
|
|
2011-01-15 20:40:59 +08:00
|
|
|
return event;
|
|
|
|
}
|
2011-01-30 20:46:46 +08:00
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
union perf_event *perf_mmap__read_forward(struct perf_mmap *md, bool check_messup)
|
2016-04-27 10:19:20 +08:00
|
|
|
{
|
|
|
|
u64 head;
|
|
|
|
u64 old = md->prev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if event was unmapped due to a POLLHUP/POLLERR.
|
|
|
|
*/
|
2017-02-21 23:35:01 +08:00
|
|
|
if (!refcount_read(&md->refcnt))
|
2016-04-27 10:19:20 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
head = perf_mmap__read_head(md);
|
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
return perf_mmap__read(md, check_messup, old, head, &md->prev);
|
2016-04-27 10:19:20 +08:00
|
|
|
}
|
|
|
|
|
2016-05-09 09:47:50 +08:00
|
|
|
union perf_event *
|
2016-07-14 16:34:35 +08:00
|
|
|
perf_mmap__read_backward(struct perf_mmap *md)
|
2016-05-09 09:47:50 +08:00
|
|
|
{
|
|
|
|
u64 head, end;
|
|
|
|
u64 start = md->prev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if event was unmapped due to a POLLHUP/POLLERR.
|
|
|
|
*/
|
2017-02-21 23:35:01 +08:00
|
|
|
if (!refcount_read(&md->refcnt))
|
2016-05-09 09:47:50 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
head = perf_mmap__read_head(md);
|
|
|
|
if (!head)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'head' pointer starts from 0. Kernel minus sizeof(record) form
|
|
|
|
* it each time when kernel writes to it, so in fact 'head' is
|
|
|
|
* negative. 'end' pointer is made manually by adding the size of
|
|
|
|
* the ring buffer to 'head' pointer, means the validate data can
|
|
|
|
* read is the whole ring buffer. If 'end' is positive, the ring
|
|
|
|
* buffer has not fully filled, so we must adjust 'end' to 0.
|
|
|
|
*
|
|
|
|
* However, since both 'head' and 'end' is unsigned, we can't
|
|
|
|
* simply compare 'end' against 0. Here we compare '-head' and
|
|
|
|
* the size of the ring buffer, where -head is the number of bytes
|
|
|
|
* kernel write to the ring buffer.
|
|
|
|
*/
|
|
|
|
if (-head < (u64)(md->mask + 1))
|
|
|
|
end = 0;
|
|
|
|
else
|
|
|
|
end = head + md->mask + 1;
|
|
|
|
|
|
|
|
return perf_mmap__read(md, false, start, end, &md->prev);
|
|
|
|
}
|
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
union perf_event *perf_evlist__mmap_read_forward(struct perf_evlist *evlist, int idx)
|
|
|
|
{
|
|
|
|
struct perf_mmap *md = &evlist->mmap[idx];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check messup is required for forward overwritable ring buffer:
|
|
|
|
* memory pointed by md->prev can be overwritten in this case.
|
|
|
|
* No need for read-write ring buffer: kernel stop outputting when
|
|
|
|
* it hit md->prev (perf_mmap__consume()).
|
|
|
|
*/
|
|
|
|
return perf_mmap__read_forward(md, evlist->overwrite);
|
|
|
|
}
|
|
|
|
|
|
|
|
union perf_event *perf_evlist__mmap_read_backward(struct perf_evlist *evlist, int idx)
|
|
|
|
{
|
|
|
|
struct perf_mmap *md = &evlist->mmap[idx];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No need to check messup for backward ring buffer:
|
|
|
|
* We can always read arbitrary long data from a backward
|
|
|
|
* ring buffer unless we forget to pause it before reading.
|
|
|
|
*/
|
|
|
|
return perf_mmap__read_backward(md);
|
|
|
|
}
|
|
|
|
|
2016-05-25 21:44:50 +08:00
|
|
|
union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
|
|
|
|
{
|
2016-07-14 16:34:41 +08:00
|
|
|
return perf_evlist__mmap_read_forward(evlist, idx);
|
2016-05-25 21:44:50 +08:00
|
|
|
}
|
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
void perf_mmap__read_catchup(struct perf_mmap *md)
|
2016-05-09 09:47:50 +08:00
|
|
|
{
|
|
|
|
u64 head;
|
|
|
|
|
2017-02-21 23:35:01 +08:00
|
|
|
if (!refcount_read(&md->refcnt))
|
2016-05-09 09:47:50 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
head = perf_mmap__read_head(md);
|
|
|
|
md->prev = head;
|
|
|
|
}
|
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
void perf_evlist__mmap_read_catchup(struct perf_evlist *evlist, int idx)
|
|
|
|
{
|
|
|
|
perf_mmap__read_catchup(&evlist->mmap[idx]);
|
|
|
|
}
|
|
|
|
|
2014-09-09 00:26:35 +08:00
|
|
|
static bool perf_mmap__empty(struct perf_mmap *md)
|
|
|
|
{
|
2015-04-25 03:29:43 +08:00
|
|
|
return perf_mmap__read_head(md) == md->prev && !md->auxtrace_mmap.base;
|
2014-09-09 00:26:35 +08:00
|
|
|
}
|
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
static void perf_mmap__get(struct perf_mmap *map)
|
2014-09-09 00:26:35 +08:00
|
|
|
{
|
2017-02-21 23:35:01 +08:00
|
|
|
refcount_inc(&map->refcnt);
|
2014-09-09 00:26:35 +08:00
|
|
|
}
|
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
static void perf_mmap__put(struct perf_mmap *md)
|
2014-09-09 00:26:35 +08:00
|
|
|
{
|
2017-02-21 23:35:01 +08:00
|
|
|
BUG_ON(md->base && refcount_read(&md->refcnt) == 0);
|
2014-09-09 00:26:35 +08:00
|
|
|
|
2017-02-21 23:35:01 +08:00
|
|
|
if (refcount_dec_and_test(&md->refcnt))
|
2016-07-14 16:34:35 +08:00
|
|
|
perf_mmap__munmap(md);
|
2014-09-09 00:26:35 +08:00
|
|
|
}
|
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
void perf_mmap__consume(struct perf_mmap *md, bool overwrite)
|
|
|
|
{
|
|
|
|
if (!overwrite) {
|
2015-04-07 23:20:37 +08:00
|
|
|
u64 old = md->prev;
|
2013-10-24 15:43:33 +08:00
|
|
|
|
|
|
|
perf_mmap__write_tail(md, old);
|
|
|
|
}
|
2014-09-09 00:26:35 +08:00
|
|
|
|
2017-02-21 23:35:01 +08:00
|
|
|
if (refcount_read(&md->refcnt) == 1 && perf_mmap__empty(md))
|
2016-07-14 16:34:35 +08:00
|
|
|
perf_mmap__put(md);
|
|
|
|
}
|
|
|
|
|
|
|
|
void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx)
|
|
|
|
{
|
|
|
|
perf_mmap__consume(&evlist->mmap[idx], evlist->overwrite);
|
2013-10-24 15:43:33 +08:00
|
|
|
}
|
|
|
|
|
2015-04-09 23:53:42 +08: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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
static void perf_mmap__munmap(struct perf_mmap *map)
|
2013-07-04 21:20:26 +08:00
|
|
|
{
|
2016-07-14 16:34:35 +08:00
|
|
|
if (map->base != NULL) {
|
|
|
|
munmap(map->base, perf_mmap__mmap_len(map));
|
|
|
|
map->base = NULL;
|
|
|
|
map->fd = -1;
|
2017-02-21 23:35:01 +08:00
|
|
|
refcount_set(&map->refcnt, 0);
|
2013-07-04 21:20:26 +08:00
|
|
|
}
|
2016-07-14 16:34:35 +08:00
|
|
|
auxtrace_mmap__munmap(&map->auxtrace_mmap);
|
|
|
|
}
|
|
|
|
|
2016-07-14 16:34:38 +08:00
|
|
|
static void perf_evlist__munmap_nofree(struct perf_evlist *evlist)
|
2011-01-30 20:46:46 +08: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 20:39:00 +08:00
|
|
|
int i;
|
2011-01-30 20:46:46 +08:00
|
|
|
|
2016-07-14 16:34:39 +08:00
|
|
|
if (evlist->mmap)
|
|
|
|
for (i = 0; i < evlist->nr_mmaps; i++)
|
|
|
|
perf_mmap__munmap(&evlist->mmap[i]);
|
2014-01-04 04:25:49 +08:00
|
|
|
|
2016-07-14 16:34:39 +08:00
|
|
|
if (evlist->backward_mmap)
|
|
|
|
for (i = 0; i < evlist->nr_mmaps; i++)
|
|
|
|
perf_mmap__munmap(&evlist->backward_mmap[i]);
|
2016-07-14 16:34:38 +08: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 20:39:00 +08:00
|
|
|
|
2016-07-14 16:34:38 +08:00
|
|
|
void perf_evlist__munmap(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
perf_evlist__munmap_nofree(evlist);
|
2013-12-27 04:41:15 +08:00
|
|
|
zfree(&evlist->mmap);
|
2016-07-14 16:34:39 +08:00
|
|
|
zfree(&evlist->backward_mmap);
|
2011-01-30 20:46:46 +08:00
|
|
|
}
|
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
static struct perf_mmap *perf_evlist__alloc_mmap(struct perf_evlist *evlist)
|
2011-01-30 20:46:46 +08:00
|
|
|
{
|
2016-05-21 00:38:24 +08:00
|
|
|
int i;
|
2016-07-14 16:34:35 +08:00
|
|
|
struct perf_mmap *map;
|
2016-05-21 00:38:24 +08:00
|
|
|
|
2012-09-26 23:41:14 +08:00
|
|
|
evlist->nr_mmaps = cpu_map__nr(evlist->cpus);
|
2013-05-23 08:42:38 +08:00
|
|
|
if (cpu_map__empty(evlist->cpus))
|
2013-03-11 15:43:14 +08:00
|
|
|
evlist->nr_mmaps = thread_map__nr(evlist->threads);
|
2016-07-14 16:34:35 +08:00
|
|
|
map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
|
|
|
|
if (!map)
|
|
|
|
return NULL;
|
2016-05-31 21:06:15 +08:00
|
|
|
|
2017-02-24 00:24:34 +08:00
|
|
|
for (i = 0; i < evlist->nr_mmaps; i++) {
|
2016-07-14 16:34:35 +08:00
|
|
|
map[i].fd = -1;
|
2017-02-24 00:24:34 +08:00
|
|
|
/*
|
|
|
|
* When the perf_mmap() call is made we grab one refcount, plus
|
|
|
|
* one extra to let perf_evlist__mmap_consume() get the last
|
|
|
|
* events after all real references (perf_mmap__get()) are
|
|
|
|
* dropped.
|
|
|
|
*
|
|
|
|
* Each PERF_EVENT_IOC_SET_OUTPUT points to this mmap and
|
|
|
|
* thus does perf_mmap__get() on it.
|
|
|
|
*/
|
|
|
|
refcount_set(&map[i].refcnt, 0);
|
|
|
|
}
|
2016-07-14 16:34:35 +08:00
|
|
|
return map;
|
2011-01-30 20:46:46 +08:00
|
|
|
}
|
|
|
|
|
2014-07-14 18:02:52 +08:00
|
|
|
struct mmap_params {
|
|
|
|
int prot;
|
|
|
|
int mask;
|
2015-04-09 23:53:42 +08:00
|
|
|
struct auxtrace_mmap_params auxtrace_mp;
|
2014-07-14 18:02:52 +08:00
|
|
|
};
|
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
static int perf_mmap__mmap(struct perf_mmap *map,
|
|
|
|
struct mmap_params *mp, int fd)
|
2011-01-30 20:46:46 +08:00
|
|
|
{
|
2014-09-09 00:26:35 +08: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().
|
|
|
|
*/
|
2017-02-21 23:35:01 +08:00
|
|
|
refcount_set(&map->refcnt, 2);
|
2016-07-14 16:34:35 +08:00
|
|
|
map->prev = 0;
|
|
|
|
map->mask = mp->mask;
|
|
|
|
map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
|
|
|
|
MAP_SHARED, fd, 0);
|
|
|
|
if (map->base == MAP_FAILED) {
|
2013-11-01 21:51:33 +08:00
|
|
|
pr_debug2("failed to mmap perf event ring buffer, error %d\n",
|
|
|
|
errno);
|
2016-07-14 16:34:35 +08:00
|
|
|
map->base = NULL;
|
2011-01-30 20:46:46 +08:00
|
|
|
return -1;
|
2011-12-19 21:39:30 +08:00
|
|
|
}
|
2016-07-14 16:34:35 +08:00
|
|
|
map->fd = fd;
|
2014-08-19 03:44:06 +08:00
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
if (auxtrace_mmap__mmap(&map->auxtrace_mmap,
|
|
|
|
&mp->auxtrace_mp, map->base, fd))
|
2015-04-09 23:53:42 +08:00
|
|
|
return -1;
|
|
|
|
|
2011-01-30 20:46:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-24 10:28:59 +08:00
|
|
|
static bool
|
|
|
|
perf_evlist__should_poll(struct perf_evlist *evlist __maybe_unused,
|
|
|
|
struct perf_evsel *evsel)
|
|
|
|
{
|
2016-07-14 16:34:33 +08:00
|
|
|
if (evsel->attr.write_backward)
|
2016-05-24 10:28:59 +08:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-18 20:29:13 +08:00
|
|
|
static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
|
2016-09-08 18:21:51 +08:00
|
|
|
struct mmap_params *mp, int cpu_idx,
|
2016-07-14 16:34:40 +08:00
|
|
|
int thread, int *_output, int *_output_backward)
|
perf evlist: Fix per thread mmap setup
The PERF_EVENT_IOC_SET_OUTPUT ioctl was returning -EINVAL when using
--pid when monitoring multithreaded apps, as we can only share a ring
buffer for events on the same thread if not doing per cpu.
Fix it by using per thread ring buffers.
Tested with:
[root@felicio ~]# tuna -t 26131 -CP | nl
1 thread ctxt_switches
2 pid SCHED_ rtpri affinity voluntary nonvoluntary cmd
3 26131 OTHER 0 0,1 10814276 2397830 chromium-browse
4 642 OTHER 0 0,1 14688 0 chromium-browse
5 26148 OTHER 0 0,1 713602 115479 chromium-browse
6 26149 OTHER 0 0,1 801958 2262 chromium-browse
7 26150 OTHER 0 0,1 1271128 248 chromium-browse
8 26151 OTHER 0 0,1 3 0 chromium-browse
9 27049 OTHER 0 0,1 36796 9 chromium-browse
10 618 OTHER 0 0,1 14711 0 chromium-browse
11 661 OTHER 0 0,1 14593 0 chromium-browse
12 29048 OTHER 0 0,1 28125 0 chromium-browse
13 26143 OTHER 0 0,1 2202789 781 chromium-browse
[root@felicio ~]#
So 11 threads under pid 26131, then:
[root@felicio ~]# perf record -F 50000 --pid 26131
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fa4a2538000-7fa4a25b9000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fa4a25b9000-7fa4a263a000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
3 7fa4a263a000-7fa4a26bb000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
4 7fa4a26bb000-7fa4a273c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
5 7fa4a273c000-7fa4a27bd000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
6 7fa4a27bd000-7fa4a283e000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
7 7fa4a283e000-7fa4a28bf000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
8 7fa4a28bf000-7fa4a2940000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
9 7fa4a2940000-7fa4a29c1000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
10 7fa4a29c1000-7fa4a2a42000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
11 7fa4a2a42000-7fa4a2ac3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
11 mmaps, one per thread since we didn't specify any CPU list, so we need one
mmap per thread and:
[root@felicio ~]# perf record -F 50000 --pid 26131
^M
^C[ perf record: Woken up 79 times to write data ]
[ perf record: Captured and wrote 20.614 MB perf.data (~900639 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 371310 26131
2 96516 26148
3 95694 26149
4 95203 26150
5 7291 26143
6 87 27049
7 76 661
8 60 29048
9 47 618
10 43 642
[root@felicio ~]#
Ok, one of the threads, 26151 was quiescent, so no samples there, but all the
others are there.
Then, if I specify one CPU:
[root@felicio ~]# perf record -F 50000 --pid 26131 --cpu 1
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.680 MB perf.data (~29730 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 8444 26131
2 2584 26149
3 2518 26148
4 2324 26150
5 123 26143
6 9 661
7 9 29048
[root@felicio ~]#
This machine has two cores, so fewer threads appeared on the radar, and:
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f484b922000-7f484b9a3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Just one mmap, as now we can use just one per-cpu buffer instead of the
per-thread needed in the previous case.
For global profiling:
[root@felicio ~]# perf record -F 50000 -a
^C[ perf record: Woken up 26 times to write data ]
[ perf record: Captured and wrote 7.128 MB perf.data (~311412 samples) ]
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fb49b435000-7fb49b4b6000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fb49b4b6000-7fb49b537000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
It uses per-cpu buffers.
For just one thread:
[root@felicio ~]# perf record -F 50000 --tid 26148
^C[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.330 MB perf.data (~14426 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 9969 26148
[root@felicio ~]#
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f286a51b000-7f286a59c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Tested-by: David Ahern <dsahern@gmail.com>
Tested-by: Lin Ming <ming.m.lin@intel.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/r/20110426204401.GB1746@ghostprotocols.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-15 20:39:00 +08:00
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
2016-05-24 10:28:59 +08:00
|
|
|
int revent;
|
2016-09-08 18:21:51 +08:00
|
|
|
int evlist_cpu = cpu_map__cpu(evlist->cpus, cpu_idx);
|
2013-10-18 20:29:13 +08:00
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
2016-07-14 16:34:40 +08:00
|
|
|
struct perf_mmap *maps = evlist->mmap;
|
|
|
|
int *output = _output;
|
2014-07-31 14:00:51 +08:00
|
|
|
int fd;
|
2016-09-08 18:21:51 +08:00
|
|
|
int cpu;
|
2014-07-31 14:00:51 +08:00
|
|
|
|
2016-07-14 16:34:40 +08:00
|
|
|
if (evsel->attr.write_backward) {
|
|
|
|
output = _output_backward;
|
|
|
|
maps = evlist->backward_mmap;
|
|
|
|
|
|
|
|
if (!maps) {
|
|
|
|
maps = perf_evlist__alloc_mmap(evlist);
|
|
|
|
if (!maps)
|
|
|
|
return -1;
|
|
|
|
evlist->backward_mmap = maps;
|
2016-07-14 16:34:42 +08:00
|
|
|
if (evlist->bkw_mmap_state == BKW_MMAP_NOTREADY)
|
|
|
|
perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_RUNNING);
|
2016-07-14 16:34:40 +08:00
|
|
|
}
|
|
|
|
}
|
2016-05-24 10:28:59 +08:00
|
|
|
|
2014-07-31 14:00:51 +08:00
|
|
|
if (evsel->system_wide && thread)
|
|
|
|
continue;
|
|
|
|
|
2016-09-08 18:21:51 +08:00
|
|
|
cpu = cpu_map__idx(evsel->cpus, evlist_cpu);
|
|
|
|
if (cpu == -1)
|
|
|
|
continue;
|
|
|
|
|
2014-07-31 14:00:51 +08:00
|
|
|
fd = FD(evsel, cpu, thread);
|
2013-10-18 20:29:13 +08:00
|
|
|
|
|
|
|
if (*output == -1) {
|
|
|
|
*output = fd;
|
2016-07-14 16:34:40 +08:00
|
|
|
|
|
|
|
if (perf_mmap__mmap(&maps[idx], mp, *output) < 0)
|
2013-10-18 20:29:13 +08:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
|
|
|
|
return -1;
|
2014-09-09 00:26:35 +08:00
|
|
|
|
2016-07-14 16:34:40 +08:00
|
|
|
perf_mmap__get(&maps[idx]);
|
2013-10-18 20:29:13 +08:00
|
|
|
}
|
|
|
|
|
2016-05-24 10:28:59 +08:00
|
|
|
revent = perf_evlist__should_poll(evlist, evsel) ? POLLIN : 0;
|
|
|
|
|
2014-11-11 22:16:39 +08: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 &&
|
2016-07-14 16:34:40 +08:00
|
|
|
__perf_evlist__add_pollfd(evlist, fd, &maps[idx], revent) < 0) {
|
|
|
|
perf_mmap__put(&maps[idx]);
|
2014-08-19 03:44:06 +08:00
|
|
|
return -1;
|
2014-09-09 00:26:35 +08:00
|
|
|
}
|
2014-09-08 23:55:12 +08:00
|
|
|
|
2014-10-27 21:49:22 +08: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 20:29:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-14 18:02:52 +08:00
|
|
|
static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist,
|
|
|
|
struct mmap_params *mp)
|
2013-10-18 20:29:13 +08: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 20:39:00 +08:00
|
|
|
int cpu, thread;
|
2013-03-11 15:43:14 +08: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 20:39:00 +08:00
|
|
|
|
2013-08-14 20:48:24 +08:00
|
|
|
pr_debug2("perf event ring buffer mmapped per cpu\n");
|
2013-03-11 15:43:14 +08: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 20:39:00 +08:00
|
|
|
int output = -1;
|
2016-07-14 16:34:40 +08:00
|
|
|
int output_backward = -1;
|
perf evlist: Fix per thread mmap setup
The PERF_EVENT_IOC_SET_OUTPUT ioctl was returning -EINVAL when using
--pid when monitoring multithreaded apps, as we can only share a ring
buffer for events on the same thread if not doing per cpu.
Fix it by using per thread ring buffers.
Tested with:
[root@felicio ~]# tuna -t 26131 -CP | nl
1 thread ctxt_switches
2 pid SCHED_ rtpri affinity voluntary nonvoluntary cmd
3 26131 OTHER 0 0,1 10814276 2397830 chromium-browse
4 642 OTHER 0 0,1 14688 0 chromium-browse
5 26148 OTHER 0 0,1 713602 115479 chromium-browse
6 26149 OTHER 0 0,1 801958 2262 chromium-browse
7 26150 OTHER 0 0,1 1271128 248 chromium-browse
8 26151 OTHER 0 0,1 3 0 chromium-browse
9 27049 OTHER 0 0,1 36796 9 chromium-browse
10 618 OTHER 0 0,1 14711 0 chromium-browse
11 661 OTHER 0 0,1 14593 0 chromium-browse
12 29048 OTHER 0 0,1 28125 0 chromium-browse
13 26143 OTHER 0 0,1 2202789 781 chromium-browse
[root@felicio ~]#
So 11 threads under pid 26131, then:
[root@felicio ~]# perf record -F 50000 --pid 26131
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fa4a2538000-7fa4a25b9000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fa4a25b9000-7fa4a263a000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
3 7fa4a263a000-7fa4a26bb000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
4 7fa4a26bb000-7fa4a273c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
5 7fa4a273c000-7fa4a27bd000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
6 7fa4a27bd000-7fa4a283e000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
7 7fa4a283e000-7fa4a28bf000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
8 7fa4a28bf000-7fa4a2940000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
9 7fa4a2940000-7fa4a29c1000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
10 7fa4a29c1000-7fa4a2a42000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
11 7fa4a2a42000-7fa4a2ac3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
11 mmaps, one per thread since we didn't specify any CPU list, so we need one
mmap per thread and:
[root@felicio ~]# perf record -F 50000 --pid 26131
^M
^C[ perf record: Woken up 79 times to write data ]
[ perf record: Captured and wrote 20.614 MB perf.data (~900639 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 371310 26131
2 96516 26148
3 95694 26149
4 95203 26150
5 7291 26143
6 87 27049
7 76 661
8 60 29048
9 47 618
10 43 642
[root@felicio ~]#
Ok, one of the threads, 26151 was quiescent, so no samples there, but all the
others are there.
Then, if I specify one CPU:
[root@felicio ~]# perf record -F 50000 --pid 26131 --cpu 1
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.680 MB perf.data (~29730 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 8444 26131
2 2584 26149
3 2518 26148
4 2324 26150
5 123 26143
6 9 661
7 9 29048
[root@felicio ~]#
This machine has two cores, so fewer threads appeared on the radar, and:
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f484b922000-7f484b9a3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Just one mmap, as now we can use just one per-cpu buffer instead of the
per-thread needed in the previous case.
For global profiling:
[root@felicio ~]# perf record -F 50000 -a
^C[ perf record: Woken up 26 times to write data ]
[ perf record: Captured and wrote 7.128 MB perf.data (~311412 samples) ]
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fb49b435000-7fb49b4b6000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fb49b4b6000-7fb49b537000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
It uses per-cpu buffers.
For just one thread:
[root@felicio ~]# perf record -F 50000 --tid 26148
^C[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.330 MB perf.data (~14426 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 9969 26148
[root@felicio ~]#
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f286a51b000-7f286a59c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Tested-by: David Ahern <dsahern@gmail.com>
Tested-by: Lin Ming <ming.m.lin@intel.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/r/20110426204401.GB1746@ghostprotocols.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-15 20:39:00 +08:00
|
|
|
|
2015-04-09 23:53:42 +08:00
|
|
|
auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, cpu,
|
|
|
|
true);
|
|
|
|
|
2013-03-11 15:43:14 +08:00
|
|
|
for (thread = 0; thread < nr_threads; thread++) {
|
2014-07-14 18:02:52 +08:00
|
|
|
if (perf_evlist__mmap_per_evsel(evlist, cpu, mp, cpu,
|
2016-07-14 16:34:40 +08:00
|
|
|
thread, &output, &output_backward))
|
2013-10-18 20:29:13 +08: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 20:39:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_unmap:
|
2016-07-14 16:34:38 +08:00
|
|
|
perf_evlist__munmap_nofree(evlist);
|
perf evlist: Fix per thread mmap setup
The PERF_EVENT_IOC_SET_OUTPUT ioctl was returning -EINVAL when using
--pid when monitoring multithreaded apps, as we can only share a ring
buffer for events on the same thread if not doing per cpu.
Fix it by using per thread ring buffers.
Tested with:
[root@felicio ~]# tuna -t 26131 -CP | nl
1 thread ctxt_switches
2 pid SCHED_ rtpri affinity voluntary nonvoluntary cmd
3 26131 OTHER 0 0,1 10814276 2397830 chromium-browse
4 642 OTHER 0 0,1 14688 0 chromium-browse
5 26148 OTHER 0 0,1 713602 115479 chromium-browse
6 26149 OTHER 0 0,1 801958 2262 chromium-browse
7 26150 OTHER 0 0,1 1271128 248 chromium-browse
8 26151 OTHER 0 0,1 3 0 chromium-browse
9 27049 OTHER 0 0,1 36796 9 chromium-browse
10 618 OTHER 0 0,1 14711 0 chromium-browse
11 661 OTHER 0 0,1 14593 0 chromium-browse
12 29048 OTHER 0 0,1 28125 0 chromium-browse
13 26143 OTHER 0 0,1 2202789 781 chromium-browse
[root@felicio ~]#
So 11 threads under pid 26131, then:
[root@felicio ~]# perf record -F 50000 --pid 26131
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fa4a2538000-7fa4a25b9000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fa4a25b9000-7fa4a263a000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
3 7fa4a263a000-7fa4a26bb000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
4 7fa4a26bb000-7fa4a273c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
5 7fa4a273c000-7fa4a27bd000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
6 7fa4a27bd000-7fa4a283e000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
7 7fa4a283e000-7fa4a28bf000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
8 7fa4a28bf000-7fa4a2940000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
9 7fa4a2940000-7fa4a29c1000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
10 7fa4a29c1000-7fa4a2a42000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
11 7fa4a2a42000-7fa4a2ac3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
11 mmaps, one per thread since we didn't specify any CPU list, so we need one
mmap per thread and:
[root@felicio ~]# perf record -F 50000 --pid 26131
^M
^C[ perf record: Woken up 79 times to write data ]
[ perf record: Captured and wrote 20.614 MB perf.data (~900639 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 371310 26131
2 96516 26148
3 95694 26149
4 95203 26150
5 7291 26143
6 87 27049
7 76 661
8 60 29048
9 47 618
10 43 642
[root@felicio ~]#
Ok, one of the threads, 26151 was quiescent, so no samples there, but all the
others are there.
Then, if I specify one CPU:
[root@felicio ~]# perf record -F 50000 --pid 26131 --cpu 1
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.680 MB perf.data (~29730 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 8444 26131
2 2584 26149
3 2518 26148
4 2324 26150
5 123 26143
6 9 661
7 9 29048
[root@felicio ~]#
This machine has two cores, so fewer threads appeared on the radar, and:
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f484b922000-7f484b9a3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Just one mmap, as now we can use just one per-cpu buffer instead of the
per-thread needed in the previous case.
For global profiling:
[root@felicio ~]# perf record -F 50000 -a
^C[ perf record: Woken up 26 times to write data ]
[ perf record: Captured and wrote 7.128 MB perf.data (~311412 samples) ]
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fb49b435000-7fb49b4b6000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fb49b4b6000-7fb49b537000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
It uses per-cpu buffers.
For just one thread:
[root@felicio ~]# perf record -F 50000 --tid 26148
^C[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.330 MB perf.data (~14426 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 9969 26148
[root@felicio ~]#
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f286a51b000-7f286a59c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Tested-by: David Ahern <dsahern@gmail.com>
Tested-by: Lin Ming <ming.m.lin@intel.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/r/20110426204401.GB1746@ghostprotocols.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-15 20:39:00 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-07-14 18:02:52 +08: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 20:39:00 +08:00
|
|
|
{
|
|
|
|
int thread;
|
2013-03-11 15:43:14 +08: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 20:39:00 +08:00
|
|
|
|
2013-08-14 20:48:24 +08:00
|
|
|
pr_debug2("perf event ring buffer mmapped per thread\n");
|
2013-03-11 15:43:14 +08: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 20:39:00 +08:00
|
|
|
int output = -1;
|
2016-07-14 16:34:40 +08:00
|
|
|
int output_backward = -1;
|
perf evlist: Fix per thread mmap setup
The PERF_EVENT_IOC_SET_OUTPUT ioctl was returning -EINVAL when using
--pid when monitoring multithreaded apps, as we can only share a ring
buffer for events on the same thread if not doing per cpu.
Fix it by using per thread ring buffers.
Tested with:
[root@felicio ~]# tuna -t 26131 -CP | nl
1 thread ctxt_switches
2 pid SCHED_ rtpri affinity voluntary nonvoluntary cmd
3 26131 OTHER 0 0,1 10814276 2397830 chromium-browse
4 642 OTHER 0 0,1 14688 0 chromium-browse
5 26148 OTHER 0 0,1 713602 115479 chromium-browse
6 26149 OTHER 0 0,1 801958 2262 chromium-browse
7 26150 OTHER 0 0,1 1271128 248 chromium-browse
8 26151 OTHER 0 0,1 3 0 chromium-browse
9 27049 OTHER 0 0,1 36796 9 chromium-browse
10 618 OTHER 0 0,1 14711 0 chromium-browse
11 661 OTHER 0 0,1 14593 0 chromium-browse
12 29048 OTHER 0 0,1 28125 0 chromium-browse
13 26143 OTHER 0 0,1 2202789 781 chromium-browse
[root@felicio ~]#
So 11 threads under pid 26131, then:
[root@felicio ~]# perf record -F 50000 --pid 26131
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fa4a2538000-7fa4a25b9000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fa4a25b9000-7fa4a263a000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
3 7fa4a263a000-7fa4a26bb000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
4 7fa4a26bb000-7fa4a273c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
5 7fa4a273c000-7fa4a27bd000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
6 7fa4a27bd000-7fa4a283e000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
7 7fa4a283e000-7fa4a28bf000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
8 7fa4a28bf000-7fa4a2940000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
9 7fa4a2940000-7fa4a29c1000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
10 7fa4a29c1000-7fa4a2a42000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
11 7fa4a2a42000-7fa4a2ac3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
11 mmaps, one per thread since we didn't specify any CPU list, so we need one
mmap per thread and:
[root@felicio ~]# perf record -F 50000 --pid 26131
^M
^C[ perf record: Woken up 79 times to write data ]
[ perf record: Captured and wrote 20.614 MB perf.data (~900639 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 371310 26131
2 96516 26148
3 95694 26149
4 95203 26150
5 7291 26143
6 87 27049
7 76 661
8 60 29048
9 47 618
10 43 642
[root@felicio ~]#
Ok, one of the threads, 26151 was quiescent, so no samples there, but all the
others are there.
Then, if I specify one CPU:
[root@felicio ~]# perf record -F 50000 --pid 26131 --cpu 1
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.680 MB perf.data (~29730 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 8444 26131
2 2584 26149
3 2518 26148
4 2324 26150
5 123 26143
6 9 661
7 9 29048
[root@felicio ~]#
This machine has two cores, so fewer threads appeared on the radar, and:
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f484b922000-7f484b9a3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Just one mmap, as now we can use just one per-cpu buffer instead of the
per-thread needed in the previous case.
For global profiling:
[root@felicio ~]# perf record -F 50000 -a
^C[ perf record: Woken up 26 times to write data ]
[ perf record: Captured and wrote 7.128 MB perf.data (~311412 samples) ]
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fb49b435000-7fb49b4b6000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fb49b4b6000-7fb49b537000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
It uses per-cpu buffers.
For just one thread:
[root@felicio ~]# perf record -F 50000 --tid 26148
^C[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.330 MB perf.data (~14426 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 9969 26148
[root@felicio ~]#
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f286a51b000-7f286a59c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Tested-by: David Ahern <dsahern@gmail.com>
Tested-by: Lin Ming <ming.m.lin@intel.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/r/20110426204401.GB1746@ghostprotocols.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-15 20:39:00 +08:00
|
|
|
|
2015-04-09 23:53:42 +08:00
|
|
|
auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, thread,
|
|
|
|
false);
|
|
|
|
|
2014-07-14 18:02:52 +08:00
|
|
|
if (perf_evlist__mmap_per_evsel(evlist, thread, mp, 0, thread,
|
2016-07-14 16:34:40 +08:00
|
|
|
&output, &output_backward))
|
2013-10-18 20:29:13 +08: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 20:39:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_unmap:
|
2016-07-14 16:34:38 +08:00
|
|
|
perf_evlist__munmap_nofree(evlist);
|
perf evlist: Fix per thread mmap setup
The PERF_EVENT_IOC_SET_OUTPUT ioctl was returning -EINVAL when using
--pid when monitoring multithreaded apps, as we can only share a ring
buffer for events on the same thread if not doing per cpu.
Fix it by using per thread ring buffers.
Tested with:
[root@felicio ~]# tuna -t 26131 -CP | nl
1 thread ctxt_switches
2 pid SCHED_ rtpri affinity voluntary nonvoluntary cmd
3 26131 OTHER 0 0,1 10814276 2397830 chromium-browse
4 642 OTHER 0 0,1 14688 0 chromium-browse
5 26148 OTHER 0 0,1 713602 115479 chromium-browse
6 26149 OTHER 0 0,1 801958 2262 chromium-browse
7 26150 OTHER 0 0,1 1271128 248 chromium-browse
8 26151 OTHER 0 0,1 3 0 chromium-browse
9 27049 OTHER 0 0,1 36796 9 chromium-browse
10 618 OTHER 0 0,1 14711 0 chromium-browse
11 661 OTHER 0 0,1 14593 0 chromium-browse
12 29048 OTHER 0 0,1 28125 0 chromium-browse
13 26143 OTHER 0 0,1 2202789 781 chromium-browse
[root@felicio ~]#
So 11 threads under pid 26131, then:
[root@felicio ~]# perf record -F 50000 --pid 26131
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fa4a2538000-7fa4a25b9000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fa4a25b9000-7fa4a263a000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
3 7fa4a263a000-7fa4a26bb000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
4 7fa4a26bb000-7fa4a273c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
5 7fa4a273c000-7fa4a27bd000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
6 7fa4a27bd000-7fa4a283e000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
7 7fa4a283e000-7fa4a28bf000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
8 7fa4a28bf000-7fa4a2940000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
9 7fa4a2940000-7fa4a29c1000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
10 7fa4a29c1000-7fa4a2a42000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
11 7fa4a2a42000-7fa4a2ac3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
11 mmaps, one per thread since we didn't specify any CPU list, so we need one
mmap per thread and:
[root@felicio ~]# perf record -F 50000 --pid 26131
^M
^C[ perf record: Woken up 79 times to write data ]
[ perf record: Captured and wrote 20.614 MB perf.data (~900639 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 371310 26131
2 96516 26148
3 95694 26149
4 95203 26150
5 7291 26143
6 87 27049
7 76 661
8 60 29048
9 47 618
10 43 642
[root@felicio ~]#
Ok, one of the threads, 26151 was quiescent, so no samples there, but all the
others are there.
Then, if I specify one CPU:
[root@felicio ~]# perf record -F 50000 --pid 26131 --cpu 1
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.680 MB perf.data (~29730 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 8444 26131
2 2584 26149
3 2518 26148
4 2324 26150
5 123 26143
6 9 661
7 9 29048
[root@felicio ~]#
This machine has two cores, so fewer threads appeared on the radar, and:
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f484b922000-7f484b9a3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Just one mmap, as now we can use just one per-cpu buffer instead of the
per-thread needed in the previous case.
For global profiling:
[root@felicio ~]# perf record -F 50000 -a
^C[ perf record: Woken up 26 times to write data ]
[ perf record: Captured and wrote 7.128 MB perf.data (~311412 samples) ]
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fb49b435000-7fb49b4b6000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fb49b4b6000-7fb49b537000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
It uses per-cpu buffers.
For just one thread:
[root@felicio ~]# perf record -F 50000 --tid 26148
^C[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.330 MB perf.data (~14426 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 9969 26148
[root@felicio ~]#
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f286a51b000-7f286a59c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Tested-by: David Ahern <dsahern@gmail.com>
Tested-by: Lin Ming <ming.m.lin@intel.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/r/20110426204401.GB1746@ghostprotocols.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-15 20:39:00 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-04-16 04:46:31 +08:00
|
|
|
unsigned long perf_event_mlock_kb_in_pages(void)
|
2013-09-01 18:36:12 +08:00
|
|
|
{
|
2016-04-16 04:46:31 +08:00
|
|
|
unsigned long pages;
|
|
|
|
int max;
|
2014-12-13 04:46:45 +08:00
|
|
|
|
2016-04-16 04:46:31 +08:00
|
|
|
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);
|
|
|
|
}
|
2014-12-13 04:46:45 +08:00
|
|
|
|
2016-04-16 04:46:31 +08:00
|
|
|
pages = (max * 1024) / page_size;
|
|
|
|
if (!is_power_of_2(pages))
|
|
|
|
pages = rounddown_pow_of_two(pages);
|
|
|
|
|
|
|
|
return pages;
|
|
|
|
}
|
|
|
|
|
2017-01-09 17:51:59 +08:00
|
|
|
size_t perf_evlist__mmap_size(unsigned long pages)
|
2016-04-16 04:46:31 +08:00
|
|
|
{
|
|
|
|
if (pages == UINT_MAX)
|
|
|
|
pages = perf_event_mlock_kb_in_pages();
|
|
|
|
else if (!is_power_of_2(pages))
|
2013-09-01 18:36:12 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return (pages + 1) * page_size;
|
|
|
|
}
|
|
|
|
|
2013-11-12 22:46:55 +08:00
|
|
|
static long parse_pages_arg(const char *str, unsigned long min,
|
|
|
|
unsigned long max)
|
2013-09-01 18:36:12 +08:00
|
|
|
{
|
2013-10-22 15:34:18 +08:00
|
|
|
unsigned long pages, val;
|
2013-09-01 18:36:13 +08: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 18:36:12 +08:00
|
|
|
|
2013-11-12 22:46:53 +08:00
|
|
|
if (str == NULL)
|
2013-11-12 22:46:55 +08:00
|
|
|
return -EINVAL;
|
2013-11-12 22:46:53 +08:00
|
|
|
|
2013-09-01 18:36:13 +08:00
|
|
|
val = parse_tag_value(str, tags);
|
2013-10-22 15:34:18 +08:00
|
|
|
if (val != (unsigned long) -1) {
|
2013-09-01 18:36:13 +08: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 22:46:55 +08:00
|
|
|
if (*eptr != '\0')
|
|
|
|
return -EINVAL;
|
2013-09-01 18:36:12 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 21:18:37 +08:00
|
|
|
if (pages == 0 && min == 0) {
|
2013-11-12 22:46:55 +08:00
|
|
|
/* leave number of pages at 0 */
|
2013-12-09 21:18:39 +08:00
|
|
|
} else if (!is_power_of_2(pages)) {
|
2017-01-09 17:51:55 +08:00
|
|
|
char buf[100];
|
|
|
|
|
2013-11-12 22:46:55 +08:00
|
|
|
/* round pages up to next power of 2 */
|
2014-12-17 00:24:41 +08:00
|
|
|
pages = roundup_pow_of_two(pages);
|
2013-12-09 21:18:39 +08:00
|
|
|
if (!pages)
|
|
|
|
return -EINVAL;
|
2017-01-09 17:51:55 +08:00
|
|
|
|
|
|
|
unit_number__scnprintf(buf, sizeof(buf), pages * page_size);
|
|
|
|
pr_info("rounding mmap pages size to %s (%lu pages)\n",
|
|
|
|
buf, pages);
|
2013-10-22 15:34:18 +08:00
|
|
|
}
|
|
|
|
|
2013-11-12 22:46:55 +08:00
|
|
|
if (pages > max)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return pages;
|
|
|
|
}
|
|
|
|
|
2015-04-09 23:53:46 +08:00
|
|
|
int __perf_evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str)
|
2013-11-12 22:46:55 +08:00
|
|
|
{
|
|
|
|
unsigned long max = UINT_MAX;
|
|
|
|
long pages;
|
|
|
|
|
2013-12-09 21:18:38 +08:00
|
|
|
if (max > SIZE_MAX / page_size)
|
2013-11-12 22:46:55 +08: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 18:36:12 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*mmap_pages = pages;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-09 23:53:46 +08: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 20:29:12 +08:00
|
|
|
/**
|
2015-04-09 23:53:42 +08:00
|
|
|
* perf_evlist__mmap_ex - Create mmaps to receive events.
|
2013-10-18 20:29:12 +08:00
|
|
|
* @evlist: list of events
|
|
|
|
* @pages: map length in pages
|
|
|
|
* @overwrite: overwrite older events?
|
2015-04-09 23:53:42 +08:00
|
|
|
* @auxtrace_pages - auxtrace map length in pages
|
|
|
|
* @auxtrace_overwrite - overwrite older auxtrace data?
|
2011-01-30 20:46:46 +08:00
|
|
|
*
|
2013-10-18 20:29:12 +08: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 21:59:43 +08:00
|
|
|
*
|
2015-04-09 23:53:42 +08:00
|
|
|
* Similarly, if @auxtrace_overwrite is %false the user needs to signal data
|
|
|
|
* consumption using auxtrace_mmap__write_tail().
|
|
|
|
*
|
2013-10-18 20:29:12 +08:00
|
|
|
* Return: %0 on success, negative error code otherwise.
|
2011-01-30 20:46:46 +08:00
|
|
|
*/
|
2015-04-09 23:53:42 +08:00
|
|
|
int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
|
|
|
|
bool overwrite, unsigned int auxtrace_pages,
|
|
|
|
bool auxtrace_overwrite)
|
2011-01-30 20:46:46 +08: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 20:39:00 +08:00
|
|
|
struct perf_evsel *evsel;
|
2011-01-30 21:59:43 +08:00
|
|
|
const struct cpu_map *cpus = evlist->cpus;
|
|
|
|
const struct thread_map *threads = evlist->threads;
|
2014-07-14 18:02:52 +08:00
|
|
|
struct mmap_params mp = {
|
|
|
|
.prot = PROT_READ | (overwrite ? 0 : PROT_WRITE),
|
|
|
|
};
|
2011-11-09 19:10:47 +08:00
|
|
|
|
2016-07-14 16:34:35 +08:00
|
|
|
if (!evlist->mmap)
|
|
|
|
evlist->mmap = perf_evlist__alloc_mmap(evlist);
|
|
|
|
if (!evlist->mmap)
|
2011-01-30 20:46:46 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2014-09-04 05:02:59 +08:00
|
|
|
if (evlist->pollfd.entries == NULL && perf_evlist__alloc_pollfd(evlist) < 0)
|
2011-01-30 20:46:46 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
evlist->overwrite = overwrite;
|
2013-09-01 18:36:12 +08:00
|
|
|
evlist->mmap_len = perf_evlist__mmap_size(pages);
|
2013-10-18 20:29:07 +08:00
|
|
|
pr_debug("mmap size %zuB\n", evlist->mmap_len);
|
2014-07-14 18:02:52 +08:00
|
|
|
mp.mask = evlist->mmap_len - page_size - 1;
|
2011-01-30 20:46:46 +08:00
|
|
|
|
2015-04-09 23:53:42 +08:00
|
|
|
auxtrace_mmap_params__init(&mp.auxtrace_mp, evlist->mmap_len,
|
|
|
|
auxtrace_pages, auxtrace_overwrite);
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
2011-01-30 20:46:46 +08:00
|
|
|
if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
|
2011-03-10 22:15:54 +08:00
|
|
|
evsel->sample_id == NULL &&
|
2012-09-26 23:41:14 +08:00
|
|
|
perf_evsel__alloc_id(evsel, cpu_map__nr(cpus), threads->nr) < 0)
|
2011-01-30 20:46:46 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-05-23 08:42:38 +08:00
|
|
|
if (cpu_map__empty(cpus))
|
2014-07-14 18:02:52 +08:00
|
|
|
return perf_evlist__mmap_per_thread(evlist, &mp);
|
2011-01-30 20:46:46 +08:00
|
|
|
|
2014-07-14 18:02:52 +08:00
|
|
|
return perf_evlist__mmap_per_cpu(evlist, &mp);
|
2011-01-30 20:46:46 +08:00
|
|
|
}
|
2011-01-30 21:59:43 +08:00
|
|
|
|
2015-04-09 23:53:42 +08: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 03:46:16 +08:00
|
|
|
int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
|
2011-01-30 21:59:43 +08:00
|
|
|
{
|
2015-09-08 15:58:57 +08:00
|
|
|
struct cpu_map *cpus;
|
|
|
|
struct thread_map *threads;
|
2011-01-30 21:59:43 +08:00
|
|
|
|
2015-09-08 15:58:57 +08:00
|
|
|
threads = thread_map__new_str(target->pid, target->tid, target->uid);
|
2011-01-30 21:59:43 +08:00
|
|
|
|
2015-09-08 15:58:57 +08:00
|
|
|
if (!threads)
|
2011-01-30 21:59:43 +08:00
|
|
|
return -1;
|
|
|
|
|
2013-12-05 06:56:40 +08:00
|
|
|
if (target__uses_dummy_map(target))
|
2015-09-08 15:58:57 +08:00
|
|
|
cpus = cpu_map__dummy_new();
|
2012-05-16 17:45:48 +08:00
|
|
|
else
|
2015-09-08 15:58:57 +08:00
|
|
|
cpus = cpu_map__new(target->cpu_list);
|
2011-01-30 21:59:43 +08:00
|
|
|
|
2015-09-08 15:58:57 +08:00
|
|
|
if (!cpus)
|
2011-01-30 21:59:43 +08:00
|
|
|
goto out_delete_threads;
|
|
|
|
|
2015-09-08 15:58:52 +08:00
|
|
|
evlist->has_user_cpus = !!target->cpu_list;
|
|
|
|
|
2015-09-08 15:58:57 +08:00
|
|
|
perf_evlist__set_maps(evlist, cpus, threads);
|
2015-09-08 15:58:51 +08:00
|
|
|
|
|
|
|
return 0;
|
2011-01-30 21:59:43 +08:00
|
|
|
|
|
|
|
out_delete_threads:
|
2015-09-08 15:58:57 +08:00
|
|
|
thread_map__put(threads);
|
2011-01-30 21:59:43 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-09-08 15:58:51 +08:00
|
|
|
void perf_evlist__set_maps(struct perf_evlist *evlist, struct cpu_map *cpus,
|
|
|
|
struct thread_map *threads)
|
2015-07-21 20:31:30 +08:00
|
|
|
{
|
2015-09-08 15:58:56 +08: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 20:31:30 +08:00
|
|
|
cpu_map__put(evlist->cpus);
|
2016-02-17 21:57:19 +08:00
|
|
|
evlist->cpus = cpu_map__get(cpus);
|
2015-09-08 15:58:56 +08:00
|
|
|
}
|
2015-07-21 20:31:30 +08:00
|
|
|
|
2015-09-08 15:58:56 +08:00
|
|
|
if (threads != evlist->threads) {
|
2015-07-21 20:31:30 +08:00
|
|
|
thread_map__put(evlist->threads);
|
2016-02-17 21:57:19 +08:00
|
|
|
evlist->threads = thread_map__get(threads);
|
2015-09-08 15:58:56 +08:00
|
|
|
}
|
2015-07-21 20:31:30 +08:00
|
|
|
|
2015-09-08 15:58:52 +08:00
|
|
|
perf_evlist__propagate_maps(evlist);
|
2015-07-21 20:31:30 +08:00
|
|
|
}
|
|
|
|
|
2016-04-12 05:37:45 +08:00
|
|
|
void __perf_evlist__set_sample_bit(struct perf_evlist *evlist,
|
|
|
|
enum perf_event_sample_format bit)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel)
|
2016-04-12 05:37:45 +08:00
|
|
|
__perf_evsel__set_sample_bit(evsel, bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __perf_evlist__reset_sample_bit(struct perf_evlist *evlist,
|
|
|
|
enum perf_event_sample_format bit)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel)
|
2016-04-12 05:37:45 +08:00
|
|
|
__perf_evsel__reset_sample_bit(evsel, bit);
|
|
|
|
}
|
|
|
|
|
2015-03-25 06:23:47 +08:00
|
|
|
int perf_evlist__apply_filters(struct perf_evlist *evlist, struct perf_evsel **err_evsel)
|
2011-02-26 11:51:54 +08:00
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
2012-09-27 02:07:39 +08:00
|
|
|
int err = 0;
|
|
|
|
const int ncpus = cpu_map__nr(evlist->cpus),
|
2013-03-11 15:43:14 +08:00
|
|
|
nthreads = thread_map__nr(evlist->threads);
|
2011-02-26 11:51:54 +08:00
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
2012-09-27 02:07:39 +08:00
|
|
|
if (evsel->filter == NULL)
|
2011-02-26 11:51:54 +08:00
|
|
|
continue;
|
2012-09-27 02:07:39 +08:00
|
|
|
|
2015-08-21 14:23:14 +08: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 02:53:49 +08:00
|
|
|
err = perf_evsel__apply_filter(evsel, ncpus, nthreads, evsel->filter);
|
2015-03-25 06:23:47 +08:00
|
|
|
if (err) {
|
|
|
|
*err_evsel = evsel;
|
2012-09-27 02:07:39 +08:00
|
|
|
break;
|
2015-03-25 06:23:47 +08:00
|
|
|
}
|
2011-02-26 11:51:54 +08:00
|
|
|
}
|
|
|
|
|
2012-09-27 02:07:39 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
int err = 0;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
2016-02-26 17:31:53 +08:00
|
|
|
if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
|
|
|
|
continue;
|
|
|
|
|
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 04:42:03 +08:00
|
|
|
err = perf_evsel__set_filter(evsel, filter);
|
2012-09-27 02:07:39 +08:00
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2011-02-26 11:51:54 +08:00
|
|
|
}
|
2011-05-21 23:49:00 +08:00
|
|
|
|
2015-02-22 03:33:47 +08:00
|
|
|
int perf_evlist__set_filter_pids(struct perf_evlist *evlist, size_t npids, pid_t *pids)
|
2015-02-22 02:09:55 +08:00
|
|
|
{
|
|
|
|
char *filter;
|
2015-02-22 03:33:47 +08:00
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
2015-02-22 02:09:55 +08:00
|
|
|
|
2015-02-22 03:33:47 +08: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 02:09:55 +08:00
|
|
|
|
|
|
|
ret = perf_evlist__set_filter(evlist, filter);
|
2015-02-22 03:33:47 +08:00
|
|
|
out_free:
|
2015-02-22 02:09:55 +08:00
|
|
|
free(filter);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-22 03:33:47 +08: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 03:42:15 +08:00
|
|
|
bool perf_evlist__valid_sample_type(struct perf_evlist *evlist)
|
2011-05-21 23:49:00 +08:00
|
|
|
{
|
2013-08-27 16:23:09 +08:00
|
|
|
struct perf_evsel *pos;
|
2011-06-02 22:04:54 +08:00
|
|
|
|
2013-08-27 16:23:09 +08:00
|
|
|
if (evlist->nr_entries == 1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (evlist->id_pos < 0 || evlist->is_pos < 0)
|
|
|
|
return false;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, pos) {
|
2013-08-27 16:23:09 +08:00
|
|
|
if (pos->id_pos != evlist->id_pos ||
|
|
|
|
pos->is_pos != evlist->is_pos)
|
2011-06-02 22:04:54 +08:00
|
|
|
return false;
|
2011-05-21 23:49:00 +08:00
|
|
|
}
|
|
|
|
|
2011-06-02 22:04:54 +08:00
|
|
|
return true;
|
2011-05-21 23:49:00 +08:00
|
|
|
}
|
|
|
|
|
2013-08-27 16:23:09 +08:00
|
|
|
u64 __perf_evlist__combined_sample_type(struct perf_evlist *evlist)
|
2011-06-02 22:04:54 +08:00
|
|
|
{
|
2013-08-27 16:23:09 +08:00
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
|
|
|
if (evlist->combined_sample_type)
|
|
|
|
return evlist->combined_sample_type;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel)
|
2013-08-27 16:23:09 +08: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 22:04:54 +08:00
|
|
|
}
|
|
|
|
|
2015-07-18 23:24:47 +08:00
|
|
|
u64 perf_evlist__combined_branch_type(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
u64 branch_type = 0;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel)
|
2015-07-18 23:24:47 +08:00
|
|
|
branch_type |= evsel->attr.branch_sample_type;
|
|
|
|
return branch_type;
|
|
|
|
}
|
|
|
|
|
2012-10-10 23:38:13 +08: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;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, pos) {
|
2012-10-10 23:38:13 +08: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 03:42:15 +08:00
|
|
|
u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist)
|
2011-11-12 08:28:50 +08:00
|
|
|
{
|
2012-08-15 03:42:15 +08:00
|
|
|
struct perf_evsel *first = perf_evlist__first(evlist);
|
2011-11-12 08:28:50 +08: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 16:23:09 +08:00
|
|
|
|
|
|
|
if (sample_type & PERF_SAMPLE_IDENTIFIER)
|
|
|
|
size += sizeof(data->id);
|
2011-11-12 08:28:50 +08:00
|
|
|
out:
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2012-08-15 03:42:15 +08:00
|
|
|
bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist)
|
2011-05-21 23:49:00 +08:00
|
|
|
{
|
2012-08-15 03:42:15 +08:00
|
|
|
struct perf_evsel *first = perf_evlist__first(evlist), *pos = first;
|
2011-06-02 22:04:54 +08:00
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry_continue(evlist, pos) {
|
2011-06-02 22:04:54 +08:00
|
|
|
if (first->attr.sample_id_all != pos->attr.sample_id_all)
|
|
|
|
return false;
|
2011-05-21 23:49:00 +08:00
|
|
|
}
|
|
|
|
|
2011-06-02 22:04:54 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-15 03:42:15 +08:00
|
|
|
bool perf_evlist__sample_id_all(struct perf_evlist *evlist)
|
2011-06-02 22:04:54 +08:00
|
|
|
{
|
2012-08-15 03:42:15 +08:00
|
|
|
struct perf_evsel *first = perf_evlist__first(evlist);
|
2011-06-02 22:04:54 +08:00
|
|
|
return first->attr.sample_id_all;
|
2011-05-21 23:49:00 +08:00
|
|
|
}
|
2011-10-06 06:11:32 +08:00
|
|
|
|
|
|
|
void perf_evlist__set_selected(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel)
|
|
|
|
{
|
|
|
|
evlist->selected = evsel;
|
|
|
|
}
|
2011-10-25 20:42:19 +08:00
|
|
|
|
2013-03-15 13:48:48 +08: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);
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry_reverse(evlist, evsel) {
|
2016-10-03 22:07:24 +08:00
|
|
|
int n = evsel->cpus ? evsel->cpus->nr : ncpus;
|
2014-01-17 23:34:06 +08:00
|
|
|
perf_evsel__close(evsel, n, nthreads);
|
|
|
|
}
|
2013-03-15 13:48:48 +08:00
|
|
|
}
|
|
|
|
|
2014-10-11 02:55:15 +08:00
|
|
|
static int perf_evlist__create_syswide_maps(struct perf_evlist *evlist)
|
|
|
|
{
|
2015-09-08 15:59:00 +08:00
|
|
|
struct cpu_map *cpus;
|
|
|
|
struct thread_map *threads;
|
2014-10-11 02:55:15 +08: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 15:59:00 +08:00
|
|
|
cpus = cpu_map__new(NULL);
|
|
|
|
if (!cpus)
|
2014-10-11 02:55:15 +08:00
|
|
|
goto out;
|
|
|
|
|
2015-09-08 15:59:00 +08:00
|
|
|
threads = thread_map__new_dummy();
|
|
|
|
if (!threads)
|
|
|
|
goto out_put;
|
2014-10-11 02:55:15 +08:00
|
|
|
|
2015-09-08 15:59:00 +08:00
|
|
|
perf_evlist__set_maps(evlist, cpus, threads);
|
2014-10-11 02:55:15 +08:00
|
|
|
out:
|
|
|
|
return err;
|
2015-09-08 15:59:00 +08:00
|
|
|
out_put:
|
|
|
|
cpu_map__put(cpus);
|
2014-10-11 02:55:15 +08: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 18:22:36 +08:00
|
|
|
int perf_evlist__open(struct perf_evlist *evlist)
|
2011-10-25 20:42:19 +08: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 18:22:36 +08:00
|
|
|
struct perf_evsel *evsel;
|
2013-03-15 13:48:48 +08:00
|
|
|
int err;
|
2011-10-25 20:42:19 +08:00
|
|
|
|
2014-10-11 02:55:15 +08: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 03:40:11 +08:00
|
|
|
perf_evlist__update_id_pos(evlist);
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
2016-01-07 17:13:59 +08:00
|
|
|
err = perf_evsel__open(evsel, evsel->cpus, evsel->threads);
|
2011-10-25 20:42:19 +08:00
|
|
|
if (err < 0)
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out_err:
|
2013-03-15 13:48:48 +08:00
|
|
|
perf_evlist__close(evlist);
|
2012-02-23 11:13:36 +08:00
|
|
|
errno = -err;
|
2011-10-25 20:42:19 +08:00
|
|
|
return err;
|
|
|
|
}
|
2011-11-09 18:47:15 +08:00
|
|
|
|
2013-11-13 03:46:16 +08:00
|
|
|
int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *target,
|
2013-03-11 15:43:17 +08:00
|
|
|
const char *argv[], bool pipe_output,
|
2014-01-04 01:56:49 +08:00
|
|
|
void (*exec_error)(int signo, siginfo_t *info, void *ucontext))
|
2011-11-09 18:47:15 +08:00
|
|
|
{
|
|
|
|
int 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 23:39:50 +08:00
|
|
|
int ret;
|
|
|
|
|
2013-03-11 15:43:16 +08:00
|
|
|
if (pipe_output)
|
2011-11-09 18:47:15 +08:00
|
|
|
dup2(2, 1);
|
|
|
|
|
2013-05-26 07:50:39 +08:00
|
|
|
signal(SIGTERM, SIG_DFL);
|
|
|
|
|
2011-11-09 18:47:15 +08: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 23:39:50 +08: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-04 00:29:05 +08:00
|
|
|
* For cancelling the workload without actually running it,
|
2014-07-28 23:39:50 +08: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 18:47:15 +08:00
|
|
|
|
|
|
|
execvp(argv[0], (char **)argv);
|
|
|
|
|
2014-01-04 01:56:49 +08:00
|
|
|
if (exec_error) {
|
2014-01-03 02:11:25 +08:00
|
|
|
union sigval val;
|
|
|
|
|
|
|
|
val.sival_int = errno;
|
|
|
|
if (sigqueue(getppid(), SIGUSR1, val))
|
|
|
|
perror(argv[0]);
|
|
|
|
} else
|
|
|
|
perror(argv[0]);
|
2011-11-09 18:47:15 +08:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2014-01-04 01:56:49 +08:00
|
|
|
if (exec_error) {
|
|
|
|
struct sigaction act = {
|
|
|
|
.sa_flags = SA_SIGINFO,
|
|
|
|
.sa_sigaction = exec_error,
|
|
|
|
};
|
|
|
|
sigaction(SIGUSR1, &act, NULL);
|
|
|
|
}
|
|
|
|
|
2014-10-11 01:29:49 +08: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 06:36:02 +08:00
|
|
|
thread_map__set_pid(evlist->threads, 0, evlist->workload.pid);
|
2014-10-11 01:29:49 +08:00
|
|
|
}
|
2011-11-09 18:47:15 +08: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 15:14:15 +08:00
|
|
|
fcntl(go_pipe[1], F_SETFD, FD_CLOEXEC);
|
2011-11-09 18:47:15 +08: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 03:27:21 +08:00
|
|
|
char bf = 0;
|
2013-06-26 15:14:15 +08:00
|
|
|
int ret;
|
2011-11-09 18:47:15 +08:00
|
|
|
/*
|
|
|
|
* Remove the cork, let it rip!
|
|
|
|
*/
|
2013-06-26 15:14:15 +08:00
|
|
|
ret = write(evlist->workload.cork_fd, &bf, 1);
|
|
|
|
if (ret < 0)
|
2017-01-10 21:41:00 +08:00
|
|
|
perror("unable to write to pipe");
|
2013-06-26 15:14:15 +08:00
|
|
|
|
|
|
|
close(evlist->workload.cork_fd);
|
|
|
|
return ret;
|
2011-11-09 18:47:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-08-02 22:42:57 +08:00
|
|
|
|
2012-08-02 23:23:46 +08:00
|
|
|
int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event,
|
2012-09-26 23:48:18 +08:00
|
|
|
struct perf_sample *sample)
|
2012-08-02 22:42:57 +08:00
|
|
|
{
|
2013-08-27 16:23:09 +08:00
|
|
|
struct perf_evsel *evsel = perf_evlist__event2evsel(evlist, event);
|
|
|
|
|
|
|
|
if (!evsel)
|
|
|
|
return -EFAULT;
|
2012-09-26 23:48:18 +08:00
|
|
|
return perf_evsel__parse_sample(evsel, event, sample);
|
2012-08-02 22:42:57 +08:00
|
|
|
}
|
2012-09-07 01:54:11 +08:00
|
|
|
|
|
|
|
size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
size_t printed = 0;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
2012-09-07 01:54:11 +08:00
|
|
|
printed += fprintf(fp, "%s%s", evsel->idx ? ", " : "",
|
|
|
|
perf_evsel__name(evsel));
|
|
|
|
}
|
|
|
|
|
2013-11-13 14:24:24 +08:00
|
|
|
return printed + fprintf(fp, "\n");
|
2012-09-07 01:54:11 +08:00
|
|
|
}
|
2013-10-17 23:07:58 +08:00
|
|
|
|
2016-02-19 00:34:09 +08:00
|
|
|
int perf_evlist__strerror_open(struct perf_evlist *evlist,
|
perf trace: Improve messages related to /proc/sys/kernel/perf_event_paranoid
kernel/events/core.c has:
/*
* perf event paranoia level:
* -1 - not paranoid at all
* 0 - disallow raw tracepoint access for unpriv
* 1 - disallow cpu events for unpriv
* 2 - disallow kernel profiling for unpriv
*/
int sysctl_perf_event_paranoid __read_mostly = 1;
So, with the default being 1, a non-root user can trace his stuff:
[acme@zoo ~]$ cat /proc/sys/kernel/perf_event_paranoid
1
[acme@zoo ~]$ yes > /dev/null &
[1] 15338
[acme@zoo ~]$ trace -p 15338 | head -5
0.005 ( 0.005 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.045 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.085 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.125 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.165 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
[acme@zoo ~]$
[acme@zoo ~]$ trace --duration 1 sleep 1
1002.148 (1001.218 ms): nanosleep(rqtp: 0x7fff46c79250 ) = 0
[acme@zoo ~]$
[acme@zoo ~]$ trace -- usleep 1 | tail -5
0.905 ( 0.002 ms): brk( ) = 0x1c82000
0.910 ( 0.003 ms): brk(brk: 0x1ca3000 ) = 0x1ca3000
0.913 ( 0.001 ms): brk( ) = 0x1ca3000
0.990 ( 0.059 ms): nanosleep(rqtp: 0x7fffe31a3280 ) = 0
0.995 ( 0.000 ms): exit_group(
[acme@zoo ~]$
But can't do system wide tracing:
[acme@zoo ~]$ trace
Error: Operation not permitted.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 1.
[acme@zoo ~]$
[acme@zoo ~]$ trace --cpu 0
Error: Operation not permitted.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 1.
[acme@zoo ~]$
If the paranoid level is >= 2, i.e. turn this perf stuff off for !root users:
[acme@zoo ~]$ sudo sh -c 'echo 2 > /proc/sys/kernel/perf_event_paranoid'
[acme@zoo ~]$ cat /proc/sys/kernel/perf_event_paranoid
2
[acme@zoo ~]$
[acme@zoo ~]$ trace usleep 1
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
[acme@zoo ~]$ trace
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
[acme@zoo ~]$ trace --cpu 1
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
If the user manages to get what he/she wants, convincing root not
to be paranoid at all...
[root@zoo ~]# echo -1 > /proc/sys/kernel/perf_event_paranoid
[root@zoo ~]# cat /proc/sys/kernel/perf_event_paranoid
-1
[root@zoo ~]#
[acme@zoo ~]$ ps -eo user,pid,comm | grep Xorg
root 729 Xorg
[acme@zoo ~]$
[acme@zoo ~]$ trace -a --duration 0.001 -e \!select,ioctl,writev | grep Xorg | head -5
23.143 ( 0.003 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
23.152 ( 0.004 ms): Xorg/729 read(fd: 31, buf: 0x2544af0, count: 4096 ) = 8
23.161 ( 0.002 ms): Xorg/729 read(fd: 31, buf: 0x2544af0, count: 4096 ) = -1 EAGAIN Resource temporarily unavailable
23.175 ( 0.002 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
23.235 ( 0.002 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
[acme@zoo ~]$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-di28olfwd28rvkox7v3hqhu1@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-10-18 04:38:29 +08:00
|
|
|
int err, char *buf, size_t size)
|
|
|
|
{
|
|
|
|
int printed, value;
|
tools: Introduce str_error_r()
The tools so far have been using the strerror_r() GNU variant, that
returns a string, be it the buffer passed or something else.
But that, besides being tricky in cases where we expect that the
function using strerror_r() returns the error formatted in a provided
buffer (we have to check if it returned something else and copy that
instead), breaks the build on systems not using glibc, like Alpine
Linux, where musl libc is used.
So, introduce yet another wrapper, str_error_r(), that has the GNU
interface, but uses the portable XSI variant of strerror_r(), so that
users rest asured that the provided buffer is used and it is what is
returned.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-d4t42fnf48ytlk8rjxs822tf@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-07-06 22:56:20 +08:00
|
|
|
char sbuf[STRERR_BUFSIZE], *emsg = str_error_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 04:38:29 +08: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 20:36:23 +08: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 04:38:29 +08: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 04:18:54 +08: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 04:38:29 +08:00
|
|
|
|
|
|
|
printed += scnprintf(buf + printed, size - printed,
|
2014-06-11 04:18:54 +08: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 04:38:29 +08:00
|
|
|
break;
|
2016-02-19 00:34:09 +08:00
|
|
|
case EINVAL: {
|
|
|
|
struct perf_evsel *first = perf_evlist__first(evlist);
|
|
|
|
int max_freq;
|
|
|
|
|
|
|
|
if (sysctl__read_int("kernel/perf_event_max_sample_rate", &max_freq) < 0)
|
|
|
|
goto out_default;
|
|
|
|
|
|
|
|
if (first->attr.sample_freq < (u64)max_freq)
|
|
|
|
goto out_default;
|
|
|
|
|
|
|
|
printed = scnprintf(buf, size,
|
|
|
|
"Error:\t%s.\n"
|
|
|
|
"Hint:\tCheck /proc/sys/kernel/perf_event_max_sample_rate.\n"
|
|
|
|
"Hint:\tThe current value is %d and %" PRIu64 " is being requested.",
|
|
|
|
emsg, max_freq, first->attr.sample_freq);
|
|
|
|
break;
|
|
|
|
}
|
perf trace: Improve messages related to /proc/sys/kernel/perf_event_paranoid
kernel/events/core.c has:
/*
* perf event paranoia level:
* -1 - not paranoid at all
* 0 - disallow raw tracepoint access for unpriv
* 1 - disallow cpu events for unpriv
* 2 - disallow kernel profiling for unpriv
*/
int sysctl_perf_event_paranoid __read_mostly = 1;
So, with the default being 1, a non-root user can trace his stuff:
[acme@zoo ~]$ cat /proc/sys/kernel/perf_event_paranoid
1
[acme@zoo ~]$ yes > /dev/null &
[1] 15338
[acme@zoo ~]$ trace -p 15338 | head -5
0.005 ( 0.005 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.045 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.085 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.125 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.165 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
[acme@zoo ~]$
[acme@zoo ~]$ trace --duration 1 sleep 1
1002.148 (1001.218 ms): nanosleep(rqtp: 0x7fff46c79250 ) = 0
[acme@zoo ~]$
[acme@zoo ~]$ trace -- usleep 1 | tail -5
0.905 ( 0.002 ms): brk( ) = 0x1c82000
0.910 ( 0.003 ms): brk(brk: 0x1ca3000 ) = 0x1ca3000
0.913 ( 0.001 ms): brk( ) = 0x1ca3000
0.990 ( 0.059 ms): nanosleep(rqtp: 0x7fffe31a3280 ) = 0
0.995 ( 0.000 ms): exit_group(
[acme@zoo ~]$
But can't do system wide tracing:
[acme@zoo ~]$ trace
Error: Operation not permitted.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 1.
[acme@zoo ~]$
[acme@zoo ~]$ trace --cpu 0
Error: Operation not permitted.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 1.
[acme@zoo ~]$
If the paranoid level is >= 2, i.e. turn this perf stuff off for !root users:
[acme@zoo ~]$ sudo sh -c 'echo 2 > /proc/sys/kernel/perf_event_paranoid'
[acme@zoo ~]$ cat /proc/sys/kernel/perf_event_paranoid
2
[acme@zoo ~]$
[acme@zoo ~]$ trace usleep 1
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
[acme@zoo ~]$ trace
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
[acme@zoo ~]$ trace --cpu 1
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
If the user manages to get what he/she wants, convincing root not
to be paranoid at all...
[root@zoo ~]# echo -1 > /proc/sys/kernel/perf_event_paranoid
[root@zoo ~]# cat /proc/sys/kernel/perf_event_paranoid
-1
[root@zoo ~]#
[acme@zoo ~]$ ps -eo user,pid,comm | grep Xorg
root 729 Xorg
[acme@zoo ~]$
[acme@zoo ~]$ trace -a --duration 0.001 -e \!select,ioctl,writev | grep Xorg | head -5
23.143 ( 0.003 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
23.152 ( 0.004 ms): Xorg/729 read(fd: 31, buf: 0x2544af0, count: 4096 ) = 8
23.161 ( 0.002 ms): Xorg/729 read(fd: 31, buf: 0x2544af0, count: 4096 ) = -1 EAGAIN Resource temporarily unavailable
23.175 ( 0.002 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
23.235 ( 0.002 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
[acme@zoo ~]$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-di28olfwd28rvkox7v3hqhu1@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-10-18 04:38:29 +08:00
|
|
|
default:
|
2016-02-19 00:34:09 +08:00
|
|
|
out_default:
|
perf trace: Improve messages related to /proc/sys/kernel/perf_event_paranoid
kernel/events/core.c has:
/*
* perf event paranoia level:
* -1 - not paranoid at all
* 0 - disallow raw tracepoint access for unpriv
* 1 - disallow cpu events for unpriv
* 2 - disallow kernel profiling for unpriv
*/
int sysctl_perf_event_paranoid __read_mostly = 1;
So, with the default being 1, a non-root user can trace his stuff:
[acme@zoo ~]$ cat /proc/sys/kernel/perf_event_paranoid
1
[acme@zoo ~]$ yes > /dev/null &
[1] 15338
[acme@zoo ~]$ trace -p 15338 | head -5
0.005 ( 0.005 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.045 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.085 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.125 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.165 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
[acme@zoo ~]$
[acme@zoo ~]$ trace --duration 1 sleep 1
1002.148 (1001.218 ms): nanosleep(rqtp: 0x7fff46c79250 ) = 0
[acme@zoo ~]$
[acme@zoo ~]$ trace -- usleep 1 | tail -5
0.905 ( 0.002 ms): brk( ) = 0x1c82000
0.910 ( 0.003 ms): brk(brk: 0x1ca3000 ) = 0x1ca3000
0.913 ( 0.001 ms): brk( ) = 0x1ca3000
0.990 ( 0.059 ms): nanosleep(rqtp: 0x7fffe31a3280 ) = 0
0.995 ( 0.000 ms): exit_group(
[acme@zoo ~]$
But can't do system wide tracing:
[acme@zoo ~]$ trace
Error: Operation not permitted.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 1.
[acme@zoo ~]$
[acme@zoo ~]$ trace --cpu 0
Error: Operation not permitted.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 1.
[acme@zoo ~]$
If the paranoid level is >= 2, i.e. turn this perf stuff off for !root users:
[acme@zoo ~]$ sudo sh -c 'echo 2 > /proc/sys/kernel/perf_event_paranoid'
[acme@zoo ~]$ cat /proc/sys/kernel/perf_event_paranoid
2
[acme@zoo ~]$
[acme@zoo ~]$ trace usleep 1
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
[acme@zoo ~]$ trace
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
[acme@zoo ~]$ trace --cpu 1
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
If the user manages to get what he/she wants, convincing root not
to be paranoid at all...
[root@zoo ~]# echo -1 > /proc/sys/kernel/perf_event_paranoid
[root@zoo ~]# cat /proc/sys/kernel/perf_event_paranoid
-1
[root@zoo ~]#
[acme@zoo ~]$ ps -eo user,pid,comm | grep Xorg
root 729 Xorg
[acme@zoo ~]$
[acme@zoo ~]$ trace -a --duration 0.001 -e \!select,ioctl,writev | grep Xorg | head -5
23.143 ( 0.003 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
23.152 ( 0.004 ms): Xorg/729 read(fd: 31, buf: 0x2544af0, count: 4096 ) = 8
23.161 ( 0.002 ms): Xorg/729 read(fd: 31, buf: 0x2544af0, count: 4096 ) = -1 EAGAIN Resource temporarily unavailable
23.175 ( 0.002 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
23.235 ( 0.002 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
[acme@zoo ~]$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-di28olfwd28rvkox7v3hqhu1@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-10-18 04:38:29 +08:00
|
|
|
scnprintf(buf, size, "%s", emsg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-11 20:36:35 +08:00
|
|
|
|
2014-12-12 05:03:01 +08:00
|
|
|
int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size)
|
|
|
|
{
|
tools: Introduce str_error_r()
The tools so far have been using the strerror_r() GNU variant, that
returns a string, be it the buffer passed or something else.
But that, besides being tricky in cases where we expect that the
function using strerror_r() returns the error formatted in a provided
buffer (we have to check if it returned something else and copy that
instead), breaks the build on systems not using glibc, like Alpine
Linux, where musl libc is used.
So, introduce yet another wrapper, str_error_r(), that has the GNU
interface, but uses the portable XSI variant of strerror_r(), so that
users rest asured that the provided buffer is used and it is what is
returned.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-d4t42fnf48ytlk8rjxs822tf@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-07-06 22:56:20 +08:00
|
|
|
char sbuf[STRERR_BUFSIZE], *emsg = str_error_r(err, sbuf, sizeof(sbuf));
|
2014-12-13 03:25:33 +08:00
|
|
|
int pages_attempted = evlist->mmap_len / 1024, pages_max_per_user, printed = 0;
|
2014-12-12 05:03:01 +08:00
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
case EPERM:
|
2014-12-13 02:59:51 +08:00
|
|
|
sysctl__read_int("kernel/perf_event_mlock_kb", &pages_max_per_user);
|
2014-12-13 03:25:33 +08:00
|
|
|
printed += scnprintf(buf + printed, size - printed,
|
|
|
|
"Error:\t%s.\n"
|
2014-12-12 05:03:01 +08:00
|
|
|
"Hint:\tCheck /proc/sys/kernel/perf_event_mlock_kb (%d kB) setting.\n"
|
2014-12-13 03:25:33 +08:00
|
|
|
"Hint:\tTried using %zd kB.\n",
|
2014-12-13 02:59:51 +08:00
|
|
|
emsg, pages_max_per_user, pages_attempted);
|
2014-12-13 03:25:33 +08: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 05:03:01 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
scnprintf(buf, size, "%s", emsg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-11 20:36:35 +08: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;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry_safe(evlist, n, evsel) {
|
2013-12-11 20:36:35 +08:00
|
|
|
if (evsel->leader == move_evsel->leader)
|
|
|
|
list_move_tail(&evsel->node, &move);
|
|
|
|
}
|
|
|
|
|
|
|
|
list_splice(&move, &evlist->entries);
|
|
|
|
}
|
2014-07-31 14:00:52 +08: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;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
2014-07-31 14:00:52 +08:00
|
|
|
if (evsel != tracking_evsel)
|
|
|
|
evsel->tracking = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tracking_evsel->tracking = true;
|
|
|
|
}
|
perf tools: Enable passing event to BPF object
A new syntax is added to the parser so that the user can access
predefined perf events in BPF objects.
After this patch, BPF programs for perf are finally able to utilize
bpf_perf_event_read() introduced in commit 35578d798400 ("bpf: Implement
function bpf_perf_event_read() that get the selected hardware PMU
counter").
Test result:
# cat test_bpf_map_2.c
/************************ BEGIN **************************/
#include <uapi/linux/bpf.h>
#define SEC(NAME) __attribute__((section(NAME), used))
struct bpf_map_def {
unsigned int type;
unsigned int key_size;
unsigned int value_size;
unsigned int max_entries;
};
static int (*trace_printk)(const char *fmt, int fmt_size, ...) =
(void *)BPF_FUNC_trace_printk;
static int (*get_smp_processor_id)(void) =
(void *)BPF_FUNC_get_smp_processor_id;
static int (*perf_event_read)(struct bpf_map_def *, int) =
(void *)BPF_FUNC_perf_event_read;
struct bpf_map_def SEC("maps") pmu_map = {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(int),
.max_entries = __NR_CPUS__,
};
SEC("func_write=sys_write")
int func_write(void *ctx)
{
unsigned long long val;
char fmt[] = "sys_write: pmu=%llu\n";
val = perf_event_read(&pmu_map, get_smp_processor_id());
trace_printk(fmt, sizeof(fmt), val);
return 0;
}
SEC("func_write_return=sys_write%return")
int func_write_return(void *ctx)
{
unsigned long long val = 0;
char fmt[] = "sys_write_return: pmu=%llu\n";
val = perf_event_read(&pmu_map, get_smp_processor_id());
trace_printk(fmt, sizeof(fmt), val);
return 0;
}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = LINUX_VERSION_CODE;
/************************* END ***************************/
Normal case:
# echo "" > /sys/kernel/debug/tracing/trace
# perf record -i -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=cycles/' ls /
[SNIP]
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.013 MB perf.data (7 samples) ]
# cat /sys/kernel/debug/tracing/trace | grep ls
ls-17066 [000] d... 938449.863301: : sys_write: pmu=1157327
ls-17066 [000] dN.. 938449.863342: : sys_write_return: pmu=1225218
ls-17066 [000] d... 938449.863349: : sys_write: pmu=1241922
ls-17066 [000] dN.. 938449.863369: : sys_write_return: pmu=1267445
Normal case (system wide):
# echo "" > /sys/kernel/debug/tracing/trace
# perf record -i -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=cycles/' -a
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.811 MB perf.data (120 samples) ]
# cat /sys/kernel/debug/tracing/trace | grep -v '18446744073709551594' | grep -v perf | head -n 20
[SNIP]
# TASK-PID CPU# |||| TIMESTAMP FUNCTION
# | | | |||| | |
gmain-30828 [002] d... 2740551.068992: : sys_write: pmu=84373
gmain-30828 [002] d... 2740551.068992: : sys_write_return: pmu=87696
gmain-30828 [002] d... 2740551.068996: : sys_write: pmu=100658
gmain-30828 [002] d... 2740551.068997: : sys_write_return: pmu=102572
Error case 1:
# perf record -e './test_bpf_map_2.c' ls /
[SNIP]
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.014 MB perf.data ]
# cat /sys/kernel/debug/tracing/trace | grep ls
ls-17115 [007] d... 2724279.665625: : sys_write: pmu=18446744073709551614
ls-17115 [007] dN.. 2724279.665651: : sys_write_return: pmu=18446744073709551614
ls-17115 [007] d... 2724279.665658: : sys_write: pmu=18446744073709551614
ls-17115 [007] dN.. 2724279.665677: : sys_write_return: pmu=18446744073709551614
(18446744073709551614 is 0xfffffffffffffffe (-2))
Error case 2:
# perf record -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=evt/' -a
event syntax error: '..ps:pmu_map.event=evt/'
\___ Event not found for map setting
Hint: Valid config terms:
map:[<arraymap>].value=[value]
map:[<eventmap>].event=[event]
[SNIP]
Error case 3:
# ls /proc/2348/task/
2348 2505 2506 2507 2508
# perf record -i -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=cycles/' -p 2348
ERROR: Apply config to BPF failed: Cannot set event to BPF map in multi-thread tracing
Error case 4:
# perf record -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=cycles/' ls /
ERROR: Apply config to BPF failed: Doesn't support inherit event (Hint: use -i to turn off inherit)
Error case 5:
# perf record -i -e raw_syscalls:sys_enter -e './test_bpf_map_2.c/map:pmu_map.event=raw_syscalls:sys_enter/' ls
ERROR: Apply config to BPF failed: Can only put raw, hardware and BPF output event into a BPF map
Error case 6:
# perf record -i -e './test_bpf_map_2.c/map:pmu_map.event=123/' ls /
event syntax error: '.._map.event=123/'
\___ Incorrect value type for map
[SNIP]
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Cody P Schafer <dev@codyps.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
Cc: Kirill Smelkov <kirr@nexedi.com>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1456132275-98875-7-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-02-22 17:10:33 +08:00
|
|
|
|
|
|
|
struct perf_evsel *
|
|
|
|
perf_evlist__find_evsel_by_str(struct perf_evlist *evlist,
|
|
|
|
const char *str)
|
|
|
|
{
|
|
|
|
struct perf_evsel *evsel;
|
|
|
|
|
2016-06-23 22:26:15 +08:00
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
perf tools: Enable passing event to BPF object
A new syntax is added to the parser so that the user can access
predefined perf events in BPF objects.
After this patch, BPF programs for perf are finally able to utilize
bpf_perf_event_read() introduced in commit 35578d798400 ("bpf: Implement
function bpf_perf_event_read() that get the selected hardware PMU
counter").
Test result:
# cat test_bpf_map_2.c
/************************ BEGIN **************************/
#include <uapi/linux/bpf.h>
#define SEC(NAME) __attribute__((section(NAME), used))
struct bpf_map_def {
unsigned int type;
unsigned int key_size;
unsigned int value_size;
unsigned int max_entries;
};
static int (*trace_printk)(const char *fmt, int fmt_size, ...) =
(void *)BPF_FUNC_trace_printk;
static int (*get_smp_processor_id)(void) =
(void *)BPF_FUNC_get_smp_processor_id;
static int (*perf_event_read)(struct bpf_map_def *, int) =
(void *)BPF_FUNC_perf_event_read;
struct bpf_map_def SEC("maps") pmu_map = {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(int),
.max_entries = __NR_CPUS__,
};
SEC("func_write=sys_write")
int func_write(void *ctx)
{
unsigned long long val;
char fmt[] = "sys_write: pmu=%llu\n";
val = perf_event_read(&pmu_map, get_smp_processor_id());
trace_printk(fmt, sizeof(fmt), val);
return 0;
}
SEC("func_write_return=sys_write%return")
int func_write_return(void *ctx)
{
unsigned long long val = 0;
char fmt[] = "sys_write_return: pmu=%llu\n";
val = perf_event_read(&pmu_map, get_smp_processor_id());
trace_printk(fmt, sizeof(fmt), val);
return 0;
}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = LINUX_VERSION_CODE;
/************************* END ***************************/
Normal case:
# echo "" > /sys/kernel/debug/tracing/trace
# perf record -i -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=cycles/' ls /
[SNIP]
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.013 MB perf.data (7 samples) ]
# cat /sys/kernel/debug/tracing/trace | grep ls
ls-17066 [000] d... 938449.863301: : sys_write: pmu=1157327
ls-17066 [000] dN.. 938449.863342: : sys_write_return: pmu=1225218
ls-17066 [000] d... 938449.863349: : sys_write: pmu=1241922
ls-17066 [000] dN.. 938449.863369: : sys_write_return: pmu=1267445
Normal case (system wide):
# echo "" > /sys/kernel/debug/tracing/trace
# perf record -i -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=cycles/' -a
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.811 MB perf.data (120 samples) ]
# cat /sys/kernel/debug/tracing/trace | grep -v '18446744073709551594' | grep -v perf | head -n 20
[SNIP]
# TASK-PID CPU# |||| TIMESTAMP FUNCTION
# | | | |||| | |
gmain-30828 [002] d... 2740551.068992: : sys_write: pmu=84373
gmain-30828 [002] d... 2740551.068992: : sys_write_return: pmu=87696
gmain-30828 [002] d... 2740551.068996: : sys_write: pmu=100658
gmain-30828 [002] d... 2740551.068997: : sys_write_return: pmu=102572
Error case 1:
# perf record -e './test_bpf_map_2.c' ls /
[SNIP]
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.014 MB perf.data ]
# cat /sys/kernel/debug/tracing/trace | grep ls
ls-17115 [007] d... 2724279.665625: : sys_write: pmu=18446744073709551614
ls-17115 [007] dN.. 2724279.665651: : sys_write_return: pmu=18446744073709551614
ls-17115 [007] d... 2724279.665658: : sys_write: pmu=18446744073709551614
ls-17115 [007] dN.. 2724279.665677: : sys_write_return: pmu=18446744073709551614
(18446744073709551614 is 0xfffffffffffffffe (-2))
Error case 2:
# perf record -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=evt/' -a
event syntax error: '..ps:pmu_map.event=evt/'
\___ Event not found for map setting
Hint: Valid config terms:
map:[<arraymap>].value=[value]
map:[<eventmap>].event=[event]
[SNIP]
Error case 3:
# ls /proc/2348/task/
2348 2505 2506 2507 2508
# perf record -i -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=cycles/' -p 2348
ERROR: Apply config to BPF failed: Cannot set event to BPF map in multi-thread tracing
Error case 4:
# perf record -e cycles -e './test_bpf_map_2.c/map:pmu_map.event=cycles/' ls /
ERROR: Apply config to BPF failed: Doesn't support inherit event (Hint: use -i to turn off inherit)
Error case 5:
# perf record -i -e raw_syscalls:sys_enter -e './test_bpf_map_2.c/map:pmu_map.event=raw_syscalls:sys_enter/' ls
ERROR: Apply config to BPF failed: Can only put raw, hardware and BPF output event into a BPF map
Error case 6:
# perf record -i -e './test_bpf_map_2.c/map:pmu_map.event=123/' ls /
event syntax error: '.._map.event=123/'
\___ Incorrect value type for map
[SNIP]
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Cody P Schafer <dev@codyps.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
Cc: Kirill Smelkov <kirr@nexedi.com>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1456132275-98875-7-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-02-22 17:10:33 +08:00
|
|
|
if (!evsel->name)
|
|
|
|
continue;
|
|
|
|
if (strcmp(str, evsel->name) == 0)
|
|
|
|
return evsel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-07-14 16:34:42 +08:00
|
|
|
|
|
|
|
void perf_evlist__toggle_bkw_mmap(struct perf_evlist *evlist,
|
|
|
|
enum bkw_mmap_state state)
|
|
|
|
{
|
|
|
|
enum bkw_mmap_state old_state = evlist->bkw_mmap_state;
|
|
|
|
enum action {
|
|
|
|
NONE,
|
|
|
|
PAUSE,
|
|
|
|
RESUME,
|
|
|
|
} action = NONE;
|
|
|
|
|
|
|
|
if (!evlist->backward_mmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (old_state) {
|
|
|
|
case BKW_MMAP_NOTREADY: {
|
|
|
|
if (state != BKW_MMAP_RUNNING)
|
|
|
|
goto state_err;;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BKW_MMAP_RUNNING: {
|
|
|
|
if (state != BKW_MMAP_DATA_PENDING)
|
|
|
|
goto state_err;
|
|
|
|
action = PAUSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BKW_MMAP_DATA_PENDING: {
|
|
|
|
if (state != BKW_MMAP_EMPTY)
|
|
|
|
goto state_err;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BKW_MMAP_EMPTY: {
|
|
|
|
if (state != BKW_MMAP_RUNNING)
|
|
|
|
goto state_err;
|
|
|
|
action = RESUME;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
WARN_ONCE(1, "Shouldn't get there\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
evlist->bkw_mmap_state = state;
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case PAUSE:
|
|
|
|
perf_evlist__pause(evlist);
|
|
|
|
break;
|
|
|
|
case RESUME:
|
|
|
|
perf_evlist__resume(evlist);
|
|
|
|
break;
|
|
|
|
case NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
state_err:
|
|
|
|
return;
|
|
|
|
}
|