]>
git.proxmox.com Git - ceph.git/blob - ceph/src/erasure-code/jerasure/jerasure/Examples/reed_sol_time_gf.c
2 * Copyright (c) 2014, James S. Plank and Kevin Greenan
5 * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
8 * Revision 2.0: Galois Field backend now links to GF-Complete
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * - Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
22 * - Neither the name of the University of Tennessee nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
33 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
34 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
36 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
40 /* Jerasure's authors:
42 Revision 2.x - 2014: James S. Plank and Kevin M. Greenan.
43 Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
44 Revision 1.0 - 2007: James S. Plank.
50 #include <gf_complete.h>
52 #include <gf_method.h>
57 static void * malloc16 ( int size
) {
58 void * mem
= malloc ( size
+ 16 + sizeof ( void *));
59 void ** ptr
= ( void **)(( long )( mem
+ 16 + sizeof ( void *)) & ~( 15 ));
64 static void free16 ( void * ptr
) {
65 free ((( void **) ptr
)[- 1 ]);
68 #define talloc(type, num) (type *) malloc16(sizeof(type)*(num))
71 timer_start ( double * t
)
75 gettimeofday (& tv
, NULL
);
76 * t
= ( double ) tv
. tv_sec
+ ( double ) tv
. tv_usec
* 1e-6 ;
80 timer_split ( const double * t
)
85 gettimeofday (& tv
, NULL
);
86 cur_t
= ( double ) tv
. tv_sec
+ ( double ) tv
. tv_usec
* 1e-6 ;
92 fprintf ( stderr
, "usage: reed_sol_time_gf k m w seed iterations bufsize (additional GF args) - Test and time Reed-Solomon in a particular GF(2^w). \n " );
93 fprintf ( stderr
, " \n " );
94 fprintf ( stderr
, " w must be 8, 16 or 32. k+m must be <= 2^w. \n " );
95 fprintf ( stderr
, " See the README for information on the additional GF args. \n " );
96 fprintf ( stderr
, " Set up a Vandermonde-based distribution matrix and encodes k devices of \n " );
97 fprintf ( stderr
, " bufsize bytes each with it. Then it decodes. \n " );
98 fprintf ( stderr
, " \n " );
99 fprintf ( stderr
, "This tests: jerasure_matrix_encode() \n " );
100 fprintf ( stderr
, " jerasure_matrix_decode() \n " );
101 fprintf ( stderr
, " jerasure_print_matrix() \n " );
102 fprintf ( stderr
, " galois_change_technique() \n " );
103 fprintf ( stderr
, " reed_sol_vandermonde_coding_matrix() \n " );
104 if ( s
!= NULL
) fprintf ( stderr
, "%s \n " , s
);
108 gf_t
* get_gf ( int w
, int argc
, char ** argv
, int starting
)
110 gf_t
* gf
= ( gf_t
*) malloc ( sizeof ( gf_t
));
111 if ( create_gf_from_argv ( gf
, w
, argc
, argv
, starting
) == 0 ) {
118 int main ( int argc
, char ** argv
)
121 int k
, w
, i
, j
, m
, iterations
, bufsize
;
123 char ** data
, ** coding
, ** old_values
;
124 int * erasures
, * erased
;
125 int * decoding_matrix
, * dm_ids
;
127 double t
= 0 , total_time
= 0 ;
130 if ( argc
< 8 ) usage ( NULL
);
131 if ( sscanf ( argv
[ 1 ], "%d" , & k
) == 0 || k
<= 0 ) usage ( "Bad k" );
132 if ( sscanf ( argv
[ 2 ], "%d" , & m
) == 0 || m
<= 0 ) usage ( "Bad m" );
133 if ( sscanf ( argv
[ 3 ], "%d" , & w
) == 0 || ( w
!= 8 && w
!= 16 && w
!= 32 )) usage ( "Bad w" );
134 if ( sscanf ( argv
[ 4 ], "%d" , & seed
) == 0 ) usage ( "Bad seed" );
135 if ( sscanf ( argv
[ 5 ], "%d" , & iterations
) == 0 ) usage ( "Bad iterations" );
136 if ( sscanf ( argv
[ 6 ], "%d" , & bufsize
) == 0 ) usage ( "Bad bufsize" );
137 if ( w
<= 16 && k
+ m
> ( 1 << w
)) usage ( "k + m is too big" );
141 gf
= get_gf ( w
, argc
, argv
, 7 );
144 usage ( "Invalid arguments given for GF! \n " );
147 galois_change_technique ( gf
, w
);
149 matrix
= reed_sol_vandermonde_coding_matrix ( k
, m
, w
);
151 printf ( "<HTML><TITLE>reed_sol_time_gf" );
152 for ( i
= 1 ; i
< argc
; i
++) printf ( " %s" , argv
[ i
]);
153 printf ( "</TITLE> \n " );
154 printf ( "<h3>reed_sol_time_gf" );
155 for ( i
= 1 ; i
< argc
; i
++) printf ( " %s" , argv
[ i
]);
159 printf ( "Last m rows of the generator matrix (G^T): \n\n " );
160 jerasure_print_matrix ( matrix
, m
, k
, w
);
163 data
= talloc ( char *, k
);
164 for ( i
= 0 ; i
< k
; i
++) {
165 data
[ i
] = talloc ( char , bufsize
);
166 MOA_Fill_Random_Region ( data
[ i
], bufsize
);
169 coding
= talloc ( char *, m
);
170 old_values
= talloc ( char *, m
);
171 for ( i
= 0 ; i
< m
; i
++) {
172 coding
[ i
] = talloc ( char , bufsize
);
173 old_values
[ i
] = talloc ( char , bufsize
);
176 for ( i
= 0 ; i
< iterations
; i
++) {
178 jerasure_matrix_encode ( k
, m
, w
, matrix
, data
, coding
, bufsize
);
179 total_time
+= timer_split (& t
);
182 printf ( "Encode throughput for %d iterations: %.2f MB/s (%.2f sec) \n " , iterations
, ( double )( k
* iterations
* bufsize
/ 1024 / 1024 ) / total_time
, total_time
);
184 erasures
= talloc ( int , ( m
+ 1 ));
185 erased
= talloc ( int , ( k
+ m
));
186 for ( i
= 0 ; i
< m
+ k
; i
++) erased
[ i
] = 0 ;
188 for ( i
= 0 ; i
< m
; ) {
189 erasures
[ i
] = (( unsigned int ) MOA_Random_W ( w
, 1 ))%( k
+ m
);
190 if ( erased
[ erasures
[ i
]] == 0 ) {
191 erased
[ erasures
[ i
]] = 1 ;
192 memcpy ( old_values
[ i
], ( erasures
[ i
] < k
) ? data
[ erasures
[ i
]] : coding
[ erasures
[ i
]- k
], bufsize
);
193 bzero (( erasures
[ i
] < k
) ? data
[ erasures
[ i
]] : coding
[ erasures
[ i
]- k
], bufsize
);
199 for ( i
= 0 ; i
< iterations
; i
++) {
201 jerasure_matrix_decode ( k
, m
, w
, matrix
, 1 , erasures
, data
, coding
, bufsize
);
202 total_time
+= timer_split (& t
);
205 printf ( "Decode throughput for %d iterations: %.2f MB/s (%.2f sec) \n " , iterations
, ( double )( k
* iterations
* bufsize
/ 1024 / 1024 ) / total_time
, total_time
);
207 for ( i
= 0 ; i
< m
; i
++) {
208 if ( erasures
[ i
] < k
) {
209 if ( memcmp ( data
[ erasures
[ i
]], old_values
[ i
], bufsize
)) {
210 fprintf ( stderr
, "Decoding failed for %d! \n " , erasures
[ i
]);
214 if ( memcmp ( coding
[ erasures
[ i
]- k
], old_values
[ i
], bufsize
)) {
215 fprintf ( stderr
, "Decoding failed for %d! \n " , erasures
[ i
]);