Browse Source

MT#55283 flexible sleep time for looper threads

Change-Id: I6159b2f030df68c532f0fb3d76abd975a3d5089e
pull/1676/head
Richard Fuchs 3 years ago
parent
commit
688c75f9d8
3 changed files with 11 additions and 7 deletions
  1. +7
    -3
      daemon/aux.c
  2. +3
    -3
      daemon/main.c
  3. +1
    -1
      include/aux.h

+ 7
- 3
daemon/aux.c View File

@ -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);
}

+ 3
- 3
daemon/main.c View File

@ -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");


+ 1
- 1
include/aux.h View File

@ -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);
}


Loading…
Cancel
Save