Merge remote-tracking branch 'usb-chipidea-next/ci-for-usb-next'
[deliverable/linux.git] / drivers / staging / lustre / 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, 2015, 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/statfs.h>
35 #include "../include/obd_cksum.h"
36 #include "../include/obd_class.h"
37 #include "../include/lprocfs_status.h"
38 #include <linux/seq_file.h>
39 #include "osc_internal.h"
40
41 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
42 char *buf)
43 {
44 struct obd_device *dev = container_of(kobj, struct obd_device,
45 obd_kobj);
46
47 return sprintf(buf, "%d\n", !dev->u.cli.cl_import->imp_deactive);
48 }
49
50 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
51 const char *buffer,
52 size_t count)
53 {
54 struct obd_device *dev = container_of(kobj, struct obd_device,
55 obd_kobj);
56 int rc;
57 unsigned long val;
58
59 rc = kstrtoul(buffer, 10, &val);
60 if (rc)
61 return rc;
62 if (val > 1)
63 return -ERANGE;
64
65 /* opposite senses */
66 if (dev->u.cli.cl_import->imp_deactive == val)
67 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
68 else
69 CDEBUG(D_CONFIG, "activate %ld: ignoring repeat request\n",
70 val);
71
72 return count;
73 }
74 LUSTRE_RW_ATTR(active);
75
76 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
77 struct attribute *attr,
78 char *buf)
79 {
80 struct obd_device *dev = container_of(kobj, struct obd_device,
81 obd_kobj);
82 struct client_obd *cli = &dev->u.cli;
83
84 return sprintf(buf, "%u\n", cli->cl_max_rpcs_in_flight);
85 }
86
87 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
88 struct attribute *attr,
89 const char *buffer,
90 size_t count)
91 {
92 struct obd_device *dev = container_of(kobj, struct obd_device,
93 obd_kobj);
94 struct client_obd *cli = &dev->u.cli;
95 int rc;
96 unsigned long val;
97 int adding, added, req_count;
98
99 rc = kstrtoul(buffer, 10, &val);
100 if (rc)
101 return rc;
102
103 if (val < 1 || val > OSC_MAX_RIF_MAX)
104 return -ERANGE;
105
106 adding = val - cli->cl_max_rpcs_in_flight;
107 req_count = atomic_read(&osc_pool_req_count);
108 if (adding > 0 && req_count < osc_reqpool_maxreqcount) {
109 /*
110 * There might be some race which will cause over-limit
111 * allocation, but it is fine.
112 */
113 if (req_count + adding > osc_reqpool_maxreqcount)
114 adding = osc_reqpool_maxreqcount - req_count;
115
116 added = osc_rq_pool->prp_populate(osc_rq_pool, adding);
117 atomic_add(added, &osc_pool_req_count);
118 }
119
120 spin_lock(&cli->cl_loi_list_lock);
121 cli->cl_max_rpcs_in_flight = val;
122 spin_unlock(&cli->cl_loi_list_lock);
123
124 return count;
125 }
126 LUSTRE_RW_ATTR(max_rpcs_in_flight);
127
128 static ssize_t max_dirty_mb_show(struct kobject *kobj,
129 struct attribute *attr,
130 char *buf)
131 {
132 struct obd_device *dev = container_of(kobj, struct obd_device,
133 obd_kobj);
134 struct client_obd *cli = &dev->u.cli;
135 long val;
136 int mult;
137
138 spin_lock(&cli->cl_loi_list_lock);
139 val = cli->cl_dirty_max;
140 spin_unlock(&cli->cl_loi_list_lock);
141
142 mult = 1 << 20;
143 return lprocfs_read_frac_helper(buf, PAGE_SIZE, val, mult);
144 }
145
146 static ssize_t max_dirty_mb_store(struct kobject *kobj,
147 struct attribute *attr,
148 const char *buffer,
149 size_t count)
150 {
151 struct obd_device *dev = container_of(kobj, struct obd_device,
152 obd_kobj);
153 struct client_obd *cli = &dev->u.cli;
154 int rc;
155 unsigned long pages_number;
156
157 rc = kstrtoul(buffer, 10, &pages_number);
158 if (rc)
159 return rc;
160
161 pages_number *= 1 << (20 - PAGE_SHIFT); /* MB -> pages */
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 = (u32)(pages_number << PAGE_SHIFT);
170 osc_wake_cache_waiters(cli);
171 spin_unlock(&cli->cl_loi_list_lock);
172
173 return count;
174 }
175 LUSTRE_RW_ATTR(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,
184 "used_mb: %d\n"
185 "busy_cnt: %d\n",
186 (atomic_read(&cli->cl_lru_in_list) +
187 atomic_read(&cli->cl_lru_busy)) >> shift,
188 atomic_read(&cli->cl_lru_busy));
189
190 return 0;
191 }
192
193 /* shrink the number of caching pages to a specific number */
194 static ssize_t osc_cached_mb_seq_write(struct file *file,
195 const char __user *buffer,
196 size_t count, loff_t *off)
197 {
198 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
199 struct client_obd *cli = &dev->u.cli;
200 int pages_number, mult, rc;
201 char kernbuf[128];
202
203 if (count >= sizeof(kernbuf))
204 return -EINVAL;
205
206 if (copy_from_user(kernbuf, buffer, count))
207 return -EFAULT;
208 kernbuf[count] = 0;
209
210 mult = 1 << (20 - PAGE_SHIFT);
211 buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
212 kernbuf;
213 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
214 if (rc)
215 return rc;
216
217 if (pages_number < 0)
218 return -ERANGE;
219
220 rc = atomic_read(&cli->cl_lru_in_list) - pages_number;
221 if (rc > 0) {
222 struct lu_env *env;
223 int refcheck;
224
225 env = cl_env_get(&refcheck);
226 if (!IS_ERR(env)) {
227 (void)osc_lru_shrink(env, cli, rc, true);
228 cl_env_put(env, &refcheck);
229 }
230 }
231
232 return count;
233 }
234
235 LPROC_SEQ_FOPS(osc_cached_mb);
236
237 static ssize_t cur_dirty_bytes_show(struct kobject *kobj,
238 struct attribute *attr,
239 char *buf)
240 {
241 struct obd_device *dev = container_of(kobj, struct obd_device,
242 obd_kobj);
243 struct client_obd *cli = &dev->u.cli;
244 int len;
245
246 spin_lock(&cli->cl_loi_list_lock);
247 len = sprintf(buf, "%lu\n", cli->cl_dirty);
248 spin_unlock(&cli->cl_loi_list_lock);
249
250 return len;
251 }
252 LUSTRE_RO_ATTR(cur_dirty_bytes);
253
254 static ssize_t cur_grant_bytes_show(struct kobject *kobj,
255 struct attribute *attr,
256 char *buf)
257 {
258 struct obd_device *dev = container_of(kobj, struct obd_device,
259 obd_kobj);
260 struct client_obd *cli = &dev->u.cli;
261 int len;
262
263 spin_lock(&cli->cl_loi_list_lock);
264 len = sprintf(buf, "%lu\n", cli->cl_avail_grant);
265 spin_unlock(&cli->cl_loi_list_lock);
266
267 return len;
268 }
269
270 static ssize_t cur_grant_bytes_store(struct kobject *kobj,
271 struct attribute *attr,
272 const char *buffer,
273 size_t count)
274 {
275 struct obd_device *obd = container_of(kobj, struct obd_device,
276 obd_kobj);
277 struct client_obd *cli = &obd->u.cli;
278 int rc;
279 unsigned long long val;
280
281 rc = kstrtoull(buffer, 10, &val);
282 if (rc)
283 return rc;
284
285 /* this is only for shrinking grant */
286 spin_lock(&cli->cl_loi_list_lock);
287 if (val >= cli->cl_avail_grant) {
288 spin_unlock(&cli->cl_loi_list_lock);
289 return -EINVAL;
290 }
291 spin_unlock(&cli->cl_loi_list_lock);
292
293 if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
294 rc = osc_shrink_grant_to_target(cli, val);
295 if (rc)
296 return rc;
297 return count;
298 }
299 LUSTRE_RW_ATTR(cur_grant_bytes);
300
301 static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj,
302 struct attribute *attr,
303 char *buf)
304 {
305 struct obd_device *dev = container_of(kobj, struct obd_device,
306 obd_kobj);
307 struct client_obd *cli = &dev->u.cli;
308 int len;
309
310 spin_lock(&cli->cl_loi_list_lock);
311 len = sprintf(buf, "%lu\n", cli->cl_lost_grant);
312 spin_unlock(&cli->cl_loi_list_lock);
313
314 return len;
315 }
316 LUSTRE_RO_ATTR(cur_lost_grant_bytes);
317
318 static ssize_t grant_shrink_interval_show(struct kobject *kobj,
319 struct attribute *attr,
320 char *buf)
321 {
322 struct obd_device *obd = container_of(kobj, struct obd_device,
323 obd_kobj);
324
325 return sprintf(buf, "%d\n", obd->u.cli.cl_grant_shrink_interval);
326 }
327
328 static ssize_t grant_shrink_interval_store(struct kobject *kobj,
329 struct attribute *attr,
330 const char *buffer,
331 size_t count)
332 {
333 struct obd_device *obd = container_of(kobj, struct obd_device,
334 obd_kobj);
335 int rc;
336 unsigned long val;
337
338 rc = kstrtoul(buffer, 10, &val);
339 if (rc)
340 return rc;
341
342 if (val <= 0)
343 return -ERANGE;
344
345 obd->u.cli.cl_grant_shrink_interval = val;
346
347 return count;
348 }
349 LUSTRE_RW_ATTR(grant_shrink_interval);
350
351 static ssize_t checksums_show(struct kobject *kobj,
352 struct attribute *attr,
353 char *buf)
354 {
355 struct obd_device *obd = container_of(kobj, struct obd_device,
356 obd_kobj);
357
358 return sprintf(buf, "%d\n", obd->u.cli.cl_checksum ? 1 : 0);
359 }
360
361 static ssize_t checksums_store(struct kobject *kobj,
362 struct attribute *attr,
363 const char *buffer,
364 size_t count)
365 {
366 struct obd_device *obd = container_of(kobj, struct obd_device,
367 obd_kobj);
368 int rc;
369 unsigned long val;
370
371 rc = kstrtoul(buffer, 10, &val);
372 if (rc)
373 return rc;
374
375 obd->u.cli.cl_checksum = (val ? 1 : 0);
376
377 return count;
378 }
379 LUSTRE_RW_ATTR(checksums);
380
381 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
382 {
383 struct obd_device *obd = m->private;
384 int i;
385
386 DECLARE_CKSUM_NAME;
387
388 if (!obd)
389 return 0;
390
391 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
392 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
393 continue;
394 if (obd->u.cli.cl_cksum_type == (1 << i))
395 seq_printf(m, "[%s] ", cksum_name[i]);
396 else
397 seq_printf(m, "%s ", cksum_name[i]);
398 }
399 seq_putc(m, '\n');
400 return 0;
401 }
402
403 static ssize_t osc_checksum_type_seq_write(struct file *file,
404 const char __user *buffer,
405 size_t count, loff_t *off)
406 {
407 struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
408 int i;
409
410 DECLARE_CKSUM_NAME;
411 char kernbuf[10];
412
413 if (!obd)
414 return 0;
415
416 if (count > sizeof(kernbuf) - 1)
417 return -EINVAL;
418 if (copy_from_user(kernbuf, buffer, count))
419 return -EFAULT;
420 if (count > 0 && kernbuf[count - 1] == '\n')
421 kernbuf[count - 1] = '\0';
422 else
423 kernbuf[count] = '\0';
424
425 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
426 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
427 continue;
428 if (!strcmp(kernbuf, cksum_name[i])) {
429 obd->u.cli.cl_cksum_type = 1 << i;
430 return count;
431 }
432 }
433 return -EINVAL;
434 }
435
436 LPROC_SEQ_FOPS(osc_checksum_type);
437
438 static ssize_t resend_count_show(struct kobject *kobj,
439 struct attribute *attr,
440 char *buf)
441 {
442 struct obd_device *obd = container_of(kobj, struct obd_device,
443 obd_kobj);
444
445 return sprintf(buf, "%u\n", atomic_read(&obd->u.cli.cl_resends));
446 }
447
448 static ssize_t resend_count_store(struct kobject *kobj,
449 struct attribute *attr,
450 const char *buffer,
451 size_t count)
452 {
453 struct obd_device *obd = container_of(kobj, struct obd_device,
454 obd_kobj);
455 int rc;
456 unsigned long val;
457
458 rc = kstrtoul(buffer, 10, &val);
459 if (rc)
460 return rc;
461
462 atomic_set(&obd->u.cli.cl_resends, val);
463
464 return count;
465 }
466 LUSTRE_RW_ATTR(resend_count);
467
468 static ssize_t contention_seconds_show(struct kobject *kobj,
469 struct attribute *attr,
470 char *buf)
471 {
472 struct obd_device *obd = container_of(kobj, struct obd_device,
473 obd_kobj);
474 struct osc_device *od = obd2osc_dev(obd);
475
476 return sprintf(buf, "%u\n", od->od_contention_time);
477 }
478
479 static ssize_t contention_seconds_store(struct kobject *kobj,
480 struct attribute *attr,
481 const char *buffer,
482 size_t count)
483 {
484 struct obd_device *obd = container_of(kobj, struct obd_device,
485 obd_kobj);
486 struct osc_device *od = obd2osc_dev(obd);
487 int rc;
488 int val;
489
490 rc = kstrtoint(buffer, 10, &val);
491 if (rc)
492 return rc;
493
494 if (val < 0)
495 return -EINVAL;
496
497 od->od_contention_time = val;
498
499 return count;
500 }
501 LUSTRE_RW_ATTR(contention_seconds);
502
503 static ssize_t lockless_truncate_show(struct kobject *kobj,
504 struct attribute *attr,
505 char *buf)
506 {
507 struct obd_device *obd = container_of(kobj, struct obd_device,
508 obd_kobj);
509 struct osc_device *od = obd2osc_dev(obd);
510
511 return sprintf(buf, "%u\n", od->od_lockless_truncate);
512 }
513
514 static ssize_t lockless_truncate_store(struct kobject *kobj,
515 struct attribute *attr,
516 const char *buffer,
517 size_t count)
518 {
519 struct obd_device *obd = container_of(kobj, struct obd_device,
520 obd_kobj);
521 struct osc_device *od = obd2osc_dev(obd);
522 int rc;
523 unsigned int val;
524
525 rc = kstrtouint(buffer, 10, &val);
526 if (rc)
527 return rc;
528
529 od->od_lockless_truncate = val;
530
531 return count;
532 }
533 LUSTRE_RW_ATTR(lockless_truncate);
534
535 static ssize_t destroys_in_flight_show(struct kobject *kobj,
536 struct attribute *attr,
537 char *buf)
538 {
539 struct obd_device *obd = container_of(kobj, struct obd_device,
540 obd_kobj);
541
542 return sprintf(buf, "%u\n",
543 atomic_read(&obd->u.cli.cl_destroy_in_flight));
544 }
545 LUSTRE_RO_ATTR(destroys_in_flight);
546
547 static ssize_t max_pages_per_rpc_show(struct kobject *kobj,
548 struct attribute *attr,
549 char *buf)
550 {
551 struct obd_device *dev = container_of(kobj, struct obd_device,
552 obd_kobj);
553 struct client_obd *cli = &dev->u.cli;
554
555 return sprintf(buf, "%d\n", cli->cl_max_pages_per_rpc);
556 }
557
558 static ssize_t max_pages_per_rpc_store(struct kobject *kobj,
559 struct attribute *attr,
560 const char *buffer,
561 size_t count)
562 {
563 struct obd_device *dev = container_of(kobj, struct obd_device,
564 obd_kobj);
565 struct client_obd *cli = &dev->u.cli;
566 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
567 int chunk_mask, rc;
568 unsigned long long val;
569
570 rc = kstrtoull(buffer, 10, &val);
571 if (rc)
572 return rc;
573
574 /* if the max_pages is specified in bytes, convert to pages */
575 if (val >= ONE_MB_BRW_SIZE)
576 val >>= PAGE_SHIFT;
577
578 chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_SHIFT)) - 1);
579 /* max_pages_per_rpc must be chunk aligned */
580 val = (val + ~chunk_mask) & chunk_mask;
581 if (val == 0 || val > ocd->ocd_brw_size >> PAGE_SHIFT) {
582 return -ERANGE;
583 }
584 spin_lock(&cli->cl_loi_list_lock);
585 cli->cl_max_pages_per_rpc = val;
586 spin_unlock(&cli->cl_loi_list_lock);
587
588 return count;
589 }
590 LUSTRE_RW_ATTR(max_pages_per_rpc);
591
592 static ssize_t unstable_stats_show(struct kobject *kobj,
593 struct attribute *attr,
594 char *buf)
595 {
596 struct obd_device *dev = container_of(kobj, struct obd_device,
597 obd_kobj);
598 struct client_obd *cli = &dev->u.cli;
599 int pages, mb;
600
601 pages = atomic_read(&cli->cl_unstable_count);
602 mb = (pages * PAGE_SIZE) >> 20;
603
604 return sprintf(buf, "unstable_pages: %8d\n"
605 "unstable_mb: %8d\n", pages, mb);
606 }
607 LUSTRE_RO_ATTR(unstable_stats);
608
609 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
610 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
611 LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid);
612 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
613 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
614
615 LPROC_SEQ_FOPS_WR_ONLY(osc, ping);
616
617 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
618 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
619
620 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
621 { "ping", &osc_ping_fops, NULL, 0222 },
622 { "connect_flags", &osc_connect_flags_fops, NULL, 0 },
623 /*{ "filegroups", lprocfs_rd_filegroups, NULL, 0 },*/
624 { "ost_server_uuid", &osc_server_uuid_fops, NULL, 0 },
625 { "ost_conn_uuid", &osc_conn_uuid_fops, NULL, 0 },
626 { "osc_cached_mb", &osc_cached_mb_fops, NULL },
627 { "checksum_type", &osc_checksum_type_fops, NULL },
628 { "timeouts", &osc_timeouts_fops, NULL, 0 },
629 { "import", &osc_import_fops, NULL },
630 { "state", &osc_state_fops, NULL, 0 },
631 { "pinger_recov", &osc_pinger_recov_fops, NULL },
632 { NULL }
633 };
634
635 #define pct(a, b) (b ? a * 100 / b : 0)
636
637 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
638 {
639 struct timespec64 now;
640 struct obd_device *dev = seq->private;
641 struct client_obd *cli = &dev->u.cli;
642 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
643 int i;
644
645 ktime_get_real_ts64(&now);
646
647 spin_lock(&cli->cl_loi_list_lock);
648
649 seq_printf(seq, "snapshot_time: %llu.%9lu (secs.usecs)\n",
650 (s64)now.tv_sec, (unsigned long)now.tv_nsec);
651 seq_printf(seq, "read RPCs in flight: %d\n",
652 cli->cl_r_in_flight);
653 seq_printf(seq, "write RPCs in flight: %d\n",
654 cli->cl_w_in_flight);
655 seq_printf(seq, "pending write pages: %d\n",
656 atomic_read(&cli->cl_pending_w_pages));
657 seq_printf(seq, "pending read pages: %d\n",
658 atomic_read(&cli->cl_pending_r_pages));
659
660 seq_puts(seq, "\n\t\t\tread\t\t\twrite\n");
661 seq_puts(seq, "pages per rpc rpcs % cum % |");
662 seq_puts(seq, " rpcs % cum %\n");
663
664 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
665 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
666
667 read_cum = 0;
668 write_cum = 0;
669 for (i = 0; i < OBD_HIST_MAX; i++) {
670 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
671 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
672
673 read_cum += r;
674 write_cum += w;
675 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
676 1 << i, r, pct(r, read_tot),
677 pct(read_cum, read_tot), w,
678 pct(w, write_tot),
679 pct(write_cum, write_tot));
680 if (read_cum == read_tot && write_cum == write_tot)
681 break;
682 }
683
684 seq_puts(seq, "\n\t\t\tread\t\t\twrite\n");
685 seq_puts(seq, "rpcs in flight rpcs % cum % |");
686 seq_puts(seq, " rpcs % cum %\n");
687
688 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
689 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
690
691 read_cum = 0;
692 write_cum = 0;
693 for (i = 0; i < OBD_HIST_MAX; i++) {
694 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
695 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
696
697 read_cum += r;
698 write_cum += w;
699 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
700 i, r, pct(r, read_tot),
701 pct(read_cum, read_tot), w,
702 pct(w, write_tot),
703 pct(write_cum, write_tot));
704 if (read_cum == read_tot && write_cum == write_tot)
705 break;
706 }
707
708 seq_puts(seq, "\n\t\t\tread\t\t\twrite\n");
709 seq_puts(seq, "offset rpcs % cum % |");
710 seq_puts(seq, " rpcs % cum %\n");
711
712 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
713 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
714
715 read_cum = 0;
716 write_cum = 0;
717 for (i = 0; i < OBD_HIST_MAX; i++) {
718 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
719 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
720
721 read_cum += r;
722 write_cum += w;
723 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
724 (i == 0) ? 0 : 1 << (i - 1),
725 r, pct(r, read_tot), pct(read_cum, read_tot),
726 w, pct(w, write_tot), pct(write_cum, write_tot));
727 if (read_cum == read_tot && write_cum == write_tot)
728 break;
729 }
730
731 spin_unlock(&cli->cl_loi_list_lock);
732
733 return 0;
734 }
735
736 #undef pct
737
738 static ssize_t osc_rpc_stats_seq_write(struct file *file,
739 const char __user *buf,
740 size_t len, loff_t *off)
741 {
742 struct seq_file *seq = file->private_data;
743 struct obd_device *dev = seq->private;
744 struct client_obd *cli = &dev->u.cli;
745
746 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
747 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
748 lprocfs_oh_clear(&cli->cl_read_page_hist);
749 lprocfs_oh_clear(&cli->cl_write_page_hist);
750 lprocfs_oh_clear(&cli->cl_read_offset_hist);
751 lprocfs_oh_clear(&cli->cl_write_offset_hist);
752
753 return len;
754 }
755
756 LPROC_SEQ_FOPS(osc_rpc_stats);
757
758 static int osc_stats_seq_show(struct seq_file *seq, void *v)
759 {
760 struct timespec64 now;
761 struct obd_device *dev = seq->private;
762 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
763
764 ktime_get_real_ts64(&now);
765
766 seq_printf(seq, "snapshot_time: %llu.%9lu (secs.usecs)\n",
767 (s64)now.tv_sec, (unsigned long)now.tv_nsec);
768 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
769 stats->os_lockless_writes);
770 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
771 stats->os_lockless_reads);
772 seq_printf(seq, "lockless_truncate\t\t%llu\n",
773 stats->os_lockless_truncates);
774 return 0;
775 }
776
777 static ssize_t osc_stats_seq_write(struct file *file,
778 const char __user *buf,
779 size_t len, loff_t *off)
780 {
781 struct seq_file *seq = file->private_data;
782 struct obd_device *dev = seq->private;
783 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
784
785 memset(stats, 0, sizeof(*stats));
786 return len;
787 }
788
789 LPROC_SEQ_FOPS(osc_stats);
790
791 int lproc_osc_attach_seqstat(struct obd_device *dev)
792 {
793 int rc;
794
795 rc = ldebugfs_seq_create(dev->obd_debugfs_entry, "osc_stats", 0644,
796 &osc_stats_fops, dev);
797 if (rc == 0)
798 rc = ldebugfs_obd_seq_create(dev, "rpc_stats", 0644,
799 &osc_rpc_stats_fops, dev);
800
801 return rc;
802 }
803
804 static struct attribute *osc_attrs[] = {
805 &lustre_attr_active.attr,
806 &lustre_attr_checksums.attr,
807 &lustre_attr_contention_seconds.attr,
808 &lustre_attr_cur_dirty_bytes.attr,
809 &lustre_attr_cur_grant_bytes.attr,
810 &lustre_attr_cur_lost_grant_bytes.attr,
811 &lustre_attr_destroys_in_flight.attr,
812 &lustre_attr_grant_shrink_interval.attr,
813 &lustre_attr_lockless_truncate.attr,
814 &lustre_attr_max_dirty_mb.attr,
815 &lustre_attr_max_pages_per_rpc.attr,
816 &lustre_attr_max_rpcs_in_flight.attr,
817 &lustre_attr_resend_count.attr,
818 &lustre_attr_unstable_stats.attr,
819 NULL,
820 };
821
822 static struct attribute_group osc_attr_group = {
823 .attrs = osc_attrs,
824 };
825
826 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
827 {
828 lvars->sysfs_vars = &osc_attr_group;
829 lvars->obd_vars = lprocfs_osc_obd_vars;
830 }
This page took 0.067131 seconds and 5 git commands to generate.