From patchwork Thu Aug 22 14:44:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 19422 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f70.google.com (mail-qa0-f70.google.com [209.85.216.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 420D6248E6 for ; Thu, 22 Aug 2013 14:44:37 +0000 (UTC) Received: by mail-qa0-f70.google.com with SMTP id cd7sf578844qab.5 for ; Thu, 22 Aug 2013 07:44:37 -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=/CCLbj1yeKxTXnHU5n96dlFAmLiszsUav59Wl1zOdgY=; b=RQwjYaZsbo2zFpCTYZ3Y6+35pPkOhz8Rl2cSX4d8XEvvjcUxx9gNtvm2y5pCjfsQnG m6ZrdpZGY6GKFWm0X1OGMD2BiZM0ThKA/Tgo1yCEL5t0TPv9keWDQDiTnro6ZA7ZGa04 4vzcZlJLuaYoQSsyTnuc5dPQe5b3Q7Y+HZMhHdasP7KkDoj8KxyaLiQaOpEgd0SsZiOW 2F9d/qiRs+LuwPMvLQiSNZyz90i4KrnAcpCkkhkLbFFMN0PdL3/XmYGnMCPVstV5ST1w LmbNW2zWPkGQFxVS1xe6URchXlWCb8a6t6k2zDRiFcgUMcLQZ0+XD5HnpNLL0mrr85Zl vIRQ== 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=/CCLbj1yeKxTXnHU5n96dlFAmLiszsUav59Wl1zOdgY=; b=IBXZdO51gqOAR6SLvMEMLxuVvJa5h0E9G7SmgJNeqGTzlynzioOhlxI/dGZh4rpaYd 0LWlws/hCcQROrWy1dR0T370mVMuSJ8XyayuW26Ddx77FWAKAsxy9xW94D2DF458BRYi f0RuosDsmL+zAtRPa6n7/kS/ECh7pR4kEXWq/VICfMJDaz9+NSiyAehG61+jhXlU7NLM JXKWTQixvMz9gF2INeVVba8C3xk8xgR2Ss5PKPkD9DJjyBDP7lpWfWnRLwQuKhMQG1IY xAYp8BOmsFI2MkMBSBOgW6BQ90WfEU4veeMi0M07kR89gXxrS06GjJscNVz9oIHoI+WX U55A== X-Received: by 10.224.13.136 with SMTP id c8mr13168714qaa.0.1377182677092; Thu, 22 Aug 2013 07:44:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.49.42 with SMTP id r10ls1179889qen.86.gmail; Thu, 22 Aug 2013 07:44:37 -0700 (PDT) X-Received: by 10.221.27.73 with SMTP id rp9mr896494vcb.29.1377182676984; Thu, 22 Aug 2013 07:44:36 -0700 (PDT) Received: from mail-ve0-x22a.google.com (mail-ve0-x22a.google.com [2607:f8b0:400c:c01::22a]) by mx.google.com with ESMTPS id wh9si647515vcb.93.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Aug 2013 07:44:36 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22a 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:c01::22a; Received: by mail-ve0-f170.google.com with SMTP id 15so1645735vea.1 for ; Thu, 22 Aug 2013 07:44:36 -0700 (PDT) X-Gm-Message-State: ALoCoQkzzetZ3qB7fTaJ+0wUB3KzYXFobIxpwmQneDRwKjaMf14LPI7gdkArY2ChaQxSYS0IX7xD X-Received: by 10.58.197.5 with SMTP id iq5mr736813vec.30.1377182676899; Thu, 22 Aug 2013 07:44:36 -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 u4csp34804vcz; Thu, 22 Aug 2013 07:44:36 -0700 (PDT) X-Received: by 10.204.224.77 with SMTP id in13mr7317193bkb.24.1377182675704; Thu, 22 Aug 2013 07:44:35 -0700 (PDT) Received: from mail-bk0-x232.google.com (mail-bk0-x232.google.com [2a00:1450:4008:c01::232]) by mx.google.com with ESMTPS id qh3si2333113bkb.324.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: pass (google.com: domain of rric.net@gmail.com designates 2a00:1450:4008:c01::232 as permitted sender) client-ip=2a00:1450:4008:c01::232; Received: by mail-bk0-f50.google.com with SMTP id mz11so716310bkb.23 for ; Thu, 22 Aug 2013 07:44:34 -0700 (PDT) X-Received: by 10.204.111.197 with SMTP id t5mr2260683bkp.37.1377182674664; Thu, 22 Aug 2013 07:44:34 -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:34 -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 3/4] perf tools: Add attr syntax to event parser Date: Thu, 22 Aug 2013 16:44:04 +0200 Message-Id: <1377182645-12922-4-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:c01::22a 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 The event parser is limited to update only a subset of all fields in struct perf_event_attr (config*, period, branch_type). We are not able to set other attr fields, esp. flags. Introducing a new syntax to set any field of the event attribute by using an index to the u64 value to be used within struct perf_event_attr. The new syntax attr is similar to config, but specifies the index to be used. E.g. attr5:23 sets bit 23 of the flag field of attr. The persistent event implementation is a use case of the above. In this case sysfs provides: /sys/bus/event_source/devices/persistent/events/mce_record:persistent,config=106 /sys/bus/event_source/devices/persistent/format/persistent:attr5:23 Persistent events are exposed via sysfs and need to set the persistent flag (bit 23 of the flag field). With the sysfs entry above we are able to define the persistent flag format and then may setup a mce_record event with that flag set. In general we are now flexible to describe with sysfs any event to be setup by perf tools. Signed-off-by: Robert Richter Signed-off-by: Robert Richter --- tools/perf/util/parse-events.l | 14 ++++++++++++++ tools/perf/util/pmu.c | 32 ++++++-------------------------- tools/perf/util/pmu.h | 9 ++------- tools/perf/util/pmu.l | 1 + tools/perf/util/pmu.y | 18 ++++++++++++++---- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index a2f2f90..5bc876c 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -67,6 +67,19 @@ static int attr(yyscan_t scanner, u64 idx) return PE_TERM_ATTR; } +static int attr_parse(yyscan_t scanner) +{ + YYSTYPE *yylval = parse_events_get_lval(scanner); + char *text = parse_events_get_text(scanner); + + errno = 0; + yylval->num = strtoull(text + 4, NULL, 10); + if (errno) + return PE_ERROR; + + return PE_TERM_ATTR; +} + %} %x cond_mem @@ -162,6 +175,7 @@ refs|Reference|ops|access | misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); } { +attr[0-9]* { return attr_parse(yyscanner); } config { return attr(yyscanner, PERF_ATTR_IDX(config)); } config1 { return attr(yyscanner, PERF_ATTR_IDX(config1)); } config2 { return attr(yyscanner, PERF_ATTR_IDX(config2)); } diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index bc9d806..2e28787 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -17,8 +17,8 @@ struct perf_pmu_alias { }; struct perf_pmu_format { - char *name; - int value; + char *name; + u64 idx; DECLARE_BITMAP(bits, PERF_PMU_FORMAT_BITS); struct list_head list; }; @@ -418,7 +418,6 @@ static int pmu_config_term(struct list_head *formats, struct parse_events_term *term) { struct perf_pmu_format *format; - __u64 *vp; /* * Support only for hardcoded and numnerial terms. @@ -435,27 +434,8 @@ static int pmu_config_term(struct list_head *formats, if (!format) return -EINVAL; - switch (format->value) { - case PERF_PMU_FORMAT_VALUE_CONFIG: - vp = &attr->config; - break; - case PERF_PMU_FORMAT_VALUE_CONFIG1: - vp = &attr->config1; - break; - case PERF_PMU_FORMAT_VALUE_CONFIG2: - vp = &attr->config2; - break; - default: - return -EINVAL; - } - - /* - * XXX If we ever decide to go with string values for - * non-hardcoded terms, here's the place to translate - * them into value. - */ - *vp |= pmu_format_value(format->bits, term->val.num); - return 0; + return parse_events__set_attr(attr, format->idx, + pmu_format_value(format->bits, term->val.num)); } int perf_pmu__config_terms(struct list_head *formats, @@ -537,7 +517,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms) } int perf_pmu__new_format(struct list_head *list, char *name, - int config, unsigned long *bits) + __u64 idx, unsigned long *bits) { struct perf_pmu_format *format; @@ -546,7 +526,7 @@ int perf_pmu__new_format(struct list_head *list, char *name, return -ENOMEM; format->name = strdup(name); - format->value = config; + format->idx = idx; memcpy(format->bits, bits, sizeof(format->bits)); list_add_tail(&format->list, list); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 6b2cbe2..b66859d 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -4,12 +4,7 @@ #include #include #include - -enum { - PERF_PMU_FORMAT_VALUE_CONFIG, - PERF_PMU_FORMAT_VALUE_CONFIG1, - PERF_PMU_FORMAT_VALUE_CONFIG2, -}; +#include "parse-events.h" #define PERF_PMU_FORMAT_BITS 64 @@ -35,7 +30,7 @@ int perf_pmu_wrap(void); void perf_pmu_error(struct list_head *list, char *name, char const *msg); int perf_pmu__new_format(struct list_head *list, char *name, - int config, unsigned long *bits); + __u64 idx, unsigned long *bits); void perf_pmu__set_format(unsigned long *bits, long from, long to); int perf_pmu__format_parse(char *dir, struct list_head *head); diff --git a/tools/perf/util/pmu.l b/tools/perf/util/pmu.l index a15d9fb..9d5aa62 100644 --- a/tools/perf/util/pmu.l +++ b/tools/perf/util/pmu.l @@ -26,6 +26,7 @@ num_dec [0-9]+ %% {num_dec} { return value(10); } +attr { return PP_ATTR; } config { return PP_CONFIG; } config1 { return PP_CONFIG1; } config2 { return PP_CONFIG2; } diff --git a/tools/perf/util/pmu.y b/tools/perf/util/pmu.y index bfd7e85..fb86df8 100644 --- a/tools/perf/util/pmu.y +++ b/tools/perf/util/pmu.y @@ -20,7 +20,7 @@ do { \ %} -%token PP_CONFIG PP_CONFIG1 PP_CONFIG2 +%token PP_ATTR PP_CONFIG PP_CONFIG1 PP_CONFIG2 %token PP_VALUE PP_ERROR %type PP_VALUE %type bit_term @@ -40,24 +40,34 @@ format format_term format_term format_term: +PP_ATTR ':' bits +{ + ABORT_ON(perf_pmu__new_format(format, name, 0, $3)); +} +| +PP_ATTR PP_VALUE ':' bits +{ + ABORT_ON(perf_pmu__new_format(format, name, $2, $4)); +} +| PP_CONFIG ':' bits { ABORT_ON(perf_pmu__new_format(format, name, - PERF_PMU_FORMAT_VALUE_CONFIG, + PERF_ATTR_IDX(config), $3)); } | PP_CONFIG1 ':' bits { ABORT_ON(perf_pmu__new_format(format, name, - PERF_PMU_FORMAT_VALUE_CONFIG1, + PERF_ATTR_IDX(config1), $3)); } | PP_CONFIG2 ':' bits { ABORT_ON(perf_pmu__new_format(format, name, - PERF_PMU_FORMAT_VALUE_CONFIG2, + PERF_ATTR_IDX(config2), $3)); }