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
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/proc_fs.h>
20 #include <linux/seq_file.h>
21 #include <linux/sunrpc/clnt.h>
22 #include <linux/sunrpc/svcsock.h>
23 #include <linux/sunrpc/metrics.h>
24 #include <net/net_namespace.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
;
48 statp
->rpcauthrefresh
);
50 for (i
= 0; i
< prog
->nrvers
; i
++) {
51 const struct rpc_version
*vers
= prog
->version
[i
];
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
);
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 const struct file_operations rpc_proc_fops
= {
71 .open
= rpc_proc_open
,
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
;
93 "rpc %u %u %u %u %u\n",
95 statp
->rpcbadfmt
+statp
->rpcbadauth
+statp
->rpcbadclnt
,
100 for (i
= 0; i
< prog
->pg_nvers
; i
++) {
101 if (!(vers
= prog
->pg_vers
[i
]) || !(proc
= vers
->vs_proc
))
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
);
109 EXPORT_SYMBOL(svc_seq_show
);
112 * rpc_alloc_iostats - allocate an rpc_iostats structure
113 * @clnt: RPC program, version, and xprt
116 struct rpc_iostats
*rpc_alloc_iostats(struct rpc_clnt
*clnt
)
118 struct rpc_iostats
*new;
119 new = kcalloc(clnt
->cl_maxproc
, sizeof(struct rpc_iostats
), GFP_KERNEL
);
122 EXPORT_SYMBOL_GPL(rpc_alloc_iostats
);
125 * rpc_free_iostats - release an rpc_iostats structure
126 * @stats: doomed rpc_iostats structure
129 void rpc_free_iostats(struct rpc_iostats
*stats
)
133 EXPORT_SYMBOL_GPL(rpc_free_iostats
);
136 * rpc_count_iostats - tally up per-task stats
137 * @task: completed rpc_task
139 * Relies on the caller for serialization.
141 void rpc_count_iostats(struct rpc_task
*task
)
143 struct rpc_rqst
*req
= task
->tk_rqstp
;
144 struct rpc_iostats
*stats
= task
->tk_client
->cl_metrics
;
145 struct rpc_iostats
*op_metrics
;
146 long rtt
, execute
, queue
;
150 op_metrics
= &stats
[task
->tk_msg
.rpc_proc
->p_statidx
];
152 op_metrics
->om_ops
++;
153 op_metrics
->om_ntrans
+= req
->rq_ntrans
;
154 op_metrics
->om_timeouts
+= task
->tk_timeouts
;
156 op_metrics
->om_bytes_sent
+= task
->tk_bytes_sent
;
157 op_metrics
->om_bytes_recv
+= req
->rq_received
;
159 queue
= (long)req
->rq_xtime
- task
->tk_start
;
162 op_metrics
->om_queue
+= queue
;
167 op_metrics
->om_rtt
+= rtt
;
169 execute
= (long)jiffies
- task
->tk_start
;
172 op_metrics
->om_execute
+= execute
;
175 static void _print_name(struct seq_file
*seq
, unsigned int op
,
176 struct rpc_procinfo
*procs
)
178 if (procs
[op
].p_name
)
179 seq_printf(seq
, "\t%12s: ", procs
[op
].p_name
);
181 seq_printf(seq
, "\t NULL: ");
183 seq_printf(seq
, "\t%12u: ", op
);
186 #define MILLISECS_PER_JIFFY (1000 / HZ)
188 void rpc_print_iostats(struct seq_file
*seq
, struct rpc_clnt
*clnt
)
190 struct rpc_iostats
*stats
= clnt
->cl_metrics
;
191 struct rpc_xprt
*xprt
= clnt
->cl_xprt
;
192 unsigned int op
, maxproc
= clnt
->cl_maxproc
;
197 seq_printf(seq
, "\tRPC iostats version: %s ", RPC_IOSTATS_VERS
);
198 seq_printf(seq
, "p/v: %u/%u (%s)\n",
199 clnt
->cl_prog
, clnt
->cl_vers
, clnt
->cl_protname
);
202 xprt
->ops
->print_stats(xprt
, seq
);
204 seq_printf(seq
, "\tper-op statistics\n");
205 for (op
= 0; op
< maxproc
; op
++) {
206 struct rpc_iostats
*metrics
= &stats
[op
];
207 _print_name(seq
, op
, clnt
->cl_procinfo
);
208 seq_printf(seq
, "%lu %lu %lu %Lu %Lu %Lu %Lu %Lu\n",
211 metrics
->om_timeouts
,
212 metrics
->om_bytes_sent
,
213 metrics
->om_bytes_recv
,
214 metrics
->om_queue
* MILLISECS_PER_JIFFY
,
215 metrics
->om_rtt
* MILLISECS_PER_JIFFY
,
216 metrics
->om_execute
* MILLISECS_PER_JIFFY
);
219 EXPORT_SYMBOL_GPL(rpc_print_iostats
);
222 * Register/unregister RPC proc files
224 static inline struct proc_dir_entry
*
225 do_register(const char *name
, void *data
, const struct file_operations
*fops
)
227 struct proc_dir_entry
*ent
;
230 dprintk("RPC: registering /proc/net/rpc/%s\n", name
);
232 ent
= create_proc_entry(name
, 0, proc_net_rpc
);
234 ent
->proc_fops
= fops
;
240 struct proc_dir_entry
*
241 rpc_proc_register(struct rpc_stat
*statp
)
243 return do_register(statp
->program
->name
, statp
, &rpc_proc_fops
);
245 EXPORT_SYMBOL_GPL(rpc_proc_register
);
248 rpc_proc_unregister(const char *name
)
250 remove_proc_entry(name
, proc_net_rpc
);
252 EXPORT_SYMBOL_GPL(rpc_proc_unregister
);
254 struct proc_dir_entry
*
255 svc_proc_register(struct svc_stat
*statp
, const struct file_operations
*fops
)
257 return do_register(statp
->program
->pg_name
, statp
, fops
);
259 EXPORT_SYMBOL(svc_proc_register
);
262 svc_proc_unregister(const char *name
)
264 remove_proc_entry(name
, proc_net_rpc
);
266 EXPORT_SYMBOL(svc_proc_unregister
);
271 dprintk("RPC: registering /proc/net/rpc\n");
273 struct proc_dir_entry
*ent
;
274 ent
= proc_mkdir("rpc", init_net
.proc_net
);
276 ent
->owner
= THIS_MODULE
;
285 dprintk("RPC: unregistering /proc/net/rpc\n");
288 remove_proc_entry("rpc", init_net
.proc_net
);