kernel/trace/trace_sched_switch.c
Source file repositories/reference/linux-study-clean/kernel/trace/trace_sched_switch.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/trace_sched_switch.c- Extension
.c- Size
- 14857 bytes
- Lines
- 666
- 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/module.hlinux/kallsyms.hlinux/uaccess.hlinux/kmemleak.hlinux/ftrace.htrace/events/sched.htrace.h
Detected Declarations
struct saved_cmdlines_bufferfunction probe_sched_switchfunction probe_sched_wakeupfunction tracing_sched_registerfunction tracing_sched_unregisterfunction tracing_start_sched_switchfunction tracing_stop_sched_switchfunction tracing_start_cmdline_recordfunction tracing_stop_cmdline_recordfunction tracing_start_tgid_recordfunction tracing_stop_tgid_recordfunction set_cmdlinefunction free_saved_cmdlines_bufferfunction trace_create_savedcmdfunction trace_save_cmdlinefunction __trace_find_cmdlinefunction trace_find_cmdlinefunction trace_find_tgidfunction trace_save_tgidfunction tracing_record_taskinfo_skipfunction tracing_record_taskinfofunction tracing_record_taskinfo_sched_switchfunction tracing_record_cmdlinefunction tracing_record_tgidfunction trace_alloc_tgid_mapfunction saved_tgids_stopfunction tracing_saved_tgids_openfunction saved_cmdlines_stopfunction saved_cmdlines_showfunction tracing_saved_cmdlines_openfunction tracing_saved_cmdlines_size_readfunction trace_free_saved_cmdlines_bufferfunction tracing_resize_saved_cmdlinesfunction tracing_saved_cmdlines_size_write
Annotated Snippet
const struct file_operations tracing_saved_tgids_fops = {
.open = tracing_saved_tgids_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static void *saved_cmdlines_next(struct seq_file *m, void *v, loff_t *pos)
{
unsigned int *ptr = v;
if (*pos || m->count)
ptr++;
(*pos)++;
for (; ptr < &savedcmd->map_cmdline_to_pid[savedcmd->cmdline_num];
ptr++) {
if (*ptr == -1 || *ptr == NO_CMDLINE_MAP)
continue;
return ptr;
}
return NULL;
}
static void *saved_cmdlines_start(struct seq_file *m, loff_t *pos)
{
void *v;
loff_t l = 0;
preempt_disable();
arch_spin_lock(&trace_cmdline_lock);
v = &savedcmd->map_cmdline_to_pid[0];
while (l <= *pos) {
v = saved_cmdlines_next(m, v, &l);
if (!v)
return NULL;
}
return v;
}
static void saved_cmdlines_stop(struct seq_file *m, void *v)
{
arch_spin_unlock(&trace_cmdline_lock);
preempt_enable();
}
static int saved_cmdlines_show(struct seq_file *m, void *v)
{
char buf[TASK_COMM_LEN];
unsigned int *pid = v;
__trace_find_cmdline(*pid, buf);
seq_printf(m, "%d %s\n", *pid, buf);
return 0;
}
static const struct seq_operations tracing_saved_cmdlines_seq_ops = {
.start = saved_cmdlines_start,
.next = saved_cmdlines_next,
.stop = saved_cmdlines_stop,
.show = saved_cmdlines_show,
};
static int tracing_saved_cmdlines_open(struct inode *inode, struct file *filp)
{
int ret;
ret = tracing_check_open_get_tr(NULL);
if (ret)
return ret;
return seq_open(filp, &tracing_saved_cmdlines_seq_ops);
}
const struct file_operations tracing_saved_cmdlines_fops = {
.open = tracing_saved_cmdlines_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static ssize_t
tracing_saved_cmdlines_size_read(struct file *filp, char __user *ubuf,
size_t cnt, loff_t *ppos)
{
Annotation
- Immediate include surface: `linux/module.h`, `linux/kallsyms.h`, `linux/uaccess.h`, `linux/kmemleak.h`, `linux/ftrace.h`, `trace/events/sched.h`, `trace.h`.
- Detected declarations: `struct saved_cmdlines_buffer`, `function probe_sched_switch`, `function probe_sched_wakeup`, `function tracing_sched_register`, `function tracing_sched_unregister`, `function tracing_start_sched_switch`, `function tracing_stop_sched_switch`, `function tracing_start_cmdline_record`, `function tracing_stop_cmdline_record`, `function tracing_start_tgid_record`.
- 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.