[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170523074853.54892-10-davidcc@google.com>
Date: Tue, 23 May 2017 00:48:49 -0700
From: David Carrillo-Cisneros <davidcc@...gle.com>
To: linux-kernel@...r.kernel.org
Cc: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Andi Kleen <ak@...ux.intel.com>, Simon Que <sque@...omium.org>,
Wang Nan <wangnan0@...wei.com>, Jiri Olsa <jolsa@...nel.org>,
He Kuang <hekuang@...wei.com>,
Masami Hiramatsu <mhiramat@...nel.org>,
David Ahern <dsa@...ulusnetworks.com>,
Namhyung Kim <namhyung@...nel.org>,
Stephane Eranian <eranian@...gle.com>,
Paul Turner <pjt@...gle.com>,
David Carrillo-Cisneros <davidcc@...gle.com>
Subject: [PATCH v2 09/13] perf header: use struct feat_fd in read header records
As preparation for using header records in-pipe mode, replace
int fd with struct feat_fd in read functions for all header
record types.
This patch does not change behavior.
Signed-off-by: David Carrillo-Cisneros <davidcc@...gle.com>
---
tools/perf/util/header.c | 93 ++++++++++++++++++++++++------------------------
1 file changed, 46 insertions(+), 47 deletions(-)
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index dc923f5639f8..65cd2d1f1721 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -124,16 +124,16 @@ static int do_write_string(struct feat_fd *fd, const char *str)
return write_padded(fd, str, olen, len);
}
-static int __do_read(int fd, void *addr, ssize_t size)
+static int __do_read(struct feat_fd *fd, void *addr, ssize_t size)
{
- ssize_t ret = readn(fd, addr, size);
+ ssize_t ret = readn(fd->fd, addr, size);
if (ret != (ssize_t)size)
return ret < 0 ? (int)ret : -1;
return 0;
}
-static int do_read_u32(int fd, struct perf_header *ph, u32 *addr)
+static int do_read_u32(struct feat_fd *fd, u32 *addr)
{
int ret;
@@ -141,12 +141,12 @@ static int do_read_u32(int fd, struct perf_header *ph, u32 *addr)
if (ret)
return ret;
- if (ph->needs_swap)
+ if (fd->ph->needs_swap)
*addr = bswap_32(*addr);
return 0;
}
-static int do_read_u64(int fd, struct perf_header *ph, u64 *addr)
+static int do_read_u64(struct feat_fd *fd, u64 *addr)
{
int ret;
@@ -154,17 +154,17 @@ static int do_read_u64(int fd, struct perf_header *ph, u64 *addr)
if (ret)
return ret;
- if (ph->needs_swap)
+ if (fd->ph->needs_swap)
*addr = bswap_64(*addr);
return 0;
}
-static char *do_read_string(int fd, struct perf_header *ph)
+static char *do_read_string(struct feat_fd *fd)
{
u32 len;
char *buf;
- if (do_read_u32(fd, ph, &len))
+ if (do_read_u32(fd, &len))
return NULL;
buf = malloc(len);
@@ -1206,8 +1206,7 @@ static void free_event_desc(struct perf_evsel *events)
free(events);
}
-static struct perf_evsel *
-read_event_desc(struct perf_header *ph, int fd)
+static struct perf_evsel *read_event_desc(struct feat_fd *fd)
{
struct perf_evsel *evsel, *events = NULL;
u64 *id;
@@ -1217,10 +1216,10 @@ read_event_desc(struct perf_header *ph, int fd)
size_t msz;
/* number of events */
- if (do_read_u32(fd, ph, &nre))
+ if (do_read_u32(fd, &nre))
goto error;
- if (do_read_u32(fd, ph, &sz))
+ if (do_read_u32(fd, &sz))
goto error;
/* buffer to hold on file attr struct */
@@ -1248,18 +1247,18 @@ read_event_desc(struct perf_header *ph, int fd)
if (ret != (ssize_t)sz)
goto error;
- if (ph->needs_swap)
+ if (fd->ph->needs_swap)
perf_event__attr_swap(buf);
memcpy(&evsel->attr, buf, msz);
- if (do_read_u32(fd, ph, &nr))
+ if (do_read_u32(fd, &nr))
goto error;
- if (ph->needs_swap)
+ if (fd->ph->needs_swap)
evsel->needs_swap = true;
- evsel->name = do_read_string(fd, ph);
+ evsel->name = do_read_string(fd);
if (!nr)
continue;
@@ -1271,7 +1270,7 @@ read_event_desc(struct perf_header *ph, int fd)
evsel->id = id;
for (j = 0 ; j < nr; j++) {
- if (do_read_u64(fd, ph, id))
+ if (do_read_u64(fd, id))
goto error;
id++;
}
@@ -1293,7 +1292,7 @@ static int __desc_attr__fprintf(FILE *fp, const char *name, const char *val,
static void print_event_desc(struct feat_fd *fd, FILE *fp)
{
- struct perf_evsel *evsel, *events = read_event_desc(fd->ph, fd->fd);
+ struct perf_evsel *evsel, *events = read_event_desc(fd);
u32 j;
u64 *id;
@@ -1587,7 +1586,7 @@ static int perf_header__read_build_ids(struct perf_header *header,
#define FEAT_PROCESS_STR_FUN(__feat, __feat_env) \
static int process_##__feat(struct feat_fd *fd, void *data __maybe_unused) \
{\
- fd->ph->env.__feat_env = do_read_string(fd->fd, fd->ph); \
+ fd->ph->env.__feat_env = do_read_string(fd); \
return fd->ph->env.__feat_env ? 0 : -ENOMEM; \
}
@@ -1617,11 +1616,11 @@ 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->fd, fd->ph, &nr_cpus_avail);
+ ret = do_read_u32(fd, &nr_cpus_avail);
if (ret)
return ret;
- ret = do_read_u32(fd->fd, fd->ph, &nr_cpus_online);
+ ret = do_read_u32(fd, &nr_cpus_online);
if (ret)
return ret;
fd->ph->env.nr_cpus_avail = (int)nr_cpus_avail;
@@ -1634,7 +1633,7 @@ static int process_total_mem(struct feat_fd *fd, void *data __maybe_unused)
u64 total_mem;
int ret;
- ret = do_read_u64(fd->fd, fd->ph, &total_mem);
+ ret = do_read_u64(fd, &total_mem);
if (ret)
return -1;
fd->ph->env.total_mem = (unsigned long long)total_mem;
@@ -1677,7 +1676,7 @@ static int
process_event_desc(struct feat_fd *fd, void *data __maybe_unused)
{
struct perf_session *session;
- struct perf_evsel *evsel, *events = read_event_desc(fd->ph, fd->fd);
+ struct perf_evsel *evsel, *events = read_event_desc(fd);
if (!events)
return 0;
@@ -1696,7 +1695,7 @@ 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->fd, fd->ph, &nr))
+ if (do_read_u32(fd, &nr))
return -1;
fd->ph->env.nr_cmdline = nr;
@@ -1710,7 +1709,7 @@ static int process_cmdline(struct feat_fd *fd, void *data __maybe_unused)
goto error;
for (i = 0; i < nr; i++) {
- str = do_read_string(fd->fd, fd->ph);
+ str = do_read_string(fd);
if (!str)
goto error;
@@ -1742,7 +1741,7 @@ static int process_cpu_topology(struct feat_fd *fd, void *data __maybe_unused)
if (!ph->env.cpu)
return -1;
- if (do_read_u32(fd->fd, fd->ph, &nr))
+ if (do_read_u32(fd, &nr))
goto free_cpu;
ph->env.nr_sibling_cores = nr;
@@ -1750,7 +1749,7 @@ static int process_cpu_topology(struct feat_fd *fd, void *data __maybe_unused)
goto free_cpu;
for (i = 0; i < nr; i++) {
- str = do_read_string(fd->fd, fd->ph);
+ str = do_read_string(fd);
if (!str)
goto error;
@@ -1761,13 +1760,13 @@ static int process_cpu_topology(struct feat_fd *fd, void *data __maybe_unused)
}
ph->env.sibling_cores = strbuf_detach(&sb, NULL);
- if (do_read_u32(fd->fd, fd->ph, &nr))
+ if (do_read_u32(fd, &nr))
return -1;
ph->env.nr_sibling_threads = nr;
for (i = 0; i < nr; i++) {
- str = do_read_string(fd->fd, fd->ph);
+ str = do_read_string(fd);
if (!str)
goto error;
@@ -1788,12 +1787,12 @@ static int process_cpu_topology(struct feat_fd *fd, void *data __maybe_unused)
}
for (i = 0; i < (u32)cpu_nr; i++) {
- if (do_read_u32(fd->fd, fd->ph, &nr))
+ if (do_read_u32(fd, &nr))
goto free_cpu;
ph->env.cpu[i].core_id = nr;
- if (do_read_u32(fd->fd, fd->ph, &nr))
+ if (do_read_u32(fd, &nr))
goto free_cpu;
if (nr != (u32)-1 && nr > (u32)cpu_nr) {
@@ -1822,7 +1821,7 @@ static int process_numa_topology(struct feat_fd *fd, void *data __maybe_unused)
char *str;
/* nr nodes */
- if (do_read_u32(fd->fd, fd->ph, &nr))
+ if (do_read_u32(fd, &nr))
return -1;
nodes = zalloc(sizeof(*nodes) * nr);
@@ -1833,16 +1832,16 @@ static int process_numa_topology(struct feat_fd *fd, void *data __maybe_unused)
n = &nodes[i];
/* node number */
- if (do_read_u32(fd->fd, fd->ph, &n->node))
+ if (do_read_u32(fd, &n->node))
goto error;
- if (do_read_u64(fd->fd, fd->ph, &n->mem_total))
+ if (do_read_u64(fd, &n->mem_total))
goto error;
- if (do_read_u64(fd->fd, fd->ph, &n->mem_free))
+ if (do_read_u64(fd, &n->mem_free))
goto error;
- str = do_read_string(fd->fd, fd->ph);
+ str = do_read_string(fd);
if (!str)
goto error;
@@ -1869,7 +1868,7 @@ static int process_pmu_mappings(struct feat_fd *fd, void *data __maybe_unused)
u32 type;
struct strbuf sb;
- if (do_read_u32(fd->fd, fd->ph, &pmu_num))
+ if (do_read_u32(fd, &pmu_num))
return -1;
if (!pmu_num) {
@@ -1882,10 +1881,10 @@ static int process_pmu_mappings(struct feat_fd *fd, void *data __maybe_unused)
return -1;
while (pmu_num) {
- if (do_read_u32(fd->fd, fd->ph, &type))
+ if (do_read_u32(fd, &type))
goto error;
- name = do_read_string(fd->fd, fd->ph);
+ name = do_read_string(fd);
if (!name)
goto error;
@@ -1922,7 +1921,7 @@ static int process_group_desc(struct feat_fd *fd, void *data __maybe_unused)
u32 nr_members;
} *desc;
- if (do_read_u32(fd->fd, fd->ph, &nr_groups))
+ if (do_read_u32(fd, &nr_groups))
return -1;
ph->env.nr_groups = nr_groups;
@@ -1936,14 +1935,14 @@ static int process_group_desc(struct feat_fd *fd, void *data __maybe_unused)
return -1;
for (i = 0; i < nr_groups; i++) {
- desc[i].name = do_read_string(fd->fd, fd->ph);
+ desc[i].name = do_read_string(fd);
if (!desc[i].name)
goto out_free;
- if (do_read_u32(fd->fd, fd->ph, &desc[i].leader_idx))
+ if (do_read_u32(fd, &desc[i].leader_idx))
goto out_free;
- if (do_read_u32(fd->fd, fd->ph, &desc[i].nr_members))
+ if (do_read_u32(fd, &desc[i].nr_members))
goto out_free;
}
@@ -2013,13 +2012,13 @@ 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->fd, fd->ph, &version))
+ if (do_read_u32(fd, &version))
return -1;
if (version != 1)
return -1;
- if (do_read_u32(fd->fd, fd->ph, &cnt))
+ if (do_read_u32(fd, &cnt))
return -1;
caches = zalloc(sizeof(*caches) * cnt);
@@ -2030,7 +2029,7 @@ static int process_cache(struct feat_fd *fd, void *data __maybe_unused)
struct cpu_cache_level c;
#define _R(v) \
- if (do_read_u32(fd->fd, fd->ph, &c.v))\
+ if (do_read_u32(fd, &c.v))\
goto out_free_caches; \
_R(level)
@@ -2040,7 +2039,7 @@ static int process_cache(struct feat_fd *fd, void *data __maybe_unused)
#undef _R
#define _R(v) \
- c.v = do_read_string(fd->fd, fd->ph); \
+ c.v = do_read_string(fd); \
if (!c.v) \
goto out_free_caches;
--
2.13.0.219.gdb65acc882-goog
Powered by blists - more mailing lists