diff options
author | Tushar Gohad <tushar.gohad@intel.com> | 2014-07-17 15:29:33 -0700 |
---|---|---|
committer | Tushar Gohad <tushar.gohad@intel.com> | 2014-07-17 15:29:33 -0700 |
commit | dee9ece2f7c91f873992c565466a711ed4518b94 (patch) | |
tree | 6a1cd8786702fea53877c515ee94895bbfc2c79c /src/erasurecode_helpers.c | |
parent | e30f788f9ad41cc0fa5a4599edbf4c8b1b9a25f7 (diff) | |
download | liberasurecode-dee9ece2f7c91f873992c565466a711ed4518b94.tar.gz |
Add get_aligned_data_size() to ec helpers
Signed-off-by: Tushar Gohad <tushar.gohad@intel.com>
Diffstat (limited to 'src/erasurecode_helpers.c')
-rw-r--r-- | src/erasurecode_helpers.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/erasurecode_helpers.c b/src/erasurecode_helpers.c index a851efd..d4a1949 100644 --- a/src/erasurecode_helpers.c +++ b/src/erasurecode_helpers.c @@ -26,7 +26,9 @@ * vi: set noai tw=79 ts=4 sw=4: */ +#include "erasurecode_backend.h" #include "erasurecode_helpers.h" +#include "erasurecode_stdinc.h" /* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */ @@ -84,6 +86,41 @@ int free_fragment_buffer(char *buf) /* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */ +/** + * Compute a size aligned to the number of data and the underlying wordsize + * of the EC algorithm. + * + * @param instance, ec_backend_t instance (to extract args) + * @param data_len, integer length of data in bytes + * @return integer data length aligned with wordsize of EC algorithm + */ +int get_aligned_data_size(ec_backend_t instance, int data_len) +{ + int k = instance->args.uargs.k; + int m = instance->args.uargs.m; + int w = instance->args.uargs.w; + int word_size = w / 8; + int alignment_multiple; + int aligned_size = 0; + + /* + * For Cauchy reed-solomon align to k*word_size*packet_size + * For Vandermonde reed-solomon and flat-XOR, align to k*word_size + */ + if (instance->common.id == EC_BACKEND_JERASURE_RS_CAUCHY) { + alignment_multiple = k * w * (sizeof(long) * 128); + } else { + alignment_multiple = k * word_size; + } + + aligned_size = (int) + ceill((double) data_len / alignment_multiple) * alignment_multiple; + + return aligned_size; +} + +/* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */ + char *get_data_ptr_from_fragment(char *buf) { buf += sizeof(fragment_header_t); |