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 <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2021-12-07 11:11:32 +10:00
parent 8dd8786c48
commit 64a49d18b9
2 changed files with 10 additions and 4 deletions

View file

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

View file

@ -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",