]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/misc/sgi-gru/gruprocfs.c
X86: uv: implement a gru_read_gpa kernel function
[net-next-2.6.git] / drivers / misc / sgi-gru / gruprocfs.c
CommitLineData
1d09d737
JS
1/*
2 * SN Platform GRU Driver
3 *
4 * PROC INTERFACES
5 *
6 * This file supports the /proc interfaces for the GRU driver
7 *
8 * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <linux/proc_fs.h>
26#include <linux/device.h>
27#include <linux/seq_file.h>
28#include <linux/uaccess.h>
29#include "gru.h"
30#include "grulib.h"
31#include "grutables.h"
32
33#define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34
35static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36{
37 unsigned long val = atomic_long_read(v);
38
39 if (val)
40 seq_printf(s, "%16lu %s\n", val, id);
41}
42
43static int statistics_show(struct seq_file *s, void *p)
44{
45 printstat(s, vdata_alloc);
46 printstat(s, vdata_free);
47 printstat(s, gts_alloc);
48 printstat(s, gts_free);
49 printstat(s, vdata_double_alloc);
50 printstat(s, gts_double_allocate);
51 printstat(s, assign_context);
52 printstat(s, assign_context_failed);
53 printstat(s, free_context);
836ce679
JS
54 printstat(s, load_user_context);
55 printstat(s, load_kernel_context);
56 printstat(s, lock_kernel_context);
57 printstat(s, unlock_kernel_context);
58 printstat(s, steal_user_context);
59 printstat(s, steal_kernel_context);
1d09d737
JS
60 printstat(s, steal_context_failed);
61 printstat(s, nopfn);
62 printstat(s, break_cow);
63 printstat(s, asid_new);
64 printstat(s, asid_next);
65 printstat(s, asid_wrap);
66 printstat(s, asid_reuse);
67 printstat(s, intr);
43884604 68 printstat(s, intr_mm_lock_failed);
1d09d737 69 printstat(s, call_os);
43884604 70 printstat(s, call_os_offnode_reference);
1d09d737
JS
71 printstat(s, call_os_check_for_bug);
72 printstat(s, call_os_wait_queue);
73 printstat(s, user_flush_tlb);
74 printstat(s, user_unload_context);
75 printstat(s, user_exception);
92b39388 76 printstat(s, set_context_option);
1d09d737
JS
77 printstat(s, migrate_check);
78 printstat(s, migrated_retarget);
79 printstat(s, migrated_unload);
80 printstat(s, migrated_unload_delay);
81 printstat(s, migrated_nopfn_retarget);
82 printstat(s, migrated_nopfn_unload);
83 printstat(s, tlb_dropin);
84 printstat(s, tlb_dropin_fail_no_asid);
85 printstat(s, tlb_dropin_fail_upm);
86 printstat(s, tlb_dropin_fail_invalid);
87 printstat(s, tlb_dropin_fail_range_active);
88 printstat(s, tlb_dropin_fail_idle);
89 printstat(s, tlb_dropin_fail_fmm);
cd1334f0
JS
90 printstat(s, tlb_dropin_fail_no_exception);
91 printstat(s, tlb_dropin_fail_no_exception_war);
270952a9 92 printstat(s, tfh_stale_on_fault);
1d09d737
JS
93 printstat(s, mmu_invalidate_range);
94 printstat(s, mmu_invalidate_page);
95 printstat(s, mmu_clear_flush_young);
96 printstat(s, flush_tlb);
97 printstat(s, flush_tlb_gru);
98 printstat(s, flush_tlb_gru_tgh);
99 printstat(s, flush_tlb_gru_zero_asid);
100 printstat(s, copy_gpa);
289750d1 101 printstat(s, read_gpa);
1d09d737
JS
102 printstat(s, mesq_receive);
103 printstat(s, mesq_receive_none);
104 printstat(s, mesq_send);
105 printstat(s, mesq_send_failed);
106 printstat(s, mesq_noop);
107 printstat(s, mesq_send_unexpected_error);
108 printstat(s, mesq_send_lb_overflow);
109 printstat(s, mesq_send_qlimit_reached);
110 printstat(s, mesq_send_amo_nacked);
111 printstat(s, mesq_send_put_nacked);
112 printstat(s, mesq_qf_not_full);
113 printstat(s, mesq_qf_locked);
114 printstat(s, mesq_qf_noop_not_full);
115 printstat(s, mesq_qf_switch_head_failed);
116 printstat(s, mesq_qf_unexpected_error);
117 printstat(s, mesq_noop_unexpected_error);
118 printstat(s, mesq_noop_lb_overflow);
119 printstat(s, mesq_noop_qlimit_reached);
120 printstat(s, mesq_noop_amo_nacked);
121 printstat(s, mesq_noop_put_nacked);
122 return 0;
123}
124
125static ssize_t statistics_write(struct file *file, const char __user *userbuf,
126 size_t count, loff_t *data)
127{
128 memset(&gru_stats, 0, sizeof(gru_stats));
129 return count;
130}
131
e56484da
JS
132static int mcs_statistics_show(struct seq_file *s, void *p)
133{
134 int op;
135 unsigned long total, count, max;
136 static char *id[] = {"cch_allocate", "cch_start", "cch_interrupt",
137 "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"};
138
139 for (op = 0; op < mcsop_last; op++) {
140 count = atomic_long_read(&mcs_op_statistics[op].count);
141 total = atomic_long_read(&mcs_op_statistics[op].total);
142 max = mcs_op_statistics[op].max;
143 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
144 count ? total / count : 0, max);
145 }
146 return 0;
147}
148
149static ssize_t mcs_statistics_write(struct file *file,
150 const char __user *userbuf, size_t count, loff_t *data)
151{
152 memset(mcs_op_statistics, 0, sizeof(mcs_op_statistics));
153 return count;
154}
155
1d09d737
JS
156static int options_show(struct seq_file *s, void *p)
157{
9ca8e40c 158 seq_printf(s, "0x%lx\n", gru_options);
1d09d737
JS
159 return 0;
160}
161
162static ssize_t options_write(struct file *file, const char __user *userbuf,
163 size_t count, loff_t *data)
164{
d39b7dd1 165 char buf[20];
1d09d737 166
d39b7dd1
LT
167 if (count >= sizeof(buf))
168 return -EINVAL;
169 if (copy_from_user(buf, userbuf, count))
1d09d737 170 return -EFAULT;
d39b7dd1
LT
171 buf[count] = '\0';
172 if (strict_strtoul(buf, 0, &gru_options))
173 return -EINVAL;
1d09d737
JS
174
175 return count;
176}
177
178static int cch_seq_show(struct seq_file *file, void *data)
179{
180 long gid = *(long *)data;
181 int i;
182 struct gru_state *gru = GID_TO_GRU(gid);
183 struct gru_thread_state *ts;
184 const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" };
185
186 if (gid == 0)
187 seq_printf(file, "#%5s%5s%6s%9s%6s%8s%8s\n", "gid", "bid",
188 "ctx#", "pid", "cbrs", "dsbytes", "mode");
189 if (gru)
190 for (i = 0; i < GRU_NUM_CCH; i++) {
191 ts = gru->gs_gts[i];
192 if (!ts)
193 continue;
194 seq_printf(file, " %5d%5d%6d%9d%6d%8d%8s\n",
195 gru->gs_gid, gru->gs_blade_id, i,
196 ts->ts_tgid_owner,
197 ts->ts_cbr_au_count * GRU_CBR_AU_SIZE,
198 ts->ts_cbr_au_count * GRU_DSR_AU_BYTES,
199 mode[ts->ts_user_options &
200 GRU_OPT_MISS_MASK]);
201 }
202
203 return 0;
204}
205
206static int gru_seq_show(struct seq_file *file, void *data)
207{
208 long gid = *(long *)data, ctxfree, cbrfree, dsrfree;
209 struct gru_state *gru = GID_TO_GRU(gid);
210
211 if (gid == 0) {
212 seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "gid", "nid",
213 "ctx", "cbr", "dsr", "ctx", "cbr", "dsr");
214 seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "", "", "busy",
215 "busy", "busy", "free", "free", "free");
216 }
217 if (gru) {
218 ctxfree = GRU_NUM_CCH - gru->gs_active_contexts;
219 cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE;
220 dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES;
221 seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n",
222 gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree,
223 GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree,
224 ctxfree, cbrfree, dsrfree);
225 }
226
227 return 0;
228}
229
230static void seq_stop(struct seq_file *file, void *data)
231{
232}
233
234static void *seq_start(struct seq_file *file, loff_t *gid)
235{
e1c3219d 236 if (*gid < gru_max_gids)
1d09d737
JS
237 return gid;
238 return NULL;
239}
240
241static void *seq_next(struct seq_file *file, void *data, loff_t *gid)
242{
243 (*gid)++;
e1c3219d 244 if (*gid < gru_max_gids)
1d09d737
JS
245 return gid;
246 return NULL;
247}
248
249static const struct seq_operations cch_seq_ops = {
250 .start = seq_start,
251 .next = seq_next,
252 .stop = seq_stop,
253 .show = cch_seq_show
254};
255
256static const struct seq_operations gru_seq_ops = {
257 .start = seq_start,
258 .next = seq_next,
259 .stop = seq_stop,
260 .show = gru_seq_show
261};
262
263static int statistics_open(struct inode *inode, struct file *file)
264{
265 return single_open(file, statistics_show, NULL);
266}
267
e56484da
JS
268static int mcs_statistics_open(struct inode *inode, struct file *file)
269{
270 return single_open(file, mcs_statistics_show, NULL);
271}
272
1d09d737
JS
273static int options_open(struct inode *inode, struct file *file)
274{
275 return single_open(file, options_show, NULL);
276}
277
278static int cch_open(struct inode *inode, struct file *file)
279{
280 return seq_open(file, &cch_seq_ops);
281}
282
283static int gru_open(struct inode *inode, struct file *file)
284{
285 return seq_open(file, &gru_seq_ops);
286}
287
288/* *INDENT-OFF* */
289static const struct file_operations statistics_fops = {
290 .open = statistics_open,
291 .read = seq_read,
292 .write = statistics_write,
293 .llseek = seq_lseek,
294 .release = single_release,
295};
296
e56484da
JS
297static const struct file_operations mcs_statistics_fops = {
298 .open = mcs_statistics_open,
299 .read = seq_read,
300 .write = mcs_statistics_write,
301 .llseek = seq_lseek,
302 .release = single_release,
303};
304
1d09d737
JS
305static const struct file_operations options_fops = {
306 .open = options_open,
307 .read = seq_read,
308 .write = options_write,
309 .llseek = seq_lseek,
310 .release = single_release,
311};
312
313static const struct file_operations cch_fops = {
314 .open = cch_open,
315 .read = seq_read,
316 .llseek = seq_lseek,
317 .release = seq_release,
318};
319static const struct file_operations gru_fops = {
320 .open = gru_open,
321 .read = seq_read,
322 .llseek = seq_lseek,
323 .release = seq_release,
324};
325
326static struct proc_entry {
327 char *name;
328 int mode;
329 const struct file_operations *fops;
330 struct proc_dir_entry *entry;
331} proc_files[] = {
332 {"statistics", 0644, &statistics_fops},
e56484da 333 {"mcs_statistics", 0644, &mcs_statistics_fops},
1d09d737
JS
334 {"debug_options", 0644, &options_fops},
335 {"cch_status", 0444, &cch_fops},
336 {"gru_status", 0444, &gru_fops},
337 {NULL}
338};
339/* *INDENT-ON* */
340
341static struct proc_dir_entry *proc_gru __read_mostly;
342
343static int create_proc_file(struct proc_entry *p)
344{
f8679af8 345 p->entry = proc_create(p->name, p->mode, proc_gru, p->fops);
1d09d737
JS
346 if (!p->entry)
347 return -1;
1d09d737
JS
348 return 0;
349}
350
351static void delete_proc_files(void)
352{
353 struct proc_entry *p;
354
355 if (proc_gru) {
356 for (p = proc_files; p->name; p++)
357 if (p->entry)
358 remove_proc_entry(p->name, proc_gru);
359 remove_proc_entry("gru", NULL);
360 }
361}
362
363int gru_proc_init(void)
364{
365 struct proc_entry *p;
366
1d09d737
JS
367 proc_gru = proc_mkdir("sgi_uv/gru", NULL);
368
369 for (p = proc_files; p->name; p++)
370 if (create_proc_file(p))
371 goto err;
372 return 0;
373
374err:
375 delete_proc_files();
376 return -1;
377}
378
379void gru_proc_exit(void)
380{
381 delete_proc_files();
382}