From patchwork Fri Oct 23 09:23:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 55473 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lf0-f72.google.com (mail-lf0-f72.google.com [209.85.215.72]) by patches.linaro.org (Postfix) with ESMTPS id 86A7320581 for ; Fri, 23 Oct 2015 09:31:17 +0000 (UTC) Received: by lfaz124 with SMTP id z124sf45717496lfa.0 for ; Fri, 23 Oct 2015 02:31:16 -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 :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=3f6aqgTNcffDXt+Ps8/iJiGUG6JDXH/hs0pT1NU3E9c=; b=AiTO9h1Qg7+zZrE63/FL5RurGCHu/D8O7nSXo6zXLgD9wBotFNRO/hyp6+eO+KdaL9 /+1NKvA/N6R3KhluReKKR7YsmpERnY2kwrAZAq/1nEhsMomnl5uYgTVnPYRFcINwAibJ 5gLjaFUqQVjV3TXGuDtdEz/dLahzyzVKjzV44G3drpJP7d/ZsgEdySiHuz0ehuw06iu/ 0Yfe2t3KA3yyixZR4TpkYsGMBHu2Rm5pm4JqfF1xTfHHl3whKmJjxiw4HSCqW0xvuHRo R6qjpNxvzkacuAjRrRAoUeTh28MOlruXMTP5091EBgY9ZViBKCJw8Iv19BL5nrX6m5QM CNIA== X-Gm-Message-State: ALoCoQlVrId1fenan+996SpY9K0DaeWn44xaUXZXAo+qY9RdrxT42/WcN4nfUZzX1ziG3F8X999Q X-Received: by 10.180.82.101 with SMTP id h5mr625139wiy.5.1445592676506; Fri, 23 Oct 2015 02:31:16 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.143.76 with SMTP id r73ls427966lfd.6.gmail; Fri, 23 Oct 2015 02:31:16 -0700 (PDT) X-Received: by 10.112.199.137 with SMTP id jk9mr10723175lbc.86.1445592676312; Fri, 23 Oct 2015 02:31:16 -0700 (PDT) Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id qp8si12158687lbb.66.2015.10.23.02.31.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Oct 2015 02:31:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by lfaz124 with SMTP id z124so76980193lfa.1 for ; Fri, 23 Oct 2015 02:31:16 -0700 (PDT) X-Received: by 10.112.17.34 with SMTP id l2mr10850954lbd.117.1445592676174; Fri, 23 Oct 2015 02:31:16 -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 w3csp1099894lbq; Fri, 23 Oct 2015 02:31:15 -0700 (PDT) X-Received: by 10.107.19.219 with SMTP id 88mr23785761iot.41.1445592675197; Fri, 23 Oct 2015 02:31:15 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h10si2440355igh.20.2015.10.23.02.31.14; Fri, 23 Oct 2015 02:31:15 -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 S1752672AbbJWJbL (ORCPT + 28 others); Fri, 23 Oct 2015 05:31:11 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:37067 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752449AbbJWJbI (ORCPT ); Fri, 23 Oct 2015 05:31:08 -0400 Received: from 172.24.1.48 (EHLO szxeml426-hub.china.huawei.com) ([172.24.1.48]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CUY33895; Fri, 23 Oct 2015 17:24:28 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml426-hub.china.huawei.com (10.82.67.181) with Microsoft SMTP Server id 14.3.235.1; Fri, 23 Oct 2015 17:23:29 +0800 From: Wang Nan To: CC: , Wang Nan , "Arnaldo Carvalho de Melo" , Alexei Starovoitov , Peter Zijlstra , Li Zefan , Subject: [PATCH] perf tools: Enable pre-event inherit setting by config terms Date: Fri, 23 Oct 2015 09:23:22 +0000 Message-ID: <1445592202-132130-1-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 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.215.44 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 allows perf record setting event's attr.inherit bit by config terms like: # perf record -e cycles/no-inherit/ ... So user can control inherit bit for each event separately. In following example, a.out fork()s in main then do some complex CPU intensive computations in both of its children. Basic result with and without inherit: # perf record -e cycles -e instructions ./a.out [ perf record: Woken up 9 times to write data ] [ perf record: Captured and wrote 2.205 MB perf.data (47920 samples) ] # perf report --stdio # ... # Samples: 23K of event 'cycles' # Event count (approx.): 23641752891 ... # Samples: 24K of event 'instructions' # Event count (approx.): 30428312415 # perf record -i -e cycles -e instructions ./a.out [ perf record: Woken up 5 times to write data ] [ perf record: Captured and wrote 1.111 MB perf.data (24019 samples) ] ... # Samples: 12K of event 'cycles' # Event count (approx.): 11699501775 ... # Samples: 12K of event 'instructions' # Event count (approx.): 15058023559 Cancel inherit for one event when globally enable: # perf record -e cycles/no-inherit/ -e instructions ./a.out [ perf record: Woken up 7 times to write data ] [ perf record: Captured and wrote 1.660 MB perf.data (36004 samples) ] ... # Samples: 12K of event 'cycles/no-inherit/' # Event count (approx.): 11895759282 ... # Samples: 24K of event 'instructions' # Event count (approx.): 30668000441 Enable inherit for one event when globally disable: # perf record -i -e cycles/no-inherit=0/ -e instructions ./a.out [ perf record: Woken up 7 times to write data ] [ perf record: Captured and wrote 1.654 MB perf.data (35868 samples) ] ... # Samples: 23K of event 'cycles/no-inherit=0/' # Event count (approx.): 23285400229 ... # Samples: 11K of event 'instructions' # Event count (approx.): 14969050259 Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Peter Zijlstra Cc: Li Zefan Cc: pi3orama@163.com Link: http://lkml.kernel.org/n/ebpf-2rrcnl73ih4o1qiu6t7bdxls@git.kernel.org --- In [1], Alexei enforces BPF fd array that only no-inherit event can be used. Unfortunately, inherit is the default setting for perf and can only be turned off globally. We need this patch to support BPF PMU reading feature support for perf so we can insert a no-inherit perf event into fd array while other perf events still inherit. [1] http://lkml.kernel.org/r/1445559014-4667-1-git-send-email-ast@kernel.org --- tools/perf/util/evsel.c | 9 +++++++++ tools/perf/util/evsel.h | 2 ++ tools/perf/util/parse-events.c | 7 +++++++ tools/perf/util/parse-events.h | 1 + tools/perf/util/parse-events.l | 1 + 5 files changed, 20 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ab05fa5..5566b16 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -652,6 +652,15 @@ static void apply_config_terms(struct perf_evsel *evsel, case PERF_EVSEL__CONFIG_TERM_STACK_USER: dump_size = term->val.stack_user; break; + case PERF_EVSEL__CONFIG_TERM_NOINHERIT: + /* + * attr->inherit should has already been set by + * perf_evsel__config. If user explicitly set + * inherit using config terms, override global + * opt->no_inherit setting. + */ + attr->inherit = !term->val.no_inherit; + break; default: break; } diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 02a5fed..28dbac1 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -43,6 +43,7 @@ enum { PERF_EVSEL__CONFIG_TERM_TIME, PERF_EVSEL__CONFIG_TERM_CALLGRAPH, PERF_EVSEL__CONFIG_TERM_STACK_USER, + PERF_EVSEL__CONFIG_TERM_NOINHERIT, PERF_EVSEL__CONFIG_TERM_MAX, }; @@ -55,6 +56,7 @@ struct perf_evsel_config_term { bool time; char *callgraph; u64 stack_user; + u64 no_inherit; } val; }; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 06ff8d6..478aecc 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -740,6 +740,9 @@ do { \ case PARSE_EVENTS__TERM_TYPE_STACKSIZE: CHECK_TYPE_VAL(NUM); break; + case PARSE_EVENTS__TERM_TYPE_NOINHERIT: + CHECK_TYPE_VAL(NUM); + break; case PARSE_EVENTS__TERM_TYPE_NAME: CHECK_TYPE_VAL(STR); break; @@ -775,6 +778,7 @@ static int config_term_tracepoint(struct perf_event_attr *attr, switch (term->type_term) { case PARSE_EVENTS__TERM_TYPE_CALLGRAPH: case PARSE_EVENTS__TERM_TYPE_STACKSIZE: + case PARSE_EVENTS__TERM_TYPE_NOINHERIT: return config_term_common(attr, term, err); default: if (err) { @@ -838,6 +842,9 @@ do { \ case PARSE_EVENTS__TERM_TYPE_STACKSIZE: ADD_CONFIG_TERM(STACK_USER, stack_user, term->val.num); break; + case PARSE_EVENTS__TERM_TYPE_NOINHERIT: + ADD_CONFIG_TERM(NOINHERIT, no_inherit, term->val.num); + break; default: break; } diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index fbb16c7..70cf07f 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -67,6 +67,7 @@ enum { PARSE_EVENTS__TERM_TYPE_TIME, PARSE_EVENTS__TERM_TYPE_CALLGRAPH, PARSE_EVENTS__TERM_TYPE_STACKSIZE, + PARSE_EVENTS__TERM_TYPE_NOINHERIT }; struct parse_events_term { diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 5e5d31a..64d3ba8 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -189,6 +189,7 @@ branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE time { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_TIME); } call-graph { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CALLGRAPH); } stack-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); } +no-inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); } , { return ','; } "/" { BEGIN(INITIAL); return '/'; } {name_minus} { return str(yyscanner, PE_NAME); }