aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/parse-events.c
diff options
context:
space:
mode:
authorHe Kuang <hekuang@huawei.com>2015-09-27 23:52:13 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-09-28 16:25:53 -0400
commit0b8891a8e62cb537b65ebc55cfbbb4ec22333c44 (patch)
tree7183e177cbd4fc2a61949de2212cc2bd21f8ebc5 /tools/perf/util/parse-events.c
parentba11ba65e02836c475427ae199adfc2d8cc4a900 (diff)
perf tools: Adds the config_term callback for different type events
Currently, function config_term() is used for checking config terms of all types of events, while unknown terms is not reported as an error because pmu events have valid terms in sysfs. But this is wrong when unknown terms are specificed to hw/sw events. This patch Adds the config_term callback so we can use separate check routines for each type of events. Signed-off-by: He Kuang <hekuang@huawei.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Kan Liang <kan.liang@intel.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Wang Nan <wangnan0@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1443412336-120050-1-git-send-email-hekuang@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/parse-events.c')
-rw-r--r--tools/perf/util/parse-events.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 61c2bc20926d..9dc3fb6ee81e 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -599,9 +599,13 @@ static int check_type_val(struct parse_events_term *term,
599 return -EINVAL; 599 return -EINVAL;
600} 600}
601 601
602static int config_term(struct perf_event_attr *attr, 602typedef int config_term_func_t(struct perf_event_attr *attr,
603 struct parse_events_term *term, 603 struct parse_events_term *term,
604 struct parse_events_error *err) 604 struct parse_events_error *err);
605
606static int config_term_common(struct perf_event_attr *attr,
607 struct parse_events_term *term,
608 struct parse_events_error *err)
605{ 609{
606#define CHECK_TYPE_VAL(type) \ 610#define CHECK_TYPE_VAL(type) \
607do { \ 611do { \
@@ -610,12 +614,6 @@ do { \
610} while (0) 614} while (0)
611 615
612 switch (term->type_term) { 616 switch (term->type_term) {
613 case PARSE_EVENTS__TERM_TYPE_USER:
614 /*
615 * Always succeed for sysfs terms, as we dont know
616 * at this point what type they need to have.
617 */
618 return 0;
619 case PARSE_EVENTS__TERM_TYPE_CONFIG: 617 case PARSE_EVENTS__TERM_TYPE_CONFIG:
620 CHECK_TYPE_VAL(NUM); 618 CHECK_TYPE_VAL(NUM);
621 attr->config = term->val.num; 619 attr->config = term->val.num;
@@ -665,9 +663,24 @@ do { \
665#undef CHECK_TYPE_VAL 663#undef CHECK_TYPE_VAL
666} 664}
667 665
666static int config_term_pmu(struct perf_event_attr *attr,
667 struct parse_events_term *term,
668 struct parse_events_error *err)
669{
670 if (term->type_term == PARSE_EVENTS__TERM_TYPE_USER)
671 /*
672 * Always succeed for sysfs terms, as we dont know
673 * at this point what type they need to have.
674 */
675 return 0;
676 else
677 return config_term_common(attr, term, err);
678}
679
668static int config_attr(struct perf_event_attr *attr, 680static int config_attr(struct perf_event_attr *attr,
669 struct list_head *head, 681 struct list_head *head,
670 struct parse_events_error *err) 682 struct parse_events_error *err,
683 config_term_func_t config_term)
671{ 684{
672 struct parse_events_term *term; 685 struct parse_events_term *term;
673 686
@@ -735,7 +748,8 @@ int parse_events_add_numeric(struct parse_events_evlist *data,
735 attr.config = config; 748 attr.config = config;
736 749
737 if (head_config) { 750 if (head_config) {
738 if (config_attr(&attr, head_config, data->error)) 751 if (config_attr(&attr, head_config, data->error,
752 config_term_common))
739 return -EINVAL; 753 return -EINVAL;
740 754
741 if (get_config_terms(head_config, &config_terms)) 755 if (get_config_terms(head_config, &config_terms))
@@ -795,7 +809,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
795 * Configure hardcoded terms first, no need to check 809 * Configure hardcoded terms first, no need to check
796 * return value when called with fail == 0 ;) 810 * return value when called with fail == 0 ;)
797 */ 811 */
798 if (config_attr(&attr, head_config, data->error)) 812 if (config_attr(&attr, head_config, data->error, config_term_pmu))
799 return -EINVAL; 813 return -EINVAL;
800 814
801 if (get_config_terms(head_config, &config_terms)) 815 if (get_config_terms(head_config, &config_terms))