kernel/trace/trace_osnoise.c

Source file repositories/reference/linux-study-clean/kernel/trace/trace_osnoise.c

File Facts

System
Linux kernel
Corpus path
kernel/trace/trace_osnoise.c
Extension
.c
Size
78502 bytes
Lines
3185
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.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations timerlat_fd_fops = {
	.open		= timerlat_fd_open,
	.read		= timerlat_fd_read,
	.release	= timerlat_fd_release,
	.llseek		= generic_file_llseek,
};
#endif

static const struct file_operations cpus_fops = {
	.open		= tracing_open_generic,
	.read		= osnoise_cpus_read,
	.write		= osnoise_cpus_write,
	.llseek		= generic_file_llseek,
};

static const struct file_operations osnoise_options_fops = {
	.open		= osnoise_options_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= seq_release,
	.write		= osnoise_options_write
};

#ifdef CONFIG_TIMERLAT_TRACER
#ifdef CONFIG_STACKTRACE
static int init_timerlat_stack_tracefs(struct dentry *top_dir)
{
	struct dentry *tmp;

	tmp = tracefs_create_file("print_stack", TRACE_MODE_WRITE, top_dir,
				  &osnoise_print_stack, &trace_min_max_fops);
	if (!tmp)
		return -ENOMEM;

	return 0;
}
#else /* CONFIG_STACKTRACE */
static int init_timerlat_stack_tracefs(struct dentry *top_dir)
{
	return 0;
}
#endif /* CONFIG_STACKTRACE */

static int osnoise_create_cpu_timerlat_fd(struct dentry *top_dir)
{
	struct dentry *timerlat_fd;
	struct dentry *per_cpu;
	struct dentry *cpu_dir;
	char cpu_str[30]; /* see trace.c: tracing_init_tracefs_percpu() */
	long cpu;

	/*
	 * Why not using tracing instance per_cpu/ dir?
	 *
	 * Because osnoise/timerlat have a single workload, having
	 * multiple files like these are waste of memory.
	 */
	per_cpu = tracefs_create_dir("per_cpu", top_dir);
	if (!per_cpu)
		return -ENOMEM;

	for_each_possible_cpu(cpu) {
		snprintf(cpu_str, 30, "cpu%ld", cpu);
		cpu_dir = tracefs_create_dir(cpu_str, per_cpu);
		if (!cpu_dir)
			goto out_clean;

		timerlat_fd = trace_create_file("timerlat_fd", TRACE_MODE_READ,
						cpu_dir, NULL, &timerlat_fd_fops);
		if (!timerlat_fd)
			goto out_clean;

		/* Record the CPU */
		d_inode(timerlat_fd)->i_cdev = (void *)(cpu);
	}

	return 0;

out_clean:
	tracefs_remove(per_cpu);
	return -ENOMEM;
}

/*
 * init_timerlat_tracefs - A function to initialize the timerlat interface files
 */
static int init_timerlat_tracefs(struct dentry *top_dir)
{
	struct dentry *tmp;
	int retval;

Annotation

Implementation Notes