All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Carrillo-Cisneros <davidcc@google.com>
To: linux-kernel@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Andi Kleen <ak@linux.intel.com>, Simon Que <sque@chromium.org>,
	Wang Nan <wangnan0@huawei.com>, Jiri Olsa <jolsa@kernel.org>,
	He Kuang <hekuang@huawei.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	David Ahern <dsa@cumulusnetworks.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Stephane Eranian <eranian@google.com>,
	Paul Turner <pjt@google.com>,
	David Carrillo-Cisneros <davidcc@google.com>
Subject: [PATCH v2 08/13] perf header: use struct feat_fd to process header records
Date: Tue, 23 May 2017 00:48:48 -0700	[thread overview]
Message-ID: <20170523074853.54892-9-davidcc@google.com> (raw)
In-Reply-To: <20170523074853.54892-1-davidcc@google.com>

As preparation for using header records in pipe-mode, replace
int fd with struct feat_fd in process functions for all header
record types.

This patch does not change behavior.

Signed-off-by: David Carrillo-Cisneros <davidcc@google.com>
---
 tools/perf/util/header.c | 171 +++++++++++++++++++++--------------------------
 1 file changed, 78 insertions(+), 93 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 3d0c61027170..dc923f5639f8 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1585,12 +1585,10 @@ static int perf_header__read_build_ids(struct perf_header *header,
 
 /* Macro for features that simply need to read and store a string. */
 #define FEAT_PROCESS_STR_FUN(__feat, __feat_env) \
-static int process_##__feat(struct perf_file_section *section __maybe_unused, \
-			    struct perf_header *ph, int fd,		      \
-			    void *data __maybe_unused) \
+static int process_##__feat(struct feat_fd *fd, void *data __maybe_unused) \
 {\
-	ph->env.__feat_env = do_read_string(fd, ph); \
-	return ph->env.__feat_env ? 0 : -ENOMEM; \
+	fd->ph->env.__feat_env = do_read_string(fd->fd, fd->ph); \
+	return fd->ph->env.__feat_env ? 0 : -ENOMEM; \
 }
 
 FEAT_PROCESS_STR_FUN(hostname, hostname);
@@ -1600,53 +1598,46 @@ FEAT_PROCESS_STR_FUN(arch, arch);
 FEAT_PROCESS_STR_FUN(cpudesc, cpu_desc);
 FEAT_PROCESS_STR_FUN(cpuid, cpuid);
 
-static int process_tracing_data(struct perf_file_section *section __maybe_unused,
-				struct perf_header *ph __maybe_unused,
-				int fd, void *data)
+static int process_build_id(struct feat_fd *fd, void *data __maybe_unused)
 {
-	ssize_t ret = trace_report(fd, data, false);
-	return ret < 0 ? -1 : 0;
+	if (perf_header__read_build_ids(fd->ph, fd->fd, fd->offset, fd->size))
+		pr_debug("Failed to read buildids, continuing...\n");
+	return 0;
 }
 
-static int process_build_id(struct perf_file_section *section,
-			    struct perf_header *ph, int fd,
-			    void *data __maybe_unused)
+static int process_tracing_data(struct feat_fd *fd, void *data)
 {
-	if (perf_header__read_build_ids(ph, fd, section->offset, section->size))
-		pr_debug("Failed to read buildids, continuing...\n");
-	return 0;
+	ssize_t ret = trace_report(fd->fd, data, false);
+
+	return ret < 0 ? -1 : 0;
 }
 
-static int process_nrcpus(struct perf_file_section *section __maybe_unused,
-			  struct perf_header *ph, int fd,
-			  void *data __maybe_unused)
+static int process_nrcpus(struct feat_fd *fd, void *data __maybe_unused)
 {
 	int ret;
 	u32 nr_cpus_avail, nr_cpus_online;
 
-	ret = do_read_u32(fd, ph, &nr_cpus_avail);
+	ret = do_read_u32(fd->fd, fd->ph, &nr_cpus_avail);
 	if (ret)
 		return ret;
 
-	ret = do_read_u32(fd, ph, &nr_cpus_online);
+	ret = do_read_u32(fd->fd, fd->ph, &nr_cpus_online);
 	if (ret)
 		return ret;
-	ph->env.nr_cpus_avail = (int)nr_cpus_avail;
-	ph->env.nr_cpus_online = (int)nr_cpus_online;
+	fd->ph->env.nr_cpus_avail = (int)nr_cpus_avail;
+	fd->ph->env.nr_cpus_online = (int)nr_cpus_online;
 	return 0;
 }
 
