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