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