1*5e3eaea3SApple OSS Distributions /*
2*5e3eaea3SApple OSS Distributions * Copyright (c) 2021 Apple Inc. All rights reserved.
3*5e3eaea3SApple OSS Distributions *
4*5e3eaea3SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*5e3eaea3SApple OSS Distributions *
6*5e3eaea3SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*5e3eaea3SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*5e3eaea3SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*5e3eaea3SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*5e3eaea3SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*5e3eaea3SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*5e3eaea3SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*5e3eaea3SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*5e3eaea3SApple OSS Distributions *
15*5e3eaea3SApple OSS Distributions * Please obtain a copy of the License at
16*5e3eaea3SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*5e3eaea3SApple OSS Distributions *
18*5e3eaea3SApple OSS Distributions * The Original Code and all software distributed under the License are
19*5e3eaea3SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*5e3eaea3SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*5e3eaea3SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*5e3eaea3SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*5e3eaea3SApple OSS Distributions * Please see the License for the specific language governing rights and
24*5e3eaea3SApple OSS Distributions * limitations under the License.
25*5e3eaea3SApple OSS Distributions *
26*5e3eaea3SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*5e3eaea3SApple OSS Distributions */
28*5e3eaea3SApple OSS Distributions /*
29*5e3eaea3SApple OSS Distributions * Compresor and swap benchmarks.
30*5e3eaea3SApple OSS Distributions */
31*5e3eaea3SApple OSS Distributions
32*5e3eaea3SApple OSS Distributions #include <err.h>
33*5e3eaea3SApple OSS Distributions #include <errno.h>
34*5e3eaea3SApple OSS Distributions #include <mach/vm_page_size.h>
35*5e3eaea3SApple OSS Distributions #include <stdio.h>
36*5e3eaea3SApple OSS Distributions #include <stdlib.h>
37*5e3eaea3SApple OSS Distributions #include <string.h>
38*5e3eaea3SApple OSS Distributions #include <sys/mman.h>
39*5e3eaea3SApple OSS Distributions #include <sys/sysctl.h>
40*5e3eaea3SApple OSS Distributions #include <sys/types.h>
41*5e3eaea3SApple OSS Distributions
42*5e3eaea3SApple OSS Distributions #include "benchmark/helpers.h"
43*5e3eaea3SApple OSS Distributions
44*5e3eaea3SApple OSS Distributions /*
45*5e3eaea3SApple OSS Distributions * There are four different types of benchmarks
46*5e3eaea3SApple OSS Distributions * Each type can run on a variable size buffer
47*5e3eaea3SApple OSS Distributions * and with different types of data.
48*5e3eaea3SApple OSS Distributions */
49*5e3eaea3SApple OSS Distributions typedef enum test_variant {
50*5e3eaea3SApple OSS Distributions VARIANT_COMPRESS,
51*5e3eaea3SApple OSS Distributions VARIANT_COMPRESS_AND_DECOMPRESS,
52*5e3eaea3SApple OSS Distributions VARIANT_SWAPOUT,
53*5e3eaea3SApple OSS Distributions VARIANT_SWAPOUT_AND_SWAPIN
54*5e3eaea3SApple OSS Distributions } test_variant_t;
55*5e3eaea3SApple OSS Distributions
56*5e3eaea3SApple OSS Distributions /*
57*5e3eaea3SApple OSS Distributions * Each benchmark supports buffers filled with different contents.
58*5e3eaea3SApple OSS Distributions */
59*5e3eaea3SApple OSS Distributions typedef enum allocation_type {
60*5e3eaea3SApple OSS Distributions VARIANT_ZEROS,
61*5e3eaea3SApple OSS Distributions VARIANT_RANDOM,
62*5e3eaea3SApple OSS Distributions VARIANT_TYPICAL
63*5e3eaea3SApple OSS Distributions } allocation_type_t;
64*5e3eaea3SApple OSS Distributions
65*5e3eaea3SApple OSS Distributions /* Arguments parsed from the command line */
66*5e3eaea3SApple OSS Distributions typedef struct test_args {
67*5e3eaea3SApple OSS Distributions uint64_t ta_duration_seconds;
68*5e3eaea3SApple OSS Distributions uint64_t ta_buffer_size;
69*5e3eaea3SApple OSS Distributions test_variant_t ta_variant;
70*5e3eaea3SApple OSS Distributions allocation_type_t ta_alloc_type;
71*5e3eaea3SApple OSS Distributions bool ta_verbose;
72*5e3eaea3SApple OSS Distributions } test_args_t;
73*5e3eaea3SApple OSS Distributions
74*5e3eaea3SApple OSS Distributions struct perf_compressor_data {
75*5e3eaea3SApple OSS Distributions user_addr_t buffer;
76*5e3eaea3SApple OSS Distributions size_t buffer_size;
77*5e3eaea3SApple OSS Distributions uint64_t benchmark_time;
78*5e3eaea3SApple OSS Distributions uint64_t bytes_processed;
79*5e3eaea3SApple OSS Distributions uint64_t compressor_growth;
80*5e3eaea3SApple OSS Distributions };
81*5e3eaea3SApple OSS Distributions
82*5e3eaea3SApple OSS Distributions /* Test Variants */
83*5e3eaea3SApple OSS Distributions static const char *kCompressArgument = "compress";
84*5e3eaea3SApple OSS Distributions static const char *kCompressAndDecompressArgument = "compress-and-decompress";
85*5e3eaea3SApple OSS Distributions
86*5e3eaea3SApple OSS Distributions /* Allocation types */
87*5e3eaea3SApple OSS Distributions static const char *kAllocZeroes = "zero";
88*5e3eaea3SApple OSS Distributions static const char *kAllocRandom = "random";
89*5e3eaea3SApple OSS Distributions static const char *kAllocTypical = "typical";
90*5e3eaea3SApple OSS Distributions
91*5e3eaea3SApple OSS Distributions /*
92*5e3eaea3SApple OSS Distributions * Failure codes
93*5e3eaea3SApple OSS Distributions */
94*5e3eaea3SApple OSS Distributions static int kInvalidArgument = 1;
95*5e3eaea3SApple OSS Distributions static int kAllocationFailure = 2;
96*5e3eaea3SApple OSS Distributions static int kCompressionFailure = 3;
97*5e3eaea3SApple OSS Distributions static int kNYI = 4;
98*5e3eaea3SApple OSS Distributions
99*5e3eaea3SApple OSS Distributions static void parse_arguments(int argc, const char **argv, test_args_t *args /* OUT */);
100*5e3eaea3SApple OSS Distributions static void print_help(const char** argv);
101*5e3eaea3SApple OSS Distributions static unsigned char *alloc_and_fill_buffer(size_t size, allocation_type_t alloc_type);
102*5e3eaea3SApple OSS Distributions void fill_with_typical_data(unsigned char *buf, size_t size);
103*5e3eaea3SApple OSS Distributions static void run_compress_benchmark(const test_args_t *args);
104*5e3eaea3SApple OSS Distributions static uint64_t decompress_buffer(unsigned char *buf, size_t size);
105*5e3eaea3SApple OSS Distributions
106*5e3eaea3SApple OSS Distributions int
main(int argc,const char ** argv)107*5e3eaea3SApple OSS Distributions main(int argc, const char **argv)
108*5e3eaea3SApple OSS Distributions {
109*5e3eaea3SApple OSS Distributions test_args_t args = {0};
110*5e3eaea3SApple OSS Distributions parse_arguments(argc, argv, &args);
111*5e3eaea3SApple OSS Distributions switch (args.ta_variant) {
112*5e3eaea3SApple OSS Distributions case VARIANT_COMPRESS:
113*5e3eaea3SApple OSS Distributions case VARIANT_COMPRESS_AND_DECOMPRESS:
114*5e3eaea3SApple OSS Distributions run_compress_benchmark(&args);
115*5e3eaea3SApple OSS Distributions break;
116*5e3eaea3SApple OSS Distributions default:
117*5e3eaea3SApple OSS Distributions err(kNYI, "NYI: Test variant has not been implemented");
118*5e3eaea3SApple OSS Distributions }
119*5e3eaea3SApple OSS Distributions }
120*5e3eaea3SApple OSS Distributions
121*5e3eaea3SApple OSS Distributions static void
run_compress_benchmark(const test_args_t * args)122*5e3eaea3SApple OSS Distributions run_compress_benchmark(const test_args_t *args)
123*5e3eaea3SApple OSS Distributions {
124*5e3eaea3SApple OSS Distributions uint64_t total_compressor_time = 0;
125*5e3eaea3SApple OSS Distributions uint64_t total_bytes_compressed = 0;
126*5e3eaea3SApple OSS Distributions uint64_t total_compressor_bytes_used = 0;
127*5e3eaea3SApple OSS Distributions uint64_t total_decompressor_time = 0;
128*5e3eaea3SApple OSS Distributions double compressor_throughput = 0, decompressor_throughput = 0, compression_ratio = 0;
129*5e3eaea3SApple OSS Distributions while (total_compressor_time < args->ta_duration_seconds * NSEC_PER_SEC) {
130*5e3eaea3SApple OSS Distributions unsigned char *buf;
131*5e3eaea3SApple OSS Distributions struct perf_compressor_data sysctl_data = {0};
132*5e3eaea3SApple OSS Distributions size_t len = sizeof(sysctl_data);
133*5e3eaea3SApple OSS Distributions
134*5e3eaea3SApple OSS Distributions benchmark_log(args->ta_verbose, "Start allocation\n");
135*5e3eaea3SApple OSS Distributions buf = alloc_and_fill_buffer(args->ta_buffer_size, args->ta_alloc_type);
136*5e3eaea3SApple OSS Distributions if (!buf) {
137*5e3eaea3SApple OSS Distributions err(kAllocationFailure, "Unable to allocate test buffer\n");
138*5e3eaea3SApple OSS Distributions }
139*5e3eaea3SApple OSS Distributions benchmark_log(args->ta_verbose, "Finished allocation\n");
140*5e3eaea3SApple OSS Distributions
141*5e3eaea3SApple OSS Distributions sysctl_data.buffer = (user_addr_t) buf;
142*5e3eaea3SApple OSS Distributions sysctl_data.buffer_size = args->ta_buffer_size;
143*5e3eaea3SApple OSS Distributions benchmark_log(args->ta_verbose, "Start compression\n");
144*5e3eaea3SApple OSS Distributions int ret = sysctlbyname("kern.perf_compressor", &sysctl_data, &len, &sysctl_data, sizeof(sysctl_data));
145*5e3eaea3SApple OSS Distributions if (ret < 0) {
146*5e3eaea3SApple OSS Distributions fprintf(stderr, "Failed to compress buffer: %s\n", strerror(errno));
147*5e3eaea3SApple OSS Distributions exit(kCompressionFailure);
148*5e3eaea3SApple OSS Distributions }
149*5e3eaea3SApple OSS Distributions if (sysctl_data.bytes_processed != args->ta_buffer_size) {
150*5e3eaea3SApple OSS Distributions fprintf(stderr, "WARNING: Failed to compress the whole buffer. Only compressed %llu bytes out of %llu bytes\n", sysctl_data.bytes_processed, args->ta_buffer_size);
151*5e3eaea3SApple OSS Distributions }
152*5e3eaea3SApple OSS Distributions total_bytes_compressed += sysctl_data.bytes_processed;
153*5e3eaea3SApple OSS Distributions total_compressor_time += sysctl_data.benchmark_time;
154*5e3eaea3SApple OSS Distributions total_compressor_bytes_used += sysctl_data.compressor_growth;
155*5e3eaea3SApple OSS Distributions benchmark_log(args->ta_verbose, "Finished compression\n");
156*5e3eaea3SApple OSS Distributions
157*5e3eaea3SApple OSS Distributions if (args->ta_variant == VARIANT_COMPRESS_AND_DECOMPRESS) {
158*5e3eaea3SApple OSS Distributions benchmark_log(args->ta_verbose, "Start decompression\n");
159*5e3eaea3SApple OSS Distributions total_decompressor_time += decompress_buffer(buf, args->ta_buffer_size);
160*5e3eaea3SApple OSS Distributions benchmark_log(args->ta_verbose, "Finished decompression\n");
161*5e3eaea3SApple OSS Distributions }
162*5e3eaea3SApple OSS Distributions munmap(buf, args->ta_buffer_size);
163*5e3eaea3SApple OSS Distributions }
164*5e3eaea3SApple OSS Distributions compressor_throughput = (double) total_bytes_compressed / total_compressor_time * NSEC_PER_SEC;
165*5e3eaea3SApple OSS Distributions printf("bytes_compressed=%llu, compressor_bytes_used=%llu\n", total_bytes_compressed, total_compressor_bytes_used);
166*5e3eaea3SApple OSS Distributions compression_ratio = (double) total_bytes_compressed / total_compressor_bytes_used;
167*5e3eaea3SApple OSS Distributions if (total_decompressor_time != 0) {
168*5e3eaea3SApple OSS Distributions decompressor_throughput = (double) total_bytes_compressed / total_decompressor_time * NSEC_PER_SEC;
169*5e3eaea3SApple OSS Distributions }
170*5e3eaea3SApple OSS Distributions printf("-----Results-----\n");
171*5e3eaea3SApple OSS Distributions printf("Compressor Throughput");
172*5e3eaea3SApple OSS Distributions if (args->ta_variant == VARIANT_COMPRESS_AND_DECOMPRESS) {
173*5e3eaea3SApple OSS Distributions printf(", Decompressor Throughput");
174*5e3eaea3SApple OSS Distributions }
175*5e3eaea3SApple OSS Distributions if (args->ta_alloc_type != VARIANT_ZEROS) {
176*5e3eaea3SApple OSS Distributions printf(", Compression Ratio\n");
177*5e3eaea3SApple OSS Distributions } else {
178*5e3eaea3SApple OSS Distributions printf("\n");
179*5e3eaea3SApple OSS Distributions }
180*5e3eaea3SApple OSS Distributions
181*5e3eaea3SApple OSS Distributions printf("%.0f", compressor_throughput);
182*5e3eaea3SApple OSS Distributions if (args->ta_variant == VARIANT_COMPRESS_AND_DECOMPRESS) {
183*5e3eaea3SApple OSS Distributions printf(", %.0f", decompressor_throughput);
184*5e3eaea3SApple OSS Distributions }
185*5e3eaea3SApple OSS Distributions if (args->ta_alloc_type != VARIANT_ZEROS) {
186*5e3eaea3SApple OSS Distributions printf(", %.2f\n", compression_ratio);
187*5e3eaea3SApple OSS Distributions } else {
188*5e3eaea3SApple OSS Distributions printf("\n");
189*5e3eaea3SApple OSS Distributions }
190*5e3eaea3SApple OSS Distributions }
191*5e3eaea3SApple OSS Distributions
192*5e3eaea3SApple OSS Distributions static unsigned char *
alloc_and_fill_buffer(size_t size,allocation_type_t alloc_type)193*5e3eaea3SApple OSS Distributions alloc_and_fill_buffer(size_t size, allocation_type_t alloc_type)
194*5e3eaea3SApple OSS Distributions {
195*5e3eaea3SApple OSS Distributions unsigned char *buf = mmap_buffer(size);
196*5e3eaea3SApple OSS Distributions if (!buf) {
197*5e3eaea3SApple OSS Distributions return buf;
198*5e3eaea3SApple OSS Distributions }
199*5e3eaea3SApple OSS Distributions switch (alloc_type) {
200*5e3eaea3SApple OSS Distributions case VARIANT_ZEROS:
201*5e3eaea3SApple OSS Distributions bzero(buf, size);
202*5e3eaea3SApple OSS Distributions break;
203*5e3eaea3SApple OSS Distributions case VARIANT_RANDOM:
204*5e3eaea3SApple OSS Distributions arc4random_buf(buf, size);
205*5e3eaea3SApple OSS Distributions break;
206*5e3eaea3SApple OSS Distributions case VARIANT_TYPICAL:
207*5e3eaea3SApple OSS Distributions fill_with_typical_data(buf, size);
208*5e3eaea3SApple OSS Distributions break;
209*5e3eaea3SApple OSS Distributions default:
210*5e3eaea3SApple OSS Distributions err(kInvalidArgument, "Unknown allocation variant\n");
211*5e3eaea3SApple OSS Distributions }
212*5e3eaea3SApple OSS Distributions
213*5e3eaea3SApple OSS Distributions return buf;
214*5e3eaea3SApple OSS Distributions }
215*5e3eaea3SApple OSS Distributions
216*5e3eaea3SApple OSS Distributions static uint64_t
decompress_buffer(unsigned char * buf,size_t size)217*5e3eaea3SApple OSS Distributions decompress_buffer(unsigned char *buf, size_t size)
218*5e3eaea3SApple OSS Distributions {
219*5e3eaea3SApple OSS Distributions /*
220*5e3eaea3SApple OSS Distributions * Fault in the compressed buffer to measure the decompression
221*5e3eaea3SApple OSS Distributions * throughput.
222*5e3eaea3SApple OSS Distributions */
223*5e3eaea3SApple OSS Distributions uint64_t start_time, end_time;
224*5e3eaea3SApple OSS Distributions start_time = current_timestamp_ns();
225*5e3eaea3SApple OSS Distributions volatile unsigned char val;
226*5e3eaea3SApple OSS Distributions for (unsigned char* ptr = buf; ptr < buf + size; ptr += vm_kernel_page_size) {
227*5e3eaea3SApple OSS Distributions val = *ptr;
228*5e3eaea3SApple OSS Distributions }
229*5e3eaea3SApple OSS Distributions end_time = current_timestamp_ns();
230*5e3eaea3SApple OSS Distributions return end_time - start_time;
231*5e3eaea3SApple OSS Distributions }
232*5e3eaea3SApple OSS Distributions
233*5e3eaea3SApple OSS Distributions /*
234*5e3eaea3SApple OSS Distributions * Gives us the compression ratio we see in the typical case (~2.5)
235*5e3eaea3SApple OSS Distributions */
236*5e3eaea3SApple OSS Distributions void
fill_with_typical_data(unsigned char * buf,size_t size)237*5e3eaea3SApple OSS Distributions fill_with_typical_data(unsigned char *buf, size_t size)
238*5e3eaea3SApple OSS Distributions {
239*5e3eaea3SApple OSS Distributions for (size_t i = 0; i < size / vm_kernel_page_size; i++) {
240*5e3eaea3SApple OSS Distributions unsigned char val = 0;
241*5e3eaea3SApple OSS Distributions for (size_t j = 0; j < vm_kernel_page_size; j += 16) {
242*5e3eaea3SApple OSS Distributions memset(&buf[i * vm_kernel_page_size + j], val, 16);
243*5e3eaea3SApple OSS Distributions if (i < 3400 * (vm_kernel_page_size / 4096)) {
244*5e3eaea3SApple OSS Distributions val++;
245*5e3eaea3SApple OSS Distributions }
246*5e3eaea3SApple OSS Distributions }
247*5e3eaea3SApple OSS Distributions }
248*5e3eaea3SApple OSS Distributions }
249*5e3eaea3SApple OSS Distributions
250*5e3eaea3SApple OSS Distributions static void
parse_arguments(int argc,const char ** argv,test_args_t * args)251*5e3eaea3SApple OSS Distributions parse_arguments(int argc, const char** argv, test_args_t *args)
252*5e3eaea3SApple OSS Distributions {
253*5e3eaea3SApple OSS Distributions int current_positional_argument = 0;
254*5e3eaea3SApple OSS Distributions long duration = -1, size_mb = -1;
255*5e3eaea3SApple OSS Distributions memset(args, 0, sizeof(test_args_t));
256*5e3eaea3SApple OSS Distributions for (int current_argument = 1; current_argument < argc; current_argument++) {
257*5e3eaea3SApple OSS Distributions if (argv[current_argument][0] == '-') {
258*5e3eaea3SApple OSS Distributions if (strcmp(argv[current_argument], "-v") == 0) {
259*5e3eaea3SApple OSS Distributions args->ta_verbose = true;
260*5e3eaea3SApple OSS Distributions } else {
261*5e3eaea3SApple OSS Distributions fprintf(stderr, "Unknown argument %s\n", argv[current_argument]);
262*5e3eaea3SApple OSS Distributions print_help(argv);
263*5e3eaea3SApple OSS Distributions exit(kInvalidArgument);
264*5e3eaea3SApple OSS Distributions }
265*5e3eaea3SApple OSS Distributions if (current_argument >= argc) {
266*5e3eaea3SApple OSS Distributions print_help(argv);
267*5e3eaea3SApple OSS Distributions exit(kInvalidArgument);
268*5e3eaea3SApple OSS Distributions }
269*5e3eaea3SApple OSS Distributions } else {
270*5e3eaea3SApple OSS Distributions const char *curr = argv[current_argument];
271*5e3eaea3SApple OSS Distributions if (current_positional_argument == 0) {
272*5e3eaea3SApple OSS Distributions if (strcasecmp(curr, kCompressArgument) == 0) {
273*5e3eaea3SApple OSS Distributions args->ta_variant = VARIANT_COMPRESS;
274*5e3eaea3SApple OSS Distributions } else if (strcasecmp(curr, kCompressAndDecompressArgument) == 0) {
275*5e3eaea3SApple OSS Distributions args->ta_variant = VARIANT_COMPRESS_AND_DECOMPRESS;
276*5e3eaea3SApple OSS Distributions } else {
277*5e3eaea3SApple OSS Distributions print_help(argv);
278*5e3eaea3SApple OSS Distributions exit(kInvalidArgument);
279*5e3eaea3SApple OSS Distributions }
280*5e3eaea3SApple OSS Distributions } else if (current_positional_argument == 1) {
281*5e3eaea3SApple OSS Distributions if (strcasecmp(curr, kAllocZeroes) == 0) {
282*5e3eaea3SApple OSS Distributions args->ta_alloc_type = VARIANT_ZEROS;
283*5e3eaea3SApple OSS Distributions } else if (strcasecmp(curr, kAllocRandom) == 0) {
284*5e3eaea3SApple OSS Distributions args->ta_alloc_type = VARIANT_RANDOM;
285*5e3eaea3SApple OSS Distributions } else if (strcasecmp(curr, kAllocTypical) == 0) {
286*5e3eaea3SApple OSS Distributions args->ta_alloc_type = VARIANT_TYPICAL;
287*5e3eaea3SApple OSS Distributions } else {
288*5e3eaea3SApple OSS Distributions print_help(argv);
289*5e3eaea3SApple OSS Distributions exit(kInvalidArgument);
290*5e3eaea3SApple OSS Distributions }
291*5e3eaea3SApple OSS Distributions } else if (current_positional_argument == 2) {
292*5e3eaea3SApple OSS Distributions duration = strtol(argv[current_argument], NULL, 10);
293*5e3eaea3SApple OSS Distributions if (duration <= 0) {
294*5e3eaea3SApple OSS Distributions print_help(argv);
295*5e3eaea3SApple OSS Distributions exit(kInvalidArgument);
296*5e3eaea3SApple OSS Distributions }
297*5e3eaea3SApple OSS Distributions } else if (current_positional_argument == 3) {
298*5e3eaea3SApple OSS Distributions size_mb = strtol(argv[current_argument], NULL, 10);
299*5e3eaea3SApple OSS Distributions if (size_mb <= 0) {
300*5e3eaea3SApple OSS Distributions print_help(argv);
301*5e3eaea3SApple OSS Distributions exit(kInvalidArgument);
302*5e3eaea3SApple OSS Distributions }
303*5e3eaea3SApple OSS Distributions } else {
304*5e3eaea3SApple OSS Distributions print_help(argv);
305*5e3eaea3SApple OSS Distributions exit(kInvalidArgument);
306*5e3eaea3SApple OSS Distributions }
307*5e3eaea3SApple OSS Distributions current_positional_argument++;
308*5e3eaea3SApple OSS Distributions }
309*5e3eaea3SApple OSS Distributions }
310*5e3eaea3SApple OSS Distributions if (current_positional_argument != 4) {
311*5e3eaea3SApple OSS Distributions fprintf(stderr, "Expected 4 positional arguments. %d were supplied.\n", current_positional_argument);
312*5e3eaea3SApple OSS Distributions print_help(argv);
313*5e3eaea3SApple OSS Distributions exit(kInvalidArgument);
314*5e3eaea3SApple OSS Distributions }
315*5e3eaea3SApple OSS Distributions args->ta_duration_seconds = (uint64_t) duration;
316*5e3eaea3SApple OSS Distributions args->ta_buffer_size = ((uint64_t) size_mb * (1UL << 20));
317*5e3eaea3SApple OSS Distributions }
318*5e3eaea3SApple OSS Distributions
319*5e3eaea3SApple OSS Distributions static void
print_help(const char ** argv)320*5e3eaea3SApple OSS Distributions print_help(const char** argv)
321*5e3eaea3SApple OSS Distributions {
322*5e3eaea3SApple OSS Distributions fprintf(stderr, "%s: [-v] <test-variant> allocation-type duration_seconds buffer_size_mb\n", argv[0]);
323*5e3eaea3SApple OSS Distributions fprintf(stderr, "\ntest variants:\n");
324*5e3eaea3SApple OSS Distributions fprintf(stderr, " %s Measure compressor throughput.\n", kCompressArgument);
325*5e3eaea3SApple OSS Distributions fprintf(stderr, " %s Measure compressor and decompressor throughput.\n", kCompressAndDecompressArgument);
326*5e3eaea3SApple OSS Distributions fprintf(stderr, "\n allocation types:\n");
327*5e3eaea3SApple OSS Distributions fprintf(stderr, " %s All zeros.\n", kAllocZeroes);
328*5e3eaea3SApple OSS Distributions fprintf(stderr, " %s Random bytes.\n", kAllocRandom);
329*5e3eaea3SApple OSS Distributions fprintf(stderr, " %s Typical compression ratio (~2.5:1).\n", kAllocTypical);
330*5e3eaea3SApple OSS Distributions }
331