Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2821979yba; Sat, 18 May 2019 03:49:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhOIPRDaDukW3eZM4n6z3+GJmbxP7FwSaSdQC96I2lqVRCyEqAWEK/zbiS5Jx9cmIpc//r X-Received: by 2002:a63:d150:: with SMTP id c16mr61767488pgj.439.1558176542685; Sat, 18 May 2019 03:49:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558176542; cv=none; d=google.com; s=arc-20160816; b=XYUWhnYNcPM+PvWSPdgoyW1h8BP54bwi5Y/3Sslc5NHmu8MSnrguudPBHkT8VbTgmU zO0LByEShsmQVHm/sd9bLq+tiDbUC3JegK0A5RD7tmUac8Pgy0oCTGKVUemtpfeJFzzI awR0uwYBbJKlo8G3qwCo4bRrhUUnr/OBdWkyB4xyCW+4kDBY9W5uDg44ks9o73Qq7Z6Z EYgQeZS6/75Z2pOAe8i3lnZM7LmgSAuqBs6zzx/BnWWH/+kbZBv2FxJC+4zLCsWUZzxO jnYWvaJQOZayw4ggSuwdkLi9B7qDFNKKAhZByx0cTRI8PbU19cl1Gtc+WNDXx4Hm9wIv kBKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=sdZAATLzm52Z0/jInaQGYxsiymrbEglKbG6HDEpCeHw=; b=LuOxiOoVrs/0XU5fLl/dOtfoDrzNqvjMb+P9/38vCWYFSvwidkBM31u64U6PxZ13op l3xdlcSkx5WPmLAhevprJoS3LNZGozqHnkJTqZf9UbEjooXKfInTYJ3zLZnnRTbBWgAL yEnu4Ij3lzqvkynKkFA33ZPA9vIcCwZnGNq7axB8LLFqg7c8KSTvHfht/xgH5OhKOebi 5RIihdz1huDik2cESu5WBQJOwjz+AR4zA0YOecVC91a9hTFxOKZ9jHPrbhyvwpCQXD3l aH9VbU6UpdmW4107Nrncpm1K/+MXo8Z+jpDkUHFotD8zZSNvBcgEAqaurodFAUDyQFRo 2XUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=VQp0R1Ly; 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=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 21si11762603pfc.98.2019.05.18.03.48.47; Sat, 18 May 2019 03:49:02 -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=@zytor.com header.s=2019041745 header.b=VQp0R1Ly; 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=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729850AbfERJWo (ORCPT + 99 others); Sat, 18 May 2019 05:22:44 -0400 Received: from terminus.zytor.com ([198.137.202.136]:48655 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbfERJWn (ORCPT ); Sat, 18 May 2019 05:22:43 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x4I9MVVP1739127 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sat, 18 May 2019 02:22:31 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x4I9MVVP1739127 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019041745; t=1558171351; bh=sdZAATLzm52Z0/jInaQGYxsiymrbEglKbG6HDEpCeHw=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=VQp0R1LyeBUyViKKsRuYv1AWBbCG77POv69y1A8Livc5n5svv++bib9/nfEC1sTV/ ck/ik+Km27N4DNKZNw5J+f8mhMglj2r8Jb0jUlT2yCAj7kH1JQptMjm/+jbqR3tZw3 /RKZZboPYdAjsVfonU+8RFwn7v5j8NTqMYCN3/2b271igDRLPGPpAGZxOj37SPyjF/ P7+1ygKZnwlY/Khc5wQdH/VY9BLKfuj2VFnK+7sJuqAfsbqhnOB0m1X9eYZEA+zdLh YxO8hMn+MXLsudmYZYRc20aWFY1vrcg2vzLE7LZY2BPdn0zG/N9K+it4zeuZyMSeap cI8ELkpD9srKA== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x4I9MUNa1739124; Sat, 18 May 2019 02:22:30 -0700 Date: Sat, 18 May 2019 02:22:30 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Alexey Budankov Message-ID: Cc: acme@redhat.com, alexander.shishkin@linux.intel.com, ak@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, jolsa@kernel.org, alexey.budankov@linux.intel.com, hpa@zytor.com, mingo@kernel.org, namhyung@kernel.org Reply-To: alexander.shishkin@linux.intel.com, acme@redhat.com, tglx@linutronix.de, peterz@infradead.org, ak@linux.intel.com, alexey.budankov@linux.intel.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, namhyung@kernel.org, mingo@kernel.org, hpa@zytor.com In-Reply-To: <744df43f-3932-2594-ddef-1e99a3cad03a@linux.intel.com> References: <744df43f-3932-2594-ddef-1e99a3cad03a@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf record: Implement compression for serial trace streaming Git-Commit-ID: 5d7f41164930ecc1797702b7f9728ac702609ef3 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 5d7f41164930ecc1797702b7f9728ac702609ef3 Gitweb: https://git.kernel.org/tip/5d7f41164930ecc1797702b7f9728ac702609ef3 Author: Alexey Budankov AuthorDate: Mon, 18 Mar 2019 20:43:35 +0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 15 May 2019 16:36:49 -0300 perf record: Implement compression for serial trace streaming Compression is implemented using the functions from zstd.c. As the memory to operate on the compression uses mmap->data buffer. If Zstd streaming compression API fails for some reason the data to be compressed are just copied into the memory buffers using plain memcpy(). Compressed trace frame consists of an array of PERF_RECORD_COMPRESSED records. Each element of the array is not longer that PERF_SAMPLE_MAX_SIZE and consists of perf_event_header followed by the compressed chunk that is decompressed on the loading stage. Comitter notes: Undo some unnecessary line breaks, remove some unnecessary () around zstd_data to then just get its address, and fix conflicts with BPF_PROG_INFO/BPF_BTF patchkits. Signed-off-by: Alexey Budankov Reviewed-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/744df43f-3932-2594-ddef-1e99a3cad03a@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-record.c | 51 +++++++++++++++++++++++++++++++++++++++++++-- tools/perf/util/session.h | 2 ++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index ca6d7488e34b..de9632c69852 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -133,6 +133,9 @@ static int record__write(struct record *rec, struct perf_mmap *map __maybe_unuse return 0; } +static size_t zstd_compress(struct perf_session *session, void *dst, size_t dst_size, + void *src, size_t src_size); + #ifdef HAVE_AIO_SUPPORT static int record__aio_write(struct aiocb *cblock, int trace_fd, void *buf, size_t size, off_t off) @@ -392,6 +395,11 @@ static int record__pushfn(struct perf_mmap *map, void *to, void *bf, size_t size { struct record *rec = to; + if (record__comp_enabled(rec)) { + size = zstd_compress(rec->session, map->data, perf_mmap__mmap_len(map), bf, size); + bf = map->data; + } + rec->samples++; return record__write(rec, map, bf, size); } @@ -778,6 +786,37 @@ static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) } } +static size_t process_comp_header(void *record, size_t increment) +{ + struct compressed_event *event = record; + size_t size = sizeof(*event); + + if (increment) { + event->header.size += increment; + return increment; + } + + event->header.type = PERF_RECORD_COMPRESSED; + event->header.size = size; + + return size; +} + +static size_t zstd_compress(struct perf_session *session, void *dst, size_t dst_size, + void *src, size_t src_size) +{ + size_t compressed; + size_t max_record_size = PERF_SAMPLE_MAX_SIZE - sizeof(struct compressed_event) - 1; + + compressed = zstd_compress_stream_to_records(&session->zstd_data, dst, dst_size, src, src_size, + max_record_size, process_comp_header); + + session->bytes_transferred += src_size; + session->bytes_compressed += compressed; + + return compressed; +} + static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evlist, bool overwrite, bool synch) { @@ -1225,6 +1264,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) fd = perf_data__fd(data); rec->session = session; + if (zstd_init(&session->zstd_data, rec->opts.comp_level) < 0) { + pr_err("Compression initialization failed.\n"); + return -1; + } + + session->header.env.comp_type = PERF_COMP_ZSTD; + session->header.env.comp_level = rec->opts.comp_level; + record__init_features(rec); if (rec->opts.use_clockid && rec->opts.clockid_res_ns) @@ -1565,6 +1612,7 @@ out_child: } out_delete_session: + zstd_fini(&session->zstd_data); perf_session__delete(session); if (!opts->no_bpf_event) @@ -2294,8 +2342,7 @@ int cmd_record(int argc, const char **argv) if (rec->opts.nr_cblocks > nr_cblocks_max) rec->opts.nr_cblocks = nr_cblocks_max; - if (verbose > 0) - pr_info("nr_cblocks: %d\n", rec->opts.nr_cblocks); + pr_debug("nr_cblocks: %d\n", rec->opts.nr_cblocks); pr_debug("affinity: %s\n", affinity_tags[rec->opts.affinity]); pr_debug("mmap flush: %d\n", rec->opts.mmap_flush); diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 0e14884f28b2..6c984c895924 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -8,6 +8,7 @@ #include "machine.h" #include "data.h" #include "ordered-events.h" +#include "util/compress.h" #include #include #include @@ -37,6 +38,7 @@ struct perf_session { struct perf_tool *tool; u64 bytes_transferred; u64 bytes_compressed; + struct zstd_data zstd_data; }; struct perf_tool;