Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1203046imd; Thu, 1 Nov 2018 11:49:04 -0700 (PDT) X-Google-Smtp-Source: AJdET5e4e08SPUcaeJR4XEMDA56VBM0KE/yJzW6Z3sY9Btr+Q4MwyWl5iHUWk+60m3a0zP6UkQek X-Received: by 2002:a62:380e:: with SMTP id f14-v6mr8739112pfa.203.1541098144354; Thu, 01 Nov 2018 11:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541098144; cv=none; d=google.com; s=arc-20160816; b=k/I+5wdMOiwN23wMq7CgLA7S+MWOREjhmSXDc7WIQFA1ssMyGlRmizfhaB4I5UExTu 43Zc/In4YmyD4e5ZjYPK2c3N2Uek9SauX8TLOdZVKNzuO3xUXG00lL4nkWiEG3tbk/dg j490++R2u1/NbE7k+APFLBRJNx1Bc6eeKbYis/vd+/eDTLJuyNz/2OI1PtPnVHJefUKU iEtoU9v71GH/x1wlh/s2hrruQpOtMDYTCPzOstqBNdGgvjW45kkgWaSgADQTZamdOS4r xHteFe7+bIEH3xY2ovPHmHcTyVTv/IVnZmzYRKLmzaVZs7GEbPIGOpRPztIwwcjFy6Nf 90hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5nYWpLGnNiZiMINgsxABC7LPTW8BjU1QK3MpX/ZZQ8U=; b=0End3GfBpwMybD30vm6QQS6JPVhPCvcYAKhcfJVyWgxKaKOSJ16qm8d1uKs+SzRlKj D0gVHuejyj8LEaDU3OPZ/vWcBJRZD1UdgFohFdZOR6D4YDTs6wA/nGGdwsTX8BM96DT/ mVjar6ieEIc86JqWHzSy//Gt4NEOOl8W6ZPwHgEeZQfSpdPJzehLwedAptElgaR45vve tI2qu9iAwKt5rUgQ+fyQlw+qLYgAX/tJi/tk7NBb6AdKz5tIXDYQ86Z3L/U2roi55cHY /rRcFyExjPEBO/YSHrBgVB1U7kjaTdbm5mDqLNVZPP+n6pr25GI0aMMY+EpJNgNunSFJ gc4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JagDbMBz; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w6-v6si29799611pgp.42.2018.11.01.11.48.49; Thu, 01 Nov 2018 11:49:04 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JagDbMBz; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727567AbeKBDvz (ORCPT + 99 others); Thu, 1 Nov 2018 23:51:55 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:42401 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725961AbeKBDvy (ORCPT ); Thu, 1 Nov 2018 23:51:54 -0400 Received: by mail-qt1-f196.google.com with SMTP id z20-v6so22255046qti.9 for ; Thu, 01 Nov 2018 11:47:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5nYWpLGnNiZiMINgsxABC7LPTW8BjU1QK3MpX/ZZQ8U=; b=JagDbMBzA9Q8ChPMJtJTzA8PDcJTc6XPz4QC5L2pvR9jzgtuGEXYehKI1vbdJBSyLb vGcctn2LasT2VkAUCkBtwyvn8gk24LfsHRMqypdO1b/eE1O4RNEp0nLpVlOrhoMZS6T3 9gDE6Bge/QeYF6ggU8F5DkDjq/EHqtHuCjYXaC+kNGPw6xtITwPEXWFT27z7YWMrA2fC 1a6hLlhgx7LRvvR2EUaFppHWWIxagx0dwcGtZXLZBJ2TLBVxSl5wFo8P7eBMT3/2DdPX 7vrGV4fOhZ/5usFGj+DWUHy1dPAC+nkPNzEO5WdSztfzxV/7/r19nWo5YAPGvvYX4ZG+ ANMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5nYWpLGnNiZiMINgsxABC7LPTW8BjU1QK3MpX/ZZQ8U=; b=pwUeW3Q6InyaEur3UEdUi/F24m3Xfh86ZCx0d3tpNAEx3KZvwNhBuDJvE/gsT45+aR nAGVJAn/MUs8wUBXVWK7MvaNQsl5AZUHEuj38BFD3K05AUqf+XloehyU1H35mlvlITZn eMDEC5cEB6aL7I3J+YiIeT4jxxNm/QexxFJou+RPP57IKCJ2udO4nSJeN3dR/zqQpj6P DrPifLuBCAqIQ6jsybdQB5N/PwgA6CltaSHKka4TDI4ZzxUHA+cGRHxfCjuf25be6P5c MaENG6bAWH42rwA9k6LcDy6ed15xEf7R7ATpTC839V35K5lBGecl6VKQLcmd0wluGei6 jEMg== X-Gm-Message-State: AGRZ1gJAg6ZL1JYUoLYsfD22geobcMMwhlwE4obG5csy8QBTYwgmyfRL Hrb+DQANXTgcfN7cHS0GSWhEMAA/t8hHP4/lqTTz5DKw X-Received: by 2002:ac8:3312:: with SMTP id t18mr7947956qta.225.1541098063266; Thu, 01 Nov 2018 11:47:43 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Song Liu Date: Thu, 1 Nov 2018 11:47:32 -0700 Message-ID: Subject: Re: [PATCH v14 1/3]: perf util: map data buffer for preserving collected data To: Alexey Budankov Cc: Peter Zijlstra , mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, ak@linux.intel.com, open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 14, 2018 at 11:44 PM Alexey Budankov wrote: > > > 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 Acked-by: Song Liu Shall we add libaio to tools/build/Makefile.feature? It will be great to see whether aio is enabled in "Auto-detecting system features:". Thanks for implementing this! Song > --- > Changes in v13: > - grouped aio functions under single #ifdef HAVE_AIO_SUPPORT > Changes in v12: > - applied stub functions design for the whole patch kit > - grouped AIO related data into a struct under struct perf_mmap > Changes in v10: > - moved specific code to perf_mmap__aio_mmap(), perf_mmap__aio_munmap() > - adjusted error reporting by using %m > Changes in v9: > - implemented NO_AIO and HAVE_AIO_SUPPORT defines to cover cases of > libc implementations without Posix AIO API support > 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/Makefile.config | 5 +++++ > tools/perf/Makefile.perf | 7 ++++++- > tools/perf/util/evlist.c | 2 +- > tools/perf/util/mmap.c | 49 +++++++++++++++++++++++++++++++++++++++++++++- > tools/perf/util/mmap.h | 11 ++++++++++- > 5 files changed, 70 insertions(+), 4 deletions(-) > > diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config > index f6d1a03c7523..2e90f4ce9214 100644 > --- a/tools/perf/Makefile.config > +++ b/tools/perf/Makefile.config > @@ -355,6 +355,11 @@ endif # NO_LIBELF > > ifeq ($(feature-glibc), 1) > CFLAGS += -DHAVE_GLIBC_SUPPORT > + ifndef NO_AIO > + ifndef BIONIC > + CFLAGS += -DHAVE_AIO_SUPPORT > + endif > + endif > endif > > ifdef NO_DWARF > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf > index 92514fb3689f..7becc6a72cf2 100644 > --- a/tools/perf/Makefile.perf > +++ b/tools/perf/Makefile.perf > @@ -97,8 +97,13 @@ include ../scripts/utilities.mak > # Define LIBCLANGLLVM if you DO want builtin clang and llvm support. > # When selected, pass LLVM_CONFIG=/path/to/llvm-config to `make' if > # llvm-config is not in $PATH. > - > +# > # Define NO_CORESIGHT if you do not want support for CoreSight trace decoding. > +# > +# Define NO_AIO if you do not want support of Posix AIO based trace > +# streaming for record mode. Currently Posix AIO trace streaming is > +# supported only when linking with glibc. > +# > > # As per kernel Makefile, avoid funny character set dependencies > unexport LC_ALL > diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c > index be440df29615..1a83bf2c069c 100644 > --- a/tools/perf/util/evlist.c > +++ b/tools/perf/util/evlist.c > @@ -1028,7 +1028,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages, > * Its value is decided by evsel's write_backward. > * So &mp should not be passed through const pointer. > */ > - struct mmap_params mp; > + struct mmap_params mp = { .nr_cblocks = 0 }; > > if (!evlist->mmap) > evlist->mmap = perf_evlist__alloc_mmap(evlist, false); > diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c > index cdb95b3a1213..47cdc3ad6546 100644 > --- a/tools/perf/util/mmap.c > +++ b/tools/perf/util/mmap.c > @@ -153,8 +153,55 @@ void __weak auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp __mayb > { > } > > +#ifdef HAVE_AIO_SUPPORT > +static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp) > +{ > + int delta_max; > + > + if (mp->nr_cblocks) { > + map->aio.data = malloc(perf_mmap__mmap_len(map)); > + if (!map->aio.data) { > + pr_debug2("failed to allocate data buffer, error %m\n"); > + 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->aio.cblock.aio_fildes = -1; > + /* > + * Allocate cblock with max priority delta to > + * have faster aio write system calls. > + */ > + delta_max = sysconf(_SC_AIO_PRIO_DELTA_MAX); > + map->aio.cblock.aio_reqprio = delta_max; > + } > + > + return 0; > +} > + > +static void perf_mmap__aio_munmap(struct perf_mmap *map) > +{ > + if (map->aio.data) > + zfree(&map->aio.data); > +} > +#else > +static int perf_mmap__aio_mmap(struct perf_mmap *map __maybe_unused, > + struct mmap_params *mp __maybe_unused) > +{ > + return 0; > +} > + > +static void perf_mmap__aio_munmap(struct perf_mmap *map __maybe_unused) > +{ > +} > +#endif > + > void perf_mmap__munmap(struct perf_mmap *map) > { > + perf_mmap__aio_munmap(map); > if (map->base != NULL) { > munmap(map->base, perf_mmap__mmap_len(map)); > map->base = NULL; > @@ -197,7 +244,7 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int c > &mp->auxtrace_mp, map->base, fd)) > return -1; > > - return 0; > + return perf_mmap__aio_mmap(map, mp); > } > > static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end) > diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h > index e603314dc792..a46dbdcdcc8a 100644 > --- a/tools/perf/util/mmap.h > +++ b/tools/perf/util/mmap.h > @@ -6,6 +6,9 @@ > #include > #include > #include > +#ifdef HAVE_AIO_SUPPORT > +#include > +#endif > #include "auxtrace.h" > #include "event.h" > > @@ -26,6 +29,12 @@ struct perf_mmap { > bool overwrite; > struct auxtrace_mmap auxtrace_mmap; > char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8); > +#ifdef HAVE_AIO_SUPPORT > + struct { > + void *data; > + struct aiocb cblock; > + } aio; > +#endif > }; > > /* > @@ -57,7 +66,7 @@ enum bkw_mmap_state { > }; > > struct mmap_params { > - int prot, mask; > + int prot, mask, nr_cblocks; > struct auxtrace_mmap_params auxtrace_mp; > }; >