Skip to content

Feature: visualize variable lifetimes #2

@dylandreimerink

Description

@dylandreimerink

Variable lifetimes are very important when trying to reason about what changes to make in the BPF sources to reduce stack usage. Having a lot of variables with non-overlapping lifetimes will fit in the same stack space. But variables with long lifetimes tend to overlap thus causing more stack space to be allocated.

The lifetime of a variable starts when its stack slot is initialized and ends at the last instruction that uses that stack slot. Variable lifetimes are made up of multiple "intervals" for example, if a program has 50 instructions, the lifetime of a variable may be from 10 to 20 and 30 to 40, but outside of that instruction range the stack slot could be reused by some other variable.

It would be nice if we can visualize the lifetime of variables in some graphical way to allow a user to identify variables as targets for optimization.

For example, we might visualize this by having variables on a vertical axis, and instructions on the horizontal axis. Each interval is represented by a bar.

This should allow us to identify variables with a very long lifetime, be the size of the bars. It should also allow us to identify which variables have overlapping lifetimes. Particularly those variables which have live at the top of the stack.

We may be able to calculate this lifetime information from the eBPF instructions alone by parsing with cilium/ebpf, or we may need to get some additional information such as the LLVM IR at a particular stage in the optimization pipeline or LLVM debug output of the stack/register allocator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions