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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/osd/osd_lproc.c
40 * Author: Mikhail Pershin <tappro@sun.com>
43 #define DEBUG_SUBSYSTEM S_CLASS
45 #include <lprocfs_status.h>
48 #include <lustre/lustre_idl.h>
50 #include "osd_internal.h"
54 void osd_brw_stats_update(struct osd_device *osd, struct osd_iobuf *iobuf)
56 struct brw_stats *s = &osd->od_brw_stats;
57 unsigned long *last_block = NULL;
58 struct page **pages = iobuf->dr_pages;
59 struct page *last_page = NULL;
60 unsigned long discont_pages = 0;
61 unsigned long discont_blocks = 0;
62 unsigned long *blocks = iobuf->dr_blocks;
63 int i, nr_pages = iobuf->dr_npages;
65 int rw = iobuf->dr_rw;
67 if (unlikely(nr_pages == 0))
70 blocks_per_page = CFS_PAGE_SIZE >> osd_sb(osd)->s_blocksize_bits;
72 lprocfs_oh_tally_log2(&s->hist[BRW_R_PAGES+rw], nr_pages);
74 while (nr_pages-- > 0) {
75 if (last_page && (*pages)->index != (last_page->index + 1))
79 for (i = 0; i < blocks_per_page; i++) {
80 if (last_block && *blocks != (*last_block + 1))
82 last_block = blocks++;
86 lprocfs_oh_tally(&s->hist[BRW_R_DISCONT_PAGES+rw], discont_pages);
87 lprocfs_oh_tally(&s->hist[BRW_R_DISCONT_BLOCKS+rw], discont_blocks);
90 #define pct(a, b) (b ? a * 100 / b : 0)
92 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
93 struct obd_histogram *read, struct obd_histogram *write, int scale)
95 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
98 seq_printf(seq, "\n%26s read | write\n", " ");
99 seq_printf(seq, "%-22s %-5s %% cum %% | %-11s %% cum %%\n",
102 read_tot = lprocfs_oh_sum(read);
103 write_tot = lprocfs_oh_sum(write);
104 for (i = 0; i < OBD_HIST_MAX; i++) {
105 r = read->oh_buckets[i];
106 w = write->oh_buckets[i];
109 if (read_cum == 0 && write_cum == 0)
113 seq_printf(seq, "%u", i);
115 seq_printf(seq, "%u", scale << i);
117 seq_printf(seq, "%uK", scale << (i-10));
119 seq_printf(seq, "%uM", scale << (i-20));
121 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
122 r, pct(r, read_tot), pct(read_cum, read_tot),
123 w, pct(w, write_tot), pct(write_cum, write_tot));
125 if (read_cum == read_tot && write_cum == write_tot)
130 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
134 /* this sampling races with updates */
135 cfs_gettimeofday(&now);
136 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
137 now.tv_sec, now.tv_usec);
139 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
140 &brw_stats->hist[BRW_R_PAGES],
141 &brw_stats->hist[BRW_W_PAGES], 1);
143 display_brw_stats(seq, "discontiguous pages", "rpcs",
144 &brw_stats->hist[BRW_R_DISCONT_PAGES],
145 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
147 display_brw_stats(seq, "discontiguous blocks", "rpcs",
148 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
149 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
151 display_brw_stats(seq, "disk fragmented I/Os", "ios",
152 &brw_stats->hist[BRW_R_DIO_FRAGS],
153 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
155 display_brw_stats(seq, "disk I/Os in flight", "ios",
156 &brw_stats->hist[BRW_R_RPC_HIST],
157 &brw_stats->hist[BRW_W_RPC_HIST], 0);
159 display_brw_stats(seq, "I/O time (1/1000s)", "ios",
160 &brw_stats->hist[BRW_R_IO_TIME],
161 &brw_stats->hist[BRW_W_IO_TIME], 1000 / CFS_HZ);
163 display_brw_stats(seq, "disk I/O size", "ios",
164 &brw_stats->hist[BRW_R_DISK_IOSIZE],
165 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
170 static int osd_brw_stats_seq_show(struct seq_file *seq, void *v)
172 struct osd_device *osd = seq->private;
174 brw_stats_show(seq, &osd->od_brw_stats);
179 static ssize_t osd_brw_stats_seq_write(struct file *file, const char *buf,
180 size_t len, loff_t *off)
182 struct seq_file *seq = file->private_data;
183 struct osd_device *osd = seq->private;
186 for (i = 0; i < BRW_LAST; i++)
187 lprocfs_oh_clear(&osd->od_brw_stats.hist[i]);
192 LPROC_SEQ_FOPS(osd_brw_stats);
194 static int osd_stats_init(struct osd_device *osd)
199 for (i = 0; i < BRW_LAST; i++)
200 cfs_spin_lock_init(&osd->od_brw_stats.hist[i].oh_lock);
202 osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
203 if (osd->od_stats != NULL) {
204 result = lprocfs_register_stats(osd->od_proc_entry, "stats",
209 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
210 LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
212 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
213 LPROCFS_CNTR_AVGMINMAX,
214 "get_page_failures", "num");
215 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
216 LPROCFS_CNTR_AVGMINMAX,
217 "cache_access", "pages");
218 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
219 LPROCFS_CNTR_AVGMINMAX,
220 "cache_hit", "pages");
221 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
222 LPROCFS_CNTR_AVGMINMAX,
223 "cache_miss", "pages");
224 #if OSD_THANDLE_STATS
225 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
226 LPROCFS_CNTR_AVGMINMAX,
227 "thandle starting", "usec");
228 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
229 LPROCFS_CNTR_AVGMINMAX,
230 "thandle open", "usec");
231 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
232 LPROCFS_CNTR_AVGMINMAX,
233 "thandle closing", "usec");
235 lprocfs_seq_create(osd->od_proc_entry, "brw_stats",
236 0444, &osd_brw_stats_fops, osd);
244 static const char *osd_counter_names[] = {
245 #if OSD_THANDLE_STATS
246 [LPROC_OSD_THANDLE_STARTING] = "thandle starting",
247 [LPROC_OSD_THANDLE_OPEN] = "thandle open",
248 [LPROC_OSD_THANDLE_CLOSING] = "thandle closing"
252 int osd_procfs_init(struct osd_device *osd, const char *name)
254 struct lprocfs_static_vars lvars;
255 struct lu_device *ld = &osd->od_dt_dev.dd_lu_dev;
256 struct obd_type *type;
260 type = ld->ld_type->ldt_obd_type;
262 LASSERT(name != NULL);
263 LASSERT(type != NULL);
265 /* Find the type procroot and add the proc entry for this device */
266 lprocfs_osd_init_vars(&lvars);
267 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
268 lvars.obd_vars, osd);
269 if (IS_ERR(osd->od_proc_entry)) {
270 rc = PTR_ERR(osd->od_proc_entry);
271 CERROR("Error %d setting up lprocfs for %s\n",
273 osd->od_proc_entry = NULL;
277 rc = lu_time_init(&osd->od_stats,
279 osd_counter_names, ARRAY_SIZE(osd_counter_names));
281 rc = osd_stats_init(osd);
286 osd_procfs_fini(osd);
290 int osd_procfs_fini(struct osd_device *osd)
293 lu_time_fini(&osd->od_stats);
295 if (osd->od_proc_entry) {
296 lprocfs_remove(&osd->od_proc_entry);
297 osd->od_proc_entry = NULL;
302 void osd_lprocfs_time_start(const struct lu_env *env)
304 lu_lprocfs_time_start(env);
307 void osd_lprocfs_time_end(const struct lu_env *env, struct osd_device *osd,
310 lu_lprocfs_time_end(env, osd->od_stats, idx);
315 int lprocfs_osd_rd_blksize(char *page, char **start, off_t off, int count,
316 int *eof, void *data)
318 struct osd_device *osd = data;
321 if (unlikely(osd->od_mount == NULL))
324 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
327 rc = snprintf(page, count, "%ld\n", osd->od_kstatfs.f_bsize);
332 int lprocfs_osd_rd_kbytestotal(char *page, char **start, off_t off, int count,
333 int *eof, void *data)
335 struct osd_device *osd = data;
338 if (unlikely(osd->od_mount == NULL))
341 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
343 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
344 __u64 result = osd->od_kstatfs.f_blocks;
346 while (blk_size >>= 1)
350 rc = snprintf(page, count, LPU64"\n", result);
355 int lprocfs_osd_rd_kbytesfree(char *page, char **start, off_t off, int count,
356 int *eof, void *data)
358 struct osd_device *osd = data;
361 if (unlikely(osd->od_mount == NULL))
364 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
366 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
367 __u64 result = osd->od_kstatfs.f_bfree;
369 while (blk_size >>= 1)
373 rc = snprintf(page, count, LPU64"\n", result);
378 int lprocfs_osd_rd_kbytesavail(char *page, char **start, off_t off, int count,
379 int *eof, void *data)
381 struct osd_device *osd = data;
384 if (unlikely(osd->od_mount == NULL))
387 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
389 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
390 __u64 result = osd->od_kstatfs.f_bavail;
392 while (blk_size >>= 1)
396 rc = snprintf(page, count, LPU64"\n", result);
401 int lprocfs_osd_rd_filestotal(char *page, char **start, off_t off, int count,
402 int *eof, void *data)
404 struct osd_device *osd = data;
407 if (unlikely(osd->od_mount == NULL))
410 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
413 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_files);
419 int lprocfs_osd_rd_filesfree(char *page, char **start, off_t off, int count,
420 int *eof, void *data)
422 struct osd_device *osd = data;
425 if (unlikely(osd->od_mount == NULL))
428 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
431 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_ffree);
436 int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count,
437 int *eof, void *data)
439 struct obd_device *osd = data;
441 LASSERT(osd != NULL);
442 return snprintf(page, count, "ldiskfs\n");
445 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
446 int *eof, void *data)
448 struct osd_device *osd = data;
450 LASSERT(osd != NULL);
451 if (unlikely(osd->od_mount == NULL))
454 LASSERT(osd->od_mount->lmi_mnt->mnt_devname);
457 return snprintf(page, count, "%s\n",
458 osd->od_mount->lmi_mnt->mnt_devname);
461 #ifdef HAVE_LDISKFS_PDO
462 static int lprocfs_osd_rd_pdo(char *page, char **start, off_t off, int count,
463 int *eof, void *data)
467 return snprintf(page, count, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
470 static int lprocfs_osd_wr_pdo(struct file *file, const char *buffer,
471 unsigned long count, void *data)
476 rc = lprocfs_write_helper(buffer, count, &pdo);
486 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
487 { "blocksize", lprocfs_osd_rd_blksize, 0, 0 },
488 { "kbytestotal", lprocfs_osd_rd_kbytestotal, 0, 0 },
489 { "kbytesfree", lprocfs_osd_rd_kbytesfree, 0, 0 },
490 { "kbytesavail", lprocfs_osd_rd_kbytesavail, 0, 0 },
491 { "filestotal", lprocfs_osd_rd_filestotal, 0, 0 },
492 { "filesfree", lprocfs_osd_rd_filesfree, 0, 0 },
493 { "fstype", lprocfs_osd_rd_fstype, 0, 0 },
494 { "mntdev", lprocfs_osd_rd_mntdev, 0, 0 },
495 #ifdef HAVE_LDISKFS_PDO
496 { "pdo", lprocfs_osd_rd_pdo, lprocfs_osd_wr_pdo, 0 },
501 struct lprocfs_vars lprocfs_osd_module_vars[] = {
502 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
506 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars)
508 lvars->module_vars = lprocfs_osd_module_vars;
509 lvars->obd_vars = lprocfs_osd_obd_vars;