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>
28 #include <linux/version.h>
30 #include "filter_internal.h"
33 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
34 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
37 static int lprocfs_filter_rd_groups(char *page, char **start, off_t off,
38 int count, int *eof, void *data)
40 struct obd_device *obd = (struct obd_device *)data;
43 return snprintf(page, count, "%u\n", obd->u.filter.fo_group_count);
46 static int lprocfs_filter_rd_tot_dirty(char *page, char **start, off_t off,
47 int count, int *eof, void *data)
49 struct obd_device *obd = (struct obd_device *)data;
53 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_dirty);
56 static int lprocfs_filter_rd_tot_granted(char *page, char **start, off_t off,
57 int count, int *eof, void *data)
59 struct obd_device *obd = (struct obd_device *)data;
63 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_granted);
66 static int lprocfs_filter_rd_tot_pending(char *page, char **start, off_t off,
67 int count, int *eof, void *data)
69 struct obd_device *obd = (struct obd_device *)data;
73 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_pending);
76 static int lprocfs_filter_rd_mntdev(char *page, char **start, off_t off,
77 int count, int *eof, void *data)
79 struct obd_device *obd = (struct obd_device *)data;
82 LASSERT(obd->u.filter.fo_vfsmnt->mnt_devname);
84 return snprintf(page, count, "%s\n",
85 obd->u.filter.fo_vfsmnt->mnt_devname);
88 static int lprocfs_filter_rd_last_id(char *page, char **start, off_t off,
89 int count, int *eof, void *data)
91 struct obd_device *obd = data;
92 struct filter_obd *filter = &obd->u.filter;
93 int retval = 0, rc, i;
98 for (i = 1; i < filter->fo_group_count; i++) {
99 rc = snprintf(page, count, LPU64"\n",filter_last_id(filter, i));
111 int lprocfs_filter_rd_readcache(char *page, char **start, off_t off, int count,
112 int *eof, void *data)
114 struct obd_device *obd = data;
117 rc = snprintf(page, count, LPU64"\n",
118 obd->u.filter.fo_readcache_max_filesize);
122 int lprocfs_filter_wr_readcache(struct file *file, const char *buffer,
123 unsigned long count, void *data)
125 struct obd_device *obd = data;
129 rc = lprocfs_write_u64_helper(buffer, count, &val);
133 obd->u.filter.fo_readcache_max_filesize = val;
137 int lprocfs_filter_rd_capa_stat(char *page, char **start, off_t off, int count,
138 int *eof, void *data)
140 struct obd_device *obd = data;
143 rc = snprintf(page, count, "%d\n",
144 obd->u.filter.fo_capa_stat);
148 int lprocfs_filter_wr_capa_stat(struct file *file, const char *buffer,
149 unsigned long count, void *data)
151 struct obd_device *obd = data;
155 rc = lprocfs_write_helper(buffer, count, &val);
159 obd->u.filter.fo_capa_stat = val;
163 static struct lprocfs_vars lprocfs_obd_vars[] = {
164 { "uuid", lprocfs_rd_uuid, 0, 0 },
165 { "blocksize", lprocfs_rd_blksize, 0, 0 },
166 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
167 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
168 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
169 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
170 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
171 { "filegroups", lprocfs_filter_rd_groups, 0, 0 },
172 { "fstype", lprocfs_rd_fstype, 0, 0 },
173 { "mntdev", lprocfs_filter_rd_mntdev, 0, 0 },
174 { "last_id", lprocfs_filter_rd_last_id,0, 0 },
175 { "tot_dirty", lprocfs_filter_rd_tot_dirty, 0, 0 },
176 { "tot_pending", lprocfs_filter_rd_tot_pending, 0, 0 },
177 { "tot_granted", lprocfs_filter_rd_tot_granted, 0, 0 },
178 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
179 { "readcache_max_filesize",
180 lprocfs_filter_rd_readcache,
181 lprocfs_filter_wr_readcache, 0 },
182 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
183 { "capa", lprocfs_filter_rd_capa_stat,
184 lprocfs_filter_wr_capa_stat, 0 },
188 static struct lprocfs_vars lprocfs_module_vars[] = {
189 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
193 void filter_tally_write(struct filter_obd *filter, struct page **pages,
194 int nr_pages, unsigned long *blocks, int blocks_per_page)
196 struct page *last_page = NULL;
197 unsigned long *last_block = NULL;
198 unsigned long discont_pages = 0;
199 unsigned long discont_blocks = 0;
205 lprocfs_oh_tally_log2(&filter->fo_w_pages, nr_pages);
207 while (nr_pages-- > 0) {
208 if (last_page && (*pages)->index != (last_page->index + 1))
212 for (i = 0; i < blocks_per_page; i++) {
213 if (last_block && *blocks != (*last_block + 1))
215 last_block = blocks++;
219 lprocfs_oh_tally(&filter->fo_w_discont_pages, discont_pages);
220 lprocfs_oh_tally(&filter->fo_w_discont_blocks, discont_blocks);
223 void filter_tally_read(struct filter_obd *filter, struct niobuf_local *lnb,
226 struct niobuf_local *end;
227 struct page *last_page = NULL;
228 unsigned long discont_pages = 0;
229 unsigned long discont_blocks = 0;
234 for (end = lnb + niocount; lnb < end && lnb->page; lnb++) {
235 struct page *page = lnb->page;
237 if (page->index != (last_page->index + 1))
239 /* XXX not so smart for now */
240 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
241 if ((page->buffers && last_page->buffers) &&
242 (page->buffers->b_blocknr !=
243 (last_page->buffers->b_blocknr + 1)))
246 #warning "port on 2.6 -bzzz"
252 lprocfs_oh_tally_log2(&filter->fo_r_pages, niocount);
253 lprocfs_oh_tally(&filter->fo_r_discont_pages, discont_pages);
254 lprocfs_oh_tally(&filter->fo_r_discont_blocks, discont_blocks);
257 #define pct(a,b) (b ? a * 100 / b : 0)
259 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
262 struct obd_device *dev = seq->private;
263 struct filter_obd *filter = &dev->u.filter;
264 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
267 do_gettimeofday(&now);
269 /* this sampling races with updates */
271 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
272 now.tv_sec, now.tv_usec);
274 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
275 seq_printf(seq, "pages per brw brws %% cum %% |");
276 seq_printf(seq, " rpcs %% cum %%\n");
278 read_tot = lprocfs_oh_sum(&filter->fo_r_pages);
279 write_tot = lprocfs_oh_sum(&filter->fo_w_pages);
283 for (i = 0; i < OBD_HIST_MAX; i++) {
284 unsigned long r = filter->fo_r_pages.oh_buckets[i];
285 unsigned long w = filter->fo_w_pages.oh_buckets[i];
288 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
289 1 << i, r, pct(r, read_tot),
290 pct(read_cum, read_tot), w,
292 pct(write_cum, write_tot));
293 if (read_cum == read_tot && write_cum == write_tot)
297 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
298 seq_printf(seq, "discont pages rpcs %% cum %% |");
299 seq_printf(seq, " rpcs %% cum %%\n");
301 read_tot = lprocfs_oh_sum(&filter->fo_r_discont_pages);
302 write_tot = lprocfs_oh_sum(&filter->fo_w_discont_pages);
307 for (i = 0; i < OBD_HIST_MAX; i++) {
308 unsigned long r = filter->fo_r_discont_pages.oh_buckets[i];
309 unsigned long w = filter->fo_w_discont_pages.oh_buckets[i];
312 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
313 i, r, pct(r, read_tot),
314 pct(read_cum, read_tot), w,
316 pct(write_cum, write_tot));
317 if (read_cum == read_tot && write_cum == write_tot)
321 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
322 seq_printf(seq, "discont blocks rpcs %% cum %% |");
323 seq_printf(seq, " rpcs %% cum %%\n");
325 read_tot = lprocfs_oh_sum(&filter->fo_r_discont_blocks);
326 write_tot = lprocfs_oh_sum(&filter->fo_w_discont_blocks);
330 for (i = 0; i < OBD_HIST_MAX; i++) {
331 unsigned long r = filter->fo_r_discont_blocks.oh_buckets[i];
332 unsigned long w = filter->fo_w_discont_blocks.oh_buckets[i];
335 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
336 i, r, pct(r, read_tot),
337 pct(read_cum, read_tot), w,
339 pct(write_cum, write_tot));
340 if (read_cum == read_tot && write_cum == write_tot)
348 static void *filter_brw_stats_seq_start(struct seq_file *p, loff_t *pos)
354 static void *filter_brw_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
359 static void filter_brw_stats_seq_stop(struct seq_file *p, void *v)
362 struct seq_operations filter_brw_stats_seq_sops = {
363 .start = filter_brw_stats_seq_start,
364 .stop = filter_brw_stats_seq_stop,
365 .next = filter_brw_stats_seq_next,
366 .show = filter_brw_stats_seq_show,
369 static int filter_brw_stats_seq_open(struct inode *inode, struct file *file)
371 struct proc_dir_entry *dp = PDE(inode);
372 struct seq_file *seq;
375 rc = seq_open(file, &filter_brw_stats_seq_sops);
378 seq = file->private_data;
379 seq->private = dp->data;
383 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
384 size_t len, loff_t *off)
386 struct seq_file *seq = file->private_data;
387 struct obd_device *dev = seq->private;
388 struct filter_obd *filter = &dev->u.filter;
390 lprocfs_oh_clear(&filter->fo_r_pages);
391 lprocfs_oh_clear(&filter->fo_w_pages);
392 lprocfs_oh_clear(&filter->fo_r_discont_pages);
393 lprocfs_oh_clear(&filter->fo_w_discont_pages);
394 lprocfs_oh_clear(&filter->fo_r_discont_blocks);
395 lprocfs_oh_clear(&filter->fo_w_discont_blocks);
400 struct file_operations filter_brw_stats_fops = {
401 .owner = THIS_MODULE,
402 .open = filter_brw_stats_seq_open,
404 .write = filter_brw_stats_seq_write,
406 .release = seq_release,
409 int lproc_filter_attach_seqstat(struct obd_device *dev)
411 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
412 &filter_brw_stats_fops, dev);
418 LPROCFS_INIT_VARS(filter, lprocfs_module_vars, lprocfs_obd_vars)