From patchwork Fri May 13 07:56:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 67730 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp135574qge; Fri, 13 May 2016 00:57:19 -0700 (PDT) X-Received: by 10.98.51.132 with SMTP id z126mr20536276pfz.23.1463126232261; Fri, 13 May 2016 00:57:12 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q66si23008572pfb.190.2016.05.13.00.57.12; Fri, 13 May 2016 00:57:12 -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 S1752741AbcEMH5C (ORCPT + 29 others); Fri, 13 May 2016 03:57:02 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:62018 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752473AbcEMH4v (ORCPT ); Fri, 13 May 2016 03:56:51 -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 DKL57618; Fri, 13 May 2016 15:56:42 +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:30 +0800 From: Wang Nan To: CC: , , Wang Nan , He Kuang , "Arnaldo Carvalho de Melo" , Jiri Olsa , Masami Hiramatsu , Namhyung Kim , "Zefan Li" , Subject: [PATCH 13/17] perf tools: Add API to pause a channel Date: Fri, 13 May 2016 07:56:10 +0000 Message-ID: <1463126174-119290-14-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.573588BB.00E1, 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: 54318baa032779a8ba408d1710390f29 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org perf_evlist__channel_toggle_paused() is introduced to pause/resume a channel in an evlist. Utilize PERF_EVENT_IOC_PAUSE_OUTPUT ioctl. Following commits use perf_evlist__channel_toggle_paused() to ensure overwrite ring buffer is turned off before reading. 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/util/evlist.c | 28 ++++++++++++++++++++++++++++ tools/perf/util/evlist.h | 2 ++ 2 files changed, 30 insertions(+) -- 1.8.3.4 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 4295d7e..cfcd39a 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -706,6 +706,34 @@ int perf_evlist__channel_idx(struct perf_evlist *evlist, return 0; } +int perf_evlist__channel_toggle_paused(struct perf_evlist *evlist, + int channel, bool pause) +{ + int i; + + if (channel >= perf_evlist__channel_nr(evlist)) + return -E2BIG; + if (!evlist->mmap) + return -EFAULT; + for (i = 0; i < evlist->nr_mmaps; i++) { + int n = channel * evlist->nr_mmaps + i; + int fd = evlist->mmap[n].fd; + int err; + + if (fd < 0) + continue; + err = ioctl(fd, PERF_EVENT_IOC_PAUSE_OUTPUT, + pause ? 1 : 0); + if (err) { + err = (errno == 0 ? -EINVAL : -errno); + pr_err("Unable to pause output on %d: %s\n", + fd, strerror(-err)); + return err; + } + } + return 0; +} + /* When check_messup is true, 'end' must points to a good entry */ static union perf_event * perf_mmap__read(struct perf_mmap *md, bool check_messup, u64 start, diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index ee17449..2bb42fd 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -195,6 +195,8 @@ perf_evlist__get_mmap(struct perf_evlist *evlist, return &evlist->mmap[idx]; } +int perf_evlist__channel_toggle_paused(struct perf_evlist *evlist, + int channel, bool pause); int perf_evlist__open(struct perf_evlist *evlist); void perf_evlist__close(struct perf_evlist *evlist);