[SERIAL] typo: buad -> baud
[linux-2.6/cjktty.git] / net / sunrpc / stats.c
blob15c2db26767bc5e5b6848d904078c9b0975dcfa4
1 /*
2 * linux/net/sunrpc/stats.c
4 * procfs-based user access to generic RPC statistics. The stats files
5 * reside in /proc/net/rpc.
7 * The read routines assume that the buffer passed in is just big enough.
8 * If you implement an RPC service that has its own stats routine which
9 * appends the generic RPC stats, make sure you don't exceed the PAGE_SIZE
10 * limit.
12 * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
15 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/proc_fs.h>
21 #include <linux/seq_file.h>
22 #include <linux/sunrpc/clnt.h>
23 #include <linux/sunrpc/svcsock.h>
24 #include <linux/sunrpc/metrics.h>
26 #define RPCDBG_FACILITY RPCDBG_MISC
28 struct proc_dir_entry *proc_net_rpc = NULL;
31 * Get RPC client stats
33 static int rpc_proc_show(struct seq_file *seq, void *v) {
34 const struct rpc_stat *statp = seq->private;
35 const struct rpc_program *prog = statp->program;
36 int i, j;
38 seq_printf(seq,
39 "net %u %u %u %u\n",
40 statp->netcnt,
41 statp->netudpcnt,
42 statp->nettcpcnt,
43 statp->nettcpconn);
44 seq_printf(seq,
45 "rpc %u %u %u\n",
46 statp->rpccnt,
47 statp->rpcretrans,
48 statp->rpcauthrefresh);
50 for (i = 0; i < prog->nrvers; i++) {
51 const struct rpc_version *vers = prog->version[i];
52 if (!vers)
53 continue;
54 seq_printf(seq, "proc%u %u",
55 vers->number, vers->nrprocs);
56 for (j = 0; j < vers->nrprocs; j++)
57 seq_printf(seq, " %u",
58 vers->procs[j].p_count);
59 seq_putc(seq, '\n');
61 return 0;
64 static int rpc_proc_open(struct inode *inode, struct file *file)
66 return single_open(file, rpc_proc_show, PDE(inode)->data);
69 static struct file_operations rpc_proc_fops = {
70 .owner = THIS_MODULE,
71 .open = rpc_proc_open,
72 .read = seq_read,
73 .llseek = seq_lseek,
74 .release = single_release,
78 * Get RPC server stats
80 void svc_seq_show(struct seq_file *seq, const struct svc_stat *statp) {
81 const struct svc_program *prog = statp->program;
82 const struct svc_procedure *proc;
83 const struct svc_version *vers;
84 int i, j;
86 seq_printf(seq,
87 "net %u %u %u %u\n",
88 statp->netcnt,
89 statp->netudpcnt,
90 statp->nettcpcnt,
91 statp->nettcpconn);
92 seq_printf(seq,
93 "rpc %u %u %u %u %u\n",
94 statp->rpccnt,
95 statp->rpcbadfmt+statp->rpcbadauth+statp->rpcbadclnt,
96 statp->rpcbadfmt,
97 statp->rpcbadauth,
98 statp->rpcbadclnt);
100 for (i = 0; i < prog->pg_nvers; i++) {
101 if (!(vers = prog->pg_vers[i]) || !(proc = vers->vs_proc))
102 continue;
103 seq_printf(seq, "proc%d %u", i, vers->vs_nproc);
104 for (j = 0; j < vers->vs_nproc; j++, proc++)
105 seq_printf(seq, " %u", proc->pc_count);
106 seq_putc(seq, '\n');
111 * rpc_alloc_iostats - allocate an rpc_iostats structure
112 * @clnt: RPC program, version, and xprt
115 struct rpc_iostats *rpc_alloc_iostats(struct rpc_clnt *clnt)
117 unsigned int ops = clnt->cl_maxproc;
118 size_t size = ops * sizeof(struct rpc_iostats);
119 struct rpc_iostats *new;
121 new = kmalloc(size, GFP_KERNEL);
122 if (new)
123 memset(new, 0 , size);
124 return new;
126 EXPORT_SYMBOL(rpc_alloc_iostats);
129 * rpc_free_iostats - release an rpc_iostats structure
130 * @stats: doomed rpc_iostats structure
133 void rpc_free_iostats(struct rpc_iostats *stats)
135 kfree(stats);
137 EXPORT_SYMBOL(rpc_free_iostats);
140 * rpc_count_iostats - tally up per-task stats
141 * @task: completed rpc_task
143 * Relies on the caller for serialization.
145 void rpc_count_iostats(struct rpc_task *task)
147 struct rpc_rqst *req = task->tk_rqstp;
148 struct rpc_iostats *stats = task->tk_client->cl_metrics;
149 struct rpc_iostats *op_metrics;
150 long rtt, execute, queue;
152 if (!stats || !req)
153 return;
154 op_metrics = &stats[task->tk_msg.rpc_proc->p_statidx];
156 op_metrics->om_ops++;
157 op_metrics->om_ntrans += req->rq_ntrans;
158 op_metrics->om_timeouts += task->tk_timeouts;
160 op_metrics->om_bytes_sent += task->tk_bytes_sent;
161 op_metrics->om_bytes_recv += req->rq_received;
163 queue = (long)req->rq_xtime - task->tk_start;
164 if (queue < 0)
165 queue = -queue;
166 op_metrics->om_queue += queue;
168 rtt = task->tk_rtt;
169 if (rtt < 0)
170 rtt = -rtt;
171 op_metrics->om_rtt += rtt;
173 execute = (long)jiffies - task->tk_start;
174 if (execute < 0)
175 execute = -execute;
176 op_metrics->om_execute += execute;
179 static void _print_name(struct seq_file *seq, unsigned int op,
180 struct rpc_procinfo *procs)
182 if (procs[op].p_name)
183 seq_printf(seq, "\t%12s: ", procs[op].p_name);
184 else if (op == 0)
185 seq_printf(seq, "\t NULL: ");
186 else
187 seq_printf(seq, "\t%12u: ", op);
190 #define MILLISECS_PER_JIFFY (1000 / HZ)
192 void rpc_print_iostats(struct seq_file *seq, struct rpc_clnt *clnt)
194 struct rpc_iostats *stats = clnt->cl_metrics;
195 struct rpc_xprt *xprt = clnt->cl_xprt;
196 unsigned int op, maxproc = clnt->cl_maxproc;
198 if (!stats)
199 return;
201 seq_printf(seq, "\tRPC iostats version: %s ", RPC_IOSTATS_VERS);
202 seq_printf(seq, "p/v: %u/%u (%s)\n",
203 clnt->cl_prog, clnt->cl_vers, clnt->cl_protname);
205 if (xprt)
206 xprt->ops->print_stats(xprt, seq);
208 seq_printf(seq, "\tper-op statistics\n");
209 for (op = 0; op < maxproc; op++) {
210 struct rpc_iostats *metrics = &stats[op];
211 _print_name(seq, op, clnt->cl_procinfo);
212 seq_printf(seq, "%lu %lu %lu %Lu %Lu %Lu %Lu %Lu\n",
213 metrics->om_ops,
214 metrics->om_ntrans,
215 metrics->om_timeouts,
216 metrics->om_bytes_sent,
217 metrics->om_bytes_recv,
218 metrics->om_queue * MILLISECS_PER_JIFFY,
219 metrics->om_rtt * MILLISECS_PER_JIFFY,
220 metrics->om_execute * MILLISECS_PER_JIFFY);
223 EXPORT_SYMBOL(rpc_print_iostats);
226 * Register/unregister RPC proc files
228 static inline struct proc_dir_entry *
229 do_register(const char *name, void *data, const struct file_operations *fops)
231 struct proc_dir_entry *ent;
233 rpc_proc_init();
234 dprintk("RPC: registering /proc/net/rpc/%s\n", name);
236 ent = create_proc_entry(name, 0, proc_net_rpc);
237 if (ent) {
238 ent->proc_fops = fops;
239 ent->data = data;
241 return ent;
244 struct proc_dir_entry *
245 rpc_proc_register(struct rpc_stat *statp)
247 return do_register(statp->program->name, statp, &rpc_proc_fops);
250 void
251 rpc_proc_unregister(const char *name)
253 remove_proc_entry(name, proc_net_rpc);
256 struct proc_dir_entry *
257 svc_proc_register(struct svc_stat *statp, const struct file_operations *fops)
259 return do_register(statp->program->pg_name, statp, fops);
262 void
263 svc_proc_unregister(const char *name)
265 remove_proc_entry(name, proc_net_rpc);
268 void
269 rpc_proc_init(void)
271 dprintk("RPC: registering /proc/net/rpc\n");
272 if (!proc_net_rpc) {
273 struct proc_dir_entry *ent;
274 ent = proc_mkdir("rpc", proc_net);
275 if (ent) {
276 ent->owner = THIS_MODULE;
277 proc_net_rpc = ent;
282 void
283 rpc_proc_exit(void)
285 dprintk("RPC: unregistering /proc/net/rpc\n");
286 if (proc_net_rpc) {
287 proc_net_rpc = NULL;
288 remove_proc_entry("net/rpc", NULL);