diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2026-10-11 11:35:18 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2026-10-11 12:42:26 -0700 |
| commit | 0bb1b14e5c6c308ee214f076592c783a2a9d54f1 (patch) | |
| tree | a1aea26c57d4f717d5f78bc2e4c3f9fa899e7586 /tools/perf/scripts/python/stackcollapse.py | |
| parent | 722c861ed56824f10a58b72bb67302a5b2470cc7 (diff) | |
| download | linux-next-0bb1b14e5c6c308ee214f076592c783a2a9d54f1.tar.gz linux-next-0bb1b14e5c6c308ee214f076592c783a2a9d54f1.zip | |
assoc_array: replace the labels in gc's tree walk with a loop
assoc_array_gc() walks the old tree depth first, without recursion,
building the copy as it goes. Its position is a handful of locals, and
its moves are labels: descend copies a node and the shortcut in front
of it, continue_node goes on through the node's slots, the code after
the fold removes a node holding nothing but a shortcut or a shortcut in
front of a small node, and ascend_old_tree climbs back up.
Keep the walk and its order, but give the position a structure,
struct assoc_array_gc_walk, and each move a function:
assoc_array_gc_copy(), assoc_array_gc_next(), assoc_array_gc_pack() and
assoc_array_gc_ascend(). assoc_array_gc() becomes a loop that copies a
subtree, then finds the next one, packing and climbing past the nodes
that are done.
Finishing is one test now: after packing, a copy has no parent exactly
when it is the whole tree. That covers all four ways the old code
finished: the three gotos to gc_complete, and the climb out of a node
below a root shortcut that is kept, which now stops at the packing.
The copy is made in one place, so gcc inlines all of it into
assoc_array_gc(), which has no recursion: its stack frame is 152 bytes,
against 128 before, on an x86-64 defconfig.
No functional change.
Assisted-by: LLM
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools/perf/scripts/python/stackcollapse.py')
0 files changed, 0 insertions, 0 deletions
