From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@kernel.org>
Cc: Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org,
Kan Liang <kan.liang@linux.intel.com>,
Leo Yan <leo.yan@linaro.org>
Subject: [PATCH 3/9] perf pmu: Add perf_pmu__destroy() function
Date: Fri, 31 Mar 2023 13:29:43 -0700 [thread overview]
Message-ID: <20230331202949.810326-4-namhyung@kernel.org> (raw)
In-Reply-To: <20230331202949.810326-1-namhyung@kernel.org>
It seems there's no function to delete the perf pmu struct. Add the
perf_pmu__destroy() to do the job. While at it, add some more helper
functions to delete pmu aliases and caps.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/pmu.c | 50 +++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/pmu.h | 2 ++
2 files changed, 52 insertions(+)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index e3aae731bd6f..b112606f36ec 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -300,6 +300,16 @@ void perf_pmu_free_alias(struct perf_pmu_alias *newalias)
free(newalias);
}
+static void perf_pmu__del_aliases(struct perf_pmu *pmu)
+{
+ struct perf_pmu_alias *alias, *tmp;
+
+ list_for_each_entry_safe(alias, tmp, &pmu->aliases, list) {
+ list_del(&alias->list);
+ perf_pmu_free_alias(alias);
+ }
+}
+
/* Merge an alias, search in alias list. If this name is already
* present merge both of them to combine all information.
*/
@@ -921,6 +931,8 @@ static struct perf_pmu *pmu_lookup(const char *lookup_name)
if (is_hybrid)
list_add_tail(&pmu->hybrid_list, &perf_pmu__hybrid_pmus);
+ else
+ INIT_LIST_HEAD(&pmu->hybrid_list);
pmu->default_config = perf_pmu__get_default_config(pmu);
@@ -1750,6 +1762,18 @@ static int perf_pmu__new_caps(struct list_head *list, char *name, char *value)
return -ENOMEM;
}
+static void perf_pmu__del_caps(struct perf_pmu *pmu)
+{
+ struct perf_pmu_caps *caps, *tmp;
+
+ list_for_each_entry_safe(caps, tmp, &pmu->caps, list) {
+ list_del(&caps->list);
+ free(caps->name);
+ free(caps->value);
+ free(caps);
+ }
+}
+
/*
* Reading/parsing the given pmu capabilities, which should be located at:
* /sys/bus/event_source/devices/<dev>/caps as sysfs group attributes.
@@ -1932,3 +1956,29 @@ int perf_pmu__pathname_scnprintf(char *buf, size_t size,
return 0;
return scnprintf(buf, size, "%s%s/%s", base_path, pmu_name, filename);
}
+
+static void perf_pmu__delete(struct perf_pmu *pmu)
+{
+ perf_pmu__del_formats(&pmu->format);
+ perf_pmu__del_aliases(pmu);
+ perf_pmu__del_caps(pmu);
+
+ perf_cpu_map__put(pmu->cpus);
+
+ free(pmu->default_config);
+ free(pmu->name);
+ free(pmu->alias_name);
+ free(pmu);
+}
+
+void perf_pmu__destroy(void)
+{
+ struct perf_pmu *pmu, *tmp;
+
+ list_for_each_entry_safe(pmu, tmp, &pmus, list) {
+ list_del(&pmu->list);
+ list_del(&pmu->hybrid_list);
+
+ perf_pmu__delete(pmu);
+ }
+}
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 24cf69ab32cd..72fd5de334c0 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -259,4 +259,6 @@ int perf_pmu__pathname_scnprintf(char *buf, size_t size,
const char *pmu_name, const char *filename);
FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name);
+void perf_pmu__destroy(void);
+
#endif /* __PMU_H */
--
2.40.0.348.gf938b09366-goog
next prev parent reply other threads:[~2023-03-31 20:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-31 20:29 [PATCHSET 0/9] perf tools: Update pmu scan using openat() (v1) Namhyung Kim
2023-03-31 20:29 ` [PATCH 1/9] perf list: Use relative path for tracepoint scan Namhyung Kim
2023-04-03 21:59 ` Arnaldo Carvalho de Melo
2023-04-03 22:00 ` Arnaldo Carvalho de Melo
2023-04-04 14:10 ` Arnaldo Carvalho de Melo
2023-04-04 22:08 ` Namhyung Kim
2023-04-04 22:19 ` Arnaldo Carvalho de Melo
2023-03-31 20:29 ` [PATCH 2/9] perf tools: Fix a asan issue in parse_events_multi_pmu_add() Namhyung Kim
2023-03-31 20:29 ` Namhyung Kim [this message]
2023-03-31 20:29 ` [PATCH 4/9] perf bench: Add pmu-scan benchmark Namhyung Kim
2023-03-31 20:29 ` [PATCH 5/9] perf pmu: Use relative path for sysfs scan Namhyung Kim
2023-04-03 17:23 ` Ian Rogers
2023-03-31 20:29 ` [PATCH 6/9] perf pmu: Use relative path in perf_pmu__caps_parse() Namhyung Kim
2023-03-31 20:29 ` [PATCH 7/9] perf pmu: Use relative path in setup_pmu_alias_list() Namhyung Kim
2023-03-31 20:29 ` [PATCH 8/9] perf pmu: Add perf_pmu__{open,scan}_file_at() Namhyung Kim
2023-03-31 20:29 ` [PATCH 9/9] perf intel-pt: Use perf_pmu__scan_file_at() if possible Namhyung Kim
2023-04-03 4:51 ` Adrian Hunter
2023-04-03 17:28 ` [PATCHSET 0/9] perf tools: Update pmu scan using openat() (v1) Ian Rogers
2023-04-03 20:25 ` Arnaldo Carvalho de Melo
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=20230331202949.810326-4-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=leo.yan@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/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
all inboxes | Powered by JetHome®