604-v5.19-net-page_pool-introduce-ethtool-stats.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. From f3c5264f452a5b0ac1de1f2f657efbabdea3c76a Mon Sep 17 00:00:00 2001
  2. From: Lorenzo Bianconi <[email protected]>
  3. Date: Tue, 12 Apr 2022 18:31:58 +0200
  4. Subject: [PATCH] net: page_pool: introduce ethtool stats
  5. Introduce page_pool APIs to report stats through ethtool and reduce
  6. duplicated code in each driver.
  7. Signed-off-by: Lorenzo Bianconi <[email protected]>
  8. Reviewed-by: Jakub Kicinski <[email protected]>
  9. Reviewed-by: Ilias Apalodimas <[email protected]>
  10. Signed-off-by: David S. Miller <[email protected]>
  11. ---
  12. include/net/page_pool.h | 21 ++++++++++++++
  13. net/core/page_pool.c | 63 ++++++++++++++++++++++++++++++++++++++++-
  14. 2 files changed, 83 insertions(+), 1 deletion(-)
  15. --- a/include/net/page_pool.h
  16. +++ b/include/net/page_pool.h
  17. @@ -115,6 +115,10 @@ struct page_pool_stats {
  18. struct page_pool_recycle_stats recycle_stats;
  19. };
  20. +int page_pool_ethtool_stats_get_count(void);
  21. +u8 *page_pool_ethtool_stats_get_strings(u8 *data);
  22. +u64 *page_pool_ethtool_stats_get(u64 *data, void *stats);
  23. +
  24. /*
  25. * Drivers that wish to harvest page pool stats and report them to users
  26. * (perhaps via ethtool, debugfs, or another mechanism) can allocate a
  27. @@ -122,6 +126,23 @@ struct page_pool_stats {
  28. */
  29. bool page_pool_get_stats(struct page_pool *pool,
  30. struct page_pool_stats *stats);
  31. +#else
  32. +
  33. +static inline int page_pool_ethtool_stats_get_count(void)
  34. +{
  35. + return 0;
  36. +}
  37. +
  38. +static inline u8 *page_pool_ethtool_stats_get_strings(u8 *data)
  39. +{
  40. + return data;
  41. +}
  42. +
  43. +static inline u64 *page_pool_ethtool_stats_get(u64 *data, void *stats)
  44. +{
  45. + return data;
  46. +}
  47. +
  48. #endif
  49. struct page_pool {
  50. --- a/net/core/page_pool.c
  51. +++ b/net/core/page_pool.c
  52. @@ -18,6 +18,7 @@
  53. #include <linux/page-flags.h>
  54. #include <linux/mm.h> /* for __put_page() */
  55. #include <linux/poison.h>
  56. +#include <linux/ethtool.h>
  57. #include <trace/events/page_pool.h>
  58. @@ -42,6 +43,20 @@
  59. this_cpu_add(s->__stat, val); \
  60. } while (0)
  61. +static const char pp_stats[][ETH_GSTRING_LEN] = {
  62. + "rx_pp_alloc_fast",
  63. + "rx_pp_alloc_slow",
  64. + "rx_pp_alloc_slow_ho",
  65. + "rx_pp_alloc_empty",
  66. + "rx_pp_alloc_refill",
  67. + "rx_pp_alloc_waive",
  68. + "rx_pp_recycle_cached",
  69. + "rx_pp_recycle_cache_full",
  70. + "rx_pp_recycle_ring",
  71. + "rx_pp_recycle_ring_full",
  72. + "rx_pp_recycle_released_ref",
  73. +};
  74. +
  75. bool page_pool_get_stats(struct page_pool *pool,
  76. struct page_pool_stats *stats)
  77. {
  78. @@ -50,7 +65,13 @@ bool page_pool_get_stats(struct page_poo
  79. if (!stats)
  80. return false;
  81. - memcpy(&stats->alloc_stats, &pool->alloc_stats, sizeof(pool->alloc_stats));
  82. + /* The caller is responsible to initialize stats. */
  83. + stats->alloc_stats.fast += pool->alloc_stats.fast;
  84. + stats->alloc_stats.slow += pool->alloc_stats.slow;
  85. + stats->alloc_stats.slow_high_order += pool->alloc_stats.slow_high_order;
  86. + stats->alloc_stats.empty += pool->alloc_stats.empty;
  87. + stats->alloc_stats.refill += pool->alloc_stats.refill;
  88. + stats->alloc_stats.waive += pool->alloc_stats.waive;
  89. for_each_possible_cpu(cpu) {
  90. const struct page_pool_recycle_stats *pcpu =
  91. @@ -66,6 +87,46 @@ bool page_pool_get_stats(struct page_poo
  92. return true;
  93. }
  94. EXPORT_SYMBOL(page_pool_get_stats);
  95. +
  96. +u8 *page_pool_ethtool_stats_get_strings(u8 *data)
  97. +{
  98. + int i;
  99. +
  100. + for (i = 0; i < ARRAY_SIZE(pp_stats); i++) {
  101. + memcpy(data, pp_stats[i], ETH_GSTRING_LEN);
  102. + data += ETH_GSTRING_LEN;
  103. + }
  104. +
  105. + return data;
  106. +}
  107. +EXPORT_SYMBOL(page_pool_ethtool_stats_get_strings);
  108. +
  109. +int page_pool_ethtool_stats_get_count(void)
  110. +{
  111. + return ARRAY_SIZE(pp_stats);
  112. +}
  113. +EXPORT_SYMBOL(page_pool_ethtool_stats_get_count);
  114. +
  115. +u64 *page_pool_ethtool_stats_get(u64 *data, void *stats)
  116. +{
  117. + struct page_pool_stats *pool_stats = stats;
  118. +
  119. + *data++ = pool_stats->alloc_stats.fast;
  120. + *data++ = pool_stats->alloc_stats.slow;
  121. + *data++ = pool_stats->alloc_stats.slow_high_order;
  122. + *data++ = pool_stats->alloc_stats.empty;
  123. + *data++ = pool_stats->alloc_stats.refill;
  124. + *data++ = pool_stats->alloc_stats.waive;
  125. + *data++ = pool_stats->recycle_stats.cached;
  126. + *data++ = pool_stats->recycle_stats.cache_full;
  127. + *data++ = pool_stats->recycle_stats.ring;
  128. + *data++ = pool_stats->recycle_stats.ring_full;
  129. + *data++ = pool_stats->recycle_stats.released_refcnt;
  130. +
  131. + return data;
  132. +}
  133. +EXPORT_SYMBOL(page_pool_ethtool_stats_get);
  134. +
  135. #else
  136. #define alloc_stat_inc(pool, __stat)
  137. #define recycle_stat_inc(pool, __stat)