From 90679884efa7bc277ced354032ca655e1e99faa2 Mon Sep 17 00:00:00 2001 From: Daniel Axtens Date: Fri, 10 Feb 2017 13:55:15 +1100 Subject: [PATCH] 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 --- include/isa_l/isa_l_common.h | 1 + src/backends/isa-l/isa_l_common.c | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/include/isa_l/isa_l_common.h b/include/isa_l/isa_l_common.h index caad19a..0445544 100644 --- a/include/isa_l/isa_l_common.h +++ b/include/isa_l/isa_l_common.h @@ -52,6 +52,7 @@ typedef struct { /* fields needed to hold state */ unsigned char *matrix; + unsigned char *encode_tables; int k; int m; int w; diff --git a/src/backends/isa-l/isa_l_common.c b/src/backends/isa-l/isa_l_common.c index b7fb05e..63e7cca 100644 --- a/src/backends/isa-l/isa_l_common.c +++ b/src/backends/isa-l/isa_l_common.c @@ -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);