diff options
author | Ian Rogers <irogers@google.com> | 2023-04-05 23:52:23 -0700 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2023-04-06 21:40:28 -0300 |
commit | 3d88aec0d42eec26b633fb2a473e294a1125bbd7 (patch) | |
tree | 863dfa7c6b567419ded68258bd4d774a9de733c6 /tools/perf/util/pmu.c | |
parent | e5116f46d44b72ede59a6923829f68a8b8f84e76 (diff) |
perf pmu: Make parser reentrant
By default bison uses global state for compatibility with yacc. Make
the parser reentrant so that it may be used in asynchronous and
multithreaded situations.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Gaosheng Cui <cuigaosheng1@huawei.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20230406065224.2553640-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/pmu.c')
-rw-r--r-- | tools/perf/util/pmu.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 78a407b42ad1..96ef317bac41 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -24,6 +24,8 @@ #include "evsel.h" #include "pmu.h" #include "pmus.h" +#include "pmu-bison.h" +#include "pmu-flex.h" #include "parse-events.h" #include "print-events.h" #include "header.h" @@ -57,9 +59,6 @@ struct perf_pmu_format { struct list_head list; }; -int perf_pmu_parse(struct list_head *list, char *name); -extern FILE *perf_pmu_in; - static bool hybrid_scanned; static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name); @@ -81,6 +80,8 @@ int perf_pmu__format_parse(int dirfd, struct list_head *head) while (!ret && (evt_ent = readdir(format_dir))) { char *name = evt_ent->d_name; int fd; + void *scanner; + FILE *file; if (!strcmp(name, ".") || !strcmp(name, "..")) continue; @@ -91,9 +92,22 @@ int perf_pmu__format_parse(int dirfd, struct list_head *head) if (fd < 0) break; - perf_pmu_in = fdopen(fd, "r"); - ret = perf_pmu_parse(head, name); - fclose(perf_pmu_in); + file = fdopen(fd, "r"); + if (!file) { + close(fd); + break; + } + + ret = perf_pmu_lex_init(&scanner); + if (ret) { + fclose(file); + break; + } + + perf_pmu_set_in(file, scanner); + ret = perf_pmu_parse(head, name, scanner); + perf_pmu_lex_destroy(scanner); + fclose(file); } closedir(format_dir); |