perf evlist: Split perf_evlist__id_hash

The previous situation was to receive an fd from where to read the event
ID.

Spin off a routine for when we have the ID handy, not having to read it
from some fd.

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 60098917
...@@ -106,12 +106,24 @@ void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd) ...@@ -106,12 +106,24 @@ void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
evlist->nr_fds++; evlist->nr_fds++;
} }
static int perf_evlist__id_hash(struct perf_evlist *evlist, struct perf_evsel *evsel, void perf_evlist__id_hash(struct perf_evlist *evlist, struct perf_evsel *evsel,
int cpu, int thread, u64 id)
{
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]);
}
static int perf_evlist__id_hash_fd(struct perf_evlist *evlist,
struct perf_evsel *evsel,
int cpu, int thread, int fd) int cpu, int thread, int fd)
{ {
struct perf_sample_id *sid;
u64 read_data[4] = { 0, }; u64 read_data[4] = { 0, };
int hash, id_idx = 1; /* The first entry is the counter value */ int id_idx = 1; /* The first entry is the counter value */
if (!(evsel->attr.read_format & PERF_FORMAT_ID) || if (!(evsel->attr.read_format & PERF_FORMAT_ID) ||
read(fd, &read_data, sizeof(read_data)) == -1) read(fd, &read_data, sizeof(read_data)) == -1)
...@@ -122,11 +134,7 @@ static int perf_evlist__id_hash(struct perf_evlist *evlist, struct perf_evsel *e ...@@ -122,11 +134,7 @@ static int perf_evlist__id_hash(struct perf_evlist *evlist, struct perf_evsel *e
if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
++id_idx; ++id_idx;
sid = SID(evsel, cpu, thread); perf_evlist__id_hash(evlist, evsel, cpu, thread, read_data[id_idx]);
sid->id = read_data[id_idx];
sid->evsel = evsel;
hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS);
hlist_add_head(&sid->node, &evlist->heads[hash]);
return 0; return 0;
} }
...@@ -300,7 +308,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite) ...@@ -300,7 +308,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite)
goto out_unmap; goto out_unmap;
if ((evsel->attr.read_format & PERF_FORMAT_ID) && if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
perf_evlist__id_hash(evlist, evsel, cpu, thread, fd) < 0) perf_evlist__id_hash_fd(evlist, evsel, cpu, thread, fd) < 0)
goto out_unmap; goto out_unmap;
} }
} }
......
...@@ -38,6 +38,9 @@ void perf_evlist__delete(struct perf_evlist *evlist); ...@@ -38,6 +38,9 @@ void perf_evlist__delete(struct perf_evlist *evlist);
void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry); void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry);
int perf_evlist__add_default(struct perf_evlist *evlist); int perf_evlist__add_default(struct perf_evlist *evlist);
void perf_evlist__id_hash(struct perf_evlist *evlist, struct perf_evsel *evsel,
int cpu, int thread, u64 id);
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist); int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd); void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd);
......
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