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