Re: [PATCH v5 perf,bpf 09/15] perf, bpf: save btf information as headers to perf.data

From: Jiri Olsa
Date: Mon Mar 04 2019 - 08:52:23 EST


On Wed, Feb 27, 2019 at 09:06:37PM -0800, Song Liu wrote:

SNIP

>
> +static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused)
> +{
> + struct perf_env *env = &ff->ph->env;
> + u32 count, i;
> +
> + if (do_read_u32(ff, &count))
> + return -1;
> +
> + down_write(&env->bpf_progs.lock);
> +
> + for (i = 0; i < count; ++i) {
> + struct btf_node *node;
> + u32 id, data_size;
> +
> + if (do_read_u32(ff, &id))
> + return -1;
> + if (do_read_u32(ff, &data_size))
> + return -1;
> +
> + node = malloc(sizeof(struct btf_node) + data_size);
> + if (!node)
> + return -1;
> +
> + node->id = id;
> + node->data_size = data_size;
> +
> + if (__do_read(ff, node->data, data_size)) {
> + free(node);
> + return -1;
> + }
> +
> + /* endian mismatch, drop the btf, continue */
> + if (ff->ph->needs_swap) {
> + free(node);
> + continue;
> + }

again, we can check for needs_swap in the begining,
display warning and skip the loop in here

perhaps we should warn just once for all the bpf data
missed when needs_swap is set

jirka