return write_padded(ff, str, olen, len);
}
-static int __do_read(int fd, void *addr, ssize_t size)
+static int __do_read(struct feat_fd *ff, void *addr, ssize_t size)
{
- ssize_t ret = readn(fd, addr, size);
+ ssize_t ret = readn(ff->fd, addr, size);
if (ret != 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 *ff, u32 *addr)
{
int ret;
- ret = __do_read(fd, addr, sizeof(*addr));
+ ret = __do_read(ff, addr, sizeof(*addr));
if (ret)
return ret;
- if (ph->needs_swap)
+ if (ff->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 *ff, u64 *addr)
{
int ret;
- ret = __do_read(fd, addr, sizeof(*addr));
+ ret = __do_read(ff, addr, sizeof(*addr));
if (ret)
return ret;
- if (ph->needs_swap)
+ if (ff->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 *ff)
{
u32 len;
char *buf;
- if (do_read_u32(fd, ph, &len))
+ if (do_read_u32(ff, &len))
return NULL;
buf = malloc(len);
if (!buf)
return NULL;
- if (!__do_read(fd, buf, len)) {
+ if (!__do_read(ff, buf, len)) {
/*
* strings are padded by zeroes
* thus the actual strlen of buf
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 *ff)
{
struct perf_evsel *evsel, *events = NULL;
u64 *id;
size_t msz;
/* number of events */
- if (do_read_u32(fd, ph, &nre))
+ if (do_read_u32(ff, &nre))
goto error;
- if (do_read_u32(fd, ph, &sz))
+ if (do_read_u32(ff, &sz))
goto error;
/* buffer to hold on file attr struct */
* must read entire on-file attr struct to
* sync up with layout.
*/
- if (__do_read(fd, buf, sz))
+ if (__do_read(ff, buf, sz))
goto error;
- if (ph->needs_swap)
+ if (ff->ph->needs_swap)
perf_event__attr_swap(buf);
memcpy(&evsel->attr, buf, msz);
- if (do_read_u32(fd, ph, &nr))
+ if (do_read_u32(ff, &nr))
goto error;
- if (ph->needs_swap)
+ if (ff->ph->needs_swap)
evsel->needs_swap = true;
- evsel->name = do_read_string(fd, ph);
+ evsel->name = do_read_string(ff);
if (!evsel->name)
goto error;
evsel->id = id;
for (j = 0 ; j < nr; j++) {
- if (do_read_u64(fd, ph, id))
+ if (do_read_u64(ff, id))
goto error;
id++;
}
static void print_event_desc(struct feat_fd *ff, FILE *fp)
{
- struct perf_evsel *evsel, *events = read_event_desc(ff->ph, ff->fd);
+ struct perf_evsel *evsel, *events = read_event_desc(ff);
u32 j;
u64 *id;
#define FEAT_PROCESS_STR_FUN(__feat, __feat_env) \
static int process_##__feat(struct feat_fd *ff, void *data __maybe_unused) \
{\
- ff->ph->env.__feat_env = do_read_string(ff->fd, ff->ph); \
+ ff->ph->env.__feat_env = do_read_string(ff); \
return ff->ph->env.__feat_env ? 0 : -ENOMEM; \
}
int ret;
u32 nr_cpus_avail, nr_cpus_online;
- ret = do_read_u32(ff->fd, ff->ph, &nr_cpus_avail);
+ ret = do_read_u32(ff, &nr_cpus_avail);
if (ret)
return ret;
- ret = do_read_u32(ff->fd, ff->ph, &nr_cpus_online);
+ ret = do_read_u32(ff, &nr_cpus_online);
if (ret)
return ret;
ff->ph->env.nr_cpus_avail = (int)nr_cpus_avail;
u64 total_mem;
int ret;
- ret = do_read_u64(ff->fd, ff->ph, &total_mem);
+ ret = do_read_u64(ff, &total_mem);
if (ret)
return -1;
ff->ph->env.total_mem = (unsigned long long)total_mem;
process_event_desc(struct feat_fd *ff, void *data __maybe_unused)
{
struct perf_session *session;
- struct perf_evsel *evsel, *events = read_event_desc(ff->ph, ff->fd);
+ struct perf_evsel *evsel, *events = read_event_desc(ff);
if (!events)
return 0;
char *str, *cmdline = NULL, **argv = NULL;
u32 nr, i, len = 0;
- if (do_read_u32(ff->fd, ff->ph, &nr))
+ if (do_read_u32(ff, &nr))
return -1;
ff->ph->env.nr_cmdline = nr;
goto error;
for (i = 0; i < nr; i++) {
- str = do_read_string(ff->fd, ff->ph);
+ str = do_read_string(ff);
if (!str)
goto error;
if (!ph->env.cpu)
return -1;
- if (do_read_u32(ff->fd, ph, &nr))
+ if (do_read_u32(ff, &nr))
goto free_cpu;
ph->env.nr_sibling_cores = nr;
goto free_cpu;
for (i = 0; i < nr; i++) {
- str = do_read_string(ff->fd, ph);
+ str = do_read_string(ff);
if (!str)
goto error;
}
ph->env.sibling_cores = strbuf_detach(&sb, NULL);
- if (do_read_u32(ff->fd, ph, &nr))
+ if (do_read_u32(ff, &nr))
return -1;
ph->env.nr_sibling_threads = nr;
size += sizeof(u32);
for (i = 0; i < nr; i++) {
- str = do_read_string(ff->fd, ph);
+ str = do_read_string(ff);
if (!str)
goto error;
}
for (i = 0; i < (u32)cpu_nr; i++) {
- if (do_read_u32(ff->fd, ph, &nr))
+ if (do_read_u32(ff, &nr))
goto free_cpu;
ph->env.cpu[i].core_id = nr;
- if (do_read_u32(ff->fd, ph, &nr))
+ if (do_read_u32(ff, &nr))
goto free_cpu;
if (nr != (u32)-1 && nr > (u32)cpu_nr) {
char *str;
/* nr nodes */
- if (do_read_u32(ff->fd, ff->ph, &nr))
+ if (do_read_u32(ff, &nr))
return -1;
nodes = zalloc(sizeof(*nodes) * nr);
n = &nodes[i];
/* node number */
- if (do_read_u32(ff->fd, ff->ph, &n->node))
+ if (do_read_u32(ff, &n->node))
goto error;
- if (do_read_u64(ff->fd, ff->ph, &n->mem_total))
+ if (do_read_u64(ff, &n->mem_total))
goto error;
- if (do_read_u64(ff->fd, ff->ph, &n->mem_free))
+ if (do_read_u64(ff, &n->mem_free))
goto error;
- str = do_read_string(ff->fd, ff->ph);
+ str = do_read_string(ff);
if (!str)
goto error;
u32 type;
struct strbuf sb;
- if (do_read_u32(ff->fd, ff->ph, &pmu_num))
+ if (do_read_u32(ff, &pmu_num))
return -1;
if (!pmu_num) {
return -1;
while (pmu_num) {
- if (do_read_u32(ff->fd, ff->ph, &type))
+ if (do_read_u32(ff, &type))
goto error;
- name = do_read_string(ff->fd, ff->ph);
+ name = do_read_string(ff);
if (!name)
goto error;
u32 nr_members;
} *desc;
- if (do_read_u32(ff->fd, ff->ph, &nr_groups))
+ if (do_read_u32(ff, &nr_groups))
return -1;
ff->ph->env.nr_groups = nr_groups;
return -1;
for (i = 0; i < nr_groups; i++) {
- desc[i].name = do_read_string(ff->fd, ff->ph);
+ desc[i].name = do_read_string(ff);
if (!desc[i].name)
goto out_free;
- if (do_read_u32(ff->fd, ff->ph, &desc[i].leader_idx))
+ if (do_read_u32(ff, &desc[i].leader_idx))
goto out_free;
- if (do_read_u32(ff->fd, ff->ph, &desc[i].nr_members))
+ if (do_read_u32(ff, &desc[i].nr_members))
goto out_free;
}
struct cpu_cache_level *caches;
u32 cnt, i, version;
- if (do_read_u32(ff->fd, ff->ph, &version))
+ if (do_read_u32(ff, &version))
return -1;
if (version != 1)
return -1;
- if (do_read_u32(ff->fd, ff->ph, &cnt))
+ if (do_read_u32(ff, &cnt))
return -1;
caches = zalloc(sizeof(*caches) * cnt);
struct cpu_cache_level c;
#define _R(v) \
- if (do_read_u32(ff->fd, ff->ph, &c.v))\
+ if (do_read_u32(ff, &c.v))\
goto out_free_caches; \
_R(level)
#undef _R
#define _R(v) \
- c.v = do_read_string(ff->fd, ff->ph); \
+ c.v = do_read_string(ff); \
if (!c.v) \
goto out_free_caches;