]> git.proxmox.com Git - ceph.git/blame - ceph/src/isa-l/erasure_code/erasure_code_perf.c
Import ceph 15.2.8
[ceph.git] / ceph / src / isa-l / erasure_code / erasure_code_perf.c
CommitLineData
7c673cae
FG
1/**********************************************************************
2 Copyright(c) 2011-2015 Intel Corporation All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
f91f0fd5 5 modification, are permitted provided that the following conditions
7c673cae
FG
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))
7c673cae
FG
41# define TEST_TYPE_STR "_warm"
42#else
43# ifndef TEST_CUSTOM
44// Uncached test. Pull from large mem base.
45# define TEST_SOURCES 32
46# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
47# define TEST_LEN(m) ((GT_L3_CACHE / m) & ~(64-1))
7c673cae
FG
48# define TEST_TYPE_STR "_cold"
49# else
50# define TEST_TYPE_STR "_cus"
7c673cae
FG
51# endif
52#endif
53
54#define MMAX TEST_SOURCES
55#define KMAX TEST_SOURCES
56
f91f0fd5
TL
57#define BAD_MATRIX -1
58
7c673cae
FG
59typedef unsigned char u8;
60
f91f0fd5
TL
61void ec_encode_perf(int m, int k, u8 * a, u8 * g_tbls, u8 ** buffs, struct perf *start)
62{
63 ec_init_tables(k, m - k, &a[k * k], g_tbls);
64 BENCHMARK(start, BENCHMARK_TIME,
65 ec_encode_data(TEST_LEN(m), k, m - k, g_tbls, buffs, &buffs[k]));
66}
67
68int ec_decode_perf(int m, int k, u8 * a, u8 * g_tbls, u8 ** buffs, u8 * src_in_err,
69 u8 * src_err_list, int nerrs, u8 ** temp_buffs, struct perf *start)
70{
71 int i, j, r;
72 u8 b[MMAX * KMAX], c[MMAX * KMAX], d[MMAX * KMAX];
73 u8 *recov[TEST_SOURCES];
74
75 // Construct b by removing error rows
76 for (i = 0, r = 0; i < k; i++, r++) {
77 while (src_in_err[r])
78 r++;
79 recov[i] = buffs[r];
80 for (j = 0; j < k; j++)
81 b[k * i + j] = a[k * r + j];
82 }
83
84 if (gf_invert_matrix(b, d, k) < 0)
85 return BAD_MATRIX;
86
87 for (i = 0; i < nerrs; i++)
88 for (j = 0; j < k; j++)
89 c[k * i + j] = d[k * src_err_list[i] + j];
90
91 // Recover data
92 ec_init_tables(k, nerrs, c, g_tbls);
93 BENCHMARK(start, BENCHMARK_TIME,
94 ec_encode_data(TEST_LEN(m), k, nerrs, g_tbls, recov, temp_buffs));
95
96 return 0;
97}
98
7c673cae
FG
99int main(int argc, char *argv[])
100{
f91f0fd5 101 int i, j, m, k, nerrs, check;
7c673cae
FG
102 void *buf;
103 u8 *temp_buffs[TEST_SOURCES], *buffs[TEST_SOURCES];
f91f0fd5 104 u8 a[MMAX * KMAX];
7c673cae 105 u8 g_tbls[KMAX * TEST_SOURCES * 32], src_in_err[TEST_SOURCES];
f91f0fd5
TL
106 u8 src_err_list[TEST_SOURCES];
107 struct perf start;
7c673cae
FG
108
109 // Pick test parameters
110 m = 14;
111 k = 10;
112 nerrs = 4;
113 const u8 err_list[] = { 2, 4, 5, 7 };
114
115 printf("erasure_code_perf: %dx%d %d\n", m, TEST_LEN(m), nerrs);
116
117 if (m > MMAX || k > KMAX || nerrs > (m - k)) {
118 printf(" Input test parameter error\n");
119 return -1;
120 }
121
122 memcpy(src_err_list, err_list, nerrs);
123 memset(src_in_err, 0, TEST_SOURCES);
124 for (i = 0; i < nerrs; i++)
125 src_in_err[src_err_list[i]] = 1;
126
127 // Allocate the arrays
128 for (i = 0; i < m; i++) {
129 if (posix_memalign(&buf, 64, TEST_LEN(m))) {
130 printf("alloc error: Fail\n");
131 return -1;
132 }
133 buffs[i] = buf;
134 }
135
136 for (i = 0; i < (m - k); i++) {
137 if (posix_memalign(&buf, 64, TEST_LEN(m))) {
138 printf("alloc error: Fail\n");
139 return -1;
140 }
141 temp_buffs[i] = buf;
142 }
143
144 // Make random data
145 for (i = 0; i < k; i++)
146 for (j = 0; j < TEST_LEN(m); j++)
147 buffs[i][j] = rand();
148
149 gf_gen_rs_matrix(a, m, k);
7c673cae
FG
150
151 // Start encode test
f91f0fd5 152 ec_encode_perf(m, k, a, g_tbls, buffs, &start);
7c673cae 153 printf("erasure_code_encode" TEST_TYPE_STR ": ");
f91f0fd5 154 perf_print(start, (long long)(TEST_LEN(m)) * (m));
7c673cae
FG
155
156 // Start decode test
f91f0fd5
TL
157 check = ec_decode_perf(m, k, a, g_tbls, buffs, src_in_err, src_err_list, nerrs,
158 temp_buffs, &start);
7c673cae 159
f91f0fd5
TL
160 if (check == BAD_MATRIX) {
161 printf("BAD MATRIX\n");
162 return check;
7c673cae 163 }
7c673cae
FG
164
165 for (i = 0; i < nerrs; i++) {
166 if (0 != memcmp(temp_buffs[i], buffs[src_err_list[i]], TEST_LEN(m))) {
167 printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs);
168 return -1;
169 }
170 }
171
172 printf("erasure_code_decode" TEST_TYPE_STR ": ");
f91f0fd5 173 perf_print(start, (long long)(TEST_LEN(m)) * (k + nerrs));
7c673cae
FG
174
175 printf("done all: Pass\n");
176 return 0;
177}