kernel/events/core.c
Source file repositories/reference/linux-study-clean/kernel/events/core.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/events/core.c- Extension
.c- Size
- 385255 bytes
- Lines
- 15450
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core 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 or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/fs.hlinux/mm.hlinux/cpu.hlinux/smp.hlinux/idr.hlinux/file.hlinux/poll.hlinux/slab.hlinux/hash.hlinux/tick.hlinux/sysfs.hlinux/dcache.hlinux/percpu.hlinux/ptrace.hlinux/reboot.hlinux/vmstat.hlinux/device.hlinux/export.hlinux/vmalloc.hlinux/hardirq.hlinux/hugetlb.hlinux/rculist.hlinux/uaccess.hlinux/syscalls.hlinux/anon_inodes.hlinux/kernel_stat.hlinux/cgroup.hlinux/perf_event.hlinux/trace_events.hlinux/hw_breakpoint.hlinux/mm_types.hlinux/module.h
Detected Declarations
syscall perf_event_openstruct remote_function_callstruct event_function_structstruct __group_keystruct stop_event_datastruct merge_sched_datastruct perf_read_datastruct perf_read_eventstruct remote_outputstruct perf_task_eventstruct perf_comm_eventstruct perf_namespaces_eventstruct perf_cgroup_eventstruct perf_mmap_eventstruct perf_aux_eventstruct perf_switch_eventstruct perf_ksymbol_eventstruct perf_bpf_eventstruct perf_callchain_deferred_eventstruct perf_text_poke_eventstruct perf_aux_eventstruct perf_aux_eventstruct swevent_htableenum event_type_tenum perf_probe_configfunction remote_functionfunction smp_call_function_singlefunction cpu_function_callfunction __perf_ctx_lockfunction perf_ctx_lockfunction __perf_ctx_unlockfunction perf_ctx_unlockfunction class_perf_ctx_lock_destructorfunction class_perf_ctx_lock_constructorfunction is_kernel_eventfunction event_functionfunction event_function_callfunction event_function_callfunction is_guest_mediated_pmu_loadedfunction is_guest_mediated_pmu_loadedfunction update_perf_cpu_limitsfunction perf_event_max_sample_rate_handlerfunction perf_cpu_time_max_percent_handlerfunction init_events_core_sysctlsfunction perf_duration_warnfunction perf_sample_event_tookfunction perf_event_print_debugfunction perf_event_clock
Annotated Snippet
SYSCALL_DEFINE5(perf_event_open,
struct perf_event_attr __user *, attr_uptr,
pid_t, pid, int, cpu, int, group_fd, unsigned long, flags)
{
struct perf_event *group_leader = NULL, *output_event = NULL;
struct perf_event_pmu_context *pmu_ctx;
struct perf_event *event, *sibling;
struct perf_event_attr attr;
struct perf_event_context *ctx;
struct file *event_file = NULL;
struct task_struct *task = NULL;
struct pmu *pmu;
int event_fd;
int move_group = 0;
int err;
int f_flags = O_RDWR;
int cgroup_fd = -1;
/* for future expandability... */
if (flags & ~PERF_FLAG_ALL)
return -EINVAL;
err = perf_copy_attr(attr_uptr, &attr);
if (err)
return err;
/* Do we allow access to perf_event_open(2) ? */
err = security_perf_event_open(PERF_SECURITY_OPEN);
if (err)
return err;
if (!attr.exclude_kernel) {
err = perf_allow_kernel();
if (err)
return err;
}
if (attr.namespaces) {
if (!perfmon_capable())
return -EACCES;
}
if (attr.freq) {
if (attr.sample_freq > sysctl_perf_event_sample_rate)
return -EINVAL;
} else {
if (attr.sample_period & (1ULL << 63))
return -EINVAL;
}
/* Only privileged users can get physical addresses */
if ((attr.sample_type & PERF_SAMPLE_PHYS_ADDR)) {
err = perf_allow_kernel();
if (err)
return err;
}
/* REGS_INTR can leak data, lockdown must prevent this */
if (attr.sample_type & PERF_SAMPLE_REGS_INTR) {
err = security_locked_down(LOCKDOWN_PERF);
if (err)
return err;
}
/*
* In cgroup mode, the pid argument is used to pass the fd
* opened to the cgroup directory in cgroupfs. The cpu argument
* designates the cpu on which to monitor threads from that
* cgroup.
*/
if ((flags & PERF_FLAG_PID_CGROUP) && (pid == -1 || cpu == -1))
return -EINVAL;
if (flags & PERF_FLAG_FD_CLOEXEC)
f_flags |= O_CLOEXEC;
event_fd = get_unused_fd_flags(f_flags);
if (event_fd < 0)
return event_fd;
/*
* Event creation should be under SRCU, see perf_pmu_unregister().
*/
guard(srcu)(&pmus_srcu);
CLASS(fd, group)(group_fd); // group_fd == -1 => empty
if (group_fd != -1) {
if (!is_perf_file(group)) {
err = -EBADF;
goto err_fd;
Annotation
- Immediate include surface: `linux/fs.h`, `linux/mm.h`, `linux/cpu.h`, `linux/smp.h`, `linux/idr.h`, `linux/file.h`, `linux/poll.h`, `linux/slab.h`.
- Detected declarations: `syscall perf_event_open`, `struct remote_function_call`, `struct event_function_struct`, `struct __group_key`, `struct stop_event_data`, `struct merge_sched_data`, `struct perf_read_data`, `struct perf_read_event`, `struct remote_output`, `struct perf_task_event`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.