lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Thu, 22 Jun 2023 14:49:06 -0700
From:   Namhyung Kim <namhyung@...nel.org>
To:     Ian Rogers <irogers@...gle.com>
Cc:     Thomas Richter <tmricht@...ux.ibm.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>,
        Adrian Hunter <adrian.hunter@...el.com>,
        Kan Liang <kan.liang@...ux.intel.com>,
        James Clark <james.clark@....com>,
        Ravi Bangoria <ravi.bangoria@....com>,
        linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1 1/2] perf pmus: Add notion of default PMU for JSON events

On Wed, Jun 21, 2023 at 10:03 PM Ian Rogers <irogers@...gle.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@...gle.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
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