mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: acme@redhat.com, a.p.zijlstra@chello.nl, mingo@elte.hu, paulus@samba.org
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@redhat.com>
Subject: [PATCHv2 2/5] perf tool: Initialize events IDs in a single function
Date: Sat, 19 Nov 2011 21:03:50 -0500	[thread overview]
Message-ID: <1321754633-11489-3-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1321754633-11489-1-git-send-email-jolsa@redhat.com>

Currently events' IDs initialization is scattered among the
code. Adding function 'perf_evlist__init_ids' to allocate
and retrive events' IDs in one place.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/util/evlist.c |   50 +++++++++++++++++++++++++++++----------------
 1 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index fbb4b4a..0f715d0 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -326,10 +326,6 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int m
 					if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, output) != 0)
 						goto out_unmap;
 				}
-
-				if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
-				    perf_evlist__id_add_fd(evlist, evsel, cpu, thread, fd) < 0)
-					goto out_unmap;
 			}
 		}
 	}
@@ -366,10 +362,6 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, in
 				if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, output) != 0)
 					goto out_unmap;
 			}
-
-			if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
-			    perf_evlist__id_add_fd(evlist, evsel, 0, thread, fd) < 0)
-				goto out_unmap;
 		}
 	}
 
@@ -385,6 +377,33 @@ out_unmap:
 	return -1;
 }
 
+static int perf_evlist__init_ids(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel;
+	struct thread_map *threads = evlist->threads;
+	struct cpu_map *cpus = evlist->cpus;
+	int cpu, thread;
+
+	list_for_each_entry(evsel, &evlist->entries, node) {
+		if (!(evsel->attr.read_format & PERF_FORMAT_ID))
+			continue;
+
+		if ((!evsel->sample_id) &&
+		    perf_evsel__alloc_id(evsel, cpus->nr, threads->nr) < 0)
+			return -ENOMEM;
+
+		for (cpu = 0; cpu < cpus->nr; cpu++)
+			for (thread = 0; thread < threads->nr; thread++) {
+				int fd = FD(evsel, cpu, thread);
+				if (perf_evlist__id_add_fd(evlist, evsel,
+							   cpu, thread, fd))
+					return -EINVAL;
+			}
+	}
+
+	return 0;
+}
+
 /** perf_evlist__mmap - Create per cpu maps to receive events
  *
  * @evlist - list of events
@@ -403,10 +422,8 @@ out_unmap:
 int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite)
 {
 	unsigned int page_size = sysconf(_SC_PAGE_SIZE);
-	int mask = pages * page_size - 1;
-	struct perf_evsel *evsel;
+	int mask = pages * page_size - 1, ret;
 	const struct cpu_map *cpus = evlist->cpus;
-	const struct thread_map *threads = evlist->threads;
 	int prot = PROT_READ | (overwrite ? 0 : PROT_WRITE);
 
 	if (evlist->mmap == NULL && perf_evlist__alloc_mmap(evlist) < 0)
@@ -418,14 +435,11 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite)
 	evlist->overwrite = overwrite;
 	evlist->mmap_len = (pages + 1) * page_size;
 
-	list_for_each_entry(evsel, &evlist->entries, node) {
-		if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
-		    evsel->sample_id == NULL &&
-		    perf_evsel__alloc_id(evsel, cpus->nr, threads->nr) < 0)
-			return -ENOMEM;
-	}
+	ret = perf_evlist__init_ids(evlist);
+	if (ret)
+		return ret;
 
-	if (evlist->cpus->map[0] == -1)
+	if (cpus->map[0] == -1)
 		return perf_evlist__mmap_per_thread(evlist, prot, mask);
 
 	return perf_evlist__mmap_per_cpu(evlist, prot, mask);
-- 
1.7.6.4


  parent reply	other threads:[~2011-11-19 19:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-18 13:46 [RFC,PATCH] perf tool: Refactoring IO data files code Jiri Olsa
2011-11-18 13:46 ` [PATCH 1/5] perf tool: Fix session host_nachine retrieval Jiri Olsa
2011-11-18 14:24   ` Arnaldo Carvalho de Melo
2011-11-18 13:46 ` [PATCH 2/5] perf tool: Initialize events IDs in a single function Jiri Olsa
2011-11-18 14:22   ` Arnaldo Carvalho de Melo
2011-11-20  1:36     ` Jiri Olsa
2011-11-20  1:03       ` Arnaldo Carvalho de Melo
2011-11-18 13:46 ` [PATCH 3/5] perf tool: Introducing perf_mmap object Jiri Olsa
2011-11-18 14:37   ` Arnaldo Carvalho de Melo
2011-11-20  1:39     ` Jiri Olsa
2011-11-18 13:46 ` [PATCH 4/5] perf tool: Introducing perf_data object Jiri Olsa
2011-11-18 13:46 ` [PATCH 5/5] perf tool: Putting mmap support to " Jiri Olsa
2011-11-18 14:14 ` [RFC,PATCH] perf tool: Refactoring IO data files code Arnaldo Carvalho de Melo
2011-11-20  2:03 ` [RFC,PATCHv2] " Jiri Olsa
2011-11-20  2:03   ` [PATCHv2 1/5] perf tool: Fix session host_nachine retrieval Jiri Olsa
2011-11-20  2:03   ` Jiri Olsa [this message]
2011-11-20  2:03   ` [PATCHv2 3/5] perf tool: Introducing perf_mmap object Jiri Olsa
2011-11-20  2:03   ` [PATCHv2 4/5] perf tool: Introducing perf_data object Jiri Olsa
2011-11-20  2:03   ` [PATCHv2 5/5] perf tool: Putting mmap support to " Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1321754633-11489-3-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome