bench correctly measures time for multi-threaded compression (posix only)

This commit is contained in:
Yann Collet
2016-12-31 03:31:26 +01:00
parent f765a375a5
commit c6a6417458
3 changed files with 32 additions and 19 deletions
+5 -9
View File
@@ -60,9 +60,8 @@ static void *POOL_thread(void *opaque) {
if (pthread_mutex_unlock(&ctx->queueMutex)) { return NULL; }
return opaque;
}
{
/* Pop a job off the queue */
POOL_job job = ctx->queue[ctx->queueHead];
/* Pop a job off the queue */
{ POOL_job job = ctx->queue[ctx->queueHead];
ctx->queueHead = (ctx->queueHead + 1) % ctx->queueSize;
/* Unlock the mutex, signal a pusher, and run the job */
if (pthread_mutex_unlock(&ctx->queueMutex)) { return NULL; }
@@ -105,8 +104,7 @@ POOL_ctx *POOL_create(size_t numThreads, size_t queueSize) {
ctx->numThreads = i;
POOL_free(ctx);
return NULL;
}
}
} }
ctx->numThreads = numThreads;
}
return ctx;
@@ -127,8 +125,7 @@ static void POOL_join(POOL_ctx *ctx) {
{ size_t i;
for (i = 0; i < ctx->numThreads; ++i) {
pthread_join(ctx->threads[i], NULL);
}
}
} }
}
void POOL_free(POOL_ctx *ctx) {
@@ -147,8 +144,7 @@ void POOL_add(void *ctxVoid, POOL_function function, void *opaque) {
if (!ctx) { return; }
pthread_mutex_lock(&ctx->queueMutex);
{
POOL_job job = {function, opaque};
{ POOL_job const job = {function, opaque};
/* Wait until there is space in the queue for the new job */
size_t newTail = (ctx->queueTail + 1) % ctx->queueSize;
while (ctx->queueHead == newTail && !ctx->shutdown) {
+3 -3
View File
@@ -322,16 +322,16 @@ size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* cctx)
return 0;
}
size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx* cctx,
size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx* mtctx,
void* dst, size_t dstCapacity,
const void* src, size_t srcSize,
int compressionLevel)
{
ZSTDMT_jobAgency* jobAgency = &cctx->jobAgency;
ZSTDMT_jobAgency* jobAgency = &mtctx->jobAgency;
ZSTD_parameters const params = ZSTD_getParams(compressionLevel, srcSize, 0);
size_t const frameSizeTarget = (size_t)1 << (params.cParams.windowLog + 2);
unsigned const nbFramesMax = (unsigned)(srcSize / frameSizeTarget) + (srcSize < frameSizeTarget) /* min 1 */;
unsigned const nbFrames = MIN(nbFramesMax, cctx->nbThreads);
unsigned const nbFrames = MIN(nbFramesMax, mtctx->nbThreads);
size_t const avgFrameSize = (srcSize + (nbFrames-1)) / nbFrames;
size_t remainingSrcSize = srcSize;
const char* const srcStart = (const char*)src;