Linux real-time development
 help / color / mirror / Atom feed
From: Yunsheng Lin <linyunsheng@huawei.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	<linux-rdma@vger.kernel.org>, <linux-rt-devel@lists.linux.dev>,
	<netdev@vger.kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Eric Dumazet <edumazet@google.com>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	Joe Damato <jdamato@fastly.com>,
	Leon Romanovsky <leon@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Simon Horman <horms@kernel.org>, Tariq Toukan <tariqt@nvidia.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH net-next v3 4/4] page_pool: Convert page_pool_alloc_stats to u64_stats_t.
Date: Tue, 8 Apr 2025 20:27:02 +0800	[thread overview]
Message-ID: <d012a523-816b-48af-91c0-4a11f85d592b@huawei.com> (raw)
In-Reply-To: <20250408105922.1135150-5-bigeasy@linutronix.de>

On 2025/4/8 18:59, Sebastian Andrzej Siewior wrote:
> Using u64 for statistics can lead to inconsistency on 32bit because an
> update and a read requires to access two 32bit values.
> This can be avoided by using u64_stats_t for the counters and
> u64_stats_sync for the required synchronisation on 32bit platforms. The
> synchronisation is a NOP on 64bit architectures.
> 
> Use u64_stats_t for the counters in page_pool_alloc_stats.

It seems a little overkill for page_pool_alloc_stats as there is only
one updater ensured by NAPI context, but I am not able to think of a better
way, so:
Reviewed-by: Yunsheng Lin <linyunsheng@huawei.com>

> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  include/net/page_pool/types.h | 14 ++++++-----
>  net/core/page_pool.c          | 47 +++++++++++++++++++++++++----------
>  net/core/page_pool_user.c     | 12 ++++-----
>  3 files changed, 48 insertions(+), 25 deletions(-)
> 
> diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h
> index 54c79a020b334..9406fa69232ee 100644
> --- a/include/net/page_pool/types.h
> +++ b/include/net/page_pool/types.h
> @@ -96,6 +96,7 @@ struct page_pool_params {
>  #ifdef CONFIG_PAGE_POOL_STATS
>  /**
>   * struct page_pool_alloc_stats - allocation statistics
> + * @syncp:	synchronisations point for updates.
>   * @fast:	successful fast path allocations
>   * @slow:	slow path order-0 allocations
>   * @slow_high_order: slow path high order allocations
> @@ -105,12 +106,13 @@ struct page_pool_params {
>   *		the cache due to a NUMA mismatch
>   */
>  struct page_pool_alloc_stats {
> -	u64 fast;
> -	u64 slow;
> -	u64 slow_high_order;
> -	u64 empty;
> -	u64 refill;
> -	u64 waive;
> +	struct u64_stats_sync syncp;
> +	u64_stats_t fast;
> +	u64_stats_t slow;
> +	u64_stats_t slow_high_order;
> +	u64_stats_t empty;
> +	u64_stats_t refill;
> +	u64_stats_t waive;
>  };
>  
>  /**
> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> index eb2f5b995022f..46e3c56b76692 100644
> --- a/net/core/page_pool.c
> +++ b/net/core/page_pool.c
> @@ -45,7 +45,14 @@ static DEFINE_PER_CPU(struct page_pool_recycle_stats, pp_system_recycle_stats) =
>  };
>  
>  /* alloc_stat_inc is intended to be used in softirq context */
> -#define alloc_stat_inc(pool, __stat)	(pool->alloc_stats.__stat++)
> +#define alloc_stat_inc(pool, __stat)						\
> +	do {									\
> +		struct page_pool_alloc_stats *s = &pool->alloc_stats;		\
> +		u64_stats_update_begin(&s->syncp);				\
> +		u64_stats_inc(&s->__stat);					\
> +		u64_stats_update_end(&s->syncp);				\
> +	} while (0)
> +
>  /* recycle_stat_inc is safe to use when preemption is possible. */
>  #define recycle_stat_inc(pool, __stat)							\
>  	do {										\
> @@ -91,19 +98,32 @@ static const char pp_stats[][ETH_GSTRING_LEN] = {
>  bool page_pool_get_stats(const struct page_pool *pool,
>  			 struct page_pool_stats *stats)
>  {
> +	u64 fast, slow, slow_high_order, empty, refill, waive;
> +	const struct page_pool_alloc_stats *alloc_stats;
>  	unsigned int start;
>  	int cpu = 0;
>  
>  	if (!stats)
>  		return false;
>  
> +	alloc_stats = &pool->alloc_stats;
>  	/* The caller is responsible to initialize stats. */
> -	stats->alloc_stats.fast += pool->alloc_stats.fast;
> -	stats->alloc_stats.slow += pool->alloc_stats.slow;
> -	stats->alloc_stats.slow_high_order += pool->alloc_stats.slow_high_order;
> -	stats->alloc_stats.empty += pool->alloc_stats.empty;
> -	stats->alloc_stats.refill += pool->alloc_stats.refill;
> -	stats->alloc_stats.waive += pool->alloc_stats.waive;
> +	do {
> +		start = u64_stats_fetch_begin(&alloc_stats->syncp);
> +		fast = u64_stats_read(&alloc_stats->fast);
> +		slow = u64_stats_read(&alloc_stats->slow);
> +		slow_high_order = u64_stats_read(&alloc_stats->slow_high_order);
> +		empty = u64_stats_read(&alloc_stats->empty);
> +		refill = u64_stats_read(&alloc_stats->refill);
> +		waive = u64_stats_read(&alloc_stats->waive);
> +	} while (u64_stats_fetch_retry(&alloc_stats->syncp, start));
> +
> +	u64_stats_add(&stats->alloc_stats.fast, fast);
> +	u64_stats_add(&stats->alloc_stats.slow, slow);
> +	u64_stats_add(&stats->alloc_stats.slow_high_order, slow_high_order);
> +	u64_stats_add(&stats->alloc_stats.empty, empty);
> +	u64_stats_add(&stats->alloc_stats.refill, refill);
> +	u64_stats_add(&stats->alloc_stats.waive, waive);
>  
>  	for_each_possible_cpu(cpu) {
>  		u64 cached, cache_full, ring, ring_full, released_refcnt;
> @@ -153,12 +173,12 @@ u64 *page_pool_ethtool_stats_get(u64 *data, const void *stats)
>  {
>  	const struct page_pool_stats *pool_stats = stats;
>  
> -	*data++ = pool_stats->alloc_stats.fast;
> -	*data++ = pool_stats->alloc_stats.slow;
> -	*data++ = pool_stats->alloc_stats.slow_high_order;
> -	*data++ = pool_stats->alloc_stats.empty;
> -	*data++ = pool_stats->alloc_stats.refill;
> -	*data++ = pool_stats->alloc_stats.waive;
> +	*data++ = u64_stats_read(&pool_stats->alloc_stats.fast);
> +	*data++ = u64_stats_read(&pool_stats->alloc_stats.slow);
> +	*data++ = u64_stats_read(&pool_stats->alloc_stats.slow_high_order);
> +	*data++ = u64_stats_read(&pool_stats->alloc_stats.empty);
> +	*data++ = u64_stats_read(&pool_stats->alloc_stats.refill);
> +	*data++ = u64_stats_read(&pool_stats->alloc_stats.waive);
>  	*data++ = u64_stats_read(&pool_stats->recycle_stats.cached);
>  	*data++ = u64_stats_read(&pool_stats->recycle_stats.cache_full);
>  	*data++ = u64_stats_read(&pool_stats->recycle_stats.ring);
> @@ -283,6 +303,7 @@ static int page_pool_init(struct page_pool *pool,
>  		pool->recycle_stats = &pp_system_recycle_stats;
>  		pool->system = true;
>  	}
> +	u64_stats_init(&pool->alloc_stats.syncp);
>  #endif
>  
>  	if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0) {
> diff --git a/net/core/page_pool_user.c b/net/core/page_pool_user.c
> index 86c22461b7fed..53c1ebe7cbe6b 100644
> --- a/net/core/page_pool_user.c
> +++ b/net/core/page_pool_user.c
> @@ -137,17 +137,17 @@ page_pool_nl_stats_fill(struct sk_buff *rsp, const struct page_pool *pool,
>  	nla_nest_end(rsp, nest);
>  
>  	if (nla_put_uint(rsp, NETDEV_A_PAGE_POOL_STATS_ALLOC_FAST,
> -			 stats.alloc_stats.fast) ||
> +			 u64_stats_read(&stats.alloc_stats.fast)) ||
>  	    nla_put_uint(rsp, NETDEV_A_PAGE_POOL_STATS_ALLOC_SLOW,
> -			 stats.alloc_stats.slow) ||
> +			 u64_stats_read(&stats.alloc_stats.slow)) ||
>  	    nla_put_uint(rsp, NETDEV_A_PAGE_POOL_STATS_ALLOC_SLOW_HIGH_ORDER,
> -			 stats.alloc_stats.slow_high_order) ||
> +			 u64_stats_read(&stats.alloc_stats.slow_high_order)) ||
>  	    nla_put_uint(rsp, NETDEV_A_PAGE_POOL_STATS_ALLOC_EMPTY,
> -			 stats.alloc_stats.empty) ||
> +			 u64_stats_read(&stats.alloc_stats.empty)) ||
>  	    nla_put_uint(rsp, NETDEV_A_PAGE_POOL_STATS_ALLOC_REFILL,
> -			 stats.alloc_stats.refill) ||
> +			 u64_stats_read(&stats.alloc_stats.refill)) ||
>  	    nla_put_uint(rsp, NETDEV_A_PAGE_POOL_STATS_ALLOC_WAIVE,
> -			 stats.alloc_stats.waive) ||
> +			 u64_stats_read(&stats.alloc_stats.waive)) ||
>  	    nla_put_uint(rsp, NETDEV_A_PAGE_POOL_STATS_RECYCLE_CACHED,
>  			 u64_stats_read(&stats.recycle_stats.cached)) ||
>  	    nla_put_uint(rsp, NETDEV_A_PAGE_POOL_STATS_RECYCLE_CACHE_FULL,

  reply	other threads:[~2025-04-08 12:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08 10:59 [PATCH net-next v3 0/4] page_pool: Convert stats to u64_stats_t Sebastian Andrzej Siewior
2025-04-08 10:59 ` [PATCH net-next v3 1/4] mlnx5: Use generic code for page_pool statistics Sebastian Andrzej Siewior
2025-04-10  7:16   ` Tariq Toukan
2025-04-10  8:58     ` Sebastian Andrzej Siewior
2025-04-10 11:23       ` Tariq Toukan
2025-04-08 10:59 ` [PATCH net-next v3 2/4] page_pool: Provide an empty page_pool_stats for disabled stats Sebastian Andrzej Siewior
2025-04-08 10:59 ` [PATCH net-next v3 3/4] page_pool: Convert page_pool_recycle_stats to u64_stats_t Sebastian Andrzej Siewior
2025-04-08 12:13   ` Yunsheng Lin
2025-04-09 16:11     ` Sebastian Andrzej Siewior
2025-04-08 10:59 ` [PATCH net-next v3 4/4] page_pool: Convert page_pool_alloc_stats " Sebastian Andrzej Siewior
2025-04-08 12:27   ` Yunsheng Lin [this message]
2025-04-08 12:33 ` [PATCH net-next v3 0/4] page_pool: Convert stats " Yunsheng Lin
2025-04-09  1:56 ` Jakub Kicinski
2025-04-09 16:15   ` Sebastian Andrzej Siewior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d012a523-816b-48af-91c0-4a11f85d592b@huawei.com \
    --to=linyunsheng@huawei.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bigeasy@linutronix.de \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jdamato@fastly.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox