From patchwork Thu Aug 22 14:44:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 19421 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f70.google.com (mail-vb0-f70.google.com [209.85.212.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CADDA248E6 for ; Thu, 22 Aug 2013 14:44:35 +0000 (UTC) Received: by mail-vb0-f70.google.com with SMTP id h10sf1586190vbh.1 for ; Thu, 22 Aug 2013 07:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:delivered-to:sender:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=jtQiXz7yZ3l0UeCrU7CfpAGhc3T2WBC63sR4Hlf1SIA=; b=dxP6r+kn0xYeu4kseeD4/m+5G90X5m2NypHp0foWRKbGzQkfjcel+C0ho+JysGDs2K iihF7ob9WOkM6jXJNU6kkh48SFTq616wrJil6iN47HyhAhVbR9CC4OQwIvFncjqyaBWY rbyF4Ube2WhegQ638iIjDUult42DTbrZoNtn2+vHdVjg9tqRad+/2n28rbquko89cKcz EhhABnQPP8x56N57Wbpc+uaNHsbwrtdgwEx55ignFIhSCk3Uv4fnL7uAPk1PqS39Eqko NeTdZAkgNFFjd0Cqx4bPdqsBo/9my3cnCi8WjHHwhecflHczAXO5JwiC/GlfKfAaII4K dzJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:sender:from:to:cc :subject:date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=jtQiXz7yZ3l0UeCrU7CfpAGhc3T2WBC63sR4Hlf1SIA=; b=G2xxJ36oMe6vHoB/btsXcF3YUppi5fCWCchuIukXAz+O67Bwx4Y+ITOoBKeBAxqXAu hZ+VfEMB+Wuhni7PJxxBptOO/Bbe2B8gVgTFRONTR9kMHZuOQpJRTnLp1fmAjwar35r0 MidINrcuN/ofSPlxDdBC/CLnbjng3gaik9tMEwXFDHdF4yWjK+x+GVUhhMvbU8JFXato rPHDSa1ElJJL2zENRgNpRJuWe+R7wSdXggl2pVMM1EL54Jd40pRs4VFYx21TbOIB/Fnr k3yjWCU/3SZtNDMyUVqk/UyUaq4ixVuEnV38nDdvAjqzicfrIgAwAD/QU6cv4B7rzNkL z3tg== X-Received: by 10.236.51.9 with SMTP id a9mr4689206yhc.41.1377182675632; Thu, 22 Aug 2013 07:44:35 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.76.33 with SMTP id h1ls1222206qew.29.gmail; Thu, 22 Aug 2013 07:44:35 -0700 (PDT) X-Received: by 10.52.249.102 with SMTP id yt6mr10041915vdc.21.1377182675534; Thu, 22 Aug 2013 07:44:35 -0700 (PDT) Received: from mail-vb0-x229.google.com (mail-vb0-x229.google.com [2607:f8b0:400c:c02::229]) by mx.google.com with ESMTPS id c13si4058479veu.77.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:44:35 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::229 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::229; Received: by mail-vb0-f41.google.com with SMTP id g17so1316036vbg.14 for ; Thu, 22 Aug 2013 07:44:35 -0700 (PDT) X-Gm-Message-State: ALoCoQl71Jw7vaidzF7dnCPImVbkw5fDU94ufJSfuvJQCqmqctssmY1ZgNfTFJv8FNE5kDF9kHBw X-Received: by 10.52.24.4 with SMTP id q4mr9630782vdf.6.1377182675425; Thu, 22 Aug 2013 07:44:35 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp34802vcz; Thu, 22 Aug 2013 07:44:34 -0700 (PDT) X-Received: by 10.204.62.132 with SMTP id x4mr10800986bkh.22.1377182674249; Thu, 22 Aug 2013 07:44:34 -0700 (PDT) Received: from mail-bk0-x22a.google.com (mail-bk0-x22a.google.com [2a00:1450:4008:c01::22a]) by mx.google.com with ESMTPS id pr9si2341032bkb.110.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:44:34 -0700 (PDT) Received-SPF: pass (google.com: domain of rric.net@gmail.com designates 2a00:1450:4008:c01::22a as permitted sender) client-ip=2a00:1450:4008:c01::22a; Received: by mail-bk0-f42.google.com with SMTP id my10so722594bkb.15 for ; Thu, 22 Aug 2013 07:44:33 -0700 (PDT) X-Received: by 10.204.66.133 with SMTP id n5mr2275869bki.38.1377182673078; Thu, 22 Aug 2013 07:44:33 -0700 (PDT) Received: from rric.localhost (g224195237.adsl.alicedsl.de. [92.224.195.237]) by mx.google.com with ESMTPSA id h5sm3117070bkg.8.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:44:31 -0700 (PDT) Sender: Robert Richter From: Robert Richter To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , Borislav Petkov , Jiri Olsa , linux-kernel@vger.kernel.org, Robert Richter , Robert Richter Subject: [PATCH resent 2/4] perf tools: Modify event parser to update event attribute by index Date: Thu, 22 Aug 2013 16:44:03 +0200 Message-Id: <1377182645-12922-3-git-send-email-rric@kernel.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1377182645-12922-1-git-send-email-rric@kernel.org> References: <1377182645-12922-1-git-send-email-rric@kernel.org> X-Original-Sender: rric.net@gmail.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::229 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gmail.com Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Robert Richter In a later patch we want to introduce a syntax that allows updating attribute fields by an index pointing to a certain u64 entry of struct perf_event_attr. We need this to expose any event via sysfs that is available in the system where especially flag fields need to be set. Reworking the event parser to use an attribute index. This is done by introducing type PARSE_EVENTS__TERM_TYPE_ATTR for all numeric values to be added to the event attribute fields. We use an index to specify the corresponding u64 attr value. Signed-off-by: Robert Richter Signed-off-by: Robert Richter --- tools/perf/tests/parse-events.c | 12 ++++++--- tools/perf/util/parse-events.c | 59 +++++++++++++++++++---------------------- tools/perf/util/parse-events.h | 12 ++++----- tools/perf/util/parse-events.l | 18 ++++++------- tools/perf/util/parse-events.y | 24 ++++++++++------- 5 files changed, 65 insertions(+), 60 deletions(-) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index 48114d1..0f6a4a7 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -464,7 +464,9 @@ static int test__checkterms_simple(struct list_head *terms) /* config=10 */ term = list_entry(terms->next, struct parse_events_term, list); TEST_ASSERT_VAL("wrong type term", - term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG); + term->type_term == PARSE_EVENTS__TERM_TYPE_ATTR); + TEST_ASSERT_VAL("wrong type idx", + term->idx == 1); TEST_ASSERT_VAL("wrong type val", term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); TEST_ASSERT_VAL("wrong val", term->val.num == 10); @@ -473,7 +475,9 @@ static int test__checkterms_simple(struct list_head *terms) /* config1 */ term = list_entry(term->list.next, struct parse_events_term, list); TEST_ASSERT_VAL("wrong type term", - term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1); + term->type_term == PARSE_EVENTS__TERM_TYPE_ATTR); + TEST_ASSERT_VAL("wrong type idx", + term->idx == 7); TEST_ASSERT_VAL("wrong type val", term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); TEST_ASSERT_VAL("wrong val", term->val.num == 1); @@ -482,7 +486,9 @@ static int test__checkterms_simple(struct list_head *terms) /* config2=3 */ term = list_entry(term->list.next, struct parse_events_term, list); TEST_ASSERT_VAL("wrong type term", - term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2); + term->type_term == PARSE_EVENTS__TERM_TYPE_ATTR); + TEST_ASSERT_VAL("wrong type idx", + term->idx == 8); TEST_ASSERT_VAL("wrong type val", term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); TEST_ASSERT_VAL("wrong val", term->val.num == 3); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 9cba923..0d10a0a 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -535,6 +535,19 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx, return add_event(list, idx, &attr, NULL); } +int parse_events__set_attr(struct perf_event_attr *__attr, u64 idx, u64 val) +{ + __u64 *attr = (__u64 *)__attr; + + if (idx * sizeof(*attr) >= sizeof(*__attr)) + return -EINVAL; + + attr += idx; + *attr |= val; + + return 0; +} + static int config_term(struct perf_event_attr *attr, struct parse_events_term *term) { @@ -545,36 +558,17 @@ do { \ } while (0) switch (term->type_term) { - case PARSE_EVENTS__TERM_TYPE_CONFIG: + case PARSE_EVENTS__TERM_TYPE_ATTR: CHECK_TYPE_VAL(NUM); - attr->config = term->val.num; - break; - case PARSE_EVENTS__TERM_TYPE_CONFIG1: - CHECK_TYPE_VAL(NUM); - attr->config1 = term->val.num; - break; - case PARSE_EVENTS__TERM_TYPE_CONFIG2: - CHECK_TYPE_VAL(NUM); - attr->config2 = term->val.num; - break; - case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD: - CHECK_TYPE_VAL(NUM); - attr->sample_period = term->val.num; - break; - case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE: - /* - * TODO uncomment when the field is available - * attr->branch_sample_type = term->val.num; - */ - break; + return parse_events__set_attr(attr, term->idx, term->val.num); case PARSE_EVENTS__TERM_TYPE_NAME: CHECK_TYPE_VAL(STR); - break; + return 0; default: - return -EINVAL; + break; } - return 0; + return -EINVAL; #undef CHECK_TYPE_VAL } @@ -1212,7 +1206,7 @@ int parse_events__is_hardcoded_term(struct parse_events_term *term) static int new_term(struct parse_events_term **_term, int type_val, int type_term, char *config, - char *str, u64 num) + char *str, u64 num, u64 idx) { struct parse_events_term *term; @@ -1223,7 +1217,8 @@ static int new_term(struct parse_events_term **_term, int type_val, INIT_LIST_HEAD(&term->list); term->type_val = type_val; term->type_term = type_term; - term->config = config; + term->config = config; + term->idx = idx; switch (type_val) { case PARSE_EVENTS__TERM_TYPE_NUM: @@ -1242,17 +1237,17 @@ static int new_term(struct parse_events_term **_term, int type_val, } int parse_events_term__num(struct parse_events_term **term, - int type_term, char *config, u64 num) + int type_term, char *config, u64 num, u64 idx) { return new_term(term, PARSE_EVENTS__TERM_TYPE_NUM, type_term, - config, NULL, num); + config, NULL, num, idx); } int parse_events_term__str(struct parse_events_term **term, int type_term, char *config, char *str) { return new_term(term, PARSE_EVENTS__TERM_TYPE_STR, type_term, - config, str, 0); + config, str, 0, 0); } int parse_events_term__sym_hw(struct parse_events_term **term, @@ -1266,18 +1261,18 @@ int parse_events_term__sym_hw(struct parse_events_term **term, if (config) return new_term(term, PARSE_EVENTS__TERM_TYPE_STR, PARSE_EVENTS__TERM_TYPE_USER, config, - (char *) sym->symbol, 0); + (char *) sym->symbol, 0, 0); else return new_term(term, PARSE_EVENTS__TERM_TYPE_STR, PARSE_EVENTS__TERM_TYPE_USER, - (char *) "event", (char *) sym->symbol, 0); + (char *) "event", (char *) sym->symbol, 0, 0); } int parse_events_term__clone(struct parse_events_term **new, struct parse_events_term *term) { return new_term(new, term->type_val, term->type_term, term->config, - term->val.str, term->val.num); + term->val.str, term->val.num, term->idx); } void parse_events__free_terms(struct list_head *terms) diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index f1cb4c4..61bbe88 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -35,6 +35,8 @@ extern int parse_events_terms(struct list_head *terms, const char *str); extern int parse_filter(const struct option *opt, const char *str, int unset); #define EVENTS_HELP_MAX (128*1024) +#define PERF_ATTR_IDX(MEMBER) \ + (offsetof(struct perf_event_attr, MEMBER) / sizeof(__u64)) enum { PARSE_EVENTS__TERM_TYPE_NUM, @@ -43,12 +45,8 @@ enum { enum { PARSE_EVENTS__TERM_TYPE_USER, - PARSE_EVENTS__TERM_TYPE_CONFIG, - PARSE_EVENTS__TERM_TYPE_CONFIG1, - PARSE_EVENTS__TERM_TYPE_CONFIG2, + PARSE_EVENTS__TERM_TYPE_ATTR, PARSE_EVENTS__TERM_TYPE_NAME, - PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD, - PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE, }; struct parse_events_term { @@ -59,6 +57,7 @@ struct parse_events_term { } val; int type_val; int type_term; + u64 idx; struct list_head list; }; @@ -74,7 +73,7 @@ struct parse_events_terms { int parse_events__is_hardcoded_term(struct parse_events_term *term); int parse_events_term__num(struct parse_events_term **_term, - int type_term, char *config, u64 num); + int type_term, char *config, u64 num, u64 idx); int parse_events_term__str(struct parse_events_term **_term, int type_term, char *config, char *str); int parse_events_term__sym_hw(struct parse_events_term **term, @@ -97,6 +96,7 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx, int parse_events_add_pmu(struct list_head *list, int *idx, char *pmu , struct list_head *head_config); void parse_events__set_leader(char *name, struct list_head *list); +int parse_events__set_attr(struct perf_event_attr *__attr, u64 idx, u64 val); void parse_events_update_lists(struct list_head *list_event, struct list_head *list_all); void parse_events_error(void *data, void *scanner, char const *msg); diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 435b4e5..a2f2f90 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -59,12 +59,12 @@ static int sym(yyscan_t scanner, int type, int config) return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; } -static int term(yyscan_t scanner, int type) +static int attr(yyscan_t scanner, u64 idx) { YYSTYPE *yylval = parse_events_get_lval(scanner); - yylval->num = type; - return PE_TERM; + yylval->num = idx; + return PE_TERM_ATTR; } %} @@ -162,12 +162,12 @@ refs|Reference|ops|access | misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); } { -config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); } -config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); } -config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); } -name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); } -period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); } -branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); } +config { return attr(yyscanner, PERF_ATTR_IDX(config)); } +config1 { return attr(yyscanner, PERF_ATTR_IDX(config1)); } +config2 { return attr(yyscanner, PERF_ATTR_IDX(config2)); } +period { return attr(yyscanner, PERF_ATTR_IDX(sample_period)); } +branch_type { return attr(yyscanner, PERF_ATTR_IDX(branch_sample_type)); } +name { return PE_TERM_NAME; } , { return ','; } "/" { BEGIN(INITIAL); return '/'; } {name_minus} { return str(yyscanner, PE_NAME); } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 4eb67ec..2bd285e 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -40,7 +40,8 @@ static inc_group_count(struct list_head *list, %} %token PE_START_EVENTS PE_START_TERMS -%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM +%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW +%token PE_TERM_NAME PE_TERM_ATTR %token PE_EVENT_NAME %token PE_NAME %token PE_MODIFIER_EVENT PE_MODIFIER_BP @@ -51,7 +52,7 @@ static inc_group_count(struct list_head *list, %type PE_VALUE_SYM_HW %type PE_VALUE_SYM_SW %type PE_RAW -%type PE_TERM +%type PE_TERM_ATTR %type PE_NAME %type PE_NAME_CACHE_TYPE %type PE_NAME_CACHE_OP_RESULT @@ -375,7 +376,7 @@ PE_NAME '=' PE_VALUE struct parse_events_term *term; ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $3)); + $1, $3, 0)); $$ = term; } | @@ -393,7 +394,7 @@ PE_NAME struct parse_events_term *term; ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, 1)); + $1, 1, 0)); $$ = term; } | @@ -406,27 +407,30 @@ PE_VALUE_SYM_HW $$ = term; } | -PE_TERM '=' PE_NAME +PE_TERM_NAME '=' PE_NAME { struct parse_events_term *term; - ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3)); + ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_NAME, + NULL, $3)); $$ = term; } | -PE_TERM '=' PE_VALUE +PE_TERM_ATTR '=' PE_VALUE { struct parse_events_term *term; - ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3)); + ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_ATTR, + NULL, $3, $1)); $$ = term; } | -PE_TERM +PE_TERM_ATTR { struct parse_events_term *term; - ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1)); + ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_ATTR, + NULL, 1, $1)); $$ = term; }