From patchwork Wed May 25 13:44:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 68606 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1230382qge; Wed, 25 May 2016 06:59:01 -0700 (PDT) X-Received: by 10.66.100.197 with SMTP id fa5mr5945610pab.25.1464184741307; Wed, 25 May 2016 06:59:01 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hu12si12819997pac.157.2016.05.25.06.59.01; Wed, 25 May 2016 06:59:01 -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 S1753001AbcEYN66 (ORCPT + 30 others); Wed, 25 May 2016 09:58:58 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:38867 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751043AbcEYN65 (ORCPT ); Wed, 25 May 2016 09:58:57 -0400 Received: from 172.24.1.47 (EHLO szxeml433-hub.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DHS83513; Wed, 25 May 2016 21:45:19 +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; Wed, 25 May 2016 21:45:09 +0800 From: Wang Nan To: CC: , , Wang Nan , He Kuang , "Arnaldo Carvalho de Melo" , Jiri Olsa , Masami Hiramatsu , Namhyung Kim , "Zefan Li" Subject: [PATCH v6 10/10] perf record: Unmap overwrite evlist when event terminate Date: Wed, 25 May 2016 13:44:58 +0000 Message-ID: <1464183898-174512-11-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1464183898-174512-1-git-send-email-wangnan0@huawei.com> References: <1464183898-174512-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.0A020201.5745AC6F.03B9, 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: 62c0d92ff00fd8a9e7db22e4060bc662 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When see POLLERR or POLLHUP, unmap ring buffer from both the main evlist and overwrite evlist. Signed-off-by: Wang Nan Cc: 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 | 30 +++++++++++++++++++++--------- tools/perf/util/evlist.c | 3 +-- tools/perf/util/evlist.h | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) -- 1.8.3.4 diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index b9094f0..ca6376c 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -914,6 +914,26 @@ out: return err; } +static void record__munmap_filtered(struct fdarray *fda, int fd, void *arg) +{ + struct record *rec = (struct record *)arg; + + perf_evlist__mmap_put(rec->evlist, fda->priv[fd].idx); + if (rec->overwrite_evlist) + perf_evlist__mmap_put(rec->overwrite_evlist, fda->priv[fd].idx); +} + +static int record__filter_pollfd(struct record *rec) +{ + /* + * Although we may have auxiliray evlist, there is + * only one pollfd, so we don't need to filter pollfd + * for auxiliray evlist. + */ + return fdarray__filter(&rec->evlist->pollfd, POLLERR | POLLHUP, + record__munmap_filtered, rec); +} + static int __cmd_record(struct record *rec, int argc, const char **argv) { int err; @@ -1150,15 +1170,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) err = 0; waking++; - /* - * Although we may have auxiliray evlist, there is - * only one pollfd, so we don't need to filter pollfd - * for auxiliray evlist. - * - * TODO: if an event is terminated (POLLERR | POLLHUP), - * unmap mmaps for auxiliray evlist too. - */ - if (perf_evlist__filter_pollfd(rec->evlist, POLLERR | POLLHUP) == 0) + if (record__filter_pollfd(rec) == 0) draining = true; } diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 866b596..7d00d19 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -27,7 +27,6 @@ #include #include -static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx); static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx); #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) @@ -863,7 +862,7 @@ static void perf_evlist__mmap_get(struct perf_evlist *evlist, int idx) atomic_inc(&evlist->mmap[idx].refcnt); } -static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx) +void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx) { struct perf_mmap *mmap = &evlist->mmap[idx]; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 41e65ac..ba5e006 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -141,7 +141,7 @@ union perf_event *perf_evlist__mmap_read_backward(struct perf_evlist *evlist, void perf_evlist__mmap_read_catchup(struct perf_evlist *evlist, int idx); void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx); - +void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx); int perf_evlist__pause(struct perf_evlist *evlist); int perf_evlist__resume(struct perf_evlist *evlist); int perf_evlist__open(struct perf_evlist *evlist);