bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Hao Luo <haoluo@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
	dwarves@vger.kernel.org, bpf <bpf@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andriin@fb.com>, Yonghong Song <yhs@fb.com>,
	"Frank Ch. Eigler" <fche@redhat.com>,
	Mark Wielaard <mjw@redhat.com>
Subject: Re: [PATCH 1/2] btf_encoder: Move find_all_percpu_vars in generic collect_symbols
Date: Tue, 3 Nov 2020 14:31:12 -0300	[thread overview]
Message-ID: <20201103173112.GI151027@kernel.org> (raw)
In-Reply-To: <CA+khW7hRm4xwKKDjdoJkaQADfjANCzy9hpp-xL_T-Two3oNAfA@mail.gmail.com>

Em Mon, Nov 02, 2020 at 10:29:22AM -0800, Hao Luo escreveu:
> This looks good to me. Thanks, Jiri.
> 
> Acked-by: Hao Luo <haoluo@google.com>

Thanks, applied, will wait for a v2 for the other.
 
> On Sat, Oct 31, 2020 at 3:31 PM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > Moving find_all_percpu_vars under generic collect_symbols
> > function that walks over symbols and calls collect_percpu_var.
> >
> > We will add another collect function that needs to go through
> > all the symbols, so it's better we go through them just once.
> >
> > There's no functional change intended.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  btf_encoder.c | 124 +++++++++++++++++++++++++++-----------------------
> >  1 file changed, 67 insertions(+), 57 deletions(-)
> >
> > diff --git a/btf_encoder.c b/btf_encoder.c
> > index 4c92908beab2..1866bb16a8ba 100644
> > --- a/btf_encoder.c
> > +++ b/btf_encoder.c
> > @@ -250,75 +250,85 @@ static bool percpu_var_exists(uint64_t addr, uint32_t *sz, const char **name)
> >         return true;
> >  }
> >
> > -static int find_all_percpu_vars(struct btf_elf *btfe)
> > +static int collect_percpu_var(struct btf_elf *btfe, GElf_Sym *sym)
> >  {
> > -       uint32_t core_id;
> > -       GElf_Sym sym;
> > +       const char *sym_name;
> > +       uint64_t addr;
> > +       uint32_t size;
> >
> > -       /* cache variables' addresses, preparing for searching in symtab. */
> > -       percpu_var_cnt = 0;
> > +       /* compare a symbol's shndx to determine if it's a percpu variable */
> > +       if (elf_sym__section(sym) != btfe->percpu_shndx)
> > +               return 0;
> > +       if (elf_sym__type(sym) != STT_OBJECT)
> > +               return 0;
> >
> > -       /* search within symtab for percpu variables */
> > -       elf_symtab__for_each_symbol(btfe->symtab, core_id, sym) {
> > -               const char *sym_name;
> > -               uint64_t addr;
> > -               uint32_t size;
> > +       addr = elf_sym__value(sym);
> > +       /*
> > +        * Store only those symbols that have allocated space in the percpu section.
> > +        * This excludes the following three types of symbols:
> > +        *
> > +        *  1. __ADDRESSABLE(sym), which are forcely emitted as symbols.
> > +        *  2. __UNIQUE_ID(prefix), which are introduced to generate unique ids.
> > +        *  3. __exitcall(fn), functions which are labeled as exit calls.
> > +        *
> > +        * In addition, the variables defined using DEFINE_PERCPU_FIRST are
> > +        * also not included, which currently includes:
> > +        *
> > +        *  1. fixed_percpu_data
> > +        */
> > +       if (!addr)
> > +               return 0;
> >
> > -               /* compare a symbol's shndx to determine if it's a percpu variable */
> > -               if (elf_sym__section(&sym) != btfe->percpu_shndx)
> > -                       continue;
> > -               if (elf_sym__type(&sym) != STT_OBJECT)
> > -                       continue;
> > +       size = elf_sym__size(sym);
> > +       if (!size)
> > +               return 0; /* ignore zero-sized symbols */
> >
> > -               addr = elf_sym__value(&sym);
> > -               /*
> > -                * Store only those symbols that have allocated space in the percpu section.
> > -                * This excludes the following three types of symbols:
> > -                *
> > -                *  1. __ADDRESSABLE(sym), which are forcely emitted as symbols.
> > -                *  2. __UNIQUE_ID(prefix), which are introduced to generate unique ids.
> > -                *  3. __exitcall(fn), functions which are labeled as exit calls.
> > -                *
> > -                * In addition, the variables defined using DEFINE_PERCPU_FIRST are
> > -                * also not included, which currently includes:
> > -                *
> > -                *  1. fixed_percpu_data
> > -                */
> > -               if (!addr)
> > -                       continue;
> > +       sym_name = elf_sym__name(sym, btfe->symtab);
> > +       if (!btf_name_valid(sym_name)) {
> > +               dump_invalid_symbol("Found symbol of invalid name when encoding btf",
> > +                                   sym_name, btf_elf__verbose, btf_elf__force);
> > +               if (btf_elf__force)
> > +                       return 0;
> > +               return -1;
> > +       }
> >
> > -               size = elf_sym__size(&sym);
> > -               if (!size)
> > -                       continue; /* ignore zero-sized symbols */
> > +       if (btf_elf__verbose)
> > +               printf("Found per-CPU symbol '%s' at address 0x%lx\n", sym_name, addr);
> >
> > -               sym_name = elf_sym__name(&sym, btfe->symtab);
> > -               if (!btf_name_valid(sym_name)) {
> > -                       dump_invalid_symbol("Found symbol of invalid name when encoding btf",
> > -                                           sym_name, btf_elf__verbose, btf_elf__force);
> > -                       if (btf_elf__force)
> > -                               continue;
> > -                       return -1;
> > -               }
> > +       if (percpu_var_cnt == MAX_PERCPU_VAR_CNT) {
> > +               fprintf(stderr, "Reached the limit of per-CPU variables: %d\n",
> > +                       MAX_PERCPU_VAR_CNT);
> > +               return -1;
> > +       }
> > +       percpu_vars[percpu_var_cnt].addr = addr;
> > +       percpu_vars[percpu_var_cnt].sz = size;
> > +       percpu_vars[percpu_var_cnt].name = sym_name;
> > +       percpu_var_cnt++;
> >
> > -               if (btf_elf__verbose)
> > -                       printf("Found per-CPU symbol '%s' at address 0x%lx\n", sym_name, addr);
> > +       return 0;
> > +}
> > +
> > +static int collect_symbols(struct btf_elf *btfe, bool collect_percpu_vars)
> > +{
> > +       uint32_t core_id;
> > +       GElf_Sym sym;
> >
> > -               if (percpu_var_cnt == MAX_PERCPU_VAR_CNT) {
> > -                       fprintf(stderr, "Reached the limit of per-CPU variables: %d\n",
> > -                               MAX_PERCPU_VAR_CNT);
> > +       /* cache variables' addresses, preparing for searching in symtab. */
> > +       percpu_var_cnt = 0;
> > +
> > +       /* search within symtab for percpu variables */
> > +       elf_symtab__for_each_symbol(btfe->symtab, core_id, sym) {
> > +               if (collect_percpu_vars && collect_percpu_var(btfe, &sym))
> >                         return -1;
> > -               }
> > -               percpu_vars[percpu_var_cnt].addr = addr;
> > -               percpu_vars[percpu_var_cnt].sz = size;
> > -               percpu_vars[percpu_var_cnt].name = sym_name;
> > -               percpu_var_cnt++;
> >         }
> >
> > -       if (percpu_var_cnt)
> > -               qsort(percpu_vars, percpu_var_cnt, sizeof(percpu_vars[0]), percpu_var_cmp);
> > +       if (collect_percpu_vars) {
> > +               if (percpu_var_cnt)
> > +                       qsort(percpu_vars, percpu_var_cnt, sizeof(percpu_vars[0]), percpu_var_cmp);
> >
> > -       if (btf_elf__verbose)
> > -               printf("Found %d per-CPU variables!\n", percpu_var_cnt);
> > +               if (btf_elf__verbose)
> > +                       printf("Found %d per-CPU variables!\n", percpu_var_cnt);
> > +       }
> >         return 0;
> >  }
> >
> > @@ -347,7 +357,7 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force,
> >                 if (!btfe)
> >                         return -1;
> >
> > -               if (!skip_encoding_vars && find_all_percpu_vars(btfe))
> > +               if (collect_symbols(btfe, !skip_encoding_vars))
> >                         goto out;
> >
> >                 has_index_type = false;
> > --
> > 2.26.2
> >

-- 

- Arnaldo

  reply	other threads:[~2020-11-03 17:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-31 22:31 [PATCHv2 0/2] pahole: Workaround dwarf bug for function encoding Jiri Olsa
2020-10-31 22:31 ` [PATCH 1/2] btf_encoder: Move find_all_percpu_vars in generic collect_symbols Jiri Olsa
2020-11-02 18:29   ` Hao Luo
2020-11-03 17:31     ` Arnaldo Carvalho de Melo [this message]
2020-10-31 22:31 ` [PATCH 2/2] btf_encoder: Change functions check due to broken dwarf Jiri Olsa
2020-11-02 21:59   ` Jiri Olsa
2020-11-02 22:56     ` Jiri Olsa
2020-11-03 18:58       ` Andrii Nakryiko
2020-11-03 19:05         ` Jiri Olsa
2020-11-03 19:23           ` Andrii Nakryiko
2020-11-03 19:34             ` Jiri Olsa
2020-11-03 20:27             ` Yonghong Song
2020-11-03 23:18               ` Jiri Olsa
2020-11-03 18:55   ` Andrii Nakryiko
2020-11-03 23:22     ` Jiri Olsa

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=20201103173112.GI151027@kernel.org \
    --to=acme@kernel.org \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dwarves@vger.kernel.org \
    --cc=fche@redhat.com \
    --cc=haoluo@google.com \
    --cc=jolsa@kernel.org \
    --cc=mjw@redhat.com \
    --cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).