Re: [PATCH v4 1/2] perf pmu: Add PMU alias support

From: Jin, Yao
Date: Thu Aug 12 2021 - 00:33:01 EST


Hi Jiri,

On 8/12/2021 3:23 AM, Jiri Olsa wrote:
On Wed, Aug 11, 2021 at 10:48:26AM +0800, Jin Yao wrote:

SNIP

if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, false))
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index fc683bc41715..796a4be752f4 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -946,6 +946,18 @@ perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused)
return NULL;
}
+char * __weak
+pmu_find_real_name(const char *name)
+{
+ return strdup(name);
+}
hm, why does this need to return already strdup? it forces you
to add all those goto below.. could just return name and keep
the 'pmu->name = strdup(name);' below?

that should make the change simpler

jirka


In x86 specific __pmu_find_real_name,

static char *__pmu_find_real_name(const char *name)
{
struct perf_pmu_alias_name *pmu;

list_for_each_entry(pmu, &pmu_alias_name_list, list) {
if (!strcmp(name, pmu->alias))
return strdup(pmu->name);
}

return strdup(name);
}

We have returned with strdup(name).

OK, I will change the code to:

static char *__pmu_find_real_name(const char *name)
{
struct perf_pmu_alias_name *pmu;

list_for_each_entry(pmu, &pmu_alias_name_list, list) {
if (!strcmp(name, pmu->alias))
return pmu->name;
}

return name;
}

And keep 'pmu->name = strdup(name);' in pmu_lookup().

Thanks
Jin Yao