aboutsummaryrefslogtreecommitdiff
path: root/src/xz/hardware.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-02-14 00:45:29 +0200
committerLasse Collin <lasse.collin@tukaani.org>2009-02-14 00:45:29 +0200
commit3084d662d2646ab7eb58daf0dc32cf3f9a74eec7 (patch)
tree6601b6dee1b3c35b6894d71fcdbf1554801aff4f /src/xz/hardware.c
parentInitial port to DOS using DJGPP. (diff)
downloadxz-3084d662d2646ab7eb58daf0dc32cf3f9a74eec7.tar.xz
Cleanups to the code that detects the amount of RAM and
the number of CPU cores. Added support for using sysinfo() on Linux systems whose libc lacks appropriate sysconf() support (at least dietlibc). The Autoconf macros were split into separate files, and CPU core count detection was moved from hardware.c to cpucores.h. The core count isn't used for anything real for now, so a problematic part in process.c was commented out.
Diffstat (limited to 'src/xz/hardware.c')
-rw-r--r--src/xz/hardware.c50
1 files changed, 22 insertions, 28 deletions
diff --git a/src/xz/hardware.c b/src/xz/hardware.c
index 0c372726..0695ccb1 100644
--- a/src/xz/hardware.c
+++ b/src/xz/hardware.c
@@ -19,11 +19,12 @@
#include "private.h"
#include "physmem.h"
+#include "cpucores.h"
/// Maximum number of free *coder* threads. This can be set with
/// the --threads=NUM command line option.
-size_t opt_threads = 1;
+static uint32_t threads_max;
/// Memory usage limit for encoding
@@ -40,38 +41,31 @@ static uint64_t memlimit_custom = 0;
/// Get the number of CPU cores, and set opt_threads to default to that value.
/// User can then override this with --threads command line option.
static void
-hardware_cores(void)
+hardware_threadlimit_init(void)
{
-#if defined(HAVE_NUM_PROCESSORS_SYSCONF)
- const long cpus = sysconf(_SC_NPROCESSORS_ONLN);
- if (cpus > 0)
- opt_threads = (size_t)(cpus);
-
-#elif defined(HAVE_NUM_PROCESSORS_SYSCTL)
- int name[2] = { CTL_HW, HW_NCPU };
- int cpus;
- size_t cpus_size = sizeof(cpus);
- if (!sysctl(name, &cpus, &cpus_size, NULL, NULL)
- && cpus_size == sizeof(cpus) && cpus > 0)
- opt_threads = (size_t)(cpus);
-#endif
-
- // Limit opt_threads so that maximum number of threads doesn't exceed.
-
-#if defined(_SC_THREAD_THREADS_MAX)
- const long threads_max = sysconf(_SC_THREAD_THREADS_MAX);
- if (threads_max > 0 && (size_t)(threads_max) < opt_threads)
- opt_threads = (size_t)(threads_max);
-
-#elif defined(PTHREAD_THREADS_MAX)
- if (opt_threads > PTHREAD_THREADS_MAX)
- opt_threads = PTHREAD_THREADS_MAX;
-#endif
+ threads_max = cpucores();
+ if (threads_max == 0)
+ threads_max = 1;
return;
}
+extern void
+hardware_threadlimit_set(uint32_t threadlimit)
+{
+ threads_max = threadlimit;
+ return;
+}
+
+
+extern uint32_t
+hardware_threadlimit_get(void)
+{
+ return threads_max;
+}
+
+
static void
hardware_memlimit_init(void)
{
@@ -117,6 +111,6 @@ extern void
hardware_init(void)
{
hardware_memlimit_init();
- hardware_cores();
+ hardware_threadlimit_init();
return;
}