Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4260917ybp; Mon, 7 Oct 2019 05:57:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwEi7O9naoPS0RqSSEKKvTXLpBfh/RIiK00bAWzFM+E4v9E038E5nv/RxeCxsTUPdXAiHWQ X-Received: by 2002:a05:6402:121a:: with SMTP id c26mr29511354edw.100.1570453045944; Mon, 07 Oct 2019 05:57:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570453045; cv=none; d=google.com; s=arc-20160816; b=ylQoJ5Xy7P9QmSamvly1nH3KT2BvwXgaLRbdpdpI2Tg/CL7dGtASwgCW6eSTiOT6Kd JFrzmjwGp5nMaooz01EfOzaKjYJ4nqsX8/Fo6WEIujJwUAsUjaYF533WrjpRtsnlkD5/ 3u1Qu081DRTX7IOi9sfTYmXt8ziuph4Zvvaba751Bnj4bqYKV2qxvuR9I28gAHo76WPF vWqRTOJs5pxli18BFBwvRjJNzBvGkbx8Oo6zwrvYBZBMSzlCJGx2965qpnMKbUUrAjab 9PoUyqVmumXE81nJOvCL0RYYOAaKjUiu4kAk4W4Kc8fS/J8Ot5xoocpkKjW+we52/Zgj TTpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jFOEfqAZzEQIXe0ZiAN8uCn5jW8O69JcG/MbW2NUoIU=; b=CPHrxK83FtedRP/Y771PnkWyacnwvP5jK9pnDELWhW1ycyRpamhnIWL4dUn/MVdfX2 OYBWE96CeHIz9T54Pa3lgc9PxOQ+yVxqRjMBoeYi7zTUYFZHkmQ/p3/p7KXor5dp/wDe 1pzTigRrgisX0vZ6gtxVt8jSmzckxr3iRoxnEDORPbvWyElt77x0jaiNIJTEwY12o1Oy +n7q3PnIJ5VaEYYnbZtMw0Qdiu/YC9ikJYP6nttMh++ld+iMFVRTW4m3CENw4M7KeyoM AjJcn98Sm5e3QIGXvoBhOM0QobTOJiyz3smXMubkn2fuMs++xRDY3y2KTZ2a3itx8DOo +O+Q== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8si8066114edq.84.2019.10.07.05.57.02; Mon, 07 Oct 2019 05:57:25 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728084AbfJGMyD (ORCPT + 99 others); Mon, 7 Oct 2019 08:54:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36920 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728047AbfJGMyA (ORCPT ); Mon, 7 Oct 2019 08:54:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD27D85542; Mon, 7 Oct 2019 12:53:59 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4262D5DA8C; Mon, 7 Oct 2019 12:53:58 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Alexander Shishkin , Michael Petlan , Namhyung Kim , Peter Zijlstra , lkml , Ingo Molnar Subject: [PATCH 06/36] libperf: Add perf_mmap__unmap() function Date: Mon, 7 Oct 2019 14:53:14 +0200 Message-Id: <20191007125344.14268-7-jolsa@kernel.org> In-Reply-To: <20191007125344.14268-1-jolsa@kernel.org> References: <20191007125344.14268-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 07 Oct 2019 12:54:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move perf_mmap__unmap() from tools/perf to libperf, to internal header internal/mmap.h. It will be used in the following patches. And rename the existing perf's function to mmap__munmap(). Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Michael Petlan Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lore.kernel.org/lkml/20190913132355.21634-45-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/lib/include/internal/mmap.h | 1 + tools/perf/lib/mmap.c | 10 ++++++++++ tools/perf/util/evlist.c | 4 ++-- tools/perf/util/mmap.c | 11 +++-------- tools/perf/util/mmap.h | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h index 2e68974bffb4..5c2ca9ab12cd 100644 --- a/tools/perf/lib/include/internal/mmap.h +++ b/tools/perf/lib/include/internal/mmap.h @@ -39,6 +39,7 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map); void perf_mmap__init(struct perf_mmap *map, bool overwrite); int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp, int fd, int cpu); +void perf_mmap__munmap(struct perf_mmap *map); void perf_mmap__get(struct perf_mmap *map); #endif /* __LIBPERF_INTERNAL_MMAP_H */ diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c index b765e0505bb6..6eb228d89206 100644 --- a/tools/perf/lib/mmap.c +++ b/tools/perf/lib/mmap.c @@ -32,6 +32,16 @@ int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp, return 0; } +void perf_mmap__munmap(struct perf_mmap *map) +{ + if (map && map->base != NULL) { + munmap(map->base, perf_mmap__mmap_len(map)); + map->base = NULL; + map->fd = -1; + refcount_set(&map->refcnt, 0); + } +} + void perf_mmap__get(struct perf_mmap *map) { refcount_inc(&map->refcnt); diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index a7ba22e18e7b..2e5eaac6325e 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -577,11 +577,11 @@ static void evlist__munmap_nofree(struct evlist *evlist) if (evlist->mmap) for (i = 0; i < evlist->core.nr_mmaps; i++) - perf_mmap__munmap(&evlist->mmap[i]); + mmap__munmap(&evlist->mmap[i]); if (evlist->overwrite_mmap) for (i = 0; i < evlist->core.nr_mmaps; i++) - perf_mmap__munmap(&evlist->overwrite_mmap[i]); + mmap__munmap(&evlist->overwrite_mmap[i]); } void evlist__munmap(struct evlist *evlist) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index be691b58d8ab..2c73b5bcf74e 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -115,7 +115,7 @@ void perf_mmap__put(struct mmap *map) BUG_ON(map->core.base && refcount_read(&map->core.refcnt) == 0); if (refcount_dec_and_test(&map->core.refcnt)) - perf_mmap__munmap(map); + mmap__munmap(map); } void perf_mmap__consume(struct mmap *map) @@ -306,19 +306,14 @@ static void perf_mmap__aio_munmap(struct mmap *map __maybe_unused) } #endif -void perf_mmap__munmap(struct mmap *map) +void mmap__munmap(struct mmap *map) { + perf_mmap__munmap(&map->core); perf_mmap__aio_munmap(map); if (map->data != NULL) { munmap(map->data, mmap__mmap_len(map)); map->data = NULL; } - if (map->core.base != NULL) { - munmap(map->core.base, mmap__mmap_len(map)); - map->core.base = NULL; - map->core.fd = -1; - refcount_set(&map->core.refcnt, 0); - } auxtrace_mmap__munmap(&map->auxtrace_mmap); } diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h index a73402ee8fe0..6a18b2990059 100644 --- a/tools/perf/util/mmap.h +++ b/tools/perf/util/mmap.h @@ -43,7 +43,7 @@ struct mmap_params { }; int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu); -void perf_mmap__munmap(struct mmap *map); +void mmap__munmap(struct mmap *map); void perf_mmap__put(struct mmap *map); -- 2.21.0