diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-06-28 12:08:18 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-06-28 12:08:18 -0400 |
commit | 6178a9f758d60f5fc896644f1b9b0aaf4c32f2a5 (patch) | |
tree | 207d1df4696820488a87c218c95126e422805f13 /src/common/compat.c | |
parent | 042df08693521a7cba990489fa03547a6e3fec4c (diff) | |
download | tor-6178a9f758d60f5fc896644f1b9b0aaf4c32f2a5.tar.gz tor-6178a9f758d60f5fc896644f1b9b0aaf4c32f2a5.zip |
Move compute_num_cpus to lib/thread
Diffstat (limited to 'src/common/compat.c')
-rw-r--r-- | src/common/compat.c | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index f8333624ca..6d89e1c08b 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -354,81 +354,6 @@ get_uname,(void)) * Process control */ -/** Implementation logic for compute_num_cpus(). */ -static int -compute_num_cpus_impl(void) -{ -#ifdef _WIN32 - SYSTEM_INFO info; - memset(&info, 0, sizeof(info)); - GetSystemInfo(&info); - if (info.dwNumberOfProcessors >= 1 && info.dwNumberOfProcessors < INT_MAX) - return (int)info.dwNumberOfProcessors; - else - return -1; -#elif defined(HAVE_SYSCONF) -#ifdef _SC_NPROCESSORS_CONF - long cpus_conf = sysconf(_SC_NPROCESSORS_CONF); -#else - long cpus_conf = -1; -#endif -#ifdef _SC_NPROCESSORS_ONLN - long cpus_onln = sysconf(_SC_NPROCESSORS_ONLN); -#else - long cpus_onln = -1; -#endif - long cpus = -1; - - if (cpus_conf > 0 && cpus_onln < 0) { - cpus = cpus_conf; - } else if (cpus_onln > 0 && cpus_conf < 0) { - cpus = cpus_onln; - } else if (cpus_onln > 0 && cpus_conf > 0) { - if (cpus_onln < cpus_conf) { - log_notice(LD_GENERAL, "I think we have %ld CPUS, but only %ld of them " - "are available. Telling Tor to only use %ld. You can over" - "ride this with the NumCPUs option", - cpus_conf, cpus_onln, cpus_onln); - } - cpus = cpus_onln; - } - - if (cpus >= 1 && cpus < INT_MAX) - return (int)cpus; - else - return -1; -#else - return -1; -#endif /* defined(_WIN32) || ... */ -} - -#define MAX_DETECTABLE_CPUS 16 - -/** Return how many CPUs we are running with. We assume that nobody is - * using hot-swappable CPUs, so we don't recompute this after the first - * time. Return -1 if we don't know how to tell the number of CPUs on this - * system. - */ -int -compute_num_cpus(void) -{ - static int num_cpus = -2; - if (num_cpus == -2) { - num_cpus = compute_num_cpus_impl(); - tor_assert(num_cpus != -2); - if (num_cpus > MAX_DETECTABLE_CPUS) { - /* LCOV_EXCL_START */ - log_notice(LD_GENERAL, "Wow! I detected that you have %d CPUs. I " - "will not autodetect any more than %d, though. If you " - "want to configure more, set NumCPUs in your torrc", - num_cpus, MAX_DETECTABLE_CPUS); - num_cpus = MAX_DETECTABLE_CPUS; - /* LCOV_EXCL_STOP */ - } - } - return num_cpus; -} - #if defined(HW_PHYSMEM64) /* This appears to be an OpenBSD thing */ #define INT64_HW_MEM HW_PHYSMEM64 |