perf, tools: Enable type checking for perf_evsel_config_term types
PATCH 1/2 perf, tools: Enable type checking for perf_evsel_config_term types
From: Andi Kleen <[email protected]>
Use a typed enum for the perf_evsel_config_term type enum. This allows gcc to do much stronger type checks, and also check for missing case statements.
I removed the unused _MAX member from the number.
It found one missing case. I'm not sure it's a real problem, so I just turned it into a BUG_ON for now.
--- tools/perf/util/evsel.c | 2 ++ tools/perf/util/evsel.h | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-)
tools/perf/util/evsel.c +2 -0
@@ -775,6 +775,8 @@ static void apply_config_terms(struct perf_evsel *evsel,case PERF_EVSEL__CONFIG_TERM_OVERWRITE : attr->write_backward = term->val.overwrite ?1 :0 ;break ; +case PERF_EVSEL__CONFIG_TERM_DRV_CFG : +BUG_ON (1 );default :break ; }
tools/perf/util/evsel.h +2 -3
@@ -37,7 +37,7 @@ struct cgroup_sel;* It is allocated within event parsing and attached to * perf_evsel::config_terms list head. */ -enum { +enum period_type {PERF_EVSEL__CONFIG_TERM_PERIOD ,PERF_EVSEL__CONFIG_TERM_FREQ ,PERF_EVSEL__CONFIG_TERM_TIME ,
@@ -48,12 +48,11 @@ enum { PERF_EVSEL__CONFIG_TERM_OVERWRITE,PERF_EVSEL__CONFIG_TERM_DRV_CFG , PERF_EVSEL__CONFIG_TERM_BRANCH, - PERF_EVSEL__CONFIG_TERM_MAX, };struct perf_evsel_config_term {struct list_head list; -int type; +enum period_type type;union {u64 period;u64 freq;
Signature · 1 line
2.13.6
PATCH 2/2 perf, tools, record: Fix -c/-F options for cpu event aliases
From: Andi Kleen <[email protected]>
The Intel PMU event aliases have a implicit
period= specifier to set the default period.
Unfortunately this breaks overriding these periods with -c or -F, because the alias terms look like they are user specified to the internal parser, and user specified event qualifiers override the command line options.
Track that they are coming from aliases by adding a "weak" state to the term. Any weak terms don't override command line options.
I only did it for -c/-F for now, I think that's the only case that's broken currently.
Before:
$ perf record -c 1000 -vv -e uops_issued.any
...
{ sample_period, sample_freq } 2000003After:
$ perf record -c 1000 -vv -e uops_issued.any
...
{ sample_period, sample_freq } 1000--- tools/perf/util/evsel.c | 12 ++++++++---- tools/perf/util/evsel.h | 1 + tools/perf/util/parse-events.c | 2 ++ tools/perf/util/parse-events.h | 3 +++ tools/perf/util/pmu.c | 5 +++++ 5 files changed, 19 insertions(+), 4 deletions(-)
tools/perf/util/evsel.c +8 -4
@@ -733,12 +733,16 @@ static void apply_config_terms(struct perf_evsel *evsel,list_for_each_entry (term, config_terms, list) {switch (term->type) {case PERF_EVSEL__CONFIG_TERM_PERIOD : - attr->sample_period = term->val.period; - attr->freq =0 ; +if (!(term->weak && opts->user_interval !=ULLONG_MAX )) { + attr->sample_period = term->val.period; + attr->freq =0 ; + }break ;case PERF_EVSEL__CONFIG_TERM_FREQ : - attr->sample_freq = term->val.freq; - attr->freq =1 ; +if (!(term->weak && opts->user_freq !=UINT_MAX )) { + attr->sample_freq = term->val.freq; + attr->freq =1 ; + }break ;case PERF_EVSEL__CONFIG_TERM_TIME :if (term->val.time)
tools/perf/util/evsel.h +1 -0
@@ -65,6 +65,7 @@ struct perf_evsel_config_term {bool overwrite;char *branch; } val; +bool weak; };/** struct perf_evsel - event selector
tools/perf/util/parse-events.c +2 -0
@@ -1115,6 +1115,7 @@ do { \INIT_LIST_HEAD (&__t->list); \ __t->type = PERF_EVSEL__CONFIG_TERM_ ## __type; \ __t->val.__name = __val; \ + __t->weak = term->weak; \list_add_tail (&__t->list, head_terms); \ }while (0 )
@@ -2409,6 +2410,7 @@ static int new_term(struct parse_events_term **_term, *term = *temp;INIT_LIST_HEAD (&term->list); + term->weak = false;switch (term->type_val) {case PARSE_EVENTS__TERM_TYPE_NUM :
tools/perf/util/parse-events.h +3 -0
@@ -100,6 +100,9 @@ struct parse_events_term {/* error string indexes for within parsed string */ int err_term;int err_val; + +/* Coming from implicit alias */ +bool weak; };struct parse_events_error {
tools/perf/util/pmu.c +5 -0
@@ -404,6 +404,11 @@ static int pmu_alias_terms(struct perf_pmu_alias *alias,parse_events_terms__purge (&list);return ret; } +/* +* Weak terms don't override command line options, +* which we don't want for implicit terms in aliases. +*/ + cloned->weak = true;list_add_tail (&cloned->list, &list); }list_splice (&list, terms);
Signature · 1 line
2.13.6
Re: [PATCH 2/2] perf, tools, record: Fix -c/-F options for cpu event aliases
Quoted 23 lines · Andi Kleen
From: Andi Kleen <[email protected]>
The Intel PMU event aliases have a implicit
period= specifier to set the default period.Unfortunately this breaks overriding these periods with -c or -F, because the alias terms look like they are user specified to the internal parser, and user specified event qualifiers override the command line options.
Track that they are coming from aliases by adding a "weak" state to the term. Any weak terms don't override command line options.
I only did it for -c/-F for now, I think that's the only case that's broken currently.
Before:
$ perf record -c 1000 -vv -e uops_issued.any ... { sample_period, sample_freq } 2000003
Quoted 7 lines
After:
$ perf record -c 1000 -vv -e uops_issued.any ... { sample_period, sample_freq } 1000Signed-off-by Andi Kleen <[email protected]>
thanks,
jirka
tip-bot for Andi Kleen
merge bot[tip:perf/core] perf record: Fix -c/-F options for cpu event aliases
In reply to Andi Kleenperf record: Fix -c/-F options for cpu event aliases
Commit-ID: c2f1cead19b628d7a23d2cfc43e444af669f9eab Gitweb: https://git.kernel.org/tip/c2f1cead19b628d7a23d2cfc43e444af669f9eab Author: Andi Kleen <[email protected]> AuthorDate: Fri, 20 Oct 2017 13:27:55 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 16 Nov 2017 14:49:51 -0300
perf record: Fix -c/-F options for cpu event aliases
The Intel PMU event aliases have a implicit period= specifier to set the default period.
Unfortunately this breaks overriding these periods with -c or -F, because the alias terms look like they are user specified to the internal parser, and user specified event qualifiers override the command line options.
Track that they are coming from aliases by adding a "weak" state to the term. Any weak terms don't override command line options.
I only did it for -c/-F for now, I think that's the only case that's broken currently.
Before:
$ perf record -c 1000 -vv -e uops_issued.any
...
{ sample_period, sample_freq } 2000003After:
$ perf record -c 1000 -vv -e uops_issued.any
...
{ sample_period, sample_freq } 1000--- tools/perf/util/evsel.c | 12 ++++++++---- tools/perf/util/evsel.h | 1 + tools/perf/util/parse-events.c | 2 ++ tools/perf/util/parse-events.h | 3 +++ tools/perf/util/pmu.c | 5 +++++ 5 files changed, 19 insertions(+), 4 deletions(-)
tools/perf/util/evsel.c +8 -4
@@ -733,12 +733,16 @@ static void apply_config_terms(struct perf_evsel *evsel,list_for_each_entry (term, config_terms, list) {switch (term->type) {case PERF_EVSEL__CONFIG_TERM_PERIOD : - attr->sample_period = term->val.period; - attr->freq =0 ; +if (!(term->weak && opts->user_interval !=ULLONG_MAX )) { + attr->sample_period = term->val.period; + attr->freq =0 ; + }break ;case PERF_EVSEL__CONFIG_TERM_FREQ : - attr->sample_freq = term->val.freq; - attr->freq =1 ; +if (!(term->weak && opts->user_freq !=UINT_MAX )) { + attr->sample_freq = term->val.freq; + attr->freq =1 ; + }break ;case PERF_EVSEL__CONFIG_TERM_TIME :if (term->val.time)
tools/perf/util/evsel.h +1 -0
@@ -67,6 +67,7 @@ struct perf_evsel_config_term {bool overwrite;char *branch; } val; +bool weak; };struct perf_stat_evsel ;
tools/perf/util/parse-events.c +2 -0
@@ -1116,6 +1116,7 @@ do { \INIT_LIST_HEAD (&__t->list); \ __t->type = PERF_EVSEL__CONFIG_TERM_ ## __type; \ __t->val.__name = __val; \ + __t->weak = term->weak; \list_add_tail (&__t->list, head_terms); \ }while (0 )
@@ -2410,6 +2411,7 @@ static int new_term(struct parse_events_term **_term, *term = *temp;INIT_LIST_HEAD (&term->list); + term->weak = false;switch (term->type_val) {case PARSE_EVENTS__TERM_TYPE_NUM :
tools/perf/util/parse-events.h +3 -0
@@ -101,6 +101,9 @@ struct parse_events_term {/* error string indexes for within parsed string */ int err_term;int err_val; + +/* Coming from implicit alias */ +bool weak; };struct parse_events_error {
tools/perf/util/pmu.c +5 -0
@@ -405,6 +405,11 @@ static int pmu_alias_terms(struct perf_pmu_alias *alias,parse_events_terms__purge (&list);return ret; } +/* +* Weak terms don't override command line options, +* which we don't want for implicit terms in aliases. +*/ + cloned->weak = true;list_add_tail (&cloned->list, &list); }list_splice (&list, terms);
tip-bot for Andi Kleen
merge bot[tip:perf/core] perf record: Fix -c/-F options for cpu event aliases
In reply to Andi Kleenperf record: Fix -c/-F options for cpu event aliases
Commit-ID: 59622fd496a3175c7bf549046e091d81c303ecff Gitweb: https://git.kernel.org/tip/59622fd496a3175c7bf549046e091d81c303ecff Author: Andi Kleen <[email protected]> AuthorDate: Fri, 20 Oct 2017 13:27:55 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 28 Nov 2017 14:19:39 -0300
perf record: Fix -c/-F options for cpu event aliases
The Intel PMU event aliases have a implicit period= specifier to set the default period.
Unfortunately this breaks overriding these periods with -c or -F, because the alias terms look like they are user specified to the internal parser, and user specified event qualifiers override the command line options.
Track that they are coming from aliases by adding a "weak" state to the term. Any weak terms don't override command line options.
I only did it for -c/-F for now, I think that's the only case that's broken currently.
Before:
$ perf record -c 1000 -vv -e uops_issued.any
...
{ sample_period, sample_freq } 2000003After:
$ perf record -c 1000 -vv -e uops_issued.any
...
{ sample_period, sample_freq } 1000--- tools/perf/util/evsel.c | 12 ++++++++---- tools/perf/util/evsel.h | 1 + tools/perf/util/parse-events.c | 2 ++ tools/perf/util/parse-events.h | 3 +++ tools/perf/util/pmu.c | 5 +++++ 5 files changed, 19 insertions(+), 4 deletions(-)
tools/perf/util/evsel.c +8 -4
@@ -733,12 +733,16 @@ static void apply_config_terms(struct perf_evsel *evsel,list_for_each_entry (term, config_terms, list) {switch (term->type) {case PERF_EVSEL__CONFIG_TERM_PERIOD : - attr->sample_period = term->val.period; - attr->freq =0 ; +if (!(term->weak && opts->user_interval !=ULLONG_MAX )) { + attr->sample_period = term->val.period; + attr->freq =0 ; + }break ;case PERF_EVSEL__CONFIG_TERM_FREQ : - attr->sample_freq = term->val.freq; - attr->freq =1 ; +if (!(term->weak && opts->user_freq !=UINT_MAX )) { + attr->sample_freq = term->val.freq; + attr->freq =1 ; + }break ;case PERF_EVSEL__CONFIG_TERM_TIME :if (term->val.time)
tools/perf/util/evsel.h +1 -0
@@ -67,6 +67,7 @@ struct perf_evsel_config_term {bool overwrite;char *branch; } val; +bool weak; };struct perf_stat_evsel ;
tools/perf/util/parse-events.c +2 -0
@@ -1116,6 +1116,7 @@ do { \INIT_LIST_HEAD (&__t->list); \ __t->type = PERF_EVSEL__CONFIG_TERM_ ## __type; \ __t->val.__name = __val; \ + __t->weak = term->weak; \list_add_tail (&__t->list, head_terms); \ }while (0 )
@@ -2410,6 +2411,7 @@ static int new_term(struct parse_events_term **_term, *term = *temp;INIT_LIST_HEAD (&term->list); + term->weak = false;switch (term->type_val) {case PARSE_EVENTS__TERM_TYPE_NUM :
tools/perf/util/parse-events.h +3 -0
@@ -101,6 +101,9 @@ struct parse_events_term {/* error string indexes for within parsed string */ int err_term;int err_val; + +/* Coming from implicit alias */ +bool weak; };struct parse_events_error {
tools/perf/util/pmu.c +5 -0
@@ -405,6 +405,11 @@ static int pmu_alias_terms(struct perf_pmu_alias *alias,parse_events_terms__purge (&list);return ret; } +/* +* Weak terms don't override command line options, +* which we don't want for implicit terms in aliases. +*/ + cloned->weak = true;list_add_tail (&cloned->list, &list); }list_splice (&list, terms);
Quoted 35 lines · Andi Kleen
From: Andi Kleen <[email protected]>
Use a typed enum for the
perf_evsel_config_termtype enum. This allows gcc to do much stronger type checks, and also check for missing case statements.I removed the unused
_MAXmember from the number.It found one missing case. I'm not sure it's a real problem, so I just turned it into a
BUG_ONfor now.Signed-off-by Andi Kleen <[email protected]>--- tools/perf/util/evsel.c | 2 ++ tools/perf/util/evsel.h | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-)tools/perf/util/evsel.c +2
-0@@ -775,6 +775,8 @@ static void apply_config_terms(struct perf_evsel *evsel,case PERF_EVSEL__CONFIG_TERM_OVERWRITE : attr->write_backward = term->val.overwrite ?1 :0 ;break ; +case PERF_EVSEL__CONFIG_TERM_DRV_CFG : +BUG_ON (1 );default :break ; }tools/perf/util/evsel.h +0
-0
tools/perf/util/evsel.h struct cgroup_sel; · line 40
Quoted 5 lines
tools/perf/util/evsel.h +1
-1@@ -37,7 +37,7 @@ struct cgroup_sel;* It is allocated within event parsing and attached to * perf_evsel::config_terms list head. */ -enum { +enum period_type {
seems ok, but I'm puzzled with the 'period_type' name I think it should be more like 'term_type' or something
jirka
Quoted 20 lines
tools/perf/util/evsel.h +1
-2PERF_EVSEL__CONFIG_TERM_PERIOD ,PERF_EVSEL__CONFIG_TERM_FREQ , PERF_EVSEL__CONFIG_TERM_TIME,@@ -48,12 +48,11 @@ enum { PERF_EVSEL__CONFIG_TERM_OVERWRITE,PERF_EVSEL__CONFIG_TERM_DRV_CFG , PERF_EVSEL__CONFIG_TERM_BRANCH, - PERF_EVSEL__CONFIG_TERM_MAX, };struct perf_evsel_config_term {struct list_head list; -int type; +enum period_type type;union {u64 period;u64 freq;Signature · 1 line
2.13.6
Arnaldo Carvalho de Melo
maintainerEm Tue, Oct 24, 2017 at 09:38:49AM +0200, Jiri Olsa escreveu:
Quoted 36 lines · Andi Kleen
Quoted 35 lines
From: Andi Kleen <[email protected]>
Use a typed enum for the
perf_evsel_config_termtype enum. This allows gcc to do much stronger type checks, and also check for missing case statements.I removed the unused
_MAXmember from the number.It found one missing case. I'm not sure it's a real problem, so I just turned it into a
BUG_ONfor now.Signed-off-by Andi Kleen <[email protected]>--- tools/perf/util/evsel.c | 2 ++ tools/perf/util/evsel.h | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-)tools/perf/util/evsel.c +2
-0@@ -775,6 +775,8 @@ static void apply_config_terms(struct perf_evsel *evsel,case PERF_EVSEL__CONFIG_TERM_OVERWRITE : attr->write_backward = term->val.overwrite ?1 :0 ;break ; +case PERF_EVSEL__CONFIG_TERM_DRV_CFG : +BUG_ON (1 );default :break ; }tools/perf/util/evsel.h +0
-0@@ -37,7 +37,7 @@ struct cgroup_sel;
Quoted 8 lines
tools/perf/util/evsel.h struct cgroup_sel; · line 40
Quoted 5 lines
tools/perf/util/evsel.h +1
-1* It is allocated within event parsing and attached to * perf_evsel::config_terms list head. */ -enum { +enum period_type {seems ok, but I'm puzzled with the '
period_type' name I think it should be more like 'term_type' or something
Ok, renamed it to term_type and added your Acked-by,
- ARnaldo
Quoted 23 lines
jirka
Quoted 20 lines
tools/perf/util/evsel.h +1
-2PERF_EVSEL__CONFIG_TERM_PERIOD ,PERF_EVSEL__CONFIG_TERM_FREQ , PERF_EVSEL__CONFIG_TERM_TIME,@@ -48,12 +48,11 @@ enum { PERF_EVSEL__CONFIG_TERM_OVERWRITE,PERF_EVSEL__CONFIG_TERM_DRV_CFG , PERF_EVSEL__CONFIG_TERM_BRANCH, - PERF_EVSEL__CONFIG_TERM_MAX, };struct perf_evsel_config_term {struct list_head list; -int type; +enum period_type type;union {u64 period;u64 freq;Signature · 1 line
2.13.6
tip-bot for Andi Kleen
merge bot[tip:perf/core] perf evsel: Enable type checking for perf_evsel_config_term types
In reply to Andi Kleenperf evsel: Enable type checking for perf_evsel_config_term types
Commit-ID: d0565132605f454179699a1b8a3276fc0f8cc87b Gitweb: https://git.kernel.org/tip/d0565132605f454179699a1b8a3276fc0f8cc87b Author: Andi Kleen <[email protected]> AuthorDate: Fri, 20 Oct 2017 13:27:54 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 16 Nov 2017 14:49:51 -0300
perf evsel: Enable type checking for perf_evsel_config_term types
Use a typed enum for the perf_evsel_config_term type enum. This allows gcc to do much stronger type checks, and also check for missing case statements.
I removed the unused _MAX member from the number.
It found one missing case. I'm not sure it's a real problem, so I just turned it into a BUG_ON for now.
--- tools/perf/util/evsel.c | 2 ++ tools/perf/util/evsel.h | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-)
tools/perf/util/evsel.c +2 -0
@@ -779,6 +779,8 @@ static void apply_config_terms(struct perf_evsel *evsel,case PERF_EVSEL__CONFIG_TERM_OVERWRITE : attr->write_backward = term->val.overwrite ?1 :0 ;break ; +case PERF_EVSEL__CONFIG_TERM_DRV_CFG : +BUG_ON (1 );default :break ; }
tools/perf/util/evsel.h +2 -3
@@ -38,7 +38,7 @@ struct cgroup_sel;* It is allocated within event parsing and attached to * perf_evsel::config_terms list head. */ -enum { +enum term_type {PERF_EVSEL__CONFIG_TERM_PERIOD ,PERF_EVSEL__CONFIG_TERM_FREQ ,PERF_EVSEL__CONFIG_TERM_TIME ,
@@ -49,12 +49,11 @@ enum { PERF_EVSEL__CONFIG_TERM_OVERWRITE,PERF_EVSEL__CONFIG_TERM_DRV_CFG , PERF_EVSEL__CONFIG_TERM_BRANCH, - PERF_EVSEL__CONFIG_TERM_MAX, };struct perf_evsel_config_term {struct list_head list; -int type; +enum term_type type;union {u64 period;u64 freq;