[RFC PATCH v8 4/7] perf stat: Add retire latency values into the expr_parse_ctx to prepare for final metric calculation

weilin.wang@intel.com posted 7 patches 1 year, 9 months ago
There is a newer version of this series
[RFC PATCH v8 4/7] perf stat: Add retire latency values into the expr_parse_ctx to prepare for final metric calculation
Posted by weilin.wang@intel.com 1 year, 9 months ago
From: Weilin Wang <weilin.wang@intel.com>

Retire latency values of events are used in metric formulas. This update adds
code to process data from perf record for required retire latency values.

Signed-off-by: Weilin Wang <weilin.wang@intel.com>
Reviewed-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/stat-shadow.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index 3466aa952442..b97d23bfeac1 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -15,6 +15,7 @@
 #include <linux/zalloc.h>
 #include "iostat.h"
 #include "util/hashmap.h"
+#include "util/intel-tpebs.h"
 
 struct stats walltime_nsecs_stats;
 struct rusage_stats ru_stats;
@@ -355,6 +356,20 @@ static void print_nsecs(struct perf_stat_config *config,
 		print_metric(config, ctxp, NULL, NULL, "CPUs utilized", 0);
 }
 
+static int prepare_retire_lat(struct expr_parse_ctx *pctx,
+			     struct list_head *retire_lats)
+{
+	int ret = 0;
+	struct tpebs_retire_lat *t;
+
+	list_for_each_entry(t, retire_lats, nd) {
+		ret = expr__add_id_val(pctx, strdup(t->tpebs_name), t->val);
+		if (ret < 0)
+			return ret;
+	}
+	return ret;
+}
+
 static int prepare_metric(const struct metric_expr *mexp,
 			  const struct evsel *evsel,
 			  struct expr_parse_ctx *pctx,
@@ -369,6 +384,9 @@ static int prepare_metric(const struct metric_expr *mexp,
 		double val;
 		int source_count = 0;
 
+		if (metric_events[i]->retire_lat)
+			continue;
+
 		if (evsel__is_tool(metric_events[i])) {
 			struct stats *stats;
 			double scale;
@@ -486,6 +504,11 @@ static void generic_metric(struct perf_stat_config *config,
 		pctx->sctx.user_requested_cpu_list = strdup(config->user_requested_cpu_list);
 	pctx->sctx.runtime = runtime;
 	pctx->sctx.system_wide = config->system_wide;
+	i = prepare_retire_lat(pctx, &config->tpebs_results);
+	if (i < 0) {
+		expr__ctx_free(pctx);
+		return;
+	}
 	i = prepare_metric(mexp, evsel, pctx, aggr_idx);
 	if (i < 0) {
 		expr__ctx_free(pctx);
-- 
2.43.0
Re: [RFC PATCH v8 4/7] perf stat: Add retire latency values into the expr_parse_ctx to prepare for final metric calculation
Posted by Ian Rogers 1 year, 9 months ago
On Tue, May 14, 2024 at 10:44 PM <weilin.wang@intel.com> wrote:
>
> From: Weilin Wang <weilin.wang@intel.com>
>
> Retire latency values of events are used in metric formulas. This update adds
> code to process data from perf record for required retire latency values.
>
> Signed-off-by: Weilin Wang <weilin.wang@intel.com>
> Reviewed-by: Ian Rogers <irogers@google.com>

In the evsel approach:
https://lore.kernel.org/lkml/20240428053616.1125891-1-irogers@google.com/
we don't need to special case tpebs events like this. I'd prefer we
went that route. My reviewed-by no longer stands.

Thanks,
Ian

> ---
>  tools/perf/util/stat-shadow.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
> index 3466aa952442..b97d23bfeac1 100644
> --- a/tools/perf/util/stat-shadow.c
> +++ b/tools/perf/util/stat-shadow.c
> @@ -15,6 +15,7 @@
>  #include <linux/zalloc.h>
>  #include "iostat.h"
>  #include "util/hashmap.h"
> +#include "util/intel-tpebs.h"
>
>  struct stats walltime_nsecs_stats;
>  struct rusage_stats ru_stats;
> @@ -355,6 +356,20 @@ static void print_nsecs(struct perf_stat_config *config,
>                 print_metric(config, ctxp, NULL, NULL, "CPUs utilized", 0);
>  }
>
> +static int prepare_retire_lat(struct expr_parse_ctx *pctx,
> +                            struct list_head *retire_lats)
> +{
> +       int ret = 0;
> +       struct tpebs_retire_lat *t;
> +
> +       list_for_each_entry(t, retire_lats, nd) {
> +               ret = expr__add_id_val(pctx, strdup(t->tpebs_name), t->val);
> +               if (ret < 0)
> +                       return ret;
> +       }
> +       return ret;
> +}
> +
>  static int prepare_metric(const struct metric_expr *mexp,
>                           const struct evsel *evsel,
>                           struct expr_parse_ctx *pctx,
> @@ -369,6 +384,9 @@ static int prepare_metric(const struct metric_expr *mexp,
>                 double val;
>                 int source_count = 0;
>
> +               if (metric_events[i]->retire_lat)
> +                       continue;
> +
>                 if (evsel__is_tool(metric_events[i])) {
>                         struct stats *stats;
>                         double scale;
> @@ -486,6 +504,11 @@ static void generic_metric(struct perf_stat_config *config,
>                 pctx->sctx.user_requested_cpu_list = strdup(config->user_requested_cpu_list);
>         pctx->sctx.runtime = runtime;
>         pctx->sctx.system_wide = config->system_wide;
> +       i = prepare_retire_lat(pctx, &config->tpebs_results);
> +       if (i < 0) {
> +               expr__ctx_free(pctx);
> +               return;
> +       }
>         i = prepare_metric(mexp, evsel, pctx, aggr_idx);
>         if (i < 0) {
>                 expr__ctx_free(pctx);
> --
> 2.43.0
>