stats.c 2.7 KB

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