On Fri, 5 Aug 2022 at 08:26, Stefan Roese <s...@denx.de> wrote:
>
> 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 <s...@denx.de>
> ---
> v3:
> - No change
> v2:
> - Add depends on CYCLIC in Kconfig
>
>  MAINTAINERS  |  1 +
>  cmd/Kconfig  |  7 +++++++
>  cmd/Makefile |  1 +
>  cmd/cyclic.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 49 insertions(+)
>  create mode 100644 cmd/cyclic.c

Reviewed-by: Simon Glass <s...@chromium.org>

>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index bfb5da16d78b..9d9d3fdd4069 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -791,6 +791,7 @@ F:  doc/arch/m68k.rst
>  CYCLIC
>  M:     Stefan Roese <s...@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 a8260aa170d0..641c053003f0 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -2494,6 +2494,13 @@ 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 ?

It is nice for people to get the command by default rather than having
to hunt for it.

> +       help
> +         This enables the 'cyclic' command which provides information about
> +         cyclic excution functions.

execution

Also needs another line or two of info - perhaps briefly explain what
these functions are for and point to docs?

> +
>  config CMD_DIAG
>         bool "diag - Board diagnostics"
>         help
> diff --git a/cmd/Makefile b/cmd/Makefile
> index 5e43a1e022e8..c5a4fc5a5cfc 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..1714db18e480
> --- /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 <s...@denx.de>
> + */
> +
> +#include <common.h>
> +#include <command.h>
> +#include <cyclic.h>
> +
> +extern struct list_head cyclic_list;
> +
> +static int do_cyclic_list(struct cmd_tbl *cmdtp, int flag, int argc,
> +                         char *const argv[])
> +{
> +       struct cyclic_struct *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.1
>

Regards,
Simon

Reply via email to