Use BLAKE2 parallel version for single-chunk archives (whole file in one chunk).

Set decompression threads correctly for single-chunk archives.
This commit is contained in:
Moinak Ghosh 2013-01-26 18:28:13 +05:30
parent 68f60ba50b
commit 2da0d0950b
5 changed files with 35 additions and 13 deletions

View file

@ -164,7 +164,7 @@ PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
#endif #endif
int int
compute_checksum(uchar_t *cksum_buf, int cksum, uchar_t *buf, uint64_t bytes) compute_checksum(uchar_t *cksum_buf, int cksum, uchar_t *buf, uint64_t bytes, int mt)
{ {
DEBUG_STAT_EN(double strt, en); DEBUG_STAT_EN(double strt, en);
@ -174,12 +174,22 @@ compute_checksum(uchar_t *cksum_buf, int cksum, uchar_t *buf, uint64_t bytes)
*ck = lzma_crc64(buf, bytes, 0); *ck = lzma_crc64(buf, bytes, 0);
} else if (cksum == CKSUM_BLAKE256) { } else if (cksum == CKSUM_BLAKE256) {
if (bdsp.blake2b(cksum_buf, buf, NULL, 32, bytes, 0) != 0) if (!mt) {
return (-1); if (bdsp.blake2b(cksum_buf, buf, NULL, 32, bytes, 0) != 0)
return (-1);
} else {
if (bdsp.blake2bp(cksum_buf, buf, NULL, 32, bytes, 0) != 0)
return (-1);
}
} else if (cksum == CKSUM_BLAKE512) { } else if (cksum == CKSUM_BLAKE512) {
if (bdsp.blake2b(cksum_buf, buf, NULL, 64, bytes, 0) != 0) if (!mt) {
return (-1); if (bdsp.blake2b(cksum_buf, buf, NULL, 64, bytes, 0) != 0)
return (-1);
} else {
if (bdsp.blake2bp(cksum_buf, buf, NULL, 64, bytes, 0) != 0)
return (-1);
}
} else if (cksum == CKSUM_SKEIN256) { } else if (cksum == CKSUM_SKEIN256) {
Skein_512_Ctxt_t ctx; Skein_512_Ctxt_t ctx;
@ -683,10 +693,10 @@ init_crypto(crypto_ctx_t *cctx, uchar_t *pwd, int pwd_len, int crypto_alg,
b += 4; b += 4;
*((uint32_t *)&sb[b]) = getpid(); *((uint32_t *)&sb[b]) = getpid();
b += 4; b += 4;
compute_checksum(&sb[b], CKSUM_SHA256, sb, b); compute_checksum(&sb[b], CKSUM_SHA256, sb, b, 0);
b = 8 + 4; b = 8 + 4;
*((uint32_t *)&sb[b]) = rand(); *((uint32_t *)&sb[b]) = rand();
compute_checksum(salt, CKSUM_SHA256, &sb[b], 32 + 4); compute_checksum(salt, CKSUM_SHA256, &sb[b], 32 + 4, 0);
} }
} }

View file

@ -81,7 +81,7 @@ typedef struct {
/* /*
* Generic message digest functions. * Generic message digest functions.
*/ */
int compute_checksum(uchar_t *cksum_buf, int cksum, uchar_t *buf, uint64_t bytes); int compute_checksum(uchar_t *cksum_buf, int cksum, uchar_t *buf, uint64_t bytes, int mt);
void list_checksums(FILE *strm, char *pad); void list_checksums(FILE *strm, char *pad);
int get_checksum_props(const char *name, int *cksum, int *cksum_bytes, int get_checksum_props(const char *name, int *cksum, int *cksum_bytes,
int *mac_bytes, int accept_compatible); int *mac_bytes, int accept_compatible);

View file

@ -67,7 +67,7 @@ libbsc_stats(int show)
} }
/* /*
* BSC uses OpenMP where it is tricky to control thread count * BSC uses OpenMP where it does not control thread count
* deterministically. We only use multithread capability in BSC * deterministically. We only use multithread capability in BSC
* when compressing entire file in a single chunk. * when compressing entire file in a single chunk.
*/ */

18
main.c
View file

