Commit Graph

37 Commits

Author SHA1 Message Date
Kui-Feng Lee 1bc98ed290 btf_encoder: Collect info of per-cpu variables from threads
Collect the information of per-cpu variables from encoders of worker
threads to the primary encoder.

btf_encoder store per-cpu info separately, not in BTF.  Previously, it
merged only BTF types generated by worker threads.  So some of the
per-cpu info was missing.

Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
Tested-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: dwarves@vger.kernel.org
Link: https://lore.kernel.org/r/20220321230837.855572-1-kuifeng@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-03-26 12:04:40 -03:00
Kui-Feng Lee 2135275318 pahole: Use per-thread btf instances to avoid mutex locking
Create an instance of btf for each worker thread, and add type info to
the local btf instance in the steal-function of pahole without mutex
acquiring.  Once finished with all worker threads, merge all
per-thread btf instances to the primary btf instance.

Committer testing:

Results with no multithreading, and without further DWARF loading
improvements (not loading things that won't be converted to BTF, etc),
i.e. using pahole 1.21:

  # perf stat -r5 pahole --btf_encode /tmp/vmlinux ; btfdiff /tmp/vmlinux

   Performance counter stats for 'pahole --btf_encode /tmp/vmlinux' (5 runs):

            6,317.41 msec task-clock                #    0.985 CPUs utilized            ( +-  1.07% )
                  80      context-switches          #   12.478 /sec                     ( +- 15.25% )
                   1      cpu-migrations            #    0.156 /sec                     ( +-111.36% )
             535,890      page-faults               #   83.585 K/sec                    ( +-  0.00% )
      29,789,308,790      cycles                    #    4.646 GHz                      ( +-  0.46% )  (83.33%)
          97,696,165      stalled-cycles-frontend   #    0.33% frontend cycles idle     ( +-  4.05% )  (83.34%)
         145,554,652      stalled-cycles-backend    #    0.49% backend cycles idle      ( +- 21.53% )  (83.33%)
      78,215,192,264      instructions              #    2.61  insn per cycle
                                                    #    0.00  stalled cycles per insn  ( +-  0.05% )  (83.33%)
      18,141,376,637      branches                  #    2.830 G/sec                    ( +-  0.06% )  (83.33%)
         148,826,657      branch-misses             #    0.82% of all branches          ( +-  0.65% )  (83.34%)

              6.4129 +- 0.0682 seconds time elapsed  ( +-  1.06% )

  #

Now with pahole 1.23, with just parallel DWARF loading + trimmed DWARF
loading (skipping DWARF tags that won't be converted to BTF, etc):

  $ perf stat -r5 pahole -j --btf_encode /tmp/vmlinux

   Performance counter stats for 'pahole -j --btf_encode /tmp/vmlinux' (5 runs):

           10,828.98 msec task-clock:u              #    3.539 CPUs utilized            ( +-  0.94% )
                   0      context-switches:u        #    0.000 /sec
                   0      cpu-migrations:u          #    0.000 /sec
             105,407      page-faults:u             #    9.895 K/sec                    ( +-  0.15% )
      24,774,029,571      cycles:u                  #    2.326 GHz                      ( +-  0.50% )  (83.49%)
          76,895,232      stalled-cycles-frontend:u #    0.31% frontend cycles idle     ( +-  4.84% )  (83.50%)
          24,821,768      stalled-cycles-backend:u  #    0.10% backend cycles idle      ( +-  3.66% )  (83.11%)
      69,891,360,588      instructions:u            #    2.83  insn per cycle
                                                    #    0.00  stalled cycles per insn  ( +-  0.10% )  (83.20%)
      16,966,456,889      branches:u                #    1.593 G/sec                    ( +-  0.21% )  (83.41%)
         131,923,443      branch-misses:u           #    0.78% of all branches          ( +-  0.82% )  (83.42%)

              3.0600 +- 0.0140 seconds time elapsed  ( +-  0.46% )

  $

It is a bit better not to use -j to use all the CPU threads in the
machine, i.e. using just the number of non-hyperthreading cores, in this
machine, a Ryzen 5950x, 16 cores:

  $ perf stat -r5 pahole -j16 --btf_encode /tmp/vmlinux

   Performance counter stats for 'pahole -j16 --btf_encode /tmp/vmlinux' (5 runs):

           10,075.46 msec task-clock:u              #    3.431 CPUs utilized            ( +-  0.49% )
                   0      context-switches:u        #    0.000 /sec
                   0      cpu-migrations:u          #    0.000 /sec
              90,777      page-faults:u             #    8.983 K/sec                    ( +-  0.16% )
      22,611,016,624      cycles:u                  #    2.237 GHz                      ( +-  0.93% )  (83.34%)
          55,760,536      stalled-cycles-frontend:u #    0.24% frontend cycles idle     ( +-  2.35% )  (83.25%)
          15,985,651      stalled-cycles-backend:u  #    0.07% backend cycles idle      ( +-  8.79% )  (83.33%)
      68,976,319,497      instructions:u            #    2.96  insn per cycle
                                                    #    0.00  stalled cycles per insn  ( +-  0.34% )  (83.39%)
      16,770,540,533      branches:u                #    1.659 G/sec                    ( +-  0.31% )  (83.35%)
         128,220,385      branch-misses:u           #    0.76% of all branches          ( +-  0.77% )  (83.37%)

              2.9365 +- 0.0284 seconds time elapsed  ( +-  0.97% )

  $

Then with parallel DWARF loading + parallel BTF encoding (this patch):

  $ perf stat -r5 pahole -j --btf_encode /tmp/vmlinux

   Performance counter stats for 'pahole -j --btf_encode /tmp/vmlinux' (5 runs):

           11,063.29 msec task-clock:u              #    6.389 CPUs utilized            ( +-  0.79% )
                   0      context-switches:u        #    0.000 /sec
                   0      cpu-migrations:u          #    0.000 /sec
             163,263      page-faults:u             #   14.840 K/sec                    ( +-  0.48% )
      41,892,887,608      cycles:u                  #    3.808 GHz                      ( +-  0.96% )  (83.41%)
         197,163,158      stalled-cycles-frontend:u #    0.47% frontend cycles idle     ( +-  3.23% )  (83.46%)
         114,187,423      stalled-cycles-backend:u  #    0.27% backend cycles idle      ( +- 16.57% )  (83.43%)
      74,053,722,204      instructions:u            #    1.78  insn per cycle
                                                    #    0.00  stalled cycles per insn  ( +-  0.18% )  (83.37%)
      17,848,238,467      branches:u                #    1.622 G/sec                    ( +-  0.10% )  (83.27%)
         180,232,427      branch-misses:u           #    1.01% of all branches          ( +-  0.86% )  (83.16%)

              1.7316 +- 0.0301 seconds time elapsed  ( +-  1.74% )

  $

Again it is better not to use -j to use all the CPU threads:

  $ perf stat -r5 pahole -j16 --btf_encode /tmp/vmlinux

   Performance counter stats for 'pahole -j16 --btf_encode /tmp/vmlinux' (5 runs):

            6,626.33 msec task-clock:u              #    4.421 CPUs utilized            ( +-  0.82% )
                   0      context-switches:u        #    0.000 /sec
                   0      cpu-migrations:u          #    0.000 /sec
             140,919      page-faults:u             #   21.240 K/sec                    ( +-  1.03% )
      26,085,701,848      cycles:u                  #    3.932 GHz                      ( +-  1.20% )  (83.38%)
          98,962,246      stalled-cycles-frontend:u #    0.37% frontend cycles idle     ( +-  3.47% )  (83.41%)
         102,762,088      stalled-cycles-backend:u  #    0.39% backend cycles idle      ( +- 17.95% )  (83.38%)
      71,193,141,569      instructions:u            #    2.69  insn per cycle
                                                    #    0.00  stalled cycles per insn  ( +-  0.14% )  (83.33%)
      17,166,459,728      branches:u                #    2.587 G/sec                    ( +-  0.15% )  (83.27%)
         150,984,525      branch-misses:u           #    0.87% of all branches          ( +-  0.61% )  (83.34%)

              1.4989 +- 0.0113 seconds time elapsed  ( +-  0.76% )

  $

Minor tweaks to reduce the patch size, things like avoiding moving the
pthread_mutex_lock(&btf_lock) to after a comment, etc.

Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Link: https://lore.kernel.org/r/20220126192039.2840752-4-kuifeng@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-01-28 16:30:54 -03:00
Arnaldo Carvalho de Melo e57e23c72a btf_encoder: Add methods to maintain a list of btf encoders
We'll have one per thread and then at the end combine and dedup them one
last time.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-20 16:40:27 -03:00
Arnaldo Carvalho de Melo 819f83bd97 btf_encoder: Pass detached_filename to the constructor
The ->filename only points out to the ELF file when we're not writing to
a raw, detached BTF file, so reuse it to store the detached filename
when using that mode.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo 9eb3d7a29d btf_encoder: Pass the 'skip_encoding_vars' to the constructor
Instead of repeatedly passing it to btf_encoder__encode_cu().

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo 707101ec38 btf_encoder: No need to export the 'struct btf_definition', make it opaque
Only in btf_encoder.c we use its fields, so move everything there.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo f0f5b4f2bc btf_encoder: Move library global variable btf_gen_floats to btf_encoder class
So this should be the last global variable in the BTF encoder, good
riddance!

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:54:10 -03:00
Arnaldo Carvalho de Melo 09970b03bd btf_encoder: Ditch unused 'btf_encoder__verbose' global variable
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 10:46:52 -03:00
Arnaldo Carvalho de Melo 282a8a2187 btf_encoder: Use 'struct btf' directly, stop using btf_elf
Now that btf_elf is only crating the 'struct btf' instance, do it
directly.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-09 09:20:23 -03:00
Arnaldo Carvalho de Melo a0c5f49b0c btf_encoder: Phagocytize percpu_secinfo from btf_elf
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 17:54:35 -03:00
Arnaldo Carvalho de Melo 46a3e3a87a btf_encoder: Move the global btf_encoder to its users, like pahole
Tools should instantiate it using btf_encoder__new(), etc, ditch the
library global.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 15:38:48 -03:00
Arnaldo Carvalho de Melo fa849010b4 btf_encoder: Adopt the cu__encode_btf() method, as btf_encoder__encode_cu()
This should be the last user of the global btf_encoder variable, time to
ditch it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 15:35:30 -03:00
Arnaldo Carvalho de Melo 3be437c5e7 btf_encoder: Set btf_encoder__verbose in just one place, its users
E.g.: pahole.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 15:32:55 -03:00
Arnaldo Carvalho de Melo e1e787af44 btf_encoder: Move btf_elf__verbose var to btf_encoder class
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 15:29:55 -03:00
Arnaldo Carvalho de Melo 66f4054252 btf_encoder: Adopt btf_elf__force, its only used in btf_encoder methods
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 15:20:11 -03:00
Arnaldo Carvalho de Melo 5e1207754e pahole: Adopt btf_encoder object instantiation from btf_encoder
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 15:03:05 -03:00
Arnaldo Carvalho de Melo 0208952e8f btf_encoder: Move the function encode() to be a btf_encoder method
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 14:44:19 -03:00
Arnaldo Carvalho de Melo bcc5f95364 btf_encoder: Temporarily expose the 'encoder' variable
To move creation to pahole.c, i.e. outside the library, to the user,
then move the other methods still using the global variable.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 14:40:17 -03:00
Arnaldo Carvalho de Melo e27be59f10 btf_encoder: Move 'filename' member from btf_elf to btf_encoder
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-08 10:10:41 -03:00
Arnaldo Carvalho de Melo 92f8852d8d btf_encoder: Move global elf_functions table to the btf_encoder class
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo aa48ed55a7 btf_encoder: Move ELF's ehdr from btf_elf to btf_encoder
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo b3701a8346 btf_encoder: Move 'symtab' from btf_elf to btf_encoder
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo be8dac4869 btf_encoder: Move percpu members from btf_elf to btf_encoder
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo 7f70877b19 btf_encoder: Add a 'verbose' member for encoder specific logging requests
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo ef8a48b3bc btf_encoder: Move 'array_index_id' global variable to 'struct btf_encoder'
And this reduces the btf_encoder__encode_tag() signature, since we don't
have to pass this variable, as it is now in the 'encoder' parameter.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo f3e6edffd7 btf_encoder: Move percpu vars global variables to btf_encoder class
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo e40bc12ddf btf_encoder: Move 'need_index_type' global variable to 'struct btf_encoder'
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo 65b3c598ab btf_encoder: Move 'has_index_type' global variable to 'struct btf_encoder'
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:20 -03:00
Arnaldo Carvalho de Melo a5c732e712 btf_encoder: Introduce 'struct btf_encoder' to have all the current globals
Start grouping all the state associated with the BTF encoder into a new
class, do it transparently to the user, pahole, until the last moment,
when it will call btf_encoder__new(), etc.

First step is just encapsulating the btf_elf instance, we'll adding the
globals one by one and at the end probably the btf_elf class will be
completely fagocitated. 8-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:30:18 -03:00
Arnaldo Carvalho de Melo f93e05d8bd btf_encoder: Pass the base BTF object to the BTF encoder
We'll get rid of the 'base_btf' global variable in libbtf.c, so stop
using it in the BTF encoder.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo 89be5646a0 pahole: Allow encoding BTF into a detached file
Previously the newly encoded BTF info was stored into a ELF section in
the file where the DWARF info was obtained, but it is useful to just
dump it into a separate file, do it.

  $ ls -la vmlinux.btf
  ls: cannot access 'vmlinux.btf': No such file or directory
  $ pahole -j vmlinux.btf vmlinux
  $ ls -la vmlinux.btf
  -rw-r-----. 1 acme acme 4630082 Jun  1 16:15 vmlinux.btf
  $ pahole -C list_head ./vmlinux.btf
  struct list_head {
  	struct list_head *         next;                 /*     0     8 */
  	struct list_head *         prev;                 /*     8     8 */

  	/* size: 16, cachelines: 1, members: 2 */
  	/* last cacheline: 16 bytes */
  };
  acme@toolbox pahole]$ pahole -C raw_spinlock_t ./vmlinux.btf
  typedef struct raw_spinlock raw_spinlock_t;
  acme@toolbox pahole]$ pahole -EC raw_spinlock ./vmlinux.btf
  struct raw_spinlock {
  	/* typedef arch_spinlock_t */ struct qspinlock {
  		union {
  			/* typedef atomic_t */ struct {
  				int counter;                                                  /*     0     4 */
  			} val;                                                                /*     0     4 */
  			struct {
  				/* typedef u8 -> __u8 */ unsigned char locked;                /*     0     1 */
  				/* typedef u8 -> __u8 */ unsigned char pending;               /*     1     1 */
  			};                                                                    /*     0     2 */
  			struct {
  				/* typedef u16 -> __u16 */ short unsigned int locked_pending; /*     0     2 */
  				/* typedef u16 -> __u16 */ short unsigned int tail;           /*     2     2 */
  			};                                                                    /*     0     4 */
  		};                                                                            /*     0     4 */
  	} raw_lock;                                                                           /*     0     4 */

  	/* size: 4, cachelines: 1, members: 1 */
  	/* last cacheline: 4 bytes */
  };
  ⬢[acme@toolbox pahole]$

