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