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 BDF79C4321E for ; Fri, 7 Sep 2018 07:11:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7FA58206BB for ; Fri, 7 Sep 2018 07:11:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7FA58206BB 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 S1727664AbeIGLuj (ORCPT ); Fri, 7 Sep 2018 07:50:39 -0400 Received: from mga14.intel.com ([192.55.52.115]:28291 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725987AbeIGLui (ORCPT ); Fri, 7 Sep 2018 07:50:38 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Sep 2018 00:11:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,341,1531810800"; d="scan'208";a="81612635" Received: from linux.intel.com ([10.54.29.200]) by orsmga003.jf.intel.com with ESMTP; 07 Sep 2018 00:11:06 -0700 Received: from [10.125.252.7] (abudanko-mobl.ccr.corp.intel.com [10.125.252.7]) by linux.intel.com (Postfix) with ESMTP id D29BF5801E6; Fri, 7 Sep 2018 00:11:04 -0700 (PDT) Subject: [PATCH v8 1/3]: perf util: map data buffer for preserving collected data From: Alexey Budankov To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo Cc: Alexander Shishkin , Jiri Olsa , Namhyung Kim , Andi Kleen , linux-kernel References: Organization: Intel Corp. Message-ID: Date: Fri, 7 Sep 2018 10:11:03 +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: 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 map->data buffer is used to preserve map->base profiling data for writing to disk. AIO map->cblock is used to queue corresponding map->data buffer for asynchronous writing. Signed-off-by: Alexey Budankov --- Changes in v7: - implemented handling record.aio setting from perfconfig file Changes in v6: - adjusted setting of priorities for cblocks; Changes in v5: - reshaped layout of data structures; - implemented --aio option; 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/mmap.c | 25 +++++++++++++++++++++++++ tools/perf/util/mmap.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index fc832676a798..e53038d76445 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -155,6 +155,8 @@ void __weak auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp __mayb void perf_mmap__munmap(struct perf_mmap *map) { + if (map->data) + zfree(&map->data); if (map->base != NULL) { munmap(map->base, perf_mmap__mmap_len(map)); map->base = NULL; @@ -166,6 +168,7 @@ void perf_mmap__munmap(struct perf_mmap *map) int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd) { + int delta_max; /* * The last one will be done at perf_mmap__consume(), so that we * make sure we don't prevent tools from consuming every last event in @@ -190,6 +193,28 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd) map->base = NULL; return -1; } + delta_max = sysconf(_SC_AIO_PRIO_DELTA_MAX); + map->data = malloc(perf_mmap__mmap_len(map)); + if (!map->data) { + pr_debug2("failed to allocate data buffer, error %d\n", + errno); + return -1; + } + /* + * Use cblock.aio_fildes value different from -1 + * to denote started aio write operation on the + * cblock so it requires explicit record__aio_sync() + * call prior the cblock may be reused again. + */ + map->cblock.aio_fildes = -1; + /* + * Allocate cblock with max priority delta to + * have faster aio_write() calls because queued + * requests are kept in separate per-prio queues + * and adding a new request iterates thru shorter + * per-prio list. + */ + map->cblock.aio_reqprio = delta_max; 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; }; /*