1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define DEBUG_SUBSYSTEM S_CLASS
24 #include <linux/version.h>
25 #include <linux/lprocfs_status.h>
26 #include <linux/obd.h>
27 #include <linux/seq_file.h>
29 #include "filter_internal.h"
32 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
33 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
36 static int lprocfs_filter_rd_mntdev(char *page, char **start, off_t off,
37 int count, int *eof, void *data)
39 struct obd_device* obd = (struct obd_device *)data;
42 LASSERT(obd->u.filter.fo_vfsmnt->mnt_devname);
44 return snprintf(page, count, "%s\n",
45 obd->u.filter.fo_vfsmnt->mnt_devname);
48 static int lprocfs_filter_rd_last_id(char *page, char **start, off_t off,
49 int count, int *eof, void *data)
51 struct obd_device *obd = data;
56 return snprintf(page, count, LPU64"\n",
57 filter_last_id(&obd->u.filter, 0));
60 static struct lprocfs_vars lprocfs_obd_vars[] = {
61 { "uuid", lprocfs_rd_uuid, 0, 0 },
62 { "blocksize", lprocfs_rd_blksize, 0, 0 },
63 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
64 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
65 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
66 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
67 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
68 { "fstype", lprocfs_rd_fstype, 0, 0 },
69 { "mntdev", lprocfs_filter_rd_mntdev, 0, 0 },
70 { "last_id", lprocfs_filter_rd_last_id, 0, 0 },
74 static struct lprocfs_vars lprocfs_module_vars[] = {
75 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
79 void filter_tally_write(struct filter_obd *filter, struct page **pages,
80 int nr_pages, unsigned long *blocks, int blocks_per_page)
82 struct page *last_page = NULL;
83 unsigned long *last_block = NULL;
84 unsigned long discont_pages = 0;
85 unsigned long discont_blocks = 0;
91 lprocfs_oh_tally_log2(&filter->fo_w_pages, nr_pages);
93 while (nr_pages-- > 0) {
94 if (last_page && (*pages)->index != (last_page->index + 1))
98 for (i = 0; i < blocks_per_page; i++) {
99 if (last_block && *blocks != (*last_block + 1))
101 last_block = blocks++;
105 lprocfs_oh_tally(&filter->fo_w_discont_pages, discont_pages);
106 lprocfs_oh_tally(&filter->fo_w_discont_blocks, discont_blocks);
109 void filter_tally_read(struct filter_obd *filter, struct niobuf_local *lnb,
112 struct niobuf_local *end;
113 struct page *last_page = NULL;
114 unsigned long discont_pages = 0;
115 unsigned long discont_blocks = 0;
120 for (end = lnb + niocount; lnb < end && lnb->page; lnb++) {
121 struct page *page = lnb->page;
123 if (page->index != (last_page->index + 1))
125 /* XXX not so smart for now */
126 if ((page->buffers && last_page->buffers) &&
127 (page->buffers->b_blocknr !=
128 (last_page->buffers->b_blocknr + 1)))
134 lprocfs_oh_tally_log2(&filter->fo_r_pages, niocount);
135 lprocfs_oh_tally(&filter->fo_r_discont_pages, discont_pages);
136 lprocfs_oh_tally(&filter->fo_r_discont_blocks, discont_blocks);
139 #define pct(a,b) (b ? a * 100 / b : 0)
141 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
144 struct obd_device *dev = seq->private;
145 struct filter_obd *filter = &dev->u.filter;
146 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
149 do_gettimeofday(&now);
151 /* this sampling races with updates */
153 seq_printf(seq, "snapshot_time: %lu:%lu (secs:usecs)\n",
154 now.tv_sec, now.tv_usec);
156 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
157 seq_printf(seq, "pages per brw brws %% cum %% |");
158 seq_printf(seq, " rpcs %% cum %%\n");
160 read_tot = lprocfs_oh_sum(&filter->fo_r_pages);
161 write_tot = lprocfs_oh_sum(&filter->fo_w_pages);
165 for (i = 0; i < OBD_HIST_MAX; i++) {
166 unsigned long r = filter->fo_r_pages.oh_buckets[i];
167 unsigned long w = filter->fo_w_pages.oh_buckets[i];
170 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
171 1 << i, r, pct(r, read_tot),
172 pct(read_cum, read_tot), w,
174 pct(write_cum, write_tot));
175 if (read_cum == read_tot && write_cum == write_tot)
179 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
180 seq_printf(seq, "discont pages rpcs %% cum %% |");
181 seq_printf(seq, " rpcs %% cum %%\n");
183 read_tot = lprocfs_oh_sum(&filter->fo_r_discont_pages);
184 write_tot = lprocfs_oh_sum(&filter->fo_w_discont_pages);
189 for (i = 0; i < OBD_HIST_MAX; i++) {
190 unsigned long r = filter->fo_r_discont_pages.oh_buckets[i];
191 unsigned long w = filter->fo_w_discont_pages.oh_buckets[i];
194 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
195 i, r, pct(r, read_tot),
196 pct(read_cum, read_tot), w,
198 pct(write_cum, write_tot));
199 if (read_cum == read_tot && write_cum == write_tot)
203 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
204 seq_printf(seq, "discont blocks rpcs %% cum %% |");
205 seq_printf(seq, " rpcs %% cum %%\n");
207 read_tot = lprocfs_oh_sum(&filter->fo_r_discont_blocks);
208 write_tot = lprocfs_oh_sum(&filter->fo_w_discont_blocks);
212 for (i = 0; i < OBD_HIST_MAX; i++) {
213 unsigned long r = filter->fo_r_discont_blocks.oh_buckets[i];
214 unsigned long w = filter->fo_w_discont_blocks.oh_buckets[i];
217 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
218 i, r, pct(r, read_tot),
219 pct(read_cum, read_tot), w,
221 pct(write_cum, write_tot));
222 if (read_cum == read_tot && write_cum == write_tot)
230 static void *filter_brw_stats_seq_start(struct seq_file *p, loff_t *pos)
236 static void *filter_brw_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
241 static void filter_brw_stats_seq_stop(struct seq_file *p, void *v)
244 struct seq_operations filter_brw_stats_seq_sops = {
245 .start = filter_brw_stats_seq_start,
246 .stop = filter_brw_stats_seq_stop,
247 .next = filter_brw_stats_seq_next,
248 .show = filter_brw_stats_seq_show,
251 static int filter_brw_stats_seq_open(struct inode *inode, struct file *file)
253 struct proc_dir_entry *dp = inode->u.generic_ip;
254 struct seq_file *seq;
257 rc = seq_open(file, &filter_brw_stats_seq_sops);
260 seq = file->private_data;
261 seq->private = dp->data;
265 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
266 size_t len, loff_t *off)
268 struct seq_file *seq = file->private_data;
269 struct obd_device *dev = seq->private;
270 struct filter_obd *filter = &dev->u.filter;
272 lprocfs_oh_clear(&filter->fo_r_pages);
273 lprocfs_oh_clear(&filter->fo_w_pages);
274 lprocfs_oh_clear(&filter->fo_r_discont_pages);
275 lprocfs_oh_clear(&filter->fo_w_discont_pages);
276 lprocfs_oh_clear(&filter->fo_r_discont_blocks);
277 lprocfs_oh_clear(&filter->fo_w_discont_blocks);
282 struct file_operations filter_brw_stats_fops = {
283 .open = filter_brw_stats_seq_open,
285 .write = filter_brw_stats_seq_write,
287 .release = seq_release,
290 int lproc_filter_attach_seqstat(struct obd_device *dev)
292 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
293 &filter_brw_stats_fops, dev);
299 LPROCFS_INIT_VARS(filter,lprocfs_module_vars, lprocfs_obd_vars)