Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * @file oprofile_files.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * @remark Copyright 2002 OProfile authors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * @remark Read the file COPYING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * @author John Levon <levon@movementarian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/oprofile.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "event_buffer.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "oprofile_stats.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "oprof.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define BUFFER_SIZE_DEFAULT		131072
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define CPU_BUFFER_SIZE_DEFAULT		8192
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define BUFFER_WATERSHED_DEFAULT	32768	/* FIXME: tune */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define TIME_SLICE_DEFAULT		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) unsigned long oprofile_buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) unsigned long oprofile_cpu_buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) unsigned long oprofile_buffer_watershed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) unsigned long oprofile_time_slice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static ssize_t timeout_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 					buf, count, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static ssize_t timeout_write(struct file *file, char const __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (*offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	retval = oprofilefs_ulong_from_user(&val, buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (retval <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	retval = oprofile_set_timeout(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static const struct file_operations timeout_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	.read		= timeout_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	.write		= timeout_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	.llseek		= default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 					offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (*offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (!oprofile_ops.backtrace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	retval = oprofilefs_ulong_from_user(&val, buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (retval <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	retval = oprofile_set_ulong(&oprofile_backtrace_depth, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static const struct file_operations depth_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	.read		= depth_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	.write		= depth_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	.llseek		= default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static ssize_t pointer_size_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	return oprofilefs_ulong_to_user(sizeof(void *), buf, count, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static const struct file_operations pointer_size_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	.read		= pointer_size_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	.llseek		= default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static ssize_t cpu_type_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return oprofilefs_str_to_user(oprofile_ops.cpu_type, buf, count, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static const struct file_operations cpu_type_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.read		= cpu_type_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	.llseek		= default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (*offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	retval = oprofilefs_ulong_from_user(&val, buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (retval <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		retval = oprofile_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		oprofile_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static const struct file_operations enable_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	.read		= enable_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	.write		= enable_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	.llseek		= default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static ssize_t dump_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	wake_up_buffer_waiter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static const struct file_operations dump_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	.write		= dump_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	.llseek		= noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) void oprofile_create_files(struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	/* reinitialize default values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	oprofile_buffer_size =		BUFFER_SIZE_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	oprofile_cpu_buffer_size =	CPU_BUFFER_SIZE_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	oprofile_buffer_watershed =	BUFFER_WATERSHED_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	oprofile_time_slice =		msecs_to_jiffies(TIME_SLICE_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	oprofilefs_create_file(root, "enable", &enable_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	oprofilefs_create_file_perm(root, "dump", &dump_fops, 0666);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	oprofilefs_create_file(root, "buffer", &event_buffer_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	oprofilefs_create_ulong(root, "buffer_size", &oprofile_buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	oprofilefs_create_ulong(root, "buffer_watershed", &oprofile_buffer_watershed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	oprofilefs_create_ulong(root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	oprofilefs_create_file(root, "cpu_type", &cpu_type_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	oprofilefs_create_file(root, "backtrace_depth", &depth_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	oprofilefs_create_file(root, "pointer_size", &pointer_size_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	oprofilefs_create_file(root, "time_slice", &timeout_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	oprofile_create_stats_files(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (oprofile_ops.create_files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		oprofile_ops.create_files(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }