[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <67147a30-dd5b-35b5-c63e-a838d56b8220@linux.intel.com>
Date: Sun, 21 May 2023 15:43:53 -0400
From: "Liang, Kan" <kan.liang@...ux.intel.com>
To: Ian Rogers <irogers@...gle.com>,
Suzuki K Poulose <suzuki.poulose@....com>,
Mike Leach <mike.leach@...aro.org>,
Leo Yan <leo.yan@...aro.org>,
John Garry <john.g.garry@...cle.com>,
Will Deacon <will@...nel.org>,
James Clark <james.clark@....com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Adrian Hunter <adrian.hunter@...el.com>,
Kajol Jain <kjain@...ux.ibm.com>,
Jing Zhang <renyu.zj@...ux.alibaba.com>,
Ravi Bangoria <ravi.bangoria@....com>,
Madhavan Srinivasan <maddy@...ux.ibm.com>,
Athira Rajeev <atrajeev@...ux.vnet.ibm.com>,
Ming Wang <wangming01@...ngson.cn>,
Huacai Chen <chenhuacai@...nel.org>,
Sandipan Das <sandipan.das@....com>,
Dmitrii Dolgov <9erthalion6@...il.com>,
Sean Christopherson <seanjc@...gle.com>,
Ali Saidi <alisaidi@...zon.com>, Rob Herring <robh@...nel.org>,
Thomas Richter <tmricht@...ux.ibm.com>,
Kang Minchul <tegongkang@...il.com>,
linux-kernel@...r.kernel.org, coresight@...ts.linaro.org,
linux-arm-kernel@...ts.infradead.org,
linux-perf-users@...r.kernel.org
Subject: Re: [PATCH v1 17/23] perf pmus: Prefer perf_pmu__scan over
perf_pmus__for_each_pmu
On 2023-05-17 10:57 a.m., Ian Rogers wrote:
> perf_pmus__for_each_pmu doesn't lazily initialize pmus making its use
> error prone. Just use perf_pmu__scan as this only impacts
> non-performance critical tests.
>
> Signed-off-by: Ian Rogers <irogers@...gle.com>
Reviewed-by: Kan Liang <kan.liang@...ux.intel.com>
Thanks,
Kan
> ---
> tools/perf/bench/pmu-scan.c | 6 ++----
> tools/perf/tests/event_groups.c | 7 ++-----
> tools/perf/tests/parse-events.c | 11 ++++-------
> tools/perf/util/pmus.h | 2 --
> 4 files changed, 8 insertions(+), 18 deletions(-)
>
> diff --git a/tools/perf/bench/pmu-scan.c b/tools/perf/bench/pmu-scan.c
> index f0f007843bb8..f4a6c37cbe27 100644
> --- a/tools/perf/bench/pmu-scan.c
> +++ b/tools/perf/bench/pmu-scan.c
> @@ -40,13 +40,11 @@ static struct pmu_scan_result *results;
>
> static int save_result(void)
> {
> - struct perf_pmu *pmu;
> + struct perf_pmu *pmu = NULL;
> struct list_head *list;
> struct pmu_scan_result *r;
>
> - perf_pmu__scan(NULL);
> -
> - perf_pmus__for_each_pmu(pmu) {
> + while ((pmu = perf_pmu__scan(pmu)) != NULL) {
> r = realloc(results, (nr_pmus + 1) * sizeof(*r));
> if (r == NULL)
> return -ENOMEM;
> diff --git a/tools/perf/tests/event_groups.c b/tools/perf/tests/event_groups.c
> index 029442b4e9c6..3d9a2b524bba 100644
> --- a/tools/perf/tests/event_groups.c
> +++ b/tools/perf/tests/event_groups.c
> @@ -50,13 +50,10 @@ static int event_open(int type, unsigned long config, int group_fd)
>
> static int setup_uncore_event(void)
> {
> - struct perf_pmu *pmu;
> + struct perf_pmu *pmu = NULL;
> int i, fd;
>
> - if (list_empty(&pmus))
> - perf_pmu__scan(NULL);
> -
> - perf_pmus__for_each_pmu(pmu) {
> + while ((pmu = perf_pmu__scan(pmu)) != NULL) {
> for (i = 0; i < NR_UNCORE_PMUS; i++) {
> if (!strcmp(uncore_pmus[i].name, pmu->name)) {
> pr_debug("Using %s for uncore pmu event\n", pmu->name);
> diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
> index 72a10bed84fd..277607ede060 100644
> --- a/tools/perf/tests/parse-events.c
> +++ b/tools/perf/tests/parse-events.c
> @@ -108,11 +108,11 @@ static int test__checkevent_raw(struct evlist *evlist)
> TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
>
> perf_evlist__for_each_evsel(&evlist->core, evsel) {
> - struct perf_pmu *pmu;
> + struct perf_pmu *pmu = NULL;
> bool type_matched = false;
>
> TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a));
> - perf_pmus__for_each_pmu(pmu) {
> + while ((pmu = perf_pmu__scan(pmu)) != NULL) {
> if (pmu->type == evsel->attr.type) {
> TEST_ASSERT_VAL("PMU type expected once", !type_matched);
> type_matched = true;
> @@ -2243,13 +2243,10 @@ static int test__terms2(struct test_suite *test __maybe_unused, int subtest __ma
>
> static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
> {
> - struct perf_pmu *pmu;
> + struct perf_pmu *pmu = NULL;
> int ret = TEST_OK;
>
> - if (list_empty(&pmus))
> - perf_pmu__scan(NULL);
> -
> - perf_pmus__for_each_pmu(pmu) {
> + while ((pmu = perf_pmu__scan(pmu)) != NULL) {
> struct stat st;
> char path[PATH_MAX];
> struct dirent *ent;
> diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h
> index d475e2960c10..257de10788e8 100644
> --- a/tools/perf/util/pmus.h
> +++ b/tools/perf/util/pmus.h
> @@ -5,8 +5,6 @@
> extern struct list_head pmus;
> struct perf_pmu;
>
> -#define perf_pmus__for_each_pmu(pmu) list_for_each_entry(pmu, &pmus, list)
> -
> const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str);
>
> #endif /* __PMUS_H */
Powered by blists - more mailing lists