diff mbox series

[net-next,v4,11/11] page_pool: Add function to batch and return stats

Message ID 1643933373-6590-12-git-send-email-jdamato@fastly.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series page_pool: Add page_pool stat counters | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5979 this patch: 5979
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 879 this patch: 879
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 6130 this patch: 6130
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 46 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Joe Damato Feb. 4, 2022, 12:09 a.m. UTC
Adds a function page_pool_get_stats which can be used by drivers to obtain
the batched stats for a specified page pool.

Signed-off-by: Joe Damato <jdamato@fastly.com>
---
 include/net/page_pool.h |  9 +++++++++
 net/core/page_pool.c    | 25 +++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

Comments

Ilias Apalodimas Feb. 4, 2022, 7:46 a.m. UTC | #1
On Thu, Feb 03, 2022 at 04:09:33PM -0800, Joe Damato wrote:
> Adds a function page_pool_get_stats which can be used by drivers to obtain
> the batched stats for a specified page pool.
> 
> Signed-off-by: Joe Damato <jdamato@fastly.com>
> ---
>  include/net/page_pool.h |  9 +++++++++
>  net/core/page_pool.c    | 25 +++++++++++++++++++++++++
>  2 files changed, 34 insertions(+)
> 
> diff --git a/include/net/page_pool.h b/include/net/page_pool.h
> index bb87706..5257e46 100644
> --- a/include/net/page_pool.h
> +++ b/include/net/page_pool.h
> @@ -153,6 +153,15 @@ struct page_pool_stats {
>  		u64 waive;  /* failed refills due to numa zone mismatch */
>  	} alloc;
>  };
> +
> +/*
> + * Drivers that wish to harvest page pool stats and report them to users
> + * (perhaps via ethtool, debugfs, or another mechanism) can allocate a
> + * struct page_pool_stats and call page_pool_get_stats to get the batched pcpu
> + * stats.
> + */
> +struct page_pool_stats *page_pool_get_stats(struct page_pool *pool,
> +					    struct page_pool_stats *stats);
>  #endif
>  
>  struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp);
> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> index 0bd084c..076593bb 100644
> --- a/net/core/page_pool.c
> +++ b/net/core/page_pool.c
> @@ -35,6 +35,31 @@
>  		struct page_pool_stats __percpu *s = pool->stats;	\
>  		__this_cpu_inc(s->alloc.__stat);			\
>  	} while (0)
> +
> +struct page_pool_stats *page_pool_get_stats(struct page_pool *pool,
> +					    struct page_pool_stats *stats)
> +{
> +	int cpu = 0;
> +
> +	if (!stats)
> +		return NULL;
> +
> +	for_each_possible_cpu(cpu) {
> +		const struct page_pool_stats *pcpu =
> +			per_cpu_ptr(pool->stats, cpu);
> +
> +		stats->alloc.fast += pcpu->alloc.fast;
> +		stats->alloc.slow += pcpu->alloc.slow;
> +		stats->alloc.slow_high_order +=
> +			pcpu->alloc.slow_high_order;
> +		stats->alloc.empty += pcpu->alloc.empty;
> +		stats->alloc.refill += pcpu->alloc.refill;
> +		stats->alloc.waive += pcpu->alloc.waive;
> +	}
> +
> +	return stats;
> +}
> +EXPORT_SYMBOL(page_pool_get_stats);

You don't really need to return a pointer here. Just make the return code a
bool 

