Skip to content

Commit b27ba56

Browse files
authored
Merge pull request #4335 from Cyan4973/dec_mt_warning
warn when requesting decompression with multiple threads
2 parents f9a6031 + 19541b4 commit b27ba56

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

programs/zstdcli.c

+8-12
Original file line numberDiff line numberDiff line change
@@ -822,15 +822,6 @@ static unsigned init_nbWorkers(void) {
822822
CLEAN_RETURN(1); \
823823
} } }
824824

825-
#define NEXT_INT32(_vari32) { \
826-
const char* __nb; \
827-
NEXT_FIELD(__nb); \
828-
_vari32 = (int)readU32FromChar(&__nb); \
829-
if(*__nb != 0) { \
830-
errorOut("error: only numeric values with optional suffixes K, KB, KiB, M, MB, MiB are allowed"); \
831-
} \
832-
}
833-
834825
#define NEXT_UINT32(_varu32) { \
835826
const char* __nb; \
836827
NEXT_FIELD(__nb); \
@@ -887,7 +878,8 @@ int main(int argCount, const char* argv[])
887878
removeSrcFile = 0,
888879
cLevel = init_cLevel(),
889880
ultra = 0,
890-
cLevelLast = MINCLEVEL - 1; /* for benchmark range */
881+
cLevelLast = MINCLEVEL - 1, /* for benchmark range */
882+
setThreads_non1 = 0;
891883
unsigned nbWorkers = init_nbWorkers();
892884
ZSTD_ParamSwitch_e mmapDict = ZSTD_ps_auto;
893885
ZSTD_ParamSwitch_e useRowMatchFinder = ZSTD_ps_auto;
@@ -1090,7 +1082,7 @@ int main(int argCount, const char* argv[])
10901082
continue;
10911083
}
10921084
#endif
1093-
if (longCommandWArg(&argument, "--threads")) { NEXT_UINT32(nbWorkers); continue; }
1085+
if (longCommandWArg(&argument, "--threads")) { NEXT_UINT32(nbWorkers); setThreads_non1 = (nbWorkers != 1); continue; }
10941086
if (longCommandWArg(&argument, "--memlimit")) { NEXT_UINT32(memLimit); continue; }
10951087
if (longCommandWArg(&argument, "--memory")) { NEXT_UINT32(memLimit); continue; }
10961088
if (longCommandWArg(&argument, "--memlimit-decompress")) { NEXT_UINT32(memLimit); continue; }
@@ -1297,6 +1289,7 @@ int main(int argCount, const char* argv[])
12971289
case 'T':
12981290
argument++;
12991291
nbWorkers = readU32FromChar(&argument);
1292+
setThreads_non1 = (nbWorkers != 1);
13001293
break;
13011294

13021295
/* Dictionary Selection level */
@@ -1341,6 +1334,9 @@ int main(int argCount, const char* argv[])
13411334
DISPLAYLEVEL(3, WELCOME_MESSAGE);
13421335

13431336
#ifdef ZSTD_MULTITHREAD
1337+
if ((operation==zom_decompress) && (setThreads_non1)) {
1338+
DISPLAYLEVEL(2, "Warning : decompression does not support multi-threading\n");
1339+
}
13441340
if ((nbWorkers==NBWORKERS_AUTOCPU) && (!singleThread)) {
13451341
/* automatically set # workers based on # of reported cpu cores */
13461342
if (defaultLogicalCores) {
@@ -1354,7 +1350,7 @@ int main(int argCount, const char* argv[])
13541350
if (operation == zom_compress)
13551351
DISPLAYLEVEL(4, "Compressing with %u worker threads \n", nbWorkers);
13561352
#else
1357-
(void)singleThread; (void)nbWorkers; (void)defaultLogicalCores;
1353+
(void)singleThread; (void)nbWorkers; (void)defaultLogicalCores; (void)setThreads_non1;
13581354
#endif
13591355

13601356
g_utilDisplayLevel = g_displayLevel;

tests/cli-tests/compression/multi-threaded.sh

+10
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,13 @@ zstd -T0 -f file -q ; zstd -t file.zst
1010
zstd -T0 --auto-threads=logical -f file -q ; zstd -t file.zst
1111
zstd -T0 --auto-threads=physical -f file -q ; zstd -t file.zst
1212
zstd -T0 --jobsize=1M -f file -q ; zstd -t file.zst
13+
14+
# multi-thread decompression warning test
15+
zstd -T0 -f file -q ; zstd -t file.zst; zstd -T0 -d file.zst -o file3
16+
zstd -T0 -f file -q ; zstd -t file.zst; zstd -T2 -d file.zst -o file4
17+
# setting multi-thread via environment variable does not trigger decompression warning
18+
zstd -T0 -f file -q ; zstd -t file.zst; ZSTD_NBTHREADS=0 zstd -df file.zst -o file3
19+
zstd -T0 -f file -q ; zstd -t file.zst; ZSTD_NBTHREADS=2 zstd -df file.zst -o file4
20+
# setting nbThreads==1 does not trigger decompression warning
21+
zstd -T0 -f file -q ; zstd -t file.zst; zstd -T1 -df file.zst -o file3
22+
zstd -T0 -f file -q ; zstd -t file.zst; zstd -T2 -T1 -df file.zst -o file4

tests/cli-tests/compression/multi-threaded.sh.stderr.exact

+14
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,17 @@ file.zst : 65537 bytes
55
file.zst : 65537 bytes
66
file.zst : 65537 bytes
77
file.zst : 65537 bytes
8+
file.zst : 65537 bytes
9+
Warning : decompression does not support multi-threading
10+
file.zst : 65537 bytes
11+
file.zst : 65537 bytes
12+
Warning : decompression does not support multi-threading
13+
file.zst : 65537 bytes
14+
file.zst : 65537 bytes
15+
file.zst : 65537 bytes
16+
file.zst : 65537 bytes
17+
file.zst : 65537 bytes
18+
file.zst : 65537 bytes
19+
file.zst : 65537 bytes
20+
file.zst : 65537 bytes
21+
file.zst : 65537 bytes

0 commit comments

Comments
 (0)