Re: [PATCH v3 08/15] perf header: use struct feat_fd to process header records

Jiri Olsa
2017-06-08T11:54:44Z

On Tue, Jun 06, 2017 at 12:07:15AM -0700, David Carrillo-Cisneros wrote:

SNIP

> +static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused)
> {
> u32 nr, i;
> char *str;
> struct strbuf sb;
> - int cpu_nr = ph->env.nr_cpus_avail;
> + int cpu_nr = ff->ph->env.nr_cpus_avail;
> u64 size = 0;
> + struct perf_header *ph = ff->ph;
> + u64 start_offset = ff->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(ff->fd, ff->ph, &nr))
> goto free_cpu;
>
> ph->env.nr_sibling_cores = nr;
> @@ -1764,7 +1753,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(ff->fd, ff->ph);
> if (!str)
> goto error;
>
> @@ -1776,14 +1765,14 @@ 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(ff->fd, ff->ph, &nr))
> return -1;
>
> ph->env.nr_sibling_threads = nr;
> size += sizeof(u32);
>
> for (i = 0; i < nr; i++) {
> - str = do_read_string(fd, ph);
> + str = do_read_string(ff->fd, ff->ph);
> if (!str)
> goto error;
>
> @@ -1799,18 +1788,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 (ff->size <= ff->offset - start_offset) {

I'm lost here? how is ff->offset incremented? what's 'size' good for now?

thanks,
jirka