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