Whamcloud - gitweb
- landed b_hd_cray_merge3
[fs/lustre-release.git] / lustre / osc / lproc_osc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  *
21  */
22 #define DEBUG_SUBSYSTEM S_CLASS
23
24 #include <linux/version.h>
25 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 #include <asm/statfs.h>
27 #endif
28 #include <linux/obd_class.h>
29 #include <linux/lprocfs_status.h>
30 #include <linux/seq_file.h>
31 #include "osc_internal.h"
32
33 #ifndef LPROCFS
34 static struct lprocfs_vars lprocfs_obd_vars[]  = { {0} };
35 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
36 #else
37
38 int osc_rd_max_pages_per_rpc(char *page, char **start, off_t off, int count,
39                              int *eof, void *data)
40 {
41         struct obd_device *dev = data;
42         struct client_obd *cli = &dev->u.cli;
43         int rc;
44
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);
48         return rc;
49 }
50
51 int osc_wr_max_pages_per_rpc(struct file *file, const char *buffer,
52                              unsigned long count, void *data)
53 {
54         struct obd_device *dev = data;
55         struct client_obd *cli = &dev->u.cli;
56         int val, rc;
57
58         rc = lprocfs_write_helper(buffer, count, &val);
59         if (rc)
60                 return rc;
61
62         if (val < 1 || val > PTLRPC_MAX_BRW_PAGES)
63                 return -ERANGE;
64
65         spin_lock(&cli->cl_loi_list_lock);
66         cli->cl_max_pages_per_rpc = val;
67         spin_unlock(&cli->cl_loi_list_lock);
68
69         return count;
70 }
71
72 int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off, int count,
73                               int *eof, void *data)
74 {
75         struct obd_device *dev = data;
76         struct client_obd *cli = &dev->u.cli;
77         int rc;
78
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);
82         return rc;
83 }
84
85 int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
86                               unsigned long count, void *data)
87 {
88         struct obd_device *dev = data;
89         struct client_obd *cli = &dev->u.cli;
90         int val, rc;
91
92         rc = lprocfs_write_helper(buffer, count, &val);
93         if (rc)
94                 return rc;
95
96         if (val < 1 || val > OSC_MAX_RIF_MAX)
97                 return -ERANGE;
98
99         spin_lock(&cli->cl_loi_list_lock);
100         cli->cl_max_rpcs_in_flight = val;
101         spin_unlock(&cli->cl_loi_list_lock);
102
103         return count;
104 }
105
106 int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
107                         int *eof, void *data)
108 {
109         struct obd_device *dev = data;
110         struct client_obd *cli = &dev->u.cli;
111         unsigned val;
112
113         spin_lock(&cli->cl_loi_list_lock);
114         val = cli->cl_dirty_max >> 20;
115         spin_unlock(&cli->cl_loi_list_lock);
116
117         return snprintf(page, count, "%u\n", val);
118 }
119
120 int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
121                         unsigned long count, void *data)
122 {
123         struct obd_device *dev = data;
124         struct client_obd *cli = &dev->u.cli;
125         int val, rc;
126
127         rc = lprocfs_write_helper(buffer, count, &val);
128         if (rc)
129                 return rc;
130
131         if (val < 0 || val > OSC_MAX_DIRTY_MB_MAX ||
132             val > num_physpages >> (20 - PAGE_SHIFT - 2)) /* 1/4 of RAM */
133                 return -ERANGE;
134
135         spin_lock(&cli->cl_loi_list_lock);
136         cli->cl_dirty_max = (obd_count)val * 1024 * 1024;
137         osc_wake_cache_waiters(cli);
138         spin_unlock(&cli->cl_loi_list_lock);
139
140         return count;
141 }
142
143 int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off, int count,
144                            int *eof, void *data)
145 {
146         struct obd_device *dev = data;
147         struct client_obd *cli = &dev->u.cli;
148         int rc;
149
150         spin_lock(&cli->cl_loi_list_lock);
151         rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
152         spin_unlock(&cli->cl_loi_list_lock);
153         return rc;
154 }
155
156 int osc_rd_cur_grant_bytes(char *page, char **start, off_t off, int count,
157                            int *eof, void *data)
158 {
159         struct obd_device *dev = data;
160         struct client_obd *cli = &dev->u.cli;
161         int rc;
162
163         spin_lock(&cli->cl_loi_list_lock);
164         rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
165         spin_unlock(&cli->cl_loi_list_lock);
166         return rc;
167 }
168
169 int osc_rd_create_count(char *page, char **start, off_t off, int count,
170                         int *eof, void *data)
171 {
172         struct obd_device *obd = data;
173
174         if (obd == NULL)
175                 return 0;
176
177         return snprintf(page, count, "%d\n",
178                         obd->u.cli.cl_oscc.oscc_grow_count);
179 }
180
181 int osc_wr_create_count(struct file *file, const char *buffer,
182                         unsigned long count, void *data)
183 {
184         struct obd_device *obd = data;
185         int val, rc;
186
187         if (obd == NULL)
188                 return 0;
189
190         rc = lprocfs_write_helper(buffer, count, &val);
191         if (rc)
192                 return rc;
193
194         if (val < 0)
195                 return -ERANGE;
196
197         obd->u.cli.cl_oscc.oscc_grow_count = val;
198
199         return count;
200 }
201
202 int osc_rd_prealloc_next_id(char *page, char **start, off_t off, int count,
203                             int *eof, void *data)
204 {
205         struct obd_device *obd = data;
206
207         if (obd == NULL)
208                 return 0;
209
210         return snprintf(page, count, LPU64"\n",
211                         obd->u.cli.cl_oscc.oscc_next_id);
212 }
213
214 int osc_rd_prealloc_last_id(char *page, char **start, off_t off, int count,
215                             int *eof, void *data)
216 {
217         struct obd_device *obd = data;
218
219         if (obd == NULL)
220                 return 0;
221
222         return snprintf(page, count, LPU64"\n",
223                         obd->u.cli.cl_oscc.oscc_last_id);
224 }
225
226 static struct lprocfs_vars lprocfs_obd_vars[] = {
227         { "uuid",            lprocfs_rd_uuid,        0, 0 },
228         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
229         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
230         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
231         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
232         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
233         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
234         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
235         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
236         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
237         { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
238                                osc_wr_max_pages_per_rpc, 0 },
239         { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
240                                 osc_wr_max_rpcs_in_flight, 0 },
241         { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
242         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
243         { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
244         { "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
245         { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
246         { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
247         { 0 }
248 };
249
250 static struct lprocfs_vars lprocfs_module_vars[] = {
251         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
252         { 0 }
253 };
254
255 #define pct(a,b) (b ? a * 100 / b : 0)
256
257 #define PRINTF_STIME(stime) (unsigned long)(stime)->st_num,     \
258         lprocfs_stime_avg_ms(stime), lprocfs_stime_avg_us(stime)
259
260
261 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
262 {
263         struct timeval now;
264         struct obd_device *dev = seq->private;
265         struct client_obd *cli = &dev->u.cli;
266         unsigned long flags;
267         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
268         int i;
269
270         do_gettimeofday(&now);
271
272         spin_lock_irqsave(&cli->cl_loi_list_lock, flags);
273
274         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
275                    now.tv_sec, now.tv_usec);
276
277         seq_printf(seq, "read RPCs in flight:  %d\n",
278                    cli->cl_r_in_flight);
279         seq_printf(seq, "write RPCs in flight: %d\n",
280                    cli->cl_w_in_flight);
281         seq_printf(seq, "pending write pages:  %d\n",
282                    cli->cl_pending_w_pages);
283         seq_printf(seq, "pending read pages:   %d\n",
284                    cli->cl_pending_r_pages);
285
286
287         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
288         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
289         seq_printf(seq, "       rpcs   %% cum %%\n");
290
291         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
292         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
293
294         read_cum = 0;
295         write_cum = 0;
296         for (i = 0; i < OBD_HIST_MAX; i++) {
297                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
298                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
299                 read_cum += r;
300                 write_cum += w;
301                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
302                                  1 << i, r, pct(r, read_tot),
303                                  pct(read_cum, read_tot), w,
304                                  pct(w, write_tot),
305                                  pct(write_cum, write_tot));
306                 if (read_cum == read_tot && write_cum == write_tot)
307                         break;
308         }
309
310         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
311         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
312         seq_printf(seq, "       rpcs   %% cum %%\n");
313
314         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
315         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
316
317         read_cum = 0;
318         write_cum = 0;
319         for (i = 0; i < OBD_HIST_MAX; i++) {
320                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
321                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
322                 read_cum += r;
323                 write_cum += w;
324                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
325                                  i, r, pct(r, read_tot),
326                                  pct(read_cum, read_tot), w,
327                                  pct(w, write_tot),
328                                  pct(write_cum, write_tot));
329                 if (read_cum == read_tot && write_cum == write_tot)
330                         break;
331         }
332
333         seq_printf(seq, "\nrpc service time: (rpcs, average ms)\n");
334         seq_printf(seq, "\tread\t%lu\t%lu.%04lu\n",
335                         PRINTF_STIME(&cli->cl_read_stime));
336         seq_printf(seq, "\twrite\t%lu\t%lu.%04lu\n\n",
337                         PRINTF_STIME(&cli->cl_write_stime));
338
339         seq_printf(seq, "app waiting: (num, average ms)\n");
340         seq_printf(seq, "\tenter cache\t%lu\t%lu.%04lu\n",
341                         PRINTF_STIME(&cli->cl_enter_stime));
342
343         spin_unlock_irqrestore(&cli->cl_loi_list_lock, flags);
344
345         return 0;
346 }
347 #undef pct
348
349 static void *osc_rpc_stats_seq_start(struct seq_file *p, loff_t *pos)
350 {
351         if (*pos == 0)
352                 return (void *)1;
353         return NULL;
354 }
355 static void *osc_rpc_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
356 {
357         ++*pos;
358         return NULL;
359 }
360 static void osc_rpc_stats_seq_stop(struct seq_file *p, void *v)
361 {
362 }
363 struct seq_operations osc_rpc_stats_seq_sops = {
364         .start = osc_rpc_stats_seq_start,
365         .stop = osc_rpc_stats_seq_stop,
366         .next = osc_rpc_stats_seq_next,
367         .show = osc_rpc_stats_seq_show,
368 };
369
370 static int osc_rpc_stats_seq_open(struct inode *inode, struct file *file)
371 {
372         struct proc_dir_entry *dp = PDE(inode);
373         struct seq_file *seq;
374         int rc;
375
376         rc = seq_open(file, &osc_rpc_stats_seq_sops);
377         if (rc)
378                 return rc;
379         seq = file->private_data;
380         seq->private = dp->data;
381         return 0;
382 }
383
384 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
385                                        size_t len, loff_t *off)
386 {
387         struct seq_file *seq = file->private_data;
388         struct obd_device *dev = seq->private;
389         struct client_obd *cli = &dev->u.cli;
390
391         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
392         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
393         lprocfs_oh_clear(&cli->cl_read_page_hist);
394         lprocfs_oh_clear(&cli->cl_write_page_hist);
395
396         memset(&cli->cl_read_stime, 0, sizeof(cli->cl_read_stime));
397         memset(&cli->cl_write_stime, 0, sizeof(cli->cl_write_stime));
398         memset(&cli->cl_enter_stime, 0, sizeof(cli->cl_enter_stime));
399
400         return len;
401 }
402
403 struct file_operations osc_rpc_stats_fops = {
404         .owner   = THIS_MODULE,
405         .open    = osc_rpc_stats_seq_open,
406         .read    = seq_read,
407         .write   = osc_rpc_stats_seq_write,
408         .llseek  = seq_lseek,
409         .release = seq_release,
410 };
411
412 int lproc_osc_attach_seqstat(struct obd_device *dev)
413 {
414         return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
415                                       &osc_rpc_stats_fops, dev);
416 }
417
418 #endif /* LPROCFS */
419 LPROCFS_INIT_VARS(osc, lprocfs_module_vars, lprocfs_obd_vars)