From 64a49d18b948a5b8ac88da9207689af356a081cf Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 7 Dec 2021 11:11:32 +1000 Subject: timer: rate-limit the "timer expiry in the past" error messages We already ratelimit the normal notification about event processing lagging behind but in the case of timers actually expiring late, we'd pass those messages on. So lots of clicks on a slow-reponse system resulted in lots of messages triggered by the debounce timers. Use the same ratelimiting as the event processing warning, 5 messages per hour which should be a good balance between warning and not spamming the log. Fixes #711 Signed-off-by: Peter Hutterer --- src/libinput-private.h | 2 ++ src/timer.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libinput-private.h b/src/libinput-private.h index 051e828b..6ff81a33 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -136,6 +136,8 @@ struct libinput { struct libinput_source *source; int fd; uint64_t next_expiry; + + struct ratelimit expiry_in_past_limit; } timer; struct libinput_event **events; diff --git a/src/timer.c b/src/timer.c index 22d7a962..e1d8dd60 100644 --- a/src/timer.c +++ b/src/timer.c @@ -43,6 +43,9 @@ libinput_timer_init(struct libinput_timer *timer, timer->timer_name = safe_strdup(timer_name); timer->timer_func = timer_func; timer->timer_func_data = timer_func_data; + /* at most 5 "expiry in the past" log messages per hour */ + ratelimit_init(&libinput->timer.expiry_in_past_limit, + s2us(60 * 60), 5); } void @@ -92,10 +95,11 @@ libinput_timer_set_flags(struct libinput_timer *timer, uint64_t now = libinput_now(timer->libinput); if (expire < now) { if ((flags & TIMER_FLAG_ALLOW_NEGATIVE) == 0) - log_bug_client(timer->libinput, - "timer %s: scheduled expiry is in the past (-%dms), your system is too slow\n", - timer->timer_name, - us2ms(now - expire)); + log_bug_client_ratelimit(timer->libinput, + &timer->libinput->timer.expiry_in_past_limit, + "timer %s: scheduled expiry is in the past (-%dms), your system is too slow\n", + timer->timer_name, + us2ms(now - expire)); } else if ((expire - now) > ms2us(5000)) { log_bug_libinput(timer->libinput, "timer %s: offset more than 5s, now %d expire %d\n", -- cgit v1.2.1