From patchwork Tue Jul 12 10:00:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 71806 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp384376qga; Tue, 12 Jul 2016 03:01:58 -0700 (PDT) X-Received: by 10.98.32.148 with SMTP id m20mr42783659pfj.77.1468317718843; Tue, 12 Jul 2016 03:01:58 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d139si3806104pfd.10.2016.07.12.03.01.58; Tue, 12 Jul 2016 03:01:58 -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 S1753563AbcGLKBt (ORCPT + 30 others); Tue, 12 Jul 2016 06:01:49 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:63932 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932514AbcGLKA7 (ORCPT ); Tue, 12 Jul 2016 06:00:59 -0400 Received: from 172.24.1.47 (EHLO szxeml425-hub.china.huawei.com) ([172.24.1.47]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CEQ51174; Tue, 12 Jul 2016 18:00:33 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml425-hub.china.huawei.com (10.82.67.180) with Microsoft SMTP Server id 14.3.235.1; Tue, 12 Jul 2016 18:00:20 +0800 From: Wang Nan To: , CC: , , , Wang Nan , Arnaldo Carvalho de Melo , He Kuang , Jiri Olsa , Masami Hiramatsu , Namhyung Kim , Nilay Vaish Subject: [PATCH v15 05/12] perf tools: Extract common code in mmap failure processing Date: Tue, 12 Jul 2016 10:00:05 +0000 Message-ID: <1468317612-11598-6-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1468317612-11598-1-git-send-email-wangnan0@huawei.com> References: <1468317612-11598-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.5784BFC2.009A, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 8e5e9996aec5825b1b28dd220a68cd48 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In perf_evlist__mmap_per_cpu() and perf_evlist__mmap_per_thread(), when mmap failure, successfully created maps should be cleared. Current code uses two loops __perf_evlist__munmap() for each function. This patch extracts common code to perf_evlist__munmap_nofree() and use previous introduced decoupled API perf_mmap__munmap(). Now __perf_evlist__munmap() can be removed because of no user. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: He Kuang Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Zefan Li Cc: Nilay Vaish Cc: pi3orama@163.com --- tools/perf/util/evlist.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) -- 1.8.3.4 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 6db4b7b..bbad72f 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -28,7 +28,6 @@ #include static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx); -static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx); static void perf_mmap__munmap(struct perf_mmap *map); static void perf_mmap__put(struct perf_mmap *map); @@ -959,12 +958,7 @@ static void perf_mmap__munmap(struct perf_mmap *map) auxtrace_mmap__munmap(&map->auxtrace_mmap); } -static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx) -{ - perf_mmap__munmap(&evlist->mmap[idx]); -} - -void perf_evlist__munmap(struct perf_evlist *evlist) +static void perf_evlist__munmap_nofree(struct perf_evlist *evlist) { int i; @@ -972,8 +966,12 @@ void perf_evlist__munmap(struct perf_evlist *evlist) return; for (i = 0; i < evlist->nr_mmaps; i++) - __perf_evlist__munmap(evlist, i); + perf_mmap__munmap(&evlist->mmap[i]); +} +void perf_evlist__munmap(struct perf_evlist *evlist) +{ + perf_evlist__munmap_nofree(evlist); zfree(&evlist->mmap); } @@ -1131,8 +1129,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, return 0; out_unmap: - for (cpu = 0; cpu < nr_cpus; cpu++) - __perf_evlist__munmap(evlist, cpu); + perf_evlist__munmap_nofree(evlist); return -1; } @@ -1157,8 +1154,7 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, return 0; out_unmap: - for (thread = 0; thread < nr_threads; thread++) - __perf_evlist__munmap(evlist, thread); + perf_evlist__munmap_nofree(evlist); return -1; }