Root/
1 | /* |
2 | * linux/net/sunrpc/stats.c |
3 | * |
4 | * procfs-based user access to generic RPC statistics. The stats files |
5 | * reside in /proc/net/rpc. |
6 | * |
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. |
11 | * |
12 | * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de> |
13 | */ |
14 | |
15 | #include <linux/module.h> |
16 | #include <linux/slab.h> |
17 | |
18 | #include <linux/init.h> |
19 | #include <linux/kernel.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> |
25 | #include <net/net_namespace.h> |
26 | |
27 | #define RPCDBG_FACILITY RPCDBG_MISC |
28 | |
29 | struct proc_dir_entry *proc_net_rpc = NULL; |
30 | |
31 | /* |
32 | * Get RPC client stats |
33 | */ |
34 | static int rpc_proc_show(struct seq_file *seq, void *v) { |
35 | const struct rpc_stat *statp = seq->private; |
36 | const struct rpc_program *prog = statp->program; |
37 | unsigned int i, j; |
38 | |
39 | seq_printf(seq, |
40 | "net %u %u %u %u\n", |
41 | statp->netcnt, |
42 | statp->netudpcnt, |
43 | statp->nettcpcnt, |
44 | statp->nettcpconn); |
45 | seq_printf(seq, |
46 | "rpc %u %u %u\n", |
47 | statp->rpccnt, |
48 | statp->rpcretrans, |
49 | statp->rpcauthrefresh); |
50 | |
51 | for (i = 0; i < prog->nrvers; i++) { |
52 | const struct rpc_version *vers = prog->version[i]; |
53 | if (!vers) |
54 | continue; |
55 | seq_printf(seq, "proc%u %u", |
56 | vers->number, vers->nrprocs); |
57 | for (j = 0; j < vers->nrprocs; j++) |
58 | seq_printf(seq, " %u", |
59 | vers->procs[j].p_count); |
60 | seq_putc(seq, '\n'); |
61 | } |
62 | return 0; |
63 | } |
64 | |
65 | static int rpc_proc_open(struct inode *inode, struct file *file) |
66 | { |
67 | return single_open(file, rpc_proc_show, PDE(inode)->data); |
68 | } |
69 | |
70 | static const struct file_operations rpc_proc_fops = { |
71 | .owner = THIS_MODULE, |
72 | .open = rpc_proc_open, |
73 | .read = seq_read, |
74 | .llseek = seq_lseek, |
75 | .release = single_release, |
76 | }; |
77 | |
78 | /* |
79 | * Get RPC server stats |
80 | */ |
81 | void svc_seq_show(struct seq_file *seq, const struct svc_stat *statp) { |
82 | const struct svc_program *prog = statp->program; |
83 | const struct svc_procedure *proc; |
84 | const struct svc_version *vers; |
85 | unsigned int i, j; |
86 | |
87 | seq_printf(seq, |
88 | "net %u %u %u %u\n", |
89 | statp->netcnt, |
90 | statp->netudpcnt, |
91 | statp->nettcpcnt, |
92 | statp->nettcpconn); |
93 | seq_printf(seq, |
94 | "rpc %u %u %u %u %u\n", |
95 | statp->rpccnt, |
96 | statp->rpcbadfmt+statp->rpcbadauth+statp->rpcbadclnt, |
97 | statp->rpcbadfmt, |
98 | statp->rpcbadauth, |
99 | statp->rpcbadclnt); |
100 | |
101 | for (i = 0; i < prog->pg_nvers; i++) { |
102 | if (!(vers = prog->pg_vers[i]) || !(proc = vers->vs_proc)) |
103 | continue; |
104 | seq_printf(seq, "proc%d %u", i, vers->vs_nproc); |
105 | for (j = 0; j < vers->vs_nproc; j++, proc++) |
106 | seq_printf(seq, " %u", proc->pc_count); |
107 | seq_putc(seq, '\n'); |
108 | } |
109 | } |
110 | EXPORT_SYMBOL_GPL(svc_seq_show); |
111 | |
112 | /** |
113 | * rpc_alloc_iostats - allocate an rpc_iostats structure |
114 | * @clnt: RPC program, version, and xprt |
115 | * |
116 | */ |
117 | struct rpc_iostats *rpc_alloc_iostats(struct rpc_clnt *clnt) |
118 | { |
119 | struct rpc_iostats *new; |
120 | new = kcalloc(clnt->cl_maxproc, sizeof(struct rpc_iostats), GFP_KERNEL); |
121 | return new; |
122 | } |
123 | EXPORT_SYMBOL_GPL(rpc_alloc_iostats); |
124 | |
125 | /** |
126 | * rpc_free_iostats - release an rpc_iostats structure |
127 | * @stats: doomed rpc_iostats structure |
128 | * |
129 | */ |
130 | void rpc_free_iostats(struct rpc_iostats *stats) |
131 | { |
132 | kfree(stats); |
133 | } |
134 | EXPORT_SYMBOL_GPL(rpc_free_iostats); |
135 | |
136 | /** |
137 | * rpc_count_iostats - tally up per-task stats |
138 | * @task: completed rpc_task |
139 | * |
140 | * Relies on the caller for serialization. |
141 | */ |
142 | void rpc_count_iostats(struct rpc_task *task) |
143 | { |
144 | struct rpc_rqst *req = task->tk_rqstp; |
145 | struct rpc_iostats *stats; |
146 | struct rpc_iostats *op_metrics; |
147 | long rtt, execute, queue; |
148 | |
149 | if (!task->tk_client || !task->tk_client->cl_metrics || !req) |
150 | return; |
151 | |
152 | stats = task->tk_client->cl_metrics; |
153 | op_metrics = &stats[task->tk_msg.rpc_proc->p_statidx]; |
154 | |
155 | op_metrics->om_ops++; |
156 | op_metrics->om_ntrans += req->rq_ntrans; |
157 | op_metrics->om_timeouts += task->tk_timeouts; |
158 | |
159 | op_metrics->om_bytes_sent += task->tk_bytes_sent; |
160 | op_metrics->om_bytes_recv += req->rq_reply_bytes_recvd; |
161 | |
162 | queue = (long)req->rq_xtime - task->tk_start; |
163 | if (queue < 0) |
164 | queue = -queue; |
165 | op_metrics->om_queue += queue; |
166 | |
167 | rtt = task->tk_rtt; |
168 | if (rtt < 0) |
169 | rtt = -rtt; |
170 | op_metrics->om_rtt += rtt; |
171 | |
172 | execute = (long)jiffies - task->tk_start; |
173 | if (execute < 0) |
174 | execute = -execute; |
175 | op_metrics->om_execute += execute; |
176 | } |
177 | |
178 | static void _print_name(struct seq_file *seq, unsigned int op, |
179 | struct rpc_procinfo *procs) |
180 | { |
181 | if (procs[op].p_name) |
182 | seq_printf(seq, "\t%12s: ", procs[op].p_name); |
183 | else if (op == 0) |
184 | seq_printf(seq, "\t NULL: "); |
185 | else |
186 | seq_printf(seq, "\t%12u: ", op); |
187 | } |
188 | |
189 | #define MILLISECS_PER_JIFFY (1000 / HZ) |
190 | |
191 | void rpc_print_iostats(struct seq_file *seq, struct rpc_clnt *clnt) |
192 | { |
193 | struct rpc_iostats *stats = clnt->cl_metrics; |
194 | struct rpc_xprt *xprt = clnt->cl_xprt; |
195 | unsigned int op, maxproc = clnt->cl_maxproc; |
196 | |
197 | if (!stats) |
198 | return; |
199 | |
200 | seq_printf(seq, "\tRPC iostats version: %s ", RPC_IOSTATS_VERS); |
201 | seq_printf(seq, "p/v: %u/%u (%s)\n", |
202 | clnt->cl_prog, clnt->cl_vers, clnt->cl_protname); |
203 | |
204 | if (xprt) |
205 | xprt->ops->print_stats(xprt, seq); |
206 | |
207 | seq_printf(seq, "\tper-op statistics\n"); |
208 | for (op = 0; op < maxproc; op++) { |
209 | struct rpc_iostats *metrics = &stats[op]; |
210 | _print_name(seq, op, clnt->cl_procinfo); |
211 | seq_printf(seq, "%lu %lu %lu %Lu %Lu %Lu %Lu %Lu\n", |
212 | metrics->om_ops, |
213 | metrics->om_ntrans, |
214 | metrics->om_timeouts, |
215 | metrics->om_bytes_sent, |
216 | metrics->om_bytes_recv, |
217 | metrics->om_queue * MILLISECS_PER_JIFFY, |
218 | metrics->om_rtt * MILLISECS_PER_JIFFY, |
219 | metrics->om_execute * MILLISECS_PER_JIFFY); |
220 | } |
221 | } |
222 | EXPORT_SYMBOL_GPL(rpc_print_iostats); |
223 | |
224 | /* |
225 | * Register/unregister RPC proc files |
226 | */ |
227 | static inline struct proc_dir_entry * |
228 | do_register(const char *name, void *data, const struct file_operations *fops) |
229 | { |
230 | rpc_proc_init(); |
231 | dprintk("RPC: registering /proc/net/rpc/%s\n", name); |
232 | |
233 | return proc_create_data(name, 0, proc_net_rpc, fops, data); |
234 | } |
235 | |
236 | struct proc_dir_entry * |
237 | rpc_proc_register(struct rpc_stat *statp) |
238 | { |
239 | return do_register(statp->program->name, statp, &rpc_proc_fops); |
240 | } |
241 | EXPORT_SYMBOL_GPL(rpc_proc_register); |
242 | |
243 | void |
244 | rpc_proc_unregister(const char *name) |
245 | { |
246 | remove_proc_entry(name, proc_net_rpc); |
247 | } |
248 | EXPORT_SYMBOL_GPL(rpc_proc_unregister); |
249 | |
250 | struct proc_dir_entry * |
251 | svc_proc_register(struct svc_stat *statp, const struct file_operations *fops) |
252 | { |
253 | return do_register(statp->program->pg_name, statp, fops); |
254 | } |
255 | EXPORT_SYMBOL_GPL(svc_proc_register); |
256 | |
257 | void |
258 | svc_proc_unregister(const char *name) |
259 | { |
260 | remove_proc_entry(name, proc_net_rpc); |
261 | } |
262 | EXPORT_SYMBOL_GPL(svc_proc_unregister); |
263 | |
264 | void |
265 | rpc_proc_init(void) |
266 | { |
267 | dprintk("RPC: registering /proc/net/rpc\n"); |
268 | if (!proc_net_rpc) |
269 | proc_net_rpc = proc_mkdir("rpc", init_net.proc_net); |
270 | } |
271 | |
272 | void |
273 | rpc_proc_exit(void) |
274 | { |
275 | dprintk("RPC: unregistering /proc/net/rpc\n"); |
276 | if (proc_net_rpc) { |
277 | proc_net_rpc = NULL; |
278 | remove_proc_entry("rpc", init_net.proc_net); |
279 | } |
280 | } |
281 | |
282 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9