Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/proc_fs.h> |
| 20 | #include <linux/seq_file.h> |
| 21 | #include <linux/sunrpc/clnt.h> |
| 22 | #include <linux/sunrpc/svcsock.h> |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 23 | #include <linux/sunrpc/metrics.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 24 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #define RPCDBG_FACILITY RPCDBG_MISC |
| 27 | |
| 28 | struct proc_dir_entry *proc_net_rpc = NULL; |
| 29 | |
| 30 | /* |
| 31 | * Get RPC client stats |
| 32 | */ |
| 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; |
Chuck Lever | ea339d4 | 2007-10-26 13:32:56 -0400 | [diff] [blame] | 36 | unsigned int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | seq_printf(seq, |
Max Kellermann | 49e31cb | 2005-09-06 15:18:03 -0700 | [diff] [blame] | 39 | "net %u %u %u %u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | statp->netcnt, |
| 41 | statp->netudpcnt, |
| 42 | statp->nettcpcnt, |
| 43 | statp->nettcpconn); |
| 44 | seq_printf(seq, |
Max Kellermann | 49e31cb | 2005-09-06 15:18:03 -0700 | [diff] [blame] | 45 | "rpc %u %u %u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | statp->rpccnt, |
| 47 | statp->rpcretrans, |
| 48 | statp->rpcauthrefresh); |
| 49 | |
| 50 | for (i = 0; i < prog->nrvers; i++) { |
| 51 | const struct rpc_version *vers = prog->version[i]; |
| 52 | if (!vers) |
| 53 | continue; |
Max Kellermann | 49e31cb | 2005-09-06 15:18:03 -0700 | [diff] [blame] | 54 | seq_printf(seq, "proc%u %u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | vers->number, vers->nrprocs); |
| 56 | for (j = 0; j < vers->nrprocs; j++) |
Max Kellermann | 49e31cb | 2005-09-06 15:18:03 -0700 | [diff] [blame] | 57 | seq_printf(seq, " %u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | vers->procs[j].p_count); |
| 59 | seq_putc(seq, '\n'); |
| 60 | } |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int rpc_proc_open(struct inode *inode, struct file *file) |
| 65 | { |
| 66 | return single_open(file, rpc_proc_show, PDE(inode)->data); |
| 67 | } |
| 68 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 69 | static const struct file_operations rpc_proc_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | .owner = THIS_MODULE, |
| 71 | .open = rpc_proc_open, |
| 72 | .read = seq_read, |
| 73 | .llseek = seq_lseek, |
| 74 | .release = single_release, |
| 75 | }; |
| 76 | |
| 77 | /* |
| 78 | * Get RPC server stats |
| 79 | */ |
| 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; |
Chuck Lever | ea339d4 | 2007-10-26 13:32:56 -0400 | [diff] [blame] | 84 | unsigned int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | seq_printf(seq, |
Max Kellermann | 49e31cb | 2005-09-06 15:18:03 -0700 | [diff] [blame] | 87 | "net %u %u %u %u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | statp->netcnt, |
| 89 | statp->netudpcnt, |
| 90 | statp->nettcpcnt, |
| 91 | statp->nettcpconn); |
| 92 | seq_printf(seq, |
Max Kellermann | 49e31cb | 2005-09-06 15:18:03 -0700 | [diff] [blame] | 93 | "rpc %u %u %u %u %u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | statp->rpccnt, |
| 95 | statp->rpcbadfmt+statp->rpcbadauth+statp->rpcbadclnt, |
| 96 | statp->rpcbadfmt, |
| 97 | statp->rpcbadauth, |
| 98 | statp->rpcbadclnt); |
| 99 | |
| 100 | for (i = 0; i < prog->pg_nvers; i++) { |
| 101 | if (!(vers = prog->pg_vers[i]) || !(proc = vers->vs_proc)) |
| 102 | continue; |
Max Kellermann | 49e31cb | 2005-09-06 15:18:03 -0700 | [diff] [blame] | 103 | seq_printf(seq, "proc%d %u", i, vers->vs_nproc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | for (j = 0; j < vers->vs_nproc; j++, proc++) |
Max Kellermann | 49e31cb | 2005-09-06 15:18:03 -0700 | [diff] [blame] | 105 | seq_printf(seq, " %u", proc->pc_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | seq_putc(seq, '\n'); |
| 107 | } |
| 108 | } |
Trond Myklebust | 24c3767 | 2008-12-23 16:30:12 -0500 | [diff] [blame] | 109 | EXPORT_SYMBOL_GPL(svc_seq_show); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 111 | /** |
| 112 | * rpc_alloc_iostats - allocate an rpc_iostats structure |
| 113 | * @clnt: RPC program, version, and xprt |
| 114 | * |
| 115 | */ |
| 116 | struct rpc_iostats *rpc_alloc_iostats(struct rpc_clnt *clnt) |
| 117 | { |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 118 | struct rpc_iostats *new; |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 119 | new = kcalloc(clnt->cl_maxproc, sizeof(struct rpc_iostats), GFP_KERNEL); |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 120 | return new; |
| 121 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 122 | EXPORT_SYMBOL_GPL(rpc_alloc_iostats); |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * rpc_free_iostats - release an rpc_iostats structure |
| 126 | * @stats: doomed rpc_iostats structure |
| 127 | * |
| 128 | */ |
| 129 | void rpc_free_iostats(struct rpc_iostats *stats) |
| 130 | { |
| 131 | kfree(stats); |
| 132 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 133 | EXPORT_SYMBOL_GPL(rpc_free_iostats); |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * rpc_count_iostats - tally up per-task stats |
| 137 | * @task: completed rpc_task |
| 138 | * |
| 139 | * Relies on the caller for serialization. |
| 140 | */ |
| 141 | void rpc_count_iostats(struct rpc_task *task) |
| 142 | { |
| 143 | struct rpc_rqst *req = task->tk_rqstp; |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 144 | struct rpc_iostats *stats; |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 145 | struct rpc_iostats *op_metrics; |
| 146 | long rtt, execute, queue; |
| 147 | |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 148 | if (!task->tk_client || !task->tk_client->cl_metrics || !req) |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 149 | return; |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 150 | |
| 151 | stats = task->tk_client->cl_metrics; |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 152 | op_metrics = &stats[task->tk_msg.rpc_proc->p_statidx]; |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 153 | |
| 154 | op_metrics->om_ops++; |
| 155 | op_metrics->om_ntrans += req->rq_ntrans; |
| 156 | op_metrics->om_timeouts += task->tk_timeouts; |
| 157 | |
| 158 | op_metrics->om_bytes_sent += task->tk_bytes_sent; |
Ricardo Labiaga | dd2b63d | 2009-04-01 09:23:28 -0400 | [diff] [blame^] | 159 | op_metrics->om_bytes_recv += req->rq_reply_bytes_recvd; |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 160 | |
| 161 | queue = (long)req->rq_xtime - task->tk_start; |
| 162 | if (queue < 0) |
| 163 | queue = -queue; |
| 164 | op_metrics->om_queue += queue; |
| 165 | |
| 166 | rtt = task->tk_rtt; |
| 167 | if (rtt < 0) |
| 168 | rtt = -rtt; |
| 169 | op_metrics->om_rtt += rtt; |
| 170 | |
| 171 | execute = (long)jiffies - task->tk_start; |
| 172 | if (execute < 0) |
| 173 | execute = -execute; |
| 174 | op_metrics->om_execute += execute; |
| 175 | } |
| 176 | |
Adrian Bunk | ec535ce | 2006-04-18 13:21:50 -0400 | [diff] [blame] | 177 | static void _print_name(struct seq_file *seq, unsigned int op, |
| 178 | struct rpc_procinfo *procs) |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 179 | { |
| 180 | if (procs[op].p_name) |
| 181 | seq_printf(seq, "\t%12s: ", procs[op].p_name); |
| 182 | else if (op == 0) |
| 183 | seq_printf(seq, "\t NULL: "); |
| 184 | else |
| 185 | seq_printf(seq, "\t%12u: ", op); |
| 186 | } |
| 187 | |
Chuck Lever | 5eb53f4 | 2006-03-20 13:44:42 -0500 | [diff] [blame] | 188 | #define MILLISECS_PER_JIFFY (1000 / HZ) |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 189 | |
| 190 | void rpc_print_iostats(struct seq_file *seq, struct rpc_clnt *clnt) |
| 191 | { |
| 192 | struct rpc_iostats *stats = clnt->cl_metrics; |
| 193 | struct rpc_xprt *xprt = clnt->cl_xprt; |
| 194 | unsigned int op, maxproc = clnt->cl_maxproc; |
| 195 | |
| 196 | if (!stats) |
| 197 | return; |
| 198 | |
| 199 | seq_printf(seq, "\tRPC iostats version: %s ", RPC_IOSTATS_VERS); |
| 200 | seq_printf(seq, "p/v: %u/%u (%s)\n", |
| 201 | clnt->cl_prog, clnt->cl_vers, clnt->cl_protname); |
| 202 | |
| 203 | if (xprt) |
| 204 | xprt->ops->print_stats(xprt, seq); |
| 205 | |
| 206 | seq_printf(seq, "\tper-op statistics\n"); |
| 207 | for (op = 0; op < maxproc; op++) { |
| 208 | struct rpc_iostats *metrics = &stats[op]; |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 209 | _print_name(seq, op, clnt->cl_procinfo); |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 210 | seq_printf(seq, "%lu %lu %lu %Lu %Lu %Lu %Lu %Lu\n", |
| 211 | metrics->om_ops, |
| 212 | metrics->om_ntrans, |
| 213 | metrics->om_timeouts, |
| 214 | metrics->om_bytes_sent, |
| 215 | metrics->om_bytes_recv, |
| 216 | metrics->om_queue * MILLISECS_PER_JIFFY, |
| 217 | metrics->om_rtt * MILLISECS_PER_JIFFY, |
| 218 | metrics->om_execute * MILLISECS_PER_JIFFY); |
| 219 | } |
| 220 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 221 | EXPORT_SYMBOL_GPL(rpc_print_iostats); |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | /* |
| 224 | * Register/unregister RPC proc files |
| 225 | */ |
| 226 | static inline struct proc_dir_entry * |
Arjan van de Ven | 99ac48f | 2006-03-28 01:56:41 -0800 | [diff] [blame] | 227 | do_register(const char *name, void *data, const struct file_operations *fops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | rpc_proc_init(); |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 230 | dprintk("RPC: registering /proc/net/rpc/%s\n", name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Denis V. Lunev | e7fe233 | 2008-05-02 02:44:36 -0700 | [diff] [blame] | 232 | return proc_create_data(name, 0, proc_net_rpc, fops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | struct proc_dir_entry * |
| 236 | rpc_proc_register(struct rpc_stat *statp) |
| 237 | { |
| 238 | return do_register(statp->program->name, statp, &rpc_proc_fops); |
| 239 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 240 | EXPORT_SYMBOL_GPL(rpc_proc_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | void |
| 243 | rpc_proc_unregister(const char *name) |
| 244 | { |
| 245 | remove_proc_entry(name, proc_net_rpc); |
| 246 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 247 | EXPORT_SYMBOL_GPL(rpc_proc_unregister); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | struct proc_dir_entry * |
Arjan van de Ven | 99ac48f | 2006-03-28 01:56:41 -0800 | [diff] [blame] | 250 | svc_proc_register(struct svc_stat *statp, const struct file_operations *fops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
| 252 | return do_register(statp->program->pg_name, statp, fops); |
| 253 | } |
Trond Myklebust | 24c3767 | 2008-12-23 16:30:12 -0500 | [diff] [blame] | 254 | EXPORT_SYMBOL_GPL(svc_proc_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | void |
| 257 | svc_proc_unregister(const char *name) |
| 258 | { |
| 259 | remove_proc_entry(name, proc_net_rpc); |
| 260 | } |
Trond Myklebust | 24c3767 | 2008-12-23 16:30:12 -0500 | [diff] [blame] | 261 | EXPORT_SYMBOL_GPL(svc_proc_unregister); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
| 263 | void |
| 264 | rpc_proc_init(void) |
| 265 | { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 266 | dprintk("RPC: registering /proc/net/rpc\n"); |
Alexey Dobriyan | 99b7623 | 2009-03-25 22:48:06 +0300 | [diff] [blame] | 267 | if (!proc_net_rpc) |
| 268 | proc_net_rpc = proc_mkdir("rpc", init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | void |
| 272 | rpc_proc_exit(void) |
| 273 | { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 274 | dprintk("RPC: unregistering /proc/net/rpc\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | if (proc_net_rpc) { |
| 276 | proc_net_rpc = NULL; |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 277 | remove_proc_entry("rpc", init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |