Commit c23f5cc0 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo
Browse files

perf stat: Use metrics for --smi-cost



Rather than parsing events for --smi-cost, use the json metric group
'smi'.

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-45-irogers@google.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent d6964c5b
Loading
Loading
Loading
Loading
+11 −23
Original line number Original line Diff line number Diff line
@@ -100,14 +100,6 @@


static void print_counters(struct timespec *ts, int argc, const char **argv);
static void print_counters(struct timespec *ts, int argc, const char **argv);


static const char *smi_cost_attrs = {
	"{"
	"msr/aperf/,"
	"msr/smi/,"
	"cycles"
	"}"
};

static struct evlist	*evsel_list;
static struct evlist	*evsel_list;
static bool all_counters_use_bpf = true;
static bool all_counters_use_bpf = true;


@@ -1666,7 +1658,6 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
 */
 */
static int add_default_attributes(void)
static int add_default_attributes(void)
{
{
	int err;
	struct perf_event_attr default_attrs0[] = {
	struct perf_event_attr default_attrs0[] = {


  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK		},
  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK		},
@@ -1806,11 +1797,10 @@ static int add_default_attributes(void)
	}
	}


	if (smi_cost) {
	if (smi_cost) {
		struct parse_events_error errinfo;
		int smi;
		int smi;


		if (sysfs__read_int(FREEZE_ON_SMI_PATH, &smi) < 0) {
		if (sysfs__read_int(FREEZE_ON_SMI_PATH, &smi) < 0) {
			fprintf(stderr, "freeze_on_smi is not supported.\n");
			pr_err("freeze_on_smi is not supported.");
			return -1;
			return -1;
		}
		}


@@ -1822,23 +1812,21 @@ static int add_default_attributes(void)
			smi_reset = true;
			smi_reset = true;
		}
		}


		if (!pmu_have_event("msr", "aperf") ||
		if (!metricgroup__has_metric("smi")) {
		    !pmu_have_event("msr", "smi")) {
			pr_err("Missing smi metrics");
			fprintf(stderr, "To measure SMI cost, it needs "
				"msr/aperf/, msr/smi/ and cpu/cycles/ support\n");
			return -1;
			return -1;
		}
		}

		if (!force_metric_only)
		if (!force_metric_only)
			stat_config.metric_only = true;
			stat_config.metric_only = true;


		parse_events_error__init(&errinfo);
		return metricgroup__parse_groups(evsel_list, "smi",
		err = parse_events(evsel_list, smi_cost_attrs, &errinfo);
						stat_config.metric_no_group,
		if (err) {
						stat_config.metric_no_merge,
			parse_events_error__print(&errinfo, smi_cost_attrs);
						stat_config.metric_no_threshold,
			fprintf(stderr, "Cannot set up SMI cost events\n");
						stat_config.user_requested_cpu_list,
		}
						stat_config.system_wide,
		parse_events_error__exit(&errinfo);
						&stat_config.metric_events);
		return err ? -1 : 0;
	}
	}


	if (topdown_run) {
	if (topdown_run) {
+0 −30
Original line number Original line Diff line number Diff line
@@ -255,10 +255,6 @@ void perf_stat__update_shadow_stats(struct evsel *counter, u64 count,
		update_runtime_stat(st, STAT_DTLB_CACHE, map_idx, count, &rsd);
		update_runtime_stat(st, STAT_DTLB_CACHE, map_idx, count, &rsd);
	else if (evsel__match(counter, HW_CACHE, HW_CACHE_ITLB))
	else if (evsel__match(counter, HW_CACHE, HW_CACHE_ITLB))
		update_runtime_stat(st, STAT_ITLB_CACHE, map_idx, count, &rsd);
		update_runtime_stat(st, STAT_ITLB_CACHE, map_idx, count, &rsd);
	else if (perf_stat_evsel__is(counter, SMI_NUM))
		update_runtime_stat(st, STAT_SMI_NUM, map_idx, count, &rsd);
	else if (perf_stat_evsel__is(counter, APERF))
		update_runtime_stat(st, STAT_APERF, map_idx, count, &rsd);


	if (counter->collect_stat) {
	if (counter->collect_stat) {
		v = saved_value_lookup(counter, map_idx, true, STAT_NONE, 0, st,
		v = saved_value_lookup(counter, map_idx, true, STAT_NONE, 0, st,
@@ -479,30 +475,6 @@ static void print_ll_cache_misses(struct perf_stat_config *config,
	out->print_metric(config, out->ctx, color, "%7.2f%%", "of all LL-cache accesses", ratio);
	out->print_metric(config, out->ctx, color, "%7.2f%%", "of all LL-cache accesses", ratio);
}
}


static void print_smi_cost(struct perf_stat_config *config, int map_idx,
			   struct perf_stat_output_ctx *out,
			   struct runtime_stat *st,
			   struct runtime_stat_data *rsd)
{
	double smi_num, aperf, cycles, cost = 0.0;
	const char *color = NULL;

	smi_num = runtime_stat_avg(st, STAT_SMI_NUM, map_idx, rsd);
	aperf = runtime_stat_avg(st, STAT_APERF, map_idx, rsd);
	cycles = runtime_stat_avg(st, STAT_CYCLES, map_idx, rsd);

	if ((cycles == 0) || (aperf == 0))
		return;

	if (smi_num)
		cost = (aperf - cycles) / aperf * 100.00;

	if (cost > 10)
		color = PERF_COLOR_RED;
	out->print_metric(config, out->ctx, color, "%8.1f%%", "SMI cycles%", cost);
	out->print_metric(config, out->ctx, NULL, "%4.0f", "SMI#", smi_num);
}

static int prepare_metric(struct evsel **metric_events,
static int prepare_metric(struct evsel **metric_events,
			  struct metric_ref *metric_refs,
			  struct metric_ref *metric_refs,
			  struct expr_parse_ctx *pctx,
			  struct expr_parse_ctx *pctx,
@@ -819,8 +791,6 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config,
		if (unit != ' ')
		if (unit != ' ')
			snprintf(unit_buf, sizeof(unit_buf), "%c/sec", unit);
			snprintf(unit_buf, sizeof(unit_buf), "%c/sec", unit);
		print_metric(config, ctxp, NULL, "%8.3f", unit_buf, ratio);
		print_metric(config, ctxp, NULL, "%8.3f", unit_buf, ratio);
	} else if (perf_stat_evsel__is(evsel, SMI_NUM)) {
		print_smi_cost(config, map_idx, out, st, &rsd);
	} else {
	} else {
		num = 0;
		num = 0;
	}
	}
+0 −2
Original line number Original line Diff line number Diff line
@@ -87,8 +87,6 @@ bool __perf_stat_evsel__is(struct evsel *evsel, enum perf_stat_evsel_id id)
#define ID(id, name) [PERF_STAT_EVSEL_ID__##id] = #name
#define ID(id, name) [PERF_STAT_EVSEL_ID__##id] = #name
static const char *id_str[PERF_STAT_EVSEL_ID__MAX] = {
static const char *id_str[PERF_STAT_EVSEL_ID__MAX] = {
	ID(NONE,		x),
	ID(NONE,		x),
	ID(SMI_NUM, msr/smi/),
	ID(APERF, msr/aperf/),
};
};
#undef ID
#undef ID


+0 −4
Original line number Original line Diff line number Diff line
@@ -21,8 +21,6 @@ struct stats {


enum perf_stat_evsel_id {
enum perf_stat_evsel_id {
	PERF_STAT_EVSEL_ID__NONE = 0,
	PERF_STAT_EVSEL_ID__NONE = 0,
	PERF_STAT_EVSEL_ID__SMI_NUM,
	PERF_STAT_EVSEL_ID__APERF,
	PERF_STAT_EVSEL_ID__MAX,
	PERF_STAT_EVSEL_ID__MAX,
};
};


@@ -88,8 +86,6 @@ enum stat_type {
	STAT_LL_CACHE,
	STAT_LL_CACHE,
	STAT_ITLB_CACHE,
	STAT_ITLB_CACHE,
	STAT_DTLB_CACHE,
	STAT_DTLB_CACHE,
	STAT_SMI_NUM,
	STAT_APERF,
	STAT_MAX
	STAT_MAX
};
};