powerpc/perf: Add json file metric support for the hv_24x7 socket/chip level events
v8 cover powerpc/perf: Add json file metric support for the hv_24x7 socket/chip level events
Patchset adds json file metric support for the hv_24x7 socket/chip level events. "hv_24x7" pmu interface events needs system dependent parameter like socket/chip/core. For example, hv_24x7 chip level events needs specific chip-id to which the data is requested should be added as part of pmu events.
So to enable JSON file support to "hv_24x7" interface, patchset reads total number of sockets details in sysfs under "/sys/devices/hv_24x7/interface/".
Second patch of the patchset adds expr_scanner_ctx object to hold user data for the expr scanner, which can be used to hold runtime parameter.
Patch 4 & 6 of the patchset handles perf tool plumbing needed to replace the "?" character in the metric expression to proper value and hv_24x7 json metric file for different Socket/chip resources.
Patch set also enable Hz/hz prinitg for --metric-only option to print metric data for bus frequency.
Applied and tested all these patches cleanly on top of jiri's flex changes with the changes done by Kan Liang for "Support metric group constraint" patchset and made required changes.
Also apply this patch on top of the fix patch send earlier for printing metric name incase overlapping events.
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=perf/core&id=37cd7f65bf71a48f25eeb6d9be5dacb20d008ea6
Changelog:
v7 -> v8
- Add test case for testing parsing of "?" in metric expression
- Reaname variables name to runtime
v6 -> v7
- Spit patchset into two patch series one for kernel changes and other for tool side changes.
- Made changes Suggested by Jiri, including rather then reading runtime parameter from metric name, actually add it in structure egroup and metric_expr.
- As we don't need to read runtime parameter from metric name, now I am not appending it and rather just printing it in generic_metric function.
Kernel Side changes patch series: https://lkml.org/lkml/2020/3/27/58
v5 -> v6
- resolve compilation issue due to rearranging patch series.
- Rather then adding new function to take careof case for runtime param in metricgroup__add_metric, using metricgroup__add_metric_param itself for that work.
- Address some optimization suggested like using directly file path rather then adding new macro in header.c
- Change commit message on patch where we are adding "?" support by adding simple example.
v4 -> v5
- Using sysfs__read_int instead of sysfs__read_ull while reading parameter value in powerpc/util/header.c file.
- Using asprintf rather then malloc and sprintf
Suggested by Arnaldo Carvalho de Melo
- Break patch 6 from previous version to two patch,
- One to add refactor current "metricgroup__add_metric" function and another where actually "?" handling infra added.
- Add expr__runtimeparam as part of 'expr_scanner_ctx' struct rather then making it global variable. Thanks Jiri for adding this structure to hold user data for the expr scanner.
- Add runtime param as agrugement to function 'expr__find_other' and 'expr__parse' and made changes on references accordingly.
v3 -> v4
- Apply these patch on top of Kan liang changes.
As suggested by Jiri.
v2 -> v3
- Remove setting event_count to 0 part in function 'h_24x7_event_read' with comment rather then adding 0 to event_count value. Suggested by: Sukadev Bhattiprolu
- Apply tool side changes require to replace "?" on Jiri's flex patch series and made all require changes to make it compatible with added flex change.
v1 -> v2
- Rename hv-24x7 metric json file as nest_metrics.json
Jiri Olsa (2):
perf expr: Add expr_ prefix for parse_ctx and parse_id perf expr: Add expr_scanner_ctx object
Kajol Jain (5):
perf/tools: Refactoring metricgroup__add_metric function perf/tools: Enhance JSON/metric infrastructure to handle "?" perf/tests/expr: Added test for runtime param in metric expression tools/perf: Enable Hz/hz prinitg for --metric-only option perf/tools/pmu-events/powerpc: Add hv_24x7 socket/chip level metric
events
tools/perf/arch/powerpc/util/header.c | 8 ++ .../arch/powerpc/power9/nest_metrics.json | 19 +++++ tools/perf/tests/expr.c | 20 +++-- tools/perf/util/expr.c | 25 +++--- tools/perf/util/expr.h | 19 +++-- tools/perf/util/expr.l | 37 ++++++--- tools/perf/util/expr.y | 6 +- tools/perf/util/metricgroup.c | 78 +++++++++++++------ tools/perf/util/metricgroup.h | 2 + tools/perf/util/stat-display.c | 2 - tools/perf/util/stat-shadow.c | 19 +++-- 11 files changed, 164 insertions(+), 71 deletions(-) create mode 100644 tools/perf/pmu-events/arch/powerpc/power9/nest_metrics.json
Signature · 1 line
2.21.0
PATCH v8 1/7 perf expr: Add expr_ prefix for parse_ctx and parse_id
From: Jiri Olsa <[email protected]>
Adding expr_ prefix for parse_ctx and parse_id,
to straighten out the expr* namespace.
There's no functional change.
--- tools/perf/tests/expr.c | 4 ++-- tools/perf/util/expr.c | 10 +++++----- tools/perf/util/expr.h | 12 ++++++------ tools/perf/util/expr.y | 6 +++--- tools/perf/util/stat-shadow.c | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-)
tools/perf/tests/expr.c +2 -2
@@ -6,7 +6,7 @@#include <string.h> #include <linux/zalloc.h> -static int test (struct parse_ctx *ctx,const char *e,double val2) +static int test (struct expr_parse_ctx *ctx,const char *e,double val2) {double val;
@@ -22,7 +22,7 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)const char **other;double val;int i, ret; -struct parse_ctx ctx; +struct expr_parse_ctx ctx;int num_other;expr__ctx_init (&ctx);
tools/perf/util/expr.c +5 -5
@@ -11,7 +11,7 @@ extern int expr_debug;#endif /* Caller must make sure id is allocated */ -void expr__add_id (struct parse_ctx *ctx,const char *name,double val) +void expr__add_id (struct expr_parse_ctx *ctx,const char *name,double val) {int idx;
@@ -21,13 +21,13 @@ void expr__add_id(struct parse_ctx *ctx, const char *name, double val) ctx->ids[idx].val = val; } -void expr__ctx_init (struct parse_ctx *ctx) +void expr__ctx_init (struct expr_parse_ctx *ctx) { ctx->num_ids =0 ; }static int -__expr__parse (double *val,struct parse_ctx *ctx,const char *expr, +__expr__parse (double *val,struct expr_parse_ctx *ctx,const char *expr,int start) {YY_BUFFER_STATE buffer;
@@ -52,7 +52,7 @@ __expr__parse(double *val, struct parse_ctx *ctx, const char *expr,return ret; } -int expr__parse (double *final_val,struct parse_ctx *ctx,const char *expr) +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr) {return __expr__parse (final_val, ctx, expr,EXPR_PARSE ) ?-1 :0 ; }
@@ -75,7 +75,7 @@ int expr__find_other(const char *expr, const char *one, const char ***other, int *num_other) {int err, i =0 , j =0 ; -struct parse_ctx ctx; +struct expr_parse_ctx ctx;expr__ctx_init (&ctx); err =__expr__parse (NULL , &ctx, expr,EXPR_OTHER );
tools/perf/util/expr.h +6 -6
@@ -5,19 +5,19 @@#define EXPR_MAX_OTHER 20#define MAX_PARSE_ID EXPR_MAX_OTHER -struct parse_id { +struct expr_parse_id {const char *name;double val; }; -struct parse_ctx { +struct expr_parse_ctx {int num_ids; -struct parse_id ids[MAX_PARSE_ID ]; +struct expr_parse_id ids[MAX_PARSE_ID ]; }; -void expr__ctx_init (struct parse_ctx *ctx); -void expr__add_id (struct parse_ctx *ctx,const char *id,double val); -int expr__parse (double *final_val,struct parse_ctx *ctx,const char *expr); +void expr__ctx_init (struct expr_parse_ctx *ctx); +void expr__add_id (struct expr_parse_ctx *ctx,const char *id,double val); +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr);int expr__find_other (const char *expr,const char *one,const char ***other,int *num_other);
tools/perf/util/expr.y +3 -3
@@ -15,7 +15,7 @@ %define api.pure full %parse-param { double *final_val } -%parse-param { struct parse_ctx *ctx } +%parse-param { struct expr_parse_ctx *ctx } %parse-param {void *scanner} %lex-param {void* scanner}
@@ -39,14 +39,14 @@ %{ static void expr_error(double *final_val __maybe_unused, - struct parse_ctx *ctx __maybe_unused, + struct expr_parse_ctx *ctx __maybe_unused, void *scanner, const char *s) { pr_debug("%s\n", s); } -static int lookup_id(struct parse_ctx *ctx, char *id, double *val) +static int lookup_id(struct expr_parse_ctx *ctx, char *id, double *val) { int i;
tools/perf/util/stat-shadow.c +1 -1
@@ -729,7 +729,7 @@ static void generic_metric(struct perf_stat_config *config, struct runtime_stat *st) {print_metric_t print_metric = out->print_metric; -struct parse_ctx pctx; +struct expr_parse_ctx pctx;double ratio, scale;int i;void *ctxp = out->ctx;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
AppliedRe: [PATCH v8 1/7] perf expr: Add expr_ prefix for parse_ctx and parse_id
Em Thu, Apr 02, 2020 at 02:03:34AM +0530, Kajol Jain escreveu:
Quoted 6 lines
From: Jiri Olsa <[email protected]>
Adding
expr_prefix forparse_ctxandparse_id,
to straighten out the expr* namespace.There's no functional change.
Next time please add your Signed-off-by: as well when pushing 3rd party patches.
Applied.
- Arnaldo
Quoted 154 lines
Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/tests/expr.c | 4 ++-- tools/perf/util/expr.c | 10 +++++----- tools/perf/util/expr.h | 12 ++++++------ tools/perf/util/expr.y | 6 +++--- tools/perf/util/stat-shadow.c | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-)tools/perf/tests/expr.c +2
-2@@ -6,7 +6,7 @@#include <string.h> #include <linux/zalloc.h> -static int test (struct parse_ctx *ctx,const char *e,double val2) +static int test (struct expr_parse_ctx *ctx,const char *e,double val2) {double val;@@ -22,7 +22,7 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)const char **other;double val;int i, ret; -struct parse_ctx ctx; +struct expr_parse_ctx ctx;int num_other;expr__ctx_init (&ctx);tools/perf/util/expr.c +5
-5@@ -11,7 +11,7 @@ extern int expr_debug;#endif /* Caller must make sure id is allocated */ -void expr__add_id (struct parse_ctx *ctx,const char *name,double val) +void expr__add_id (struct expr_parse_ctx *ctx,const char *name,double val) {int idx;@@ -21,13 +21,13 @@ void expr__add_id(struct parse_ctx *ctx, const char *name, double val) ctx->ids[idx].val = val; } -void expr__ctx_init (struct parse_ctx *ctx) +void expr__ctx_init (struct expr_parse_ctx *ctx) { ctx->num_ids =0 ; }static int -__expr__parse (double *val,struct parse_ctx *ctx,const char *expr, +__expr__parse (double *val,struct expr_parse_ctx *ctx,const char *expr,int start) {YY_BUFFER_STATE buffer;@@ -52,7 +52,7 @@ __expr__parse(double *val, struct parse_ctx *ctx, const char *expr,return ret; } -int expr__parse (double *final_val,struct parse_ctx *ctx,const char *expr) +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr) {return __expr__parse (final_val, ctx, expr,EXPR_PARSE ) ?-1 :0 ; }@@ -75,7 +75,7 @@ int expr__find_other(const char *expr, const char *one, const char ***other, int *num_other) {int err, i =0 , j =0 ; -struct parse_ctx ctx; +struct expr_parse_ctx ctx;expr__ctx_init (&ctx); err =__expr__parse (NULL , &ctx, expr,EXPR_OTHER );tools/perf/util/expr.h +6
-6@@ -5,19 +5,19 @@#define EXPR_MAX_OTHER 20#define MAX_PARSE_ID EXPR_MAX_OTHER -struct parse_id { +struct expr_parse_id {const char *name;double val; }; -struct parse_ctx { +struct expr_parse_ctx {int num_ids; -struct parse_id ids[MAX_PARSE_ID ]; +struct expr_parse_id ids[MAX_PARSE_ID ]; }; -void expr__ctx_init (struct parse_ctx *ctx); -void expr__add_id (struct parse_ctx *ctx,const char *id,double val); -int expr__parse (double *final_val,struct parse_ctx *ctx,const char *expr); +void expr__ctx_init (struct expr_parse_ctx *ctx); +void expr__add_id (struct expr_parse_ctx *ctx,const char *id,double val); +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr);int expr__find_other (const char *expr,const char *one,const char ***other,int *num_other);tools/perf/util/expr.y +3
-3@@ -15,7 +15,7 @@ %define api.pure full %parse-param { double *final_val } -%parse-param { struct parse_ctx *ctx } +%parse-param { struct expr_parse_ctx *ctx } %parse-param {void *scanner} %lex-param {void* scanner}@@ -39,14 +39,14 @@ %{ static void expr_error(double *final_val __maybe_unused, - struct parse_ctx *ctx __maybe_unused, + struct expr_parse_ctx *ctx __maybe_unused, void *scanner, const char *s) { pr_debug("%s\n", s); } -static int lookup_id(struct parse_ctx *ctx, char *id, double *val) +static int lookup_id(struct expr_parse_ctx *ctx, char *id, double *val) { int i;tools/perf/util/stat-shadow.c +1
-1@@ -729,7 +729,7 @@ static void generic_metric(struct perf_stat_config *config, struct runtime_stat *st) {print_metric_t print_metric = out->print_metric; -struct parse_ctx pctx; +struct expr_parse_ctx pctx;double ratio, scale;int i;void *ctxp = out->ctx;Signature · 1 line
2.21.0
Signature · 1 line
- Arnaldo
Re: [PATCH v8 1/7] perf expr: Add expr_ prefix for parse_ctx and parse_id
Quoted 6 lines · Arnaldo Carvalho de Melo
Em Thu, Apr 02, 2020 at 02:03:34AM +0530, Kajol Jain escreveu:
Quoted 5 lines
From: Jiri Olsa <[email protected]>
Adding
expr_prefix forparse_ctxandparse_id,
to straighten out the expr* namespace.
Quoted 8 lines
Quoted 1 line
There's no functional change.
Next time please add your Signed-off-by: as well when pushing 3rd party patches.
Applied.
- Arnaldo
Hi Arnaldo,
Thanks, I will take care of it next time.
Regards,
Kajol
Quoted 156 lines
Quoted 155 lines
Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/tests/expr.c | 4 ++-- tools/perf/util/expr.c | 10 +++++----- tools/perf/util/expr.h | 12 ++++++------ tools/perf/util/expr.y | 6 +++--- tools/perf/util/stat-shadow.c | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-)tools/perf/tests/expr.c +2
-2@@ -6,7 +6,7 @@#include <string.h> #include <linux/zalloc.h> -static int test (struct parse_ctx *ctx,const char *e,double val2) +static int test (struct expr_parse_ctx *ctx,const char *e,double val2) {double val;@@ -22,7 +22,7 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)const char **other;double val;int i, ret; -struct parse_ctx ctx; +struct expr_parse_ctx ctx;int num_other;expr__ctx_init (&ctx);tools/perf/util/expr.c +5
-5@@ -11,7 +11,7 @@ extern int expr_debug;#endif /* Caller must make sure id is allocated */ -void expr__add_id (struct parse_ctx *ctx,const char *name,double val) +void expr__add_id (struct expr_parse_ctx *ctx,const char *name,double val) {int idx;@@ -21,13 +21,13 @@ void expr__add_id(struct parse_ctx *ctx, const char *name, double val) ctx->ids[idx].val = val; } -void expr__ctx_init (struct parse_ctx *ctx) +void expr__ctx_init (struct expr_parse_ctx *ctx) { ctx->num_ids =0 ; }static int -__expr__parse (double *val,struct parse_ctx *ctx,const char *expr, +__expr__parse (double *val,struct expr_parse_ctx *ctx,const char *expr,int start) {YY_BUFFER_STATE buffer;@@ -52,7 +52,7 @@ __expr__parse(double *val, struct parse_ctx *ctx, const char *expr,return ret; } -int expr__parse (double *final_val,struct parse_ctx *ctx,const char *expr) +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr) {return __expr__parse (final_val, ctx, expr,EXPR_PARSE ) ?-1 :0 ; }@@ -75,7 +75,7 @@ int expr__find_other(const char *expr, const char *one, const char ***other, int *num_other) {int err, i =0 , j =0 ; -struct parse_ctx ctx; +struct expr_parse_ctx ctx;expr__ctx_init (&ctx); err =__expr__parse (NULL , &ctx, expr,EXPR_OTHER );tools/perf/util/expr.h +6
-6@@ -5,19 +5,19 @@#define EXPR_MAX_OTHER 20#define MAX_PARSE_ID EXPR_MAX_OTHER -struct parse_id { +struct expr_parse_id {const char *name;double val; }; -struct parse_ctx { +struct expr_parse_ctx {int num_ids; -struct parse_id ids[MAX_PARSE_ID ]; +struct expr_parse_id ids[MAX_PARSE_ID ]; }; -void expr__ctx_init (struct parse_ctx *ctx); -void expr__add_id (struct parse_ctx *ctx,const char *id,double val); -int expr__parse (double *final_val,struct parse_ctx *ctx,const char *expr); +void expr__ctx_init (struct expr_parse_ctx *ctx); +void expr__add_id (struct expr_parse_ctx *ctx,const char *id,double val); +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr);int expr__find_other (const char *expr,const char *one,const char ***other,int *num_other);tools/perf/util/expr.y +3
-3@@ -15,7 +15,7 @@ %define api.pure full %parse-param { double *final_val } -%parse-param { struct parse_ctx *ctx } +%parse-param { struct expr_parse_ctx *ctx } %parse-param {void *scanner} %lex-param {void* scanner}@@ -39,14 +39,14 @@ %{ static void expr_error(double *final_val __maybe_unused, - struct parse_ctx *ctx __maybe_unused, + struct expr_parse_ctx *ctx __maybe_unused, void *scanner, const char *s) { pr_debug("%s\n", s); } -static int lookup_id(struct parse_ctx *ctx, char *id, double *val) +static int lookup_id(struct expr_parse_ctx *ctx, char *id, double *val) { int i;tools/perf/util/stat-shadow.c +1
-1@@ -729,7 +729,7 @@ static void generic_metric(struct perf_stat_config *config, struct runtime_stat *st) {print_metric_t print_metric = out->print_metric; -struct parse_ctx pctx; +struct expr_parse_ctx pctx;double ratio, scale;int i;void *ctxp = out->ctx;Signature · 1 line
2.21.0
[tip: perf/core] perf expr: Add expr_ prefix for parse_ctx and parse_id
In reply to Kajol JainThe following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: aecce63e2b98f28606b063949cca06facf215d6c Gitweb: https://git.kernel.org/tip/aecce63e2b98f28606b063949cca06facf215d6c Author: Jiri Olsa <[email protected]> AuthorDate: Thu, 02 Apr 2020 02:03:34 +05:30 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Thu, 16 Apr 2020 12:19:13 -03:00
perf expr: Add expr_ prefix for parse_ctx and parse_id
Adding expr_ prefix for parse_ctx and parse_id, to straighten out the expr* namespace.
There's no functional change.
--- tools/perf/tests/expr.c | 4 ++-- tools/perf/util/expr.c | 10 +++++----- tools/perf/util/expr.h | 12 ++++++------ tools/perf/util/expr.y | 6 +++--- tools/perf/util/stat-shadow.c | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-)
tools/perf/tests/expr.c +2 -2
@@ -6,7 +6,7 @@#include <string.h> #include <linux/zalloc.h> -static int test (struct parse_ctx *ctx,const char *e,double val2) +static int test (struct expr_parse_ctx *ctx,const char *e,double val2) {double val;
@@ -22,7 +22,7 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)const char **other;double val;int i, ret; -struct parse_ctx ctx; +struct expr_parse_ctx ctx;int num_other;expr__ctx_init (&ctx);
tools/perf/util/expr.c +5 -5
@@ -11,7 +11,7 @@ extern int expr_debug;#endif /* Caller must make sure id is allocated */ -void expr__add_id (struct parse_ctx *ctx,const char *name,double val) +void expr__add_id (struct expr_parse_ctx *ctx,const char *name,double val) {int idx;
@@ -21,13 +21,13 @@ void expr__add_id(struct parse_ctx *ctx, const char *name, double val) ctx->ids[idx].val = val; } -void expr__ctx_init (struct parse_ctx *ctx) +void expr__ctx_init (struct expr_parse_ctx *ctx) { ctx->num_ids =0 ; }static int -__expr__parse (double *val,struct parse_ctx *ctx,const char *expr, +__expr__parse (double *val,struct expr_parse_ctx *ctx,const char *expr,int start) {YY_BUFFER_STATE buffer;
@@ -52,7 +52,7 @@ __expr__parse(double *val, struct parse_ctx *ctx, const char *expr,return ret; } -int expr__parse (double *final_val,struct parse_ctx *ctx,const char *expr) +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr) {return __expr__parse (final_val, ctx, expr,EXPR_PARSE ) ?-1 :0 ; }
@@ -75,7 +75,7 @@ int expr__find_other(const char *expr, const char *one, const char ***other, int *num_other) {int err, i =0 , j =0 ; -struct parse_ctx ctx; +struct expr_parse_ctx ctx;expr__ctx_init (&ctx); err =__expr__parse (NULL , &ctx, expr,EXPR_OTHER );
tools/perf/util/expr.h +6 -6
@@ -5,19 +5,19 @@#define EXPR_MAX_OTHER 20#define MAX_PARSE_ID EXPR_MAX_OTHER -struct parse_id { +struct expr_parse_id {const char *name;double val; }; -struct parse_ctx { +struct expr_parse_ctx {int num_ids; -struct parse_id ids[MAX_PARSE_ID ]; +struct expr_parse_id ids[MAX_PARSE_ID ]; }; -void expr__ctx_init (struct parse_ctx *ctx); -void expr__add_id (struct parse_ctx *ctx,const char *id,double val); -int expr__parse (double *final_val,struct parse_ctx *ctx,const char *expr); +void expr__ctx_init (struct expr_parse_ctx *ctx); +void expr__add_id (struct expr_parse_ctx *ctx,const char *id,double val); +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr);int expr__find_other (const char *expr,const char *one,const char ***other,int *num_other);
tools/perf/util/expr.y +3 -3
@@ -15,7 +15,7 @@ %define api.pure full %parse-param { double *final_val } -%parse-param { struct parse_ctx *ctx } +%parse-param { struct expr_parse_ctx *ctx } %parse-param {void *scanner} %lex-param {void* scanner}
@@ -39,14 +39,14 @@ %{ static void expr_error(double *final_val __maybe_unused, - struct parse_ctx *ctx __maybe_unused, + struct expr_parse_ctx *ctx __maybe_unused, void *scanner, const char *s) { pr_debug("%s\n", s); } -static int lookup_id(struct parse_ctx *ctx, char *id, double *val) +static int lookup_id(struct expr_parse_ctx *ctx, char *id, double *val) { int i;
tools/perf/util/stat-shadow.c +1 -1
@@ -729,7 +729,7 @@ static void generic_metric(struct perf_stat_config *config, struct runtime_stat *st) {print_metric_t print_metric = out->print_metric; -struct parse_ctx pctx; +struct expr_parse_ctx pctx;double ratio, scale;int i;void *ctxp = out->ctx;
PATCH v8 2/7 perf expr: Add expr_scanner_ctx object
In reply to Kajol JainFrom: Jiri Olsa <[email protected]>
Adding expr_scanner_ctx object to hold user data
for the expr scanner. Currently it holds onlystart_token, Kajol Jain will use it to hold 24x7
runtime param.
--- tools/perf/util/expr.c | 6 ++++-- tools/perf/util/expr.h | 4 ++++ tools/perf/util/expr.l | 10 +++++----- 3 files changed, 13 insertions(+), 7 deletions(-)
tools/perf/util/expr.c +4 -2
@@ -3,7 +3,6 @@#include <assert.h> #include "expr.h" #include "expr-bison.h" -#define YY_EXTRA_TYPE int#include "expr-flex.h" #ifdef PARSER_DEBUG
@@ -30,11 +29,14 @@ static int __expr__parse(double *val, struct expr_parse_ctx *ctx, const char *expr, int start) { +struct expr_scanner_ctx scanner_ctx = { + .start_token = start, + };YY_BUFFER_STATE buffer;void *scanner;int ret; - ret =expr_lex_init_extra (start, &scanner); + ret =expr_lex_init_extra (&scanner_ctx, &scanner);if (ret)return ret;
tools/perf/util/expr.h +4 -0
@@ -15,6 +15,10 @@ struct expr_parse_ctx {struct expr_parse_id ids[MAX_PARSE_ID ]; }; +struct expr_scanner_ctx { +int start_token; +}; +void expr__ctx_init (struct expr_parse_ctx *ctx);void expr__add_id (struct expr_parse_ctx *ctx,const char *id,double val);int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr);
tools/perf/util/expr.l +5 -5
@@ -76,13 +76,13 @@ sym [0-9a-zA-Z_\.:@]+ symbol {spec}*{sym}*{spec}*{sym}* %% - { - int start_token; + struct expr_scanner_ctx *sctx = expr_get_extra(yyscanner); - start_token = expr_get_extra(yyscanner); + { + int start_token = sctx->start_token; - if (start_token) { - expr_set_extra(NULL, yyscanner); + if (sctx->start_token) { + sctx->start_token = 0; return start_token; } }
Signature · 1 line
2.21.0
[tip: perf/core] perf expr: Add expr_scanner_ctx object
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 871f9f599db8d9d2387c0717e712af405290edea Gitweb: https://git.kernel.org/tip/871f9f599db8d9d2387c0717e712af405290edea Author: Jiri Olsa <[email protected]> AuthorDate: Thu, 02 Apr 2020 02:03:35 +05:30 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Thu, 16 Apr 2020 12:19:13 -03:00
perf expr: Add expr_scanner_ctx object
Add the expr_scanner_ctx object to hold user data for the expr scanner. Currently it holds only start_token, Kajol Jain will use it to hold 24x7 runtime param.
--- tools/perf/util/expr.c | 6 ++++-- tools/perf/util/expr.h | 4 ++++ tools/perf/util/expr.l | 10 +++++----- 3 files changed, 13 insertions(+), 7 deletions(-)
tools/perf/util/expr.c +4 -2
@@ -3,7 +3,6 @@#include <assert.h> #include "expr.h" #include "expr-bison.h" -#define YY_EXTRA_TYPE int#include "expr-flex.h" #ifdef PARSER_DEBUG
@@ -30,11 +29,14 @@ static int __expr__parse(double *val, struct expr_parse_ctx *ctx, const char *expr, int start) { +struct expr_scanner_ctx scanner_ctx = { + .start_token = start, + };YY_BUFFER_STATE buffer;void *scanner;int ret; - ret =expr_lex_init_extra (start, &scanner); + ret =expr_lex_init_extra (&scanner_ctx, &scanner);if (ret)return ret;
tools/perf/util/expr.h +4 -0
@@ -15,6 +15,10 @@ struct expr_parse_ctx {struct expr_parse_id ids[MAX_PARSE_ID ]; }; +struct expr_scanner_ctx { +int start_token; +}; +void expr__ctx_init (struct expr_parse_ctx *ctx);void expr__add_id (struct expr_parse_ctx *ctx,const char *id,double val);int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr);
tools/perf/util/expr.l +5 -5
@@ -76,13 +76,13 @@ sym [0-9a-zA-Z_\.:@]+ symbol {spec}*{sym}*{spec}*{sym}* %% - { - int start_token; + struct expr_scanner_ctx *sctx = expr_get_extra(yyscanner); - start_token = expr_get_extra(yyscanner); + { + int start_token = sctx->start_token; - if (start_token) { - expr_set_extra(NULL, yyscanner); + if (sctx->start_token) { + sctx->start_token = 0; return start_token; } }
PATCH v8 3/7 perf/tools: Refactoring metricgroup__add_metric function
In reply to Kajol JainThis patch refactor metricgroup__add_metric function where some part of it move to function metricgroup__add_metric_param. No logic change.
--- tools/perf/util/metricgroup.c | 60 ++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 25 deletions(-)
tools/perf/util/metricgroup.c +35 -25
@@ -485,6 +485,39 @@ static bool metricgroup__has_constraint(struct pmu_event *pe)return false; } +static int __metricgroup__add_metric (struct strbuf *events, +struct list_head *group_list,struct pmu_event *pe) +{ + +const char **ids; +int idnum; +struct egroup *eg; + +if (expr__find_other (pe->metric_expr,NULL , &ids, &idnum) <0 ) +return -EINVAL ; + +if (events->len >0 ) +strbuf_addf (events,"," ); + +if (metricgroup__has_constraint (pe)) +metricgroup__add_metric_non_group (events, ids, idnum); +else +metricgroup__add_metric_weak_group (events, ids, idnum); + + eg =malloc (sizeof (*eg)); +if (!eg) +return -ENOMEM ; + + eg->ids = ids; + eg->idnum = idnum; + eg->metric_name = pe->metric_name; + eg->metric_expr = pe->metric_expr; + eg->metric_unit = pe->unit; +list_add_tail (&eg->nd, group_list); + +return 0 ; +} +static int metricgroup__add_metric (const char *metric,struct strbuf *events,struct list_head *group_list) {
@@ -504,35 +537,12 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,continue ;if (match_metric (pe->metric_group, metric) ||match_metric (pe->metric_name, metric)) { -const char **ids; -int idnum; -struct egroup *eg;pr_debug ("metric expr %s for %s\n" , pe->metric_expr, pe->metric_name); -if (expr__find_other (pe->metric_expr, -NULL , &ids, &idnum) <0 ) -continue ; -if (events->len >0 ) -strbuf_addf (events,"," ); - -if (metricgroup__has_constraint (pe)) -metricgroup__add_metric_non_group (events, ids, idnum); -else -metricgroup__add_metric_weak_group (events, ids, idnum); - - eg =malloc (sizeof (struct egroup )); -if (!eg) { - ret = -ENOMEM ; + ret =__metricgroup__add_metric (events, group_list, pe); +if (ret == -ENOMEM )break ; - } - eg->ids = ids; - eg->idnum = idnum; - eg->metric_name = pe->metric_name; - eg->metric_expr = pe->metric_expr; - eg->metric_unit = pe->unit; -list_add_tail (&eg->nd, group_list); - ret =0 ; } }return ret;
Signature · 1 line
2.21.0
[tip: perf/core] perf metrictroup: Split the metricgroup__add_metric function
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 47352aba40035ab3fdc50dd03a94456feabed7d8 Gitweb: https://git.kernel.org/tip/47352aba40035ab3fdc50dd03a94456feabed7d8 Author: Kajol Jain <[email protected]> AuthorDate: Thu, 02 Apr 2020 02:03:36 +05:30 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Thu, 16 Apr 2020 12:19:13 -03:00
perf metrictroup: Split the metricgroup__add_metric function
This patch refactors metricgroup__add_metric function where some part of it move to function metricgroup__add_metric_param. No logic change.
--- tools/perf/util/metricgroup.c | 60 +++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 25 deletions(-)
tools/perf/util/metricgroup.c +35 -25
@@ -485,6 +485,39 @@ static bool metricgroup__has_constraint(struct pmu_event *pe)return false; } +static int __metricgroup__add_metric (struct strbuf *events, +struct list_head *group_list,struct pmu_event *pe) +{ + +const char **ids; +int idnum; +struct egroup *eg; + +if (expr__find_other (pe->metric_expr,NULL , &ids, &idnum) <0 ) +return -EINVAL ; + +if (events->len >0 ) +strbuf_addf (events,"," ); + +if (metricgroup__has_constraint (pe)) +metricgroup__add_metric_non_group (events, ids, idnum); +else +metricgroup__add_metric_weak_group (events, ids, idnum); + + eg =malloc (sizeof (*eg)); +if (!eg) +return -ENOMEM ; + + eg->ids = ids; + eg->idnum = idnum; + eg->metric_name = pe->metric_name; + eg->metric_expr = pe->metric_expr; + eg->metric_unit = pe->unit; +list_add_tail (&eg->nd, group_list); + +return 0 ; +} +static int metricgroup__add_metric (const char *metric,struct strbuf *events,struct list_head *group_list) {
@@ -504,35 +537,12 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,continue ;if (match_metric (pe->metric_group, metric) ||match_metric (pe->metric_name, metric)) { -const char **ids; -int idnum; -struct egroup *eg;pr_debug ("metric expr %s for %s\n" , pe->metric_expr, pe->metric_name); -if (expr__find_other (pe->metric_expr, -NULL , &ids, &idnum) <0 ) -continue ; -if (events->len >0 ) -strbuf_addf (events,"," ); - -if (metricgroup__has_constraint (pe)) -metricgroup__add_metric_non_group (events, ids, idnum); -else -metricgroup__add_metric_weak_group (events, ids, idnum); - - eg =malloc (sizeof (struct egroup )); -if (!eg) { - ret = -ENOMEM ; + ret =__metricgroup__add_metric (events, group_list, pe); +if (ret == -ENOMEM )break ; - } - eg->ids = ids; - eg->idnum = idnum; - eg->metric_name = pe->metric_name; - eg->metric_expr = pe->metric_expr; - eg->metric_unit = pe->unit; -list_add_tail (&eg->nd, group_list); - ret =0 ; } }return ret;
PATCH v8 4/7 perf/tools: Enhance JSON/metric infrastructure to handle "?"
In reply to Kajol JainPatch enhances current metric infrastructure to handle "?" in the metric expression. The "?" can be use for parameters whose value not known while creating metric events and which can be replace later at runtime to the proper value. It also add flexibility to create multiple events out of single metric event added in json file.
Patch adds function 'arch_get_runtimeparam' which is a arch specific function, returns the count of metric events need to be created. By default it return 1.
This infrastructure needed for hv_24x7 socket/chip level events. "hv_24x7" chip level events needs specific chip-id to which the data is requested. Function 'arch_get_runtimeparam' implemented in header.c which extract number of sockets from sysfs file "sockets" under "/sys/devices/hv_24x7/interface/".
With this patch basically we are trying to create as many metric events as define by runtime_param.
For that one loop is added in function 'metricgroup__add_metric', which create multiple events at run time depend on return value of 'arch_get_runtimeparam' and merge that event in 'group_list'.
To achieve that we are actually passing this parameter value as part of expr__find_other function and changing "?" present in metric expression with this value.
As in our json file, there gonna be single metric event, and out of which we are creating multiple events.
To understand which data count belongs to which parameter value, we also printing param value in generic_metric function.
For example,
command:# ./perf stat -M PowerBUS_Frequency -C 0 -I 1000
1.000101867 9,356,933 hv_24x7/pm_pb_cyc,chip=0/ # 2.3 GHz PowerBUS_Frequency_0
1.000101867 9,366,134 hv_24x7/pm_pb_cyc,chip=1/ # 2.3 GHz PowerBUS_Frequency_1
2.000314878 9,365,868 hv_24x7/pm_pb_cyc,chip=0/ # 2.3 GHz PowerBUS_Frequency_0
2.000314878 9,366,092 hv_24x7/pm_pb_cyc,chip=1/ # 2.3 GHz PowerBUS_Frequency_1So, here _0 and _1 after PowerBUS_Frequency specify parameter value.
--- tools/perf/arch/powerpc/util/header.c | 8 ++++++++ tools/perf/tests/expr.c | 8 ++++---- tools/perf/util/expr.c | 11 ++++++----- tools/perf/util/expr.h | 5 +++-- tools/perf/util/expr.l | 27 +++++++++++++++++++------- tools/perf/util/metricgroup.c | 28 ++++++++++++++++++++++++--- tools/perf/util/metricgroup.h | 2 ++ tools/perf/util/stat-shadow.c | 17 ++++++++++------ 8 files changed, 79 insertions(+), 27 deletions(-)
tools/perf/arch/powerpc/util/header.c +8 -0
@@ -7,6 +7,8 @@#include <string.h> #include <linux/stringify.h> #include "header.h" +#include "metricgroup.h" +#include <api/fs/fs.h> #define mfspr (rn) ({unsigned long rval; \ asm volatile("mfspr %0," __stringify(rn) \
@@ -44,3 +46,9 @@ get_cpuid_str(struct perf_pmu *pmu __maybe_unused)return bufp; } + +int arch_get_runtimeparam (void ) +{ +int count; +return sysfs__read_int ("/devices/hv_24x7/interface/sockets" , &count) <0 ?1 : count; +}
tools/perf/tests/expr.c +4 -4
@@ -10,7 +10,7 @@ static int test(struct expr_parse_ctx *ctx, const char *e, double val2) {double val; -if (expr__parse (&val, ctx, e)) +if (expr__parse (&val, ctx, e,1 ))TEST_ASSERT_VAL ("parse test failed" ,0 );TEST_ASSERT_VAL ("unexpected value" , val == val2);return 0 ;
@@ -44,15 +44,15 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)return ret; p ="FOO/0" ; - ret =expr__parse (&val, &ctx, p); + ret =expr__parse (&val, &ctx, p,1 );TEST_ASSERT_VAL ("division by zero" , ret ==-1 ); p ="BAR/" ; - ret =expr__parse (&val, &ctx, p); + ret =expr__parse (&val, &ctx, p,1 );TEST_ASSERT_VAL ("missing operand" , ret ==-1 );TEST_ASSERT_VAL ("find other" , -expr__find_other ("FOO + BAR + BAZ + BOZO" ,"FOO" , &other, &num_other) ==0 ); +expr__find_other ("FOO + BAR + BAZ + BOZO" ,"FOO" , &other, &num_other,1 ) ==0 );TEST_ASSERT_VAL ("find other" , num_other ==3 );TEST_ASSERT_VAL ("find other" , !strcmp (other[0 ],"BAR" ));TEST_ASSERT_VAL ("find other" , !strcmp (other[1 ],"BAZ" ));
tools/perf/util/expr.c +6 -5
@@ -27,10 +27,11 @@ void expr__ctx_init(struct expr_parse_ctx *ctx)static int __expr__parse (double *val,struct expr_parse_ctx *ctx,const char *expr, -int start) +int start,int runtime) {struct expr_scanner_ctx scanner_ctx = { .start_token = start, + .runtime = runtime, };YY_BUFFER_STATE buffer;void *scanner;
@@ -54,9 +55,9 @@ __expr__parse(double *val, struct expr_parse_ctx *ctx, const char *expr,return ret; } -int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr) +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr,int runtime) { -return __expr__parse (final_val, ctx, expr,EXPR_PARSE ) ?-1 :0 ; +return __expr__parse (final_val, ctx, expr,EXPR_PARSE , runtime) ?-1 :0 ; } static bool
@@ -74,13 +75,13 @@ already_seen(const char *val, const char *one, const char **other, }int expr__find_other (const char *expr,const char *one,const char ***other, -int *num_other) +int *num_other,int runtime) {int err, i =0 , j =0 ;struct expr_parse_ctx ctx;expr__ctx_init (&ctx); - err =__expr__parse (NULL , &ctx, expr,EXPR_OTHER ); + err =__expr__parse (NULL , &ctx, expr,EXPR_OTHER , runtime);if (err)return -1 ;
tools/perf/util/expr.h +3 -2
@@ -17,12 +17,13 @@ struct expr_parse_ctx {struct expr_scanner_ctx {int start_token; +int runtime; };void expr__ctx_init (struct expr_parse_ctx *ctx);void expr__add_id (struct expr_parse_ctx *ctx,const char *id,double val); -int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr); +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr,int runtime);int expr__find_other (const char *expr,const char *one,const char ***other, -int *num_other); +int *num_other,int runtime);#endif
tools/perf/util/expr.l +20 -7
@@ -35,7 +35,7 @@ static int value(yyscan_t scanner, int base) * Allow @ instead of / to be able to specify pmu/event/ without * conflicts with normal division. */ -static char *normalize(char *str) +static char *normalize(char *str, int runtime) { char *ret = str; char *dst = str;
@@ -45,6 +45,19 @@ static char *normalize(char *str) *dst++ = '/'; else if (*str == '\\') *dst++ = *++str; + else if (*str == '?') { + char *paramval; + int i = 0; + int size = asprintf(¶mval, "%d", runtime); + + if (size < 0) + *dst++ = '0'; + else { + while (i < size) + *dst++ = paramval[i++]; + free(paramval); + } + } else *dst++ = *str; str++;
@@ -54,16 +67,16 @@ static char *normalize(char *str) return ret; } -static int str(yyscan_t scanner, int token) +static int str(yyscan_t scanner, int token, int runtime) { YYSTYPE *yylval = expr_get_lval(scanner); char *text = expr_get_text(scanner); - yylval->str = normalize(strdup(text)); + yylval->str = normalize(strdup(text), runtime); if (!yylval->str) return EXPR_ERROR; - yylval->str = normalize(yylval->str); + yylval->str = normalize(yylval->str, runtime); return token; } %}
@@ -72,8 +85,8 @@ number [0-9]+ sch [-,=] spec \\{sch} -sym [0-9a-zA-Z_\.:@]+ -symbol {spec}*{sym}*{spec}*{sym}* +sym [0-9a-zA-Z_\.:@?]+ +symbol {spec}*{sym}*{spec}*{sym}*{spec}*{sym} %% struct expr_scanner_ctx *sctx = expr_get_extra(yyscanner);
@@ -93,7 +106,7 @@ if { return IF; } else { return ELSE; } #smt_on { return SMT_ON; } {number} { return value(yyscanner, 10); } -{symbol} { return str(yyscanner, ID); } +{symbol} { return str(yyscanner, ID, sctx->runtime); } "|" { return '|'; } "^" { return '^'; } "&" { return '&'; }
tools/perf/util/metricgroup.c +25 -3
@@ -90,6 +90,7 @@ struct egroup {const char *metric_name;const char *metric_expr;const char *metric_unit; +int runtime; }; static struct evsel *find_evsel_group(struct evlist *perf_evlist,
@@ -202,6 +203,7 @@ static int metricgroup__setup_events(struct list_head *groups, expr->metric_name = eg->metric_name; expr->metric_unit = eg->metric_unit; expr->metric_events = metric_events; + expr->runtime = eg->runtime;list_add (&expr->nd, &me->head); }
@@ -485,15 +487,20 @@ static bool metricgroup__has_constraint(struct pmu_event *pe)return false; } +int __weak arch_get_runtimeparam (void ) +{ +return 1 ; +} +static int __metricgroup__add_metric (struct strbuf *events, -struct list_head *group_list,struct pmu_event *pe) +struct list_head *group_list,struct pmu_event *pe,int runtime) {const char **ids;int idnum;struct egroup *eg; -if (expr__find_other (pe->metric_expr,NULL , &ids, &idnum) <0 ) +if (expr__find_other (pe->metric_expr,NULL , &ids, &idnum, runtime) <0 )return -EINVAL ;if (events->len >0 )
@@ -513,6 +520,7 @@ static int __metricgroup__add_metric(struct strbuf *events, eg->metric_name = pe->metric_name; eg->metric_expr = pe->metric_expr; eg->metric_unit = pe->unit; + eg->runtime = runtime;list_add_tail (&eg->nd, group_list);return 0 ;
@@ -540,7 +548,21 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,pr_debug ("metric expr %s for %s\n" , pe->metric_expr, pe->metric_name); - ret =__metricgroup__add_metric (events, group_list, pe); +if (!strstr (pe->metric_expr,"?" )) { + ret =__metricgroup__add_metric (events, group_list, pe,1 ); + }else { +int j, count; + + count =arch_get_runtimeparam (); + +/* This loop is added to create multiple +* events depend on count value and add +* those events to group_list. +*/ + +for (j =0 ; j < count; j++) + ret =__metricgroup__add_metric (events, group_list, pe, j); + }if (ret == -ENOMEM )break ; }
tools/perf/util/metricgroup.h +2 -0
@@ -22,6 +22,7 @@ struct metric_expr {const char *metric_name;const char *metric_unit;struct evsel **metric_events; +int runtime; }; struct metric_event *metricgroup__lookup(struct rblist *metric_events,
@@ -34,4 +35,5 @@ int metricgroup__parse_groups(const struct option *opt,void metricgroup__print (bool metrics,bool groups,char *filter,bool raw,bool details);bool metricgroup__has_metric (const char *metric); +int arch_get_runtimeparam (void );#endif
tools/perf/util/stat-shadow.c +11 -6
@@ -336,7 +336,7 @@ void perf_stat__collect_metric_expr(struct evlist *evsel_list) metric_events = counter->metric_events;if (!metric_events) {if (expr__find_other (counter->metric_expr, counter->name, - &metric_names, &num_metric_names) <0 ) + &metric_names, &num_metric_names,1 ) <0 )continue ; metric_events = calloc(sizeof(struct evsel *),
@@ -723,6 +723,7 @@ static void generic_metric(struct perf_stat_config *config,char *name, const char *metric_name, const char *metric_unit, + int runtime, double avg, int cpu, struct perf_stat_output_ctx *out,
@@ -777,7 +778,7 @@ static void generic_metric(struct perf_stat_config *config, }if (!metric_events[i]) { -if (expr__parse (&ratio, &pctx, metric_expr) ==0 ) { +if (expr__parse (&ratio, &pctx, metric_expr, runtime) ==0 ) {char *unit;char metric_bf[64 ];
@@ -786,9 +787,13 @@ static void generic_metric(struct perf_stat_config *config, &unit, &scale) >= 0) { ratio *= scale; } - -scnprintf (metric_bf,sizeof (metric_bf), +if (strstr (metric_expr,"?" )) +scnprintf (metric_bf,sizeof (metric_bf), +"%s %s_%d" , unit, metric_name, runtime); +else +scnprintf (metric_bf,sizeof (metric_bf),"%s %s" , unit, metric_name); +print_metric (config, ctxp,NULL ,"%8.1f" , metric_bf, ratio); }else {
@@ -1019,7 +1024,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config,print_metric (config, ctxp,NULL ,NULL , name,0 ); }else if (evsel->metric_expr) {generic_metric (config, evsel->metric_expr, evsel->metric_events, evsel->name, - evsel->metric_name,NULL , avg, cpu, out, st); + evsel->metric_name,NULL ,1 , avg, cpu, out, st); }else if (runtime_stat_n (st,STAT_NSECS ,0 , cpu) !=0 ) {char unit ='M' ;char unit_buf[10 ];
@@ -1048,7 +1053,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, out->new_line (config, ctxp);generic_metric (config, mexp->metric_expr, mexp->metric_events, evsel->name, mexp->metric_name, - mexp->metric_unit, avg, cpu, out, st); + mexp->metric_unit, mexp->runtime, avg, cpu, out, st); } }if (num ==0 )
Signature · 1 line
2.21.0
Ian Rogers
reviewerRe: [PATCH v8 4/7] perf/tools: Enhance JSON/metric infrastructure to handle "?"
Quoted 10 lines · Kajol Jain
Patch enhances current metric infrastructure to handle "?" in the metric expression. The "?" can be use for parameters whose value not known while creating metric events and which can be replace later at runtime to the proper value. It also add flexibility to create multiple events out of single metric event added in json file.
Patch adds function '
arch_get_runtimeparam' which is a arch specific function, returns the count of metric events need to be created. By default it return 1.
Sorry for the slow response, I was trying to understand this patch in relation to the PMU aliases to see if there was an overlap - I'm still not sure. This is now merged so I'm just commenting wrt possible future cleanup. I defer to the maintainers on how this should be organized. At the metric level, this problem reminds me of both #smt_on and LLC_MISSES.PCIE_WRITE on cascade lake. #smt_on adds a degree of CPU specific behavior to an expression. LLC_MISSES.PCIE_WRITE uses .part0 ... part3 to combine separate but related counters.
The symbols that the metrics parse are then passed to parse-event. You don't change parse-event as metricgroup replaces the '?' with a read value from /devices/hv_24x7/interface/sockets, actually 0 to that value-1 are passed.
It seems unfortunate to overload the meaning of runtime with a value read from /devices/hv_24x7/interface/sockets and plumbing this value around is quite a bit of noise for everything but this use-case. I kind of wish we could do something like:
for i in 0, read("/devices/hv_24x7/interface/sockets"):
hv_24x7/pm_pb_cyc,chip=$i
in the metric code. I have some patches to send related to metric groups and I think this will be an active area of development for a while as I think there are some open questions on the organization of the code.
Thanks,
Ian
Quoted 396 lines
This infrastructure needed for
hv_24x7socket/chip level events. "hv_24x7" chip level events needs specific chip-id to which the data is requested. Function 'arch_get_runtimeparam' implemented inheader.cwhich extract number of sockets from sysfs file "sockets" under "/sys/devices/hv_24x7/interface/".With this patch basically we are trying to create as many metric events as define by
runtime_param.For that one loop is added in function '
metricgroup__add_metric', which create multiple events at run time depend on return value of 'arch_get_runtimeparam' and merge that event in 'group_list'.To achieve that we are actually passing this parameter value as part of
expr__find_otherfunction and changing "?" present in metric expression with this value.As in our json file, there gonna be single metric event, and out of which we are creating multiple events.
To understand which data count belongs to which parameter value, we also printing param value in
generic_metricfunction.For example,
command:# ./perf stat -MPowerBUS_Frequency-C 0 -I 10001.000101867 9,356,933 hv_24x7/pm_pb_cyc,chip=0/ # 2.3 GHz PowerBUS_Frequency_0 1.000101867 9,366,134 hv_24x7/pm_pb_cyc,chip=1/ # 2.3 GHz PowerBUS_Frequency_1 2.000314878 9,365,868 hv_24x7/pm_pb_cyc,chip=0/ # 2.3 GHz PowerBUS_Frequency_0 2.000314878 9,366,092 hv_24x7/pm_pb_cyc,chip=1/ # 2.3 GHz PowerBUS_Frequency_1So, here _0 and _1 after
PowerBUS_Frequencyspecify parameter value.Signed-off-by Kajol Jain <[email protected]>--- tools/perf/arch/powerpc/util/header.c | 8 ++++++++ tools/perf/tests/expr.c | 8 ++++---- tools/perf/util/expr.c | 11 ++++++----- tools/perf/util/expr.h | 5 +++-- tools/perf/util/expr.l | 27 +++++++++++++++++++------- tools/perf/util/metricgroup.c | 28 ++++++++++++++++++++++++--- tools/perf/util/metricgroup.h | 2 ++ tools/perf/util/stat-shadow.c | 17 ++++++++++------ 8 files changed, 79 insertions(+), 27 deletions(-)tools/perf/arch/powerpc/util/header.c +8
-0@@ -7,6 +7,8 @@#include <string.h> #include <linux/stringify.h> #include "header.h" +#include "metricgroup.h" +#include <api/fs/fs.h> #define mfspr (rn) ({unsigned long rval; \ asm volatile("mfspr %0," __stringify(rn) \@@ -44,3 +46,9 @@ get_cpuid_str(struct perf_pmu *pmu __maybe_unused)return bufp; } + +int arch_get_runtimeparam (void ) +{ +int count; +return sysfs__read_int ("/devices/hv_24x7/interface/sockets" , &count) <0 ?1 : count; +}tools/perf/tests/expr.c +4
-4@@ -10,7 +10,7 @@ static int test(struct expr_parse_ctx *ctx, const char *e, double val2) {double val; -if (expr__parse (&val, ctx, e)) +if (expr__parse (&val, ctx, e,1 ))TEST_ASSERT_VAL ("parse test failed" ,0 );TEST_ASSERT_VAL ("unexpected value" , val == val2);return 0 ;@@ -44,15 +44,15 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)return ret; p ="FOO/0" ; - ret =expr__parse (&val, &ctx, p); + ret =expr__parse (&val, &ctx, p,1 );TEST_ASSERT_VAL ("division by zero" , ret ==-1 ); p ="BAR/" ; - ret =expr__parse (&val, &ctx, p); + ret =expr__parse (&val, &ctx, p,1 );TEST_ASSERT_VAL ("missing operand" , ret ==-1 );TEST_ASSERT_VAL ("find other" , -expr__find_other ("FOO + BAR + BAZ + BOZO" ,"FOO" , &other, &num_other) ==0 ); +expr__find_other ("FOO + BAR + BAZ + BOZO" ,"FOO" , &other, &num_other,1 ) ==0 );TEST_ASSERT_VAL ("find other" , num_other ==3 );TEST_ASSERT_VAL ("find other" , !strcmp (other[0 ],"BAR" ));TEST_ASSERT_VAL ("find other" , !strcmp (other[1 ],"BAZ" ));tools/perf/util/expr.c +6
-5@@ -27,10 +27,11 @@ void expr__ctx_init(struct expr_parse_ctx *ctx)static int __expr__parse (double *val,struct expr_parse_ctx *ctx,const char *expr, -int start) +int start,int runtime) {struct expr_scanner_ctx scanner_ctx = { .start_token = start, + .runtime = runtime, };YY_BUFFER_STATE buffer;void *scanner;@@ -54,9 +55,9 @@ __expr__parse(double *val, struct expr_parse_ctx *ctx, const char *expr,return ret; } -int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr) +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr,int runtime) { -return __expr__parse (final_val, ctx, expr,EXPR_PARSE ) ?-1 :0 ; +return __expr__parse (final_val, ctx, expr,EXPR_PARSE , runtime) ?-1 :0 ; } static bool@@ -74,13 +75,13 @@ already_seen(const char *val, const char *one, const char **other, }int expr__find_other (const char *expr,const char *one,const char ***other, -int *num_other) +int *num_other,int runtime) {int err, i =0 , j =0 ;struct expr_parse_ctx ctx;expr__ctx_init (&ctx); - err =__expr__parse (NULL , &ctx, expr,EXPR_OTHER ); + err =__expr__parse (NULL , &ctx, expr,EXPR_OTHER , runtime);if (err)return -1 ;tools/perf/util/expr.h +3
-2@@ -17,12 +17,13 @@ struct expr_parse_ctx {struct expr_scanner_ctx {int start_token; +int runtime; };void expr__ctx_init (struct expr_parse_ctx *ctx);void expr__add_id (struct expr_parse_ctx *ctx,const char *id,double val); -int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr); +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr,int runtime);int expr__find_other (const char *expr,const char *one,const char ***other, -int *num_other); +int *num_other,int runtime);#endif tools/perf/util/expr.l +20
-7@@ -35,7 +35,7 @@ static int value(yyscan_t scanner, int base) * Allow @ instead of / to be able to specify pmu/event/ without * conflicts with normal division. */ -static char *normalize(char *str) +static char *normalize(char *str, int runtime) { char *ret = str; char *dst = str;@@ -45,6 +45,19 @@ static char *normalize(char *str) *dst++ = '/'; else if (*str == '\\') *dst++ = *++str; + else if (*str == '?') { + char *paramval; + int i = 0; + int size = asprintf(¶mval, "%d", runtime); + + if (size < 0) + *dst++ = '0'; + else { + while (i < size) + *dst++ = paramval[i++]; + free(paramval); + } + } else *dst++ = *str; str++;@@ -54,16 +67,16 @@ static char *normalize(char *str) return ret; } -static int str(yyscan_t scanner, int token) +static int str(yyscan_t scanner, int token, int runtime) { YYSTYPE *yylval = expr_get_lval(scanner); char *text = expr_get_text(scanner); - yylval->str = normalize(strdup(text)); + yylval->str = normalize(strdup(text), runtime); if (!yylval->str) return EXPR_ERROR; - yylval->str = normalize(yylval->str); + yylval->str = normalize(yylval->str, runtime); return token; } %}@@ -72,8 +85,8 @@ number [0-9]+ sch [-,=] spec \\{sch} -sym [0-9a-zA-Z_\.:@]+ -symbol {spec}*{sym}*{spec}*{sym}* +sym [0-9a-zA-Z_\.:@?]+ +symbol {spec}*{sym}*{spec}*{sym}*{spec}*{sym} %% struct expr_scanner_ctx *sctx = expr_get_extra(yyscanner);@@ -93,7 +106,7 @@ if { return IF; } else { return ELSE; } #smt_on { return SMT_ON; } {number} { return value(yyscanner, 10); } -{symbol} { return str(yyscanner, ID); } +{symbol} { return str(yyscanner, ID, sctx->runtime); } "|" { return '|'; } "^" { return '^'; } "&" { return '&'; }tools/perf/util/metricgroup.c +25
-3@@ -90,6 +90,7 @@ struct egroup {const char *metric_name;const char *metric_expr;const char *metric_unit; +int runtime; }; static struct evsel *find_evsel_group(struct evlist *perf_evlist,@@ -202,6 +203,7 @@ static int metricgroup__setup_events(struct list_head *groups, expr->metric_name = eg->metric_name; expr->metric_unit = eg->metric_unit; expr->metric_events = metric_events; + expr->runtime = eg->runtime;list_add (&expr->nd, &me->head); }@@ -485,15 +487,20 @@ static bool metricgroup__has_constraint(struct pmu_event *pe)return false; } +int __weak arch_get_runtimeparam (void ) +{ +return 1 ; +} +static int __metricgroup__add_metric (struct strbuf *events, -struct list_head *group_list,struct pmu_event *pe) +struct list_head *group_list,struct pmu_event *pe,int runtime) {const char **ids;int idnum;struct egroup *eg; -if (expr__find_other (pe->metric_expr,NULL , &ids, &idnum) <0 ) +if (expr__find_other (pe->metric_expr,NULL , &ids, &idnum, runtime) <0 )return -EINVAL ;if (events->len >0 )@@ -513,6 +520,7 @@ static int __metricgroup__add_metric(struct strbuf *events, eg->metric_name = pe->metric_name; eg->metric_expr = pe->metric_expr; eg->metric_unit = pe->unit; + eg->runtime = runtime;list_add_tail (&eg->nd, group_list);return 0 ;@@ -540,7 +548,21 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,pr_debug ("metric expr %s for %s\n" , pe->metric_expr, pe->metric_name); - ret =__metricgroup__add_metric (events, group_list, pe); +if (!strstr (pe->metric_expr,"?" )) { + ret =__metricgroup__add_metric (events, group_list, pe,1 ); + }else { +int j, count; + + count =arch_get_runtimeparam (); + +/* This loop is added to create multiple +* events depend on count value and add +* those events to group_list. +*/ + +for (j =0 ; j < count; j++) + ret =__metricgroup__add_metric (events, group_list, pe, j); + }if (ret == -ENOMEM )break ; }tools/perf/util/metricgroup.h +2
-0@@ -22,6 +22,7 @@ struct metric_expr {const char *metric_name;const char *metric_unit;struct evsel **metric_events; +int runtime; }; struct metric_event *metricgroup__lookup(struct rblist *metric_events,@@ -34,4 +35,5 @@ int metricgroup__parse_groups(const struct option *opt,void metricgroup__print (bool metrics,bool groups,char *filter,bool raw,bool details);bool metricgroup__has_metric (const char *metric); +int arch_get_runtimeparam (void );#endif tools/perf/util/stat-shadow.c +11
-7@@ -336,7 +336,7 @@ void perf_stat__collect_metric_expr(struct evlist *evsel_list) metric_events = counter->metric_events;if (!metric_events) {if (expr__find_other (counter->metric_expr, counter->name, - &metric_names, &num_metric_names) <0 ) + &metric_names, &num_metric_names,1 ) <0 )continue ; metric_events = calloc(sizeof(struct evsel *),@@ -723,6 +723,7 @@ static void generic_metric(struct perf_stat_config *config,char *name, const char *metric_name, const char *metric_unit, + int runtime, double avg, int cpu, struct perf_stat_output_ctx *out,@@ -777,7 +778,7 @@ static void generic_metric(struct perf_stat_config *config, }if (!metric_events[i]) { -if (expr__parse (&ratio, &pctx, metric_expr) ==0 ) { +if (expr__parse (&ratio, &pctx, metric_expr, runtime) ==0 ) {char *unit;char metric_bf[64 ];@@ -786,9 +787,13 @@ static void generic_metric(struct perf_stat_config *config, &unit, &scale) >= 0) { ratio *= scale; } - -scnprintf (metric_bf,sizeof (metric_bf), +if (strstr (metric_expr,"?" )) +scnprintf (metric_bf,sizeof (metric_bf), +"%s %s_%d" , unit, metric_name, runtime); +else +scnprintf (metric_bf,sizeof (metric_bf),"%s %s" , unit, metric_name); +print_metric (config, ctxp,NULL ,"%8.1f" , metric_bf, ratio); }else {@@ -1019,7 +1024,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config,print_metric (config, ctxp,NULL ,NULL , name,0 ); }else if (evsel->metric_expr) {generic_metric (config, evsel->metric_expr, evsel->metric_events, evsel->name, - evsel->metric_name,NULL , avg, cpu, out, st); + evsel->metric_name,NULL ,1 , avg, cpu, out, st); }else if (runtime_stat_n (st,STAT_NSECS ,0 , cpu) !=0 ) {char unit ='M' ;char unit_buf[10 ];@@ -1048,7 +1053,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, out->new_line (config, ctxp);generic_metric (config, mexp->metric_expr, mexp->metric_events, evsel->name, mexp->metric_name, - mexp->metric_unit, avg, cpu, out, st); + mexp->metric_unit, mexp->runtime, avg, cpu, out, st); } }if (num ==0 ) --2.21.0
[tip: perf/core] perf metricgroups: Enhance JSON/metric infrastructure to handle "?"
In reply to Kajol JainThe following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 1e1a873dc67fc748cc319a27603f33db91027730 Gitweb: https://git.kernel.org/tip/1e1a873dc67fc748cc319a27603f33db91027730 Author: Kajol Jain <[email protected]> AuthorDate: Thu, 02 Apr 2020 02:03:37 +05:30 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Thu, 30 Apr 2020 10:48:33 -03:00
perf metricgroups: Enhance JSON/metric infrastructure to handle "?"
Patch enhances current metric infrastructure to handle "?" in the metric expression. The "?" can be use for parameters whose value not known while creating metric events and which can be replace later at runtime to the proper value. It also add flexibility to create multiple events out of single metric event added in JSON file.
Patch adds function 'arch_get_runtimeparam' which is a arch specific function, returns the count of metric events need to be created. By default it return 1.
This infrastructure needed for hv_24x7 socket/chip level events. "hv_24x7" chip level events needs specific chip-id to which the data is requested. Function 'arch_get_runtimeparam' implemented in header.c which extract number of sockets from sysfs file "sockets" under "/sys/devices/hv_24x7/interface/".
With this patch basically we are trying to create as many metric events as define by runtime_param.
For that one loop is added in function 'metricgroup__add_metric', which create multiple events at run time depend on return value of 'arch_get_runtimeparam' and merge that event in 'group_list'.
To achieve that we are actually passing this parameter value as part of expr__find_other function and changing "?" present in metric expression with this value.
As in our JSON file, there gonna be single metric event, and out of which we are creating multiple events.
To understand which data count belongs to which parameter value, we also printing param value in generic_metric function.
For example,
command:# ./perf stat -M PowerBUS_Frequency -C 0 -I 1000
1.000101867 9,356,933 hv_24x7/pm_pb_cyc,chip=0/ # 2.3 GHz PowerBUS_Frequency_0
1.000101867 9,366,134 hv_24x7/pm_pb_cyc,chip=1/ # 2.3 GHz PowerBUS_Frequency_1
2.000314878 9,365,868 hv_24x7/pm_pb_cyc,chip=0/ # 2.3 GHz PowerBUS_Frequency_0
2.000314878 9,366,092 hv_24x7/pm_pb_cyc,chip=1/ # 2.3 GHz PowerBUS_Frequency_1So, here _0 and _1 after PowerBUS_Frequency specify parameter value.
--- tools/perf/arch/powerpc/util/header.c | 8 +++++++- tools/perf/tests/expr.c | 8 +++---- tools/perf/util/expr.c | 11 +++++----- tools/perf/util/expr.h | 5 +++-- tools/perf/util/expr.l | 27 ++++++++++++++++++------- tools/perf/util/metricgroup.c | 28 +++++++++++++++++++++++--- tools/perf/util/metricgroup.h | 2 ++- tools/perf/util/stat-shadow.c | 17 ++++++++++------ 8 files changed, 79 insertions(+), 27 deletions(-)
tools/perf/arch/powerpc/util/header.c +8 -0
@@ -7,6 +7,8 @@#include <string.h> #include <linux/stringify.h> #include "header.h" +#include "metricgroup.h" +#include <api/fs/fs.h> #define mfspr (rn) ({unsigned long rval; \ asm volatile("mfspr %0," __stringify(rn) \
@@ -44,3 +46,9 @@ get_cpuid_str(struct perf_pmu *pmu __maybe_unused)return bufp; } + +int arch_get_runtimeparam (void ) +{ +int count; +return sysfs__read_int ("/devices/hv_24x7/interface/sockets" , &count) <0 ?1 : count; +}
tools/perf/tests/expr.c +4 -4
@@ -10,7 +10,7 @@ static int test(struct expr_parse_ctx *ctx, const char *e, double val2) {double val; -if (expr__parse (&val, ctx, e)) +if (expr__parse (&val, ctx, e,1 ))TEST_ASSERT_VAL ("parse test failed" ,0 );TEST_ASSERT_VAL ("unexpected value" , val == val2);return 0 ;
@@ -44,15 +44,15 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)return ret; p ="FOO/0" ; - ret =expr__parse (&val, &ctx, p); + ret =expr__parse (&val, &ctx, p,1 );TEST_ASSERT_VAL ("division by zero" , ret ==-1 ); p ="BAR/" ; - ret =expr__parse (&val, &ctx, p); + ret =expr__parse (&val, &ctx, p,1 );TEST_ASSERT_VAL ("missing operand" , ret ==-1 );TEST_ASSERT_VAL ("find other" , -expr__find_other ("FOO + BAR + BAZ + BOZO" ,"FOO" , &other, &num_other) ==0 ); +expr__find_other ("FOO + BAR + BAZ + BOZO" ,"FOO" , &other, &num_other,1 ) ==0 );TEST_ASSERT_VAL ("find other" , num_other ==3 );TEST_ASSERT_VAL ("find other" , !strcmp (other[0 ],"BAR" ));TEST_ASSERT_VAL ("find other" , !strcmp (other[1 ],"BAZ" ));
tools/perf/util/expr.c +6 -5
@@ -27,10 +27,11 @@ void expr__ctx_init(struct expr_parse_ctx *ctx)static int __expr__parse (double *val,struct expr_parse_ctx *ctx,const char *expr, -int start) +int start,int runtime) {struct expr_scanner_ctx scanner_ctx = { .start_token = start, + .runtime = runtime, };YY_BUFFER_STATE buffer;void *scanner;
@@ -54,9 +55,9 @@ __expr__parse(double *val, struct expr_parse_ctx *ctx, const char *expr,return ret; } -int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr) +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr,int runtime) { -return __expr__parse (final_val, ctx, expr,EXPR_PARSE ) ?-1 :0 ; +return __expr__parse (final_val, ctx, expr,EXPR_PARSE , runtime) ?-1 :0 ; } static bool
@@ -74,13 +75,13 @@ already_seen(const char *val, const char *one, const char **other, }int expr__find_other (const char *expr,const char *one,const char ***other, -int *num_other) +int *num_other,int runtime) {int err, i =0 , j =0 ;struct expr_parse_ctx ctx;expr__ctx_init (&ctx); - err =__expr__parse (NULL , &ctx, expr,EXPR_OTHER ); + err =__expr__parse (NULL , &ctx, expr,EXPR_OTHER , runtime);if (err)return -1 ;
tools/perf/util/expr.h +3 -2
@@ -17,12 +17,13 @@ struct expr_parse_ctx {struct expr_scanner_ctx {int start_token; +int runtime; };void expr__ctx_init (struct expr_parse_ctx *ctx);void expr__add_id (struct expr_parse_ctx *ctx,const char *id,double val); -int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr); +int expr__parse (double *final_val,struct expr_parse_ctx *ctx,const char *expr,int runtime);int expr__find_other (const char *expr,const char *one,const char ***other, -int *num_other); +int *num_other,int runtime);#endif
tools/perf/util/expr.l +20 -7
@@ -35,7 +35,7 @@ static int value(yyscan_t scanner, int base) * Allow @ instead of / to be able to specify pmu/event/ without * conflicts with normal division. */ -static char *normalize(char *str) +static char *normalize(char *str, int runtime) { char *ret = str; char *dst = str;
@@ -45,6 +45,19 @@ static char *normalize(char *str) *dst++ = '/'; else if (*str == '\\') *dst++ = *++str; + else if (*str == '?') { + char *paramval; + int i = 0; + int size = asprintf(¶mval, "%d", runtime); + + if (size < 0) + *dst++ = '0'; + else { + while (i < size) + *dst++ = paramval[i++]; + free(paramval); + } + } else *dst++ = *str; str++;
@@ -54,16 +67,16 @@ static char *normalize(char *str) return ret; } -static int str(yyscan_t scanner, int token) +static int str(yyscan_t scanner, int token, int runtime) { YYSTYPE *yylval = expr_get_lval(scanner); char *text = expr_get_text(scanner); - yylval->str = normalize(strdup(text)); + yylval->str = normalize(strdup(text), runtime); if (!yylval->str) return EXPR_ERROR; - yylval->str = normalize(yylval->str); + yylval->str = normalize(yylval->str, runtime); return token; } %}
@@ -72,8 +85,8 @@ number [0-9]+ sch [-,=] spec \\{sch} -sym [0-9a-zA-Z_\.:@]+ -symbol {spec}*{sym}*{spec}*{sym}* +sym [0-9a-zA-Z_\.:@?]+ +symbol {spec}*{sym}*{spec}*{sym}*{spec}*{sym} %% struct expr_scanner_ctx *sctx = expr_get_extra(yyscanner);
@@ -93,7 +106,7 @@ if { return IF; } else { return ELSE; } #smt_on { return SMT_ON; } {number} { return value(yyscanner, 10); } -{symbol} { return str(yyscanner, ID); } +{symbol} { return str(yyscanner, ID, sctx->runtime); } "|" { return '|'; } "^" { return '^'; } "&" { return '&'; }
tools/perf/util/metricgroup.c +25 -3
@@ -90,6 +90,7 @@ struct egroup {const char *metric_name;const char *metric_expr;const char *metric_unit; +int runtime; }; static struct evsel *find_evsel_group(struct evlist *perf_evlist,
@@ -202,6 +203,7 @@ static int metricgroup__setup_events(struct list_head *groups, expr->metric_name = eg->metric_name; expr->metric_unit = eg->metric_unit; expr->metric_events = metric_events; + expr->runtime = eg->runtime;list_add (&expr->nd, &me->head); }
@@ -485,15 +487,20 @@ static bool metricgroup__has_constraint(struct pmu_event *pe)return false; } +int __weak arch_get_runtimeparam (void ) +{ +return 1 ; +} +static int __metricgroup__add_metric (struct strbuf *events, -struct list_head *group_list,struct pmu_event *pe) +struct list_head *group_list,struct pmu_event *pe,int runtime) {const char **ids;int idnum;struct egroup *eg; -if (expr__find_other (pe->metric_expr,NULL , &ids, &idnum) <0 ) +if (expr__find_other (pe->metric_expr,NULL , &ids, &idnum, runtime) <0 )return -EINVAL ;if (events->len >0 )
@@ -513,6 +520,7 @@ static int __metricgroup__add_metric(struct strbuf *events, eg->metric_name = pe->metric_name; eg->metric_expr = pe->metric_expr; eg->metric_unit = pe->unit; + eg->runtime = runtime;list_add_tail (&eg->nd, group_list);return 0 ;
@@ -540,7 +548,21 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,pr_debug ("metric expr %s for %s\n" , pe->metric_expr, pe->metric_name); - ret =__metricgroup__add_metric (events, group_list, pe); +if (!strstr (pe->metric_expr,"?" )) { + ret =__metricgroup__add_metric (events, group_list, pe,1 ); + }else { +int j, count; + + count =arch_get_runtimeparam (); + +/* This loop is added to create multiple +* events depend on count value and add +* those events to group_list. +*/ + +for (j =0 ; j < count; j++) + ret =__metricgroup__add_metric (events, group_list, pe, j); + }if (ret == -ENOMEM )break ; }
tools/perf/util/metricgroup.h +2 -0
@@ -22,6 +22,7 @@ struct metric_expr {const char *metric_name;const char *metric_unit;struct evsel **metric_events; +int runtime; }; struct metric_event *metricgroup__lookup(struct rblist *metric_events,
@@ -34,4 +35,5 @@ int metricgroup__parse_groups(const struct option *opt,void metricgroup__print (bool metrics,bool groups,char *filter,bool raw,bool details);bool metricgroup__has_metric (const char *metric); +int arch_get_runtimeparam (void );#endif
tools/perf/util/stat-shadow.c +11 -6
@@ -336,7 +336,7 @@ void perf_stat__collect_metric_expr(struct evlist *evsel_list) metric_events = counter->metric_events;if (!metric_events) {if (expr__find_other (counter->metric_expr, counter->name, - &metric_names, &num_metric_names) <0 ) + &metric_names, &num_metric_names,1 ) <0 )continue ; metric_events = calloc(sizeof(struct evsel *),
@@ -723,6 +723,7 @@ static void generic_metric(struct perf_stat_config *config,char *name, const char *metric_name, const char *metric_unit, + int runtime, double avg, int cpu, struct perf_stat_output_ctx *out,
@@ -777,7 +778,7 @@ static void generic_metric(struct perf_stat_config *config, }if (!metric_events[i]) { -if (expr__parse (&ratio, &pctx, metric_expr) ==0 ) { +if (expr__parse (&ratio, &pctx, metric_expr, runtime) ==0 ) {char *unit;char metric_bf[64 ];
@@ -786,9 +787,13 @@ static void generic_metric(struct perf_stat_config *config, &unit, &scale) >= 0) { ratio *= scale; } - -scnprintf (metric_bf,sizeof (metric_bf), +if (strstr (metric_expr,"?" )) +scnprintf (metric_bf,sizeof (metric_bf), +"%s %s_%d" , unit, metric_name, runtime); +else +scnprintf (metric_bf,sizeof (metric_bf),"%s %s" , unit, metric_name); +print_metric (config, ctxp,NULL ,"%8.1f" , metric_bf, ratio); }else {
@@ -1022,7 +1027,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config,print_metric (config, ctxp,NULL ,NULL , name,0 ); }else if (evsel->metric_expr) {generic_metric (config, evsel->metric_expr, evsel->metric_events, evsel->name, - evsel->metric_name,NULL , avg, cpu, out, st); + evsel->metric_name,NULL ,1 , avg, cpu, out, st); }else if (runtime_stat_n (st,STAT_NSECS ,0 , cpu) !=0 ) {char unit ='M' ;char unit_buf[10 ];
@@ -1051,7 +1056,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, out->new_line (config, ctxp);generic_metric (config, mexp->metric_expr, mexp->metric_events, evsel->name, mexp->metric_name, - mexp->metric_unit, avg, cpu, out, st); + mexp->metric_unit, mexp->runtime, avg, cpu, out, st); } }if (num ==0 )
PATCH v8 5/7 perf/tests/expr: Added test for runtime param in metric expression
In reply to Kajol JainAdded test case for parsing "?" in metric expression.
--- tools/perf/tests/expr.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/perf/tests/expr.c +8 -0
@@ -59,6 +59,14 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)TEST_ASSERT_VAL ("find other" , !strcmp (other[2 ],"BOZO" ));TEST_ASSERT_VAL ("find other" , other[3 ] ==NULL ); +TEST_ASSERT_VAL ("find other" , +expr__find_other ("EVENT1\\,param\\=?@ + EVENT2\\,param\\=?@" ,NULL , + &other, &num_other,3 ) ==0 ); +TEST_ASSERT_VAL ("find other" , num_other ==2 ); +TEST_ASSERT_VAL ("find other" , !strcmp (other[0 ],"EVENT1,param=3/" )); +TEST_ASSERT_VAL ("find other" , !strcmp (other[1 ],"EVENT2,param=3/" )); +TEST_ASSERT_VAL ("find other" , other[2 ] ==NULL ); +for (i =0 ; i < num_other; i++)zfree (&other[i]);free ((void *)other);
Signature · 1 line
2.21.0
[tip: perf/core] perf tests expr: Added test for runtime param in metric expression
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 9022608ec5babbb0fa631234098d52895e7e34d8 Gitweb: https://git.kernel.org/tip/9022608ec5babbb0fa631234098d52895e7e34d8 Author: Kajol Jain <[email protected]> AuthorDate: Thu, 02 Apr 2020 02:03:38 +05:30 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Thu, 30 Apr 2020 10:48:33 -03:00
perf tests expr: Added test for runtime param in metric expression
Added test case for parsing "?" in metric expression.
--- tools/perf/tests/expr.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/perf/tests/expr.c +8 -0
@@ -59,6 +59,14 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)TEST_ASSERT_VAL ("find other" , !strcmp (other[2 ],"BOZO" ));TEST_ASSERT_VAL ("find other" , other[3 ] ==NULL ); +TEST_ASSERT_VAL ("find other" , +expr__find_other ("EVENT1\\,param\\=?@ + EVENT2\\,param\\=?@" ,NULL , + &other, &num_other,3 ) ==0 ); +TEST_ASSERT_VAL ("find other" , num_other ==2 ); +TEST_ASSERT_VAL ("find other" , !strcmp (other[0 ],"EVENT1,param=3/" )); +TEST_ASSERT_VAL ("find other" , !strcmp (other[1 ],"EVENT2,param=3/" )); +TEST_ASSERT_VAL ("find other" , other[2 ] ==NULL ); +for (i =0 ; i < num_other; i++)zfree (&other[i]);free ((void *)other);
PATCH v8 6/7 tools/perf: Enable Hz/hz prinitg for --metric-only option
In reply to Kajol JainCommit 54b5091606c18 ("perf stat: Implement --metric-only mode") added function 'valid_only_metric()' which drops "Hz" or "hz", if it is part of "ScaleUnit". This patch enable it since hv_24x7 supports couple of frequency events.
--- tools/perf/util/stat-display.c | 2 -- 1 file changed, 2 deletions(-)
tools/perf/util/stat-display.c +0 -2
@@ -237,8 +237,6 @@ static bool valid_only_metric(const char *unit)if (!unit)return false;if (strstr (unit,"/sec" ) || -strstr (unit,"hz" ) || -strstr (unit,"Hz" ) ||strstr (unit,"CPUs utilized" ))return false;return true;
Signature · 1 line
2.21.0
Re: [PATCH v8 6/7] tools/perf: Enable Hz/hz prinitg for --metric-only option
Quoted 15 lines · Kajol Jain
Commit
54b5091606c18("perf stat: Implement --metric-only mode") added function 'valid_only_metric()' which drops "Hz" or "hz", if it is part of "ScaleUnit". This patch enable it sincehv_24x7supports couple of frequency events.Signed-off-by Kajol Jain <[email protected]>--- tools/perf/util/stat-display.c | 2 -- 1 file changed, 2 deletions(-)tools/perf/util/stat-display.c +0
-0
tools/perf/util/stat-display.c static bool valid_only_metric(const char *unit) · line 241
Quoted 5 lines
tools/perf/util/stat-display.c +0
-2@@ -237,8 +237,6 @@ static bool valid_only_metric(const char *unit)if (!unit)return false; if (strstr(unit, "/sec") || - strstr(unit, "hz") || - strstr(unit, "Hz") ||
will this change output of --metric-only for some setups then?
Andi, are you ok with this?
other than this, the patchset looks ok to me
thanks,
jirka
Quoted 6 lines
tools/perf/util/stat-display.c +0
-0strstr(unit, "CPUs utilized"))return false;return true;Signature · 1 line
2.21.0
Re: [PATCH v8 6/7] tools/perf: Enable Hz/hz prinitg for --metric-only option
Quoted 13 lines
tools/perf/util/stat-display.c static bool valid_only_metric(const char *unit) · line 241
Quoted 10 lines
tools/perf/util/stat-display.c +0
-2@@ -237,8 +237,6 @@ static bool valid_only_metric(const char *unit)if (!unit)return false; if (strstr(unit, "/sec") || - strstr(unit, "hz") || - strstr(unit, "Hz") ||will this change output of --metric-only for some setups then?
Quoted 1 line
Andi, are you ok with this?
Yes should be ok
$ grep -i ScaleUnit.*hz arch/x86/*/* $
Probably was for some metric we later dropped.
-Andi
[tip: perf/core] perf tools: Enable Hz/hz prinitg for --metric-only option
In reply to Kajol JainThe following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 3351c6da896bf521b118bfbb699fbda8f2a816b3 Gitweb: https://git.kernel.org/tip/3351c6da896bf521b118bfbb699fbda8f2a816b3 Author: Kajol Jain <[email protected]> AuthorDate: Thu, 02 Apr 2020 02:03:39 +05:30 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Thu, 30 Apr 2020 10:48:33 -03:00
perf tools: Enable Hz/hz prinitg for --metric-only option
Commit 54b5091606c18 ("perf stat: Implement --metric-only mode") added function 'valid_only_metric()' which drops "Hz" or "hz", if it is part of "ScaleUnit". This patch enable it since hv_24x7 supports couple of frequency events.
--- tools/perf/util/stat-display.c | 2 -- 1 file changed, 2 deletions(-)
tools/perf/util/stat-display.c +0 -2
@@ -237,8 +237,6 @@ static bool valid_only_metric(const char *unit)if (!unit)return false;if (strstr (unit,"/sec" ) || -strstr (unit,"hz" ) || -strstr (unit,"Hz" ) ||strstr (unit,"CPUs utilized" ))return false;return true;
PATCH v8 7/7 perf/tools/pmu-events/powerpc: Add hv_24x7 socket/chip level metric events
In reply to Kajol JainThe hv_24×7 feature in IBM® POWER9™ processor-based servers provide the facility to continuously collect large numbers of hardware performance metrics efficiently and accurately.
This patch adds hv_24x7 metric file for different Socket/chip resources.
Result:
power9 platform:
command:# ./perf stat --metric-only -M Memory_RD_BW_Chip -C 0 -I 1000
1.000096188 0.9 0.3
2.000285720 0.5 0.1
3.000424990 0.4 0.1command:# ./perf stat --metric-only -M PowerBUS_Frequency -C 0 -I 1000
1.000097981 2.3 2.3
2.000291713 2.3 2.3
3.000421719 2.3 2.3
4.000550912 2.3 2.3--- .../arch/powerpc/power9/nest_metrics.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tools/perf/pmu-events/arch/powerpc/power9/nest_metrics.json
tools/perf/pmu-events/arch/powerpc/power9/nest_metrics.json new file +19 -0
@@ -0,0 +1,19 @@ +[ + { + "MetricExpr": "(hv_24x7@PM_MCS01_128B_RD_DISP_PORT01\\,chip\\=?@ + hv_24x7@PM_MCS01_128B_RD_DISP_PORT23\\,chip\\=?@ + hv_24x7@PM_MCS23_128B_RD_DISP_PORT01\\,chip\\=?@ + hv_24x7@PM_MCS23_128B_RD_DISP_PORT23\\,chip\\=?@)", + "MetricName": "Memory_RD_BW_Chip", + "MetricGroup": "Memory_BW", + "ScaleUnit": "1.6e-2MB" + }, + { + "MetricExpr": "(hv_24x7@PM_MCS01_128B_WR_DISP_PORT01\\,chip\\=?@ + hv_24x7@PM_MCS01_128B_WR_DISP_PORT23\\,chip\\=?@ + hv_24x7@PM_MCS23_128B_WR_DISP_PORT01\\,chip\\=?@ + hv_24x7@PM_MCS23_128B_WR_DISP_PORT23\\,chip\\=?@ )", + "MetricName": "Memory_WR_BW_Chip", + "MetricGroup": "Memory_BW", + "ScaleUnit": "1.6e-2MB" + }, + { + "MetricExpr": "(hv_24x7@PM_PB_CYC\\,chip\\=?@ )", + "MetricName": "PowerBUS_Frequency", + "ScaleUnit": "2.5e-7GHz" + } +]
Signature · 1 line
2.21.0
[tip: perf/core] perf vendor events power9: Add hv_24x7 socket/chip level metric events
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 354575c00d61c174e0ff070f56cf3cdbe6d23f9e Gitweb: https://git.kernel.org/tip/354575c00d61c174e0ff070f56cf3cdbe6d23f9e Author: Kajol Jain <[email protected]> AuthorDate: Thu, 02 Apr 2020 02:03:40 +05:30 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Thu, 30 Apr 2020 10:48:33 -03:00
perf vendor events power9: Add hv_24x7 socket/chip level metric events
The hv_24×7 feature in IBM® POWER9™ processor-based servers provide the facility to continuously collect large numbers of hardware performance metrics efficiently and accurately.
This patch adds hv_24x7 metric file for different Socket/chip resources.
Result:
power9 platform:
command:# ./perf stat --metric-only -M Memory_RD_BW_Chip -C 0 -I 1000
1.000096188 0.9 0.3
2.000285720 0.5 0.1
3.000424990 0.4 0.1command:# ./perf stat --metric-only -M PowerBUS_Frequency -C 0 -I 1000
1.000097981 2.3 2.3
2.000291713 2.3 2.3
3.000421719 2.3 2.3
4.000550912 2.3 2.3--- tools/perf/pmu-events/arch/powerpc/power9/nest_metrics.json | 19 +++++++- 1 file changed, 19 insertions(+) create mode 100644 tools/perf/pmu-events/arch/powerpc/power9/nest_metrics.json
tools/perf/pmu-events/arch/powerpc/power9/nest_metrics.json new file +19 -0
@@ -0,0 +1,19 @@ +[ + { + "MetricExpr": "(hv_24x7@PM_MCS01_128B_RD_DISP_PORT01\\,chip\\=?@ + hv_24x7@PM_MCS01_128B_RD_DISP_PORT23\\,chip\\=?@ + hv_24x7@PM_MCS23_128B_RD_DISP_PORT01\\,chip\\=?@ + hv_24x7@PM_MCS23_128B_RD_DISP_PORT23\\,chip\\=?@)", + "MetricName": "Memory_RD_BW_Chip", + "MetricGroup": "Memory_BW", + "ScaleUnit": "1.6e-2MB" + }, + { + "MetricExpr": "(hv_24x7@PM_MCS01_128B_WR_DISP_PORT01\\,chip\\=?@ + hv_24x7@PM_MCS01_128B_WR_DISP_PORT23\\,chip\\=?@ + hv_24x7@PM_MCS23_128B_WR_DISP_PORT01\\,chip\\=?@ + hv_24x7@PM_MCS23_128B_WR_DISP_PORT23\\,chip\\=?@ )", + "MetricName": "Memory_WR_BW_Chip", + "MetricGroup": "Memory_BW", + "ScaleUnit": "1.6e-2MB" + }, + { + "MetricExpr": "(hv_24x7@PM_PB_CYC\\,chip\\=?@ )", + "MetricName": "PowerBUS_Frequency", + "ScaleUnit": "2.5e-7GHz" + } +]
Quoted 24 lines · Kajol Jain
Patchset adds json file metric support for the
hv_24x7socket/chip level events. "hv_24x7" pmu interface events needs system dependent parameter like socket/chip/core. For example,hv_24x7chip level events needs specific chip-id to which the data is requested should be added as part of pmu events.So to enable JSON file support to "
hv_24x7" interface, patchset reads total number of sockets details in sysfs under "/sys/devices/hv_24x7/interface/".Second patch of the patchset adds
expr_scanner_ctxobject to hold user data for the expr scanner, which can be used to hold runtime parameter.Patch 4 & 6 of the patchset handles perf tool plumbing needed to replace the "?" character in the metric expression to proper value and
hv_24x7json metric file for different Socket/chip resources.Patch set also enable Hz/hz prinitg for --metric-only option to print metric data for bus frequency.
Applied and tested all these patches cleanly on top of jiri's flex changes with the changes done by Kan Liang for "Support metric group constraint" patchset and made required changes.
Quoted 8 lines
Also apply this patch on top of the fix patch send earlier for printing metric name incase overlapping events.
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=perf/core&id=37cd7f65bf71a48f25eeb6d9be5dacb20d008ea6Changelog:
v7 -> v8
- Add test case for testing parsing of "?" in metric expression
- Reaname variables name to runtime
thanks,
jirka
Hi Arnaldo,
Please let me know if there any changes required in this patchset,
as some of its patches are still not part of your perf/core tree.
Thanks,
Kajol Jain
Quoted 115 lines · Kajol Jain
Patchset adds json file metric support for the
hv_24x7socket/chip level events. "hv_24x7" pmu interface events needs system dependent parameter like socket/chip/core. For example,hv_24x7chip level events needs specific chip-id to which the data is requested should be added as part of pmu events.So to enable JSON file support to "
hv_24x7" interface, patchset reads total number of sockets details in sysfs under "/sys/devices/hv_24x7/interface/".Second patch of the patchset adds
expr_scanner_ctxobject to hold user data for the expr scanner, which can be used to hold runtime parameter.Patch 4 & 6 of the patchset handles perf tool plumbing needed to replace the "?" character in the metric expression to proper value and
hv_24x7json metric file for different Socket/chip resources.Patch set also enable Hz/hz prinitg for --metric-only option to print metric data for bus frequency.
Applied and tested all these patches cleanly on top of jiri's flex changes with the changes done by Kan Liang for "Support metric group constraint" patchset and made required changes.
Also apply this patch on top of the fix patch send earlier for printing metric name incase overlapping events.
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=perf/core&id=37cd7f65bf71a48f25eeb6d9be5dacb20d008ea6Changelog:
v7 -> v8
- Add test case for testing parsing of "?" in metric expression
- Reaname variables name to runtimev6 -> v7
- Spit patchset into two patch series one for kernel changes and other for tool side changes.
- Made changes Suggested by Jiri, including rather then reading runtime parameter from metric name, actually add it in structure egroup andmetric_expr.
- As we don't need to read runtime parameter from metric name, now I am not appending it and rather just printing it ingeneric_metricfunction.Kernel Side changes patch series: https://lkml.org/lkml/2020/3/27/58
v5 -> v6
- resolve compilation issue due to rearranging patch series.
- Rather then adding new function to take careof case for runtime param inmetricgroup__add_metric, usingmetricgroup__add_metric_paramitself for that work.
- Address some optimization suggested like using directly file path rather then adding new macro inheader.c
- Change commit message on patch where we are adding "?" support by adding simple example.v4 -> v5
- Usingsysfs__read_intinstead ofsysfs__read_ullwhile reading parameter value inpowerpc/util/header.cfile.- Using asprintf rather then malloc and sprintf
Suggested by Arnaldo Carvalho de Melo- Break patch 6 from previous version to two patch,
- One to add refactor current "metricgroup__add_metric" function and another where actually "?" handling infra added.- Add
expr__runtimeparamas part of 'expr_scanner_ctx' struct rather then making it global variable. Thanks Jiri for adding this structure to hold user data for the expr scanner.- Add runtime param as agrugement to function '
expr__find_other' and 'expr__parse' and made changes on references accordingly.v3 -> v4
- Apply these patch on top of Kan liang changes.
As suggested by Jiri.v2 -> v3
- Remove settingevent_countto 0 part in function 'h_24x7_event_read' with comment rather then adding 0 toevent_countvalue. Suggested by: Sukadev Bhattiprolu- Apply tool side changes require to replace "?" on Jiri's flex patch series and made all require changes to make it compatible with added flex change.
v1 -> v2
- Rename hv-24x7 metric json file as nest_metrics.jsonJiri Olsa (2):
perf expr: Addexpr_prefix forparse_ctxandparse_idperf expr: Addexpr_scanner_ctxobjectKajol Jain (5):
perf/tools: Refactoringmetricgroup__add_metricfunction perf/tools: Enhance JSON/metric infrastructure to handle "?" perf/tests/expr: Added test for runtime param in metric expressiontools/perf: Enable Hz/hz prinitg for --metric-only option perf/tools/pmu-events/powerpc: Addhv_24x7socket/chip level metric
eventstools/perf/arch/powerpc/util/header.c | 8 ++ .../arch/powerpc/power9/nest_metrics.json | 19 +++++ tools/perf/tests/expr.c | 20 +++-- tools/perf/util/expr.c | 25 +++--- tools/perf/util/expr.h | 19 +++-- tools/perf/util/expr.l | 37 ++++++--- tools/perf/util/expr.y | 6 +- tools/perf/util/metricgroup.c | 78 +++++++++++++------ tools/perf/util/metricgroup.h | 2 + tools/perf/util/stat-display.c | 2 - tools/perf/util/stat-shadow.c | 19 +++-- 11 files changed, 164 insertions(+), 71 deletions(-) create mode 100644 tools/perf/pmu-events/arch/powerpc/power9/nest_metrics.json
Em Tue, Apr 28, 2020 at 12:02:42PM +0530, kajoljain escreveu:
Quoted 3 lines
Hi Arnaldo,
Please let me know if there any changes required in this patchset,
as some of its patches are still not part of your perf/core tree.
Thanks, I checked and all seems ok, added Jiri's Acked-by, appreciated, thanks,
- Arnaldo
Quoted 119 lines
Thanks,
Kajol JainQuoted 115 lines · Kajol Jain
Patchset adds json file metric support for the
hv_24x7socket/chip level events. "hv_24x7" pmu interface events needs system dependent parameter like socket/chip/core. For example,hv_24x7chip level events needs specific chip-id to which the data is requested should be added as part of pmu events.So to enable JSON file support to "
hv_24x7" interface, patchset reads total number of sockets details in sysfs under "/sys/devices/hv_24x7/interface/".Second patch of the patchset adds
expr_scanner_ctxobject to hold user data for the expr scanner, which can be used to hold runtime parameter.Patch 4 & 6 of the patchset handles perf tool plumbing needed to replace the "?" character in the metric expression to proper value and
hv_24x7json metric file for different Socket/chip resources.Patch set also enable Hz/hz prinitg for --metric-only option to print metric data for bus frequency.
Applied and tested all these patches cleanly on top of jiri's flex changes with the changes done by Kan Liang for "Support metric group constraint" patchset and made required changes.
Also apply this patch on top of the fix patch send earlier for printing metric name incase overlapping events.
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?h=perf/core&id=37cd7f65bf71a48f25eeb6d9be5dacb20d008ea6Changelog:
v7 -> v8
- Add test case for testing parsing of "?" in metric expression
- Reaname variables name to runtimev6 -> v7
- Spit patchset into two patch series one for kernel changes and other for tool side changes.
- Made changes Suggested by Jiri, including rather then reading runtime parameter from metric name, actually add it in structure egroup andmetric_expr.
- As we don't need to read runtime parameter from metric name, now I am not appending it and rather just printing it ingeneric_metricfunction.Kernel Side changes patch series: https://lkml.org/lkml/2020/3/27/58
v5 -> v6
- resolve compilation issue due to rearranging patch series.
- Rather then adding new function to take careof case for runtime param inmetricgroup__add_metric, usingmetricgroup__add_metric_paramitself for that work.
- Address some optimization suggested like using directly file path rather then adding new macro inheader.c
- Change commit message on patch where we are adding "?" support by adding simple example.v4 -> v5
- Usingsysfs__read_intinstead ofsysfs__read_ullwhile reading parameter value inpowerpc/util/header.cfile.- Using asprintf rather then malloc and sprintf
Suggested by Arnaldo Carvalho de Melo- Break patch 6 from previous version to two patch,
- One to add refactor current "metricgroup__add_metric" function and another where actually "?" handling infra added.- Add
expr__runtimeparamas part of 'expr_scanner_ctx' struct rather then making it global variable. Thanks Jiri for adding this structure to hold user data for the expr scanner.- Add runtime param as agrugement to function '
expr__find_other' and 'expr__parse' and made changes on references accordingly.v3 -> v4
- Apply these patch on top of Kan liang changes.
As suggested by Jiri.v2 -> v3
- Remove settingevent_countto 0 part in function 'h_24x7_event_read' with comment rather then adding 0 toevent_countvalue. Suggested by: Sukadev Bhattiprolu- Apply tool side changes require to replace "?" on Jiri's flex patch series and made all require changes to make it compatible with added flex change.
v1 -> v2
- Rename hv-24x7 metric json file as nest_metrics.jsonJiri Olsa (2):
perf expr: Addexpr_prefix forparse_ctxandparse_idperf expr: Addexpr_scanner_ctxobjectKajol Jain (5):
perf/tools: Refactoringmetricgroup__add_metricfunction perf/tools: Enhance JSON/metric infrastructure to handle "?" perf/tests/expr: Added test for runtime param in metric expressiontools/perf: Enable Hz/hz prinitg for --metric-only option perf/tools/pmu-events/powerpc: Addhv_24x7socket/chip level metric
eventstools/perf/arch/powerpc/util/header.c | 8 ++ .../arch/powerpc/power9/nest_metrics.json | 19 +++++ tools/perf/tests/expr.c | 20 +++-- tools/perf/util/expr.c | 25 +++--- tools/perf/util/expr.h | 19 +++-- tools/perf/util/expr.l | 37 ++++++--- tools/perf/util/expr.y | 6 +- tools/perf/util/metricgroup.c | 78 +++++++++++++------ tools/perf/util/metricgroup.h | 2 + tools/perf/util/stat-display.c | 2 - tools/perf/util/stat-shadow.c | 19 +++-- 11 files changed, 164 insertions(+), 71 deletions(-) create mode 100644 tools/perf/pmu-events/arch/powerpc/power9/nest_metrics.json
Signature · 1 line
- Arnaldo