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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * procfs-based user access to knfsd statistics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * /proc/net/rpc/nfsd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Format:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	rc <hits> <misses> <nocache>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *			Statistsics for the reply cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *	fh <stale> <total-lookups> <anonlookups> <dir-not-in-dcache> <nondir-not-in-dcache>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *			statistics for filehandle lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *	io <bytes-read> <bytes-written>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *			statistics for IO throughput
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *	th <threads> <fullcnt> <10%-20%> <20%-30%> ... <90%-100%> <100%> 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *			time (seconds) when nfsd thread usage above thresholds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *			and number of times that all threads were in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *	ra cache-size  <10%  <20%  <30% ... <100% not-found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *			number of times that read-ahead entry was found that deep in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *			the cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *	plus generic RPC stats (see net/sunrpc/stats.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/sunrpc/stats.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "nfsd.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) struct nfsd_stats	nfsdstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) struct svc_stat		nfsd_svcstats = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	.program	= &nfsd_program,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static int nfsd_proc_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	seq_printf(seq, "rc %u %u %u\nfh %u %u %u %u %u\nio %u %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		      nfsdstats.rchits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		      nfsdstats.rcmisses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		      nfsdstats.rcnocache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		      nfsdstats.fh_stale,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		      nfsdstats.fh_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		      nfsdstats.fh_anon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		      nfsdstats.fh_nocache_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		      nfsdstats.fh_nocache_nondir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		      nfsdstats.io_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		      nfsdstats.io_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	/* thread usage: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	seq_printf(seq, "th %u %u", nfsdstats.th_cnt, nfsdstats.th_fullcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	for (i=0; i<10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		unsigned int jifs = nfsdstats.th_usage[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		unsigned int sec = jifs / HZ, msec = (jifs % HZ)*1000/HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		seq_printf(seq, " %u.%03u", sec, msec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	/* newline and ra-cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	seq_printf(seq, "\nra %u", nfsdstats.ra_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	for (i=0; i<11; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		seq_printf(seq, " %u", nfsdstats.ra_depth[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	seq_putc(seq, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/* show my rpc info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	svc_seq_show(seq, &nfsd_svcstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #ifdef CONFIG_NFSD_V4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	/* Show count for individual nfsv4 operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	/* Writing operation numbers 0 1 2 also for maintaining uniformity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	seq_printf(seq,"proc4ops %u", LAST_NFS4_OP + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	for (i = 0; i <= LAST_NFS4_OP; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		seq_printf(seq, " %u", nfsdstats.nfs4_opcount[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	seq_putc(seq, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static int nfsd_proc_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	return single_open(file, nfsd_proc_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static const struct proc_ops nfsd_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	.proc_open	= nfsd_proc_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	.proc_read	= seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	.proc_lseek	= seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	.proc_release	= single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) nfsd_stat_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	svc_proc_register(&init_net, &nfsd_svcstats, &nfsd_proc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) nfsd_stat_shutdown(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	svc_proc_unregister(&init_net, "nfsd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }