linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	James Clark <james.clark@arm.com>,
	Ravi Bangoria <ravi.bangoria@amd.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/2] perf pmus: Add notion of default PMU for JSON events
Date: Thu, 22 Jun 2023 14:49:06 -0700	[thread overview]
Message-ID: <CAM9d7cjWYG4NgMPFUVC0q-u0GGekrvqpw8jU2o4KfiWqFC8x6g@mail.gmail.com> (raw)
In-Reply-To: <20230622050330.3733114-1-irogers@google.com>

On Wed, Jun 21, 2023 at 10:03 PM Ian Rogers <irogers@google.com> wrote:
>
> JSON events created in pmu-events.c by jevents.py may not specify a
> PMU they are associated with, in which case it is implied that it is
> the first core PMU. Care is needed to select this for regular 'cpu',
> s390 'cpum_cf' and ARMs many names as at the point the name is first
> needed the core PMUs list hasn't been initialized. Add a helper in
> perf_pmus to create this value, in the worst case by scanning sysfs.
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---

[SNIP]
> diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
> index d891d72c824e..80797e1b862f 100644
> --- a/tools/perf/util/pmus.c
> +++ b/tools/perf/util/pmus.c
> @@ -524,6 +524,37 @@ bool perf_pmus__supports_extended_type(void)
>         return perf_pmus__do_support_extended_type;
>  }
>
> +char *perf_pmus__default_pmu_name(void)
> +{
> +       int fd;
> +       DIR *dir;
> +       struct dirent *dent;
> +       char *result = NULL;
> +
> +       if (!list_empty(&core_pmus))
> +               return strdup(list_first_entry(&core_pmus, struct perf_pmu, list)->name);
> +
> +       fd = perf_pmu__event_source_devices_fd();
> +       if (fd < 0)
> +               return strdup("cpu");
> +
> +       dir = fdopendir(fd);
> +       if (!dir)
> +               return strdup("cpu");

close(fd) ?

Thanks,
Namhyung


> +
> +       while ((dent = readdir(dir))) {
> +               if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
> +                       continue;
> +               if (is_pmu_core(dent->d_name)) {
> +                       result = strdup(dent->d_name);
> +                       break;
> +               }
> +       }
> +
> +       closedir(dir);
> +       return result ?: strdup("cpu");
> +}
> +
>  struct perf_pmu *evsel__find_pmu(const struct evsel *evsel)
>  {
>         struct perf_pmu *pmu = evsel->pmu;
> diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h
> index d02ffea5d3a4..a21464432d0f 100644
> --- a/tools/perf/util/pmus.h
> +++ b/tools/perf/util/pmus.h
> @@ -20,5 +20,6 @@ void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, void *p
>  bool perf_pmus__have_event(const char *pname, const char *name);
>  int perf_pmus__num_core_pmus(void);
>  bool perf_pmus__supports_extended_type(void);
> +char *perf_pmus__default_pmu_name(void);
>
>  #endif /* __PMUS_H */
> --
> 2.41.0.162.gfafddb0af9-goog
>

      parent reply	other threads:[~2023-06-22 21:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-22  5:03 [PATCH v1 1/2] perf pmus: Add notion of default PMU for JSON events Ian Rogers
2023-06-22  5:03 ` [PATCH v1 2/2] perf pmu: Remove a hard coded cpu PMU assumption Ian Rogers
2023-06-22  8:35   ` Thomas Richter
2023-06-22 21:49 ` Namhyung Kim [this message]

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=CAM9d7cjWYG4NgMPFUVC0q-u0GGekrvqpw8jU2o4KfiWqFC8x6g@mail.gmail.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@arm.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=tmricht@linux.ibm.com \
    /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).