Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * linux/net/sunrpc/stats.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * procfs-based user access to generic RPC statistics. The stats files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * reside in /proc/net/rpc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * The read routines assume that the buffer passed in is just big enough.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * If you implement an RPC service that has its own stats routine which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * appends the generic RPC stats, make sure you don't exceed the PAGE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * limit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/sunrpc/svcsock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/sunrpc/metrics.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <trace/events/sunrpc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "netns.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define RPCDBG_FACILITY	RPCDBG_MISC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * Get RPC client stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static int rpc_proc_show(struct seq_file *seq, void *v) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	const struct rpc_stat	*statp = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	const struct rpc_program *prog = statp->program;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		"net %u %u %u %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			statp->netcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			statp->netudpcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			statp->nettcpcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			statp->nettcpconn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		"rpc %u %u %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			statp->rpccnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			statp->rpcretrans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			statp->rpcauthrefresh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	for (i = 0; i < prog->nrvers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		const struct rpc_version *vers = prog->version[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		if (!vers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		seq_printf(seq, "proc%u %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 					vers->number, vers->nrprocs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		for (j = 0; j < vers->nrprocs; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			seq_printf(seq, " %u", vers->counts[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		seq_putc(seq, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static int rpc_proc_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	return single_open(file, rpc_proc_show, PDE_DATA(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static const struct proc_ops rpc_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	.proc_open	= rpc_proc_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.proc_read	= seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.proc_lseek	= seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.proc_release	= single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * Get RPC server stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) void svc_seq_show(struct seq_file *seq, const struct svc_stat *statp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	const struct svc_program *prog = statp->program;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	const struct svc_version *vers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		"net %u %u %u %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			statp->netcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			statp->netudpcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			statp->nettcpcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			statp->nettcpconn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		"rpc %u %u %u %u %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			statp->rpccnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			statp->rpcbadfmt+statp->rpcbadauth+statp->rpcbadclnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			statp->rpcbadfmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			statp->rpcbadauth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			statp->rpcbadclnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	for (i = 0; i < prog->pg_nvers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		vers = prog->pg_vers[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		if (!vers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		seq_printf(seq, "proc%d %u", i, vers->vs_nproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		for (j = 0; j < vers->vs_nproc; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			seq_printf(seq, " %u", vers->vs_count[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		seq_putc(seq, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) EXPORT_SYMBOL_GPL(svc_seq_show);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * rpc_alloc_iostats - allocate an rpc_iostats structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * @clnt: RPC program, version, and xprt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct rpc_iostats *rpc_alloc_iostats(struct rpc_clnt *clnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct rpc_iostats *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	stats = kcalloc(clnt->cl_maxproc, sizeof(*stats), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (stats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		for (i = 0; i < clnt->cl_maxproc; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			spin_lock_init(&stats[i].om_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	return stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) EXPORT_SYMBOL_GPL(rpc_alloc_iostats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * rpc_free_iostats - release an rpc_iostats structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * @stats: doomed rpc_iostats structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) void rpc_free_iostats(struct rpc_iostats *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	kfree(stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) EXPORT_SYMBOL_GPL(rpc_free_iostats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * rpc_count_iostats_metrics - tally up per-task stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * @task: completed rpc_task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * @op_metrics: stat structure for OP that will accumulate stats from @task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) void rpc_count_iostats_metrics(const struct rpc_task *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			       struct rpc_iostats *op_metrics)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct rpc_rqst *req = task->tk_rqstp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	ktime_t backlog, execute, now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (!op_metrics || !req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	now = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	spin_lock(&op_metrics->om_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	op_metrics->om_ops++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* kernel API: om_ops must never become larger than om_ntrans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	op_metrics->om_ntrans += max(req->rq_ntrans, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	op_metrics->om_timeouts += task->tk_timeouts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	op_metrics->om_bytes_sent += req->rq_xmit_bytes_sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	op_metrics->om_bytes_recv += req->rq_reply_bytes_recvd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	backlog = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (ktime_to_ns(req->rq_xtime)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		backlog = ktime_sub(req->rq_xtime, task->tk_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		op_metrics->om_queue = ktime_add(op_metrics->om_queue, backlog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	op_metrics->om_rtt = ktime_add(op_metrics->om_rtt, req->rq_rtt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	execute = ktime_sub(now, task->tk_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	op_metrics->om_execute = ktime_add(op_metrics->om_execute, execute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (task->tk_status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		op_metrics->om_error_status++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	spin_unlock(&op_metrics->om_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	trace_rpc_stats_latency(req->rq_task, backlog, req->rq_rtt, execute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) EXPORT_SYMBOL_GPL(rpc_count_iostats_metrics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  * rpc_count_iostats - tally up per-task stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * @task: completed rpc_task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * @stats: array of stat structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * Uses the statidx from @task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) void rpc_count_iostats(const struct rpc_task *task, struct rpc_iostats *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	rpc_count_iostats_metrics(task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				  &stats[task->tk_msg.rpc_proc->p_statidx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) EXPORT_SYMBOL_GPL(rpc_count_iostats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static void _print_name(struct seq_file *seq, unsigned int op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			const struct rpc_procinfo *procs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (procs[op].p_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		seq_printf(seq, "\t%12s: ", procs[op].p_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	else if (op == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		seq_printf(seq, "\t        NULL: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		seq_printf(seq, "\t%12u: ", op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static void _add_rpc_iostats(struct rpc_iostats *a, struct rpc_iostats *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	a->om_ops += b->om_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	a->om_ntrans += b->om_ntrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	a->om_timeouts += b->om_timeouts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	a->om_bytes_sent += b->om_bytes_sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	a->om_bytes_recv += b->om_bytes_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	a->om_queue = ktime_add(a->om_queue, b->om_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	a->om_rtt = ktime_add(a->om_rtt, b->om_rtt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	a->om_execute = ktime_add(a->om_execute, b->om_execute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	a->om_error_status += b->om_error_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static void _print_rpc_iostats(struct seq_file *seq, struct rpc_iostats *stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			       int op, const struct rpc_procinfo *procs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	_print_name(seq, op, procs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	seq_printf(seq, "%lu %lu %lu %llu %llu %llu %llu %llu %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		   stats->om_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		   stats->om_ntrans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		   stats->om_timeouts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		   stats->om_bytes_sent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		   stats->om_bytes_recv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		   ktime_to_ms(stats->om_queue),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		   ktime_to_ms(stats->om_rtt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		   ktime_to_ms(stats->om_execute),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		   stats->om_error_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int do_print_stats(struct rpc_clnt *clnt, struct rpc_xprt *xprt, void *seqv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct seq_file *seq = seqv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	xprt->ops->print_stats(xprt, seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) void rpc_clnt_show_stats(struct seq_file *seq, struct rpc_clnt *clnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	unsigned int op, maxproc = clnt->cl_maxproc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (!clnt->cl_metrics)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	seq_printf(seq, "\tRPC iostats version: %s  ", RPC_IOSTATS_VERS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	seq_printf(seq, "p/v: %u/%u (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			clnt->cl_prog, clnt->cl_vers, clnt->cl_program->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	rpc_clnt_iterate_for_each_xprt(clnt, do_print_stats, seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	seq_printf(seq, "\tper-op statistics\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	for (op = 0; op < maxproc; op++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		struct rpc_iostats stats = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		struct rpc_clnt *next = clnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			_add_rpc_iostats(&stats, &next->cl_metrics[op]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			if (next == next->cl_parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			next = next->cl_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		} while (next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		_print_rpc_iostats(seq, &stats, op, clnt->cl_procinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) EXPORT_SYMBOL_GPL(rpc_clnt_show_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  * Register/unregister RPC proc files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static inline struct proc_dir_entry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) do_register(struct net *net, const char *name, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	    const struct proc_ops *proc_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct sunrpc_net *sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	dprintk("RPC:       registering /proc/net/rpc/%s\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	return proc_create_data(name, 0, sn->proc_net_rpc, proc_ops, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct proc_dir_entry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) rpc_proc_register(struct net *net, struct rpc_stat *statp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	return do_register(net, statp->program->name, statp, &rpc_proc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) EXPORT_SYMBOL_GPL(rpc_proc_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) rpc_proc_unregister(struct net *net, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct sunrpc_net *sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	remove_proc_entry(name, sn->proc_net_rpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) EXPORT_SYMBOL_GPL(rpc_proc_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct proc_dir_entry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) svc_proc_register(struct net *net, struct svc_stat *statp, const struct proc_ops *proc_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	return do_register(net, statp->program->pg_name, statp, proc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) EXPORT_SYMBOL_GPL(svc_proc_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) svc_proc_unregister(struct net *net, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	struct sunrpc_net *sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	remove_proc_entry(name, sn->proc_net_rpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) EXPORT_SYMBOL_GPL(svc_proc_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) int rpc_proc_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	struct sunrpc_net *sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	dprintk("RPC:       registering /proc/net/rpc\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	if (sn->proc_net_rpc == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) void rpc_proc_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	dprintk("RPC:       unregistering /proc/net/rpc\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	remove_proc_entry("rpc", net->proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }