1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

xz: Add support --threads=+N so that -T+1 gives threaded mode.

This commit is contained in:
Lasse Collin 2022-11-19 19:06:13 +02:00
parent a11a2b8b5e
commit d327743bb5
4 changed files with 51 additions and 6 deletions

View file

@ -258,11 +258,23 @@ parse_real(args_info *args, int argc, char **argv)
suffix_set(optarg);
break;
case 'T':
case 'T': {
// Since xz 5.4.0: Ignore leading '+' first.
const char *s = optarg;
if (optarg[0] == '+')
++s;
// The max is from src/liblzma/common/common.h.
hardware_threads_set(str_to_uint64("threads",
optarg, 0, 16384));
uint32_t t = str_to_uint64("threads", s, 0, 16384);
// If leading '+' was used then use multi-threaded
// mode even if exactly one thread was specified.
if (t == 1 && optarg[0] == '+')
t = UINT32_MAX;
hardware_threads_set(t);
break;
}
// --version
case 'V':

View file

@ -21,6 +21,10 @@ static uint32_t threads_max = 1;
/// on the available hardware threads.
static bool threads_are_automatic = false;
/// If true, then try to use multi-threaded mode (if memlimit allows)
/// even if only one thread was requested explicitly (-T+1).
static bool use_mt_mode_with_one_thread = false;
/// Memory usage limit for compression
static uint64_t memlimit_compress = 0;
@ -57,9 +61,16 @@ static uint64_t total_ram;
extern void
hardware_threads_set(uint32_t n)
{
// Reset these to false first and set them to true when appropriate.
threads_are_automatic = false;
use_mt_mode_with_one_thread = false;
if (n == 0) {
// Automatic number of threads was requested.
// If there is only one hardware thread, multi-threaded
// mode will still be used if memory limit allows.
threads_are_automatic = true;
use_mt_mode_with_one_thread = true;
// If threading support was enabled at build time,
// use the number of available CPU cores. Otherwise
@ -72,9 +83,11 @@ hardware_threads_set(uint32_t n)
#else
threads_max = 1;
#endif
} else if (n == UINT32_MAX) {
use_mt_mode_with_one_thread = true;
threads_max = 1;
} else {
threads_max = n;
threads_are_automatic = false;
}
return;
@ -92,7 +105,7 @@ extern bool
hardware_threads_is_mt(void)
{
#ifdef MYTHREAD_ENABLED
return threads_max > 1 || threads_are_automatic;
return threads_max > 1 || use_mt_mode_with_one_thread;
#else
return false;
#endif

View file

@ -16,6 +16,7 @@ extern void hardware_init(void);
/// Set the maximum number of worker threads.
/// A special value of UINT32_MAX sets one thread in multi-threaded mode.
extern void hardware_threads_set(uint32_t threadlimit);
/// Get the maximum number of worker threads.

View file

@ -5,7 +5,7 @@
.\" This file has been put into the public domain.
.\" You can do whatever you want with this file.
.\"
.TH XZ 1 "2022-11-09" "Tukaani" "XZ Utils"
.TH XZ 1 "2022-11-19" "Tukaani" "XZ Utils"
.
.SH NAME
xz, unxz, xzcat, lzma, unlzma, lzcat \- Compress or decompress .xz and .lzma files
@ -1214,6 +1214,25 @@ even if the system supports only one hardware thread.
5.2.x
used single-threaded mode in this situation.)
.IP ""
To use multi-threaded mode with only one thread, set
.I threads
to
.BR +1 .
The
.B +
prefix has no effect with values other than
.BR 1 .
A memory usage limit can still make
.B xz
switch to single-threaded mode unless
.B \-\-no\-adjust
is used.
Support for the
.B +
prefix was added in
.B xz
5.4.0.
.IP ""
If an automatic number of threads has been requested and
no memory usage limit has been specified,
then a system-specific default soft limit will be used to possibly