diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-09-28 14:36:28 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-09-28 14:42:21 -0400 |
commit | 73d93c033d3f4b9c95e8f3a5cc7e4a255d523b84 (patch) | |
tree | 4a6ef543d04d0153134d973977b0e5bfce80425d /src/or | |
parent | c612ddee17c2f6e70fde9f0bdd7116516f384ae8 (diff) | |
download | tor-73d93c033d3f4b9c95e8f3a5cc7e4a255d523b84.tar.gz tor-73d93c033d3f4b9c95e8f3a5cc7e4a255d523b84.zip |
Autodetect the number of CPUs when possible if NumCPUs==0
This is needed for IOCP, since telling the IOCP backend about all
your CPUs is a good idea. It'll also come in handy with asn's
multithreaded crypto stuff, and for people who run servers without
reading the manual.
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/config.c | 17 | ||||
-rw-r--r-- | src/or/config.h | 2 | ||||
-rw-r--r-- | src/or/cpuworker.c | 2 |
3 files changed, 18 insertions, 3 deletions
diff --git a/src/or/config.c b/src/or/config.c index c5b0ccf586..23cad9268b 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -307,7 +307,7 @@ static config_var_t _option_vars[] = { V(WarnUnsafeSocks, BOOL, "1"), V(NoPublish, BOOL, "0"), VAR("NodeFamily", LINELIST, NodeFamilies, NULL), - V(NumCpus, UINT, "1"), + V(NumCpus, UINT, "0"), V(NumEntryGuards, UINT, "3"), V(ORListenAddress, LINELIST, NULL), V(ORPort, UINT, "0"), @@ -4892,6 +4892,19 @@ config_parse_interval(const char *s, int *ok) return (int)r; } +/** Return the number of cpus configured in <b>options</b>. If we are + * told to auto-detect the number of cpus, return the auto-detected number. */ +int +get_num_cpus(const or_options_t *options) +{ + if (options->NumCpus == 0) { + int n = compute_num_cpus(); + return (n >= 1) ? n : 1; + } else { + return options->NumCpus; + } +} + /** * Initialize the libevent library. */ @@ -4913,7 +4926,7 @@ init_libevent(const or_options_t *options) memset(&cfg, 0, sizeof(cfg)); cfg.disable_iocp = options->DisableIOCP; - cfg.num_cpus = options->NumCpus; + cfg.num_cpus = get_num_cpus(options); tor_libevent_initialize(&cfg); diff --git a/src/or/config.h b/src/or/config.h index 7a4ba5c60f..bd5827b4e8 100644 --- a/src/or/config.h +++ b/src/or/config.h @@ -57,6 +57,8 @@ char *options_get_datadir_fname2_suffix(or_options_t *options, #define get_datadir_fname_suffix(sub1, suffix) \ get_datadir_fname2_suffix((sub1), NULL, (suffix)) +int get_num_cpus(const or_options_t *options); + or_state_t *get_or_state(void); int or_state_save(time_t now); diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c index e5b2c71025..cfe9f3af9c 100644 --- a/src/or/cpuworker.c +++ b/src/or/cpuworker.c @@ -366,7 +366,7 @@ spawn_cpuworker(void) static void spawn_enough_cpuworkers(void) { - int num_cpuworkers_needed = get_options()->NumCpus; + int num_cpuworkers_needed = get_num_cpus(get_options()); if (num_cpuworkers_needed < MIN_CPUWORKERS) num_cpuworkers_needed = MIN_CPUWORKERS; |