From 472638c8617fb4cb6485d09dfbce9a90bdcdc6f2 Mon Sep 17 00:00:00 2001 From: inikep Date: Wed, 23 Mar 2016 12:28:28 +0100 Subject: [PATCH] added mili_sleep and setHighPriority --- lib/zstd_compress.c | 5 ----- lib/zstd_internal.h | 2 -- programs/bench.c | 20 +++++++++++++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/zstd_compress.c b/lib/zstd_compress.c index 266999ca..28a7a1c3 100644 --- a/lib/zstd_compress.c +++ b/lib/zstd_compress.c @@ -98,7 +98,6 @@ struct ZSTD_CCtx_s U32 nextToUpdate3; /* index from which to continue dictionary update */ U32 loadedDictEnd; U32 stage; - U32 additionalParam; ZSTD_parameters params; void* workSpace; size_t workSpaceSize; @@ -276,7 +275,6 @@ size_t ZSTD_copyCCtx(ZSTD_CCtx* dstCCtx, const ZSTD_CCtx* srcCCtx) dstCCtx->dictLimit = srcCCtx->dictLimit; dstCCtx->lowLimit = srcCCtx->lowLimit; dstCCtx->loadedDictEnd= srcCCtx->loadedDictEnd; - dstCCtx->additionalParam = srcCCtx->additionalParam; /* copy entropy tables */ dstCCtx->flagStaticTables = srcCCtx->flagStaticTables; @@ -2454,6 +2452,3 @@ ZSTD_parameters ZSTD_getParams(int compressionLevel, U64 srcSize) result.srcSize = srcSize; return result; } - - -void ZSTD_setAdditionalParam(ZSTD_CCtx* ctx, int additionalParam) { ctx->additionalParam = additionalParam; }; diff --git a/lib/zstd_internal.h b/lib/zstd_internal.h index 39258b21..ba350c4f 100644 --- a/lib/zstd_internal.h +++ b/lib/zstd_internal.h @@ -222,7 +222,5 @@ typedef struct { seqStore_t ZSTD_copySeqStore(const ZSTD_CCtx* ctx); -void ZSTD_setAdditionalParam(ZSTD_CCtx* ctx, int additionalParam); - #endif /* ZSTD_CCOMMON_H_MODULE */ diff --git a/programs/bench.c b/programs/bench.c index 5b2e5644..84380400 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -44,27 +44,34 @@ /* ************************************* * Includes ***************************************/ +#define _POSIX_C_SOURCE 199309L /* before - needed for nanosleep() */ #include /* malloc, free */ #include /* memset */ #include /* fprintf, fopen, ftello64 */ #include /* stat64 */ #include /* stat64 */ -#include /* clock_t, clock, CLOCKS_PER_SEC */ +#include /* clock_t, nanosleep, clock, CLOCKS_PER_SEC */ /* sleep : posix - windows - others */ #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) # include +# include /* setpriority */ # define BMK_sleep(s) sleep(s) +# define mili_sleep(mili) { struct timespec t; t.tv_sec=0; t.tv_nsec=mili*1000000L; nanosleep(&t, NULL); } +# define setHighPriority() setpriority(PRIO_PROCESS, 0, -20) #elif defined(_WIN32) # include # define BMK_sleep(s) Sleep(1000*s) +# define mili_sleep(mili) Sleep(mili) +# define setHighPriority() SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS) #else # define BMK_sleep(s) /* disabled */ +# define mili_sleep(mili) /* disabled */ +# define setHighPriority() /* disabled */ #endif #include "mem.h" #include "zstd_static.h" -#include "zstd_internal.h" /* ZSTD_setAdditionalParam */ #include "xxhash.h" #include "datagen.h" /* RDG_genBuffer */ @@ -199,7 +206,7 @@ typedef struct #define MAX(a,b) ((a)>(b) ? (a) : (b)) static int BMK_benchMem(const void* srcBuffer, size_t srcSize, - const char* displayName, int cLevel, int additionalParam, + const char* displayName, int cLevel, const size_t* fileSizes, U32 nbFiles, const void* dictBuffer, size_t dictBufferSize, benchResult_t *result) { @@ -247,7 +254,6 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, } } } /* warmimg up memory */ - ZSTD_setAdditionalParam(refCtx, additionalParam); RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1); /* Bench */ @@ -275,6 +281,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, DISPLAYLEVEL(2, "%2i-%-17.17s :%10u ->\r", testNb, displayName, (U32)srcSize); memset(compressedBuffer, 0xE5, maxCompressedSize); /* warm up and erase result buffer */ + mili_sleep(1); /* give processor time to other processes */ clockStart = clock(); while (clock() == clockStart); clockStart = clock(); @@ -303,6 +310,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, /* Decompression */ memset(resultBuffer, 0xD6, srcSize); /* warm result buffer */ + mili_sleep(1); /* give processor time to other processes */ clockStart = clock(); while (clock() == clockStart); clockStart = clock(); @@ -403,6 +411,8 @@ static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize, benchResult_t result, total; int l; + setHighPriority(); + const char* pch = strrchr(displayName, '\\'); /* Windows */ if (!pch) pch = strrchr(displayName, '/'); /* Linux */ if (pch) displayName = pch+1; @@ -417,7 +427,7 @@ static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize, for (l=cLevel; l <= cLevelLast; l++) { BMK_benchMem(srcBuffer, benchedSize, - displayName, l, additionalParam, + displayName, l, fileSizes, nbFiles, dictBuffer, dictBufferSize, &result); if (g_displayLevel == 1) {