Commit cc26ffaa authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf stat: Hide runtime_stat

runtime_stat is only shared for the sake of tests that don't care
about its value. Move the definition into stat-shadow.c and have the
tests also use the global version.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Florian Fischer <florian.fischer@muhq.space>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Link: https://lore.kernel.org/r/20230219092848.639226-48-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 758bc8e6
...@@ -2074,8 +2074,7 @@ static void perf_sample__fprint_metric(struct perf_script *script, ...@@ -2074,8 +2074,7 @@ static void perf_sample__fprint_metric(struct perf_script *script,
val = sample->period * evsel->scale; val = sample->period * evsel->scale;
perf_stat__update_shadow_stats(evsel, perf_stat__update_shadow_stats(evsel,
val, val,
sample->cpu, sample->cpu);
&rt_stat);
evsel_script(evsel)->val = val; evsel_script(evsel)->val = val;
if (evsel_script(leader)->gnum == leader->core.nr_members) { if (evsel_script(leader)->gnum == leader->core.nr_members) {
for_each_group_member (ev2, leader) { for_each_group_member (ev2, leader) {
...@@ -2083,8 +2082,7 @@ static void perf_sample__fprint_metric(struct perf_script *script, ...@@ -2083,8 +2082,7 @@ static void perf_sample__fprint_metric(struct perf_script *script,
evsel_script(ev2)->val, evsel_script(ev2)->val,
sample->cpu, sample->cpu,
&ctx, &ctx,
NULL, NULL);
&rt_stat);
} }
evsel_script(leader)->gnum = 0; evsel_script(leader)->gnum = 0;
} }
......
...@@ -434,7 +434,7 @@ static void process_interval(void) ...@@ -434,7 +434,7 @@ static void process_interval(void)
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
diff_timespec(&rs, &ts, &ref_time); diff_timespec(&rs, &ts, &ref_time);
perf_stat__reset_shadow_per_stat(&rt_stat); perf_stat__reset_shadow_per_stat();
evlist__reset_aggr_stats(evsel_list); evlist__reset_aggr_stats(evsel_list);
if (read_counters(&rs) == 0) if (read_counters(&rs) == 0)
...@@ -910,7 +910,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) ...@@ -910,7 +910,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
evlist__copy_prev_raw_counts(evsel_list); evlist__copy_prev_raw_counts(evsel_list);
evlist__reset_prev_raw_counts(evsel_list); evlist__reset_prev_raw_counts(evsel_list);
evlist__reset_aggr_stats(evsel_list); evlist__reset_aggr_stats(evsel_list);
perf_stat__reset_shadow_per_stat(&rt_stat); perf_stat__reset_shadow_per_stat();
} else { } else {
update_stats(&walltime_nsecs_stats, t1 - t0); update_stats(&walltime_nsecs_stats, t1 - t0);
update_rusage_stats(&ru_stats, &stat_config.ru_data); update_rusage_stats(&ru_stats, &stat_config.ru_data);
......
...@@ -30,8 +30,7 @@ static u64 find_value(const char *name, struct value *values) ...@@ -30,8 +30,7 @@ static u64 find_value(const char *name, struct value *values)
return 0; return 0;
} }
static void load_runtime_stat(struct runtime_stat *st, struct evlist *evlist, static void load_runtime_stat(struct evlist *evlist, struct value *vals)
struct value *vals)
{ {
struct evsel *evsel; struct evsel *evsel;
u64 count; u64 count;
...@@ -39,14 +38,14 @@ static void load_runtime_stat(struct runtime_stat *st, struct evlist *evlist, ...@@ -39,14 +38,14 @@ static void load_runtime_stat(struct runtime_stat *st, struct evlist *evlist,
perf_stat__reset_shadow_stats(); perf_stat__reset_shadow_stats();
evlist__for_each_entry(evlist, evsel) { evlist__for_each_entry(evlist, evsel) {
count = find_value(evsel->name, vals); count = find_value(evsel->name, vals);
perf_stat__update_shadow_stats(evsel, count, 0, st); perf_stat__update_shadow_stats(evsel, count, 0);
if (!strcmp(evsel->name, "duration_time")) if (!strcmp(evsel->name, "duration_time"))
update_stats(&walltime_nsecs_stats, count); update_stats(&walltime_nsecs_stats, count);
} }
} }
static double compute_single(struct rblist *metric_events, struct evlist *evlist, static double compute_single(struct rblist *metric_events, struct evlist *evlist,
struct runtime_stat *st, const char *name) const char *name)
{ {
struct metric_expr *mexp; struct metric_expr *mexp;
struct metric_event *me; struct metric_event *me;
...@@ -58,7 +57,7 @@ static double compute_single(struct rblist *metric_events, struct evlist *evlist ...@@ -58,7 +57,7 @@ static double compute_single(struct rblist *metric_events, struct evlist *evlist
list_for_each_entry (mexp, &me->head, nd) { list_for_each_entry (mexp, &me->head, nd) {
if (strcmp(mexp->metric_name, name)) if (strcmp(mexp->metric_name, name))
continue; continue;
return test_generic_metric(mexp, 0, st); return test_generic_metric(mexp, 0);
} }
} }
} }
...@@ -74,7 +73,6 @@ static int __compute_metric(const char *name, struct value *vals, ...@@ -74,7 +73,6 @@ static int __compute_metric(const char *name, struct value *vals,
}; };
const struct pmu_metrics_table *pme_test; const struct pmu_metrics_table *pme_test;
struct perf_cpu_map *cpus; struct perf_cpu_map *cpus;
struct runtime_stat st;
struct evlist *evlist; struct evlist *evlist;
int err; int err;
...@@ -93,7 +91,6 @@ static int __compute_metric(const char *name, struct value *vals, ...@@ -93,7 +91,6 @@ static int __compute_metric(const char *name, struct value *vals,
} }
perf_evlist__set_maps(&evlist->core, cpus, NULL); perf_evlist__set_maps(&evlist->core, cpus, NULL);
runtime_stat__init(&st);
/* Parse the metric into metric_events list. */ /* Parse the metric into metric_events list. */
pme_test = find_core_metrics_table("testarch", "testcpu"); pme_test = find_core_metrics_table("testarch", "testcpu");
...@@ -107,18 +104,17 @@ static int __compute_metric(const char *name, struct value *vals, ...@@ -107,18 +104,17 @@ static int __compute_metric(const char *name, struct value *vals,
goto out; goto out;
/* Load the runtime stats with given numbers for events. */ /* Load the runtime stats with given numbers for events. */
load_runtime_stat(&st, evlist, vals); load_runtime_stat(evlist, vals);
/* And execute the metric */ /* And execute the metric */
if (name1 && ratio1) if (name1 && ratio1)
*ratio1 = compute_single(&metric_events, evlist, &st, name1); *ratio1 = compute_single(&metric_events, evlist, name1);
if (name2 && ratio2) if (name2 && ratio2)
*ratio2 = compute_single(&metric_events, evlist, &st, name2); *ratio2 = compute_single(&metric_events, evlist, name2);
out: out:
/* ... cleanup. */ /* ... cleanup. */
metricgroup__rblist_exit(&metric_events); metricgroup__rblist_exit(&metric_events);
runtime_stat__exit(&st);
evlist__free_stats(evlist); evlist__free_stats(evlist);
perf_cpu_map__put(cpus); perf_cpu_map__put(cpus);
evlist__delete(evlist); evlist__delete(evlist);
...@@ -300,6 +296,7 @@ static int test_metric_group(void) ...@@ -300,6 +296,7 @@ static int test_metric_group(void)
static int test__parse_metric(struct test_suite *test __maybe_unused, int subtest __maybe_unused) static int test__parse_metric(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
{ {
perf_stat__init_shadow_stats();
TEST_ASSERT_VAL("IPC failed", test_ipc() == 0); TEST_ASSERT_VAL("IPC failed", test_ipc() == 0);
TEST_ASSERT_VAL("frontend failed", test_frontend() == 0); TEST_ASSERT_VAL("frontend failed", test_frontend() == 0);
TEST_ASSERT_VAL("DCache_L2 failed", test_dcache_l2() == 0); TEST_ASSERT_VAL("DCache_L2 failed", test_dcache_l2() == 0);
......
...@@ -816,7 +816,6 @@ static int test__parsing_callback(const struct pmu_metric *pm, ...@@ -816,7 +816,6 @@ static int test__parsing_callback(const struct pmu_metric *pm,
int k; int k;
struct evlist *evlist; struct evlist *evlist;
struct perf_cpu_map *cpus; struct perf_cpu_map *cpus;
struct runtime_stat st;
struct evsel *evsel; struct evsel *evsel;
struct rblist metric_events = { struct rblist metric_events = {
.nr_entries = 0, .nr_entries = 0,
...@@ -844,7 +843,6 @@ static int test__parsing_callback(const struct pmu_metric *pm, ...@@ -844,7 +843,6 @@ static int test__parsing_callback(const struct pmu_metric *pm,
} }
perf_evlist__set_maps(&evlist->core, cpus, NULL); perf_evlist__set_maps(&evlist->core, cpus, NULL);
runtime_stat__init(&st);
err = metricgroup__parse_groups_test(evlist, table, pm->metric_name, &metric_events); err = metricgroup__parse_groups_test(evlist, table, pm->metric_name, &metric_events);
if (err) { if (err) {
...@@ -867,7 +865,7 @@ static int test__parsing_callback(const struct pmu_metric *pm, ...@@ -867,7 +865,7 @@ static int test__parsing_callback(const struct pmu_metric *pm,
k = 1; k = 1;
perf_stat__reset_shadow_stats(); perf_stat__reset_shadow_stats();
evlist__for_each_entry(evlist, evsel) { evlist__for_each_entry(evlist, evsel) {
perf_stat__update_shadow_stats(evsel, k, 0, &st); perf_stat__update_shadow_stats(evsel, k, 0);
if (!strcmp(evsel->name, "duration_time")) if (!strcmp(evsel->name, "duration_time"))
update_stats(&walltime_nsecs_stats, k); update_stats(&walltime_nsecs_stats, k);
k++; k++;
...@@ -881,7 +879,7 @@ static int test__parsing_callback(const struct pmu_metric *pm, ...@@ -881,7 +879,7 @@ static int test__parsing_callback(const struct pmu_metric *pm,
list_for_each_entry (mexp, &me->head, nd) { list_for_each_entry (mexp, &me->head, nd) {
if (strcmp(mexp->metric_name, pm->metric_name)) if (strcmp(mexp->metric_name, pm->metric_name))
continue; continue;
pr_debug("Result %f\n", test_generic_metric(mexp, 0, &st)); pr_debug("Result %f\n", test_generic_metric(mexp, 0));
err = 0; err = 0;
(*failures)--; (*failures)--;
goto out_err; goto out_err;
...@@ -896,7 +894,6 @@ static int test__parsing_callback(const struct pmu_metric *pm, ...@@ -896,7 +894,6 @@ static int test__parsing_callback(const struct pmu_metric *pm,
/* ... cleanup. */ /* ... cleanup. */
metricgroup__rblist_exit(&metric_events); metricgroup__rblist_exit(&metric_events);
runtime_stat__exit(&st);
evlist__free_stats(evlist); evlist__free_stats(evlist);
perf_cpu_map__put(cpus); perf_cpu_map__put(cpus);
evlist__delete(evlist); evlist__delete(evlist);
...@@ -908,6 +905,7 @@ static int test__parsing(struct test_suite *test __maybe_unused, ...@@ -908,6 +905,7 @@ static int test__parsing(struct test_suite *test __maybe_unused,
{ {
int failures = 0; int failures = 0;
perf_stat__init_shadow_stats();
pmu_for_each_core_metric(test__parsing_callback, &failures); pmu_for_each_core_metric(test__parsing_callback, &failures);
pmu_for_each_sys_metric(test__parsing_callback, &failures); pmu_for_each_sys_metric(test__parsing_callback, &failures);
......
...@@ -729,7 +729,7 @@ static void printout(struct perf_stat_config *config, struct outstate *os, ...@@ -729,7 +729,7 @@ static void printout(struct perf_stat_config *config, struct outstate *os,
if (ok) { if (ok) {
perf_stat__print_shadow_stats(config, counter, uval, map_idx, perf_stat__print_shadow_stats(config, counter, uval, map_idx,
&out, &config->metric_events, &rt_stat); &out, &config->metric_events);
} else { } else {
pm(config, os, /*color=*/NULL, /*format=*/NULL, /*unit=*/"", /*val=*/0); pm(config, os, /*color=*/NULL, /*format=*/NULL, /*unit=*/"", /*val=*/0);
} }
...@@ -1089,8 +1089,7 @@ static void print_metric_headers(struct perf_stat_config *config, ...@@ -1089,8 +1089,7 @@ static void print_metric_headers(struct perf_stat_config *config,
perf_stat__print_shadow_stats(config, counter, 0, perf_stat__print_shadow_stats(config, counter, 0,
0, 0,
&out, &out,
&config->metric_events, &config->metric_events);
&rt_stat);
} }
if (!config->json_output) if (!config->json_output)
......
This diff is collapsed.
...@@ -659,7 +659,7 @@ static void evsel__update_shadow_stats(struct evsel *evsel) ...@@ -659,7 +659,7 @@ static void evsel__update_shadow_stats(struct evsel *evsel)
for (i = 0; i < ps->nr_aggr; i++) { for (i = 0; i < ps->nr_aggr; i++) {
struct perf_counts_values *aggr_counts = &ps->aggr[i].counts; struct perf_counts_values *aggr_counts = &ps->aggr[i].counts;
perf_stat__update_shadow_stats(evsel, aggr_counts->val, i, &rt_stat); perf_stat__update_shadow_stats(evsel, aggr_counts->val, i);
} }
} }
......
...@@ -55,10 +55,6 @@ enum aggr_mode { ...@@ -55,10 +55,6 @@ enum aggr_mode {
AGGR_MAX AGGR_MAX
}; };
struct runtime_stat {
struct rblist value_list;
};
struct rusage_stats { struct rusage_stats {
struct stats ru_utime_usec_stat; struct stats ru_utime_usec_stat;
struct stats ru_stime_usec_stat; struct stats ru_stime_usec_stat;
...@@ -153,7 +149,6 @@ static inline void update_rusage_stats(struct rusage_stats *ru_stats, struct rus ...@@ -153,7 +149,6 @@ static inline void update_rusage_stats(struct rusage_stats *ru_stats, struct rus
struct evsel; struct evsel;
struct evlist; struct evlist;
extern struct runtime_stat rt_stat;
extern struct stats walltime_nsecs_stats; extern struct stats walltime_nsecs_stats;
extern struct rusage_stats ru_stats; extern struct rusage_stats ru_stats;
...@@ -162,13 +157,10 @@ typedef void (*print_metric_t)(struct perf_stat_config *config, ...@@ -162,13 +157,10 @@ typedef void (*print_metric_t)(struct perf_stat_config *config,
const char *fmt, double val); const char *fmt, double val);
typedef void (*new_line_t)(struct perf_stat_config *config, void *ctx); typedef void (*new_line_t)(struct perf_stat_config *config, void *ctx);
void runtime_stat__init(struct runtime_stat *st);
void runtime_stat__exit(struct runtime_stat *st);
void perf_stat__init_shadow_stats(void); void perf_stat__init_shadow_stats(void);
void perf_stat__reset_shadow_stats(void); void perf_stat__reset_shadow_stats(void);
void perf_stat__reset_shadow_per_stat(struct runtime_stat *st); void perf_stat__reset_shadow_per_stat(void);
void perf_stat__update_shadow_stats(struct evsel *counter, u64 count, void perf_stat__update_shadow_stats(struct evsel *counter, u64 count, int map_idx);
int map_idx, struct runtime_stat *st);
struct perf_stat_output_ctx { struct perf_stat_output_ctx {
void *ctx; void *ctx;
print_metric_t print_metric; print_metric_t print_metric;
...@@ -180,8 +172,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, ...@@ -180,8 +172,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config,
struct evsel *evsel, struct evsel *evsel,
double avg, int map_idx, double avg, int map_idx,
struct perf_stat_output_ctx *out, struct perf_stat_output_ctx *out,
struct rblist *metric_events, struct rblist *metric_events);
struct runtime_stat *st);
int evlist__alloc_stats(struct perf_stat_config *config, int evlist__alloc_stats(struct perf_stat_config *config,
struct evlist *evlist, bool alloc_raw); struct evlist *evlist, bool alloc_raw);
...@@ -220,5 +211,5 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf ...@@ -220,5 +211,5 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf
struct target *_target, struct timespec *ts, int argc, const char **argv); struct target *_target, struct timespec *ts, int argc, const char **argv);
struct metric_expr; struct metric_expr;
double test_generic_metric(struct metric_expr *mexp, int map_idx, struct runtime_stat *st); double test_generic_metric(struct metric_expr *mexp, int map_idx);
#endif #endif
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