1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include <linux/version.h>
39 #include <lustre_lite.h>
40 #include <lprocfs_status.h>
41 #include <linux/seq_file.h>
42 #include <obd_support.h>
44 #include "llite_internal.h"
46 struct proc_dir_entry *proc_lustre_fs_root;
49 /* /proc/lustre/llite mount point registration */
50 extern struct file_operations vvp_dump_pgcache_file_ops;
51 struct file_operations ll_rw_extents_stats_fops;
52 struct file_operations ll_rw_extents_stats_pp_fops;
53 struct file_operations ll_rw_offset_stats_fops;
55 static int ll_rd_blksize(char *page, char **start, off_t off, int count,
58 struct super_block *sb = (struct super_block *)data;
59 struct obd_statfs osfs;
63 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
67 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
73 static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
76 struct super_block *sb = (struct super_block *)data;
77 struct obd_statfs osfs;
81 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
84 __u32 blk_size = osfs.os_bsize >> 10;
85 __u64 result = osfs.os_blocks;
87 while (blk_size >>= 1)
91 rc = snprintf(page, count, LPU64"\n", result);
97 static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
100 struct super_block *sb = (struct super_block *)data;
101 struct obd_statfs osfs;
105 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
108 __u32 blk_size = osfs.os_bsize >> 10;
109 __u64 result = osfs.os_bfree;
111 while (blk_size >>= 1)
115 rc = snprintf(page, count, LPU64"\n", result);
120 static int ll_rd_kbytesavail(char *page, char **start, off_t off, int count,
121 int *eof, void *data)
123 struct super_block *sb = (struct super_block *)data;
124 struct obd_statfs osfs;
128 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
131 __u32 blk_size = osfs.os_bsize >> 10;
132 __u64 result = osfs.os_bavail;
134 while (blk_size >>= 1)
138 rc = snprintf(page, count, LPU64"\n", result);
143 static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
144 int *eof, void *data)
146 struct super_block *sb = (struct super_block *)data;
147 struct obd_statfs osfs;
151 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
155 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
160 static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
161 int *eof, void *data)
163 struct super_block *sb = (struct super_block *)data;
164 struct obd_statfs osfs;
168 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
172 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
178 static int ll_rd_client_type(char *page, char **start, off_t off, int count,
179 int *eof, void *data)
181 struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)data);
184 LASSERT(sbi != NULL);
187 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
188 rc = snprintf(page, count, "remote client\n");
190 rc = snprintf(page, count, "local client\n");
195 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
196 int *eof, void *data)
198 struct super_block *sb = (struct super_block*)data;
202 return snprintf(page, count, "%s\n", sb->s_type->name);
205 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
206 int *eof, void *data)
208 struct super_block *sb = (struct super_block *)data;
212 return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
215 static int ll_rd_site_stats(char *page, char **start, off_t off,
216 int count, int *eof, void *data)
218 struct super_block *sb = data;
221 * See description of statistical counters in struct cl_site, and
224 return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site),
228 static int ll_rd_max_readahead_mb(char *page, char **start, off_t off,
229 int count, int *eof, void *data)
231 struct super_block *sb = data;
232 struct ll_sb_info *sbi = ll_s2sbi(sb);
236 spin_lock(&sbi->ll_lock);
237 pages_number = sbi->ll_ra_info.ra_max_pages;
238 spin_unlock(&sbi->ll_lock);
240 mult = 1 << (20 - PAGE_CACHE_SHIFT);
241 return lprocfs_read_frac_helper(page, count, pages_number, mult);
244 static int ll_wr_max_readahead_mb(struct file *file, const char *buffer,
245 unsigned long count, void *data)
247 struct super_block *sb = data;
248 struct ll_sb_info *sbi = ll_s2sbi(sb);
249 int mult, rc, pages_number;
251 mult = 1 << (20 - CFS_PAGE_SHIFT);
252 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
256 if (pages_number < 0 || pages_number > num_physpages / 2) {
257 CERROR("can't set file readahead more than %lu MB\n",
258 num_physpages >> (20 - CFS_PAGE_SHIFT + 1)); /*1/2 of RAM*/
262 spin_lock(&sbi->ll_lock);
263 sbi->ll_ra_info.ra_max_pages = pages_number;
264 spin_unlock(&sbi->ll_lock);
269 static int ll_rd_max_read_ahead_whole_mb(char *page, char **start, off_t off,
270 int count, int *eof, void *data)
272 struct super_block *sb = data;
273 struct ll_sb_info *sbi = ll_s2sbi(sb);
277 spin_lock(&sbi->ll_lock);
278 pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
279 spin_unlock(&sbi->ll_lock);
281 mult = 1 << (20 - CFS_PAGE_SHIFT);
282 return lprocfs_read_frac_helper(page, count, pages_number, mult);
285 static int ll_wr_max_read_ahead_whole_mb(struct file *file, const char *buffer,
286 unsigned long count, void *data)
288 struct super_block *sb = data;
289 struct ll_sb_info *sbi = ll_s2sbi(sb);
290 int mult, rc, pages_number;
292 mult = 1 << (20 - CFS_PAGE_SHIFT);
293 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
297 /* Cap this at the current max readahead window size, the readahead
298 * algorithm does this anyway so it's pointless to set it larger. */
299 if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
300 CERROR("can't set max_read_ahead_whole_mb more than "
301 "max_read_ahead_mb: %lu\n",
302 sbi->ll_ra_info.ra_max_pages >> (20 - CFS_PAGE_SHIFT));
306 spin_lock(&sbi->ll_lock);
307 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
308 spin_unlock(&sbi->ll_lock);
313 static int ll_rd_max_cached_mb(char *page, char **start, off_t off,
314 int count, int *eof, void *data)
316 struct super_block *sb = data;
317 struct ll_sb_info *sbi = ll_s2sbi(sb);
321 spin_lock(&sbi->ll_lock);
322 pages_number = sbi->ll_async_page_max;
323 spin_unlock(&sbi->ll_lock);
325 mult = 1 << (20 - CFS_PAGE_SHIFT);
326 return lprocfs_read_frac_helper(page, count, pages_number, mult);;
329 static int ll_wr_max_cached_mb(struct file *file, const char *buffer,
330 unsigned long count, void *data)
332 struct super_block *sb = data;
333 struct ll_sb_info *sbi = ll_s2sbi(sb);
334 int mult, rc, pages_number;
336 mult = 1 << (20 - CFS_PAGE_SHIFT);
337 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
341 if (pages_number < 0 || pages_number > num_physpages) {
342 CERROR("can't set max cache more than %lu MB\n",
343 num_physpages >> (20 - CFS_PAGE_SHIFT));
347 spin_lock(&sbi->ll_lock);
348 sbi->ll_async_page_max = pages_number ;
349 spin_unlock(&sbi->ll_lock);
352 /* Not set up yet, don't call llap_shrink_cache */
358 static int ll_rd_checksum(char *page, char **start, off_t off,
359 int count, int *eof, void *data)
361 struct super_block *sb = data;
362 struct ll_sb_info *sbi = ll_s2sbi(sb);
364 return snprintf(page, count, "%u\n",
365 (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
368 static int ll_wr_checksum(struct file *file, const char *buffer,
369 unsigned long count, void *data)
371 struct super_block *sb = data;
372 struct ll_sb_info *sbi = ll_s2sbi(sb);
379 rc = lprocfs_write_helper(buffer, count, &val);
383 sbi->ll_flags |= LL_SBI_CHECKSUM;
385 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
387 rc = obd_set_info_async(sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
388 KEY_CHECKSUM, sizeof(val), &val, NULL);
390 CWARN("Failed to set OSC checksum flags: %d\n", rc);
395 static int ll_rd_max_rw_chunk(char *page, char **start, off_t off,
396 int count, int *eof, void *data)
398 struct super_block *sb = data;
400 return snprintf(page, count, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
403 static int ll_wr_max_rw_chunk(struct file *file, const char *buffer,
404 unsigned long count, void *data)
406 struct super_block *sb = data;
409 rc = lprocfs_write_helper(buffer, count, &val);
412 ll_s2sbi(sb)->ll_max_rw_chunk = val;
416 static int ll_rd_track_id(char *page, int count, void *data,
417 enum stats_track_type type)
419 struct super_block *sb = data;
421 if (ll_s2sbi(sb)->ll_stats_track_type == type) {
422 return snprintf(page, count, "%d\n",
423 ll_s2sbi(sb)->ll_stats_track_id);
425 } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
426 return snprintf(page, count, "0 (all)\n");
428 return snprintf(page, count, "untracked\n");
432 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
433 enum stats_track_type type)
435 struct super_block *sb = data;
438 rc = lprocfs_write_helper(buffer, count, &pid);
441 ll_s2sbi(sb)->ll_stats_track_id = pid;
443 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
445 ll_s2sbi(sb)->ll_stats_track_type = type;
446 lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
450 static int ll_rd_track_pid(char *page, char **start, off_t off,
451 int count, int *eof, void *data)
453 return (ll_rd_track_id(page, count, data, STATS_TRACK_PID));
456 static int ll_wr_track_pid(struct file *file, const char *buffer,
457 unsigned long count, void *data)
459 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PID));
462 static int ll_rd_track_ppid(char *page, char **start, off_t off,
463 int count, int *eof, void *data)
465 return (ll_rd_track_id(page, count, data, STATS_TRACK_PPID));
468 static int ll_wr_track_ppid(struct file *file, const char *buffer,
469 unsigned long count, void *data)
471 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PPID));
474 static int ll_rd_track_gid(char *page, char **start, off_t off,
475 int count, int *eof, void *data)
477 return (ll_rd_track_id(page, count, data, STATS_TRACK_GID));
480 static int ll_wr_track_gid(struct file *file, const char *buffer,
481 unsigned long count, void *data)
483 return (ll_wr_track_id(buffer, count, data, STATS_TRACK_GID));
486 static int ll_rd_statahead_max(char *page, char **start, off_t off,
487 int count, int *eof, void *data)
489 struct super_block *sb = data;
490 struct ll_sb_info *sbi = ll_s2sbi(sb);
492 return snprintf(page, count, "%u\n", sbi->ll_sa_max);
495 static int ll_wr_statahead_max(struct file *file, const char *buffer,
496 unsigned long count, void *data)
498 struct super_block *sb = data;
499 struct ll_sb_info *sbi = ll_s2sbi(sb);
502 rc = lprocfs_write_helper(buffer, count, &val);
506 if (val >= 0 && val <= LL_SA_RPC_MAX)
507 sbi->ll_sa_max = val;
509 CERROR("Bad statahead_max value %d. Valid values are in the "
510 "range [0, %d]\n", val, LL_SA_RPC_MAX);
515 static int ll_rd_statahead_stats(char *page, char **start, off_t off,
516 int count, int *eof, void *data)
518 struct super_block *sb = data;
519 struct ll_sb_info *sbi = ll_s2sbi(sb);
521 return snprintf(page, count,
522 "statahead wrong: %u\n"
523 "statahead total: %u\n"
527 "miss count: %llu\n",
536 static int ll_rd_lazystatfs(char *page, char **start, off_t off,
537 int count, int *eof, void *data)
539 struct super_block *sb = data;
540 struct ll_sb_info *sbi = ll_s2sbi(sb);
542 return snprintf(page, count, "%u\n",
543 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
546 static int ll_wr_lazystatfs(struct file *file, const char *buffer,
547 unsigned long count, void *data)
549 struct super_block *sb = data;
550 struct ll_sb_info *sbi = ll_s2sbi(sb);
553 rc = lprocfs_write_helper(buffer, count, &val);
558 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
560 sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
565 static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
566 { "uuid", ll_rd_sb_uuid, 0, 0 },
567 //{ "mntpt_path", ll_rd_path, 0, 0 },
568 { "fstype", ll_rd_fstype, 0, 0 },
569 { "site", ll_rd_site_stats, 0, 0 },
570 { "blocksize", ll_rd_blksize, 0, 0 },
571 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
572 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
573 { "kbytesavail", ll_rd_kbytesavail, 0, 0 },
574 { "filestotal", ll_rd_filestotal, 0, 0 },
575 { "filesfree", ll_rd_filesfree, 0, 0 },
576 { "client_type", ll_rd_client_type, 0, 0 },
577 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
578 { "max_read_ahead_mb", ll_rd_max_readahead_mb,
579 ll_wr_max_readahead_mb, 0 },
580 { "max_read_ahead_whole_mb", ll_rd_max_read_ahead_whole_mb,
581 ll_wr_max_read_ahead_whole_mb, 0 },
582 { "max_cached_mb", ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
583 { "checksum_pages", ll_rd_checksum, ll_wr_checksum, 0 },
584 { "max_rw_chunk", ll_rd_max_rw_chunk, ll_wr_max_rw_chunk, 0 },
585 { "stats_track_pid", ll_rd_track_pid, ll_wr_track_pid, 0 },
586 { "stats_track_ppid", ll_rd_track_ppid, ll_wr_track_ppid, 0 },
587 { "stats_track_gid", ll_rd_track_gid, ll_wr_track_gid, 0 },
588 { "statahead_max", ll_rd_statahead_max, ll_wr_statahead_max, 0 },
589 { "statahead_stats", ll_rd_statahead_stats, 0, 0 },
590 { "lazystatfs", ll_rd_lazystatfs, ll_wr_lazystatfs, 0 },
594 #define MAX_STRING_SIZE 128
596 struct llite_file_opcode {
600 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
602 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
603 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
604 { LPROC_LL_WB_WRITEPAGE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
605 "writeback_from_writepage" },
606 { LPROC_LL_WB_PRESSURE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
607 "writeback_from_pressure" },
608 { LPROC_LL_WB_OK, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
609 "writeback_ok_pages" },
610 { LPROC_LL_WB_FAIL, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
611 "writeback_failed_pages" },
612 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
614 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
616 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
618 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
621 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
622 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
623 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
624 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
625 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
626 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
627 /* inode operation */
628 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
629 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "truncate" },
630 { LPROC_LL_LOCKLESS_TRUNC, LPROCFS_TYPE_REGS, "lockless_truncate"},
631 { LPROC_LL_FLOCK, LPROCFS_TYPE_REGS, "flock" },
632 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
633 /* special inode operation */
634 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
635 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
636 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
637 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
638 { LPROC_LL_LISTXATTR, LPROCFS_TYPE_REGS, "listxattr" },
639 { LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_REGS, "removexattr" },
640 { LPROC_LL_INODE_PERM, LPROCFS_TYPE_REGS, "inode_permission" },
641 { LPROC_LL_DIRECT_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
643 { LPROC_LL_DIRECT_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
645 { LPROC_LL_LOCKLESS_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
646 "lockless_read_bytes" },
647 { LPROC_LL_LOCKLESS_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
648 "lockless_write_bytes" },
652 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
656 if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
657 lprocfs_counter_add(sbi->ll_stats, op, count);
658 else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
659 sbi->ll_stats_track_id == current->pid)
660 lprocfs_counter_add(sbi->ll_stats, op, count);
661 else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
662 sbi->ll_stats_track_id == current->p_pptr->pid)
663 lprocfs_counter_add(sbi->ll_stats, op, count);
664 else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
665 sbi->ll_stats_track_id == current->gid)
666 lprocfs_counter_add(sbi->ll_stats, op, count);
668 EXPORT_SYMBOL(ll_stats_ops_tally);
670 static const char *ra_stat_string[] = {
671 [RA_STAT_HIT] = "hits",
672 [RA_STAT_MISS] = "misses",
673 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
674 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
675 [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
676 [RA_STAT_FAILED_MATCH] = "failed lock match",
677 [RA_STAT_DISCARDED] = "read but discarded",
678 [RA_STAT_ZERO_LEN] = "zero length file",
679 [RA_STAT_ZERO_WINDOW] = "zero size window",
680 [RA_STAT_EOF] = "read-ahead to EOF",
681 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
682 [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
686 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
687 struct super_block *sb, char *osc, char *mdc)
689 struct lprocfs_vars lvars[2];
690 struct lustre_sb_info *lsi = s2lsi(sb);
691 struct ll_sb_info *sbi = ll_s2sbi(sb);
692 struct obd_device *obd;
693 char name[MAX_STRING_SIZE + 1], *ptr;
694 int err, id, len, rc;
697 memset(lvars, 0, sizeof(lvars));
699 name[MAX_STRING_SIZE] = '\0';
700 lvars[0].name = name;
702 LASSERT(sbi != NULL);
703 LASSERT(mdc != NULL);
704 LASSERT(osc != NULL);
707 len = strlen(lsi->lsi_lmd->lmd_profile);
708 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
709 if (ptr && (strcmp(ptr, "-client") == 0))
713 snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
714 lsi->lsi_lmd->lmd_profile, sb);
716 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
717 if (IS_ERR(sbi->ll_proc_root)) {
718 err = PTR_ERR(sbi->ll_proc_root);
719 sbi->ll_proc_root = NULL;
723 rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
724 &vvp_dump_pgcache_file_ops, sbi);
726 CWARN("Error adding the dump_page_cache file\n");
728 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
729 &ll_rw_extents_stats_fops, sbi);
731 CWARN("Error adding the extent_stats file\n");
733 rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
734 0644, &ll_rw_extents_stats_pp_fops, sbi);
736 CWARN("Error adding the extents_stats_per_process file\n");
738 rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
739 &ll_rw_offset_stats_fops, sbi);
741 CWARN("Error adding the offset_stats file\n");
743 /* File operations stats */
744 sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
745 LPROCFS_STATS_FLAG_NONE);
746 if (sbi->ll_stats == NULL)
747 GOTO(out, err = -ENOMEM);
748 /* do counter init */
749 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
750 __u32 type = llite_opcode_table[id].type;
752 if (type & LPROCFS_TYPE_REGS)
754 else if (type & LPROCFS_TYPE_BYTES)
756 else if (type & LPROCFS_TYPE_PAGES)
758 lprocfs_counter_init(sbi->ll_stats,
759 llite_opcode_table[id].opcode,
760 (type & LPROCFS_CNTR_AVGMINMAX),
761 llite_opcode_table[id].opname, ptr);
763 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
767 sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
768 LPROCFS_STATS_FLAG_NONE);
769 if (sbi->ll_ra_stats == NULL)
770 GOTO(out, err = -ENOMEM);
772 for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
773 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
774 ra_stat_string[id], "pages");
775 err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
781 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
786 obd = class_name2obd(mdc);
788 LASSERT(obd != NULL);
789 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
790 LASSERT(obd->obd_type->typ_name != NULL);
792 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
793 obd->obd_type->typ_name);
794 lvars[0].read_fptr = lprocfs_rd_name;
795 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
799 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
800 lvars[0].read_fptr = lprocfs_rd_uuid;
801 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
806 obd = class_name2obd(osc);
808 LASSERT(obd != NULL);
809 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
810 LASSERT(obd->obd_type->typ_name != NULL);
812 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
813 obd->obd_type->typ_name);
814 lvars[0].read_fptr = lprocfs_rd_name;
815 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
819 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
820 lvars[0].read_fptr = lprocfs_rd_uuid;
821 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
824 lprocfs_remove(&sbi->ll_proc_root);
825 lprocfs_free_stats(&sbi->ll_ra_stats);
826 lprocfs_free_stats(&sbi->ll_stats);
831 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
833 if (sbi->ll_proc_root) {
834 lprocfs_remove(&sbi->ll_proc_root);
835 lprocfs_free_stats(&sbi->ll_ra_stats);
836 lprocfs_free_stats(&sbi->ll_stats);
839 #undef MAX_STRING_SIZE
841 #define pct(a,b) (b ? a * 100 / b : 0)
843 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
844 struct seq_file *seq, int which)
846 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
847 unsigned long start, end, r, w;
848 char *unitp = "KMGTPEZY";
850 struct per_process_info *pp_info = &io_extents->pp_extents[which];
856 for(i = 0; i < LL_HIST_MAX; i++) {
857 read_tot += pp_info->pp_r_hist.oh_buckets[i];
858 write_tot += pp_info->pp_w_hist.oh_buckets[i];
861 for(i = 0; i < LL_HIST_MAX; i++) {
862 r = pp_info->pp_r_hist.oh_buckets[i];
863 w = pp_info->pp_w_hist.oh_buckets[i];
866 end = 1 << (i + LL_HIST_START - units);
867 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | "
868 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
869 (i == LL_HIST_MAX - 1) ? '+' : ' ',
870 r, pct(r, read_tot), pct(read_cum, read_tot),
871 w, pct(w, write_tot), pct(write_cum, write_tot));
873 if (start == 1<<10) {
878 if (read_cum == read_tot && write_cum == write_tot)
883 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
886 struct ll_sb_info *sbi = seq->private;
887 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
890 do_gettimeofday(&now);
892 if (!sbi->ll_rw_stats_on) {
893 seq_printf(seq, "disabled\n"
894 "write anything in this file to activate, "
895 "then 0 or \"[D/d]isabled\" to deactivate\n");
898 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
899 now.tv_sec, now.tv_usec);
900 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
901 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
902 "extents", "calls", "%", "cum%",
903 "calls", "%", "cum%");
904 spin_lock(&sbi->ll_pp_extent_lock);
905 for(k = 0; k < LL_PROCESS_HIST_MAX; k++) {
906 if(io_extents->pp_extents[k].pid != 0) {
907 seq_printf(seq, "\nPID: %d\n",
908 io_extents->pp_extents[k].pid);
909 ll_display_extents_info(io_extents, seq, k);
912 spin_unlock(&sbi->ll_pp_extent_lock);
916 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
917 const char *buf, size_t len,
920 struct seq_file *seq = file->private_data;
921 struct ll_sb_info *sbi = seq->private;
922 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
924 int value = 1, rc = 0;
926 rc = lprocfs_write_helper(buf, len, &value);
927 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
928 strcmp(buf, "Disabled") == 0))
932 sbi->ll_rw_stats_on = 0;
934 sbi->ll_rw_stats_on = 1;
936 spin_lock(&sbi->ll_pp_extent_lock);
937 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
938 io_extents->pp_extents[i].pid = 0;
939 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
940 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
942 spin_unlock(&sbi->ll_pp_extent_lock);
946 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
948 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
951 struct ll_sb_info *sbi = seq->private;
952 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
954 do_gettimeofday(&now);
956 if (!sbi->ll_rw_stats_on) {
957 seq_printf(seq, "disabled\n"
958 "write anything in this file to activate, "
959 "then 0 or \"[D/d]isabled\" to deactivate\n");
962 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
963 now.tv_sec, now.tv_usec);
965 seq_printf(seq, "%15s %19s | %20s\n", " ", "read", "write");
966 seq_printf(seq, "%13s %14s %4s %4s | %14s %4s %4s\n",
967 "extents", "calls", "%", "cum%",
968 "calls", "%", "cum%");
969 spin_lock(&sbi->ll_lock);
970 ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
971 spin_unlock(&sbi->ll_lock);
976 static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
977 size_t len, loff_t *off)
979 struct seq_file *seq = file->private_data;
980 struct ll_sb_info *sbi = seq->private;
981 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
983 int value = 1, rc = 0;
985 rc = lprocfs_write_helper(buf, len, &value);
986 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
987 strcmp(buf, "Disabled") == 0))
991 sbi->ll_rw_stats_on = 0;
993 sbi->ll_rw_stats_on = 1;
994 spin_lock(&sbi->ll_pp_extent_lock);
995 for(i = 0; i <= LL_PROCESS_HIST_MAX; i++)
997 io_extents->pp_extents[i].pid = 0;
998 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
999 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1001 spin_unlock(&sbi->ll_pp_extent_lock);
1006 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1008 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1009 struct ll_file_data *file, loff_t pos,
1010 size_t count, int rw)
1013 struct ll_rw_process_info *process;
1014 struct ll_rw_process_info *offset;
1015 int *off_count = &sbi->ll_rw_offset_entry_count;
1016 int *process_count = &sbi->ll_offset_process_count;
1017 struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1019 if(!sbi->ll_rw_stats_on)
1021 process = sbi->ll_rw_process_info;
1022 offset = sbi->ll_rw_offset_info;
1024 spin_lock(&sbi->ll_pp_extent_lock);
1025 /* Extent statistics */
1026 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1027 if(io_extents->pp_extents[i].pid == pid) {
1035 sbi->ll_extent_process_count =
1036 (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1037 cur = sbi->ll_extent_process_count;
1038 io_extents->pp_extents[cur].pid = pid;
1039 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1040 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1043 for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1044 (i < (LL_HIST_MAX - 1)); i++);
1046 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1047 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1049 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1050 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1052 spin_unlock(&sbi->ll_pp_extent_lock);
1054 spin_lock(&sbi->ll_process_lock);
1055 /* Offset statistics */
1056 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1057 if (process[i].rw_pid == pid) {
1058 if (process[i].rw_last_file != file) {
1059 process[i].rw_range_start = pos;
1060 process[i].rw_last_file_pos = pos + count;
1061 process[i].rw_smallest_extent = count;
1062 process[i].rw_largest_extent = count;
1063 process[i].rw_offset = 0;
1064 process[i].rw_last_file = file;
1065 spin_unlock(&sbi->ll_process_lock);
1068 if (process[i].rw_last_file_pos != pos) {
1070 (*off_count + 1) % LL_OFFSET_HIST_MAX;
1071 offset[*off_count].rw_op = process[i].rw_op;
1072 offset[*off_count].rw_pid = pid;
1073 offset[*off_count].rw_range_start =
1074 process[i].rw_range_start;
1075 offset[*off_count].rw_range_end =
1076 process[i].rw_last_file_pos;
1077 offset[*off_count].rw_smallest_extent =
1078 process[i].rw_smallest_extent;
1079 offset[*off_count].rw_largest_extent =
1080 process[i].rw_largest_extent;
1081 offset[*off_count].rw_offset =
1082 process[i].rw_offset;
1083 process[i].rw_op = rw;
1084 process[i].rw_range_start = pos;
1085 process[i].rw_smallest_extent = count;
1086 process[i].rw_largest_extent = count;
1087 process[i].rw_offset = pos -
1088 process[i].rw_last_file_pos;
1090 if(process[i].rw_smallest_extent > count)
1091 process[i].rw_smallest_extent = count;
1092 if(process[i].rw_largest_extent < count)
1093 process[i].rw_largest_extent = count;
1094 process[i].rw_last_file_pos = pos + count;
1095 spin_unlock(&sbi->ll_process_lock);
1099 *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1100 process[*process_count].rw_pid = pid;
1101 process[*process_count].rw_op = rw;
1102 process[*process_count].rw_range_start = pos;
1103 process[*process_count].rw_last_file_pos = pos + count;
1104 process[*process_count].rw_smallest_extent = count;
1105 process[*process_count].rw_largest_extent = count;
1106 process[*process_count].rw_offset = 0;
1107 process[*process_count].rw_last_file = file;
1108 spin_unlock(&sbi->ll_process_lock);
1111 char lpszt[] = LPSZ;
1113 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1116 struct ll_sb_info *sbi = seq->private;
1117 struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1118 struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1122 do_gettimeofday(&now);
1124 if (!sbi->ll_rw_stats_on) {
1125 seq_printf(seq, "disabled\n"
1126 "write anything in this file to activate, "
1127 "then 0 or \"[D/d]isabled\" to deactivate\n");
1130 spin_lock(&sbi->ll_process_lock);
1132 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
1133 now.tv_sec, now.tv_usec);
1134 seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1135 "R/W", "PID", "RANGE START", "RANGE END",
1136 "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1137 sprintf(format, "%s%s%s%s%s\n",
1138 "%3c %10d %14Lu %14Lu %17", lpszt+1, " %17", lpszt+1, " %14Ld");
1139 /* We stored the discontiguous offsets here; print them first */
1140 for(i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1141 if (offset[i].rw_pid != 0)
1142 /* Is there a way to snip the '%' off of LPSZ? */
1143 seq_printf(seq, format,
1144 offset[i].rw_op ? 'W' : 'R',
1146 offset[i].rw_range_start,
1147 offset[i].rw_range_end,
1148 offset[i].rw_smallest_extent,
1149 offset[i].rw_largest_extent,
1150 offset[i].rw_offset);
1152 /* Then print the current offsets for each process */
1153 for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1154 if (process[i].rw_pid != 0)
1155 seq_printf(seq, format,
1156 process[i].rw_op ? 'W' : 'R',
1158 process[i].rw_range_start,
1159 process[i].rw_last_file_pos,
1160 process[i].rw_smallest_extent,
1161 process[i].rw_largest_extent,
1162 process[i].rw_offset);
1164 spin_unlock(&sbi->ll_process_lock);
1169 static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1170 size_t len, loff_t *off)
1172 struct seq_file *seq = file->private_data;
1173 struct ll_sb_info *sbi = seq->private;
1174 struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1175 struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1176 int value = 1, rc = 0;
1178 rc = lprocfs_write_helper(buf, len, &value);
1180 if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1181 strcmp(buf, "Disabled") == 0))
1185 sbi->ll_rw_stats_on = 0;
1187 sbi->ll_rw_stats_on = 1;
1189 spin_lock(&sbi->ll_process_lock);
1190 sbi->ll_offset_process_count = 0;
1191 sbi->ll_rw_offset_entry_count = 0;
1192 memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1193 LL_PROCESS_HIST_MAX);
1194 memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1195 LL_OFFSET_HIST_MAX);
1196 spin_unlock(&sbi->ll_process_lock);
1201 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1203 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
1205 lvars->module_vars = NULL;
1206 lvars->obd_vars = lprocfs_llite_obd_vars;
1208 #endif /* LPROCFS */