@ -572,7 +572,7 @@ redo:
* If it does not match we set length of chunk to 0 to indicate * If it does not match we set length of chunk to 0 to indicate
* exit to the writer thread. * exit to the writer thread.
*/ */
compute_checksum(checksum, cksum, tdat->uncompressed_chunk, _chunksize); compute_checksum(checksum, cksum, tdat->uncompressed_chunk, _chunksize, tdat->cksum_mt);
if (memcmp(checksum, tdat->checksum, cksum_bytes) != 0) { if (memcmp(checksum, tdat->checksum, cksum_bytes) != 0) {
tdat->len_cmp = 0; tdat->len_cmp = 0;
fprintf(stderr, "ERROR: Chunk %d, checksums do not match.\n", tdat->id); fprintf(stderr, "ERROR: Chunk %d, checksums do not match.\n", tdat->id);
@ -937,6 +937,8 @@ start_decompress(const char *filename, const char *to_filename)
nthreads = nprocs; nthreads = nprocs;
set_threadcounts(&props, &nthreads, nprocs, DECOMPRESS_THREADS); set_threadcounts(&props, &nthreads, nprocs, DECOMPRESS_THREADS);
if (props.is_single_chunk)
nthreads = 1;
fprintf(stderr, "Scaling to %d thread", nthreads * props.nthreads); fprintf(stderr, "Scaling to %d thread", nthreads * props.nthreads);
if (nthreads * props.nthreads > 1) fprintf(stderr, "s"); if (nthreads * props.nthreads > 1) fprintf(stderr, "s");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
@ -959,6 +961,10 @@ start_decompress(const char *filename, const char *to_filename)
tdat->compress = _compress_func; tdat->compress = _compress_func;
tdat->decompress = _decompress_func; tdat->decompress = _decompress_func;
tdat->cancel = 0; tdat->cancel = 0;
if (props.is_single_chunk)
tdat->cksum_mt = 1;
else
tdat->cksum_mt = 0;
tdat->level = level; tdat->level = level;
tdat->data = NULL; tdat->data = NULL;
tdat->props = &props; tdat->props = &props;
@ -1196,7 +1202,8 @@ redo:
* back into cmp_seg. Avoids an extra memcpy(). * back into cmp_seg. Avoids an extra memcpy().
*/ */
if (!encrypt_type) if (!encrypt_type)
compute_checksum(tdat->checksum, cksum, tdat->cmp_seg, tdat->rbytes); compute_checksum(tdat->checksum, cksum, tdat->cmp_seg, tdat->rbytes,
tdat->cksum_mt);
rctx = tdat->rctx; rctx = tdat->rctx;
reset_dedupe_context(tdat->rctx); reset_dedupe_context(tdat->rctx);
@ -1211,7 +1218,8 @@ redo:
* Compute checksum of original uncompressed chunk. * Compute checksum of original uncompressed chunk.
*/ */
if (!encrypt_type) if (!encrypt_type)
compute_checksum(tdat->checksum, cksum, tdat->uncompressed_chunk, tdat->rbytes); compute_checksum(tdat->checksum, cksum, tdat->uncompressed_chunk,
tdat->rbytes, tdat->cksum_mt);
} }
/* /*
@ -1692,6 +1700,10 @@ start_compress(const char *filename, uint64_t chunksize, int level)
tdat->decompress = _decompress_func; tdat->decompress = _decompress_func;
tdat->uncompressed_chunk = (uchar_t *)1; tdat->uncompressed_chunk = (uchar_t *)1;
tdat->cancel = 0; tdat->cancel = 0;
if (single_chunk)
tdat->cksum_mt = 1;
else
tdat->cksum_mt = 0;
tdat->level = level; tdat->level = level;
tdat->data = NULL; tdat->data = NULL;
tdat->props = &props; tdat->props = &props;

View file

@ -184,7 +184,7 @@ struct cmp_data {
uint64_t chunksize; uint64_t chunksize;
uint64_t len_cmp, len_cmp_be; uint64_t len_cmp, len_cmp_be;
uchar_t checksum[CKSUM_MAX_BYTES]; uchar_t checksum[CKSUM_MAX_BYTES];
int level; int level, cksum_mt;
unsigned int id; unsigned int id;
compress_func_ptr compress; compress_func_ptr compress;
compress_func_ptr decompress; compress_func_ptr decompress;