tools/perf/builtin-sched.c
Source file repositories/reference/linux-study-clean/tools/perf/builtin-sched.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/builtin-sched.c- Extension
.c- Size
- 133203 bytes
- Lines
- 5074
- 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.
- 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
builtin.hperf.hperf-sys.hutil/cpumap.hutil/evlist.hutil/evsel.hutil/evsel_fprintf.hutil/mutex.hutil/symbol.hutil/thread.hutil/header.hutil/session.hutil/tool.hutil/cloexec.hutil/thread_map.hutil/color.hutil/stat.hutil/string2.hutil/callchain.hutil/time-utils.hsubcmd/pager.hsubcmd/parse-options.hutil/trace-event.hutil/debug.hutil/event.hutil/util.hutil/synthetic-events.hutil/target.hlinux/kernel.hlinux/log2.hlinux/zalloc.hsys/prctl.h
Detected Declarations
struct sched_atomstruct task_descstruct sched_atomstruct work_atomstruct work_atomsstruct perf_schedstruct trace_sched_handlerstruct perf_sched_mapstruct perf_schedstruct thread_runtimestruct evsel_runtimestruct idle_thread_runtimestruct sched_thread_parmsstruct sort_dimensionstruct total_run_statsstruct schedstat_domainstruct schedstat_cpuenum sched_event_typeenum thread_statefunction get_nsecsfunction burn_nsecsfunction sleep_nsecsfunction calibrate_run_measurement_overheadfunction calibrate_sleep_measurement_overheadfunction get_new_eventfunction add_sched_event_runfunction add_sched_event_wakeupfunction add_sched_event_sleepfunction print_task_tracesfunction add_cross_task_wakeupsfunction perf_sched__process_eventfunction get_cpu_usage_nsec_parentfunction self_open_countersfunction get_cpu_usage_nsec_selffunction create_tasksfunction destroy_tasksfunction wait_for_tasksfunction run_one_testfunction test_calibrationsfunction replay_wakeup_eventfunction replay_switch_eventfunction replay_fork_eventfunction init_priofunction thread_lat_cmpfunction list_for_each_entryfunction thread_atoms_searchfunction __thread_latency_insertfunction thread_atoms_insert
Annotated Snippet
struct task_desc {
unsigned long nr;
unsigned long pid;
char comm[COMM_LEN];
unsigned long nr_events;
unsigned long curr_event;
struct sched_atom **atoms;
pthread_t thread;
sem_t ready_for_work;
sem_t work_done_sem;
u64 cpu_usage;
};
enum sched_event_type {
SCHED_EVENT_RUN,
SCHED_EVENT_SLEEP,
SCHED_EVENT_WAKEUP,
};
struct sched_atom {
enum sched_event_type type;
u64 timestamp;
u64 duration;
unsigned long nr;
sem_t *wait_sem;
struct task_desc *wakee;
};
enum thread_state {
THREAD_SLEEPING = 0,
THREAD_WAIT_CPU,
THREAD_SCHED_IN,
THREAD_IGNORE
};
struct work_atom {
struct list_head list;
enum thread_state state;
u64 sched_out_time;
u64 wake_up_time;
u64 sched_in_time;
u64 runtime;
};
struct work_atoms {
struct list_head work_list;
struct thread *thread;
struct rb_node node;
u64 max_lat;
u64 max_lat_start;
u64 max_lat_end;
u64 total_lat;
u64 nb_atoms;
u64 total_runtime;
int num_merged;
};
typedef int (*sort_fn_t)(struct work_atoms *, struct work_atoms *);
struct perf_sched;
struct trace_sched_handler {
int (*switch_event)(struct perf_sched *sched, struct evsel *evsel,
struct perf_sample *sample, struct machine *machine);
int (*runtime_event)(struct perf_sched *sched, struct evsel *evsel,
struct perf_sample *sample, struct machine *machine);
int (*wakeup_event)(struct perf_sched *sched, struct evsel *evsel,
struct perf_sample *sample, struct machine *machine);
/* PERF_RECORD_FORK event, not sched_process_fork tracepoint */
int (*fork_event)(struct perf_sched *sched, union perf_event *event,
struct machine *machine);
int (*migrate_task_event)(struct perf_sched *sched,
struct evsel *evsel,
struct perf_sample *sample,
struct machine *machine);
};
#define COLOR_PIDS PERF_COLOR_BLUE
#define COLOR_CPUS PERF_COLOR_BG_RED
struct perf_sched_map {
DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);
Annotation
- Immediate include surface: `builtin.h`, `perf.h`, `perf-sys.h`, `util/cpumap.h`, `util/evlist.h`, `util/evsel.h`, `util/evsel_fprintf.h`, `util/mutex.h`.
- Detected declarations: `struct sched_atom`, `struct task_desc`, `struct sched_atom`, `struct work_atom`, `struct work_atoms`, `struct perf_sched`, `struct trace_sched_handler`, `struct perf_sched_map`, `struct perf_sched`, `struct thread_runtime`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.