From patchwork Sat Oct 17 10:48:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 55154 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id A5984230A1 for ; Sat, 17 Oct 2015 10:49:55 +0000 (UTC) Received: by wikv3 with SMTP id v3sf3837497wik.1 for ; Sat, 17 Oct 2015 03:49:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=46i2iizSR7S7aCNeZFSYGN1RDtuACptYfk1NI50urkc=; b=cL/oq1YWvOdZP5eY2o8BS3RpQEbWzXXtvviYBEpRR2JI2bK8dGPaQK/8clxLFSsGSu PMIEsnyCI2jcY1lCNNXb1BiaK7+ZwopuUoL1RUSuRPquu1UttpxFhV9viP+ZGp02XcxQ Qfo3K6IzCHpzHhSADyEgrWj5IkvMtgtNCboXbUXWrbpZz8eb2RNIxVlomouqNx3gf/4p E+MhhqtyyP9fqN8b8ZzkVhWRACmFgwJLc/jt6SQi0iKkR0ejHT2a1R+rlptB941/eAaU 3+dToM2EtMIQsEWkcs29Y8n3u2dtlciXDPl8TQ5nSzdzLK3ZxIqfwzgkqWzIkMbNwq5B VVOg== X-Gm-Message-State: ALoCoQnDwT11AOE+TBGx7/tEYVl3EK+9PIrnu+IX4XBJl+E+uXW4WyoP26LTYizbaCca2GzLgXc2 X-Received: by 10.112.181.10 with SMTP id ds10mr4796788lbc.3.1445078994995; Sat, 17 Oct 2015 03:49:54 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.205.7 with SMTP id d7ls444335lfg.82.gmail; Sat, 17 Oct 2015 03:49:54 -0700 (PDT) X-Received: by 10.25.167.195 with SMTP id q186mr6776154lfe.24.1445078994751; Sat, 17 Oct 2015 03:49:54 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id y15si15806902lfd.55.2015.10.17.03.49.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Oct 2015 03:49:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbbes7 with SMTP id es7so25527237lbb.2 for ; Sat, 17 Oct 2015 03:49:54 -0700 (PDT) X-Received: by 10.112.159.136 with SMTP id xc8mr8436156lbb.76.1445078994403; Sat, 17 Oct 2015 03:49:54 -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.112.59.35 with SMTP id w3csp436296lbq; Sat, 17 Oct 2015 03:49:53 -0700 (PDT) X-Received: by 10.66.222.70 with SMTP id qk6mr22577479pac.68.1445078993294; Sat, 17 Oct 2015 03:49:53 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ej15si36096786pac.96.2015.10.17.03.49.52; Sat, 17 Oct 2015 03:49:53 -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 S1752550AbbJQKtW (ORCPT + 30 others); Sat, 17 Oct 2015 06:49:22 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:7832 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751365AbbJQKtS (ORCPT ); Sat, 17 Oct 2015 06:49:18 -0400 Received: from 172.24.1.50 (EHLO szxeml428-hub.china.huawei.com) ([172.24.1.50]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CWX99314; Sat, 17 Oct 2015 18:48:56 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.235.1; Sat, 17 Oct 2015 18:48:46 +0800 From: Wang Nan To: , , CC: , , , , , , , , , , , , Wang Nan , Arnaldo Carvalho de Melo Subject: [RFC PATCH 6/7] perf tools: Enable indics setting syntax for BPF maps Date: Sat, 17 Oct 2015 10:48:29 +0000 Message-ID: <1445078910-73699-7-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1445078910-73699-1-git-send-email-wangnan0@huawei.com> References: <1445078910-73699-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected 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: wangnan0@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) smtp.mailfrom=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: , This patch introduce a new syntax to perf event parser: # perf record -e bpf_file.c/maps.mymap.value[0,3-5,7]=1234/ ... By utilizing the basic facilities in bpf-loader.c which allow setting different slots in a BPF map separately, the newly introduced syntax allows perf to control specific elements in a BPF map. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com --- tools/perf/util/parse-events.c | 4 +- tools/perf/util/parse-events.l | 11 +++++ tools/perf/util/parse-events.y | 92 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 42ac1cb..a2af5a8 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -654,7 +654,9 @@ parse_events_config_bpf(struct parse_events_evlist *data, err, errbuf, sizeof(errbuf)); data->error->help = strdup( "Hint:\tValid config term:\n" -" \tmaps..value\n" +" \tmaps..value\n" +"\n" +" \twhere is something like [0,3-4]\n" " \t(add -v to see detail)"); data->error->str = strdup(errbuf); if (err == -EINVAL) diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index eeea4e1..0d92a4d 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -111,6 +111,7 @@ do { \ %x mem %s config %x event +%x array group [^,{}/]*[{][^}]*[}][^,{}/]* event_pmu [^,{}/]+[/][^/]*[/][^,{}/]* @@ -176,6 +177,14 @@ modifier_bp [rwx]{1,3} } +{ +"]" { BEGIN(config); return ']'; } +{num_dec} { return value(yyscanner, 10); } +{num_hex} { return value(yyscanner, 16); } +, { return ','; } +- { return '-'; } +} + { /* * Please update parse_events_formats_error_string any time @@ -194,6 +203,8 @@ stack-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); } , { return ','; } "/" { BEGIN(INITIAL); return '/'; } {name_minus} { return str(yyscanner, PE_NAME); } +\[all\] { return PE_ARRAY_ALL; } +"[" { BEGIN(array); return '['; } } { diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 255387a..81fe702 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -48,6 +48,7 @@ static inc_group_count(struct list_head *list, %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP %token PE_ERROR %token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT +%token PE_ARRAY_ALL %type PE_VALUE %type PE_VALUE_SYM_HW %type PE_VALUE_SYM_SW @@ -84,6 +85,9 @@ static inc_group_count(struct list_head *list, %type group_def %type group %type groups +%type array +%type array_term +%type array_terms %union { @@ -95,6 +99,10 @@ static inc_group_count(struct list_head *list, char *sys; char *event; } tracepoint_name; + struct array { + size_t nr_indics; + u64 *indics; + } array; } %% @@ -599,6 +607,90 @@ PE_TERM ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL)); $$ = term; } +| +PE_NAME array '=' PE_NAME +{ + struct parse_events_term *term; + int i; + + ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, + $1, $4, &@1, &@4)); + + term->nr_indics = $2.nr_indics; + term->indics = $2.indics; + $$ = term; +} +| +PE_NAME array '=' PE_VALUE +{ + struct parse_events_term *term; + + ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, + $1, $4, &@1, &@4)); + term->nr_indics = $2.nr_indics; + term->indics = $2.indics; + $$ = term; +} + +array: +'[' array_terms ']' +{ + $$ = $2; +} +| +PE_ARRAY_ALL +{ + $$.nr_indics = 0; + $$.indics = NULL; +} + +array_terms: +array_terms ',' array_term +{ + struct array array = $1; + struct array new_array = $3; + u64 *new_indics; + + new_indics = realloc(array.indics, + (array.nr_indics + new_array.nr_indics) * sizeof(u64)); + ABORT_ON(!new_indics); + + memcpy(&new_indics[array.nr_indics], new_array.indics, + sizeof(u64) * new_array.nr_indics); + + array.nr_indics += new_array.nr_indics; + array.indics = new_indics; + free(new_array.indics); + $$ = array; +} +| +array_term + +array_term: +PE_VALUE +{ + struct array array; + array.nr_indics = 1; + array.indics = malloc(sizeof(u64)); + ABORT_ON(!array.indics); + array.indics[0] = $1; + $$ = array; +} +| +PE_VALUE '-' PE_VALUE +{ + struct array array; + int i; + + ABORT_ON($3 < $1); + array.nr_indics = $3 - $1 + 1; + array.indics = malloc(sizeof(u64) * array.nr_indics); + ABORT_ON(!array.indics); + + for (i = 0; i < array.nr_indics; i++) + array.indics[i] = $1 + i; + $$ = array; +} sep_dc: ':' |