From patchwork Fri May 13 07:56:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 67735 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp136045qge; Fri, 13 May 2016 00:58:48 -0700 (PDT) X-Received: by 10.66.141.139 with SMTP id ro11mr1556426pab.74.1463126328399; Fri, 13 May 2016 00:58:48 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k70si23069791pfk.75.2016.05.13.00.58.48; Fri, 13 May 2016 00:58:48 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752585AbcEMH4x (ORCPT + 29 others); Fri, 13 May 2016 03:56:53 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:61976 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752450AbcEMH4t (ORCPT ); Fri, 13 May 2016 03:56:49 -0400 Received: from 172.24.1.137 (EHLO szxeml433-hub.china.huawei.com) ([172.24.1.137]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DKL57605; Fri, 13 May 2016 15:56:38 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml433-hub.china.huawei.com (10.82.67.210) with Microsoft SMTP Server id 14.3.235.1; Fri, 13 May 2016 15:56:28 +0800 From: Wang Nan To: CC: , , Wang Nan , He Kuang , "Arnaldo Carvalho de Melo" , Jiri Olsa , Masami Hiramatsu , Namhyung Kim , "Zefan Li" , Subject: [PATCH 11/17] perf tools: Set write_backward attribut bit for overwrite events Date: Fri, 13 May 2016 07:56:08 +0000 Message-ID: <1463126174-119290-12-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1463126174-119290-1-git-send-email-wangnan0@huawei.com> References: <1463126174-119290-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.573588B7.0013, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 901850e0a00c47b35fc3db778e1144b5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org write_backward attribute makes kernel filling ring buffer from the end of it, makes reading from overwrite ring buffer possible. This patch selects this attribute if evsel->overwrite is selected explicitly by user. Overwrite and write_backward are still controled separatly for legacy readonly mmap users (most of them are in perf/tests). Signed-off-by: Wang Nan Signed-off-by: He Kuang Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Zefan Li Cc: pi3orama@163.com --- tools/perf/builtin-record.c | 7 +++++++ tools/perf/util/evlist.c | 2 ++ tools/perf/util/evlist.h | 1 + tools/perf/util/evsel.c | 13 +++++++++++++ 4 files changed, 23 insertions(+) -- 1.8.3.4 diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 939aa68..49c41c3 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -300,6 +300,13 @@ static int record__open(struct record *rec) perf_evlist__config(evlist, opts, &callchain_param); evlist__for_each(evlist, pos) { + if (pos->overwrite) { + if (!pos->attr.write_backward) { + ui__warning("Unable to read from overwrite ring buffer\n\n"); + rc = -ENOSYS; + goto out; + } + } try_again: if (perf_evsel__open(pos, pos->cpus, pos->threads) < 0) { if (perf_evsel__fallback(pos, errno, msg, sizeof(msg))) { diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index f0b0457..dc2e509 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1043,6 +1043,8 @@ perf_evlist__channel_for_evsel(struct perf_evsel *evsel __maybe_unused) if (evsel->overwrite) flag |= PERF_EVLIST__CHANNEL_RDONLY; + if (evsel->attr.write_backward) + flag |= PERF_EVLIST__CHANNEL_BACKWARD; return flag; } diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index c53bdbd..bdd8e98 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -24,6 +24,7 @@ struct record_opts; enum perf_evlist_mmap_flag { PERF_EVLIST__CHANNEL_ENABLED = 1, PERF_EVLIST__CHANNEL_RDONLY = 2, + PERF_EVLIST__CHANNEL_BACKWARD = 4, }; /** diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index be4fc25..f1b060b 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -678,6 +678,19 @@ static void apply_config_terms(struct perf_evsel *evsel, } } + /* + * Set backward after config term processing because it is + * possible to set overwrite globally, without config + * terms. + */ + if (evsel->overwrite) { + if (opts->has_write_backward) + attr->write_backward = 1; + else + pr_err("Reading from overwrite event %s is not supported\n", + evsel->name); + } + /* User explicitly set per-event callgraph, clear the old setting and reset. */ if ((callgraph_buf != NULL) || (dump_size > 0)) {