From patchwork Mon Jul 24 06:58:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 1811541 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=NoCLiYTu; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R8WG603RYz1yYC for ; Mon, 24 Jul 2023 16:58:21 +1000 (AEST) 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) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NEUTRAL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 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 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