From 27a0fee88230d027dddad1e5d6b2adc991aec6c1 Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Tue, 20 Jun 2023 16:29:48 +0000 Subject: [PATCH 1/2] Bug 40808: Change KISTSchedRunInterval range and default; add KISTSchedRunIntervalClient --- src/core/or/scheduler.h | 6 +++--- src/core/or/scheduler_kist.c | 14 +++++++++++--- src/test/test_scheduler.c | 10 ++++------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/core/or/scheduler.h b/src/core/or/scheduler.h index 7d3c6f7390..dab7f37f0e 100644 --- a/src/core/or/scheduler.h +++ b/src/core/or/scheduler.h @@ -102,9 +102,9 @@ typedef struct scheduler_t { *****************************************************************************/ /* Default interval that KIST runs (in ms). */ -#define KIST_SCHED_RUN_INTERVAL_DEFAULT 10 -/* Minimum interval that KIST runs. This value disables KIST. */ -#define KIST_SCHED_RUN_INTERVAL_MIN 0 +#define KIST_SCHED_RUN_INTERVAL_DEFAULT 2 +/* Minimum interval that KIST runs. */ +#define KIST_SCHED_RUN_INTERVAL_MIN 2 /* Maximum interval that KIST runs (in ms). */ #define KIST_SCHED_RUN_INTERVAL_MAX 100 diff --git a/src/core/or/scheduler_kist.c b/src/core/or/scheduler_kist.c index 52bc62f1b4..69804247c8 100644 --- a/src/core/or/scheduler_kist.c +++ b/src/core/or/scheduler_kist.c @@ -13,6 +13,7 @@ #include "app/config/config.h" #include "core/mainloop/connection.h" #include "feature/nodelist/networkstatus.h" +#include "feature/relay/routermode.h" #define CHANNEL_OBJECT_PRIVATE #include "core/or/channel.h" #include "core/or/channeltls.h" @@ -810,12 +811,19 @@ kist_scheduler_run_interval(void) log_debug(LD_SCHED, "KISTSchedRunInterval=0, turning to the consensus."); - /* Will either be the consensus value or the default. Note that 0 can be - * returned which means the consensus wants us to NOT use KIST. */ - return networkstatus_get_param(NULL, "KISTSchedRunInterval", + /* Clients and relays have a separate consensus parameter. Clients + * need a lower KIST interval, since they have only a couple connections */ + if (server_mode(get_options())) { + return networkstatus_get_param(NULL, "KISTSchedRunInterval", KIST_SCHED_RUN_INTERVAL_DEFAULT, KIST_SCHED_RUN_INTERVAL_MIN, KIST_SCHED_RUN_INTERVAL_MAX); + } else { + return networkstatus_get_param(NULL, "KISTSchedRunIntervalClient", + KIST_SCHED_RUN_INTERVAL_DEFAULT, + KIST_SCHED_RUN_INTERVAL_MIN, + KIST_SCHED_RUN_INTERVAL_MAX); + } } /* Set KISTLite mode that is KIST without kernel support. */ diff --git a/src/test/test_scheduler.c b/src/test/test_scheduler.c index 7e41a4be25..06b3dafce8 100644 --- a/src/test/test_scheduler.c +++ b/src/test/test_scheduler.c @@ -81,8 +81,7 @@ mock_vanilla_networkstatus_get_param( (void)default_val; (void)min_val; (void)max_val; - // only support KISTSchedRunInterval right now - tor_assert(strcmp(param_name, "KISTSchedRunInterval")==0); + (void)param_name; return 0; } @@ -95,8 +94,7 @@ mock_kist_networkstatus_get_param( (void)default_val; (void)min_val; (void)max_val; - // only support KISTSchedRunInterval right now - tor_assert(strcmp(param_name, "KISTSchedRunInterval")==0); + (void)param_name; return 12; } @@ -863,7 +861,7 @@ test_scheduler_initfree(void *arg) /* We have specified nothing in the torrc and there's no consensus so the * KIST scheduler is what should be in use */ tt_ptr_op(the_scheduler, OP_EQ, get_kist_scheduler()); - tt_int_op(sched_run_interval, OP_EQ, 10); + tt_int_op(sched_run_interval, OP_EQ, KIST_SCHED_RUN_INTERVAL_DEFAULT); scheduler_free_all(); @@ -906,7 +904,7 @@ test_scheduler_can_use_kist(void *arg) #else /* HAVE_KIST_SUPPORT */ tt_int_op(res_should, OP_EQ, 0); #endif /* HAVE_KIST_SUPPORT */ - tt_int_op(res_freq, OP_EQ, 10); + tt_int_op(res_freq, OP_EQ, KIST_SCHED_RUN_INTERVAL_DEFAULT); /* Test defer to consensus, and kist consensus available */ MOCK(networkstatus_get_param, mock_kist_networkstatus_get_param); From ba2e0bcc49681fb72d17558c84e072ef7e9c98cf Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Tue, 20 Jun 2023 16:30:55 +0000 Subject: [PATCH 2/2] Changes file for bug40808 --- changes/bug40808 | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changes/bug40808 diff --git a/changes/bug40808 b/changes/bug40808 new file mode 100644 index 0000000000..2aae6b47e4 --- /dev/null +++ b/changes/bug40808 @@ -0,0 +1,5 @@ + o Minor bugfixes (KIST): + - Prevent KISTSchedRunInterval from having values of 0 or 1, neither of + which work properly. Additionally, make a separate KISTSchedRunIntervalClient + parameter, so that the client and relay KIST values can be set separately. + Set the default of both to 2ms. Fixes bug 40808; bugfix on 0.3.2.1-alpha.