diff --git a/daemon/aux.c b/daemon/aux.c index 61930720f..02b6cfc93 100644 --- a/daemon/aux.c +++ b/daemon/aux.c @@ -36,6 +36,7 @@ struct scheduler { struct looper_thread { void (*f)(void); const char *name; + long long interval_us; }; @@ -314,7 +315,7 @@ static void thread_looper_helper(void *fp) { struct looper_thread lh = *lhp; g_slice_free1(sizeof(*lhp), lhp); - long long interval_us = 1000000; + long long interval_us = lh.interval_us; static const long long warn_limit_pct = 20; // 20% long long warn_limit_us = interval_us * warn_limit_pct / 100; @@ -335,16 +336,19 @@ static void thread_looper_helper(void *fp) { warn_limit_us / 1000000, warn_limit_us % 1000000); thread_cancel_enable(); - usleep(1000000); /* sleep for 1 second in each iteration */ + usleep(interval_us); thread_cancel_disable(); } } -void thread_create_looper(void (*f)(void), const char *scheduler, int priority, const char *name) { +void thread_create_looper(void (*f)(void), const char *scheduler, int priority, const char *name, + long long interval_us) +{ struct looper_thread *lh = g_slice_alloc(sizeof(*lh)); *lh = (__typeof__(*lh)) { .f = f, .name = name, + .interval_us = interval_us, }; thread_create_detach_prio(thread_looper_helper, lh, scheduler, priority, name); } diff --git a/daemon/main.c b/daemon/main.c index f68bd12e2..5db5b927b 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1348,7 +1348,7 @@ int main(int argc, char **argv) { /* separate thread for releasing ports (sockets), which are scheduled for clearing */ thread_create_looper(release_closed_sockets, rtpe_config.idle_scheduling, - rtpe_config.idle_priority, "release closed sockets"); + rtpe_config.idle_priority, "release closed sockets", 1000000); /* separate thread for update of running min/max call counters */ thread_create_detach_prio(call_rate_stats_updater, NULL, rtpe_config.idle_scheduling, @@ -1356,11 +1356,11 @@ int main(int argc, char **argv) { /* separate thread for ports iterations (stats update from the kernel) functionality */ thread_create_looper(kernel_stats_updater, rtpe_config.idle_scheduling, - rtpe_config.idle_priority, "kernel stats updater"); + rtpe_config.idle_priority, "kernel stats updater", 1000000); /* separate thread for ice slow timer functionality */ thread_create_looper(ice_slow_timer, rtpe_config.idle_scheduling, - rtpe_config.idle_priority, "ice slow timer"); + rtpe_config.idle_priority, "ice slow timer", 1000000); if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && initial_rtpe_config.redis_delete_async) thread_create_detach(redis_delete_async_loop, NULL, "redis async"); diff --git a/include/aux.h b/include/aux.h index 06a3a91d5..fb684b9ba 100644 --- a/include/aux.h +++ b/include/aux.h @@ -327,7 +327,7 @@ void thread_waker_add(struct thread_waker *); void thread_waker_del(struct thread_waker *); void threads_join_all(bool cancel); void thread_create_detach_prio(void (*)(void *), void *, const char *, int, const char *); -void thread_create_looper(void (*f)(void), const char *scheduler, int priority, const char *name); +void thread_create_looper(void (*f)(void), const char *scheduler, int priority, const char *name, long long); INLINE void thread_create_detach(void (*f)(void *), void *a, const char *name) { thread_create_detach_prio(f, a, NULL, 0, name); }