cyclic: Add rate limiting in schedule() via CYCLIC_RATELIMIT_US
PATCH v2 1/1 cyclic: Add rate limiting in schedule() via CYCLIC_RATELIMIT_US
This patch adds the new Kconfig option CONFIG_CYCLIC_RATELIMIT_US which defines the min allowed time after with a new call into the cyclic infrastructure is allowed. This results in a rate limiting of the all functions hooked into the cyclic interface. As it's been noticed that on some platforms, that high frequent calls to schedule() (replaced from WATCHDOG_RESET) may lead to a performance degradation.
When a high frequent calling into schedule() is detected, a warning is logged only once to help indentify this frantic caller.
Signed-off-by Stefan Roese <[email protected]>
Cc Simon Glass <[email protected]>
Cc Christophe Leroy <[email protected]>
---
- Some spelling fixes (Simon)
- Minor coding style improvement in comment (Simon)
common/Kconfig | 11 +++++++++++ common/cyclic.c | 27 +++++++++++++++++++++++++-- include/asm-generic/global_data.h | 1 + 3 files changed, 37 insertions(+), 2 deletions(-)
common/Kconfig +11 -0
@@ -601,6 +601,17 @@ config CYCLIC_MAX_CPU_TIME_US takes longer than this duration this function will get unregistered automatically. +config CYCLIC_RATELIMIT_US + int "Sets the min time/delay in us after a new call into schedule is done" + default 100 + help + The min allowed time after with a new call into the cyclic + infrastructure is allowed. This results in a rate limiting of the + all functions hooked into the cyclic interface. + As it's been noticed that on some platforms, that high frequent + calls to schedule() (replaced from WATCHDOG_RESET) may lead to a + performance degradation. + endif # CYCLIC config EVENT
common/cyclic.c +25 -2
@@ -12,6 +12,7 @@#include <log.h> #include <malloc.h> #include <time.h> +#include <linux/bug.h> #include <linux/errno.h> #include <linux/list.h> #include <asm/global_data.h>
@@ -109,8 +110,30 @@ void schedule(void)* schedule() might get called very early before the cyclic IF is * ready. Make sure to only call cyclic_run() when it's initalized. */ -if (gd) -cyclic_run (); +if (gd) { +uint64_t now; + +/* +* Add some rate limiting to not call into the cyclic IF too +* ofter. As it's been noticed that on some platforms, that +* high frequent calls to schedule() (replaced from +* WATCHDOG_RESET) may lead to a performance degradation. +* -> Do not reset the watchdog too often +*/ + now =timer_get_us (); +if (time_after_eq64 (now, gd->cyclic_next_call)) { +cyclic_run (); + gd->cyclic_next_call = now +CONFIG_CYCLIC_RATELIMIT_US ; + }else { +/* +* Throw a warning (only once) to help identifying +* frantic callers +*/ +WARN_ONCE (1 ,"schedule() called very often, now = %lld us next call at %lld us, dt = %lld us\n" , + now, gd->cyclic_next_call, + gd->cyclic_next_call - now); + } + } }int cyclic_unregister_all (void )
include/asm-generic/global_data.h +1 -0
@@ -490,6 +490,7 @@ struct global_data {* @cyclic_list: list of registered cyclic functions */ struct hlist_head cyclic_list; +uint64_t cyclic_next_call;#endif /** * @dmtag_list: List of DM tags
Signature · 1 line
2.39.2