Whamcloud - gitweb
LU-8475 target: use slab allocation
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32 #define DEBUG_SUBSYSTEM S_CLASS
33
34 #include <linux/version.h>
35 #include <asm/statfs.h>
36 #include <obd_cksum.h>
37 #include <obd_class.h>
38 #include <lprocfs_status.h>
39 #include <linux/seq_file.h>
40 #include <lustre_osc.h>
41
42 #include "osc_internal.h"
43
44 #ifdef CONFIG_PROC_FS
45 static int osc_active_seq_show(struct seq_file *m, void *v)
46 {
47         struct obd_device *dev = m->private;
48
49         LPROCFS_CLIMP_CHECK(dev);
50         seq_printf(m, "%d\n", !dev->u.cli.cl_import->imp_deactive);
51         LPROCFS_CLIMP_EXIT(dev);
52         return 0;
53 }
54
55 static ssize_t osc_active_seq_write(struct file *file,
56                                     const char __user *buffer,
57                                     size_t count, loff_t *off)
58 {
59         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
60         int rc;
61         __s64 val;
62
63         rc = lprocfs_str_to_s64(buffer, count, &val);
64         if (rc)
65                 return rc;
66         if (val < 0 || val > 1)
67                 return -ERANGE;
68
69         /* opposite senses */
70         if (dev->u.cli.cl_import->imp_deactive == val)
71                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
72         else
73                 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n",
74                         (int)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
85         spin_lock(&cli->cl_loi_list_lock);
86         seq_printf(m, "%u\n", cli->cl_max_rpcs_in_flight);
87         spin_unlock(&cli->cl_loi_list_lock);
88         return 0;
89 }
90
91 static ssize_t osc_max_rpcs_in_flight_seq_write(struct file *file,
92                                                 const char __user *buffer,
93                                                 size_t count, loff_t *off)
94 {
95         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
96         struct client_obd *cli = &dev->u.cli;
97         int rc;
98         int adding, added, req_count;
99         __s64 val;
100
101         rc = lprocfs_str_to_s64(buffer, count, &val);
102         if (rc)
103                 return rc;
104         if (val < 1 || val > OSC_MAX_RIF_MAX)
105                 return -ERANGE;
106
107         LPROCFS_CLIMP_CHECK(dev);
108
109         adding = (int)val - cli->cl_max_rpcs_in_flight;
110         req_count = atomic_read(&osc_pool_req_count);
111         if (adding > 0 && req_count < osc_reqpool_maxreqcount) {
112                 /*
113                  * There might be some race which will cause over-limit
114                  * allocation, but it is fine.
115                  */
116                 if (req_count + adding > osc_reqpool_maxreqcount)
117                         adding = osc_reqpool_maxreqcount - req_count;
118
119                 added = osc_rq_pool->prp_populate(osc_rq_pool, adding);
120                 atomic_add(added, &osc_pool_req_count);
121         }
122
123         spin_lock(&cli->cl_loi_list_lock);
124         cli->cl_max_rpcs_in_flight = val;
125         client_adjust_max_dirty(cli);
126         spin_unlock(&cli->cl_loi_list_lock);
127
128         LPROCFS_CLIMP_EXIT(dev);
129         return count;
130 }
131 LPROC_SEQ_FOPS(osc_max_rpcs_in_flight);
132
133 static int osc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
134 {
135         struct obd_device *dev = m->private;
136         struct client_obd *cli = &dev->u.cli;
137         long val;
138         int mult;
139
140         spin_lock(&cli->cl_loi_list_lock);
141         val = cli->cl_dirty_max_pages;
142         spin_unlock(&cli->cl_loi_list_lock);
143
144         mult = 1 << (20 - PAGE_SHIFT);
145         return lprocfs_seq_read_frac_helper(m, val, mult);
146 }
147
148 static ssize_t osc_max_dirty_mb_seq_write(struct file *file,
149                                           const char __user *buffer,
150                                           size_t count, loff_t *off)
151 {
152         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
153         struct client_obd *cli = &dev->u.cli;
154         int rc;
155         __s64 pages_number;
156
157         rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
158         if (rc)
159                 return rc;
160
161         pages_number >>= PAGE_SHIFT;
162
163         if (pages_number <= 0 ||
164             pages_number >= OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_SHIFT) ||
165             pages_number > totalram_pages / 4) /* 1/4 of RAM */
166                 return -ERANGE;
167
168         spin_lock(&cli->cl_loi_list_lock);
169         cli->cl_dirty_max_pages = pages_number;
170         osc_wake_cache_waiters(cli);
171         spin_unlock(&cli->cl_loi_list_lock);
172
173         return count;
174 }
175 LPROC_SEQ_FOPS(osc_max_dirty_mb);
176
177 static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
178 {
179         struct obd_device *dev = m->private;
180         struct client_obd *cli = &dev->u.cli;
181         int shift = 20 - PAGE_SHIFT;
182
183         seq_printf(m, "used_mb: %ld\n"
184                    "busy_cnt: %ld\n"
185                    "reclaim: %llu\n",
186                    (atomic_long_read(&cli->cl_lru_in_list) +
187                     atomic_long_read(&cli->cl_lru_busy)) >> shift,
188                     atomic_long_read(&cli->cl_lru_busy),
189                    cli->cl_lru_reclaim);
190
191         return 0;
192 }
193
194 /* shrink the number of caching pages to a specific number */
195 static ssize_t
196 osc_cached_mb_seq_write(struct file *file, const char __user *buffer,
197                         size_t count, loff_t *off)
198 {
199         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
200         struct client_obd *cli = &dev->u.cli;
201         __s64 pages_number;
202         long rc;
203         char kernbuf[128];
204
205         if (count >= sizeof(kernbuf))
206                 return -EINVAL;
207
208         if (copy_from_user(kernbuf, buffer, count))
209                 return -EFAULT;
210         kernbuf[count] = 0;
211
212         buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
213                   kernbuf;
214         rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
215         if (rc)
216                 return rc;
217
218         pages_number >>= PAGE_SHIFT;
219
220         if (pages_number < 0)
221                 return -ERANGE;
222
223         rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
224         if (rc > 0) {
225                 struct lu_env *env;
226                 __u16 refcheck;
227
228                 env = cl_env_get(&refcheck);
229                 if (!IS_ERR(env)) {
230                         (void)osc_lru_shrink(env, cli, rc, true);
231                         cl_env_put(env, &refcheck);
232                 }
233         }
234
235         return count;
236 }
237 LPROC_SEQ_FOPS(osc_cached_mb);
238
239 static int osc_cur_dirty_bytes_seq_show(struct seq_file *m, void *v)
240 {
241         struct obd_device *dev = m->private;
242         struct client_obd *cli = &dev->u.cli;
243
244         spin_lock(&cli->cl_loi_list_lock);
245         seq_printf(m, "%lu\n", cli->cl_dirty_pages << PAGE_SHIFT);
246         spin_unlock(&cli->cl_loi_list_lock);
247         return 0;
248 }
249 LPROC_SEQ_FOPS_RO(osc_cur_dirty_bytes);
250
251 static int osc_cur_grant_bytes_seq_show(struct seq_file *m, void *v)
252 {
253         struct obd_device *dev = m->private;
254         struct client_obd *cli = &dev->u.cli;
255
256         spin_lock(&cli->cl_loi_list_lock);
257         seq_printf(m, "%lu\n", cli->cl_avail_grant);
258         spin_unlock(&cli->cl_loi_list_lock);
259         return 0;
260 }
261
262 static ssize_t osc_cur_grant_bytes_seq_write(struct file *file,
263                                              const char __user *buffer,
264                                              size_t count, loff_t *off)
265 {
266         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
267         struct client_obd *cli = &obd->u.cli;
268         int                rc;
269         __s64              val;
270
271         if (obd == NULL)
272                 return 0;
273
274         rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
275         if (rc)
276                 return rc;
277         if (val < 0)
278                 return -ERANGE;
279
280         /* this is only for shrinking grant */
281         spin_lock(&cli->cl_loi_list_lock);
282         if (val >= cli->cl_avail_grant) {
283                 spin_unlock(&cli->cl_loi_list_lock);
284                 return 0;
285         }
286
287         spin_unlock(&cli->cl_loi_list_lock);
288
289         LPROCFS_CLIMP_CHECK(obd);
290         if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
291                 rc = osc_shrink_grant_to_target(cli, val);
292         LPROCFS_CLIMP_EXIT(obd);
293         if (rc)
294                 return rc;
295         return count;
296 }
297 LPROC_SEQ_FOPS(osc_cur_grant_bytes);
298
299 static int osc_cur_lost_grant_bytes_seq_show(struct seq_file *m, void *v)
300 {
301         struct obd_device *dev = m->private;
302         struct client_obd *cli = &dev->u.cli;
303
304         spin_lock(&cli->cl_loi_list_lock);
305         seq_printf(m, "%lu\n", cli->cl_lost_grant);
306         spin_unlock(&cli->cl_loi_list_lock);
307         return 0;
308 }
309 LPROC_SEQ_FOPS_RO(osc_cur_lost_grant_bytes);
310
311 static int osc_cur_dirty_grant_bytes_seq_show(struct seq_file *m, void *v)
312 {
313         struct obd_device *dev = m->private;
314         struct client_obd *cli = &dev->u.cli;
315
316         spin_lock(&cli->cl_loi_list_lock);
317         seq_printf(m, "%lu\n", cli->cl_dirty_grant);
318         spin_unlock(&cli->cl_loi_list_lock);
319         return 0;
320 }
321 LPROC_SEQ_FOPS_RO(osc_cur_dirty_grant_bytes);
322
323 static int osc_grant_shrink_interval_seq_show(struct seq_file *m, void *v)
324 {
325         struct obd_device *obd = m->private;
326
327         if (obd == NULL)
328                 return 0;
329         seq_printf(m, "%lld\n",
330                    obd->u.cli.cl_grant_shrink_interval);
331         return 0;
332 }
333
334 static ssize_t osc_grant_shrink_interval_seq_write(struct file *file,
335                                                    const char __user *buffer,
336                                                    size_t count, loff_t *off)
337 {
338         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
339         int rc;
340         __s64 val;
341
342         if (obd == NULL)
343                 return 0;
344
345         rc = lprocfs_str_to_s64(buffer, count, &val);
346         if (rc)
347                 return rc;
348
349         if (val <= 0 || val > INT_MAX)
350                 return -ERANGE;
351
352         obd->u.cli.cl_grant_shrink_interval = val;
353
354         return count;
355 }
356 LPROC_SEQ_FOPS(osc_grant_shrink_interval);
357
358 static int osc_checksum_seq_show(struct seq_file *m, void *v)
359 {
360         struct obd_device *obd = m->private;
361
362         if (obd == NULL)
363                 return 0;
364
365         seq_printf(m, "%d\n", obd->u.cli.cl_checksum ? 1 : 0);
366         return 0;
367 }
368
369 static ssize_t osc_checksum_seq_write(struct file *file,
370                                       const char __user *buffer,
371                                       size_t count, loff_t *off)
372 {
373         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
374         int rc;
375         __s64 val;
376
377         if (obd == NULL)
378                 return 0;
379
380         rc = lprocfs_str_to_s64(buffer, count, &val);
381         if (rc)
382                 return rc;
383
384         obd->u.cli.cl_checksum = !!val;
385
386         return count;
387 }
388 LPROC_SEQ_FOPS(osc_checksum);
389
390 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
391 {
392         struct obd_device *obd = m->private;
393         int i;
394         DECLARE_CKSUM_NAME;
395
396         if (obd == NULL)
397                 return 0;
398
399         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
400                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
401                         continue;
402                 if (obd->u.cli.cl_cksum_type == (1 << i))
403                         seq_printf(m, "[%s] ", cksum_name[i]);
404                 else
405                         seq_printf(m, "%s ", cksum_name[i]);
406         }
407         seq_printf(m, "\n");
408         return 0;
409 }
410
411 static ssize_t osc_checksum_type_seq_write(struct file *file,
412                                            const char __user *buffer,
413                                            size_t count, loff_t *off)
414 {
415         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
416         int i;
417         DECLARE_CKSUM_NAME;
418         char kernbuf[10];
419
420         if (obd == NULL)
421                 return 0;
422
423         if (count > sizeof(kernbuf) - 1)
424                 return -EINVAL;
425         if (copy_from_user(kernbuf, buffer, count))
426                 return -EFAULT;
427         if (count > 0 && kernbuf[count - 1] == '\n')
428                 kernbuf[count - 1] = '\0';
429         else
430                 kernbuf[count] = '\0';
431
432         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
433                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
434                         continue;
435                 if (!strcmp(kernbuf, cksum_name[i])) {
436                        obd->u.cli.cl_cksum_type = 1 << i;
437                        return count;
438                 }
439         }
440         return -EINVAL;
441 }
442 LPROC_SEQ_FOPS(osc_checksum_type);
443
444 static int osc_resend_count_seq_show(struct seq_file *m, void *v)
445 {
446         struct obd_device *obd = m->private;
447
448         seq_printf(m, "%u\n", atomic_read(&obd->u.cli.cl_resends));
449         return 0;
450 }
451
452 static ssize_t osc_resend_count_seq_write(struct file *file,
453                                           const char __user *buffer,
454                                           size_t count, loff_t *off)
455 {
456         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
457         int rc;
458         __s64 val;
459
460         rc = lprocfs_str_to_s64(buffer, count, &val);
461         if (rc)
462                 return rc;
463
464         if (val < 0 || val > INT_MAX)
465                 return -EINVAL;
466
467         atomic_set(&obd->u.cli.cl_resends, val);
468
469         return count;
470 }
471 LPROC_SEQ_FOPS(osc_resend_count);
472
473 static int osc_checksum_dump_seq_show(struct seq_file *m, void *v)
474 {
475         struct obd_device *obd = m->private;
476
477         if (obd == NULL)
478                 return 0;
479
480         seq_printf(m, "%d\n", obd->u.cli.cl_checksum_dump ? 1 : 0);
481         return 0;
482 }
483
484 static ssize_t osc_checksum_dump_seq_write(struct file *file,
485                                            const char __user *buffer,
486                                            size_t count, loff_t *off)
487 {
488         struct obd_device *obd;
489         int rc;
490         __s64 val;
491
492         obd = ((struct seq_file *)file->private_data)->private;
493         if (obd == NULL)
494                 return 0;
495
496         rc = lprocfs_str_to_s64(buffer, count, &val);
497         if (rc)
498                 return rc;
499
500         obd->u.cli.cl_checksum_dump = (val ? 1 : 0);
501
502         return count;
503 }
504 LPROC_SEQ_FOPS(osc_checksum_dump);
505
506 static int osc_contention_seconds_seq_show(struct seq_file *m, void *v)
507 {
508         struct obd_device *obd = m->private;
509         struct osc_device *od  = obd2osc_dev(obd);
510
511         seq_printf(m, "%u\n", od->od_contention_time);
512         return 0;
513 }
514
515 static ssize_t osc_contention_seconds_seq_write(struct file *file,
516                                                 const char __user *buffer,
517                                                 size_t count, loff_t *off)
518 {
519         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
520         struct osc_device *od  = obd2osc_dev(obd);
521         int rc;
522         __s64 val;
523
524         rc = lprocfs_str_to_s64(buffer, count, &val);
525         if (rc)
526                 return rc;
527         if (val < 0 || val > INT_MAX)
528                 return -ERANGE;
529
530         od->od_contention_time = val;
531
532         return count;
533 }
534 LPROC_SEQ_FOPS(osc_contention_seconds);
535
536 static int osc_lockless_truncate_seq_show(struct seq_file *m, void *v)
537 {
538         struct obd_device *obd = m->private;
539         struct osc_device *od  = obd2osc_dev(obd);
540
541         seq_printf(m, "%u\n", od->od_lockless_truncate);
542         return 0;
543 }
544
545 static ssize_t osc_lockless_truncate_seq_write(struct file *file,
546                                                const char __user *buffer,
547                                     size_t count, loff_t *off)
548 {
549         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
550         struct osc_device *od  = obd2osc_dev(obd);
551         int rc;
552         __s64 val;
553
554         rc = lprocfs_str_to_s64(buffer, count, &val);
555         if (rc)
556                 return rc;
557         if (val < 0)
558                 return -ERANGE;
559
560         od->od_lockless_truncate = !!val;
561
562         return count;
563 }
564 LPROC_SEQ_FOPS(osc_lockless_truncate);
565
566 static int osc_destroys_in_flight_seq_show(struct seq_file *m, void *v)
567 {
568         struct obd_device *obd = m->private;
569         seq_printf(m, "%u\n",
570                    atomic_read(&obd->u.cli.cl_destroy_in_flight));
571         return 0;
572 }
573 LPROC_SEQ_FOPS_RO(osc_destroys_in_flight);
574
575 LPROC_SEQ_FOPS_RW_TYPE(osc, obd_max_pages_per_rpc);
576
577 static int osc_unstable_stats_seq_show(struct seq_file *m, void *v)
578 {
579         struct obd_device *dev = m->private;
580         struct client_obd *cli = &dev->u.cli;
581         long pages;
582         int mb;
583
584         pages = atomic_long_read(&cli->cl_unstable_count);
585         mb    = (pages * PAGE_SIZE) >> 20;
586
587         seq_printf(m, "unstable_pages: %20ld\n"
588                    "unstable_mb:              %10d\n",
589                    pages, mb);
590         return 0;
591 }
592 LPROC_SEQ_FOPS_RO(osc_unstable_stats);
593
594 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
595 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
596 LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid);
597 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
598 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
599
600 LPROC_SEQ_FOPS_WR_ONLY(osc, ping);
601
602 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
603 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
604
605 struct lprocfs_vars lprocfs_osc_obd_vars[] = {
606         { .name =       "ping",
607           .fops =       &osc_ping_fops,
608           .proc_mode =  0222                            },
609         { .name =       "connect_flags",
610           .fops =       &osc_connect_flags_fops         },
611         { .name =       "ost_server_uuid",
612           .fops =       &osc_server_uuid_fops           },
613         { .name =       "ost_conn_uuid",
614           .fops =       &osc_conn_uuid_fops             },
615         { .name =       "active",
616           .fops =       &osc_active_fops                },
617         { .name =       "max_pages_per_rpc",
618           .fops =       &osc_obd_max_pages_per_rpc_fops },
619         { .name =       "max_rpcs_in_flight",
620           .fops =       &osc_max_rpcs_in_flight_fops    },
621         { .name =       "destroys_in_flight",
622           .fops =       &osc_destroys_in_flight_fops    },
623         { .name =       "max_dirty_mb",
624           .fops =       &osc_max_dirty_mb_fops          },
625         { .name =       "osc_cached_mb",
626           .fops =       &osc_cached_mb_fops             },
627         { .name =       "cur_dirty_bytes",
628           .fops =       &osc_cur_dirty_bytes_fops       },
629         { .name =       "cur_grant_bytes",
630           .fops =       &osc_cur_grant_bytes_fops       },
631         { .name =       "cur_lost_grant_bytes",
632           .fops =       &osc_cur_lost_grant_bytes_fops  },
633         { .name =       "cur_dirty_grant_bytes",
634           .fops =       &osc_cur_dirty_grant_bytes_fops },
635         { .name =       "grant_shrink_interval",
636           .fops =       &osc_grant_shrink_interval_fops },
637         { .name =       "checksums",
638           .fops =       &osc_checksum_fops              },
639         { .name =       "checksum_type",
640           .fops =       &osc_checksum_type_fops         },
641         { .name =       "checksum_dump",
642           .fops =       &osc_checksum_dump_fops         },
643         { .name =       "resend_count",
644           .fops =       &osc_resend_count_fops          },
645         { .name =       "timeouts",
646           .fops =       &osc_timeouts_fops              },
647         { .name =       "contention_seconds",
648           .fops =       &osc_contention_seconds_fops    },
649         { .name =       "lockless_truncate",
650           .fops =       &osc_lockless_truncate_fops     },
651         { .name =       "import",
652           .fops =       &osc_import_fops                },
653         { .name =       "state",
654           .fops =       &osc_state_fops                 },
655         { .name =       "pinger_recov",
656           .fops =       &osc_pinger_recov_fops          },
657         { .name =       "unstable_stats",
658           .fops =       &osc_unstable_stats_fops        },
659         { NULL }
660 };
661
662 #define pct(a,b) (b ? a * 100 / b : 0)
663
664 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
665 {
666         struct timespec64 now;
667         struct obd_device *dev = seq->private;
668         struct client_obd *cli = &dev->u.cli;
669         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
670         int i;
671
672         ktime_get_real_ts64(&now);
673
674         spin_lock(&cli->cl_loi_list_lock);
675
676         seq_printf(seq, "snapshot_time:         %lld.%09lu (secs.nsecs)\n",
677                    (s64)now.tv_sec, now.tv_nsec);
678         seq_printf(seq, "read RPCs in flight:  %d\n",
679                    cli->cl_r_in_flight);
680         seq_printf(seq, "write RPCs in flight: %d\n",
681                    cli->cl_w_in_flight);
682         seq_printf(seq, "pending write pages:  %d\n",
683                    atomic_read(&cli->cl_pending_w_pages));
684         seq_printf(seq, "pending read pages:   %d\n",
685                    atomic_read(&cli->cl_pending_r_pages));
686
687         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
688         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
689         seq_printf(seq, "       rpcs   %% cum %%\n");
690
691         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
692         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
693
694         read_cum = 0;
695         write_cum = 0;
696         for (i = 0; i < OBD_HIST_MAX; i++) {
697                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
698                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
699
700                 read_cum += r;
701                 write_cum += w;
702                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
703                            1 << i, r, pct(r, read_tot),
704                            pct(read_cum, read_tot), w,
705                            pct(w, write_tot),
706                            pct(write_cum, write_tot));
707                 if (read_cum == read_tot && write_cum == write_tot)
708                         break;
709         }
710
711         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
712         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
713         seq_printf(seq, "       rpcs   %% cum %%\n");
714
715         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
716         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
717
718         read_cum = 0;
719         write_cum = 0;
720         for (i = 0; i < OBD_HIST_MAX; i++) {
721                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
722                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
723                 read_cum += r;
724                 write_cum += w;
725                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
726                            i, r, pct(r, read_tot),
727                            pct(read_cum, read_tot), w,
728                            pct(w, write_tot),
729                            pct(write_cum, write_tot));
730                 if (read_cum == read_tot && write_cum == write_tot)
731                         break;
732         }
733
734         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
735         seq_printf(seq, "offset                rpcs   %% cum %% |");
736         seq_printf(seq, "       rpcs   %% cum %%\n");
737
738         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
739         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
740
741         read_cum = 0;
742         write_cum = 0;
743         for (i = 0; i < OBD_HIST_MAX; i++) {
744                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
745                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
746                 read_cum += r;
747                 write_cum += w;
748                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
749                            (i == 0) ? 0 : 1 << (i - 1),
750                            r, pct(r, read_tot), pct(read_cum, read_tot),
751                            w, pct(w, write_tot), pct(write_cum, write_tot));
752                 if (read_cum == read_tot && write_cum == write_tot)
753                         break;
754         }
755
756         spin_unlock(&cli->cl_loi_list_lock);
757
758         return 0;
759 }
760 #undef pct
761
762 static ssize_t osc_rpc_stats_seq_write(struct file *file,
763                                        const char __user *buf,
764                                        size_t len, loff_t *off)
765 {
766         struct seq_file *seq = file->private_data;
767         struct obd_device *dev = seq->private;
768         struct client_obd *cli = &dev->u.cli;
769
770         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
771         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
772         lprocfs_oh_clear(&cli->cl_read_page_hist);
773         lprocfs_oh_clear(&cli->cl_write_page_hist);
774         lprocfs_oh_clear(&cli->cl_read_offset_hist);
775         lprocfs_oh_clear(&cli->cl_write_offset_hist);
776
777         return len;
778 }
779 LPROC_SEQ_FOPS(osc_rpc_stats);
780
781 static int osc_stats_seq_show(struct seq_file *seq, void *v)
782 {
783         struct timespec64 now;
784         struct obd_device *dev = seq->private;
785         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
786
787         ktime_get_real_ts64(&now);
788
789         seq_printf(seq, "snapshot_time:         %lld.%09lu (secs.nsecs)\n",
790                    (s64)now.tv_sec, now.tv_nsec);
791         seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
792                    stats->os_lockless_writes);
793         seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
794                    stats->os_lockless_reads);
795         seq_printf(seq, "lockless_truncate\t\t%llu\n",
796                    stats->os_lockless_truncates);
797         return 0;
798 }
799
800 static ssize_t osc_stats_seq_write(struct file *file,
801                                    const char __user *buf,
802                                    size_t len, loff_t *off)
803 {
804         struct seq_file *seq = file->private_data;
805         struct obd_device *dev = seq->private;
806         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
807
808         memset(stats, 0, sizeof(*stats));
809         return len;
810 }
811
812 LPROC_SEQ_FOPS(osc_stats);
813
814 int lproc_osc_attach_seqstat(struct obd_device *dev)
815 {
816         int rc;
817
818         rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
819                                 &osc_stats_fops, dev);
820         if (rc == 0)
821                 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
822                                             &osc_rpc_stats_fops, dev);
823
824         return rc;
825 }
826 #endif /* CONFIG_PROC_FS */