From fbc9e92fdb364a741a3190fc22c6fa65d90e92e3 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Wed, 23 Nov 2022 13:47:59 -0500 Subject: relay: Use the configured number of threads for worker work calculation We cap our number of CPU worker threads to at least 2 even if we have a single core. But also, before we used to always add one extra thread regardless of the number of core. This meant that we were off when re-using the get_num_cpus() function when calculating our onionskin work overhead because we were always off by one. This commit makes it that we always use the number of thread our actual thread pool was configured with. Fixes #40719 Signed-off-by: David Goulet --- src/feature/relay/onion_queue.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/feature/relay') diff --git a/src/feature/relay/onion_queue.c b/src/feature/relay/onion_queue.c index 6d1a6de15c..b844aefcd1 100644 --- a/src/feature/relay/onion_queue.c +++ b/src/feature/relay/onion_queue.c @@ -152,7 +152,13 @@ have_room_for_onionskin(uint16_t type) /* If we've got fewer than 50 entries, we always have room for one more. */ if (ol_entries[type] < 50) return 1; - num_cpus = get_num_cpus(options); + + /* If zero, this means our thread pool was never initialized meaning we can't + * really get here but make sure we don't have such value because we are + * using as a divisor. */ + num_cpus = cpuworker_get_n_threads(); + tor_assert(num_cpus > 0); + max_onion_queue_delay = get_onion_queue_max_delay(options); /* Compute how many microseconds we'd expect to need to clear all -- cgit v1.2.3-54-g00ecf