From fb96767ac5c26cd40f4b50ae2c87724bd3e1af2c Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Mon, 29 Jun 2020 16:44:23 +0200 Subject: trx_rate_ctr: Fix immediate rescheduling on per-sec thresholds For instance, use in VTY: "ctr-error-threshold tx_underruns 5 per-second" If the condition becomes true (eg 5 underruns happened in one sec), the statement inside OSMO_MAX would become -1, but it was being handled as an unsigned when doing the OSMO_MAX internal comparison. As a result, OSMO_MAX((unsigned)-1, 1) was returning -1 (unsigned) stored in threshold_timer_sched_secs which then became and int -1, which was handled by osmo_timer_schedule as a 0, hence having an immediate trigerring all the time. While at it, make threshold_timer_sched_secs unsigned since it doesn't make sense to have it as signed anyway. Change-Id: I6ea3d64dff189a5bc924e72d846e02d50536a8ea --- CommonLibs/trx_rate_ctr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CommonLibs/trx_rate_ctr.cpp b/CommonLibs/trx_rate_ctr.cpp index d10b315..381b387 100644 --- a/CommonLibs/trx_rate_ctr.cpp +++ b/CommonLibs/trx_rate_ctr.cpp @@ -81,7 +81,7 @@ static Mutex rate_ctr_mutex; struct osmo_timer_list threshold_timer; static LLIST_HEAD(threshold_list); -static int threshold_timer_sched_secs; +static unsigned int threshold_timer_sched_secs; static bool threshold_initied; const struct value_string rate_ctr_intv[] = { @@ -260,7 +260,7 @@ static void threshold_timer_update_intv() { } - threshold_timer_sched_secs = OSMO_MAX(min_secs / 2 - 1, 1); + threshold_timer_sched_secs = OSMO_MAX((int)(min_secs / 2 - 1), 1); LOGC(DMAIN, INFO) << "New ctr-error-threshold check interval: " << threshold_timer_sched_secs << " seconds"; osmo_timer_schedule(&threshold_timer, threshold_timer_sched_secs, 0); -- cgit v1.2.3