]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/erasure_code/erasure_code_perf.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / isa-l / erasure_code / erasure_code_perf.c
1 /**********************************************************************
2 Copyright(c) 2011-2015 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 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h> // for memset, memcmp
33 #include "erasure_code.h"
34 #include "test.h"
35
36 //#define CACHED_TEST
37 #ifdef CACHED_TEST
38 // Cached test, loop many times over small dataset
39 # define TEST_SOURCES 32
40 # define TEST_LEN(m) ((128*1024 / m) & ~(64-1))
41 # define TEST_LOOPS(m) (10000*m)
42 # define TEST_TYPE_STR "_warm"
43 #else
44 # ifndef TEST_CUSTOM
45 // Uncached test. Pull from large mem base.
46 # define TEST_SOURCES 32
47 # define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
48 # define TEST_LEN(m) ((GT_L3_CACHE / m) & ~(64-1))
49 # define TEST_LOOPS(m) (50*m)
50 # define TEST_TYPE_STR "_cold"
51 # else
52 # define TEST_TYPE_STR "_cus"
53 # ifndef TEST_LOOPS
54 # define TEST_LOOPS(m) 1000
55 # endif
56 # endif
57 #endif
58
59 #define MMAX TEST_SOURCES
60 #define KMAX TEST_SOURCES
61
62 typedef unsigned char u8;
63
64 int main(int argc, char *argv[])
65 {
66 int i, j, rtest, m, k, nerrs, r;
67 void *buf;
68 u8 *temp_buffs[TEST_SOURCES], *buffs[TEST_SOURCES];
69 u8 a[MMAX * KMAX], b[MMAX * KMAX], c[MMAX * KMAX], d[MMAX * KMAX];
70 u8 g_tbls[KMAX * TEST_SOURCES * 32], src_in_err[TEST_SOURCES];
71 u8 src_err_list[TEST_SOURCES], *recov[TEST_SOURCES];
72 struct perf start, stop;
73
74 // Pick test parameters
75 m = 14;
76 k = 10;
77 nerrs = 4;
78 const u8 err_list[] = { 2, 4, 5, 7 };
79
80 printf("erasure_code_perf: %dx%d %d\n", m, TEST_LEN(m), nerrs);
81
82 if (m > MMAX || k > KMAX || nerrs > (m - k)) {
83 printf(" Input test parameter error\n");
84 return -1;
85 }
86
87 memcpy(src_err_list, err_list, nerrs);
88 memset(src_in_err, 0, TEST_SOURCES);
89 for (i = 0; i < nerrs; i++)
90 src_in_err[src_err_list[i]] = 1;
91
92 // Allocate the arrays
93 for (i = 0; i < m; i++) {
94 if (posix_memalign(&buf, 64, TEST_LEN(m))) {
95 printf("alloc error: Fail\n");
96 return -1;
97 }
98 buffs[i] = buf;
99 }
100
101 for (i = 0; i < (m - k); i++) {
102 if (posix_memalign(&buf, 64, TEST_LEN(m))) {
103 printf("alloc error: Fail\n");
104 return -1;
105 }
106 temp_buffs[i] = buf;
107 }
108
109 // Make random data
110 for (i = 0; i < k; i++)
111 for (j = 0; j < TEST_LEN(m); j++)
112 buffs[i][j] = rand();
113
114 gf_gen_rs_matrix(a, m, k);
115 ec_init_tables(k, m - k, &a[k * k], g_tbls);
116 ec_encode_data(TEST_LEN(m), k, m - k, g_tbls, buffs, &buffs[k]);
117
118 // Start encode test
119 perf_start(&start);
120 for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) {
121 // Make parity vects
122 ec_init_tables(k, m - k, &a[k * k], g_tbls);
123 ec_encode_data(TEST_LEN(m), k, m - k, g_tbls, buffs, &buffs[k]);
124 }
125 perf_stop(&stop);
126 printf("erasure_code_encode" TEST_TYPE_STR ": ");
127 perf_print(stop, start, (long long)(TEST_LEN(m)) * (m) * rtest);
128
129 // Start decode test
130 perf_start(&start);
131 for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) {
132 // Construct b by removing error rows
133 for (i = 0, r = 0; i < k; i++, r++) {
134 while (src_in_err[r])
135 r++;
136 recov[i] = buffs[r];
137 for (j = 0; j < k; j++)
138 b[k * i + j] = a[k * r + j];
139 }
140
141 if (gf_invert_matrix(b, d, k) < 0) {
142 printf("BAD MATRIX\n");
143 return -1;
144 }
145
146 for (i = 0; i < nerrs; i++)
147 for (j = 0; j < k; j++)
148 c[k * i + j] = d[k * src_err_list[i] + j];
149
150 // Recover data
151 ec_init_tables(k, nerrs, c, g_tbls);
152 ec_encode_data(TEST_LEN(m), k, nerrs, g_tbls, recov, temp_buffs);
153 }
154 perf_stop(&stop);
155
156 for (i = 0; i < nerrs; i++) {
157 if (0 != memcmp(temp_buffs[i], buffs[src_err_list[i]], TEST_LEN(m))) {
158 printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs);
159 return -1;
160 }
161 }
162
163 printf("erasure_code_decode" TEST_TYPE_STR ": ");
164 perf_print(stop, start, (long long)(TEST_LEN(m)) * (k + nerrs) * rtest);
165
166 printf("done all: Pass\n");
167 return 0;
168 }