ISA-L: Only calculate gf tables on init, not every encode
Currently, the Galois Field multiplication tables are recalcuated every time an encode is done. This is wasteful, as they are fixed by k and m, which is set on init. Calculate the tables only once, on init. This trades off a little bit of per-context memory and creation time for measurably faster encodes when using the same context. On powerpc64le, when repeatedly encoding a 4kB file with pyeclib, this increases the measured speed by over 10%. Change-Id: I2f025aaee2d13cb1717a331e443e179ad5a13302 Signed-off-by: Daniel Axtens <dja@axtens.net>
This commit is contained in:
parent
10e096fe09
commit
90679884ef
|
@ -52,6 +52,7 @@ typedef struct {
|
|||
|
||||
/* fields needed to hold state */
|
||||
unsigned char *matrix;
|
||||
unsigned char *encode_tables;
|
||||
int k;
|
||||
int m;
|
||||
int w;
|
||||
|
|
|
@ -41,22 +41,13 @@ int isa_l_encode(void *desc, char **data, char **parity,
|
|||
{
|
||||
isa_l_descriptor *isa_l_desc = (isa_l_descriptor*) desc;
|
||||
|
||||
unsigned char *g_tbls = NULL;
|
||||
unsigned char *g_tbls = isa_l_desc->encode_tables;
|
||||
int k = isa_l_desc->k;
|
||||
int m = isa_l_desc->m;
|
||||
|
||||
// Generate g_tbls from encode matrix encode_matrix
|
||||
g_tbls = malloc(sizeof(unsigned char) * (k * m * 32));
|
||||
if (NULL == g_tbls) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
isa_l_desc->ec_init_tables(k, m, &isa_l_desc->matrix[k * k], g_tbls);
|
||||
|
||||
/* FIXME - make ec_encode_data return a value */
|
||||
isa_l_desc->ec_encode_data(blocksize, k, m, g_tbls, (unsigned char**)data,
|
||||
(unsigned char**)parity);
|
||||
free(g_tbls);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -444,6 +435,7 @@ int isa_l_exit(void *desc)
|
|||
|
||||
isa_l_desc = (isa_l_descriptor*) desc;
|
||||
|
||||
free(isa_l_desc->encode_tables);
|
||||
free(isa_l_desc->matrix);
|
||||
free(isa_l_desc);
|
||||
|
||||
|
@ -536,8 +528,24 @@ void * isa_l_common_init(struct ec_backend_args *args, void *backend_sohandle,
|
|||
*/
|
||||
desc->gf_gen_encoding_matrix(desc->matrix, desc->k + desc->m, desc->k);
|
||||
|
||||
|
||||
/**
|
||||
* Generate the tables for encoding
|
||||
*/
|
||||
desc->encode_tables = malloc(sizeof(unsigned char) *
|
||||
(desc->k * desc->m * 32));
|
||||
if (NULL == desc->encode_tables) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
desc->ec_init_tables(desc->k, desc->m,
|
||||
&desc->matrix[desc->k * desc->k],
|
||||
desc->encode_tables);
|
||||
|
||||
return desc;
|
||||
|
||||
error_free:
|
||||
free(desc->matrix);
|
||||
error:
|
||||
free(desc);
|
||||
|
||||
|
|
Loading…
Reference in New Issue