oprofile_files.c 2.48 KB
Newer Older
John Levon's avatar
John Levon committed
1 2 3 4 5 6 7 8 9 10
/**
 * @file oprofile_files.c
 *
 * @remark Copyright 2002 OProfile authors
 * @remark Read the file COPYING
 *
 * @author John Levon <levon@movementarian.org>
 */

#include <linux/fs.h>
John Levon's avatar
John Levon committed
11 12
#include <linux/oprofile.h>

John Levon's avatar
John Levon committed
13 14
#include "event_buffer.h"
#include "oprofile_stats.h"
John Levon's avatar
John Levon committed
15
#include "oprof.h"
John Levon's avatar
John Levon committed
16 17 18 19 20 21
 
unsigned long fs_buffer_size = 131072;
unsigned long fs_cpu_buffer_size = 8192;
unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */

 
22 23 24 25 26 27 28 29 30 31 32
static ssize_t pointer_size_read(struct file * file, char * buf, size_t count, loff_t * offset)
{
	return oprofilefs_ulong_to_user((unsigned long)sizeof(void *), buf, count, offset);
}


static struct file_operations pointer_size_fops = {
	.read		= pointer_size_read,
};


John Levon's avatar
John Levon committed
33 34
static ssize_t cpu_type_read(struct file * file, char * buf, size_t count, loff_t * offset)
{
35
	return oprofilefs_str_to_user(oprofile_ops->cpu_type, buf, count, offset);
John Levon's avatar
John Levon committed
36 37 38 39 40 41 42 43 44 45
}
 
 
static struct file_operations cpu_type_fops = {
	.read		= cpu_type_read,
};
 
 
static ssize_t enable_read(struct file * file, char * buf, size_t count, loff_t * offset)
{
46
	return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
John Levon's avatar
John Levon committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
}


static ssize_t enable_write(struct file *file, char const * buf, size_t count, loff_t * offset)
{
	unsigned long val;
	int retval;

	if (*offset)
		return -EINVAL;

	retval = oprofilefs_ulong_from_user(&val, buf, count);
	if (retval)
		return retval;
 
	if (val)
		retval = oprofile_start();
	else
		oprofile_stop();

	if (retval)
		return retval;
	return count;
}

 
static struct file_operations enable_fops = {
	.read		= enable_read,
	.write		= enable_write,
};

John Levon's avatar
John Levon committed
78 79 80 81 82 83 84 85 86 87 88

static ssize_t dump_write(struct file *file, char const * buf, size_t count, loff_t * offset)
{
	wake_up_buffer_waiter();
	return count;
}


static struct file_operations dump_fops = {
	.write		= dump_write,
};
John Levon's avatar
John Levon committed
89 90 91 92
 
void oprofile_create_files(struct super_block * sb, struct dentry * root)
{
	oprofilefs_create_file(sb, root, "enable", &enable_fops);
John Levon's avatar
John Levon committed
93
	oprofilefs_create_file(sb, root, "dump", &dump_fops);
John Levon's avatar
John Levon committed
94 95 96 97 98
	oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
	oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
	oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
	oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
	oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops); 
99
	oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
John Levon's avatar
John Levon committed
100 101 102 103
	oprofile_create_stats_files(sb, root);
	if (oprofile_ops->create_files)
		oprofile_ops->create_files(sb, root);
}