kernel/trace/fgraph.c
Source file repositories/reference/linux-study-clean/kernel/trace/fgraph.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/fgraph.c- Extension
.c- Size
- 41638 bytes
- Lines
- 1470
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/jump_label.hlinux/suspend.hlinux/ftrace.hlinux/static_call.hlinux/slab.htrace/events/sched.hftrace_internal.htrace.h
Detected Declarations
function fgraph_lru_initfunction fgraph_lru_release_indexfunction fgraph_lru_alloc_indexfunction __get_offsetfunction __get_typefunction __get_data_indexfunction __get_data_sizefunction get_fgraph_entryfunction get_frame_offsetfunction get_bitmap_bitsfunction set_bitmapfunction make_data_type_valfunction entry_runfunction return_runfunction ret_stack_get_task_varfunction ret_stack_init_task_varsfunction entryfuncfunction retfuncfunction get_ret_stackfunction fgraph_retrieve_datafunction ftrace_enable_ftrace_graph_callerfunction ftrace_disable_ftrace_graph_callerfunction ftrace_graph_entry_stubfunction ftrace_graph_ret_stubfunction ftrace_graph_stopfunction ftrace_push_return_tracefunction function_graph_enter_regsfunction for_each_set_bitfunction ftrace_pop_return_tracefunction ftrace_suspend_notifier_callfunction __ftrace_return_to_handlerfunction for_each_set_bitfunction ftrace_return_to_handlerfunction ftrace_return_to_handlerfunction ftrace_graph_get_ret_stackfunction ftrace_graph_top_ret_addrfunction addressfunction fgraph_init_opsfunction alloc_retstack_tasklistfunction ftrace_graph_probe_sched_switchfunction graph_init_taskfunction ftrace_graph_init_idle_taskfunction ftrace_graph_init_taskfunction ftrace_graph_exit_taskfunction fgraph_pid_funcfunction fgraph_update_pid_funcfunction list_for_each_entryfunction start_graph_tracing
Annotated Snippet
sizeof(fgraph_array_bitmask) * BITS_PER_BYTE) {
struct fgraph_ops *gops = READ_ONCE(fgraph_array[i]);
int save_curr_ret_stack;
if (gops == &fgraph_stub)
continue;
save_curr_ret_stack = current->curr_ret_stack;
if (ftrace_ops_test(&gops->ops, func, NULL) &&
gops->entryfunc(&trace, gops, fregs))
bitmap |= BIT(i);
else
/* Clear out any saved storage */
current->curr_ret_stack = save_curr_ret_stack;
}
}
if (!bitmap)
goto out_ret;
/*
* Since this function uses fgraph_idx = 0 as a tail-call checking
* flag, set that bit always.
*/
set_bitmap(current, offset, bitmap | BIT(0));
ftrace_test_recursion_unlock(bit);
return 0;
out_ret:
current->curr_ret_stack -= FGRAPH_FRAME_OFFSET + 1;
out:
current->curr_ret_depth--;
ftrace_test_recursion_unlock(bit);
return -EBUSY;
}
/* Retrieve a function return address to the trace stack on thread info.*/
static struct ftrace_ret_stack *
ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
unsigned long frame_pointer, int *offset)
{
struct ftrace_ret_stack *ret_stack;
ret_stack = get_ret_stack(current, current->curr_ret_stack, offset);
if (unlikely(!ret_stack)) {
ftrace_graph_stop();
WARN(1, "Bad function graph ret_stack pointer: %d",
current->curr_ret_stack);
/* Might as well panic, otherwise we have no where to go */
*ret = (unsigned long)panic;
return NULL;
}
#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
/*
* The arch may choose to record the frame pointer used
* and check it here to make sure that it is what we expect it
* to be. If gcc does not set the place holder of the return
* address in the frame pointer, and does a copy instead, then
* the function graph trace will fail. This test detects this
* case.
*
* Currently, x86_32 with optimize for size (-Os) makes the latest
* gcc do the above.
*
* Note, -mfentry does not use frame pointers, and this test
* is not needed if CC_USING_FENTRY is set.
*/
if (unlikely(ret_stack->fp != frame_pointer)) {
ftrace_graph_stop();
WARN(1, "Bad frame pointer: expected %lx, received %lx\n"
" from func %ps return to %lx\n",
ret_stack->fp,
frame_pointer,
(void *)ret_stack->func,
ret_stack->ret);
*ret = (unsigned long)panic;
return NULL;
}
#endif
*offset += FGRAPH_FRAME_OFFSET;
*ret = ret_stack->ret;
trace->func = ret_stack->func;
trace->overrun = atomic_read(¤t->trace_overrun);
trace->depth = current->curr_ret_depth;
/*
* We still want to trace interrupts coming in if
* max_depth is set to 1. Make sure the decrement is
* seen before ftrace_graph_return.
Annotation
- Immediate include surface: `linux/bits.h`, `linux/jump_label.h`, `linux/suspend.h`, `linux/ftrace.h`, `linux/static_call.h`, `linux/slab.h`, `trace/events/sched.h`, `ftrace_internal.h`.
- Detected declarations: `function fgraph_lru_init`, `function fgraph_lru_release_index`, `function fgraph_lru_alloc_index`, `function __get_offset`, `function __get_type`, `function __get_data_index`, `function __get_data_size`, `function get_fgraph_entry`, `function get_frame_offset`, `function get_bitmap_bits`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.