]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
added mili_sleep and setHighPriority
authorinikep <inikep@gmail.com>
Wed, 23 Mar 2016 11:28:28 +0000 (12:28 +0100)
committerinikep <inikep@gmail.com>
Wed, 23 Mar 2016 11:28:28 +0000 (12:28 +0100)
lib/zstd_compress.c
lib/zstd_internal.h
programs/bench.c

index 266999ca70808518c7761bad011a763ec093dfec..28a7a1c3c6f0963187ddf8947eda4488d53fc464 100644 (file)
@@ -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; };
index 39258b21f2eede15ee88626e65934068b0042648..ba350c4f69e1bb2d67d86d423714f0b6182018a1 100644 (file)
@@ -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 */
index 5b2e5644a5c0800469e7ded4261f289121dfd5dd..84380400d255cf46f07893ef0cdd1bc16d0866b8 100644 (file)
 /* *************************************
 *  Includes
 ***************************************/
+#define _POSIX_C_SOURCE 199309L /* before <time.h> - needed for nanosleep() */
 #include <stdlib.h>      /* malloc, free */
 #include <string.h>      /* memset */
 #include <stdio.h>       /* fprintf, fopen, ftello64 */
 #include <sys/types.h>   /* stat64 */
 #include <sys/stat.h>    /* stat64 */
-#include <time.h>         /* clock_t, clock, CLOCKS_PER_SEC */
+#include <time.h>         /* clock_t, nanosleep, clock, CLOCKS_PER_SEC */
 
 /* sleep : posix - windows - others */
 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
 #  include <unistd.h>
+#  include <sys/resource.h> /* 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 <windows.h>
 #  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) {