kernel/trace/trace_stat.c
Source file repositories/reference/linux-study-clean/kernel/trace/trace_stat.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/trace_stat.c- Extension
.c- Size
- 7587 bytes
- Lines
- 359
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/security.hlinux/list.hlinux/slab.hlinux/rbtree.hlinux/tracefs.htrace_stat.htrace.h
Detected Declarations
struct stat_nodestruct stat_sessionfunction __reset_stat_sessionfunction rbtree_postorder_for_each_entry_safefunction reset_stat_sessionfunction destroy_sessionfunction insert_statfunction dummy_cmpfunction stat_seq_initfunction stat_seq_stopfunction stat_seq_showfunction tracing_stat_openfunction tracing_stat_releasefunction tracing_stat_initfunction init_stat_filefunction register_stat_tracerfunction unregister_stat_tracer
Annotated Snippet
static const struct file_operations tracing_stat_fops = {
.open = tracing_stat_open,
.read = seq_read,
.llseek = seq_lseek,
.release = tracing_stat_release
};
static int tracing_stat_init(void)
{
int ret;
ret = tracing_init_dentry();
if (ret)
return -ENODEV;
stat_dir = tracefs_create_dir("trace_stat", NULL);
if (!stat_dir) {
pr_warn("Could not create tracefs 'trace_stat' entry\n");
return -ENOMEM;
}
return 0;
}
static int init_stat_file(struct stat_session *session)
{
int ret;
if (!stat_dir && (ret = tracing_stat_init()))
return ret;
session->file = tracefs_create_file(session->ts->name, TRACE_MODE_WRITE,
stat_dir, session,
&tracing_stat_fops);
if (!session->file)
return -ENOMEM;
return 0;
}
int register_stat_tracer(struct tracer_stat *trace)
{
struct stat_session *session, *node;
int ret;
if (!trace)
return -EINVAL;
if (!trace->stat_start || !trace->stat_next || !trace->stat_show)
return -EINVAL;
guard(mutex)(&all_stat_sessions_mutex);
/* Already registered? */
list_for_each_entry(node, &all_stat_sessions, session_list) {
if (node->ts == trace)
return -EINVAL;
}
/* Init the session */
session = kzalloc_obj(*session);
if (!session)
return -ENOMEM;
session->ts = trace;
INIT_LIST_HEAD(&session->session_list);
mutex_init(&session->stat_mutex);
ret = init_stat_file(session);
if (ret) {
destroy_session(session);
return ret;
}
/* Register */
list_add_tail(&session->session_list, &all_stat_sessions);
return 0;
}
void unregister_stat_tracer(struct tracer_stat *trace)
{
struct stat_session *node, *tmp;
mutex_lock(&all_stat_sessions_mutex);
list_for_each_entry_safe(node, tmp, &all_stat_sessions, session_list) {
if (node->ts == trace) {
list_del(&node->session_list);
destroy_session(node);
break;
}
}
Annotation
- Immediate include surface: `linux/security.h`, `linux/list.h`, `linux/slab.h`, `linux/rbtree.h`, `linux/tracefs.h`, `trace_stat.h`, `trace.h`.
- Detected declarations: `struct stat_node`, `struct stat_session`, `function __reset_stat_session`, `function rbtree_postorder_for_each_entry_safe`, `function reset_stat_session`, `function destroy_session`, `function insert_stat`, `function dummy_cmp`, `function stat_seq_init`, `function stat_seq_stop`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: pattern 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.