Skip to content

Commit 725a152

Browse files
committed
benchmark uses 1 thread by default
1 parent c41fc1a commit 725a152

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

‎programs/zstdcli.c‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#define ZSTDCLI_NBTHREADS_DEFAULT (unsigned)(MAX(1, MIN(4, UTIL_countLogicalCores() / 4)))
4848
#endif
4949

50-
50+
static unsigned init_nbWorkers(unsigned defaultNbWorkers);
5151

5252
/*-************************************
5353
* Constants
@@ -95,6 +95,7 @@ static U32 g_ldmBucketSizeLog = LDM_PARAM_DEFAULT;
9595

9696
#define DEFAULT_ACCEL 1
9797
#define NBWORKERS_AUTOCPU 0
98+
#define NBWORKERS_UNSET UINT_MAX
9899

99100
typedef enum { cover, fastCover, legacy } dictType;
100101

@@ -233,7 +234,7 @@ static void usageAdvanced(const char* programName)
233234
DISPLAYOUT(" --patch-from=REF Use REF as the reference point for Zstandard's diff engine. \n");
234235
DISPLAYOUT(" --patch-apply Equivalent for `-d --patch-from` \n\n");
235236
# ifdef ZSTD_MULTITHREAD
236-
DISPLAYOUT(" -T# Spawn # compression threads. [Default: %i; pass 0 for core count.]\n", ZSTDCLI_NBTHREADS_DEFAULT);
237+
DISPLAYOUT(" -T# Spawn # compression threads. [Default: %u; pass 0 for core count.]\n", init_nbWorkers(ZSTDCLI_NBTHREADS_DEFAULT));
237238
DISPLAYOUT(" --single-thread Share a single thread for I/O and compression (slightly different than `-T1`).\n");
238239
DISPLAYOUT(" --auto-threads={physical|logical}\n");
239240
DISPLAYOUT(" Use physical/logical cores when using `-T0`. [Default: Physical]\n\n");
@@ -783,7 +784,7 @@ static int init_cLevel(void) {
783784
return ZSTDCLI_CLEVEL_DEFAULT;
784785
}
785786

786-
static unsigned init_nbWorkers(void) {
787+
static unsigned init_nbWorkers(unsigned defaultNbWorkers) {
787788
#ifdef ZSTD_MULTITHREAD
788789
const char* const env = getenv(ENV_NBWORKERS);
789790
if (env != NULL) {
@@ -792,15 +793,15 @@ static unsigned init_nbWorkers(void) {
792793
unsigned nbThreads;
793794
if (readU32FromCharChecked(&ptr, &nbThreads)) {
794795
DISPLAYLEVEL(2, "Ignore environment variable setting %s=%s: numeric value too large \n", ENV_NBWORKERS, env);
795-
return ZSTDCLI_NBTHREADS_DEFAULT;
796+
return defaultNbWorkers;
796797
} else if (*ptr == 0) {
797798
return nbThreads;
798799
}
799800
}
800801
DISPLAYLEVEL(2, "Ignore environment variable setting %s=%s: not a valid unsigned value \n", ENV_NBWORKERS, env);
801802
}
802803

803-
return ZSTDCLI_NBTHREADS_DEFAULT;
804+
return defaultNbWorkers;
804805
#else
805806
return 1;
806807
#endif
@@ -881,7 +882,7 @@ int main(int argCount, const char* argv[])
881882
ultra = 0,
882883
cLevelLast = MINCLEVEL - 1, /* for benchmark range */
883884
setThreads_non1 = 0;
884-
unsigned nbWorkers = init_nbWorkers();
885+
unsigned nbWorkers = init_nbWorkers(NBWORKERS_UNSET);
885886
ZSTD_ParamSwitch_e mmapDict = ZSTD_ps_auto;
886887
ZSTD_ParamSwitch_e useRowMatchFinder = ZSTD_ps_auto;
887888
FIO_compressionType_t cType = FIO_zstdCompression;
@@ -1410,7 +1411,9 @@ int main(int argCount, const char* argv[])
14101411
/* Check if benchmark is selected */
14111412
if (operation==zom_bench) {
14121413
#ifndef ZSTD_NOBENCH
1413-
int const benchThreadsMsgLevel = 2 + (nbWorkers <= 1);
1414+
int benchThreadsMsgLevel = 2;
1415+
if (nbWorkers == NBWORKERS_UNSET) nbWorkers = 1;
1416+
if (nbWorkers <= 1) benchThreadsMsgLevel = 3;
14141417
if (cType != FIO_zstdCompression) {
14151418
DISPLAYLEVEL(1, "benchmark mode is only compatible with zstd format \n");
14161419
CLEAN_RETURN(1);
@@ -1471,6 +1474,7 @@ int main(int argCount, const char* argv[])
14711474
zParams.compressionLevel = dictCLevel;
14721475
zParams.notificationLevel = (unsigned)g_displayLevel;
14731476
zParams.dictID = dictID;
1477+
if (nbWorkers == NBWORKERS_UNSET) nbWorkers = init_nbWorkers(ZSTDCLI_NBTHREADS_DEFAULT);
14741478
if (dict == cover) {
14751479
int const optimize = !coverParams.k || !coverParams.d;
14761480
coverParams.nbThreads = (unsigned)nbWorkers;
@@ -1593,6 +1597,7 @@ int main(int argCount, const char* argv[])
15931597
#ifndef ZSTD_NOCOMPRESS
15941598
FIO_setCompressionType(prefs, cType);
15951599
FIO_setContentSize(prefs, contentSize);
1600+
if (nbWorkers == NBWORKERS_UNSET) nbWorkers = init_nbWorkers(ZSTDCLI_NBTHREADS_DEFAULT);
15961601
FIO_setNbWorkers(prefs, (int)nbWorkers);
15971602
FIO_setJobSize(prefs, (int)chunkSize);
15981603
if (g_overlapLog!=OVERLAP_LOG_DEFAULT) FIO_setOverlapLog(prefs, (int)g_overlapLog);

0 commit comments

Comments
 (0)