Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
5a0e3ad6 | 16 | #include <linux/slab.h> |
1da177e4 LT |
17 | |
18 | #include <linux/init.h> | |
19 | #include <linux/kernel.h> | |
1da177e4 LT |
20 | #include <linux/proc_fs.h> |
21 | #include <linux/seq_file.h> | |
22 | #include <linux/sunrpc/clnt.h> | |
23 | #include <linux/sunrpc/svcsock.h> | |
11c556b3 | 24 | #include <linux/sunrpc/metrics.h> |
2446ab60 | 25 | #include <linux/rcupdate.h> |
1da177e4 | 26 | |
4f42d0d5 | 27 | #include "netns.h" |
1da177e4 | 28 | |
4f42d0d5 | 29 | #define RPCDBG_FACILITY RPCDBG_MISC |
1da177e4 LT |
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; | |
ea339d46 | 37 | unsigned int i, j; |
1da177e4 LT |
38 | |
39 | seq_printf(seq, | |
49e31cba | 40 | "net %u %u %u %u\n", |
1da177e4 LT |
41 | statp->netcnt, |
42 | statp->netudpcnt, | |
43 | statp->nettcpcnt, | |
44 | statp->nettcpconn); | |
45 | seq_printf(seq, | |
49e31cba | 46 | "rpc %u %u %u\n", |
1da177e4 LT |
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; | |
49e31cba | 55 | seq_printf(seq, "proc%u %u", |
1da177e4 LT |
56 | vers->number, vers->nrprocs); |
57 | for (j = 0; j < vers->nrprocs; j++) | |
49e31cba | 58 | seq_printf(seq, " %u", |
1da177e4 LT |
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 | { | |
d9dda78b | 67 | return single_open(file, rpc_proc_show, PDE_DATA(inode)); |
1da177e4 LT |
68 | } |
69 | ||
da7071d7 | 70 | static const struct file_operations rpc_proc_fops = { |
1da177e4 LT |
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; | |
ea339d46 | 85 | unsigned int i, j; |
1da177e4 LT |
86 | |
87 | seq_printf(seq, | |
49e31cba | 88 | "net %u %u %u %u\n", |
1da177e4 LT |
89 | statp->netcnt, |
90 | statp->netudpcnt, | |
91 | statp->nettcpcnt, | |
92 | statp->nettcpconn); | |
93 | seq_printf(seq, | |
49e31cba | 94 | "rpc %u %u %u %u %u\n", |
1da177e4 LT |
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; | |
49e31cba | 104 | seq_printf(seq, "proc%d %u", i, vers->vs_nproc); |
1da177e4 | 105 | for (j = 0; j < vers->vs_nproc; j++, proc++) |
49e31cba | 106 | seq_printf(seq, " %u", proc->pc_count); |
1da177e4 LT |
107 | seq_putc(seq, '\n'); |
108 | } | |
109 | } | |
24c3767e | 110 | EXPORT_SYMBOL_GPL(svc_seq_show); |
1da177e4 | 111 | |
11c556b3 CL |
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 | { | |
edef1297 CL |
119 | struct rpc_iostats *stats; |
120 | int i; | |
121 | ||
122 | stats = kcalloc(clnt->cl_maxproc, sizeof(*stats), GFP_KERNEL); | |
123 | if (stats) { | |
124 | for (i = 0; i < clnt->cl_maxproc; i++) | |
125 | spin_lock_init(&stats[i].om_lock); | |
126 | } | |
127 | return stats; | |
11c556b3 | 128 | } |
e8914c65 | 129 | EXPORT_SYMBOL_GPL(rpc_alloc_iostats); |
11c556b3 CL |
130 | |
131 | /** | |
132 | * rpc_free_iostats - release an rpc_iostats structure | |
133 | * @stats: doomed rpc_iostats structure | |
134 | * | |
135 | */ | |
136 | void rpc_free_iostats(struct rpc_iostats *stats) | |
137 | { | |
138 | kfree(stats); | |
139 | } | |
e8914c65 | 140 | EXPORT_SYMBOL_GPL(rpc_free_iostats); |
11c556b3 CL |
141 | |
142 | /** | |
840210fc | 143 | * rpc_count_iostats_metrics - tally up per-task stats |
11c556b3 | 144 | * @task: completed rpc_task |
840210fc | 145 | * @op_metrics: stat structure for OP that will accumulate stats from @task |
11c556b3 | 146 | */ |
840210fc WAA |
147 | void rpc_count_iostats_metrics(const struct rpc_task *task, |
148 | struct rpc_iostats *op_metrics) | |
11c556b3 CL |
149 | { |
150 | struct rpc_rqst *req = task->tk_rqstp; | |
edef1297 | 151 | ktime_t delta, now; |
11c556b3 | 152 | |
840210fc | 153 | if (!op_metrics || !req) |
11c556b3 | 154 | return; |
55ae1aab | 155 | |
edef1297 | 156 | now = ktime_get(); |
edef1297 CL |
157 | spin_lock(&op_metrics->om_lock); |
158 | ||
11c556b3 CL |
159 | op_metrics->om_ops++; |
160 | op_metrics->om_ntrans += req->rq_ntrans; | |
161 | op_metrics->om_timeouts += task->tk_timeouts; | |
162 | ||
d60dbb20 | 163 | op_metrics->om_bytes_sent += req->rq_xmit_bytes_sent; |
dd2b63d0 | 164 | op_metrics->om_bytes_recv += req->rq_reply_bytes_recvd; |
11c556b3 | 165 | |
ff839970 CL |
166 | delta = ktime_sub(req->rq_xtime, task->tk_start); |
167 | op_metrics->om_queue = ktime_add(op_metrics->om_queue, delta); | |
11c556b3 | 168 | |
d60dbb20 | 169 | op_metrics->om_rtt = ktime_add(op_metrics->om_rtt, req->rq_rtt); |
11c556b3 | 170 | |
edef1297 | 171 | delta = ktime_sub(now, task->tk_start); |
ff839970 | 172 | op_metrics->om_execute = ktime_add(op_metrics->om_execute, delta); |
edef1297 CL |
173 | |
174 | spin_unlock(&op_metrics->om_lock); | |
11c556b3 | 175 | } |
840210fc WAA |
176 | EXPORT_SYMBOL_GPL(rpc_count_iostats_metrics); |
177 | ||
178 | /** | |
179 | * rpc_count_iostats - tally up per-task stats | |
180 | * @task: completed rpc_task | |
181 | * @stats: array of stat structures | |
182 | * | |
183 | * Uses the statidx from @task | |
184 | */ | |
185 | void rpc_count_iostats(const struct rpc_task *task, struct rpc_iostats *stats) | |
186 | { | |
187 | rpc_count_iostats_metrics(task, | |
188 | &stats[task->tk_msg.rpc_proc->p_statidx]); | |
189 | } | |
0a702195 | 190 | EXPORT_SYMBOL_GPL(rpc_count_iostats); |
11c556b3 | 191 | |
ec535ce1 AB |
192 | static void _print_name(struct seq_file *seq, unsigned int op, |
193 | struct rpc_procinfo *procs) | |
cc0175c1 CL |
194 | { |
195 | if (procs[op].p_name) | |
196 | seq_printf(seq, "\t%12s: ", procs[op].p_name); | |
197 | else if (op == 0) | |
198 | seq_printf(seq, "\t NULL: "); | |
199 | else | |
200 | seq_printf(seq, "\t%12u: ", op); | |
201 | } | |
202 | ||
11c556b3 CL |
203 | void rpc_print_iostats(struct seq_file *seq, struct rpc_clnt *clnt) |
204 | { | |
205 | struct rpc_iostats *stats = clnt->cl_metrics; | |
2446ab60 | 206 | struct rpc_xprt *xprt; |
11c556b3 CL |
207 | unsigned int op, maxproc = clnt->cl_maxproc; |
208 | ||
209 | if (!stats) | |
210 | return; | |
211 | ||
212 | seq_printf(seq, "\tRPC iostats version: %s ", RPC_IOSTATS_VERS); | |
213 | seq_printf(seq, "p/v: %u/%u (%s)\n", | |
55909f21 | 214 | clnt->cl_prog, clnt->cl_vers, clnt->cl_program->name); |
11c556b3 | 215 | |
2446ab60 TM |
216 | rcu_read_lock(); |
217 | xprt = rcu_dereference(clnt->cl_xprt); | |
11c556b3 CL |
218 | if (xprt) |
219 | xprt->ops->print_stats(xprt, seq); | |
2446ab60 | 220 | rcu_read_unlock(); |
11c556b3 CL |
221 | |
222 | seq_printf(seq, "\tper-op statistics\n"); | |
223 | for (op = 0; op < maxproc; op++) { | |
224 | struct rpc_iostats *metrics = &stats[op]; | |
cc0175c1 | 225 | _print_name(seq, op, clnt->cl_procinfo); |
11c556b3 CL |
226 | seq_printf(seq, "%lu %lu %lu %Lu %Lu %Lu %Lu %Lu\n", |
227 | metrics->om_ops, | |
228 | metrics->om_ntrans, | |
229 | metrics->om_timeouts, | |
230 | metrics->om_bytes_sent, | |
231 | metrics->om_bytes_recv, | |
ff839970 CL |
232 | ktime_to_ms(metrics->om_queue), |
233 | ktime_to_ms(metrics->om_rtt), | |
234 | ktime_to_ms(metrics->om_execute)); | |
11c556b3 CL |
235 | } |
236 | } | |
e8914c65 | 237 | EXPORT_SYMBOL_GPL(rpc_print_iostats); |
11c556b3 | 238 | |
1da177e4 LT |
239 | /* |
240 | * Register/unregister RPC proc files | |
241 | */ | |
242 | static inline struct proc_dir_entry * | |
ec7652aa SK |
243 | do_register(struct net *net, const char *name, void *data, |
244 | const struct file_operations *fops) | |
1da177e4 | 245 | { |
4f42d0d5 | 246 | struct sunrpc_net *sn; |
1da177e4 | 247 | |
4f42d0d5 | 248 | dprintk("RPC: registering /proc/net/rpc/%s\n", name); |
ec7652aa | 249 | sn = net_generic(net, sunrpc_net_id); |
4f42d0d5 | 250 | return proc_create_data(name, 0, sn->proc_net_rpc, fops, data); |
1da177e4 LT |
251 | } |
252 | ||
253 | struct proc_dir_entry * | |
ec7652aa | 254 | rpc_proc_register(struct net *net, struct rpc_stat *statp) |
1da177e4 | 255 | { |
ec7652aa | 256 | return do_register(net, statp->program->name, statp, &rpc_proc_fops); |
1da177e4 | 257 | } |
e8914c65 | 258 | EXPORT_SYMBOL_GPL(rpc_proc_register); |
1da177e4 LT |
259 | |
260 | void | |
ec7652aa | 261 | rpc_proc_unregister(struct net *net, const char *name) |
1da177e4 | 262 | { |
4f42d0d5 PE |
263 | struct sunrpc_net *sn; |
264 | ||
ec7652aa | 265 | sn = net_generic(net, sunrpc_net_id); |
4f42d0d5 | 266 | remove_proc_entry(name, sn->proc_net_rpc); |
1da177e4 | 267 | } |
e8914c65 | 268 | EXPORT_SYMBOL_GPL(rpc_proc_unregister); |
1da177e4 LT |
269 | |
270 | struct proc_dir_entry * | |
246590f5 | 271 | svc_proc_register(struct net *net, struct svc_stat *statp, const struct file_operations *fops) |
1da177e4 | 272 | { |
246590f5 | 273 | return do_register(net, statp->program->pg_name, statp, fops); |
1da177e4 | 274 | } |
24c3767e | 275 | EXPORT_SYMBOL_GPL(svc_proc_register); |
1da177e4 LT |
276 | |
277 | void | |
246590f5 | 278 | svc_proc_unregister(struct net *net, const char *name) |
1da177e4 | 279 | { |
4f42d0d5 PE |
280 | struct sunrpc_net *sn; |
281 | ||
246590f5 | 282 | sn = net_generic(net, sunrpc_net_id); |
4f42d0d5 | 283 | remove_proc_entry(name, sn->proc_net_rpc); |
1da177e4 | 284 | } |
24c3767e | 285 | EXPORT_SYMBOL_GPL(svc_proc_unregister); |
1da177e4 | 286 | |
4f42d0d5 | 287 | int rpc_proc_init(struct net *net) |
1da177e4 | 288 | { |
4f42d0d5 PE |
289 | struct sunrpc_net *sn; |
290 | ||
46121cf7 | 291 | dprintk("RPC: registering /proc/net/rpc\n"); |
4f42d0d5 PE |
292 | sn = net_generic(net, sunrpc_net_id); |
293 | sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net); | |
294 | if (sn->proc_net_rpc == NULL) | |
295 | return -ENOMEM; | |
296 | ||
297 | return 0; | |
1da177e4 LT |
298 | } |
299 | ||
4f42d0d5 | 300 | void rpc_proc_exit(struct net *net) |
1da177e4 | 301 | { |
46121cf7 | 302 | dprintk("RPC: unregistering /proc/net/rpc\n"); |
4f42d0d5 | 303 | remove_proc_entry("rpc", net->proc_net); |
1da177e4 LT |
304 | } |
305 |