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