mirror of
https://github.com/ckolivas/lrzip.git
synced 2026-02-13 10:54:23 +01:00
Deal with number of available CPUs rather than number of online CPUs to cope with CPU affinity being set.
This commit is contained in:
parent
7534c29ff8
commit
3f48188a45
23
lrzip.c
23
lrzip.c
|
|
@ -1464,6 +1464,27 @@ error:
|
|||
return false;
|
||||
}
|
||||
|
||||
static int get_available_cpus(void)
|
||||
{
|
||||
long sys;
|
||||
#ifdef __linux__
|
||||
cpu_set_t mask;
|
||||
CPU_ZERO(&mask);
|
||||
|
||||
if (sched_getaffinity(0, sizeof(mask), &mask) == 0) {
|
||||
int count = CPU_COUNT(&mask);
|
||||
if (count > 0)
|
||||
return count;
|
||||
}
|
||||
#endif
|
||||
/* Fallback to system-wide online CPUs */
|
||||
sys = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
if (sys > 0)
|
||||
return (int)sys;
|
||||
|
||||
return 1; /* Absolute minimum */
|
||||
}
|
||||
|
||||
bool initialise_control(rzip_control *control)
|
||||
{
|
||||
time_t now_t, tdiff;
|
||||
|
|
@ -1481,7 +1502,7 @@ bool initialise_control(rzip_control *control)
|
|||
if (unlikely(control->ramsize == -1))
|
||||
return false;
|
||||
/* for testing single CPU */
|
||||
control->threads = PROCESSORS; /* get CPUs for LZMA */
|
||||
control->threads = get_available_cpus(); /* get CPUs for LZMA */
|
||||
control->page_size = PAGE_SIZE;
|
||||
control->nice_val = 19;
|
||||
|
||||
|
|
|
|||
|
|
@ -249,12 +249,6 @@ typedef sem_t cksem_t;
|
|||
|
||||
#define one_g (1000 * 1024 * 1024)
|
||||
|
||||
#if defined(NOTHREAD) || !defined(_SC_NPROCESSORS_ONLN)
|
||||
# define PROCESSORS (1)
|
||||
#else
|
||||
# define PROCESSORS (sysconf(_SC_NPROCESSORS_ONLN))
|
||||
#endif
|
||||
|
||||
#ifndef PAGE_SIZE
|
||||
# ifdef _SC_PAGE_SIZE
|
||||
# define PAGE_SIZE (sysconf(_SC_PAGE_SIZE))
|
||||
|
|
|
|||
2
main.c
2
main.c
|
|
@ -163,7 +163,7 @@ static void show_summary(void)
|
|||
if (!TEST_ONLY)
|
||||
print_verbose("The following options are in effect for this %s.\n",
|
||||
DECOMPRESS ? "DECOMPRESSION" : "COMPRESSION");
|
||||
print_verbose("Threading is %s. Number of CPUs detected: %d\n", control->threads > 1? "ENABLED" : "DISABLED",
|
||||
print_verbose("Threading is %s. Number of CPUs available detected: %d\n", control->threads > 1? "ENABLED" : "DISABLED",
|
||||
control->threads);
|
||||
print_verbose("Detected %"PRId64" bytes ram\n", control->ramsize);
|
||||
print_verbose("Compression level %d\n", control->compression_level);
|
||||
|
|
|
|||
Loading…
Reference in a new issue