Regards
/Ilias
>  #else
>  #define this_cpu_inc_alloc_stat(pool, __stat)
>  #endif
> -- 
> 2.7.4
>
Joe Damato Feb. 4, 2022, 6 p.m. UTC | #2
On Thu, Feb 3, 2022 at 11:46 PM Ilias Apalodimas
<ilias.apalodimas@linaro.org> wrote:
>
> On Thu, Feb 03, 2022 at 04:09:33PM -0800, Joe Damato wrote:
> > Adds a function page_pool_get_stats which can be used by drivers to obtain
> > the batched stats for a specified page pool.
> >
> > Signed-off-by: Joe Damato <jdamato@fastly.com>
> > ---
> >  include/net/page_pool.h |  9 +++++++++
> >  net/core/page_pool.c    | 25 +++++++++++++++++++++++++
> >  2 files changed, 34 insertions(+)
> >
> > diff --git a/include/net/page_pool.h b/include/net/page_pool.h
> > index bb87706..5257e46 100644
> > --- a/include/net/page_pool.h
> > +++ b/include/net/page_pool.h
> > @@ -153,6 +153,15 @@ struct page_pool_stats {
> >               u64 waive;  /* failed refills due to numa zone mismatch */
> >       } alloc;
> >  };
> > +
> > +/*
> > + * Drivers that wish to harvest page pool stats and report them to users
> > + * (perhaps via ethtool, debugfs, or another mechanism) can allocate a
> > + * struct page_pool_stats and call page_pool_get_stats to get the batched pcpu
> > + * stats.
> > + */
> > +struct page_pool_stats *page_pool_get_stats(struct page_pool *pool,
> > +                                         struct page_pool_stats *stats);
> >  #endif
> >
> >  struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp);
> > diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> > index 0bd084c..076593bb 100644
> > --- a/net/core/page_pool.c
> > +++ b/net/core/page_pool.c
> > @@ -35,6 +35,31 @@
> >               struct page_pool_stats __percpu *s = pool->stats;       \
> >               __this_cpu_inc(s->alloc.__stat);                        \
> >       } while (0)
> > +
> > +struct page_pool_stats *page_pool_get_stats(struct page_pool *pool,
> > +                                         struct page_pool_stats *stats)
> > +{
> > +     int cpu = 0;
> > +
> > +     if (!stats)
> > +             return NULL;
> > +
> > +     for_each_possible_cpu(cpu) {
> > +             const struct page_pool_stats *pcpu =
> > +                     per_cpu_ptr(pool->stats, cpu);
> > +
> > +             stats->alloc.fast += pcpu->alloc.fast;
> > +             stats->alloc.slow += pcpu->alloc.slow;
> > +             stats->alloc.slow_high_order +=
> > +                     pcpu->alloc.slow_high_order;
> > +             stats->alloc.empty += pcpu->alloc.empty;
> > +             stats->alloc.refill += pcpu->alloc.refill;
> > +             stats->alloc.waive += pcpu->alloc.waive;
> > +     }
> > +
> > +     return stats;
> > +}
> > +EXPORT_SYMBOL(page_pool_get_stats);
>
> You don't really need to return a pointer here. Just make the return code a
> bool

OK. Updated page_pool_get_stats to return a bool in my v5 branch.
diff mbox series

Patch

diff --git a/include/net/page_pool.h b/include/net/page_pool.h
index bb87706..5257e46 100644
--- a/include/net/page_pool.h
+++ b/include/net/page_pool.h
@@ -153,6 +153,15 @@  struct page_pool_stats {
 		u64 waive;  /* failed refills due to numa zone mismatch */
 	} alloc;
 };
+
+/*
+ * Drivers that wish to harvest page pool stats and report them to users
+ * (perhaps via ethtool, debugfs, or another mechanism) can allocate a
+ * struct page_pool_stats and call page_pool_get_stats to get the batched pcpu
+ * stats.
+ */
+struct page_pool_stats *page_pool_get_stats(struct page_pool *pool,
+					    struct page_pool_stats *stats);
 #endif
 
 struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp);
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 0bd084c..076593bb 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -35,6 +35,31 @@ 
 		struct page_pool_stats __percpu *s = pool->stats;	\
 		__this_cpu_inc(s->alloc.__stat);			\
 	} while (0)
+
+struct page_pool_stats *page_pool_get_stats(struct page_pool *pool,
+					    struct page_pool_stats *stats)
+{
+	int cpu = 0;
+
+	if (!stats)
+		return NULL;
+
+	for_each_possible_cpu(cpu) {
+		const struct page_pool_stats *pcpu =
+			per_cpu_ptr(pool->stats, cpu);
+
+		stats->alloc.fast += pcpu->alloc.fast;
+		stats->alloc.slow += pcpu->alloc.slow;
+		stats->alloc.slow_high_order +=
+			pcpu->alloc.slow_high_order;
+		stats->alloc.empty += pcpu->alloc.empty;
+		stats->alloc.refill += pcpu->alloc.refill;
+		stats->alloc.waive += pcpu->alloc.waive;
+	}
+
+	return stats;
+}
+EXPORT_SYMBOL(page_pool_get_stats);
 #else
 #define this_cpu_inc_alloc_stat(pool, __stat)
 #endif