Commit d81283d
libbpf: Improve btf__add_btf() with an additional hashmap for strings.
Add a hashmap to map the string offsets from a source btf to the
string offsets from a target btf to reduce overheads.
btf__add_btf() calls btf__add_str() to add strings from a source to a
target btf. It causes many string comparisons, and it is a major
hotspot when adding a big btf. btf__add_str() uses strcmp() to check
if a hash entry is the right one. The extra hashmap here compares
offsets of strings, that are much cheaper. It remembers the results
of btf__add_str() for later uses to reduce the cost.
We are parallelizing BTF encoding for pahole by creating separated btf
instances for worker threads. These per-thread btf instances will be
added to the btf instance of the main thread by calling btf__add_str()
to deduplicate and write out. With this patch and -j4, the running
time of pahole drops to about 6.0s from 6.6s.
The following lines are the summary of 'perf stat' w/o the change.
6.668126396 seconds time elapsed
13.451054000 seconds user
0.715520000 seconds sys
The following lines are the summary w/ the change.
5.986973919 seconds time elapsed
12.939903000 seconds user
0.724152000 seconds sys
V4 fixes a bug of error checking against the pointer returned by
hashmap__new().
[v3] https://lore.kernel.org/bpf/20220118232053.2113139-1-kuifeng@fb.com/
[v2] https://lore.kernel.org/bpf/20220114193713.461349-1-kuifeng@fb.com/
Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220119180214.255634-1-kuifeng@fb.com1 parent 0ba3929 commit d81283d
1 file changed
+30
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1620 | 1620 | | |
1621 | 1621 | | |
1622 | 1622 | | |
| 1623 | + | |
1623 | 1624 | | |
1624 | 1625 | | |
1625 | 1626 | | |
1626 | 1627 | | |
1627 | 1628 | | |
1628 | | - | |
| 1629 | + | |
| 1630 | + | |
1629 | 1631 | | |
1630 | 1632 | | |
1631 | 1633 | | |
1632 | 1634 | | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
1633 | 1641 | | |
1634 | 1642 | | |
1635 | 1643 | | |
1636 | 1644 | | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
1637 | 1654 | | |
1638 | 1655 | | |
1639 | 1656 | | |
| |||
1680 | 1697 | | |
1681 | 1698 | | |
1682 | 1699 | | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
1683 | 1703 | | |
1684 | 1704 | | |
1685 | 1705 | | |
| |||
1713 | 1733 | | |
1714 | 1734 | | |
1715 | 1735 | | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
1716 | 1741 | | |
1717 | 1742 | | |
1718 | 1743 | | |
| |||
1754 | 1779 | | |
1755 | 1780 | | |
1756 | 1781 | | |
| 1782 | + | |
| 1783 | + | |
1757 | 1784 | | |
1758 | 1785 | | |
1759 | 1786 | | |
| |||
1767 | 1794 | | |
1768 | 1795 | | |
1769 | 1796 | | |
| 1797 | + | |
| 1798 | + | |
1770 | 1799 | | |
1771 | 1800 | | |
1772 | 1801 | | |
| |||
0 commit comments