2 * arch/s390/oprofile/init.c
5 * Copyright (C) 2003 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Thomas Spatzier (tspat@de.ibm.com)
7 * Author(s): Mahesh Salgaonkar (mahesh@linux.vnet.ibm.com)
8 * Author(s): Heinz Graalfs (graalfs@linux.vnet.ibm.com)
10 * @remark Copyright 2002-2011 OProfile authors
13 #include <linux/oprofile.h>
14 #include <linux/init.h>
15 #include <linux/errno.h>
16 #include <linux/oprofile.h>
17 #include <linux/errno.h>
20 #include "../../../drivers/oprofile/oprof.h"
21 #include "hwsampler.h"
23 #define DEFAULT_INTERVAL 4096
25 #define DEFAULT_SDBT_BLOCKS 1
26 #define DEFAULT_SDB_BLOCKS 511
28 static unsigned long oprofile_hw_interval = DEFAULT_INTERVAL;
29 static unsigned long oprofile_min_interval;
30 static unsigned long oprofile_max_interval;
32 static unsigned long oprofile_sdbt_blocks = DEFAULT_SDBT_BLOCKS;
33 static unsigned long oprofile_sdb_blocks = DEFAULT_SDB_BLOCKS;
35 static int hwsampler_file;
36 static int hwsampler_running; /* start_mutex must be held to change */
38 static struct oprofile_operations timer_ops;
40 extern void s390_backtrace(struct pt_regs * const regs, unsigned int depth);
42 static int oprofile_hwsampler_start(void)
46 hwsampler_running = hwsampler_file;
48 if (!hwsampler_running)
49 return timer_ops.start();
51 retval = hwsampler_allocate(oprofile_sdbt_blocks, oprofile_sdb_blocks);
55 retval = hwsampler_start_all(oprofile_hw_interval);
57 hwsampler_deallocate();
62 static void oprofile_hwsampler_stop(void)
64 if (!hwsampler_running) {
70 hwsampler_deallocate();
74 static ssize_t hwsampler_read(struct file *file, char __user *buf,
75 size_t count, loff_t *offset)
77 return oprofilefs_ulong_to_user(hwsampler_file, buf, count, offset);
80 static ssize_t hwsampler_write(struct file *file, char const __user *buf,
81 size_t count, loff_t *offset)
89 retval = oprofilefs_ulong_from_user(&val, buf, count);
95 * save to do without locking as we set
96 * hwsampler_running in start() when start_mutex is
101 hwsampler_file = val;
106 static const struct file_operations hwsampler_fops = {
107 .read = hwsampler_read,
108 .write = hwsampler_write,
111 static int oprofile_create_hwsampling_files(struct super_block *sb,
114 struct dentry *hw_dir;
116 /* reinitialize default values */
119 hw_dir = oprofilefs_mkdir(sb, root, "hwsampling");
123 oprofilefs_create_file(sb, hw_dir, "hwsampler", &hwsampler_fops);
124 oprofilefs_create_ulong(sb, hw_dir, "hw_interval",
125 &oprofile_hw_interval);
126 oprofilefs_create_ro_ulong(sb, hw_dir, "hw_min_interval",
127 &oprofile_min_interval);
128 oprofilefs_create_ro_ulong(sb, hw_dir, "hw_max_interval",
129 &oprofile_max_interval);
130 oprofilefs_create_ulong(sb, hw_dir, "hw_sdbt_blocks",
131 &oprofile_sdbt_blocks);
136 static int oprofile_hwsampler_init(struct oprofile_operations *ops)
138 if (hwsampler_setup())
142 * create hwsampler files only if hwsampler_setup() succeeds.
144 oprofile_min_interval = hwsampler_query_min_interval();
145 if (oprofile_min_interval < 0) {
146 oprofile_min_interval = 0;
149 oprofile_max_interval = hwsampler_query_max_interval();
150 if (oprofile_max_interval < 0) {
151 oprofile_max_interval = 0;
155 if (oprofile_timer_init(ops))
158 printk(KERN_INFO "oprofile: using hardware sampling\n");
160 memcpy(&timer_ops, ops, sizeof(timer_ops));
162 ops->start = oprofile_hwsampler_start;
163 ops->stop = oprofile_hwsampler_stop;
164 ops->create_files = oprofile_create_hwsampling_files;
169 static void oprofile_hwsampler_exit(void)
171 oprofile_timer_exit();
172 hwsampler_shutdown();
175 int __init oprofile_arch_init(struct oprofile_operations *ops)
177 ops->backtrace = s390_backtrace;
179 return oprofile_hwsampler_init(ops);
182 void oprofile_arch_exit(void)
184 oprofile_hwsampler_exit();