From patchwork Mon Apr 7 15:04:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 27904 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f197.google.com (mail-ig0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 41B7920490 for ; Mon, 7 Apr 2014 15:06:44 +0000 (UTC) Received: by mail-ig0-f197.google.com with SMTP id hn18sf11568489igb.8 for ; Mon, 07 Apr 2014 08:06:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=mTzL+1oQYTO8ulwgRpRSBv043MvodhG+XtqTncjiHWU=; b=Z6gxDZ9A3yNJ2ZwQTCwGXYpGUXFAPShj/ipZ9VIcNk0BIerkt7MGZWP9gEbiYJO16E 4fPRK7t4eIb3GJTjKfCbe8YoRUTiI7e5Ncc6BdtYWhcjBwp08VldoiN0hzRJrsUqp+Yd cV0G/rp/mhz3eDjtrIoHHgd00K2Zm653YJDm89X+T3wsENRBJAtM1apt0vzBZzJhyp+P SGVr1M1IXX2MyJV1+dkuILHiaPN6C7PizoeLoQU6TP9j6dkGTDcyoiygkZg4CFtchDl5 K8LUQqHByUTOHy+KxuDYhu+585LpyPp9OIqYGsZh40cXPSsLbcv3qaBnMlHWOMRirYIr l+SA== X-Gm-Message-State: ALoCoQnB+FYquhe5G0aZNVOjz+edAwCoBEtQcciQGrhooCmy/m/d9ki40RZSqhATnK18PRc2EGHl X-Received: by 10.42.115.129 with SMTP id k1mr15492239icq.25.1396883203600; Mon, 07 Apr 2014 08:06:43 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.81.201 with SMTP id f67ls108521qgd.91.gmail; Mon, 07 Apr 2014 08:06:43 -0700 (PDT) X-Received: by 10.58.96.36 with SMTP id dp4mr3392072veb.21.1396883203502; Mon, 07 Apr 2014 08:06:43 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id fn10si3164913vdc.171.2014.04.07.08.06.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Apr 2014 08:06:43 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id ik5so5587003vcb.0 for ; Mon, 07 Apr 2014 08:06:43 -0700 (PDT) X-Received: by 10.220.106.7 with SMTP id v7mr20265vco.46.1396883203395; Mon, 07 Apr 2014 08:06:43 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp169727vcv; Mon, 7 Apr 2014 08:06:42 -0700 (PDT) X-Received: by 10.68.110.165 with SMTP id ib5mr31689717pbb.61.1396883202619; Mon, 07 Apr 2014 08:06:42 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gd3si4876848pbb.98.2014.04.07.08.06.41; Mon, 07 Apr 2014 08:06:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755549AbaDGPGb (ORCPT + 27 others); Mon, 7 Apr 2014 11:06:31 -0400 Received: from mail-ee0-f44.google.com ([74.125.83.44]:58803 "EHLO mail-ee0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755333AbaDGPFa (ORCPT ); Mon, 7 Apr 2014 11:05:30 -0400 Received: by mail-ee0-f44.google.com with SMTP id e49so754319eek.3 for ; Mon, 07 Apr 2014 08:05:29 -0700 (PDT) X-Received: by 10.15.51.1 with SMTP id m1mr3490032eew.25.1396883129327; Mon, 07 Apr 2014 08:05:29 -0700 (PDT) Received: from localhost.localdomain (201-179-62-37.mobileinternet.proximus.be. [37.62.179.201]) by mx.google.com with ESMTPSA id o4sm42287649eef.20.2014.04.07.08.05.27 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 07 Apr 2014 08:05:28 -0700 (PDT) From: Jean Pihet To: Borislav Petkov , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa , linux-kernel@vger.kernel.org, Robert Richter Cc: Robert Richter , Jean Pihet Subject: [PATCH 15/16] perf tools: Add attr syntax to event parser Date: Mon, 7 Apr 2014 17:04:37 +0200 Message-Id: <1396883078-25320-16-git-send-email-jean.pihet@linaro.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1396883078-25320-1-git-send-email-jean.pihet@linaro.org> References: <1396883078-25320-1-git-send-email-jean.pihet@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: jean.pihet@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.169 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org 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:24 sets bit 24 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:24 Persistent events are exposed via sysfs and need to set the persistent flag (bit 24 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 Signed-off-by: Jean Pihet --- 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 8ef3f6c..707ce83 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 @@ -127,6 +140,7 @@ modifier_bp [rwx]{1,3} } { +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 00a7dcb..d36d750 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -21,8 +21,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; }; @@ -512,7 +512,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. @@ -529,27 +528,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, @@ -678,7 +658,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; @@ -687,7 +667,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 8b64125..10269f7 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 @@ -36,7 +31,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)); }