Whamcloud - gitweb
LU-10308 misc: update Intel copyright messages for 2017
[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, 2017, 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 LPROC_SEQ_FOPS_RW_TYPE(osc, obd_short_io_bytes);
578
579 static int osc_unstable_stats_seq_show(struct seq_file *m, void *v)
580 {
581         struct obd_device *dev = m->private;
582         struct client_obd *cli = &dev->u.cli;
583         long pages;
584         int mb;
585
586         pages = atomic_long_read(&cli->cl_unstable_count);
587         mb    = (pages * PAGE_SIZE) >> 20;
588
589         seq_printf(m, "unstable_pages: %20ld\n"
590                    "unstable_mb:              %10d\n",
591                    pages, mb);
592         return 0;
593 }
594 LPROC_SEQ_FOPS_RO(osc_unstable_stats);
595
596 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
597 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
598 LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid);
599 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
600 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
601
602 LPROC_SEQ_FOPS_WR_ONLY(osc, ping);
603
604 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
605 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
606
607 struct lprocfs_vars lprocfs_osc_obd_vars[] = {
608         { .name =       "ping",
609           .fops =       &osc_ping_fops,
610           .proc_mode =  0222                            },
611         { .name =       "connect_flags",
612           .fops =       &osc_connect_flags_fops         },
613         { .name =       "ost_server_uuid",
614           .fops =       &osc_server_uuid_fops           },
615         { .name =       "ost_conn_uuid",
616           .fops =       &osc_conn_uuid_fops             },
617         { .name =       "active",
618           .fops =       &osc_active_fops                },
619         { .name =       "max_pages_per_rpc",
620           .fops =       &osc_obd_max_pages_per_rpc_fops },
621         { .name =       "short_io_bytes",
622           .fops =       &osc_obd_short_io_bytes_fops    },
623         { .name =       "max_rpcs_in_flight",
624           .fops =       &osc_max_rpcs_in_flight_fops    },
625         { .name =       "destroys_in_flight",
626           .fops =       &osc_destroys_in_flight_fops    },
627         { .name =       "max_dirty_mb",
628           .fops =       &osc_max_dirty_mb_fops          },
629         { .name =       "osc_cached_mb",
630           .fops =       &osc_cached_mb_fops             },
631         { .name =       "cur_dirty_bytes",
632           .fops =       &osc_cur_dirty_bytes_fops       },
633         { .name =       "cur_grant_bytes",
634           .fops =       &osc_cur_grant_bytes_fops       },
635         { .name =       "cur_lost_grant_bytes",
636           .fops =       &osc_cur_lost_grant_bytes_fops  },
637         { .name =       "cur_dirty_grant_bytes",
638           .fops =       &osc_cur_dirty_grant_bytes_fops },
639         { .name =       "grant_shrink_interval",
640           .fops =       &osc_grant_shrink_interval_fops },
641         { .name =       "checksums",
642           .fops =       &osc_checksum_fops              },
643         { .name =       "checksum_type",
644           .fops =       &osc_checksum_type_fops         },
645         { .name =       "checksum_dump",
646           .fops =       &osc_checksum_dump_fops         },
647         { .name =       "resend_count",
648           .fops =       &osc_resend_count_fops          },
649         { .name =       "timeouts",
650           .fops =       &osc_timeouts_fops              },
651         { .name =       "contention_seconds",
652           .fops =       &osc_contention_seconds_fops    },
653         { .name =       "lockless_truncate",
654           .fops =       &osc_lockless_truncate_fops     },
655         { .name =       "import",
656           .fops =       &osc_import_fops                },
657         { .name =       "state",
658           .fops =       &osc_state_fops                 },
659         { .name =       "pinger_recov",
660           .fops =       &osc_pinger_recov_fops          },
661         { .name =       "unstable_stats",
662           .fops =       &osc_unstable_stats_fops        },
663         { NULL }
664 };
665
666 #define pct(a,b) (b ? a * 100 / b : 0)
667
668 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
669 {
670         struct timespec64 now;
671         struct obd_device *dev = seq->private;
672         struct client_obd *cli = &dev->u.cli;
673         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
674         int i;
675
676         ktime_get_real_ts64(&now);
677
678         spin_lock(&cli->cl_loi_list_lock);
679
680         seq_printf(seq, "snapshot_time:         %lld.%09lu (secs.nsecs)\n",
681                    (s64)now.tv_sec, now.tv_nsec);
682         seq_printf(seq, "read RPCs in flight:  %d\n",
683                    cli->cl_r_in_flight);
684         seq_printf(seq, "write RPCs in flight: %d\n",
685                    cli->cl_w_in_flight);
686         seq_printf(seq, "pending write pages:  %d\n",
687                    atomic_read(&cli->cl_pending_w_pages));
688         seq_printf(seq, "pending read pages:   %d\n",
689                    atomic_read(&cli->cl_pending_r_pages));
690
691         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
692         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
693         seq_printf(seq, "       rpcs   %% cum %%\n");
694
695         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
696         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
697
698         read_cum = 0;
699         write_cum = 0;
700         for (i = 0; i < OBD_HIST_MAX; i++) {
701                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
702                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
703
704                 read_cum += r;
705                 write_cum += w;
706                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
707                            1 << i, r, pct(r, read_tot),
708                            pct(read_cum, read_tot), w,
709                            pct(w, write_tot),
710                            pct(write_cum, write_tot));
711                 if (read_cum == read_tot && write_cum == write_tot)
712                         break;
713         }
714
715         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
716         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
717         seq_printf(seq, "       rpcs   %% cum %%\n");
718
719         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
720         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
721
722         read_cum = 0;
723         write_cum = 0;
724         for (i = 0; i < OBD_HIST_MAX; i++) {
725                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
726                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
727                 read_cum += r;
728                 write_cum += w;
729                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
730                            i, r, pct(r, read_tot),
731                            pct(read_cum, read_tot), w,
732                            pct(w, write_tot),
733                            pct(write_cum, write_tot));
734                 if (read_cum == read_tot && write_cum == write_tot)
735                         break;
736         }
737
738         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
739         seq_printf(seq, "offset                rpcs   %% cum %% |");
740         seq_printf(seq, "       rpcs   %% cum %%\n");
741
742         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
743         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
744
745         read_cum = 0;
746         write_cum = 0;
747         for (i = 0; i < OBD_HIST_MAX; i++) {
748                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
749                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
750                 read_cum += r;
751                 write_cum += w;
752                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
753                            (i == 0) ? 0 : 1 << (i - 1),
754                            r, pct(r, read_tot), pct(read_cum, read_tot),
755                            w, pct(w, write_tot), pct(write_cum, write_tot));
756                 if (read_cum == read_tot && write_cum == write_tot)
757                         break;
758         }
759
760         spin_unlock(&cli->cl_loi_list_lock);
761
762         return 0;
763 }
764 #undef pct
765
766 static ssize_t osc_rpc_stats_seq_write(struct file *file,
767                                        const char __user *buf,
768                                        size_t len, loff_t *off)
769 {
770         struct seq_file *seq = file->private_data;
771         struct obd_device *dev = seq->private;
772         struct client_obd *cli = &dev->u.cli;
773
774         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
775         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
776         lprocfs_oh_clear(&cli->cl_read_page_hist);
777         lprocfs_oh_clear(&cli->cl_write_page_hist);
778         lprocfs_oh_clear(&cli->cl_read_offset_hist);
779         lprocfs_oh_clear(&cli->cl_write_offset_hist);
780
781         return len;
782 }
783 LPROC_SEQ_FOPS(osc_rpc_stats);
784
785 static int osc_stats_seq_show(struct seq_file *seq, void *v)
786 {
787         struct timespec64 now;
788         struct obd_device *dev = seq->private;
789         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
790
791         ktime_get_real_ts64(&now);
792
793         seq_printf(seq, "snapshot_time:         %lld.%09lu (secs.nsecs)\n",
794                    (s64)now.tv_sec, now.tv_nsec);
795         seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
796                    stats->os_lockless_writes);
797         seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
798                    stats->os_lockless_reads);
799         seq_printf(seq, "lockless_truncate\t\t%llu\n",
800                    stats->os_lockless_truncates);
801         return 0;
802 }
803
804 static ssize_t osc_stats_seq_write(struct file *file,
805                                    const char __user *buf,
806                                    size_t len, loff_t *off)
807 {
808         struct seq_file *seq = file->private_data;
809         struct obd_device *dev = seq->private;
810         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
811
812         memset(stats, 0, sizeof(*stats));
813         return len;
814 }
815
816 LPROC_SEQ_FOPS(osc_stats);
817
818 int lproc_osc_attach_seqstat(struct obd_device *dev)
819 {
820         int rc;
821
822         rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
823                                 &osc_stats_fops, dev);
824         if (rc == 0)
825                 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
826                                             &osc_rpc_stats_fops, dev);
827
828         return rc;
829 }
830 #endif /* CONFIG_PROC_FS */