-static int process_total_mem(struct perf_file_section *section __maybe_unused,
-			     struct perf_header *ph, int fd,
-			     void *data __maybe_unused)
+static int process_total_mem(struct feat_fd *fd, void *data __maybe_unused)
 {
 	u64 total_mem;
 	int ret;
 
-	ret = do_read_u64(fd, ph, &total_mem);
+	ret = do_read_u64(fd->fd, fd->ph, &total_mem);
 	if (ret)
 		return -1;
-	ph->env.total_mem = (unsigned long long)total_mem;
+	fd->ph->env.total_mem = (unsigned long long)total_mem;
 	return 0;
 }
 
@@ -1683,17 +1674,15 @@ perf_evlist__set_event_name(struct perf_evlist *evlist,
 }
 
 static int
-process_event_desc(struct perf_file_section *section __maybe_unused,
-		   struct perf_header *header, int fd,
-		   void *data __maybe_unused)
+process_event_desc(struct feat_fd *fd, void *data __maybe_unused)
 {
 	struct perf_session *session;
-	struct perf_evsel *evsel, *events = read_event_desc(header, fd);
+	struct perf_evsel *evsel, *events = read_event_desc(fd->ph, fd->fd);
 
 	if (!events)
 		return 0;
 
-	session = container_of(header, struct perf_session, header);
+	session = container_of(fd->ph, struct perf_session, header);
 	for (evsel = events; evsel->attr.size; evsel++)
 		perf_evlist__set_event_name(session->evlist, evsel);
 
@@ -1702,19 +1691,17 @@ process_event_desc(struct perf_file_section *section __maybe_unused,
 	return 0;
 }
 
-static int process_cmdline(struct perf_file_section *section,
-			   struct perf_header *ph, int fd,
-			   void *data __maybe_unused)
+static int process_cmdline(struct feat_fd *fd, void *data __maybe_unused)
 {
 	char *str, *cmdline = NULL, **argv = NULL;
 	u32 nr, i, len = 0;
 
-	if (do_read_u32(fd, ph, &nr))
+	if (do_read_u32(fd->fd, fd->ph, &nr))
 		return -1;
 
-	ph->env.nr_cmdline = nr;
+	fd->ph->env.nr_cmdline = nr;
 
-	cmdline = zalloc(section->size + nr + 1);
+	cmdline = zalloc(fd->size + nr + 1);
 	if (!cmdline)
 		return -1;
 
@@ -1723,7 +1710,7 @@ static int process_cmdline(struct perf_file_section *section,
 		goto error;
 
 	for (i = 0; i < nr; i++) {
-		str = do_read_string(fd, ph);
+		str = do_read_string(fd->fd, fd->ph);
 		if (!str)
 			goto error;
 
@@ -1732,8 +1719,8 @@ static int process_cmdline(struct perf_file_section *section,
 		len += strlen(str) + 1;
 		free(str);
 	}
-	ph->env.cmdline = cmdline;
-	ph->env.cmdline_argv = (const char **) argv;
+	fd->ph->env.cmdline = cmdline;
+	fd->ph->env.cmdline_argv = (const char **) argv;
 	return 0;
 
 error:
@@ -1742,21 +1729,20 @@ static int process_cmdline(struct perf_file_section *section,
 	return -1;
 }
 
-static int process_cpu_topology(struct perf_file_section *section,
-				struct perf_header *ph, int fd,
-				void *data __maybe_unused)
+static int process_cpu_topology(struct feat_fd *fd, void *data __maybe_unused)
 {
 	u32 nr, i;
 	char *str;
 	struct strbuf sb;
-	int cpu_nr = ph->env.nr_cpus_avail;
-	u64 size = 0;
+	int cpu_nr = fd->ph->env.nr_cpus_avail;
+	struct perf_header *ph = fd->ph;
+	u64 start_offset = fd->offset;
 
 	ph->env.cpu = calloc(cpu_nr, sizeof(*ph->env.cpu));
 	if (!ph->env.cpu)
 		return -1;
 
-	if (do_read_u32(fd, ph, &nr))
+	if (do_read_u32(fd->fd, fd->ph, &nr))
 		goto free_cpu;
 
 	ph->env.nr_sibling_cores = nr;
@@ -1764,7 +1750,7 @@ static int process_cpu_topology(struct perf_file_section *section,
 		goto free_cpu;
 
 	for (i = 0; i < nr; i++) {
-		str = do_read_string(fd, ph);
+		str = do_read_string(fd->fd, fd->ph);
 		if (!str)
 			goto error;
 
@@ -1775,13 +1761,13 @@ static int process_cpu_topology(struct perf_file_section *section,
 	}
 	ph->env.sibling_cores = strbuf_detach(&sb, NULL);
 
-	if (do_read_u32(fd, ph, &nr))
+	if (do_read_u32(fd->fd, fd->ph, &nr))
 		return -1;
 
 	ph->env.nr_sibling_threads = nr;
 
 	for (i = 0; i < nr; i++) {
-		str = do_read_string(fd, ph);
+		str = do_read_string(fd->fd, fd->ph);
 		if (!str)
 			goto error;
 
@@ -1796,18 +1782,18 @@ static int process_cpu_topology(struct perf_file_section *section,
 	 * The header may be from old perf,
 	 * which doesn't include core id and socket id information.
 	 */
-	if (section->size <= size) {
+	if (fd->size <= fd->offset - start_offset) {
 		zfree(&ph->env.cpu);
 		return 0;
 	}
 
 	for (i = 0; i < (u32)cpu_nr; i++) {
-		if (do_read_u32(fd, ph, &nr))
+		if (do_read_u32(fd->fd, fd->ph, &nr))
 			goto free_cpu;
 
 		ph->env.cpu[i].core_id = nr;
 
-		if (do_read_u32(fd, ph, &nr))
+		if (do_read_u32(fd->fd, fd->ph, &nr))
 			goto free_cpu;
 
 		if (nr != (u32)-1 && nr > (u32)cpu_nr) {
@@ -1828,16 +1814,15 @@ static int process_cpu_topology(struct perf_file_section *section,
 	return -1;
 }
 
-static int process_numa_topology(struct perf_file_section *section __maybe_unused,
-				 struct perf_header *ph, int fd,
-				 void *data __maybe_unused)
+static int process_numa_topology(struct feat_fd *fd, void *data __maybe_unused)
 {
+	struct perf_header *ph = fd->ph;
 	struct numa_node *nodes, *n;
 	u32 nr, i;
 	char *str;
 
 	/* nr nodes */
-	if (do_read_u32(fd, ph, &nr))
+	if (do_read_u32(fd->fd, fd->ph, &nr))
 		return -1;
 
 	nodes = zalloc(sizeof(*nodes) * nr);
@@ -1848,16 +1833,16 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse
 		n = &nodes[i];
 
 		/* node number */
-		if (do_read_u32(fd, ph, &n->node))
+		if (do_read_u32(fd->fd, fd->ph, &n->node))
 			goto error;
 
-		if (do_read_u64(fd, ph, &n->mem_total))
+		if (do_read_u64(fd->fd, fd->ph, &n->mem_total))
 			goto error;
 
-		if (do_read_u64(fd, ph, &n->mem_free))
+		if (do_read_u64(fd->fd, fd->ph, &n->mem_free))
 			goto error;
 
-		str = do_read_string(fd, ph);
+		str = do_read_string(fd->fd, fd->ph);
 		if (!str)
 			goto error;
 
@@ -1876,16 +1861,15 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse
 	return -1;
 }
 
-static int process_pmu_mappings(struct perf_file_section *section __maybe_unused,
-				struct perf_header *ph, int fd,
-				void *data __maybe_unused)
+static int process_pmu_mappings(struct feat_fd *fd, void *data __maybe_unused)
 {
+	struct perf_header *ph = fd->ph;
 	char *name;
 	u32 pmu_num;
 	u32 type;
 	struct strbuf sb;
 
-	if (do_read_u32(fd, ph, &pmu_num))
+	if (do_read_u32(fd->fd, fd->ph, &pmu_num))
 		return -1;
 
 	if (!pmu_num) {
@@ -1898,10 +1882,10 @@ static int process_pmu_mappings(struct perf_file_section *section __maybe_unused
 		return -1;
 
 	while (pmu_num) {
-		if (do_read_u32(fd, ph, &type))
+		if (do_read_u32(fd->fd, fd->ph, &type))
 			goto error;
 
-		name = do_read_string(fd, ph);
+		name = do_read_string(fd->fd, fd->ph);
 		if (!name)
 			goto error;
 
@@ -1925,10 +1909,9 @@ static int process_pmu_mappings(struct perf_file_section *section __maybe_unused
 	return -1;
 }
 
-static int process_group_desc(struct perf_file_section *section __maybe_unused,
-			      struct perf_header *ph, int fd,
-			      void *data __maybe_unused)
+static int process_group_desc(struct feat_fd *fd, void *data __maybe_unused)
 {
+	struct perf_header *ph = fd->ph;
 	size_t ret = -1;
 	u32 i, nr, nr_groups;
 	struct perf_session *session;
@@ -1939,7 +1922,7 @@ static int process_group_desc(struct perf_file_section *section __maybe_unused,
 		u32 nr_members;
 	} *desc;
 
-	if (do_read_u32(fd, ph, &nr_groups))
+	if (do_read_u32(fd->fd, fd->ph, &nr_groups))
 		return -1;
 
 	ph->env.nr_groups = nr_groups;
@@ -1953,14 +1936,14 @@ static int process_group_desc(struct perf_file_section *section __maybe_unused,
 		return -1;
 
 	for (i = 0; i < nr_groups; i++) {
-		desc[i].name = do_read_string(fd, ph);
+		desc[i].name = do_read_string(fd->fd, fd->ph);
 		if (!desc[i].name)
 			goto out_free;
 
-		if (do_read_u32(fd, ph, &desc[i].leader_idx))
+		if (do_read_u32(fd->fd, fd->ph, &desc[i].leader_idx))
 			goto out_free;
 
-		if (do_read_u32(fd, ph, &desc[i].nr_members))
+		if (do_read_u32(fd->fd, fd->ph, &desc[i].nr_members))
 			goto out_free;
 	}
 
@@ -2011,36 +1994,32 @@ static int process_group_desc(struct perf_file_section *section __maybe_unused,
 	return ret;
 }
 
-static int process_auxtrace(struct perf_file_section *section,
-			    struct perf_header *ph, int fd,
-			    void *data __maybe_unused)
+static int process_auxtrace(struct feat_fd *fd, void *data __maybe_unused)
 {
 	struct perf_session *session;
 	int err;
 
-	session = container_of(ph, struct perf_session, header);
+	session = container_of(fd->ph, struct perf_session, header);
 
-	err = auxtrace_index__process(fd, section->size, session,
-				      ph->needs_swap);
+	err = auxtrace_index__process(fd->fd, fd->size, session,
+				      fd->ph->needs_swap);
 	if (err < 0)
 		pr_err("Failed to process auxtrace index\n");
 	return err;
 }
 
-static int process_cache(struct perf_file_section *section __maybe_unused,
-			 struct perf_header *ph __maybe_unused, int fd __maybe_unused,
-			 void *data __maybe_unused)
+static int process_cache(struct feat_fd *fd, void *data __maybe_unused)
 {
 	struct cpu_cache_level *caches;
 	u32 cnt, i, version;
 
-	if (do_read_u32(fd, ph, &version))
+	if (do_read_u32(fd->fd, fd->ph, &version))
 		return -1;
 
 	if (version != 1)
 		return -1;
 
-	if (do_read_u32(fd, ph, &cnt))
+	if (do_read_u32(fd->fd, fd->ph, &cnt))
 		return -1;
 
 	caches = zalloc(sizeof(*caches) * cnt);
@@ -2051,7 +2030,7 @@ static int process_cache(struct perf_file_section *section __maybe_unused,
 		struct cpu_cache_level c;
 
 		#define _R(v)						\
-			if (do_read_u32(fd, ph, &c.v))\
+			if (do_read_u32(fd->fd, fd->ph, &c.v))\
 				goto out_free_caches;			\
 
 		_R(level)
@@ -2061,7 +2040,7 @@ static int process_cache(struct perf_file_section *section __maybe_unused,
 		#undef _R
 
 		#define _R(v)				\
-			c.v = do_read_string(fd, ph);	\
+			c.v = do_read_string(fd->fd, fd->ph);	\
 			if (!c.v)			\
 				goto out_free_caches;
 
@@ -2073,8 +2052,8 @@ static int process_cache(struct perf_file_section *section __maybe_unused,
 		caches[i] = c;
 	}
 
-	ph->env.caches = caches;
-	ph->env.caches_cnt = cnt;
+	fd->ph->env.caches = caches;
+	fd->ph->env.caches_cnt = cnt;
 	return 0;
 out_free_caches:
 	free(caches);
@@ -2084,8 +2063,7 @@ static int process_cache(struct perf_file_section *section __maybe_unused,
 struct feature_ops {
 	int (*write)(struct feat_fd *fd, struct perf_evlist *evlist);
 	void (*print)(struct feat_fd *fd, FILE *fp);
-	int (*process)(struct perf_file_section *section,
-		       struct perf_header *h, int fd, void *data);
+	int (*process)(struct feat_fd *fd, void *data);
 	const char *name;
 	bool full_only;
 };
@@ -2618,6 +2596,13 @@ static int perf_file_section__process(struct perf_file_section *section,
 				      struct perf_header *ph,
 				      int feat, int fd, void *data)
 {
+	struct feat_fd fdd = {
+		.fd = fd,
+		.ph = ph,
+		.size = section->size,
+		.offset = section->offset,
+	};
+
 	if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) {
 		pr_debug("Failed to lseek to %" PRIu64 " offset for feature "
 			  "%d, continuing...\n", section->offset, feat);
@@ -2632,7 +2617,7 @@ static int perf_file_section__process(struct perf_file_section *section,
 	if (!feat_ops[feat].process)
 		return 0;
 
-	return feat_ops[feat].process(section, ph, fd, data);
+	return feat_ops[feat].process(&fdd, data);
 }
 
 static int perf_file_header__read_pipe(struct perf_pipe_file_header *header,
-- 
2.13.0.219.gdb65acc882-goog

  parent reply	other threads:[~2017-05-23  7:49 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-23  7:48 [PATCH v2 00/13] perf tool: add meta-data header support for pipe-mode David Carrillo-Cisneros
2017-05-23  7:48 ` [PATCH v2 01/13] perf header: encapsulate read and swap David Carrillo-Cisneros
2017-05-24 15:35   ` Namhyung Kim
2017-06-04 23:09     ` David Carrillo-Cisneros
2017-05-25  8:07   ` Jiri Olsa
2017-06-04 23:22     ` David Carrillo-Cisneros
2017-05-23  7:48 ` [PATCH v2 02/13] perf header: add PROCESS_STR_FUN macro David Carrillo-Cisneros
2017-05-23  7:48 ` [PATCH v2 03/13] perf header: fail on write_padded error David Carrillo-Cisneros
2017-05-23  7:48 ` [PATCH v2 04/13] perf util: add const modifier to buf in "writen" function David Carrillo-Cisneros
2017-05-23  7:48 ` [PATCH v2 05/13] perf header: revamp do_write David Carrillo-Cisneros
2017-05-25  8:08   ` Jiri Olsa
2017-06-05  2:25     ` David Carrillo-Cisneros
2017-05-23  7:48 ` [PATCH v2 06/13] perf header: add struct feat_fd for write David Carrillo-Cisneros
2017-05-25  8:07   ` Jiri Olsa
2017-06-05  1:50     ` David Carrillo-Cisneros
2017-05-23  7:48 ` [PATCH v2 07/13] perf header: use struct feat_fd for print David Carrillo-Cisneros
2017-05-25  8:09   ` Jiri Olsa
2017-06-05  2:37     ` David Carrillo-Cisneros
2017-06-05  3:01       ` David Carrillo-Cisneros
2017-05-23  7:48 ` David Carrillo-Cisneros [this message]
2017-05-23  7:48 ` [PATCH v2 09/13] perf header: use struct feat_fd in read header records David Carrillo-Cisneros
2017-05-23  7:48 ` [PATCH v2 10/13] perf header: add a buffer to struct feat_fd David Carrillo-Cisneros
2017-05-25  8:07   ` Jiri Olsa
2017-05-25  8:08   ` Jiri Olsa
2017-05-25  8:09   ` Jiri Olsa
2017-05-25  8:10   ` Jiri Olsa
2017-05-23  7:48 ` [PATCH v2 11/13] perf header: change FEAT_OP* macros David Carrillo-Cisneros
2017-05-25  8:08   ` Jiri Olsa
2017-05-25  8:08   ` Jiri Olsa
2017-06-05  2:13     ` David Carrillo-Cisneros
2017-05-23  7:48 ` [PATCH v2 12/13] perf tool: add show_feature_header to perf_tool David Carrillo-Cisneros
2017-05-23  7:48 ` [PATCH v2 13/13] perf tools: add feature header record to pipe-mode David Carrillo-Cisneros
2017-05-24 15:40   ` Namhyung Kim
2017-05-25  8:08   ` Jiri Olsa
2017-05-25  8:09   ` Jiri Olsa
2017-05-25  8:09   ` Jiri Olsa
2017-05-25  8:09   ` Jiri Olsa
     [not found]     ` <CALcN6mhWWDbnGkDP5unmbB3GPi8+LRoKW8DFAse-KMUy85Fpew@mail.gmail.com>
2017-06-06 11:03       ` Jiri Olsa
2017-05-25  8:09   ` Jiri Olsa
2017-05-25  8:10   ` Jiri Olsa
2017-06-06  1:32     ` David Carrillo-Cisneros
2017-06-06 11:04       ` Jiri Olsa
2017-06-06 18:13         ` David Carrillo-Cisneros

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=20170523074853.54892-9-davidcc@google.com \
    --to=davidcc@google.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dsa@cumulusnetworks.com \
    --cc=eranian@google.com \
    --cc=hekuang@huawei.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=sque@chromium.org \
    --cc=wangnan0@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.