From: Stefan Roese <sr@denx.de>
To: u-boot@lists.denx.de
Cc: trini@konsulko.com, sjg@chromium.org, awilliams@marvell.com,
cchavva@marvell.com
Subject: [PATCH v6 5/8] cyclic: Add 'cyclic list' and 'cyclic demo' commands
Date: Fri, 2 Sep 2022 13:57:51 +0200 [thread overview]
Message-ID: <20220902115754.1280789-6-sr@denx.de> (raw)
In-Reply-To: <20220902115754.1280789-1-sr@denx.de>
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.
The 'cyclic demo' commands registers the cyclic_demo() function to
be executed all 'cycletime_ms' milliseconds. The only thing this
function does is delaying by 'delay_us' microseconds.
Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
v6:
- Use cyclic_get_list()
- Use div64 macros for division and remainder
v5:
- Add 'cyclic demo' command
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 | 16 ++++++++++
cmd/Makefile | 1 +
cmd/cyclic.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 102 insertions(+)
create mode 100644 cmd/cyclic.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 7255b8286ae2..87eef2f1b259 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -791,6 +791,7 @@ F: doc/arch/m68k.rst
CYCLIC
M: Stefan Roese <sr@denx.de>
S: Maintained
+F: cmd/cyclic.c
F: common/cyclic.c
F: include/cyclic.h
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 8ea064b8d2fb..0649ffcbdf8e 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2505,6 +2505,22 @@ 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
+ cyclic cyclic demo <cycletime_ms> <delay_us> - register cyclic
+ demo function
+
+ 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..c1bc556aade9
--- /dev/null
+++ b/cmd/cyclic.c
@@ -0,0 +1,84 @@
+// 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 <sr@denx.de>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <cyclic.h>
+#include <div64.h>
+#include <malloc.h>
+#include <linux/delay.h>
+
+struct cyclic_demo_info {
+ uint delay_us;
+};
+
+static void cyclic_demo(void *ctx)
+{
+ struct cyclic_demo_info *info = ctx;
+
+ /* Just a small dummy delay here */
+ udelay(info->delay_us);
+}
+
+static int do_cyclic_demo(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct cyclic_demo_info *info;
+ struct cyclic_info *cyclic;
+ uint time_ms;
+
+ if (argc < 3)
+ return CMD_RET_USAGE;
+
+ info = malloc(sizeof(struct cyclic_demo_info));
+ if (!info) {
+ printf("out of memory\n");
+ return CMD_RET_FAILURE;
+ }
+
+ time_ms = simple_strtoul(argv[1], NULL, 0);
+ info->delay_us = simple_strtoul(argv[2], NULL, 0);
+
+ /* Register demo cyclic function */
+ cyclic = cyclic_register(cyclic_demo, time_ms * 1000, "cyclic_demo",
+ info);
+ if (!cyclic)
+ printf("Registering of cyclic_demo failed\n");
+
+ printf("Registered function \"%s\" to be executed all %dms\n",
+ "cyclic_demo", time_ms);
+
+ return 0;
+}
+
+static int do_cyclic_list(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct cyclic_info *cyclic, *tmp;
+ u64 cnt, freq;
+
+ list_for_each_entry_safe(cyclic, tmp, cyclic_get_list(), list) {
+ cnt = cyclic->run_cnt * 1000000ULL * 100ULL;
+ freq = lldiv(cnt, timer_get_us() - cyclic->start_time_us);
+ printf("function: %s, cpu-time: %lld us, frequency: %lld.%02d times/s\n",
+ cyclic->name, cyclic->cpu_time_us,
+ lldiv(freq, 100), do_div(freq, 100));
+ }
+
+ return 0;
+}
+
+static char cyclic_help_text[] =
+ "cyclic demo <cycletime_ms> <delay_us> - register cyclic demo function\n"
+ "cyclic list - list cyclic functions\n";
+
+U_BOOT_CMD_WITH_SUBCMDS(cyclic, "Cyclic", cyclic_help_text,
+ U_BOOT_SUBCMD_MKENT(demo, 3, 1, do_cyclic_demo),
+ U_BOOT_SUBCMD_MKENT(list, 1, 1, do_cyclic_list));
--
2.37.3
next prev parent reply other threads:[~2022-09-02 11:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-02 11:57 [PATCH v6 0/8] Add support for cyclic function execution infrastruture Stefan Roese
2022-09-02 11:57 ` [PATCH v6 1/8] time: Import time_after64() and friends from Linux Stefan Roese
2022-09-02 11:57 ` [PATCH v6 2/8] cyclic: Add basic support for cyclic function execution infrastruture Stefan Roese
2022-09-02 11:57 ` [PATCH v6 3/8] cyclic: Integrate cyclic infrastructure into WATCHDOG_RESET Stefan Roese
2022-09-02 11:57 ` [PATCH v6 4/8] cyclic: Integrate cyclic functionality at bootup in board_r/f Stefan Roese
2022-09-02 11:57 ` Stefan Roese [this message]
2022-09-02 11:57 ` [PATCH v6 6/8] mips: octeon_nic23: Add PCIe FLR fixup via cyclic infrastructure Stefan Roese
2022-09-02 11:57 ` [PATCH v6 7/8] cyclic: Add documentation Stefan Roese
2022-09-02 11:57 ` [PATCH v6 8/8] cyclic: Add a simple test Stefan Roese
2022-09-14 12:58 ` [PATCH v6 0/8] Add support for cyclic function execution infrastruture Tom Rini
2022-09-14 14:29 ` Stefan Roese
2022-09-14 14:47 ` Tom Rini
2022-09-14 15:18 ` Stefan Roese
2022-09-14 17:09 ` Simon Glass
2022-09-15 4:58 ` Stefan Roese
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220902115754.1280789-6-sr@denx.de \
--to=sr@denx.de \
--cc=awilliams@marvell.com \
--cc=cchavva@marvell.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.