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 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 #include <asm/statfs.h>
28 #include <linux/obd_class.h>
29 #include <linux/lprocfs_status.h>
30 #include <linux/seq_file.h>
31 #include "osc_internal.h"
34 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
35 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
38 static int osc_rd_max_pages_per_rpc(char *page, char **start, off_t off,
39 int count, int *eof, void *data)
41 struct obd_device *dev = data;
42 struct client_obd *cli = &dev->u.cli;
45 spin_lock(&cli->cl_loi_list_lock);
46 rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
47 spin_unlock(&cli->cl_loi_list_lock);
51 static int osc_wr_max_pages_per_rpc(struct file *file, const char *buffer,
52 unsigned long count, void *data)
54 struct obd_device *dev = data;
55 struct client_obd *cli = &dev->u.cli;
58 rc = lprocfs_write_helper(buffer, count, &val);
62 if (val < 1 || val > PTLRPC_MAX_BRW_PAGES)
65 spin_lock(&cli->cl_loi_list_lock);
66 cli->cl_max_pages_per_rpc = val;
67 spin_unlock(&cli->cl_loi_list_lock);
72 static int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
73 int count, int *eof, void *data)
75 struct obd_device *dev = data;
76 struct client_obd *cli = &dev->u.cli;
79 spin_lock(&cli->cl_loi_list_lock);
80 rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
81 spin_unlock(&cli->cl_loi_list_lock);
85 static int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
86 unsigned long count, void *data)
88 struct obd_device *dev = data;
89 struct client_obd *cli = &dev->u.cli;
92 rc = lprocfs_write_helper(buffer, count, &val);
96 if (val < 1 || val > OSC_MAX_RIF_MAX)
99 spin_lock(&cli->cl_loi_list_lock);
100 cli->cl_max_rpcs_in_flight = val;
101 spin_unlock(&cli->cl_loi_list_lock);
106 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
107 int *eof, void *data)
109 struct obd_device *dev = data;
110 struct client_obd *cli = &dev->u.cli;
113 spin_lock(&cli->cl_loi_list_lock);
114 val = cli->cl_dirty_max >> 20;
115 spin_unlock(&cli->cl_loi_list_lock);
117 return snprintf(page, count, "%u\n", val);
120 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
121 unsigned long count, void *data)
123 struct obd_device *dev = data;
124 struct client_obd *cli = &dev->u.cli;
127 rc = lprocfs_write_helper(buffer, count, &val);
131 if (val < 0 || val > OSC_MAX_DIRTY_MB_MAX || val > num_physpages / 4)
134 spin_lock(&cli->cl_loi_list_lock);
135 cli->cl_dirty_max = (obd_count)val * 1024 * 1024;
136 osc_wake_cache_waiters(cli);
137 spin_unlock(&cli->cl_loi_list_lock);
142 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
143 int count, int *eof, void *data)
145 struct obd_device *dev = data;
146 struct client_obd *cli = &dev->u.cli;
149 spin_lock(&cli->cl_loi_list_lock);
150 rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
151 spin_unlock(&cli->cl_loi_list_lock);
155 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
156 int count, int *eof, void *data)
158 struct obd_device *dev = data;
159 struct client_obd *cli = &dev->u.cli;
162 spin_lock(&cli->cl_loi_list_lock);
163 rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
164 spin_unlock(&cli->cl_loi_list_lock);
168 static int osc_rd_create_count(char *page, char **start, off_t off, int count,
169 int *eof, void *data)
171 struct obd_device *obd = data;
176 return snprintf(page, count, "%d\n",
177 obd->u.cli.cl_oscc.oscc_grow_count);
180 static int osc_wr_create_count(struct file *file, const char *buffer,
181 unsigned long count, void *data)
183 struct obd_device *obd = data;
189 rc = lprocfs_write_helper(buffer, count, &val);
195 if (val > OST_MAX_PRECREATE)
198 obd->u.cli.cl_oscc.oscc_grow_count = val;
203 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
204 int count, int *eof, void *data)
206 struct obd_device *obd = data;
211 return snprintf(page, count, LPU64"\n",
212 obd->u.cli.cl_oscc.oscc_next_id);
215 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
216 int count, int *eof, void *data)
218 struct obd_device *obd = data;
223 return snprintf(page, count, LPU64"\n",
224 obd->u.cli.cl_oscc.oscc_last_id);
227 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
228 int *eof, void *data)
230 struct obd_device *obd = data;
235 return snprintf(page, count, "%d\n",
236 obd->u.cli.cl_checksum ? 1 : 0);
239 static int osc_wr_checksum(struct file *file, const char *buffer,
240 unsigned long count, void *data)
242 struct obd_device *obd = data;
248 rc = lprocfs_write_helper(buffer, count, &val);
252 obd->u.cli.cl_checksum = (val ? 1 : 0);
257 static struct lprocfs_vars lprocfs_obd_vars[] = {
258 { "uuid", lprocfs_rd_uuid, 0, 0 },
259 { "ping", 0, lprocfs_wr_ping, 0 },
260 { "blocksize", lprocfs_rd_blksize, 0, 0 },
261 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
262 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
263 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
264 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
265 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
266 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
267 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
268 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
269 { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
270 osc_wr_max_pages_per_rpc, 0 },
271 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
272 osc_wr_max_rpcs_in_flight, 0 },
273 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
274 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
275 { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
276 { "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
277 { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
278 { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
279 { "checksums", osc_rd_checksum, osc_wr_checksum, 0 },
283 static struct lprocfs_vars lprocfs_module_vars[] = {
284 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
288 #define pct(a,b) (b ? a * 100 / b : 0)
290 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
293 struct obd_device *dev = seq->private;
294 struct client_obd *cli = &dev->u.cli;
296 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
299 do_gettimeofday(&now);
301 spin_lock_irqsave(&cli->cl_loi_list_lock, flags);
303 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
304 now.tv_sec, now.tv_usec);
305 seq_printf(seq, "read RPCs in flight: %d\n",
306 cli->cl_r_in_flight);
307 seq_printf(seq, "write RPCs in flight: %d\n",
308 cli->cl_w_in_flight);
309 seq_printf(seq, "pending write pages: %d\n",
310 cli->cl_pending_w_pages);
311 seq_printf(seq, "pending read pages: %d\n",
312 cli->cl_pending_r_pages);
314 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
315 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
316 seq_printf(seq, " rpcs %% cum %%\n");
318 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
319 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
323 for (i = 0; i < OBD_HIST_MAX; i++) {
324 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
325 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
328 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
329 1 << i, r, pct(r, read_tot),
330 pct(read_cum, read_tot), w,
332 pct(write_cum, write_tot));
333 if (read_cum == read_tot && write_cum == write_tot)
337 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
338 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
339 seq_printf(seq, " rpcs %% cum %%\n");
341 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
342 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
346 for (i = 0; i < OBD_HIST_MAX; i++) {
347 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
348 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
351 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
352 i, r, pct(r, read_tot),
353 pct(read_cum, read_tot), w,
355 pct(write_cum, write_tot));
356 if (read_cum == read_tot && write_cum == write_tot)
360 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
361 seq_printf(seq, "offset rpcs %% cum %% |");
362 seq_printf(seq, " rpcs %% cum %%\n");
364 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
365 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
369 for (i = 0; i < OBD_HIST_MAX; i++) {
370 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
371 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
374 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
375 (i == 0) ? 0 : 1 << (i - 1),
376 r, pct(r, read_tot), pct(read_cum, read_tot),
377 w, pct(w, write_tot), pct(write_cum, write_tot));
378 if (read_cum == read_tot && write_cum == write_tot)
382 spin_unlock_irqrestore(&cli->cl_loi_list_lock, flags);
388 static void *osc_rpc_stats_seq_start(struct seq_file *p, loff_t *pos)
394 static void *osc_rpc_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
399 static void osc_rpc_stats_seq_stop(struct seq_file *p, void *v)
402 struct seq_operations osc_rpc_stats_seq_sops = {
403 .start = osc_rpc_stats_seq_start,
404 .stop = osc_rpc_stats_seq_stop,
405 .next = osc_rpc_stats_seq_next,
406 .show = osc_rpc_stats_seq_show,
409 static int osc_rpc_stats_seq_open(struct inode *inode, struct file *file)
411 struct proc_dir_entry *dp = PDE(inode);
412 struct seq_file *seq;
415 rc = seq_open(file, &osc_rpc_stats_seq_sops);
418 seq = file->private_data;
419 seq->private = dp->data;
423 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
424 size_t len, loff_t *off)
426 struct seq_file *seq = file->private_data;
427 struct obd_device *dev = seq->private;
428 struct client_obd *cli = &dev->u.cli;
430 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
431 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
432 lprocfs_oh_clear(&cli->cl_read_page_hist);
433 lprocfs_oh_clear(&cli->cl_write_page_hist);
434 lprocfs_oh_clear(&cli->cl_read_offset_hist);
435 lprocfs_oh_clear(&cli->cl_write_offset_hist);
440 struct file_operations osc_rpc_stats_fops = {
441 .owner = THIS_MODULE,
442 .open = osc_rpc_stats_seq_open,
444 .write = osc_rpc_stats_seq_write,
446 .release = seq_release,
449 int lproc_osc_attach_seqstat(struct obd_device *dev)
451 return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
452 &osc_rpc_stats_fops, dev);
456 LPROCFS_INIT_VARS(osc, lprocfs_module_vars, lprocfs_obd_vars)