4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osd/osd_lproc.c
38 * Author: Mikhail Pershin <tappro@sun.com>
41 #define DEBUG_SUBSYSTEM S_CLASS
43 #include <lprocfs_status.h>
46 #include <lustre/lustre_idl.h>
48 #include "osd_internal.h"
52 void osd_brw_stats_update(struct osd_device *osd, struct osd_iobuf *iobuf)
54 struct brw_stats *s = &osd->od_brw_stats;
55 unsigned long *last_block = NULL;
56 struct page **pages = iobuf->dr_pages;
57 struct page *last_page = NULL;
58 unsigned long discont_pages = 0;
59 unsigned long discont_blocks = 0;
60 unsigned long *blocks = iobuf->dr_blocks;
61 int i, nr_pages = iobuf->dr_npages;
63 int rw = iobuf->dr_rw;
65 if (unlikely(nr_pages == 0))
68 blocks_per_page = CFS_PAGE_SIZE >> osd_sb(osd)->s_blocksize_bits;
70 lprocfs_oh_tally_log2(&s->hist[BRW_R_PAGES+rw], nr_pages);
72 while (nr_pages-- > 0) {
73 if (last_page && (*pages)->index != (last_page->index + 1))
77 for (i = 0; i < blocks_per_page; i++) {
78 if (last_block && *blocks != (*last_block + 1))
80 last_block = blocks++;
84 lprocfs_oh_tally(&s->hist[BRW_R_DISCONT_PAGES+rw], discont_pages);
85 lprocfs_oh_tally(&s->hist[BRW_R_DISCONT_BLOCKS+rw], discont_blocks);
88 #define pct(a, b) (b ? a * 100 / b : 0)
90 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
91 struct obd_histogram *read, struct obd_histogram *write, int scale)
93 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
96 seq_printf(seq, "\n%26s read | write\n", " ");
97 seq_printf(seq, "%-22s %-5s %% cum %% | %-11s %% cum %%\n",
100 read_tot = lprocfs_oh_sum(read);
101 write_tot = lprocfs_oh_sum(write);
102 for (i = 0; i < OBD_HIST_MAX; i++) {
103 r = read->oh_buckets[i];
104 w = write->oh_buckets[i];
107 if (read_cum == 0 && write_cum == 0)
111 seq_printf(seq, "%u", i);
113 seq_printf(seq, "%u", scale << i);
115 seq_printf(seq, "%uK", scale << (i-10));
117 seq_printf(seq, "%uM", scale << (i-20));
119 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
120 r, pct(r, read_tot), pct(read_cum, read_tot),
121 w, pct(w, write_tot), pct(write_cum, write_tot));
123 if (read_cum == read_tot && write_cum == write_tot)
128 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
132 /* this sampling races with updates */
133 cfs_gettimeofday(&now);
134 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
135 now.tv_sec, now.tv_usec);
137 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
138 &brw_stats->hist[BRW_R_PAGES],
139 &brw_stats->hist[BRW_W_PAGES], 1);
141 display_brw_stats(seq, "discontiguous pages", "rpcs",
142 &brw_stats->hist[BRW_R_DISCONT_PAGES],
143 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
145 display_brw_stats(seq, "discontiguous blocks", "rpcs",
146 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
147 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
149 display_brw_stats(seq, "disk fragmented I/Os", "ios",
150 &brw_stats->hist[BRW_R_DIO_FRAGS],
151 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
153 display_brw_stats(seq, "disk I/Os in flight", "ios",
154 &brw_stats->hist[BRW_R_RPC_HIST],
155 &brw_stats->hist[BRW_W_RPC_HIST], 0);
157 display_brw_stats(seq, "I/O time (1/1000s)", "ios",
158 &brw_stats->hist[BRW_R_IO_TIME],
159 &brw_stats->hist[BRW_W_IO_TIME], 1000 / CFS_HZ);
161 display_brw_stats(seq, "disk I/O size", "ios",
162 &brw_stats->hist[BRW_R_DISK_IOSIZE],
163 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
168 static int osd_brw_stats_seq_show(struct seq_file *seq, void *v)
170 struct osd_device *osd = seq->private;
172 brw_stats_show(seq, &osd->od_brw_stats);
177 static ssize_t osd_brw_stats_seq_write(struct file *file, const char *buf,
178 size_t len, loff_t *off)
180 struct seq_file *seq = file->private_data;
181 struct osd_device *osd = seq->private;
184 for (i = 0; i < BRW_LAST; i++)
185 lprocfs_oh_clear(&osd->od_brw_stats.hist[i]);
190 LPROC_SEQ_FOPS(osd_brw_stats);
192 static int osd_stats_init(struct osd_device *osd)
197 for (i = 0; i < BRW_LAST; i++)
198 cfs_spin_lock_init(&osd->od_brw_stats.hist[i].oh_lock);
200 osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
201 if (osd->od_stats != NULL) {
202 result = lprocfs_register_stats(osd->od_proc_entry, "stats",
207 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
208 LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
210 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
211 LPROCFS_CNTR_AVGMINMAX,
212 "get_page_failures", "num");
213 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
214 LPROCFS_CNTR_AVGMINMAX,
215 "cache_access", "pages");
216 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
217 LPROCFS_CNTR_AVGMINMAX,
218 "cache_hit", "pages");
219 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
220 LPROCFS_CNTR_AVGMINMAX,
221 "cache_miss", "pages");
222 #if OSD_THANDLE_STATS
223 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
224 LPROCFS_CNTR_AVGMINMAX,
225 "thandle starting", "usec");
226 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
227 LPROCFS_CNTR_AVGMINMAX,
228 "thandle open", "usec");
229 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
230 LPROCFS_CNTR_AVGMINMAX,
231 "thandle closing", "usec");
233 lprocfs_seq_create(osd->od_proc_entry, "brw_stats",
234 0444, &osd_brw_stats_fops, osd);
242 static const char *osd_counter_names[] = {
243 #if OSD_THANDLE_STATS
244 [LPROC_OSD_THANDLE_STARTING] = "thandle starting",
245 [LPROC_OSD_THANDLE_OPEN] = "thandle open",
246 [LPROC_OSD_THANDLE_CLOSING] = "thandle closing"
250 int osd_procfs_init(struct osd_device *osd, const char *name)
252 struct lprocfs_static_vars lvars;
253 struct lu_device *ld = &osd->od_dt_dev.dd_lu_dev;
254 struct obd_type *type;
258 type = ld->ld_type->ldt_obd_type;
260 LASSERT(name != NULL);
261 LASSERT(type != NULL);
263 /* Find the type procroot and add the proc entry for this device */
264 lprocfs_osd_init_vars(&lvars);
265 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
266 lvars.obd_vars, &osd->od_dt_dev);
267 if (IS_ERR(osd->od_proc_entry)) {
268 rc = PTR_ERR(osd->od_proc_entry);
269 CERROR("Error %d setting up lprocfs for %s\n",
271 osd->od_proc_entry = NULL;
275 rc = lu_time_init(&osd->od_stats,
277 osd_counter_names, ARRAY_SIZE(osd_counter_names));
279 rc = osd_stats_init(osd);
284 osd_procfs_fini(osd);
288 int osd_procfs_fini(struct osd_device *osd)
291 lu_time_fini(&osd->od_stats);
293 if (osd->od_proc_entry) {
294 lprocfs_remove(&osd->od_proc_entry);
295 osd->od_proc_entry = NULL;
300 void osd_lprocfs_time_start(const struct lu_env *env)
302 lu_lprocfs_time_start(env);
305 void osd_lprocfs_time_end(const struct lu_env *env, struct osd_device *osd,
308 lu_lprocfs_time_end(env, osd->od_stats, idx);
313 static int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count,
314 int *eof, void *data)
316 struct obd_device *osd = data;
318 LASSERT(osd != NULL);
319 return snprintf(page, count, "ldiskfs\n");
322 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
323 int *eof, void *data)
325 struct osd_device *osd = osd_dt_dev(data);
327 LASSERT(osd != NULL);
328 if (unlikely(osd->od_mount == NULL))
331 LASSERT(osd->od_mount->lmi_mnt->mnt_devname);
334 return snprintf(page, count, "%s\n",
335 osd->od_mount->lmi_mnt->mnt_devname);
338 #ifdef HAVE_LDISKFS_PDO
339 static int lprocfs_osd_rd_pdo(char *page, char **start, off_t off, int count,
340 int *eof, void *data)
344 return snprintf(page, count, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
347 static int lprocfs_osd_wr_pdo(struct file *file, const char *buffer,
348 unsigned long count, void *data)
353 rc = lprocfs_write_helper(buffer, count, &pdo);
363 static int lprocfs_osd_rd_auto_scrub(char *page, char **start, off_t off,
364 int count, int *eof, void *data)
366 struct osd_device *dev = data;
368 LASSERT(dev != NULL);
369 if (unlikely(dev->od_mount == NULL))
373 return snprintf(page, count, "%d\n", !dev->od_scrub.os_no_scrub);
376 static int lprocfs_osd_wr_auto_scrub(struct file *file, const char *buffer,
377 unsigned long count, void *data)
379 struct osd_device *dev = data;
382 LASSERT(dev != NULL);
383 if (unlikely(dev->od_mount == NULL))
386 rc = lprocfs_write_helper(buffer, count, &val);
390 dev->od_scrub.os_no_scrub = !val;
394 static int lprocfs_osd_rd_oi_scrub(char *page, char **start, off_t off,
395 int count, int *eof, void *data)
397 struct osd_device *dev = data;
399 LASSERT(dev != NULL);
400 if (unlikely(dev->od_mount == NULL))
404 return osd_scrub_dump(dev, page, count);
407 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
408 { "blocksize", lprocfs_osd_rd_blksize, 0, 0 },
409 { "kbytestotal", lprocfs_osd_rd_kbytestotal, 0, 0 },
410 { "kbytesfree", lprocfs_osd_rd_kbytesfree, 0, 0 },
411 { "kbytesavail", lprocfs_osd_rd_kbytesavail, 0, 0 },
412 { "filestotal", lprocfs_osd_rd_filestotal, 0, 0 },
413 { "filesfree", lprocfs_osd_rd_filesfree, 0, 0 },
414 { "fstype", lprocfs_osd_rd_fstype, 0, 0 },
415 { "mntdev", lprocfs_osd_rd_mntdev, 0, 0 },
416 #ifdef HAVE_LDISKFS_PDO
417 { "pdo", lprocfs_osd_rd_pdo, lprocfs_osd_wr_pdo, 0 },
419 { "auto_scrub", lprocfs_osd_rd_auto_scrub,
420 lprocfs_osd_wr_auto_scrub, 0 },
421 { "oi_scrub", lprocfs_osd_rd_oi_scrub, 0, 0 },
425 struct lprocfs_vars lprocfs_osd_module_vars[] = {
426 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
430 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars)
432 lvars->module_vars = lprocfs_osd_module_vars;
433 lvars->obd_vars = lprocfs_osd_obd_vars;