Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2821103yba; Sat, 18 May 2019 03:47:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxSTwmrUUtck/+aA0W9zgK5az2sW+N2HvZOjoMNInxvQSb4BVSkgNbvrOwmPbp+iz0VFBWF X-Received: by 2002:a65:4907:: with SMTP id p7mr61819505pgs.288.1558176464789; Sat, 18 May 2019 03:47:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558176464; cv=none; d=google.com; s=arc-20160816; b=BBDK4JpshviVbIJhWCa0lj6f32s0lJx/Dz32HoX2Z4D29pxuqf3QEP9Ys/yLWG/GAO Uc9+4IOXixMyxEFn0FWwn0xXNgSfWoIbcZn35mHFvtg8nPhq22iG7/LZ10ec2+uy54kp WLMmKEiGUILUd0SIL/Hply8pM6OMz29rmKEO5+cZ3tsCDxQ15u5MzJCQ0hGCWhijVUm0 olwdEP5eQunXJWma0cK1f4JqLcKgIjyZgFkGJcqMcbhquAFKcYWk8ORUxrIizaXIFysn 1c4+ndTtHo4a+TqqK6HrjEzUxF07emsphMZ1xjk1hcv+MomwnlnpDOaLFZWkjaJt6R7j DHVQ== 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=JN5L4QzSYCIpcc1mz6cgi4dRfmSNKY+8/f2TPOR+w/w=; b=JGOnA2TBIEsURhmi2qmuYprPJ2KaH9Aush7D4MSYCK0QFyI6Yuiv7FMEBBGzS5P+5B +/TwVmZlkKaVXd7IqFL9V3RnQ+n/xcyNqMnz+rX0OusyyAmtpRrFLvq+DiGks53qdIv9 s980dFSk3PZcolFj9a8uyxsGENPhVlMXCwqpFtXY+TsY3XHBi7/9D/bY3G61/TSwZnCD 4OZArrUM5TVAb5rlLGgBo1Ky5vMdfAi0FRUQLWd9zWQPhFdsqUAOzJpPO3+QUuTj38GW KFX9x3hpuSJhmaM7aYWrFNWdEL5AMSbIOaryz/gme0bqTwMdiZHlO5HgnWR3JgsFkQX8 QuAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=JEbaAlFP; 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 c12si5167722pgq.533.2019.05.18.03.47.30; Sat, 18 May 2019 03:47:44 -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=JEbaAlFP; 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 S1729828AbfERJWA (ORCPT + 99 others); Sat, 18 May 2019 05:22:00 -0400 Received: from terminus.zytor.com ([198.137.202.136]:38749 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbfERJV7 (ORCPT ); Sat, 18 May 2019 05:21:59 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x4I9LlCW1739064 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sat, 18 May 2019 02:21:47 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x4I9LlCW1739064 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019041745; t=1558171307; bh=JN5L4QzSYCIpcc1mz6cgi4dRfmSNKY+8/f2TPOR+w/w=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=JEbaAlFPAqRP2RPfc6krklgljjxXN7RE/lzm6aXM4TUObjKepHrzRA5YmXWqQAuMp PbaTt2fhgtwC4J/h7R5LC9rhDx3R8OBlPPN6MXEetxnndEk8yv0MW2m/p7q7AtmKaE lTaaVYmoY/glvHexYIilThWG/ol+9tz55eeORUnDLCMOn3i7wEia0FBHK/ZtGMcgWD Y55n2hz1YwhzbL9B7asHZWU1EQ20tngwLGz9B8Gqxg34oqORbyMqyLX+yJp66QpZcJ 6kmYlLS7mG+vJCK8diGo1Y8y2aL/l4kU0lgUBwGx6NUjZS4nrOPkBDMeRfvsWVpbQ7 X2Tm2vP+2EYWQ== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x4I9LkC01739061; Sat, 18 May 2019 02:21:46 -0700 Date: Sat, 18 May 2019 02:21:46 -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: alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org, jolsa@kernel.org, acme@redhat.com, hpa@zytor.com, tglx@linutronix.de, alexey.budankov@linux.intel.com, namhyung@kernel.org, peterz@infradead.org, mingo@kernel.org, ak@linux.intel.com Reply-To: ak@linux.intel.com, mingo@kernel.org, alexey.budankov@linux.intel.com, tglx@linutronix.de, peterz@infradead.org, hpa@zytor.com, namhyung@kernel.org, acme@redhat.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, alexander.shishkin@linux.intel.com In-Reply-To: <18bf36f3-b85a-1fe2-dd83-10e0c6069568@linux.intel.com> References: <18bf36f3-b85a-1fe2-dd83-10e0c6069568@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Introduce Zstd streaming based compression API Git-Commit-ID: f24c1d7523e6db26ec2115a308750c875927741b 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: f24c1d7523e6db26ec2115a308750c875927741b Gitweb: https://git.kernel.org/tip/f24c1d7523e6db26ec2115a308750c875927741b Author: Alexey Budankov AuthorDate: Mon, 18 Mar 2019 20:42:55 +0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 15 May 2019 16:36:49 -0300 perf tools: Introduce Zstd streaming based compression API Implemented functions are based on Zstd streaming compression API. The functions are used in runtime to compress data that come from mmaped kernel buffer. zstd_init(), zstd_fini() are used for initialization and finalization to allocate and deallocate internal zstd objects. zstd_compress_stream_to_records() is used to convert parts of mmaped kernel buffer into an array of PERF_RECORD_COMPRESSED records. 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/18bf36f3-b85a-1fe2-dd83-10e0c6069568@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/Build | 2 ++ tools/perf/util/compress.h | 42 ++++++++++++++++++++++++++++ tools/perf/util/zstd.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 8dd3102301ea..6d5bbc8b589b 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -145,6 +145,8 @@ perf-y += scripting-engines/ perf-$(CONFIG_ZLIB) += zlib.o perf-$(CONFIG_LZMA) += lzma.o +perf-$(CONFIG_ZSTD) += zstd.o + perf-y += demangle-java.o perf-y += demangle-rust.o diff --git a/tools/perf/util/compress.h b/tools/perf/util/compress.h index 892e92e7e7fc..1041a4fd81e2 100644 --- a/tools/perf/util/compress.h +++ b/tools/perf/util/compress.h @@ -2,6 +2,11 @@ #ifndef PERF_COMPRESS_H #define PERF_COMPRESS_H +#include +#ifdef HAVE_ZSTD_SUPPORT +#include +#endif + #ifdef HAVE_ZLIB_SUPPORT int gzip_decompress_to_file(const char *input, int output_fd); bool gzip_is_compressed(const char *input); @@ -12,4 +17,41 @@ int lzma_decompress_to_file(const char *input, int output_fd); bool lzma_is_compressed(const char *input); #endif +struct zstd_data { +#ifdef HAVE_ZSTD_SUPPORT + ZSTD_CStream *cstream; +#endif +}; + +#ifdef HAVE_ZSTD_SUPPORT + +int zstd_init(struct zstd_data *data, int level); +int zstd_fini(struct zstd_data *data); + +size_t zstd_compress_stream_to_records(struct zstd_data *data, void *dst, size_t dst_size, + void *src, size_t src_size, size_t max_record_size, + size_t process_header(void *record, size_t increment)); +#else /* !HAVE_ZSTD_SUPPORT */ + +static inline int zstd_init(struct zstd_data *data __maybe_unused, int level __maybe_unused) +{ + return 0; +} + +static inline int zstd_fini(struct zstd_data *data __maybe_unused) +{ + return 0; +} + +static inline +size_t zstd_compress_stream_to_records(struct zstd_data *data __maybe_unused, + void *dst __maybe_unused, size_t dst_size __maybe_unused, + void *src __maybe_unused, size_t src_size __maybe_unused, + size_t max_record_size __maybe_unused, + size_t process_header(void *record, size_t increment) __maybe_unused) +{ + return 0; +} +#endif + #endif /* PERF_COMPRESS_H */ diff --git a/tools/perf/util/zstd.c b/tools/perf/util/zstd.c new file mode 100644 index 000000000000..359ec9a9d306 --- /dev/null +++ b/tools/perf/util/zstd.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +#include "util/compress.h" +#include "util/debug.h" + +int zstd_init(struct zstd_data *data, int level) +{ + size_t ret; + + data->cstream = ZSTD_createCStream(); + if (data->cstream == NULL) { + pr_err("Couldn't create compression stream.\n"); + return -1; + } + + ret = ZSTD_initCStream(data->cstream, level); + if (ZSTD_isError(ret)) { + pr_err("Failed to initialize compression stream: %s\n", ZSTD_getErrorName(ret)); + return -1; + } + + return 0; +} + +int zstd_fini(struct zstd_data *data) +{ + if (data->cstream) { + ZSTD_freeCStream(data->cstream); + data->cstream = NULL; + } + + return 0; +} + +size_t zstd_compress_stream_to_records(struct zstd_data *data, void *dst, size_t dst_size, + void *src, size_t src_size, size_t max_record_size, + size_t process_header(void *record, size_t increment)) +{ + size_t ret, size, compressed = 0; + ZSTD_inBuffer input = { src, src_size, 0 }; + ZSTD_outBuffer output; + void *record; + + while (input.pos < input.size) { + record = dst; + size = process_header(record, 0); + compressed += size; + dst += size; + dst_size -= size; + output = (ZSTD_outBuffer){ dst, (dst_size > max_record_size) ? + max_record_size : dst_size, 0 }; + ret = ZSTD_compressStream(data->cstream, &output, &input); + ZSTD_flushStream(data->cstream, &output); + if (ZSTD_isError(ret)) { + pr_err("failed to compress %ld bytes: %s\n", + (long)src_size, ZSTD_getErrorName(ret)); + memcpy(dst, src, src_size); + return src_size; + } + size = output.pos; + size = process_header(record, size); + compressed += size; + dst += size; + dst_size -= size; + } + + return compressed; +}