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 6DEB7C2BB41 for ; Tue, 16 Aug 2022 10:28:48 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 492F3849BB; Tue, 16 Aug 2022 12:28:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (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=1660645713; bh=MRlO4gCH9b6RvDJbiCLQtp1ycSsF24rzrTvPh/Y8VIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=MYdbkm186a0CvH60sKm1+d1r2BjyfaQ7xV/3G6RBzWE+FMKe7ZbWHKOL4doYOAYQd bmFml7i6cBlrfA8TmiWr/RO0N6I9x0Ox088X7Us6Q9AK32KQ7J1e2tG70feBSun7qB nWG9Oj2li70tbJBk3GJAjJ36eqiIZDkws6xcCdxWZRJakhFhd+HFFvdW2RK9GGfGkE ltOnhCiJMWKgddh8iGQWC/leZIA9tddEqfBIhM5tViWVcou6gwHMRzVTUnZMYSIskD fLDtCxEQWvfWxNUXi3mBuELls0uI9Km5m8OHCSpt4vTf2sCGa9g20Uskrjka/ludno ZlOfHs6odrpaQ== Received: by phobos.denx.de (Postfix, from userid 109) id B210984912; Tue, 16 Aug 2022 12:28:25 +0200 (CEST) Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [IPv6:2001:67c:2050:101:465::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 DB5E3848C1 for ; Tue, 16 Aug 2022 12:28:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (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 [IPv6:2001:67c:2050:b231:465::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 4M6S6F0nLbz9sTB; Tue, 16 Aug 2022 12:28:21 +0200 (CEST) From: Stefan Roese To: u-boot@lists.denx.de Cc: trini@konsulko.com, sjg@chromium.org, cchavva@marvell.com, awilliams@marvell.com Subject: [PATCH v4 5/9] cyclic: Add 'cyclic list' command Date: Tue, 16 Aug 2022 12:28:12 +0200 Message-Id: <20220816102816.2938010-6-sr@denx.de> In-Reply-To: <20220816102816.2938010-1-sr@denx.de> References: <20220816102816.2938010-1-sr@denx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4M6S6F0nLbz9sTB 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.6 at phobos.denx.de X-Virus-Status: Clean This patch adds the cyclic command, which currently only supports the 'list' subcommand, to list all currently registered cyclic functions. Here an example: => cyclic list function: cyclic_demo, cpu-time: 7010 us, frequency: 99.80 times/s function: cyclic_demo2, cpu-time: 1 us, frequency: 1.13 times/s As you can see, the cpu-time is accounted, so that cyclic functions that take too long might be discovered. Additionally the frequency is logged. Signed-off-by: Stefan Roese Reviewed-by: Simon Glass --- v4: - Add 'default y' in Kconfig and extend help text - Minor spelling fix - Added Simon's RB tag v3: - No change v2: - Add depends on CYCLIC in Kconfig MAINTAINERS | 1 + cmd/Kconfig | 14 ++++++++++++++ cmd/Makefile | 1 + cmd/cyclic.c | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 cmd/cyclic.c diff --git a/MAINTAINERS b/MAINTAINERS index 61395a85a83e..e7625c0cf755 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -791,6 +791,7 @@ F: doc/arch/m68k.rst CYCLIC M: Stefan Roese S: Maintained +F: cmd/cyclic.c F: common/cyclic.c F: include/cyclic.h diff --git a/cmd/Kconfig b/cmd/Kconfig index 211ebe9c8783..eabd6921674b 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2505,6 +2505,20 @@ config CMD_CBSYSINFO memory by coreboot before jumping to U-Boot. It can be useful for debugging the beaaviour of coreboot or U-Boot. +config CMD_CYCLIC + bool "cyclic - Show information about cyclic functions" + depends on CYCLIC + default y + help + This enables the 'cyclic' command which provides information about + cyclic execution functions. This infrastructure allows registering + functions to be executed cyclically, e.g. every 100ms. These commands + are supported: + + cyclic list - list cyclic functions + + See doc/develop/cyclic.rst for more details. + config CMD_DIAG bool "diag - Board diagnostics" help diff --git a/cmd/Makefile b/cmd/Makefile index 6e87522b62e8..a0abfc623a2b 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -56,6 +56,7 @@ obj-$(CONFIG_CMD_DIAG) += diag.o endif obj-$(CONFIG_CMD_ADTIMG) += adtimg.o obj-$(CONFIG_CMD_ABOOTIMG) += abootimg.o +obj-$(CONFIG_CMD_CYCLIC) += cyclic.o obj-$(CONFIG_CMD_EVENT) += event.o obj-$(CONFIG_CMD_EXTENSION) += extension_board.o obj-$(CONFIG_CMD_ECHO) += echo.o diff --git a/cmd/cyclic.c b/cmd/cyclic.c new file mode 100644 index 000000000000..8709b64afcc1 --- /dev/null +++ b/cmd/cyclic.c @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * A general-purpose cyclic execution infrastructure, to allow "small" + * (run-time wise) functions to be executed at a specified frequency. + * Things like LED blinking or watchdog triggering are examples for such + * tasks. + * + * Copyright (C) 2022 Stefan Roese + */ + +#include +#include +#include + +extern struct list_head cyclic_list; + +static int do_cyclic_list(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct cyclic_info *cyclic, *tmp; + uint64_t cnt, freq; + + list_for_each_entry_safe(cyclic, tmp, &cyclic_list, list) { + cnt = cyclic->run_cnt * 1000000ULL * 100ULL; + freq = cnt / (timer_get_us() - cyclic->start_time_us); + printf("function: %s, cpu-time: %lld us, frequency: %lld.%02lld times/s\n", + cyclic->name, cyclic->cpu_time_us, + freq / 100, freq % 100); + } + + return 0; +} + +#ifdef CONFIG_SYS_LONGHELP +static char cyclic_help_text[] = + "cyclic list - list cyclic functions"; +#endif + +U_BOOT_CMD_WITH_SUBCMDS(cyclic, "Cyclic", cyclic_help_text, + U_BOOT_SUBCMD_MKENT(list, 1, 1, do_cyclic_list)); -- 2.37.2