Commit 70f4b20d authored by Kan Liang's avatar Kan Liang Committed by Namhyung Kim

perf mem: Clean up perf_mem_events__record_args()

The current code iterates all memory PMUs. It doesn't matter if the
system has only one memory PMU or multiple PMUs. The check of
perf_pmus__num_mem_pmus() is not required anymore.

The rec_tmp is not used in c2c and mem. Removing them as well.
Suggested-by: default avatarLeo Yan <leo.yan@linaro.org>
Tested-by: default avatarLeo Yan <leo.yan@linaro.org>
Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
Reviewed-by: default avatarIan Rogers <irogers@google.com>
Cc: ravi.bangoria@amd.com
Cc: james.clark@arm.com
Cc: will@kernel.org
Cc: mike.leach@linaro.org
Cc: renyu.zj@linux.alibaba.com
Cc: yuhaixin.yhx@linux.alibaba.com
Cc: tmricht@linux.ibm.com
Cc: atrajeev@linux.vnet.ibm.com
Cc: linux-arm-kernel@lists.infradead.org
Cc: john.g.garry@oracle.com
Link: https://lore.kernel.org/r/20240123185036.3461837-7-kan.liang@linux.intel.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
parent 8ea9dfb9
...@@ -3245,9 +3245,8 @@ static const char * const *record_mem_usage = __usage_record; ...@@ -3245,9 +3245,8 @@ static const char * const *record_mem_usage = __usage_record;
static int perf_c2c__record(int argc, const char **argv) static int perf_c2c__record(int argc, const char **argv)
{ {
int rec_argc, i = 0, j, rec_tmp_nr = 0; int rec_argc, i = 0, j;
const char **rec_argv; const char **rec_argv;
char **rec_tmp;
int ret; int ret;
bool all_user = false, all_kernel = false; bool all_user = false, all_kernel = false;
bool event_set = false; bool event_set = false;
...@@ -3285,12 +3284,6 @@ static int perf_c2c__record(int argc, const char **argv) ...@@ -3285,12 +3284,6 @@ static int perf_c2c__record(int argc, const char **argv)
if (!rec_argv) if (!rec_argv)
return -1; return -1;
rec_tmp = calloc(rec_argc + 1, sizeof(char *));
if (!rec_tmp) {
free(rec_argv);
return -1;
}
rec_argv[i++] = "record"; rec_argv[i++] = "record";
if (!event_set) { if (!event_set) {
...@@ -3319,7 +3312,7 @@ static int perf_c2c__record(int argc, const char **argv) ...@@ -3319,7 +3312,7 @@ static int perf_c2c__record(int argc, const char **argv)
rec_argv[i++] = "--phys-data"; rec_argv[i++] = "--phys-data";
rec_argv[i++] = "--sample-cpu"; rec_argv[i++] = "--sample-cpu";
ret = perf_mem_events__record_args(rec_argv, &i, rec_tmp, &rec_tmp_nr); ret = perf_mem_events__record_args(rec_argv, &i);
if (ret) if (ret)
goto out; goto out;
...@@ -3346,10 +3339,6 @@ static int perf_c2c__record(int argc, const char **argv) ...@@ -3346,10 +3339,6 @@ static int perf_c2c__record(int argc, const char **argv)
ret = cmd_record(i, rec_argv); ret = cmd_record(i, rec_argv);
out: out:
for (i = 0; i < rec_tmp_nr; i++)
free(rec_tmp[i]);
free(rec_tmp);
free(rec_argv); free(rec_argv);
return ret; return ret;
} }
......
...@@ -72,10 +72,9 @@ static const char * const *record_mem_usage = __usage; ...@@ -72,10 +72,9 @@ static const char * const *record_mem_usage = __usage;
static int __cmd_record(int argc, const char **argv, struct perf_mem *mem) static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
{ {
int rec_argc, i = 0, j, tmp_nr = 0; int rec_argc, i = 0, j;
int start, end; int start, end;
const char **rec_argv; const char **rec_argv;
char **rec_tmp;
int ret; int ret;
bool all_user = false, all_kernel = false; bool all_user = false, all_kernel = false;
struct perf_mem_event *e; struct perf_mem_event *e;
...@@ -116,15 +115,6 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem) ...@@ -116,15 +115,6 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
if (!rec_argv) if (!rec_argv)
return -1; return -1;
/*
* Save the allocated event name strings.
*/
rec_tmp = calloc(rec_argc + 1, sizeof(char *));
if (!rec_tmp) {
free(rec_argv);
return -1;
}
rec_argv[i++] = "record"; rec_argv[i++] = "record";
e = perf_pmu__mem_events_ptr(pmu, PERF_MEM_EVENTS__LOAD_STORE); e = perf_pmu__mem_events_ptr(pmu, PERF_MEM_EVENTS__LOAD_STORE);
...@@ -163,7 +153,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem) ...@@ -163,7 +153,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
rec_argv[i++] = "--data-page-size"; rec_argv[i++] = "--data-page-size";
start = i; start = i;
ret = perf_mem_events__record_args(rec_argv, &i, rec_tmp, &tmp_nr); ret = perf_mem_events__record_args(rec_argv, &i);
if (ret) if (ret)
goto out; goto out;
end = i; end = i;
...@@ -193,10 +183,6 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem) ...@@ -193,10 +183,6 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
ret = cmd_record(i, rec_argv); ret = cmd_record(i, rec_argv);
out: out:
for (i = 0; i < tmp_nr; i++)
free(rec_tmp[i]);
free(rec_tmp);
free(rec_argv); free(rec_argv);
return ret; return ret;
} }
......
...@@ -218,14 +218,14 @@ void perf_pmu__mem_events_list(struct perf_pmu *pmu) ...@@ -218,14 +218,14 @@ void perf_pmu__mem_events_list(struct perf_pmu *pmu)
} }
} }
int perf_mem_events__record_args(const char **rec_argv, int *argv_nr, int perf_mem_events__record_args(const char **rec_argv, int *argv_nr)
char **rec_tmp, int *tmp_nr)
{ {
const char *mnt = sysfs__mount(); const char *mnt = sysfs__mount();
struct perf_pmu *pmu = NULL; struct perf_pmu *pmu = NULL;
int i = *argv_nr, k = 0;
struct perf_mem_event *e; struct perf_mem_event *e;
int i = *argv_nr;
const char *s;
char *copy;
while ((pmu = perf_pmus__scan_mem(pmu)) != NULL) { while ((pmu = perf_pmus__scan_mem(pmu)) != NULL) {
for (int j = 0; j < PERF_MEM_EVENTS__MAX; j++) { for (int j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
...@@ -240,30 +240,20 @@ int perf_mem_events__record_args(const char **rec_argv, int *argv_nr, ...@@ -240,30 +240,20 @@ int perf_mem_events__record_args(const char **rec_argv, int *argv_nr,
return -1; return -1;
} }
if (perf_pmus__num_mem_pmus() == 1) { s = perf_pmu__mem_events_name(j, pmu);
rec_argv[i++] = "-e"; if (!s || !perf_pmu__mem_events_supported(mnt, pmu, e))
rec_argv[i++] = perf_pmu__mem_events_name(j, pmu); continue;
} else {
const char *s = perf_pmu__mem_events_name(j, pmu);
if (!perf_pmu__mem_events_supported(mnt, pmu, e))
continue;
rec_argv[i++] = "-e"; copy = strdup(s);
if (s) { if (!copy)
char *copy = strdup(s); return -1;
if (!copy)
return -1;
rec_argv[i++] = copy; rec_argv[i++] = "-e";
rec_tmp[k++] = copy; rec_argv[i++] = copy;
}
}
} }
} }
*argv_nr = i; *argv_nr = i;
*tmp_nr = k;
return 0; return 0;
} }
......
...@@ -46,8 +46,7 @@ struct perf_pmu *perf_mem_events_find_pmu(void); ...@@ -46,8 +46,7 @@ struct perf_pmu *perf_mem_events_find_pmu(void);
bool is_mem_loads_aux_event(struct evsel *leader); bool is_mem_loads_aux_event(struct evsel *leader);
void perf_pmu__mem_events_list(struct perf_pmu *pmu); void perf_pmu__mem_events_list(struct perf_pmu *pmu);
int perf_mem_events__record_args(const char **rec_argv, int *argv_nr, int perf_mem_events__record_args(const char **rec_argv, int *argv_nr);
char **rec_tmp, int *tmp_nr);
int perf_mem__tlb_scnprintf(char *out, size_t sz, struct mem_info *mem_info); int perf_mem__tlb_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info); int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment