Arnaldo Carvalho de Melo
d7f5824a9e
libctf: Use zfree() where applicable
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Andrii Nakryiko
29fce8dc85
strings: use BTF's string APIs for strings management
...
Switch strings container to using struct btf and its
btf__add_str()/btf__find_str() APIs, which do equivalent internal string
deduplication. This turns out to be a very significantly faster than using
tsearch functions. To satisfy CTF encoding use case, some hacky string size
fetching approach is utilized, as libbpf doesn't provide direct API to get
total string section size and to copy over just strings data section.
BEFORE:
22,624.28 msec task-clock # 1.000 CPUs utilized
85 context-switches # 0.004 K/sec
3 cpu-migrations # 0.000 K/sec
622,545 page-faults # 0.028 M/sec
68,177,206,387 cycles # 3.013 GHz (24.99%)
114,370,031,619 instructions # 1.68 insn per cycle (25.01%)
26,125,001,179 branches # 1154.733 M/sec (25.01%)
458,861,243 branch-misses # 1.76% of all branches (25.00%)
24,533,455,967 L1-dcache-loads # 1084.386 M/sec (25.02%)
973,500,214 L1-dcache-load-misses # 3.97% of all L1-dcache hits (25.05%)
338,773,561 LLC-loads # 14.974 M/sec (25.02%)
12,651,196 LLC-load-misses # 3.73% of all LL-cache hits (25.00%)
22.628910615 seconds time elapsed
21.341063000 seconds user
1.283763000 seconds sys
AFTER:
18,362.97 msec task-clock # 1.000 CPUs utilized
37 context-switches # 0.002 K/sec
0 cpu-migrations # 0.000 K/sec
626,281 page-faults # 0.034 M/sec
52,480,619,000 cycles # 2.858 GHz (25.00%)
104,736,434,384 instructions # 2.00 insn per cycle (25.01%)
23,878,428,465 branches # 1300.358 M/sec (25.01%)
252,669,685 branch-misses # 1.06% of all branches (25.03%)
21,829,390,952 L1-dcache-loads # 1188.772 M/sec (25.04%)
638,086,339 L1-dcache-load-misses # 2.92% of all L1-dcache hits (25.02%)
212,327,435 LLC-loads # 11.563 M/sec (25.00%)
14,578,117 LLC-load-misses # 6.87% of all LL-cache hits (25.00%)
18.364427347 seconds time elapsed
16.985494000 seconds user
1.377959000 seconds sys
Committer testing:
Before:
$ perf stat -r5 pahole -J vmlinux
Performance counter stats for 'pahole -J vmlinux' (5 runs):
8,735.92 msec task-clock:u # 0.998 CPUs utilized ( +- 0.34% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
353,978 page-faults:u # 0.041 M/sec ( +- 0.00% )
34,722,167,335 cycles:u # 3.975 GHz ( +- 0.12% ) (83.33%)
555,981,118 stalled-cycles-frontend:u # 1.60% frontend cycles idle ( +- 1.53% ) (83.33%)
5,215,370,531 stalled-cycles-backend:u # 15.02% backend cycles idle ( +- 1.31% ) (83.33%)
72,615,773,119 instructions:u # 2.09 insn per cycle
# 0.07 stalled cycles per insn ( +- 0.02% ) (83.34%)
16,624,959,121 branches:u # 1903.057 M/sec ( +- 0.01% ) (83.33%)
229,962,327 branch-misses:u # 1.38% of all branches ( +- 0.07% ) (83.33%)
8.7503 +- 0.0301 seconds time elapsed ( +- 0.34% )
$
After:
$ perf stat -r5 pahole -J vmlinux
Performance counter stats for 'pahole -J vmlinux' (5 runs):
7,302.31 msec task-clock:u # 0.998 CPUs utilized ( +- 1.16% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
355,884 page-faults:u # 0.049 M/sec ( +- 0.00% )
29,150,861,078 cycles:u # 3.992 GHz ( +- 0.35% ) (83.33%)
478,705,326 stalled-cycles-frontend:u # 1.64% frontend cycles idle ( +- 2.70% ) (83.33%)
5,351,001,796 stalled-cycles-backend:u # 18.36% backend cycles idle ( +- 1.20% ) (83.33%)
65,835,888,022 instructions:u # 2.26 insn per cycle
# 0.08 stalled cycles per insn ( +- 0.03% ) (83.33%)
15,025,195,460 branches:u # 2057.594 M/sec ( +- 0.05% ) (83.34%)
141,209,214 branch-misses:u # 0.94% of all branches ( +- 0.15% ) (83.33%)
7.3140 +- 0.0851 seconds time elapsed ( +- 1.16% )
$
16.04% less cycles, keep the patches coming! :-)
Had to add this patch tho:
+++ b/dwarf_loader.c
@@ -2159,7 +2159,7 @@ static unsigned long long dwarf_tag__orig_id(const struct tag *tag,
static const char *dwarf__strings_ptr(const struct cu *cu __unused,
strings_t s)
{
- return strings__ptr(strings, s);
+ return s ? strings__ptr(strings, s) : NULL;
}
To keep preexisting behaviour and to do what the BTF specific
strings_ptr method does:
static const char *btf_elf__strings_ptr(const struct cu *cu, strings_t s)
{
return btf_elf__string(cu->priv, s);
}
const char *btf_elf__string(struct btf_elf *btfe, uint32_t ref)
{
const char *s = btf__str_by_offset(btfe->btf, ref);
return s && s[0] == '\0' ? NULL : s;
}
With these adjustments, btfdiff on a vmlinux with BTF and DWARF is again
clean, i.e. pretty printing from BTF matches what we get when using
DWARF.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Cc: kernel-team@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-10-20 17:17:51 -03:00
Arnaldo Carvalho de Melo
8b1c632831
libctf: Make can't get header message to appear only in verbose mode
...
This usually means we're trying each of the type loaders (DWARF, BTF,
CTF) on some invalid file, so no need to show that message, use verbose
mode to get it, so that we show that all loaders are being tried.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-10-01 10:08:25 -03:00
Arnaldo Carvalho de Melo
7bfb1aa80f
libctf: Enlarge the 'cmd' buffer to not possibly truncate the pathname
...
Addressing this compiler warning:
[ 22%] Building C object CMakeFiles/dwarves.dir/libctf.c.o
/home/acme/git/pahole/libctf.h: In function ‘ctf__encode’:
/home/acme/git/pahole/libctf.c:744:62: error: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size 4064 [-Werror=format-truncation=]
snprintf(cmd, sizeof(cmd), "objcopy --add-section .SUNW_ctf=%s %s",
^~
pathname, ctf->filename);
~~~~~~~~
/home/acme/git/pahole/libctf.c:744:2: note: ‘snprintf’ output 34 or more bytes (assuming 4129) into a destination of size 4096
snprintf(cmd, sizeof(cmd), "objcopy --add-section .SUNW_ctf=%s %s",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pathname, ctf->filename);
~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-07-02 12:14:02 -03:00
Arnaldo Carvalho de Melo
f601f67258
libctf: The type_ids returned are uint32_t fixup where it was uint16_t
...
To help in the tree wide conversion to uint32_t to represent type IDs.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-03-11 11:44:53 -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
Arnaldo Carvalho de Melo
a54515fa6e
dwarves: Stop using 'self'
...
As Thomas Gleixner wisely pointed out, using 'self' is stupid, it
doesn't convey useful information, so use sensible names.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-08-17 18:47:15 -03:00
Rakesh Pandit
537db1da2d
libctf: Replaces deprecated elf_getshstrndx with elf_getshdrstrndx
...
Removes irritating warning while compilation.
Signed-off-by: Rakesh Pandit <rakesh@fedoraproject.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-12-29 11:36:47 -02:00
Arnaldo Carvalho de Melo
1701b6d68d
dutil: Allow returning the section index in elf_section_by_name
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-03 11:53:05 -03:00
Arnaldo Carvalho de Melo
1d7bea33b7
libctf: ctf__delete must call elf_symtab__delete
...
Its used when loading a CTF file, not when encoding.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-03 09:45:15 -03:00
Arnaldo Carvalho de Melo
4f5e2226de
ctf_encoder: ctf__encode has to free the buf when compressing
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-03 09:25:48 -03:00
Arnaldo Carvalho de Melo
bd68f6bbc1
ctf_encoder: We have to free the gobuffer entries for the sections
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-03 09:22:48 -03:00
Arnaldo Carvalho de Melo
486299a359
ctf: Plug debug_fmt_ops->strings__ptr
...
So that we can use the strings in ".strtab" directly, without duplicating them
on the global strings table.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 17:55:17 -03:00
Arnaldo Carvalho de Melo
9bb29daac4
base_type: Don't combine names with attributes
...
Such as signed, etc. This is in preparation for using directly ctf_strings.
Instead of duplicating it in the global strings table.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 16:12:36 -03:00
Arnaldo Carvalho de Melo
deb509cf6c
libctf: Ignore hidden symbols
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 14:03:04 -03:00
Arnaldo Carvalho de Melo
9f4cedc61d
ctf_encoder: ctf__ignore_symtab_object should ignore symbols with dots
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 18:19:19 -03:00
Arnaldo Carvalho de Melo
d7d419f6ab
ctf_encoder: Create objects section (data/variables)
...
Encoding all the non UNDEF OBJECT entries in the symtab. Some must be filtered
in upcoming patches, but for at least kernel/sched.o it works just fine.
To test it I used DaveM's ctfdump and also pdwtags on a --strip-debug, pahole
-Z CTF encoded object.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 16:12:00 -03:00
Arnaldo Carvalho de Melo
83d2438698
gobuffer: Introduce gobuffer__copy
...
To replace some long open coded sequences.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 15:54:53 -03:00
Arnaldo Carvalho de Melo
3b530f8f14
ctf_loader: Load the function section
...
Iterating thru the symtab and getting the missing info from
ctf_header->ctf_func_off.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:52:37 -03:00
Arnaldo Carvalho de Melo
0a924bf4eb
ctf_encoder: Interface to encode functions
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:49:13 -03:00
Arnaldo Carvalho de Melo
0f97ea0329
libctf: fix ctf__delete
...
It should free ->filename and only close the file and call
elf_end if it was opened at ctf__new.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:05:54 -03:00
Arnaldo Carvalho de Melo
60e76245b8
core: Allow cachine an open Elf file handle for reuse
...
pahole --ctf_encode being the first to put this to good use.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:00:39 -03:00
Arnaldo Carvalho de Melo
ed0c3ae7d1
ctf: Move ctf_format_flt_attrs from the loader to libctf
...
It is not glue from CTF to the core, it is pure CTF stuff.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 11:29:13 -03:00
Arnaldo Carvalho de Melo
2fd3936a9d
ctf: combine the structs ctf_state and ctf
...
Moving more CTF only stuff out of the dwarves land and into something that can
be more easily stolen by other projects not interested in funny named stuff
such as pahole.
This also will help with encoding, as we will normally be recoding data from
DWARF, so the ELF file will be available and we will just add a new section to
it.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 18:12:11 -03:00
Arnaldo Carvalho de Melo
49f590e3b9
libctf: Adopt ctf__string from ctf_loader.c
...
The ctf_loader.c file should be a direct counterpart to dwarf_loader,
that is, it should have just use what is in libctf to decode the CTF
sections and convert it to the core format in dwarves.[ch].
Also introduce a ctf__string32 for the very common idiom:
ctf_string(ctf__get32(sp->ctf, &tp->base.ctf_name), sp);
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 17:13:40 -03:00
Arnaldo Carvalho de Melo
da177f87a3
ctf_encoder: Check if something was encoded before saving the info
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 13:20:24 -03:00
Arnaldo Carvalho de Melo
ce97ac9a26
ctf_encoder: Allow encoding a bit_size in enumeration types
...
As we have to support enum bitfields, so remember the bit_size.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 12:51:30 -03:00
Arnaldo Carvalho de Melo
fedbfb60ff
libctf: Encode VARARGS an extra 0 short at the end of the parm list
...
We'll see if this is how things should be, but its good enough for me 8)
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 20:10:33 -03:00
Arnaldo Carvalho de Melo
dcef613288
libctf: give up "for now" on using libelf to add a section to an existing file
...
And use what worked so far, that is: if the section is already there,
replacing its contents works, because probably all the relocation was
done... If not, be a chicken and call system("objcopy..."), but...
I'llll be bahck!
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 19:41:14 -03:00
Arnaldo Carvalho de Melo
f2495cd1a6
libctf: comment out some debug messages
...
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 19:17:41 -03:00
Arnaldo Carvalho de Melo
feab8aa5e3
ctf: Include the initial implementation of a ctf encoder
...
"pahole -Z foo" will create foo.SUNW_ctf, that if objcopy
--add-section'ed to the right word-sized object will work, sans VARARGS,
that will get fixed soon (as in, probably, tomorrow).
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 12:16:07 -03:00
Arnaldo Carvalho de Melo
f7a428ef24
ctf: Add a filename member to struct ctf
...
That will be later used when encoding the CTF info.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 12:14:01 -03:00
Arnaldo Carvalho de Melo
7dfd45ffea
libctf: The constructor should load only if a buffer is passed
...
So that we can create a ctf object and then populate it, to do the
encoding.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2008-09-25 16:25:06 -03:00
Arnaldo Carvalho de Melo
36f454820e
libctf: Use the same coding style as the dwarves
...
Use __ as a separator for the method names, self, new/delete, use
stdint.h types, etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2008-09-25 16:01:26 -03:00
Arnaldo Carvalho de Melo
2dfa5fe6ea
[DWARVES]: Initial CTF support
...
Using a library written by David S. Miller.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2008-03-04 15:37:02 -03:00