]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/isa-l/igzip/igzip_stateless_file_perf.c
bump version to 15.2.11-pve1
[ceph.git] / ceph / src / spdk / isa-l / igzip / igzip_stateless_file_perf.c
CommitLineData
9f95a23c
TL
1/**********************************************************************
2 Copyright(c) 2011-2016 Intel Corporation All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
12 distribution.
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28**********************************************************************/
29
30#define _FILE_OFFSET_BITS 64
31#include <stdio.h>
32#include <stdlib.h>
33#include <assert.h>
34#include <string.h>
35#include <getopt.h>
36#include "igzip_lib.h"
37#include "test.h"
38
39#define BUF_SIZE 1024
40#define MIN_TEST_LOOPS 10
41#ifndef RUN_MEM_SIZE
42# define RUN_MEM_SIZE 500000000
43#endif
44
45int level_size_buf[10] = {
46#ifdef ISAL_DEF_LVL0_DEFAULT
47 ISAL_DEF_LVL0_DEFAULT,
48#else
49 0,
50#endif
51#ifdef ISAL_DEF_LVL1_DEFAULT
52 ISAL_DEF_LVL1_DEFAULT,
53#else
54 0,
55#endif
56#ifdef ISAL_DEF_LVL2_DEFAULT
57 ISAL_DEF_LVL2_DEFAULT,
58#else
59 0,
60#endif
61#ifdef ISAL_DEF_LVL3_DEFAULT
62 ISAL_DEF_LVL3_DEFAULT,
63#else
64 0,
65#endif
66#ifdef ISAL_DEF_LVL4_DEFAULT
67 ISAL_DEF_LVL4_DEFAULT,
68#else
69 0,
70#endif
71#ifdef ISAL_DEF_LVL5_DEFAULT
72 ISAL_DEF_LVL5_DEFAULT,
73#else
74 0,
75#endif
76#ifdef ISAL_DEF_LVL6_DEFAULT
77 ISAL_DEF_LVL6_DEFAULT,
78#else
79 0,
80#endif
81#ifdef ISAL_DEF_LVL7_DEFAULT
82 ISAL_DEF_LVL7_DEFAULT,
83#else
84 0,
85#endif
86#ifdef ISAL_DEF_LVL8_DEFAULT
87 ISAL_DEF_LVL8_DEFAULT,
88#else
89 0,
90#endif
91#ifdef ISAL_DEF_LVL9_DEFAULT
92 ISAL_DEF_LVL9_DEFAULT,
93#else
94 0,
95#endif
96};
97
98struct isal_zstream stream;
99
100int usage(void)
101{
102 fprintf(stderr,
103 "Usage: igzip_stateless_file_perf [options] <infile>\n"
104 " -h help\n"
105 " -X use compression level X with 0 <= X <= 2\n"
106 " -i <iter> number of iterations (at least 1)\n"
107 " -o <file> output file for compresed data\n"
108 " -w <size> log base 2 size of history window, between 8 and 15\n");
109 exit(0);
110}
111
112int main(int argc, char *argv[])
113{
114 FILE *in = NULL, *out = NULL;
115 unsigned char *inbuf, *outbuf, *level_buf = NULL;
116 int i, c, iterations = 0;
117 uint64_t infile_size, outbuf_size;
118 struct isal_huff_histogram histogram;
119 struct isal_hufftables hufftables_custom;
120 int level = 0, level_size = 0;
121 char *in_file_name = NULL, *out_file_name = NULL;
122 uint32_t hist_bits = 0;
123
124 while ((c = getopt(argc, argv, "h0123456789i:o:w:")) != -1) {
125 if (c >= '0' && c <= '9') {
126 if (c > '0' + ISAL_DEF_MAX_LEVEL)
127 usage();
128 else {
129 level = c - '0';
130 level_size = level_size_buf[level];
131 }
132 continue;
133 }
134
135 switch (c) {
136 case 'o':
137 out_file_name = optarg;
138 break;
139 case 'i':
140 iterations = atoi(optarg);
141 if (iterations < 1)
142 usage();
143 break;
144 case 'w':
145 hist_bits = atoi(optarg);
146 if (hist_bits > 15 || hist_bits < 8)
147 usage();
148 break;
149 case 'h':
150 default:
151 usage();
152 break;
153 }
154 }
155
156 if (optind < argc) {
157 in_file_name = argv[optind];
158 in = fopen(in_file_name, "rb");
159 } else
160 usage();
161
162 if (!in) {
163 fprintf(stderr, "Can't open %s for reading\n", in_file_name);
164 exit(0);
165 }
166 if (out_file_name != NULL) {
167 out = fopen(out_file_name, "wb");
168 if (!out) {
169 fprintf(stderr, "Can't open %s for writing\n", out_file_name);
170 exit(0);
171 }
172 printf("outfile=%s\n", out_file_name);
173 }
174
175 if (hist_bits == 0)
176 printf("Window Size: %d K\n", IGZIP_HIST_SIZE / 1024);
177
178 else if (hist_bits < 10)
179 printf("Window Size: %.2f K\n", 1.0 * (1 << hist_bits) / 1024);
180 else
181 printf("Window Size: %d K\n", (1 << hist_bits) / 1024);
182
183 printf("igzip_file_perf: \n");
184 fflush(0);
185 /* Allocate space for entire input file and output
186 * (assuming some possible expansion on output size)
187 */
188 infile_size = get_filesize(in);
189
190 outbuf_size = infile_size * 1.07 + BUF_SIZE;
191
192 if (iterations == 0) {
193 iterations = infile_size ? RUN_MEM_SIZE / infile_size : MIN_TEST_LOOPS;
194 if (iterations < MIN_TEST_LOOPS)
195 iterations = MIN_TEST_LOOPS;
196 }
197
198 inbuf = malloc(infile_size);
199 if (inbuf == NULL) {
200 fprintf(stderr, "Can't allocate input buffer memory\n");
201 exit(0);
202 }
203 outbuf = malloc(outbuf_size);
204 if (outbuf == NULL) {
205 fprintf(stderr, "Can't allocate output buffer memory\n");
206 exit(0);
207 }
208
209 if (level_size != 0) {
210 level_buf = malloc(level_size);
211 if (level_buf == NULL) {
212 fprintf(stderr, "Can't allocate level buffer memory\n");
213 exit(0);
214 }
215 }
216
217 printf("igzip_file_perf: %s %d iterations\n", in_file_name, iterations);
218 /* Read complete input file into buffer */
219 stream.avail_in = (uint32_t) fread(inbuf, 1, infile_size, in);
220 if (stream.avail_in != infile_size) {
221 fprintf(stderr, "Couldn't fit all of input file into buffer\n");
222 exit(0);
223 }
224
225 struct perf start, stop;
226 perf_start(&start);
227
228 for (i = 0; i < iterations; i++) {
229 isal_deflate_init(&stream);
230 stream.end_of_stream = 1; /* Do the entire file at once */
231 stream.flush = NO_FLUSH;
232 stream.next_in = inbuf;
233 stream.avail_in = infile_size;
234 stream.next_out = outbuf;
235 stream.avail_out = outbuf_size;
236 stream.level = level;
237 stream.level_buf = level_buf;
238 stream.level_buf_size = level_size;
239 stream.hist_bits = hist_bits;
240 isal_deflate_stateless(&stream);
241 if (stream.avail_in != 0)
242 break;
243 }
244 perf_stop(&stop);
245
246 if (stream.avail_in != 0) {
247 fprintf(stderr, "Could not compress all of inbuf\n");
248 exit(0);
249 }
250
251 printf(" file %s - in_size=%lu out_size=%d iter=%d ratio=%3.1f%%", in_file_name,
252 infile_size, stream.total_out, i, 100.0 * stream.total_out / infile_size);
253
254 if (level == 0) {
255 memset(&histogram, 0, sizeof(histogram));
256
257 isal_update_histogram(inbuf, infile_size, &histogram);
258 isal_create_hufftables(&hufftables_custom, &histogram);
259
260 isal_deflate_init(&stream);
261 stream.end_of_stream = 1; /* Do the entire file at once */
262 stream.flush = NO_FLUSH;
263 stream.next_in = inbuf;
264 stream.avail_in = infile_size;
265 stream.next_out = outbuf;
266 stream.avail_out = outbuf_size;
267 stream.level = level;
268 stream.level_buf = level_buf;
269 stream.level_buf_size = level_size;
270 stream.hufftables = &hufftables_custom;
271 stream.hist_bits = hist_bits;
272 isal_deflate_stateless(&stream);
273
274 printf(" ratio_custom=%3.1f%%", 100.0 * stream.total_out / infile_size);
275 }
276 printf("\n");
277
278 printf("igzip_file: ");
279 perf_print(stop, start, (long long)infile_size * i);
280
281 if (argc > 2 && out) {
282 printf("writing %s\n", out_file_name);
283 fwrite(outbuf, 1, stream.total_out, out);
284 fclose(out);
285 }
286
287 fclose(in);
288 printf("End of igzip_file_perf\n\n");
289 fflush(0);
290 return 0;
291}