tools/perf/util/thread-stack.c
Source file repositories/reference/linux-study-clean/tools/perf/util/thread-stack.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/thread-stack.c- Extension
.c- Size
- 30384 bytes
- Lines
- 1240
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/rbtree.hlinux/list.hlinux/log2.hlinux/zalloc.herrno.hstdlib.hstring.hthread.hevent.hmachine.henv.hdebug.hsymbol.hcomm.hcall-path.hthread-stack.h
Detected Declarations
struct thread_stack_entrystruct thread_stackenum retpoline_state_tfunction perf_session__register_idle_threadfunction thread_stack__growfunction thread_stack__initfunction thread_stack__pushfunction thread_stack__popfunction thread_stack__pop_trace_endfunction thread_stack__in_kernelfunction thread_stack__call_returnfunction __thread_stack__flushfunction thread_stack__flushfunction thread_stack__update_br_stackfunction thread_stack__eventfunction thread_stack__set_trace_nrfunction __thread_stack__freefunction thread_stack__resetfunction thread_stack__freefunction callchain_contextfunction thread_stack__samplefunction thread_stack__sample_latefunction thread_stack__br_samplefunction us_startfunction ks_startfunction thread_stack__br_sample_latefunction call_return_processor__newfunction call_return_processor__freefunction thread_stack__push_cpfunction thread_stack__pop_cpfunction thread_stack__bottomfunction thread_stack__pop_ksfunction thread_stack__no_call_returnfunction thread_stack__trace_beginfunction thread_stack__trace_endfunction is_x86_retpolinefunction thread_stack__x86_retpolinefunction thread_stack__processfunction thread_stack__depth
Annotated Snippet
struct thread_stack_entry {
u64 ret_addr;
u64 timestamp;
u64 ref;
u64 branch_count;
u64 insn_count;
u64 cyc_count;
u64 db_id;
struct call_path *cp;
bool no_call;
bool trace_end;
bool non_call;
};
/**
* struct thread_stack - thread stack constructed from 'call' and 'return'
* branch samples.
* @stack: array that holds the stack
* @cnt: number of entries in the stack
* @sz: current maximum stack size
* @trace_nr: current trace number
* @branch_count: running branch count
* @insn_count: running instruction count
* @cyc_count running cycle count
* @kernel_start: kernel start address
* @last_time: last timestamp
* @crp: call/return processor
* @comm: current comm
* @arr_sz: size of array if this is the first element of an array
* @rstate: used to detect retpolines
* @br_stack_rb: branch stack (ring buffer)
* @br_stack_sz: maximum branch stack size
* @br_stack_pos: current position in @br_stack_rb
* @mispred_all: mark all branches as mispredicted
*/
struct thread_stack {
struct thread_stack_entry *stack;
size_t cnt;
size_t sz;
u64 trace_nr;
u64 branch_count;
u64 insn_count;
u64 cyc_count;
u64 kernel_start;
u64 last_time;
struct call_return_processor *crp;
struct comm *comm;
unsigned int arr_sz;
enum retpoline_state_t rstate;
struct branch_stack *br_stack_rb;
unsigned int br_stack_sz;
unsigned int br_stack_pos;
bool mispred_all;
};
/*
* Assume pid == tid == 0 identifies the idle task as defined by
* perf_session__register_idle_thread(). The idle task is really 1 task per cpu,
* and therefore requires a stack for each cpu.
*/
static inline bool thread_stack__per_cpu(struct thread *thread)
{
return !(thread__tid(thread) || thread__pid(thread));
}
static int thread_stack__grow(struct thread_stack *ts)
{
struct thread_stack_entry *new_stack;
size_t sz, new_sz;
new_sz = ts->sz + STACK_GROWTH;
sz = new_sz * sizeof(struct thread_stack_entry);
new_stack = realloc(ts->stack, sz);
if (!new_stack)
return -ENOMEM;
ts->stack = new_stack;
ts->sz = new_sz;
return 0;
}
static int thread_stack__init(struct thread_stack *ts, struct thread *thread,
struct call_return_processor *crp,
bool callstack, unsigned int br_stack_sz)
{
int err;
if (callstack) {
Annotation
- Immediate include surface: `linux/rbtree.h`, `linux/list.h`, `linux/log2.h`, `linux/zalloc.h`, `errno.h`, `stdlib.h`, `string.h`, `thread.h`.
- Detected declarations: `struct thread_stack_entry`, `struct thread_stack`, `enum retpoline_state_t`, `function perf_session__register_idle_thread`, `function thread_stack__grow`, `function thread_stack__init`, `function thread_stack__push`, `function thread_stack__pop`, `function thread_stack__pop_trace_end`, `function thread_stack__in_kernel`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.