stats.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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> <deprecated filehandle cache stats>
  11. * statistics for filehandle lookup
  12. * io <bytes-read> <bytes-written>
  13. * statistics for IO throughput
  14. * th <threads> <deprecated thread usage histogram stats>
  15. * number of threads
  16. * ra <deprecated ra-cache stats>
  17. *
  18. * plus generic RPC stats (see net/sunrpc/stats.c)
  19. *
  20. * Copyright (C) 1995, 1996, 1997 Olaf Kirch <[email protected]>
  21. */
  22. #include <linux/seq_file.h>
  23. #include <linux/module.h>
  24. #include <linux/sunrpc/stats.h>
  25. #include <net/net_namespace.h>
  26. #include "nfsd.h"
  27. struct nfsd_stats nfsdstats;
  28. struct svc_stat nfsd_svcstats = {
  29. .program = &nfsd_program,
  30. };
  31. static int nfsd_show(struct seq_file *seq, void *v)
  32. {
  33. int i;
  34. seq_printf(seq, "rc %lld %lld %lld\nfh %lld 0 0 0 0\nio %lld %lld\n",
  35. percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_RC_HITS]),
  36. percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_RC_MISSES]),
  37. percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_RC_NOCACHE]),
  38. percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_FH_STALE]),
  39. percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_IO_READ]),
  40. percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_IO_WRITE]));
  41. /* thread usage: */
  42. seq_printf(seq, "th %u 0", atomic_read(&nfsdstats.th_cnt));
  43. /* deprecated thread usage histogram stats */
  44. for (i = 0; i < 10; i++)
  45. seq_puts(seq, " 0.000");
  46. /* deprecated ra-cache stats */
  47. seq_puts(seq, "\nra 0 0 0 0 0 0 0 0 0 0 0 0\n");
  48. /* show my rpc info */
  49. svc_seq_show(seq, &nfsd_svcstats);
  50. #ifdef CONFIG_NFSD_V4
  51. /* Show count for individual nfsv4 operations */
  52. /* Writing operation numbers 0 1 2 also for maintaining uniformity */
  53. seq_printf(seq,"proc4ops %u", LAST_NFS4_OP + 1);
  54. for (i = 0; i <= LAST_NFS4_OP; i++) {
  55. seq_printf(seq, " %lld",
  56. percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_NFS4_OP(i)]));
  57. }
  58. seq_putc(seq, '\n');
  59. #endif
  60. return 0;
  61. }
  62. DEFINE_PROC_SHOW_ATTRIBUTE(nfsd);
  63. int nfsd_percpu_counters_init(struct percpu_counter counters[], int num)
  64. {
  65. int i, err = 0;
  66. for (i = 0; !err && i < num; i++)
  67. err = percpu_counter_init(&counters[i], 0, GFP_KERNEL);
  68. if (!err)
  69. return 0;
  70. for (; i > 0; i--)
  71. percpu_counter_destroy(&counters[i-1]);
  72. return err;
  73. }
  74. void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num)
  75. {
  76. int i;
  77. for (i = 0; i < num; i++)
  78. percpu_counter_set(&counters[i], 0);
  79. }
  80. void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num)
  81. {
  82. int i;
  83. for (i = 0; i < num; i++)
  84. percpu_counter_destroy(&counters[i]);
  85. }
  86. static int nfsd_stat_counters_init(void)
  87. {
  88. return nfsd_percpu_counters_init(nfsdstats.counter, NFSD_STATS_COUNTERS_NUM);
  89. }
  90. static void nfsd_stat_counters_destroy(void)
  91. {
  92. nfsd_percpu_counters_destroy(nfsdstats.counter, NFSD_STATS_COUNTERS_NUM);
  93. }
  94. int nfsd_stat_init(void)
  95. {
  96. int err;
  97. err = nfsd_stat_counters_init();
  98. if (err)
  99. return err;
  100. svc_proc_register(&init_net, &nfsd_svcstats, &nfsd_proc_ops);
  101. return 0;
  102. }
  103. void nfsd_stat_shutdown(void)
  104. {
  105. nfsd_stat_counters_destroy();
  106. svc_proc_unregister(&init_net, "nfsd");
  107. }