]>
git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/erasure_code/erasure_code_perf.c
1 /**********************************************************************
2 Copyright(c) 2011-2015 Intel Corporation All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
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
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.
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 **********************************************************************/
32 #include <string.h> // for memset, memcmp
33 #include "erasure_code.h"
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"
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"
52 # define TEST_TYPE_STR "_cus"
54 # define TEST_LOOPS(m) 1000
59 #define MMAX TEST_SOURCES
60 #define KMAX TEST_SOURCES
62 typedef unsigned char u8
;
64 int main(int argc
, char *argv
[])
66 int i
, j
, rtest
, m
, k
, nerrs
, r
;
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
;
74 // Pick test parameters
78 const u8 err_list
[] = { 2, 4, 5, 7 };
80 printf("erasure_code_perf: %dx%d %d\n", m
, TEST_LEN(m
), nerrs
);
82 if (m
> MMAX
|| k
> KMAX
|| nerrs
> (m
- k
)) {
83 printf(" Input test parameter error\n");
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;
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");
101 for (i
= 0; i
< (m
- k
); i
++) {
102 if (posix_memalign(&buf
, 64, TEST_LEN(m
))) {
103 printf("alloc error: Fail\n");
110 for (i
= 0; i
< k
; i
++)
111 for (j
= 0; j
< TEST_LEN(m
); j
++)
112 buffs
[i
][j
] = rand();
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
]);
120 for (rtest
= 0; rtest
< TEST_LOOPS(m
); rtest
++) {
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
]);
126 printf("erasure_code_encode" TEST_TYPE_STR
": ");
127 perf_print(stop
, start
, (long long)(TEST_LEN(m
)) * (m
) * rtest
);
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
])
137 for (j
= 0; j
< k
; j
++)
138 b
[k
* i
+ j
] = a
[k
* r
+ j
];
141 if (gf_invert_matrix(b
, d
, k
) < 0) {
142 printf("BAD MATRIX\n");
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
];
151 ec_init_tables(k
, nerrs
, c
, g_tbls
);
152 ec_encode_data(TEST_LEN(m
), k
, nerrs
, g_tbls
, recov
, temp_buffs
);
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
);
163 printf("erasure_code_decode" TEST_TYPE_STR
": ");
164 perf_print(stop
, start
, (long long)(TEST_LEN(m
)) * (k
+ nerrs
) * rtest
);
166 printf("done all: Pass\n");