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 0EEFDC001B0 for ; Thu, 13 Jul 2023 14:17:28 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6C30E86C88; Thu, 13 Jul 2023 16:17:26 +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=1689257846; bh=9KxrIZAQBb7yvbRsrogzwkrX1YGZF6QwZlzfg6dDneY=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=wxaRlVmbkfkYmROBDe7Qk1pGWRoqjCYSaC+MF7jjeZPRm0t1Dof7rkrKbRn8wSO6r gDafu1yu5ylBSthVRvXkYjhiQwGgh3XXhrB1GWHWA9wX7jgk8gqIOiF61ENEVWrU4H TVScNaGutFXxM8ihDPWjzE6W2ZsA1SAE8Vototfl1/mZXStoUejcQgGKZwNC9Qw/Hc hOKSY9ZF1H0aHc0TiN0SHr5yoLY2Cq53g259OsjdmBcPtTp0N/VJL7CtSotw8oaXpD 5/7NiAmxuP8AFkq2BVGUXOjkeiypuvV4mSKwv+rhj/4PuemWAmWcnmfuz2bcScVM0a p8fAiZlKEMwrQ== Received: by phobos.denx.de (Postfix, from userid 109) id 343BB86C8C; Thu, 13 Jul 2023 16:17:25 +0200 (CEST) Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [80.241.59.204]) (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 185A886C49 for ; Thu, 13 Jul 2023 16:17:23 +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 smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (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-204.mailbox.org (Postfix) with ESMTPS id 4R1xWj0dp3z9sW3; Thu, 13 Jul 2023 16:17:21 +0200 (CEST) From: Stefan Roese To: u-boot@lists.denx.de Cc: Simon Glass , Christophe Leroy Subject: [PATCH] cyclic: Add ratelimiting schedule() via CYCLIC_RATELIMIT_US Date: Thu, 13 Jul 2023 16:17:20 +0200 Message-ID: <20230713141720.141513-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 ratelimiting 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 degration. 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 --- 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 42baca20a618..0611cce301a5 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 ratelimiting 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 degration. + endif # CYCLIC config EVENT diff --git a/common/cyclic.c b/common/cyclic.c index a49bfc88f5c0..c945ae55c965 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 ratelimiting 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 degration. + */ + /* 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 a1e1b9d64005..af26ae4dfc65 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -484,6 +484,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.41.0