amd64_edac: add F10h-and-later methods-p3
[linux-2.6] / drivers / s390 / cio / qdio_perf.c
1 /*
2  *  drivers/s390/cio/qdio_perf.c
3  *
4  *  Copyright IBM Corp. 2008
5  *
6  *  Author: Jan Glauber (jang@linux.vnet.ibm.com)
7  */
8 #include <linux/kernel.h>
9 #include <linux/proc_fs.h>
10 #include <linux/seq_file.h>
11 #include <asm/ccwdev.h>
12
13 #include "cio.h"
14 #include "css.h"
15 #include "device.h"
16 #include "ioasm.h"
17 #include "chsc.h"
18 #include "qdio_debug.h"
19 #include "qdio_perf.h"
20
21 int qdio_performance_stats;
22 struct qdio_perf_stats perf_stats;
23
24 #ifdef CONFIG_PROC_FS
25 static struct proc_dir_entry *qdio_perf_pde;
26 #endif
27
28 inline void qdio_perf_stat_inc(atomic_long_t *count)
29 {
30         if (qdio_performance_stats)
31                 atomic_long_inc(count);
32 }
33
34 inline void qdio_perf_stat_dec(atomic_long_t *count)
35 {
36         if (qdio_performance_stats)
37                 atomic_long_dec(count);
38 }
39
40 /*
41  * procfs functions
42  */
43 static int qdio_perf_proc_show(struct seq_file *m, void *v)
44 {
45         seq_printf(m, "Number of qdio interrupts\t\t\t: %li\n",
46                    (long)atomic_long_read(&perf_stats.qdio_int));
47         seq_printf(m, "Number of PCI interrupts\t\t\t: %li\n",
48                    (long)atomic_long_read(&perf_stats.pci_int));
49         seq_printf(m, "Number of adapter interrupts\t\t\t: %li\n",
50                    (long)atomic_long_read(&perf_stats.thin_int));
51         seq_printf(m, "\n");
52         seq_printf(m, "Inbound tasklet runs\t\t\t\t: %li\n",
53                    (long)atomic_long_read(&perf_stats.tasklet_inbound));
54         seq_printf(m, "Outbound tasklet runs\t\t\t\t: %li\n",
55                    (long)atomic_long_read(&perf_stats.tasklet_outbound));
56         seq_printf(m, "Adapter interrupt tasklet runs/loops\t\t: %li/%li\n",
57                    (long)atomic_long_read(&perf_stats.tasklet_thinint),
58                    (long)atomic_long_read(&perf_stats.tasklet_thinint_loop));
59         seq_printf(m, "Adapter interrupt inbound tasklet runs/loops\t: %li/%li\n",
60                    (long)atomic_long_read(&perf_stats.thinint_inbound),
61                    (long)atomic_long_read(&perf_stats.thinint_inbound_loop));
62         seq_printf(m, "\n");
63         seq_printf(m, "Number of SIGA In issued\t\t\t: %li\n",
64                    (long)atomic_long_read(&perf_stats.siga_in));
65         seq_printf(m, "Number of SIGA Out issued\t\t\t: %li\n",
66                    (long)atomic_long_read(&perf_stats.siga_out));
67         seq_printf(m, "Number of SIGA Sync issued\t\t\t: %li\n",
68                    (long)atomic_long_read(&perf_stats.siga_sync));
69         seq_printf(m, "\n");
70         seq_printf(m, "Number of inbound transfers\t\t\t: %li\n",
71                    (long)atomic_long_read(&perf_stats.inbound_handler));
72         seq_printf(m, "Number of outbound transfers\t\t\t: %li\n",
73                    (long)atomic_long_read(&perf_stats.outbound_handler));
74         seq_printf(m, "\n");
75         seq_printf(m, "Number of fast requeues (outg. SBAL w/o SIGA)\t: %li\n",
76                    (long)atomic_long_read(&perf_stats.fast_requeue));
77         seq_printf(m, "Number of outbound target full condition\t: %li\n",
78                    (long)atomic_long_read(&perf_stats.outbound_target_full));
79         seq_printf(m, "Number of outbound tasklet mod_timer calls\t: %li\n",
80                    (long)atomic_long_read(&perf_stats.debug_tl_out_timer));
81         seq_printf(m, "Number of stop polling calls\t\t\t: %li\n",
82                    (long)atomic_long_read(&perf_stats.debug_stop_polling));
83         seq_printf(m, "AI inbound tasklet loops after stop polling\t: %li\n",
84                    (long)atomic_long_read(&perf_stats.thinint_inbound_loop2));
85         seq_printf(m, "QEBSM EQBS total/incomplete\t\t\t: %li/%li\n",
86                    (long)atomic_long_read(&perf_stats.debug_eqbs_all),
87                    (long)atomic_long_read(&perf_stats.debug_eqbs_incomplete));
88         seq_printf(m, "QEBSM SQBS total/incomplete\t\t\t: %li/%li\n",
89                    (long)atomic_long_read(&perf_stats.debug_sqbs_all),
90                    (long)atomic_long_read(&perf_stats.debug_sqbs_incomplete));
91         seq_printf(m, "\n");
92         return 0;
93 }
94 static int qdio_perf_seq_open(struct inode *inode, struct file *filp)
95 {
96         return single_open(filp, qdio_perf_proc_show, NULL);
97 }
98
99 static struct file_operations qdio_perf_proc_fops = {
100         .owner   = THIS_MODULE,
101         .open    = qdio_perf_seq_open,
102         .read    = seq_read,
103         .llseek  = seq_lseek,
104         .release = single_release,
105 };
106
107 /*
108  * sysfs functions
109  */
110 static ssize_t qdio_perf_stats_show(struct bus_type *bus, char *buf)
111 {
112         return sprintf(buf, "%i\n", qdio_performance_stats ? 1 : 0);
113 }
114
115 static ssize_t qdio_perf_stats_store(struct bus_type *bus,
116                               const char *buf, size_t count)
117 {
118         unsigned long i;
119
120         if (strict_strtoul(buf, 16, &i) != 0)
121                 return -EINVAL;
122         if ((i != 0) && (i != 1))
123                 return -EINVAL;
124         if (i == qdio_performance_stats)
125                 return count;
126
127         qdio_performance_stats = i;
128         /* reset performance statistics */
129         if (i == 0)
130                 memset(&perf_stats, 0, sizeof(struct qdio_perf_stats));
131         return count;
132 }
133
134 static BUS_ATTR(qdio_performance_stats, 0644, qdio_perf_stats_show,
135                 qdio_perf_stats_store);
136
137 int __init qdio_setup_perf_stats(void)
138 {
139         int rc;
140
141         rc = bus_create_file(&ccw_bus_type, &bus_attr_qdio_performance_stats);
142         if (rc)
143                 return rc;
144
145 #ifdef CONFIG_PROC_FS
146         memset(&perf_stats, 0, sizeof(struct qdio_perf_stats));
147         qdio_perf_pde = proc_create("qdio_perf", S_IFREG | S_IRUGO,
148                                     NULL, &qdio_perf_proc_fops);
149 #endif
150         return 0;
151 }
152
153 void qdio_remove_perf_stats(void)
154 {
155 #ifdef CONFIG_PROC_FS
156         remove_proc_entry("qdio_perf", NULL);
157 #endif
158         bus_remove_file(&ccw_bus_type, &bus_attr_qdio_performance_stats);
159 }