]>
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 | |
40bf7eb3 CL |
27 | #include <trace/events/sunrpc.h> |
28 | ||
4f42d0d5 | 29 | #include "netns.h" |
1da177e4 | 30 | |
4f42d0d5 | 31 | #define RPCDBG_FACILITY RPCDBG_MISC |
1da177e4 LT |
32 | |
33 | /* | |
34 | * Get RPC client stats | |
35 | */ | |
36 | static int rpc_proc_show(struct seq_file *seq, void *v) { | |
37 | const struct rpc_stat *statp = seq->private; | |
38 | const struct rpc_program *prog = statp->program; | |
ea339d46 | 39 | unsigned int i, j; |
1da177e4 LT |
40 | |
41 | seq_printf(seq, | |
49e31cba | 42 | "net %u %u %u %u\n", |
1da177e4 LT |
43 | statp->netcnt, |
44 | statp->netudpcnt, | |
45 | statp->nettcpcnt, | |
46 | statp->nettcpconn); | |
47 | seq_printf(seq, | |
49e31cba | 48 | "rpc %u %u %u\n", |
1da177e4 LT |
49 | statp->rpccnt, |
50 | statp->rpcretrans, | |
51 | statp->rpcauthrefresh); | |
52 | ||
53 | for (i = 0; i < prog->nrvers; i++) { | |
54 | const struct rpc_version *vers = prog->version[i]; | |
55 | if (!vers) | |
56 | continue; | |
49e31cba | 57 | seq_printf(seq, "proc%u %u", |
1da177e4 LT |
58 | vers->number, vers->nrprocs); |
59 | for (j = 0; j < vers->nrprocs; j++) | |
1c5876dd | 60 | seq_printf(seq, " %u", vers->counts[j]); |
1da177e4 LT |
61 | seq_putc(seq, '\n'); |
62 | } | |
63 | return 0; | |
64 | } | |
65 | ||
66 | static int rpc_proc_open(struct inode *inode, struct file *file) | |
67 | { | |
d9dda78b | 68 | return single_open(file, rpc_proc_show, PDE_DATA(inode)); |
1da177e4 LT |
69 | } |
70 | ||
da7071d7 | 71 | static const struct file_operations rpc_proc_fops = { |
1da177e4 LT |
72 | .owner = THIS_MODULE, |
73 | .open = rpc_proc_open, | |
74 | .read = seq_read, | |
75 | .llseek = seq_lseek, | |
76 | .release = single_release, | |
77 | }; | |
78 | ||
79 | /* | |
80 | * Get RPC server stats | |
81 | */ | |
7fd38af9 CH |
82 | void svc_seq_show(struct seq_file *seq, const struct svc_stat *statp) |
83 | { | |
1da177e4 | 84 | const struct svc_program *prog = statp->program; |
1da177e4 | 85 | const struct svc_version *vers; |
ea339d46 | 86 | unsigned int i, j; |
1da177e4 LT |
87 | |
88 | seq_printf(seq, | |
49e31cba | 89 | "net %u %u %u %u\n", |
1da177e4 LT |
90 | statp->netcnt, |
91 | statp->netudpcnt, | |
92 | statp->nettcpcnt, | |
93 | statp->nettcpconn); | |
94 | seq_printf(seq, | |
49e31cba | 95 | "rpc %u %u %u %u %u\n", |
1da177e4 LT |
96 | statp->rpccnt, |
97 | statp->rpcbadfmt+statp->rpcbadauth+statp->rpcbadclnt, | |
98 | statp->rpcbadfmt, | |
99 | statp->rpcbadauth, | |
100 | statp->rpcbadclnt); | |
101 | ||
102 | for (i = 0; i < prog->pg_nvers; i++) { | |
7fd38af9 CH |
103 | vers = prog->pg_vers[i]; |
104 | if (!vers) | |
1da177e4 | 105 | continue; |
49e31cba | 106 | seq_printf(seq, "proc%d %u", i, vers->vs_nproc); |
7fd38af9 CH |
107 | for (j = 0; j < vers->vs_nproc; j++) |
108 | seq_printf(seq, " %u", vers->vs_count[j]); | |
1da177e4 LT |
109 | seq_putc(seq, '\n'); |
110 | } | |
111 | } | |
24c3767e | 112 | EXPORT_SYMBOL_GPL(svc_seq_show); |
1da177e4 | 113 | |
11c556b3 CL |
114 | /** |
115 | * rpc_alloc_iostats - allocate an rpc_iostats structure | |
116 | * @clnt: RPC program, version, and xprt | |
117 | * | |
118 | */ | |
119 | struct rpc_iostats *rpc_alloc_iostats(struct rpc_clnt *clnt) | |
120 | { | |
edef1297 CL |
121 | struct rpc_iostats *stats; |
122 | int i; | |
123 | ||
124 | stats = kcalloc(clnt->cl_maxproc, sizeof(*stats), GFP_KERNEL); | |
125 | if (stats) { | |
126 | for (i = 0; i < clnt->cl_maxproc; i++) | |
127 | spin_lock_init(&stats[i].om_lock); | |
128 | } | |
129 | return stats; | |
11c556b3 | 130 | } |
e8914c65 | 131 | EXPORT_SYMBOL_GPL(rpc_alloc_iostats); |
11c556b3 CL |
132 | |
133 | /** | |
134 | * rpc_free_iostats - release an rpc_iostats structure | |
135 | * @stats: doomed rpc_iostats structure | |
136 | * | |
137 | */ | |
138 | void rpc_free_iostats(struct rpc_iostats *stats) | |
139 | { | |
140 | kfree(stats); | |
141 | } | |
e8914c65 | 142 | EXPORT_SYMBOL_GPL(rpc_free_iostats); |
11c556b3 CL |
143 | |
144 | /** | |
840210fc | 145 | * rpc_count_iostats_metrics - tally up per-task stats |
11c556b3 | 146 | * @task: completed rpc_task |
840210fc | 147 | * @op_metrics: stat structure for OP that will accumulate stats from @task |
11c556b3 | 148 | */ |
840210fc WAA |
149 | void rpc_count_iostats_metrics(const struct rpc_task *task, |
150 | struct rpc_iostats *op_metrics) | |
11c556b3 CL |
151 | { |
152 | struct rpc_rqst *req = task->tk_rqstp; | |
40bf7eb3 | 153 | ktime_t backlog, execute, now; |
11c556b3 | 154 | |
840210fc | 155 | if (!op_metrics || !req) |
11c556b3 | 156 | return; |
55ae1aab | 157 | |
edef1297 | 158 | now = ktime_get(); |
edef1297 CL |
159 | spin_lock(&op_metrics->om_lock); |
160 | ||
11c556b3 | 161 | op_metrics->om_ops++; |
ae09531d CL |
162 | /* kernel API: om_ops must never become larger than om_ntrans */ |
163 | op_metrics->om_ntrans += max(req->rq_ntrans, 1); | |
11c556b3 CL |
164 | op_metrics->om_timeouts += task->tk_timeouts; |
165 | ||
d60dbb20 | 166 | op_metrics->om_bytes_sent += req->rq_xmit_bytes_sent; |
dd2b63d0 | 167 | op_metrics->om_bytes_recv += req->rq_reply_bytes_recvd; |
11c556b3 | 168 | |
40bf7eb3 | 169 | backlog = 0; |
ae09531d | 170 | if (ktime_to_ns(req->rq_xtime)) { |
40bf7eb3 CL |
171 | backlog = ktime_sub(req->rq_xtime, task->tk_start); |
172 | op_metrics->om_queue = ktime_add(op_metrics->om_queue, backlog); | |
ae09531d | 173 | } |
40bf7eb3 | 174 | |
d60dbb20 | 175 | op_metrics->om_rtt = ktime_add(op_metrics->om_rtt, req->rq_rtt); |
11c556b3 | 176 | |
40bf7eb3 CL |
177 | execute = ktime_sub(now, task->tk_start); |
178 | op_metrics->om_execute = ktime_add(op_metrics->om_execute, execute); | |
edef1297 CL |
179 | |
180 | spin_unlock(&op_metrics->om_lock); | |
40bf7eb3 CL |
181 | |
182 | trace_rpc_stats_latency(req->rq_task, backlog, req->rq_rtt, execute); | |
11c556b3 | 183 | } |
840210fc WAA |
184 | EXPORT_SYMBOL_GPL(rpc_count_iostats_metrics); |
185 | ||
186 | /** | |
187 | * rpc_count_iostats - tally up per-task stats | |
188 | * @task: completed rpc_task | |
189 | * @stats: array of stat structures | |
190 | * | |
191 | * Uses the statidx from @task | |
192 | */ | |
193 | void rpc_count_iostats(const struct rpc_task *task, struct rpc_iostats *stats) | |
194 | { | |
195 | rpc_count_iostats_metrics(task, | |
196 | &stats[task->tk_msg.rpc_proc->p_statidx]); | |
197 | } | |
0a702195 | 198 | EXPORT_SYMBOL_GPL(rpc_count_iostats); |
11c556b3 | 199 | |
ec535ce1 | 200 | static void _print_name(struct seq_file *seq, unsigned int op, |
499b4988 | 201 | const struct rpc_procinfo *procs) |
cc0175c1 CL |
202 | { |
203 | if (procs[op].p_name) | |
204 | seq_printf(seq, "\t%12s: ", procs[op].p_name); | |
205 | else if (op == 0) | |
206 | seq_printf(seq, "\t NULL: "); | |
207 | else | |
208 | seq_printf(seq, "\t%12u: ", op); | |
209 | } | |
210 | ||
11c556b3 CL |
211 | void rpc_print_iostats(struct seq_file *seq, struct rpc_clnt *clnt) |
212 | { | |
213 | struct rpc_iostats *stats = clnt->cl_metrics; | |
2446ab60 | 214 | struct rpc_xprt *xprt; |
11c556b3 CL |
215 | unsigned int op, maxproc = clnt->cl_maxproc; |
216 | ||
217 | if (!stats) | |
218 | return; | |
219 | ||
220 | seq_printf(seq, "\tRPC iostats version: %s ", RPC_IOSTATS_VERS); | |
221 | seq_printf(seq, "p/v: %u/%u (%s)\n", | |
55909f21 | 222 | clnt->cl_prog, clnt->cl_vers, clnt->cl_program->name); |
11c556b3 | 223 | |
2446ab60 TM |
224 | rcu_read_lock(); |
225 | xprt = rcu_dereference(clnt->cl_xprt); | |
11c556b3 CL |
226 | if (xprt) |
227 | xprt->ops->print_stats(xprt, seq); | |
2446ab60 | 228 | rcu_read_unlock(); |
11c556b3 CL |
229 | |
230 | seq_printf(seq, "\tper-op statistics\n"); | |
231 | for (op = 0; op < maxproc; op++) { | |
232 | struct rpc_iostats *metrics = &stats[op]; | |
cc0175c1 | 233 | _print_name(seq, op, clnt->cl_procinfo); |
11c556b3 CL |
234 | seq_printf(seq, "%lu %lu %lu %Lu %Lu %Lu %Lu %Lu\n", |
235 | metrics->om_ops, | |
236 | metrics->om_ntrans, | |
237 | metrics->om_timeouts, | |
238 | metrics->om_bytes_sent, | |
239 | metrics->om_bytes_recv, | |
ff839970 CL |
240 | ktime_to_ms(metrics->om_queue), |
241 | ktime_to_ms(metrics->om_rtt), | |
242 | ktime_to_ms(metrics->om_execute)); | |
11c556b3 CL |
243 | } |
244 | } | |
e8914c65 | 245 | EXPORT_SYMBOL_GPL(rpc_print_iostats); |
11c556b3 | 246 | |
1da177e4 LT |
247 | /* |
248 | * Register/unregister RPC proc files | |
249 | */ | |
250 | static inline struct proc_dir_entry * | |
ec7652aa SK |
251 | do_register(struct net *net, const char *name, void *data, |
252 | const struct file_operations *fops) | |
1da177e4 | 253 | { |
4f42d0d5 | 254 | struct sunrpc_net *sn; |
1da177e4 | 255 | |
4f42d0d5 | 256 | dprintk("RPC: registering /proc/net/rpc/%s\n", name); |
ec7652aa | 257 | sn = net_generic(net, sunrpc_net_id); |
4f42d0d5 | 258 | return proc_create_data(name, 0, sn->proc_net_rpc, fops, data); |
1da177e4 LT |
259 | } |
260 | ||
261 | struct proc_dir_entry * | |
ec7652aa | 262 | rpc_proc_register(struct net *net, struct rpc_stat *statp) |
1da177e4 | 263 | { |
ec7652aa | 264 | return do_register(net, statp->program->name, statp, &rpc_proc_fops); |
1da177e4 | 265 | } |
e8914c65 | 266 | EXPORT_SYMBOL_GPL(rpc_proc_register); |
1da177e4 LT |
267 | |
268 | void | |
ec7652aa | 269 | rpc_proc_unregister(struct net *net, const char *name) |
1da177e4 | 270 | { |
4f42d0d5 PE |
271 | struct sunrpc_net *sn; |
272 | ||
ec7652aa | 273 | sn = net_generic(net, sunrpc_net_id); |
4f42d0d5 | 274 | remove_proc_entry(name, sn->proc_net_rpc); |
1da177e4 | 275 | } |
e8914c65 | 276 | EXPORT_SYMBOL_GPL(rpc_proc_unregister); |
1da177e4 LT |
277 | |
278 | struct proc_dir_entry * | |
246590f5 | 279 | svc_proc_register(struct net *net, struct svc_stat *statp, const struct file_operations *fops) |
1da177e4 | 280 | { |
246590f5 | 281 | return do_register(net, statp->program->pg_name, statp, fops); |
1da177e4 | 282 | } |
24c3767e | 283 | EXPORT_SYMBOL_GPL(svc_proc_register); |
1da177e4 LT |
284 | |
285 | void | |
246590f5 | 286 | svc_proc_unregister(struct net *net, const char *name) |
1da177e4 | 287 | { |
4f42d0d5 PE |
288 | struct sunrpc_net *sn; |
289 | ||
246590f5 | 290 | sn = net_generic(net, sunrpc_net_id); |
4f42d0d5 | 291 | remove_proc_entry(name, sn->proc_net_rpc); |
1da177e4 | 292 | } |
24c3767e | 293 | EXPORT_SYMBOL_GPL(svc_proc_unregister); |
1da177e4 | 294 | |
4f42d0d5 | 295 | int rpc_proc_init(struct net *net) |
1da177e4 | 296 | { |
4f42d0d5 PE |
297 | struct sunrpc_net *sn; |
298 | ||
46121cf7 | 299 | dprintk("RPC: registering /proc/net/rpc\n"); |
4f42d0d5 PE |
300 | sn = net_generic(net, sunrpc_net_id); |
301 | sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net); | |
302 | if (sn->proc_net_rpc == NULL) | |
303 | return -ENOMEM; | |
304 | ||
305 | return 0; | |
1da177e4 LT |
306 | } |
307 | ||
4f42d0d5 | 308 | void rpc_proc_exit(struct net *net) |
1da177e4 | 309 | { |
46121cf7 | 310 | dprintk("RPC: unregistering /proc/net/rpc\n"); |
4f42d0d5 | 311 | remove_proc_entry("rpc", net->proc_net); |
1da177e4 LT |
312 | } |
313 |