From patchwork Wed Mar 2 07:55:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 12765585 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5CFFC433EF for ; Wed, 2 Mar 2022 07:56:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239938AbiCBH5i (ORCPT ); Wed, 2 Mar 2022 02:57:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239957AbiCBH5b (ORCPT ); Wed, 2 Mar 2022 02:57:31 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0E4CB6D14 for ; Tue, 1 Mar 2022 23:56:48 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id i1so902633plr.2 for ; Tue, 01 Mar 2022 23:56:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HPfQh9n09LOH2LrDbaPnNvC5rOCyguVAdFId5ncvNfM=; b=W4CLDVLOmgoqdbcTywJ6SiUonL3zYL12YNWK0gAkjkQKpsxPxWfFzCpv8JtcdE55Jf GntAgEpd0N8/i79K8/X0lwYUi8bA6A9pEtNJMt1rN6YzRh+PhGZwGXFFYEv9CR9QJlbE 9aAXQ6E6LedsuOTWHe7ClijpTqCEEjx8OdvK0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HPfQh9n09LOH2LrDbaPnNvC5rOCyguVAdFId5ncvNfM=; b=fVcTlzh4KyuygH7DOuPHjXp44nbbi9g23fq87SJTHTJgc2y0+cl/YKkcXyLfAMeBSP aaH1hDIynjEo6jkSJdRdkhVxlbGpycDZVzEt4/mG/3yeHpMxGsCeHZgvqQxM6MholHme ZiuML0m4Iabkk+BZ5TTjaKSQPq1nXXhQhHQcg2qoNiM6CGgYQNj4CMpa7yga7TeAdotJ XfixptL8eZUZr/xXhqaMbhwxKYcB9YxVLGejVuZO9KqWGaAD4ER6RuxJKYNuqOMA9KPS SD1XLP0yOvr8/3M52a+WhZ+nrPfA4YaPBheqxw3j5s36heFpRDJIJ5UFAuYA6rfeWj82 6Gpg== X-Gm-Message-State: AOAM531GHDzXLkltwKcKNJWUyJgm0VwmqvmmlayJZ305iA8SwDNNz3Ah 2poljz0mFHSJYgmkI8twQ9Z5hQ== X-Google-Smtp-Source: ABdhPJz+Eg00dYxOyiEUT1cHkQKs+ewHcDJYqWv0Ke7hxiMGw+pmbDJ83p+PfNPCiRTnRI9XimpeAA== X-Received: by 2002:a17:902:904a:b0:149:b6f1:3c8b with SMTP id w10-20020a170902904a00b00149b6f13c8bmr29873638plz.83.1646207808293; Tue, 01 Mar 2022 23:56:48 -0800 (PST) Received: from localhost.localdomain (c-73-223-190-181.hsd1.ca.comcast.net. [73.223.190.181]) by smtp.gmail.com with ESMTPSA id gb9-20020a17090b060900b001beecaf986dsm2237780pjb.52.2022.03.01.23.56.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Mar 2022 23:56:47 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org, kuba@kernel.org, ilias.apalodimas@linaro.org, davem@davemloft.net, hawk@kernel.org, saeed@kernel.org, ttoukan.linux@gmail.com, brouer@redhat.com, leon@kernel.org, linux-rdma@vger.kernel.org, saeedm@nvidia.com Cc: Joe Damato Subject: [net-next v9 3/5] page_pool: Add function to batch and return stats Date: Tue, 1 Mar 2022 23:55:49 -0800 Message-Id: <1646207751-13621-4-git-send-email-jdamato@fastly.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1646207751-13621-1-git-send-email-jdamato@fastly.com> References: <1646207751-13621-1-git-send-email-jdamato@fastly.com> Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Adds a function page_pool_get_stats which can be used by drivers to obtain stats for a specified page_pool. Signed-off-by: Joe Damato Acked-by: Jesper Dangaard Brouer Reviewed-by: Ilias Apalodimas --- include/net/page_pool.h | 17 +++++++++++++++++ net/core/page_pool.c | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/net/page_pool.h b/include/net/page_pool.h index 298af95..ea5fb70 100644 --- a/include/net/page_pool.h +++ b/include/net/page_pool.h @@ -107,6 +107,23 @@ struct page_pool_recycle_stats { * refcnt */ }; + +/* This struct wraps the above stats structs so users of the + * page_pool_get_stats API can pass a single argument when requesting the + * stats for the page pool. + */ +struct page_pool_stats { + struct page_pool_alloc_stats alloc_stats; + struct page_pool_recycle_stats recycle_stats; +}; + +/* + * 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 call page_pool_get_stats to get stats for the specified pool. + */ +bool page_pool_get_stats(struct page_pool *pool, + struct page_pool_stats *stats); #endif struct page_pool { diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 3d273cb..1943c0f 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -35,6 +35,31 @@ struct page_pool_recycle_stats __percpu *s = pool->recycle_stats; \ this_cpu_inc(s->__stat); \ } while (0) + +bool page_pool_get_stats(struct page_pool *pool, + struct page_pool_stats *stats) +{ + int cpu = 0; + + if (!stats) + return false; + + memcpy(&stats->alloc_stats, &pool->alloc_stats, sizeof(pool->alloc_stats)); + + for_each_possible_cpu(cpu) { + const struct page_pool_recycle_stats *pcpu = + per_cpu_ptr(pool->recycle_stats, cpu); + + stats->recycle_stats.cached += pcpu->cached; + stats->recycle_stats.cache_full += pcpu->cache_full; + stats->recycle_stats.ring += pcpu->ring; + stats->recycle_stats.ring_full += pcpu->ring_full; + stats->recycle_stats.released_refcnt += pcpu->released_refcnt; + } + + return true; +} +EXPORT_SYMBOL(page_pool_get_stats); #else #define alloc_stat_inc(pool, __stat) #define recycle_stat_inc(pool, __stat)