perf record: Use perf_evlist__mmap

There is more stuff that can go to the perf_ev{sel,list} layer, like
detecting if sample_id_all is available, etc, but lets try using this in
'perf test' first.

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>
LKML-Reference: <new-submission>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 70db7533
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
#define SID(e, x, y) xyarray__entry(e->id, x, y)
enum write_mode_t { enum write_mode_t {
WRITE_FORCE, WRITE_FORCE,
...@@ -78,8 +79,6 @@ static off_t post_processing_offset; ...@@ -78,8 +79,6 @@ static off_t post_processing_offset;
static struct perf_session *session; static struct perf_session *session;
static const char *cpu_list; static const char *cpu_list;
static struct perf_mmap mmap_array[MAX_NR_CPUS];
static void advance_output(size_t size) static void advance_output(size_t size)
{ {
bytes_written += size; bytes_written += size;
...@@ -196,20 +195,14 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n ...@@ -196,20 +195,14 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n
return h_attr; return h_attr;
} }
static void create_counter(struct perf_evlist *evlist, static void create_counter(struct perf_evsel *evsel, int cpu)
struct perf_evsel *evsel, int cpu)
{ {
char *filter = evsel->filter; char *filter = evsel->filter;
struct perf_event_attr *attr = &evsel->attr; struct perf_event_attr *attr = &evsel->attr;
struct perf_header_attr *h_attr; struct perf_header_attr *h_attr;
struct perf_sample_id *sid;
int thread_index; int thread_index;
int ret; int ret;
struct {
u64 count;
u64 time_enabled;
u64 time_running;
u64 id;
} read_data;
for (thread_index = 0; thread_index < threads->nr; thread_index++) { for (thread_index = 0; thread_index < threads->nr; thread_index++) {
h_attr = get_header_attr(attr, evsel->idx); h_attr = get_header_attr(attr, evsel->idx);
...@@ -223,45 +216,12 @@ static void create_counter(struct perf_evlist *evlist, ...@@ -223,45 +216,12 @@ static void create_counter(struct perf_evlist *evlist,
} }
} }
if (read(FD(evsel, cpu, thread_index), &read_data, sizeof(read_data)) == -1) { sid = SID(evsel, cpu, thread_index);
perror("Unable to read perf file descriptor"); if (perf_header_attr__add_id(h_attr, sid->id) < 0) {
exit(-1);
}
if (perf_header_attr__add_id(h_attr, read_data.id) < 0) {
pr_warning("Not enough memory to add id\n"); pr_warning("Not enough memory to add id\n");
exit(-1); exit(-1);
} }
assert(FD(evsel, cpu, thread_index) >= 0);
fcntl(FD(evsel, cpu, thread_index), F_SETFL, O_NONBLOCK);
if (evsel->idx || thread_index) {
struct perf_evsel *first;
first = list_entry(evlist->entries.next, struct perf_evsel, node);
ret = ioctl(FD(evsel, cpu, thread_index),
PERF_EVENT_IOC_SET_OUTPUT,
FD(first, cpu, 0));
if (ret) {
error("failed to set output: %d (%s)\n", errno,
strerror(errno));
exit(-1);
}
} else {
mmap_array[cpu].prev = 0;
mmap_array[cpu].mask = mmap_pages*page_size - 1;
mmap_array[cpu].base = mmap(NULL, (mmap_pages+1)*page_size,
PROT_READ | PROT_WRITE, MAP_SHARED, FD(evsel, cpu, thread_index), 0);
if (mmap_array[cpu].base == MAP_FAILED) {
error("failed to mmap with %d (%s)\n", errno, strerror(errno));
exit(-1);
}
evlist->pollfd[evlist->nr_fds].fd = FD(evsel, cpu, thread_index);
evlist->pollfd[evlist->nr_fds].events = POLLIN;
evlist->nr_fds++;
}
if (filter != NULL) { if (filter != NULL) {
ret = ioctl(FD(evsel, cpu, thread_index), ret = ioctl(FD(evsel, cpu, thread_index),
PERF_EVENT_IOC_SET_FILTER, filter); PERF_EVENT_IOC_SET_FILTER, filter);
...@@ -423,9 +383,12 @@ static void open_counters(struct perf_evlist *evlist) ...@@ -423,9 +383,12 @@ static void open_counters(struct perf_evlist *evlist)
} }
} }
if (perf_evlist__mmap(evlist, cpus, threads, mmap_pages, false) < 0)
die("failed to mmap with %d (%s)\n", errno, strerror(errno));
for (cpu = 0; cpu < cpus->nr; ++cpu) { for (cpu = 0; cpu < cpus->nr; ++cpu) {
list_for_each_entry(pos, &evlist->entries, node) list_for_each_entry(pos, &evlist->entries, node)
create_counter(evlist, pos, cpu); create_counter(pos, cpu);
} }
} }
...@@ -502,8 +465,8 @@ static void mmap_read_all(void) ...@@ -502,8 +465,8 @@ static void mmap_read_all(void)
int i; int i;
for (i = 0; i < cpus->nr; i++) { for (i = 0; i < cpus->nr; i++) {
if (mmap_array[i].base) if (evsel_list->mmap[i].base)
mmap_read(&mmap_array[i]); mmap_read(&evsel_list->mmap[i]);
} }
if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO)) if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment