Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[cascardo/linux.git] / drivers / staging / lustre / lustre / osc / lproc_osc.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #define DEBUG_SUBSYSTEM S_CLASS
37
38 #include <asm/statfs.h>
39 #include <obd_cksum.h>
40 #include <obd_class.h>
41 #include <lprocfs_status.h>
42 #include <linux/seq_file.h>
43 #include "osc_internal.h"
44
45 static int osc_active_seq_show(struct seq_file *m, void *v)
46 {
47         struct obd_device *dev = m->private;
48         int rc;
49
50         LPROCFS_CLIMP_CHECK(dev);
51         rc = seq_printf(m, "%d\n", !dev->u.cli.cl_import->imp_deactive);
52         LPROCFS_CLIMP_EXIT(dev);
53         return rc;
54 }
55
56 static ssize_t osc_active_seq_write(struct file *file, const char *buffer,
57                                     size_t count, loff_t *off)
58 {
59         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
60         int val, rc;
61
62         rc = lprocfs_write_helper(buffer, count, &val);
63         if (rc)
64                 return rc;
65         if (val < 0 || val > 1)
66                 return -ERANGE;
67
68         /* opposite senses */
69         if (dev->u.cli.cl_import->imp_deactive == val)
70                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
71         else
72                 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
73
74         return count;
75 }
76 LPROC_SEQ_FOPS(osc_active);
77
78 static int osc_max_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
79 {
80         struct obd_device *dev = m->private;
81         struct client_obd *cli = &dev->u.cli;
82         int rc;
83
84         client_obd_list_lock(&cli->cl_loi_list_lock);
85         rc = seq_printf(m, "%u\n", cli->cl_max_rpcs_in_flight);
86         client_obd_list_unlock(&cli->cl_loi_list_lock);
87         return rc;
88 }
89
90 static ssize_t osc_max_rpcs_in_flight_seq_write(struct file *file,
91                         const char *buffer, size_t count, loff_t *off)
92 {
93         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
94         struct client_obd *cli = &dev->u.cli;
95         struct ptlrpc_request_pool *pool = cli->cl_import->imp_rq_pool;
96         int val, rc;
97
98         rc = lprocfs_write_helper(buffer, count, &val);
99         if (rc)
100                 return rc;
101
102         if (val < 1 || val > OSC_MAX_RIF_MAX)
103                 return -ERANGE;
104
105         LPROCFS_CLIMP_CHECK(dev);
106         if (pool && val > cli->cl_max_rpcs_in_flight)
107                 pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
108
109         client_obd_list_lock(&cli->cl_loi_list_lock);
110         cli->cl_max_rpcs_in_flight = val;
111         client_obd_list_unlock(&cli->cl_loi_list_lock);
112
113         LPROCFS_CLIMP_EXIT(dev);
114         return count;
115 }
116 LPROC_SEQ_FOPS(osc_max_rpcs_in_flight);
117
118 static int osc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
119 {
120         struct obd_device *dev = m->private;
121         struct client_obd *cli = &dev->u.cli;
122         long val;
123         int mult;
124
125         client_obd_list_lock(&cli->cl_loi_list_lock);
126         val = cli->cl_dirty_max;
127         client_obd_list_unlock(&cli->cl_loi_list_lock);
128
129         mult = 1 << 20;
130         return lprocfs_seq_read_frac_helper(m, val, mult);
131 }
132
133 static ssize_t osc_max_dirty_mb_seq_write(struct file *file, const char *buffer,
134                                       size_t count, loff_t *off)
135 {
136         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
137         struct client_obd *cli = &dev->u.cli;
138         int pages_number, mult, rc;
139
140         mult = 1 << (20 - PAGE_CACHE_SHIFT);
141         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
142         if (rc)
143                 return rc;
144
145         if (pages_number <= 0 ||
146             pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_CACHE_SHIFT) ||
147             pages_number > totalram_pages / 4) /* 1/4 of RAM */
148                 return -ERANGE;
149
150         client_obd_list_lock(&cli->cl_loi_list_lock);
151         cli->cl_dirty_max = (obd_count)(pages_number << PAGE_CACHE_SHIFT);
152         osc_wake_cache_waiters(cli);
153         client_obd_list_unlock(&cli->cl_loi_list_lock);
154
155         return count;
156 }
157 LPROC_SEQ_FOPS(osc_max_dirty_mb);
158
159 static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
160 {
161         struct obd_device *dev = m->private;
162         struct client_obd *cli = &dev->u.cli;
163         int shift = 20 - PAGE_CACHE_SHIFT;
164         int rc;
165
166         rc = seq_printf(m,
167                       "used_mb: %d\n"
168                       "busy_cnt: %d\n",
169                       (atomic_read(&cli->cl_lru_in_list) +
170                         atomic_read(&cli->cl_lru_busy)) >> shift,
171                       atomic_read(&cli->cl_lru_busy));
172
173         return rc;
174 }
175
176 /* shrink the number of caching pages to a specific number */
177 static ssize_t osc_cached_mb_seq_write(struct file *file, const char *buffer,
178                                    size_t count, loff_t *off)
179 {
180         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
181         struct client_obd *cli = &dev->u.cli;
182         int pages_number, mult, rc;
183
184         mult = 1 << (20 - PAGE_CACHE_SHIFT);
185         buffer = lprocfs_find_named_value(buffer, "used_mb:", &count);
186         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
187         if (rc)
188                 return rc;
189
190         if (pages_number < 0)
191                 return -ERANGE;
192
193         rc = atomic_read(&cli->cl_lru_in_list) - pages_number;
194         if (rc > 0)
195                 (void)osc_lru_shrink(cli, rc);
196
197         return count;
198 }
199 LPROC_SEQ_FOPS(osc_cached_mb);
200
201 static int osc_cur_dirty_bytes_seq_show(struct seq_file *m, void *v)
202 {
203         struct obd_device *dev = m->private;
204         struct client_obd *cli = &dev->u.cli;
205         int rc;
206
207         client_obd_list_lock(&cli->cl_loi_list_lock);
208         rc = seq_printf(m, "%lu\n", cli->cl_dirty);
209         client_obd_list_unlock(&cli->cl_loi_list_lock);
210         return rc;
211 }
212 LPROC_SEQ_FOPS_RO(osc_cur_dirty_bytes);
213
214 static int osc_cur_grant_bytes_seq_show(struct seq_file *m, void *v)
215 {
216         struct obd_device *dev = m->private;
217         struct client_obd *cli = &dev->u.cli;
218         int rc;
219
220         client_obd_list_lock(&cli->cl_loi_list_lock);
221         rc = seq_printf(m, "%lu\n", cli->cl_avail_grant);
222         client_obd_list_unlock(&cli->cl_loi_list_lock);
223         return rc;
224 }
225
226 static ssize_t osc_cur_grant_bytes_seq_write(struct file *file, const char *buffer,
227                                   size_t count, loff_t *off)
228 {
229         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
230         struct client_obd *cli = &obd->u.cli;
231         int             rc;
232         __u64         val;
233
234         if (obd == NULL)
235                 return 0;
236
237         rc = lprocfs_write_u64_helper(buffer, count, &val);
238         if (rc)
239                 return rc;
240
241         /* this is only for shrinking grant */
242         client_obd_list_lock(&cli->cl_loi_list_lock);
243         if (val >= cli->cl_avail_grant) {
244                 client_obd_list_unlock(&cli->cl_loi_list_lock);
245                 return 0;
246         }
247         client_obd_list_unlock(&cli->cl_loi_list_lock);
248
249         LPROCFS_CLIMP_CHECK(obd);
250         if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
251                 rc = osc_shrink_grant_to_target(cli, val);
252         LPROCFS_CLIMP_EXIT(obd);
253         if (rc)
254                 return rc;
255         return count;
256 }
257 LPROC_SEQ_FOPS(osc_cur_grant_bytes);
258
259 static int osc_cur_lost_grant_bytes_seq_show(struct seq_file *m, void *v)
260 {
261         struct obd_device *dev = m->private;
262         struct client_obd *cli = &dev->u.cli;
263         int rc;
264
265         client_obd_list_lock(&cli->cl_loi_list_lock);
266         rc = seq_printf(m, "%lu\n", cli->cl_lost_grant);
267         client_obd_list_unlock(&cli->cl_loi_list_lock);
268         return rc;
269 }
270 LPROC_SEQ_FOPS_RO(osc_cur_lost_grant_bytes);
271
272 static int osc_grant_shrink_interval_seq_show(struct seq_file *m, void *v)
273 {
274         struct obd_device *obd = m->private;
275
276         if (obd == NULL)
277                 return 0;
278         return seq_printf(m, "%d\n",
279                         obd->u.cli.cl_grant_shrink_interval);
280 }
281
282 static ssize_t osc_grant_shrink_interval_seq_write(struct file *file,
283                                 const char *buffer, size_t count, loff_t *off)
284 {
285         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
286         int val, rc;
287
288         if (obd == NULL)
289                 return 0;
290
291         rc = lprocfs_write_helper(buffer, count, &val);
292         if (rc)
293                 return rc;
294
295         if (val <= 0)
296                 return -ERANGE;
297
298         obd->u.cli.cl_grant_shrink_interval = val;
299
300         return count;
301 }
302 LPROC_SEQ_FOPS(osc_grant_shrink_interval);
303
304 static int osc_checksum_seq_show(struct seq_file *m, void *v)
305 {
306         struct obd_device *obd = m->private;
307
308         if (obd == NULL)
309                 return 0;
310
311         return seq_printf(m, "%d\n",
312                         obd->u.cli.cl_checksum ? 1 : 0);
313 }
314
315 static ssize_t osc_checksum_seq_write(struct file *file, const char *buffer,
316                            size_t count, loff_t *off)
317 {
318         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
319         int val, rc;
320
321         if (obd == NULL)
322                 return 0;
323
324         rc = lprocfs_write_helper(buffer, count, &val);
325         if (rc)
326                 return rc;
327
328         obd->u.cli.cl_checksum = (val ? 1 : 0);
329
330         return count;
331 }
332 LPROC_SEQ_FOPS(osc_checksum);
333
334 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
335 {
336         struct obd_device *obd = m->private;
337         int i;
338         DECLARE_CKSUM_NAME;
339
340         if (obd == NULL)
341                 return 0;
342
343         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
344                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
345                         continue;
346                 if (obd->u.cli.cl_cksum_type == (1 << i))
347                         seq_printf(m, "[%s] ", cksum_name[i]);
348                 else
349                         seq_printf(m, "%s ", cksum_name[i]);
350         }
351         seq_printf(m, "\n");
352         return 0;
353 }
354
355 static ssize_t osc_checksum_type_seq_write(struct file *file, const char *buffer,
356                                 size_t count, loff_t *off)
357 {
358         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
359         int i;
360         DECLARE_CKSUM_NAME;
361         char kernbuf[10];
362
363         if (obd == NULL)
364                 return 0;
365
366         if (count > sizeof(kernbuf) - 1)
367                 return -EINVAL;
368         if (copy_from_user(kernbuf, buffer, count))
369                 return -EFAULT;
370         if (count > 0 && kernbuf[count - 1] == '\n')
371                 kernbuf[count - 1] = '\0';
372         else
373                 kernbuf[count] = '\0';
374
375         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
376                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
377                         continue;
378                 if (!strcmp(kernbuf, cksum_name[i])) {
379                        obd->u.cli.cl_cksum_type = 1 << i;
380                        return count;
381                 }
382         }
383         return -EINVAL;
384 }
385 LPROC_SEQ_FOPS(osc_checksum_type);
386
387 static int osc_resend_count_seq_show(struct seq_file *m, void *v)
388 {
389         struct obd_device *obd = m->private;
390
391         return seq_printf(m, "%u\n", atomic_read(&obd->u.cli.cl_resends));
392 }
393
394 static ssize_t osc_resend_count_seq_write(struct file *file, const char *buffer,
395                                size_t count, loff_t *off)
396 {
397         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
398         int val, rc;
399
400         rc = lprocfs_write_helper(buffer, count, &val);
401         if (rc)
402                 return rc;
403
404         if (val < 0)
405                return -EINVAL;
406
407         atomic_set(&obd->u.cli.cl_resends, val);
408
409         return count;
410 }
411 LPROC_SEQ_FOPS(osc_resend_count);
412
413 static int osc_contention_seconds_seq_show(struct seq_file *m, void *v)
414 {
415         struct obd_device *obd = m->private;
416         struct osc_device *od  = obd2osc_dev(obd);
417
418         return seq_printf(m, "%u\n", od->od_contention_time);
419 }
420
421 static ssize_t osc_contention_seconds_seq_write(struct file *file, const char *buffer,
422                                      size_t count, loff_t *off)
423 {
424         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
425         struct osc_device *od  = obd2osc_dev(obd);
426
427         return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
428                 count;
429 }
430 LPROC_SEQ_FOPS(osc_contention_seconds);
431
432 static int osc_lockless_truncate_seq_show(struct seq_file *m, void *v)
433 {
434         struct obd_device *obd = m->private;
435         struct osc_device *od  = obd2osc_dev(obd);
436
437         return seq_printf(m, "%u\n", od->od_lockless_truncate);
438 }
439
440 static ssize_t osc_lockless_truncate_seq_write(struct file *file, const char *buffer,
441                                     size_t count, loff_t *off)
442 {
443         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
444         struct osc_device *od  = obd2osc_dev(obd);
445
446         return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
447                 count;
448 }
449 LPROC_SEQ_FOPS(osc_lockless_truncate);
450
451 static int osc_destroys_in_flight_seq_show(struct seq_file *m, void *v)
452 {
453         struct obd_device *obd = m->private;
454         return seq_printf(m, "%u\n",
455                         atomic_read(&obd->u.cli.cl_destroy_in_flight));
456 }
457 LPROC_SEQ_FOPS_RO(osc_destroys_in_flight);
458
459 static int osc_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *v)
460 {
461         return lprocfs_obd_rd_max_pages_per_rpc(m, m->private);
462 }
463
464 static ssize_t osc_obd_max_pages_per_rpc_seq_write(struct file *file,
465                                 const char *buffer, size_t count, loff_t *off)
466 {
467         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
468         struct client_obd *cli = &dev->u.cli;
469         struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
470         int chunk_mask, rc;
471         __u64 val;
472
473         rc = lprocfs_write_u64_helper(buffer, count, &val);
474         if (rc)
475                 return rc;
476
477         /* if the max_pages is specified in bytes, convert to pages */
478         if (val >= ONE_MB_BRW_SIZE)
479                 val >>= PAGE_CACHE_SHIFT;
480
481         LPROCFS_CLIMP_CHECK(dev);
482
483         chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_CACHE_SHIFT)) - 1);
484         /* max_pages_per_rpc must be chunk aligned */
485         val = (val + ~chunk_mask) & chunk_mask;
486         if (val == 0 || val > ocd->ocd_brw_size >> PAGE_CACHE_SHIFT) {
487                 LPROCFS_CLIMP_EXIT(dev);
488                 return -ERANGE;
489         }
490         client_obd_list_lock(&cli->cl_loi_list_lock);
491         cli->cl_max_pages_per_rpc = val;
492         client_obd_list_unlock(&cli->cl_loi_list_lock);
493
494         LPROCFS_CLIMP_EXIT(dev);
495         return count;
496 }
497 LPROC_SEQ_FOPS(osc_obd_max_pages_per_rpc);
498
499 LPROC_SEQ_FOPS_RO_TYPE(osc, uuid);
500 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
501 LPROC_SEQ_FOPS_RO_TYPE(osc, blksize);
502 LPROC_SEQ_FOPS_RO_TYPE(osc, kbytestotal);
503 LPROC_SEQ_FOPS_RO_TYPE(osc, kbytesfree);
504 LPROC_SEQ_FOPS_RO_TYPE(osc, kbytesavail);
505 LPROC_SEQ_FOPS_RO_TYPE(osc, filestotal);
506 LPROC_SEQ_FOPS_RO_TYPE(osc, filesfree);
507 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
508 LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid);
509 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
510 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
511
512 LPROC_SEQ_FOPS_WR_ONLY(osc, ping);
513
514 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
515 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
516
517 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
518         { "uuid",            &osc_uuid_fops,    0, 0 },
519         { "ping",            &osc_ping_fops,    0, 0222 },
520         { "connect_flags",   &osc_connect_flags_fops, 0, 0 },
521         { "blocksize",       &osc_blksize_fops,     0, 0 },
522         { "kbytestotal",     &osc_kbytestotal_fops, 0, 0 },
523         { "kbytesfree",      &osc_kbytesfree_fops,  0, 0 },
524         { "kbytesavail",     &osc_kbytesavail_fops, 0, 0 },
525         { "filestotal",      &osc_filestotal_fops,  0, 0 },
526         { "filesfree",       &osc_filesfree_fops,   0, 0 },
527         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
528         { "ost_server_uuid", &osc_server_uuid_fops, 0, 0 },
529         { "ost_conn_uuid",   &osc_conn_uuid_fops, 0, 0 },
530         { "active",          &osc_active_fops, 0 },
531         { "max_pages_per_rpc", &osc_obd_max_pages_per_rpc_fops, 0 },
532         { "max_rpcs_in_flight", &osc_max_rpcs_in_flight_fops, 0 },
533         { "destroys_in_flight", &osc_destroys_in_flight_fops, 0, 0 },
534         { "max_dirty_mb",    &osc_max_dirty_mb_fops, 0 },
535         { "osc_cached_mb",   &osc_cached_mb_fops, 0 },
536         { "cur_dirty_bytes", &osc_cur_dirty_bytes_fops, 0, 0 },
537         { "cur_grant_bytes", &osc_cur_grant_bytes_fops, 0 },
538         { "cur_lost_grant_bytes", &osc_cur_lost_grant_bytes_fops, 0, 0},
539         { "grant_shrink_interval", &osc_grant_shrink_interval_fops, 0 },
540         { "checksums",       &osc_checksum_fops, 0 },
541         { "checksum_type",   &osc_checksum_type_fops, 0 },
542         { "resend_count",    &osc_resend_count_fops, 0},
543         { "timeouts",        &osc_timeouts_fops, 0, 0 },
544         { "contention_seconds", &osc_contention_seconds_fops, 0 },
545         { "lockless_truncate",  &osc_lockless_truncate_fops, 0 },
546         { "import",             &osc_import_fops, 0 },
547         { "state",              &osc_state_fops, 0, 0 },
548         { "pinger_recov",       &osc_pinger_recov_fops, 0 },
549         { 0 }
550 };
551
552 LPROC_SEQ_FOPS_RO_TYPE(osc, numrefs);
553 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
554         { "num_refs",   &osc_numrefs_fops,     0, 0 },
555         { 0 }
556 };
557
558 #define pct(a,b) (b ? a * 100 / b : 0)
559
560 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
561 {
562         struct timeval now;
563         struct obd_device *dev = seq->private;
564         struct client_obd *cli = &dev->u.cli;
565         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
566         int i;
567
568         do_gettimeofday(&now);
569
570         client_obd_list_lock(&cli->cl_loi_list_lock);
571
572         seq_printf(seq, "snapshot_time:  %lu.%lu (secs.usecs)\n",
573                    now.tv_sec, (unsigned long)now.tv_usec);
574         seq_printf(seq, "read RPCs in flight:  %d\n",
575                    cli->cl_r_in_flight);
576         seq_printf(seq, "write RPCs in flight: %d\n",
577                    cli->cl_w_in_flight);
578         seq_printf(seq, "pending write pages:  %d\n",
579                    atomic_read(&cli->cl_pending_w_pages));
580         seq_printf(seq, "pending read pages:   %d\n",
581                    atomic_read(&cli->cl_pending_r_pages));
582
583         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
584         seq_printf(seq, "pages per rpc   rpcs   %% cum %% |");
585         seq_printf(seq, "       rpcs   %% cum %%\n");
586
587         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
588         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
589
590         read_cum = 0;
591         write_cum = 0;
592         for (i = 0; i < OBD_HIST_MAX; i++) {
593                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
594                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
595                 read_cum += r;
596                 write_cum += w;
597                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
598                                  1 << i, r, pct(r, read_tot),
599                                  pct(read_cum, read_tot), w,
600                                  pct(w, write_tot),
601                                  pct(write_cum, write_tot));
602                 if (read_cum == read_tot && write_cum == write_tot)
603                         break;
604         }
605
606         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
607         seq_printf(seq, "rpcs in flight rpcs   %% cum %% |");
608         seq_printf(seq, "       rpcs   %% cum %%\n");
609
610         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
611         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
612
613         read_cum = 0;
614         write_cum = 0;
615         for (i = 0; i < OBD_HIST_MAX; i++) {
616                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
617                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
618                 read_cum += r;
619                 write_cum += w;
620                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
621                                  i, r, pct(r, read_tot),
622                                  pct(read_cum, read_tot), w,
623                                  pct(w, write_tot),
624                                  pct(write_cum, write_tot));
625                 if (read_cum == read_tot && write_cum == write_tot)
626                         break;
627         }
628
629         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
630         seq_printf(seq, "offset         rpcs   %% cum %% |");
631         seq_printf(seq, "       rpcs   %% cum %%\n");
632
633         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
634         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
635
636         read_cum = 0;
637         write_cum = 0;
638         for (i = 0; i < OBD_HIST_MAX; i++) {
639                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
640                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
641                 read_cum += r;
642                 write_cum += w;
643                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
644                            (i == 0) ? 0 : 1 << (i - 1),
645                            r, pct(r, read_tot), pct(read_cum, read_tot),
646                            w, pct(w, write_tot), pct(write_cum, write_tot));
647                 if (read_cum == read_tot && write_cum == write_tot)
648                         break;
649         }
650
651         client_obd_list_unlock(&cli->cl_loi_list_lock);
652
653         return 0;
654 }
655 #undef pct
656
657 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
658                                        size_t len, loff_t *off)
659 {
660         struct seq_file *seq = file->private_data;
661         struct obd_device *dev = seq->private;
662         struct client_obd *cli = &dev->u.cli;
663
664         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
665         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
666         lprocfs_oh_clear(&cli->cl_read_page_hist);
667         lprocfs_oh_clear(&cli->cl_write_page_hist);
668         lprocfs_oh_clear(&cli->cl_read_offset_hist);
669         lprocfs_oh_clear(&cli->cl_write_offset_hist);
670
671         return len;
672 }
673
674 LPROC_SEQ_FOPS(osc_rpc_stats);
675
676 static int osc_stats_seq_show(struct seq_file *seq, void *v)
677 {
678         struct timeval now;
679         struct obd_device *dev = seq->private;
680         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
681
682         do_gettimeofday(&now);
683
684         seq_printf(seq, "snapshot_time:  %lu.%lu (secs.usecs)\n",
685                    now.tv_sec, (unsigned long)now.tv_usec);
686         seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
687                    stats->os_lockless_writes);
688         seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
689                    stats->os_lockless_reads);
690         seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
691                    stats->os_lockless_truncates);
692         return 0;
693 }
694
695 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
696                                    size_t len, loff_t *off)
697 {
698         struct seq_file *seq = file->private_data;
699         struct obd_device *dev = seq->private;
700         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
701
702         memset(stats, 0, sizeof(*stats));
703         return len;
704 }
705
706 LPROC_SEQ_FOPS(osc_stats);
707
708 int lproc_osc_attach_seqstat(struct obd_device *dev)
709 {
710         int rc;
711
712         rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
713                                 &osc_stats_fops, dev);
714         if (rc == 0)
715                 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
716                                             &osc_rpc_stats_fops, dev);
717
718         return rc;
719 }
720
721 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
722 {
723         lvars->module_vars = lprocfs_osc_module_vars;
724         lvars->obd_vars    = lprocfs_osc_obd_vars;
725 }