From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AFF8C433F4 for ; Tue, 28 Aug 2018 15:50:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DA9F72084A for ; Tue, 28 Aug 2018 15:50:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA9F72084A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727199AbeH1Tmn (ORCPT ); Tue, 28 Aug 2018 15:42:43 -0400 Received: from mga14.intel.com ([192.55.52.115]:25519 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726951AbeH1Tmn (ORCPT ); Tue, 28 Aug 2018 15:42:43 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Aug 2018 08:50:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,300,1531810800"; d="scan'208";a="66637057" Received: from linux.intel.com ([10.54.29.200]) by fmsmga008.fm.intel.com with ESMTP; 28 Aug 2018 08:50:17 -0700 Received: from [10.125.252.157] (abudanko-mobl.ccr.corp.intel.com [10.125.252.157]) by linux.intel.com (Postfix) with ESMTP id 292CE5803E2; Tue, 28 Aug 2018 08:50:14 -0700 (PDT) Subject: [PATCH v4 1/2]: perf util: map data buffer for preserving collected data From: Alexey Budankov To: Ingo Molnar , Peter Zijlstra , Arnaldo Carvalho de Melo Cc: Alexander Shishkin , Jiri Olsa , Namhyung Kim , Andi Kleen , linux-kernel References: <74fbcac7-80af-fcf0-2666-adefca98c271@linux.intel.com> Organization: Intel Corp. Message-ID: <5ee46e7c-2708-8f32-6bc3-73d33ff82e8a@linux.intel.com> Date: Tue, 28 Aug 2018 18:50:14 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <74fbcac7-80af-fcf0-2666-adefca98c271@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The data buffer and accompanying AIO control block are allocated at perf_mmap object and the mapped data buffer size is equal to the kernel one. The buffer is then used to preserve profiling data ready for dumping and queue it for asynchronous writing into perf trace thru implemented record__aio_write() function. mmap_aio control structure of the size equal to the number of per-cpu kernel buffers is used to keep pointers to enqueued AIO control blocks for monitoring of completed AIO operations. Signed-off-by: Alexey Budankov --- Changes in v4: - converted mmap()/munmap() to malloc()/free() for mmap->data buffer management Changes in v2: - converted zalloc() to calloc() for allocation of mmap_aio array, - cleared typo and adjusted fallback branch code; --- tools/perf/util/evlist.c | 7 +++++++ tools/perf/util/evlist.h | 2 ++ tools/perf/util/mmap.c | 10 ++++++++++ tools/perf/util/mmap.h | 3 +++ 4 files changed, 22 insertions(+) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index e7a4b31a84fb..04596f74766c 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -718,6 +718,8 @@ static void perf_evlist__munmap_nofree(struct perf_evlist *evlist) void perf_evlist__munmap(struct perf_evlist *evlist) { perf_evlist__munmap_nofree(evlist); + if (evlist->mmap_aio) + zfree(&evlist->mmap_aio); zfree(&evlist->mmap); zfree(&evlist->overwrite_mmap); } @@ -749,6 +751,11 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct perf_evlist *evlist, */ refcount_set(&map[i].refcnt, 0); } + + evlist->mmap_aio = calloc(evlist->nr_mmaps, sizeof(struct aiocb *)); + if (!evlist->mmap_aio) + zfree(&map); + return map; } diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index dc66436add98..f98b949561fd 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -15,6 +15,7 @@ #include "util.h" #include #include +#include struct pollfd; struct thread_map; @@ -43,6 +44,7 @@ struct perf_evlist { } workload; struct fdarray pollfd; struct perf_mmap *mmap; + struct aiocb **mmap_aio; struct perf_mmap *overwrite_mmap; struct thread_map *threads; struct cpu_map *cpus; diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index fc832676a798..570cba187f70 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -155,6 +155,10 @@ void __weak auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp __mayb void perf_mmap__munmap(struct perf_mmap *map) { + if (map->data != NULL) { + free(map->data); + map->data = NULL; + } if (map->base != NULL) { munmap(map->base, perf_mmap__mmap_len(map)); map->base = NULL; @@ -190,6 +194,12 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd) map->base = NULL; return -1; } + map->data = malloc(perf_mmap__mmap_len(map)); + if (map->data == NULL) { + pr_debug2("failed to mmap perf event data buffer, error %d\n", + errno); + return -1; + } map->fd = fd; if (auxtrace_mmap__mmap(&map->auxtrace_mmap, diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h index d82294db1295..1974e621e36b 100644 --- a/tools/perf/util/mmap.h +++ b/tools/perf/util/mmap.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "auxtrace.h" #include "event.h" @@ -25,6 +26,8 @@ struct perf_mmap { bool overwrite; struct auxtrace_mmap auxtrace_mmap; char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8); + void *data; + struct aiocb cblock; }; /*