From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Tomasz Duszynski" <tduszynski@marvell.com>
Cc: <dev@dpdk.org>, <Ruifeng.Wang@arm.com>,
	<bruce.richardson@intel.com>, <david.marchand@redhat.com>,
	<jerinj@marvell.com>, <konstantin.v.ananyev@yandex.ru>,
	<mattias.ronnblom@ericsson.com>, <roretzla@linux.microsoft.com>,
	<stephen@networkplumber.org>, <thomas@monjalon.net>,
	<zhoumin@loongson.cn>, <wathsala.vithanage@arm.com>
Subject: RE: [PATCH v11 7/9] test/pmu: enable test
Date: Thu, 30 Oct 2025 14:03:56 +0100	[thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35F65516@smartserver.smartshare.dk> (raw)
In-Reply-To: <20251024054830.933910-8-tduszynski@marvell.com>
> From: Tomasz Duszynski [mailto:tduszynski@marvell.com]
> Sent: Friday, 24 October 2025 07.48
> 
> Enable test to allow users to verify basic functionality. Due to
> varying
> configuration options across distributions and kernels user should
> ensure that all requirements are satisfied before starting test.
> 
> Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
> ---
With these changes, the test can never return TEST_FAILED, it returns TEST_SKIPPED when something doesn't work.
IMO, the perf_allowed_quirk() check belongs in rte_pmu_init() instead.
Then, rte_pmu_init() could return a variety of error values depending on the reason for the inability to init/start the PMU library.
Amongst the high level error values should be:
-EACCES (insufficient privileges)
-ENODEV (hardware has no PMU, or kernel is custom built without PMU)
The test should only return SKIPPED if rte_pmu_init() returns -ENODEV (no PMU present to test); any other non-success should cause the test to return FAILED.
Also, the possible return values from rte_pmu_init() should be documented in its function description.
>  app/test/test_pmu.c | 60 ++++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 54 insertions(+), 6 deletions(-)
> 
> diff --git a/app/test/test_pmu.c b/app/test/test_pmu.c
> index 10513bf9c9..7f450b3566 100644
> --- a/app/test/test_pmu.c
> +++ b/app/test/test_pmu.c
> @@ -2,10 +2,48 @@
>   * Copyright(C) 2025 Marvell International Ltd.
>   */
> 
> +#include <stdbool.h>
> +#include <stdio.h>
> +#include <sys/types.h>
> +#include <unistd.h>
> +
>  #include <rte_pmu.h>
> 
>  #include "test.h"
> 
> +#define PERF_EVENT_PARANOID_PATH
> "/proc/sys/kernel/perf_event_paranoid"
> +
> +static bool perf_allowed_quirk(void)
> +{
> +	int level, ret;
> +	FILE *fp;
> +
> +	fp = fopen(PERF_EVENT_PARANOID_PATH, "r");
> +	if (!fp)
> +		return false;
> +
> +	ret = fscanf(fp, "%d", &level);
> +	fclose(fp);
> +	if (ret != 1)
> +		return false;
> +
> +	/* On vanilla Linux the default perf_event_paranoid level is 2,
> which allows non-privileged
> +	 * processes to access performance counters.
> +	 *
> +	 * Debian / Ubuntu and their derivatives apply patches that
> introduce
> +	 * additional paranoia levels:
> +	 *
> +	 * - Debian adds level 3, which restricts access to
> perf_event_open() for
> +	 *   monitoring other processes, but still allows unprivileged
> self-monitoring.
> +	 *   See: https://lore.kernel.org/all/1469630746-32279-1-git-
> send-email-jeffv@google.com/
> +	 * - Ubuntu adds level 4 (which is also the default), completely
> disabling perf_event_open()
> +	 *   for unprivileged users—effectively disabling self-
> monitoring.
> +	 *
> +	 * That said, check below should be sufficient to enable this
> test on most kernels.
> +	 */
> +	return level < 4;
> +}
> +
>  static int
>  test_pmu_read(void)
>  {
> @@ -24,8 +62,15 @@ test_pmu_read(void)
>  		return TEST_SKIPPED;
>  	}
> 
> -	if (rte_pmu_init() < 0)
> -		return TEST_FAILED;
> +	if ((getuid() != 0) && !perf_allowed_quirk()) {
> +		printf("self-monitoring disabled\n");
> +		return TEST_SKIPPED;
> +	}
> +
> +	if (rte_pmu_init() < 0) {
> +		printf("PMU not initialized\n");
> +		return TEST_SKIPPED;
> +	}
> 
>  	event = rte_pmu_add_event(name);
>  	while (tries--)
> @@ -33,7 +78,12 @@ test_pmu_read(void)
> 
>  	rte_pmu_fini();
> 
> -	return val ? TEST_SUCCESS : TEST_FAILED;
> +	/* rte_pmu_read() returns zero if it can't read perf counter.
> Thus series of zeros doesn't
> +	 * necessarily mean the counter is actually zero. It might just
> signal a problem with setup
> +	 * itself. So skip test to avoid testing failure and leave it to
> user to interpret this
> +	 * outcome.
> +	 */
> +	return val ? TEST_SUCCESS : TEST_SKIPPED;
>  }
> 
>  static struct unit_test_suite pmu_tests = {
> @@ -52,6 +102,4 @@ test_pmu(void)
>  	return unit_test_suite_runner(&pmu_tests);
>  }
> 
> -/* disabled because of reported failures, waiting for a fix
> - * REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu);
> - */
> +REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu);
> --
> 2.34.1
next prev parent reply	other threads:[~2025-10-30 13:04 UTC|newest]
Thread overview: 129+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-16  6:53 [PATCH 0/6] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-06-16  6:53 ` [PATCH 1/6] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-06-16  6:53 ` [PATCH 2/6] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-06-16  6:53 ` [PATCH 3/6] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-06-16  7:03   ` Thomas Monjalon
2025-06-16  9:54     ` Tomasz Duszynski
2025-06-16  6:53 ` [PATCH 4/6] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-06-16  7:08   ` Thomas Monjalon
2025-06-16 10:53     ` Tomasz Duszynski
2025-06-16  6:53 ` [PATCH 5/6] test/pmu: enable fast test Tomasz Duszynski
2025-06-16  6:53 ` [PATCH 6/6] trace: add PMU Tomasz Duszynski
2025-06-16  7:13   ` Thomas Monjalon
2025-06-16  9:49     ` Tomasz Duszynski
2025-06-16 10:32       ` Bruce Richardson
2025-06-16 13:18       ` Morten Brørup
2025-06-18  6:56 ` [PATCH v2 0/6] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-06-18  6:56   ` [PATCH v2 1/6] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-06-18  6:56   ` [PATCH v2 2/6] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-06-18  6:56   ` [PATCH v2 3/6] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-06-18  6:56   ` [PATCH v2 4/6] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-06-18  6:56   ` [PATCH v2 5/6] test/pmu: enable fast test Tomasz Duszynski
2025-06-18  6:56   ` [PATCH v2 6/6] trace: add PMU Tomasz Duszynski
2025-06-18  7:16     ` Morten Brørup
2025-06-18  9:47       ` Thomas Monjalon
2025-06-18 10:28         ` Bruce Richardson
2025-06-18 11:30           ` Morten Brørup
2025-06-18 10:23       ` Tomasz Duszynski
2025-06-18 10:37         ` Morten Brørup
2025-06-20 12:05   ` [PATCH v3 0/7] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 1/7] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 2/7] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 3/7] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 4/7] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 5/7] test/pmu: enable fast test Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 6/7] trace: add PMU Tomasz Duszynski
2025-06-20 12:05     ` [PATCH v3 7/7] lib/pmu: fix out-of-bound access Tomasz Duszynski
2025-06-24 12:29     ` [PATCH v4 0/7] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 1/7] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 2/7] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 3/7] lib/pmu: do not try enabling perf counter access on arm64 Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 4/7] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 5/7] test/pmu: enable fast test Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 6/7] trace: add PMU Tomasz Duszynski
2025-06-24 12:29       ` [PATCH v4 7/7] lib/pmu: fix out-of-bound access Tomasz Duszynski
2025-06-25  4:47       ` [PATCH v5 0/8] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 1/8] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 2/8] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 3/8] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 4/8] lib/pmu: do not try enabling perf counter access on arm64 Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 5/8] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 6/8] test/pmu: enable fast test Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 7/8] trace: add PMU Tomasz Duszynski
2025-06-25  4:47         ` [PATCH v5 8/8] lib/pmu: fix out-of-bound access Tomasz Duszynski
2025-06-27 10:57         ` [PATCH v6 0/8] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-06-27 10:57           ` [PATCH v6 1/8] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-06-27 10:57           ` [PATCH v6 2/8] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-06-27 10:57           ` [PATCH v6 3/8] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-06-27 10:57           ` [PATCH v6 4/8] lib/pmu: do not try enabling perf counter access on arm64 Tomasz Duszynski
2025-06-27 10:57           ` [PATCH v6 5/8] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-06-27 10:57           ` [PATCH v6 6/8] test/pmu: enable test Tomasz Duszynski
2025-06-27 10:57           ` [PATCH v6 7/8] trace: add PMU Tomasz Duszynski
2025-06-27 10:57           ` [PATCH v6 8/8] lib/pmu: fix out-of-bound access Tomasz Duszynski
2025-06-27 15:40           ` [PATCH v7 0/8] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-06-27 15:41             ` [PATCH v7 1/8] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-06-27 15:41             ` [PATCH v7 2/8] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-06-27 15:41             ` [PATCH v7 3/8] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-06-27 15:41             ` [PATCH v7 4/8] lib/pmu: do not try enabling perf counter access on arm64 Tomasz Duszynski
2025-06-27 15:41             ` [PATCH v7 5/8] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-06-27 15:41             ` [PATCH v7 6/8] test/pmu: enable test Tomasz Duszynski
2025-06-27 15:41             ` [PATCH v7 7/8] trace: add PMU Tomasz Duszynski
2025-07-01 13:33               ` David Marchand
2025-07-21 10:24                 ` Tomasz Duszynski
2025-07-21 10:45                   ` Thomas Monjalon
2025-07-22 10:10                     ` Morten Brørup
2025-07-22 11:06                       ` Tomasz Duszynski
2025-06-27 15:41             ` [PATCH v7 8/8] lib/pmu: fix out-of-bound access Tomasz Duszynski
2025-07-22 12:00             ` [PATCH v8 0/8] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-07-22 12:00               ` [PATCH v8 1/8] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-07-22 12:00               ` [PATCH v8 2/8] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-07-22 12:00               ` [PATCH v8 3/8] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-07-22 12:00               ` [PATCH v8 4/8] lib/pmu: do not try enabling perf counter access on arm64 Tomasz Duszynski
2025-07-22 12:00               ` [PATCH v8 5/8] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-07-22 12:00               ` [PATCH v8 6/8] test/pmu: enable test Tomasz Duszynski
2025-07-22 12:00               ` [PATCH v8 7/8] trace: add PMU Tomasz Duszynski
2025-07-22 12:00               ` [PATCH v8 8/8] lib/pmu: fix out-of-bound access Tomasz Duszynski
2025-07-23  4:41               ` [PATCH v9 0/8] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-07-23  4:41                 ` [PATCH v9 1/8] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-07-23 14:27                   ` Stephen Hemminger
2025-08-01  9:37                     ` Tomasz Duszynski
2025-08-01 21:57                       ` Stephen Hemminger
2025-07-23  4:41                 ` [PATCH v9 2/8] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-07-23  4:41                 ` [PATCH v9 3/8] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-07-23  4:41                 ` [PATCH v9 4/8] lib/pmu: do not try enabling perf counter access on arm64 Tomasz Duszynski
2025-07-23  4:41                 ` [PATCH v9 5/8] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-07-23  4:41                 ` [PATCH v9 6/8] test/pmu: enable test Tomasz Duszynski
2025-07-23  4:41                 ` [PATCH v9 7/8] trace: add PMU Tomasz Duszynski
2025-07-23  4:41                 ` [PATCH v9 8/8] lib/pmu: fix out-of-bound access Tomasz Duszynski
2025-08-01 10:20                 ` [PATCH v10 00/10] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-08-01 10:21                   ` [PATCH v10 01/10] trace: change scope of conditional block Tomasz Duszynski
2025-08-01 10:21                   ` [PATCH v10 02/10] lib/pmu: fix build error if ALLOW_EXPERIMENAL_API is undefined Tomasz Duszynski
2025-08-01 10:21                   ` [PATCH v10 03/10] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs Tomasz Duszynski
2025-08-01 21:47                     ` Stephen Hemminger
2025-08-04 10:09                       ` Tomasz Duszynski
2025-08-08 11:27                         ` Tomasz Duszynski
2025-10-17  6:58                           ` Tomasz Duszynski
2025-10-17  8:45                             ` David Marchand
2025-10-17  9:04                               ` Thomas Monjalon
2025-08-01 10:21                   ` [PATCH v10 04/10] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-08-01 10:21                   ` [PATCH v10 05/10] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-08-01 10:21                   ` [PATCH v10 06/10] lib/pmu: do not try enabling perf counter access on arm64 Tomasz Duszynski
2025-08-01 21:49                     ` Stephen Hemminger
2025-08-04  8:32                       ` Tomasz Duszynski
2025-08-04 17:12                     ` Wathsala Vithanage
2025-08-01 10:21                   ` [PATCH v10 07/10] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-08-01 10:21                   ` [PATCH v10 08/10] test/pmu: enable test Tomasz Duszynski
2025-08-01 10:21                   ` [PATCH v10 09/10] trace: add PMU Tomasz Duszynski
2025-08-01 10:21                   ` [PATCH v10 10/10] lib/pmu: fix out-of-bound access Tomasz Duszynski
2025-10-24  5:48                   ` [PATCH v11 0/9] lib/pmu: cleanups and trace integration Tomasz Duszynski
2025-10-24  5:48                     ` [PATCH v11 1/9] pmu: quiesce chkincs warnings Tomasz Duszynski
2025-10-24  5:48                     ` [PATCH v11 2/9] trace: change scope of conditional block Tomasz Duszynski
2025-10-24  5:48                     ` [PATCH v11 3/9] lib/pmu: export only necessary arch headers Tomasz Duszynski
2025-10-24  5:48                     ` [PATCH v11 4/9] lib/pmu: reimplement per-arch ops as callbacks Tomasz Duszynski
2025-10-24  5:48                     ` [PATCH v11 5/9] lib/pmu: do not try enabling perf counter access on arm64 Tomasz Duszynski
2025-10-24  5:48                     ` [PATCH v11 6/9] lib/pmu: use build system defined RTE_LIB_PMU macro Tomasz Duszynski
2025-10-24  5:48                     ` [PATCH v11 7/9] test/pmu: enable test Tomasz Duszynski
2025-10-30 13:03                       ` Morten Brørup [this message]
2025-10-24  5:48                     ` [PATCH v11 8/9] trace: add PMU Tomasz Duszynski
2025-10-24  5:48                     ` [PATCH v11 9/9] lib/pmu: fix out-of-bound access Tomasz Duszynski
2025-10-30  3:50                     ` [PATCH v11 0/9] lib/pmu: cleanups and trace integration Tomasz Duszynski
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=98CBD80474FA8B44BF855DF32C47DC35F65516@smartserver.smartshare.dk \
    --to=mb@smartsharesystems.com \
    --cc=Ruifeng.Wang@arm.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=konstantin.v.ananyev@yandex.ru \
    --cc=mattias.ronnblom@ericsson.com \
    --cc=roretzla@linux.microsoft.com \
    --cc=stephen@networkplumber.org \
    --cc=tduszynski@marvell.com \
    --cc=thomas@monjalon.net \
    --cc=wathsala.vithanage@arm.com \
    --cc=zhoumin@loongson.cn \
    /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;
as well as URLs for NNTP newsgroup(s).