Requested-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:54 -03:00
Hao Luo da4ad2f650 btf_encoder: Allow disabling BTF var encoding.
A new feature was introduced in commit f3d9054ba8 ("btf_encoder: Teach
pahole to store percpu variables in vmlinux BTF.") which encodes kernel
percpu variables into BTF. Add a flag --skip_encoding_btf_vars to allow
users to toggle this feature off, so that the rollout of pahole v1.18
can be protected by potential bugs in this feature.

Committer notes:

Added missing man page entry.

Signed-off-by: Hao Luo <haoluo@google.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Yonghong Song <yhs@fb.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-09-21 17:00:16 -03:00
Hao Luo f3d9054ba8 btf_encoder: Teach pahole to store percpu variables in vmlinux BTF.
On SMP systems, the global percpu variables are placed in a special
'.data..percpu' section, which is stored in a segment whose initial
address is set to 0, the addresses of per-CPU variables are relative
positive addresses [1].

This patch extracts these variables from vmlinux and places them with
their type information in BTF. More specifically, when BTF is encoded,
we find the index of the '.data..percpu' section and then traverse the
symbol table to find those global objects which are in this section.
For each of these objects, we push a BTF_KIND_VAR into the types buffer,
and a BTF_VAR_SECINFO into another buffer, percpu_secinfo. When all the
CUs have finished processing, we push a BTF_KIND_DATASEC into the
btfe->types buffer, followed by the percpu_secinfo's content.

In a v5.8-rc3 linux kernel, I was able to extract 288 such variables.
The build time overhead is small and the space overhead is also small.
See testings below.

A found variable can be invalid in two ways:

 - Its name found in elf_sym__name is invalid.
 - Its size identified by elf_sym__size is 0.

In either case, the BTF containing such symbols will be rejected by the
BTF verifier. Normally we should not see such symbols. But if one is
seen during BTF encoding, the encoder will exit with error. An new flag
'-j' (or '--force') is implemented to help testing, which skips the
invalid symbols and force emit a BTF.

Testing:

- vmlinux size has increased by ~12kb.
  Before:
   $ readelf -SW vmlinux | grep BTF
   [25] .BTF              PROGBITS        ffffffff821a905c 13a905c 2d2bf8 00
  After:
   $ pahole -J vmlinux
   $ readelf -SW vmlinux  | grep BTF
   [25] .BTF              PROGBITS        ffffffff821a905c 13a905c 2d5bca 00

- Common global percpu VARs and DATASEC are found in BTF section.
  $ bpftool btf dump file vmlinux | grep runqueues
  [14152] VAR 'runqueues' type_id=13778, linkage=global-alloc

  $ bpftool btf dump file vmlinux | grep 'cpu_stopper'
  [17582] STRUCT 'cpu_stopper' size=72 vlen=5
  [17601] VAR 'cpu_stopper' type_id=17582, linkage=static

  $ bpftool btf dump file vmlinux | grep ' DATASEC '
  [63652] DATASEC '.data..percpu' size=179288 vlen=288

- Tested bpf selftests.

- pahole exits with error if an invalid symbol is seen during encoding,
  make -f Makefile -j 36 -s
  PAHOLE: Error: Found symbol of zero size when encoding btf (sym: 'yyy', cu: 'xxx.c').
  PAHOLE: Error: Use '-j' or '--force_emit' to ignore such symbols and force emit the btf.
  scripts/link-vmlinux.sh: line 137: 2475712 Segmentation fault      LLVM_OBJCOPY=${OBJCOPY} ${PAHOLE} -J ${1}

- With the flag '-j' or '--force', the invalid symbols are ignored.

- Further in verbose mode and with '-j' or '--force' set, a warning is generated:
  PAHOLE: Warning: Found symbol of zero size when encoding btf, ignored (sym: 'yyy', cu: 'xxx.c').
  PAHOLE: Warning: Found symbol of invalid name when encoding btf, ignored (sym: 'zzz', cu: 'sss.c').

References:
 [1] https://lwn.net/Articles/531148/

Signed-off-by: Hao Luo <haoluo@google.com>
Tested-by: Andrii Nakryiko <andriin@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Oleg Rombakh <olegrom@google.com>
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-08-05 14:51:17 -03:00
Martin Lau a58c746c4c Fixup copyright notices for BTF files authored by Facebook engineers
Cc: Andrii Nakryiko <andriin@fb.com>
Cc: Domenico Andreoli <domenico.andreoli@linux.com>
Cc: Yonghong Song <yhs@fb.com>
Signed-off-by: Martin Lau <kafai@fb.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-01-18 20:34:05 -03:00
Domenico Andreoli e714d2eaa1 Adopt SPDX-License-Identifier
Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-01-18 15:41:48 -03:00
Andrii Nakryiko 65bd17abc7 btf: Allow multiple cu's in dwarf->btf conversion
Currently, the pahole dwarf->btf conversion only supports one
compilation unit. This is not ideal since we would like using pahole to
generate BTF for vmlinux which has a lot of compilation units.

This patch added support to process multiple compilation units per ELF
file. Multiple ELF files are also supported properly.

The following is a demonstration example:
  -bash-4.4$ cat t1.c
  struct t1 {
    int a1;
  } g1;
  int main(void) { return 0; }
  -bash-4.4$ cat t2.c
  struct t2 {
    char a2;
  } g2;
  int main() { return 0; }
  -bash-4.4$ cat t3.c
  struct t3 {
    unsigned char a1:4;
  } g1;
  int main(void) { return 0; }
  -bash-4.4$ cat t4.c
  struct t4 {
    volatile char a4;
  } g2;
  int main() { return 0; }
  -bash-4.4$ gcc -O2 -o t1 -g t1.c t2.c
  -bash-4.4$ gcc -O2 -o t3 -g t3.c t4.c

Note that both the binary "t1" and "t3" have two compilation units in
their respective dwarf debug_info sections. The following is the pahole
verbose output for BTF conversion for these two binaries.

  -bash-4.4$ pahole -JV t1 t3
  File t1:
  [1] STRUCT t1 size=4 vlen=1
        a1 type_id=2 bits_offset=0
  [2] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED
  [3] STRUCT t2 size=1 vlen=1
        a2 type_id=4 bits_offset=0
  [4] INT char size=1 bit_offset=0 nr_bits=8 encoding=(none)
  [5] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED

  File t3:
  [1] STRUCT t3 size=1 vlen=1
        a1 type_id=3 bits_offset=0
  [2] INT unsigned char size=1 bit_offset=0 nr_bits=8 encoding=(none)
  [3] INT unsigned char size=1 bit_offset=0 nr_bits=4 encoding=(none)
  [4] INT (anon) size=4 bit_offset=0 nr_bits=32 encoding=(none)
  [5] STRUCT t4 size=1 vlen=1
        a4 type_id=6 bits_offset=0
  [6] VOLATILE (anon) type_id=7
  [7] INT char size=1 bit_offset=0 nr_bits=8 encoding=(none)
  [8] INT int size=4 bit_offset=0 nr_bits=32 encoding=SIGNED

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Yonghong Song <yhs@fb.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-12-20 10:44:48 -03:00
Martin KaFai Lau 68645f7fac btf: Add BTF support
This patch introduces BPF Type Format (BTF).

BTF (BPF Type Format) is the meta data format which describes
the data types of BPF program/map.  Hence, it basically focus
on the C programming language which the modern BPF is primary
using.  The first use case is to provide a generic pretty print
capability for a BPF map.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-07-25 14:42:06 -03:00