kernel/trace/trace_hwlat.c
Source file repositories/reference/linux-study-clean/kernel/trace/trace_hwlat.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/trace_hwlat.c- Extension
.c- Size
- 22360 bytes
- Lines
- 888
- 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.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kthread.hlinux/tracefs.hlinux/uaccess.hlinux/cpumask.hlinux/delay.hlinux/sched/clock.htrace.h
Detected Declarations
struct hwlat_kthread_datastruct hwlat_samplefunction trace_hwlat_samplefunction trace_hwlat_callbackfunction trace_clock_localfunction TSCfunction move_to_next_cpufunction runningfunction stop_single_kthreadfunction counterfunction stop_cpu_kthreadfunction stop_per_cpu_kthreadsfunction start_cpu_kthreadfunction hwlat_hotplug_workfnfunction hwlat_cpu_initfunction hwlat_cpu_diefunction hwlat_init_hotplug_supportfunction hwlat_init_hotplug_supportfunction counterfunction for_each_cpufunction s_mode_showfunction s_mode_stopfunction hwlat_mode_openfunction hwlat_mode_writefunction init_tracefsfunction hwlat_tracer_startfunction hwlat_tracer_stopfunction hwlat_tracer_initfunction hwlat_tracer_resetfunction init_hwlat_tracer
Annotated Snippet
static const struct file_operations thread_mode_fops = {
.open = hwlat_mode_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
.write = hwlat_mode_write
};
/**
* init_tracefs - A function to initialize the tracefs interface files
*
* This function creates entries in tracefs for "hwlat_detector".
* It creates the hwlat_detector directory in the tracing directory,
* and within that directory is the count, width and window files to
* change and view those values.
*/
static int init_tracefs(void)
{
int ret;
struct dentry *top_dir;
ret = tracing_init_dentry();
if (ret)
return -ENOMEM;
top_dir = tracefs_create_dir("hwlat_detector", NULL);
if (!top_dir)
return -ENOMEM;
hwlat_sample_window = tracefs_create_file("window", TRACE_MODE_WRITE,
top_dir,
&hwlat_window,
&trace_min_max_fops);
if (!hwlat_sample_window)
goto err;
hwlat_sample_width = tracefs_create_file("width", TRACE_MODE_WRITE,
top_dir,
&hwlat_width,
&trace_min_max_fops);
if (!hwlat_sample_width)
goto err;
hwlat_thread_mode = trace_create_file("mode", TRACE_MODE_WRITE,
top_dir,
NULL,
&thread_mode_fops);
if (!hwlat_thread_mode)
goto err;
return 0;
err:
tracefs_remove(top_dir);
return -ENOMEM;
}
static void hwlat_tracer_start(struct trace_array *tr)
{
int err;
if (hwlat_data.thread_mode == MODE_PER_CPU)
err = start_per_cpu_kthreads(tr);
else
err = start_single_kthread(tr);
if (err)
pr_err(BANNER "Cannot start hwlat kthread\n");
}
static void hwlat_tracer_stop(struct trace_array *tr)
{
if (hwlat_data.thread_mode == MODE_PER_CPU)
stop_per_cpu_kthreads();
else
stop_single_kthread();
}
static int hwlat_tracer_init(struct trace_array *tr)
{
/* Only allow one instance to enable this */
if (hwlat_busy)
return -EBUSY;
hwlat_trace = tr;
atomic64_set(&hwlat_data.count, 0);
tr->max_latency = 0;
save_tracing_thresh = tracing_thresh;
/* tracing_thresh is in nsecs, we speak in usecs */
if (!tracing_thresh)
Annotation
- Immediate include surface: `linux/kthread.h`, `linux/tracefs.h`, `linux/uaccess.h`, `linux/cpumask.h`, `linux/delay.h`, `linux/sched/clock.h`, `trace.h`.
- Detected declarations: `struct hwlat_kthread_data`, `struct hwlat_sample`, `function trace_hwlat_sample`, `function trace_hwlat_callback`, `function trace_clock_local`, `function TSC`, `function move_to_next_cpu`, `function running`, `function stop_single_kthread`, `function counter`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: pattern 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.