Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4AFEFC001B0 for ; Mon, 24 Jul 2023 06:58:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AD89386851; Mon, 24 Jul 2023 08:58:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1690181899; bh=6LPMqWMKPxYVy2Jyc1rhDDDlOinVV0uzIcLmP0YBVqE=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=NoCLiYTuOflFB+vknSuSZcXX3TgzBlOztZ9S3s6ze8Wdy2C8aEE4R8FJLtzMFp1LR q9f50F+c781i0Y87Aj+tzx+lawYPF78RQxhSX+6En85b80WuEa2z5bpcaVBdG42U5u TbwOu3BhMSqMDptXsURbVUl13/HyhV3ijbFY8Fwy0pYDez8hhIvm1WbrqyJKzwuOG7 K/b+KRcmuLjViDeIuQzJqlDIU/sxaO7Gmu43tLB3TqCRrzoANIr/zf49ZfpLU+k8J3 K5bpYQJOwawilniG0ps+b9CmIbwgJ62aDUw9fGQKrPkdY6R7rWXJNQppEp3Eo2rFYD y4SsnsAb1qjTA== Received: by phobos.denx.de (Postfix, from userid 109) id 3E92D86851; Mon, 24 Jul 2023 08:58:18 +0200 (CEST) Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [IPv6:2001:67c:2050:101:465::107]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1FECA8682C for ; Mon, 24 Jul 2023 08:58:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4R8WFy1gsqz9sNW; Mon, 24 Jul 2023 08:58:14 +0200 (CEST) From: Stefan Roese To: u-boot@lists.denx.de Cc: Simon Glass , Christophe Leroy Subject: [PATCH v2] cyclic: Add rate limiting in schedule() via CYCLIC_RATELIMIT_US Date: Mon, 24 Jul 2023 08:58:13 +0200 Message-ID: <20230724065813.71548-1-sr@denx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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 Cc: Simon Glass Cc: Christophe Leroy --- - 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(-) diff --git a/common/Kconfig b/common/Kconfig index 973482f07566..7a94883f312f 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -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 diff --git a/common/cyclic.c b/common/cyclic.c index a49bfc88f5c0..9b85afc3c095 100644 --- a/common/cyclic.c +++ b/common/cyclic.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -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) diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 8fc205ded1a3..0988403d142c 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -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 -- 2.39.2