Add support for cyclic function execution infrastruture
v3 cover Add support for cyclic function execution infrastruture
This patchset adds the basic infrastructure to periodically execute code, e.g. all 100ms. Examples for such functions might be LED blinking etc. The functions that are hooked into this cyclic list should be small timewise as otherwise the execution of the other code that relies on a high frequent polling (e.g. UART rx char ready check) might be delayed too much. This patch also adds the Kconfig option CONFIG_CYCLIC_MAX_CPU_TIME_US, which configures the max allowed time for such a cyclic function. If it's execution time exceeds this time, this cyclic function will get removed from the cyclic list.
How is this cyclic functionality executed?
This patchset integrates the main function responsible for calling all registered cyclic functions cyclic_run() into the common WATCHDOG_RESET macro. This guarantees that cyclic_run() is executed very often, which is necessary for the cyclic functions to get scheduled and executed at their configured periods.
This cyclic infrastructure will be used by a board specific function on the NIC23 MIPS Octeon board, which needs to check periodically, if a PCIe FLR has occurred.
Ideas how to continue:
One idea is to rename WATCHDOG_RESET to something like SCHEDULE and move the watchdog_reset call into this cyclic infrastructure as well. Or to perhaps move the shell UART RX ready polling to a cyclic function.
It's also possible to extend the "cyclic" command, to support the creation of periodically executed shell commands (for testing etc).
Here the Azure build, without any issues:
https://dev.azure.com/sr0718/u-boot/_build/results?buildId=225&view=results
v2->v3:
- Added documentation
Thanks,
Stefan
Aaron Williams (1):
mips: octeon_nic23: Add PCIe FLR fixup via cyclic infrastructure
Stefan Roese (7):
time: Import time_after64() and friends from Linux
cyclic: Add basic support for cyclic function execution infrastruture
cyclic: Integrate cyclic infrastructure into WATCHDOG_RESET
cyclic: Integrate cyclic functionality at bootup in board_r/f
cyclic: Add 'cyclic list' command
sandbox: Add cyclic demo function
cyclic: Add documentation
MAINTAINERS | 7 + board/Marvell/octeon_nic23/board.c | 197 +++++++++++++++++++++++++++++ board/sandbox/sandbox.c | 15 +++ cmd/Kconfig | 7 + cmd/Makefile | 1 + cmd/cyclic.c | 40 ++++++ common/Kconfig | 20 +++ common/Makefile | 1 + common/board_f.c | 2 + common/board_r.c | 2 + common/cyclic.c | 112 ++++++++++++++++ configs/octeon_nic23_defconfig | 3 + configs/sandbox_defconfig | 3 + doc/develop/cyclic.rst | 50 ++++++++ doc/develop/index.rst | 1 + doc/usage/cmd/cyclic.rst | 45 +++++++ doc/usage/index.rst | 1 + fs/cramfs/uncompress.c | 2 +- include/cyclic.h | 97 ++++++++++++++ include/time.h | 19 +++ include/watchdog.h | 23 +++- 21 files changed, 644 insertions(+), 4 deletions(-) create mode 100644 cmd/cyclic.c create mode 100644 common/cyclic.c create mode 100644 doc/develop/cyclic.rst create mode 100644 doc/usage/cmd/cyclic.rst create mode 100644 include/cyclic.h
Signature · 1 line
2.37.1
PATCH v3 1/8 time: Import time_after64() and friends from Linux
When using us times it makes sense to use 64bit variables for storage. The currently implemented time_after() and friends functions only handle 32bit variables. This patch now includes the 64bit variants as well from Linux. This will be used by the upcoming generic cyclic function infrastructure.
These macros were copied from include/linux/jiffies.h of Linux 5.18.
---
v3:
- No change
v2:
- No change
include/time.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
include/time.h +19 -0
@@ -83,6 +83,25 @@ uint64_t usec_to_tick(unsigned long usec); (time_after_eq (a,b) && \time_before (a,c)) +/* Same as above, but does so with platform independent 64bit types. +* These must be used when utilizing jiffies_64 (i.e. return value of + * get_jiffies_64() */ +#define time_after64 (a,b) \ + (typecheck(__u64, a) && \ + typecheck(__u64, b) && \ + ((__s64)((b) - (a)) < 0)) +#define time_before64 (a,b) time_after64(b,a) + +#define time_after_eq64 (a,b) \ + (typecheck(__u64, a) && \ + typecheck(__u64, b) && \ + ((__s64)((a) - (b)) >= 0)) +#define time_before_eq64 (a,b) time_after_eq64(b,a) + +#define time_in_range64 (a, b, c) \ + (time_after_eq64(a, b) && \ + time_before_eq64(a, c)) +/** * usec2ticks() - Convert microseconds to internal ticks *
Signature · 1 line
2.37.1
Re: [PATCH v3 1/8] time: Import time_after64() and friends from Linux
Quoted 10 lines · Stefan Roese
When using us times it makes sense to use 64bit variables for storage. The currently implemented
time_after()and friends functions only handle 32bit variables. This patch now includes the 64bit variants as well from Linux. This will be used by the upcoming generic cyclic function infrastructure.These macros were copied from
include/linux/jiffies.hof Linux 5.18.Signed-off-by Stefan Roese <[email protected]>
Quoted 8 lines
---
v3:
- No change
v2:
- No changeinclude/time.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
PATCH v3 2/8 cyclic: Add basic support for cyclic function execution infrastruture
In reply to Stefan RoeseAdd the basic infrastructure to periodically execute code, e.g. all 100ms. Examples for such functions might be LED blinking etc. The functions that are hooked into this cyclic list should be small timewise as otherwise the execution of the other code that relies on a high frequent polling (e.g. UART rx char ready check) might be delayed too much. This patch also adds the Kconfig option CONFIG_CYCLIC_MAX_CPU_TIME_US, which configures the max allowed time for such a cyclic function. If it's execution time exceeds this time, this cyclic function will get removed from the cyclic list.
How is this cyclic functionality executed?
The following patch integrates the main function responsible for calling all registered cyclic functions cyclic_run() into the common WATCHDOG_RESET macro. This guarantees that cyclic_run() is executed very often, which is necessary for the cyclic functions to get scheduled and executed at their configured periods.
This cyclic infrastructure will be used by a board specific function on the NIC23 MIPS Octeon board, which needs to check periodically, if a PCIe FLR has occurred.
---
v3:
- No change
v2:
- Also add cyclic_register() and cyclic_unregister() as empty functions when CONFIG_CYCLIC is not defined
- Misc minor changes
MAINTAINERS | 6 +++ common/Kconfig | 20 +++++++++ common/Makefile | 1 + common/cyclic.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++ include/cyclic.h | 97 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 236 insertions(+) create mode 100644 common/cyclic.c create mode 100644 include/cyclic.h
MAINTAINERS +6 -0
@@ -788,6 +788,12 @@ T: git https://source.denx.de/u-boot/custodians/u-boot-coldfire.git F: arch/m68k/ F: doc/arch/m68k.rst +CYCLIC +M: Stefan Roese <[email protected]> +S: Maintained +F: common/cyclic.c +F: include/cyclic.h + DFU M: Lukasz Majewski <[email protected]> S: Maintained
common/Kconfig +20 -0
@@ -545,6 +545,26 @@ config DISPLAY_BOARDINFO_LATE menu "Start-up hooks" +config CYCLIC + bool "General-purpose cyclic execution mechanism" + help + This enables 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. + +if CYCLIC + +config CYCLIC_MAX_CPU_TIME_US + int "Sets the max allowed time for a cyclic function in us" + default 1000 + help + The max allowed time for a cyclic function in us. If a functions + takes longer than this duration this function will get unregistered + automatically. + +endif # CYCLIC + config EVENT bool "General-purpose event-handling mechanism" default y if SANDBOX
common/Makefile +1 -0
@@ -84,6 +84,7 @@ obj-y += malloc_simple.o endif endif +obj-$(CONFIG_CYCLIC) += cyclic.o obj-$(CONFIG_$(SPL_TPL_)EVENT) += event.o obj-$(CONFIG_$(SPL_TPL_)HASH) += hash.o
common/cyclic.c new file +112 -0
112 lines not on this page · raw message
include/cyclic.h new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
2.37.1
Re: [PATCH v3 2/8] cyclic: Add basic support for cyclic function execution infrastruture
Hi Stefan,
Quoted 31 lines · Stefan Roese
Add the basic infrastructure to periodically execute code, e.g. all 100ms. Examples for such functions might be LED blinking etc. The functions that are hooked into this cyclic list should be small timewise as otherwise the execution of the other code that relies on a high frequent polling (e.g. UART rx char ready check) might be delayed too much. This patch also adds the
KconfigoptionCONFIG_CYCLIC_MAX_CPU_TIME_US, which configures the max allowed time for such a cyclic function. If it's execution time exceeds this time, this cyclic function will get removed from the cyclic list.How is this cyclic functionality executed?
The following patch integrates the main function responsible for calling all registered cyclic functionscyclic_run()into the commonWATCHDOG_RESETmacro. This guarantees thatcyclic_run()is executed very often, which is necessary for the cyclic functions to get scheduled and executed at their configured periods.This cyclic infrastructure will be used by a board specific function on the NIC23 MIPS Octeon board, which needs to check periodically, if a PCIe FLR has occurred.
Signed-off-by Stefan Roese <[email protected]>---
v3:
- No change
v2:
- Also addcyclic_register()andcyclic_unregister()as empty functions whenCONFIG_CYCLICis not defined
- Misc minor changes
Quoted 8 lines
MAINTAINERS | 6 +++ common/Kconfig | 20 +++++++++ common/Makefile | 1 + common/cyclic.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++ include/cyclic.h | 97 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 236 insertions(+) create mode 100644 common/cyclic.c create mode 100644 include/cyclic.h
Can you document cyclic_struct - and perhaps 'struct cyclic_info' for 'struct cyclic' would be better so we don't have 'struct' in a struct?
I still do see a lot of commonality with events.
Regards,
Simon
Re: [PATCH v3 2/8] cyclic: Add basic support for cyclic function execution infrastruture
Hi Simon,
Quoted 43 lines · Simon Glass
Hi Stefan,
Quoted 31 lines · Stefan Roese
Add the basic infrastructure to periodically execute code, e.g. all 100ms. Examples for such functions might be LED blinking etc. The functions that are hooked into this cyclic list should be small timewise as otherwise the execution of the other code that relies on a high frequent polling (e.g. UART rx char ready check) might be delayed too much. This patch also adds the
KconfigoptionCONFIG_CYCLIC_MAX_CPU_TIME_US, which configures the max allowed time for such a cyclic function. If it's execution time exceeds this time, this cyclic function will get removed from the cyclic list.How is this cyclic functionality executed?
The following patch integrates the main function responsible for calling all registered cyclic functionscyclic_run()into the commonWATCHDOG_RESETmacro. This guarantees thatcyclic_run()is executed very often, which is necessary for the cyclic functions to get scheduled and executed at their configured periods.This cyclic infrastructure will be used by a board specific function on the NIC23 MIPS Octeon board, which needs to check periodically, if a PCIe FLR has occurred.
Signed-off-by Stefan Roese <[email protected]>---
v3:
- No change
v2:
- Also addcyclic_register()andcyclic_unregister()as empty functions whenCONFIG_CYCLICis not defined
- Misc minor changesQuoted 8 lines
MAINTAINERS | 6 +++ common/Kconfig | 20 +++++++++ common/Makefile | 1 + common/cyclic.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++ include/cyclic.h | 97 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 236 insertions(+)create mode 100644
common/cyclic.c
create mode 100644include/cyclic.h
Quoted 4 lines
Reviewed-by Simon Glass <[email protected]>Can you document
cyclic_struct- and perhaps 'structcyclic_info' for 'struct cyclic' would be better so we don't have 'struct' in a struct?
Agreed. My word choice was definitely not optimal. Will change in the next version.
Thanks,
Stefan
PATCH v3 3/8 cyclic: Integrate cyclic infrastructure into WATCHDOG_RESET
In reply to Stefan RoeseThis patch integrates the main function responsible for calling all registered cyclic functions cyclic_run() into the common WATCHDOG_RESET macro. This guarantees that cyclic_run() is executed very often, which is necessary for the cyclic functions to get scheduled and executed at their configured periods.
If CONFIG_WATCHDOG is not enabled, only cyclic_run() without calling watchdog_reset(). This guarantees that the cyclic functionality does not rely on CONFIG_WATCHDOG being enabled.
---
v3:
- No change
v2:
- No change
fs/cramfs/uncompress.c | 2 +- include/watchdog.h | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-)
fs/cramfs/uncompress.c +1 -1
@@ -62,7 +62,7 @@ int cramfs_uncompress_init (void) stream.avail_in =0 ;#if defined(CONFIG_HW_WATCHDOG ) || defined(CONFIG_WATCHDOG ) - stream.outcb = (cb_func )WATCHDOG_RESET ; + stream.outcb = (cb_func )watchdog_reset_func;#else stream.outcb =Z_NULL ;#endif /* CONFIG_HW_WATCHDOG */
include/watchdog.h +20 -3
@@ -11,6 +11,8 @@#define _WATCHDOG_H_#if !defined(__ASSEMBLY__) +#include <cyclic.h> +/* * Reset the watchdog timer, always returns 0 *
@@ -60,11 +62,16 @@ int init_func_watchdog_reset(void);/* Don't require the watchdog to be enabled in SPL */ #if defined(CONFIG_SPL_BUILD ) && \ !defined(CONFIG_SPL_WATCHDOG ) -#define WATCHDOG_RESET () {} +#define WATCHDOG_RESET () { \ + cyclic_run(); \ + }#else extern void watchdog_reset (void ); -#define WATCHDOG_RESET watchdog_reset +#define WATCHDOG_RESET () { \ + watchdog_reset(); \ + cyclic_run(); \ + }#endif #endif #else
@@ -74,11 +81,21 @@ int init_func_watchdog_reset(void);#if defined(__ASSEMBLY__)#define WATCHDOG_RESET /*XXX DO_NOT_DEL_THIS_COMMENT*/ #else -#define WATCHDOG_RESET () {} +#define WATCHDOG_RESET () { \ + cyclic_run(); \ + }#endif /* __ASSEMBLY__ */ #endif /* CONFIG_WATCHDOG && !__ASSEMBLY__ */ #endif /* CONFIG_HW_WATCHDOG */ +#if !defined(__ASSEMBLY__) +/* Currently only needed for fs/cramfs/uncompress.c */ +static inline void watchdog_reset_func (void ) +{ +WATCHDOG_RESET (); +} +#endif +/* * Prototypes from $(CPU)/cpu.c. */
Signature · 1 line
2.37.1
Re: [PATCH v3 3/8] cyclic: Integrate cyclic infrastructure into WATCHDOG_RESET
Hi Stefan,
Quoted 18 lines · Stefan Roese
This patch integrates the main function responsible for calling all registered cyclic functions
cyclic_run()into the commonWATCHDOG_RESETmacro. This guarantees thatcyclic_run()is executed very often, which is necessary for the cyclic functions to get scheduled and executed at their configured periods.If
CONFIG_WATCHDOGis not enabled, onlycyclic_run()without callingwatchdog_reset(). This guarantees that the cyclic functionality does not rely onCONFIG_WATCHDOGbeing enabled.Signed-off-by Stefan Roese <[email protected]>---
v3:
- No change
v2:
- No change
Quoted 3 lines
fs/cramfs/uncompress.c | 2 +- include/watchdog.h | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-)
Quoted 32 lines
fs/cramfs/uncompress.c +1
-1@@ -62,7 +62,7 @@ int cramfs_uncompress_init (void) stream.avail_in =0 ;#if defined(CONFIG_HW_WATCHDOG ) || defined(CONFIG_WATCHDOG ) - stream.outcb = (cb_func )WATCHDOG_RESET ; + stream.outcb = (cb_func )watchdog_reset_func;#else stream.outcb =Z_NULL ;#endif /* CONFIG_HW_WATCHDOG */ include/watchdog.h +2
-1@@ -11,6 +11,8 @@#define _WATCHDOG_H_#if !defined(__ASSEMBLY__) +#include <cyclic.h> +/* * Reset the watchdog timer, always returns 0 * @@ -60,11 +62,16 @@ int init_func_watchdog_reset(void);/* Don't require the watchdog to be enabled in SPL */ #if defined(CONFIG_SPL_BUILD ) && \ !defined(CONFIG_SPL_WATCHDOG ) -#define WATCHDOG_RESET () {}
include/watchdog.h int init_func_watchdog_reset(void); · line 73
Quoted 10 lines
include/watchdog.h +6
-1+#define WATCHDOG_RESET () { \ + cyclic_run(); \ + }#else extern void watchdog_reset (void ); -#define WATCHDOG_RESET watchdog_reset +#define WATCHDOG_RESET () { \ + watchdog_reset(); \ + cyclic_run(); \
Doesn't this create two function calls from every reset site? I worry about code size. I suggest creating a new function like check_watchdog() which you can define (in the C file) with IS_ENABLED() as either empty, calling watchdog_reset() and/or calling cyclic_run(). LTO should help here.
Quoted 28 lines
include/watchdog.h +12
-2+ }#endif #endif #else @@ -74,11 +81,21 @@ int init_func_watchdog_reset(void);#if defined(__ASSEMBLY__)#define WATCHDOG_RESET /*XXX DO_NOT_DEL_THIS_COMMENT*/ #else -#define WATCHDOG_RESET () {} +#define WATCHDOG_RESET () { \ + cyclic_run(); \ + }#endif /* __ASSEMBLY__ */ #endif /* CONFIG_WATCHDOG && !__ASSEMBLY__ */ #endif /* CONFIG_HW_WATCHDOG */ +#if !defined(__ASSEMBLY__) +/* Currently only needed for fs/cramfs/uncompress.c */ +static inline void watchdog_reset_func (void ) +{ +WATCHDOG_RESET (); +} +#endif +/* * Prototypes from $(CPU)/cpu.c. */ --
Quoted 2 lines
2.37.1
Regards,
Simon
Re: [PATCH v3 3/8] cyclic: Integrate cyclic infrastructure into WATCHDOG_RESET
Hi Simon,
Quoted 65 lines · Simon Glass
Hi Stefan,
Quoted 18 lines · Stefan Roese
This patch integrates the main function responsible for calling all registered cyclic functions
cyclic_run()into the commonWATCHDOG_RESETmacro. This guarantees thatcyclic_run()is executed very often, which is necessary for the cyclic functions to get scheduled and executed at their configured periods.If
CONFIG_WATCHDOGis not enabled, onlycyclic_run()without callingwatchdog_reset(). This guarantees that the cyclic functionality does not rely onCONFIG_WATCHDOGbeing enabled.Signed-off-by Stefan Roese <[email protected]>---
v3:
- No change
v2:
- No changeQuoted 3 lines
fs/cramfs/uncompress.c | 2 +- include/watchdog.h | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-)Reviewed-by Simon Glass <[email protected]>Quoted 38 lines
fs/cramfs/uncompress.c +1
-1@@ -62,7 +62,7 @@ int cramfs_uncompress_init (void) stream.avail_in =0 ;#if defined(CONFIG_HW_WATCHDOG ) || defined(CONFIG_WATCHDOG ) - stream.outcb = (cb_func )WATCHDOG_RESET ; + stream.outcb = (cb_func )watchdog_reset_func;#else stream.outcb =Z_NULL ;#endif /* CONFIG_HW_WATCHDOG */ include/watchdog.h +5
-1@@ -11,6 +11,8 @@#define _WATCHDOG_H_#if !defined(__ASSEMBLY__) +#include <cyclic.h> +/* * Reset the watchdog timer, always returns 0 * @@ -60,11 +62,16 @@ int init_func_watchdog_reset(void);/* Don't require the watchdog to be enabled in SPL */ #if defined(CONFIG_SPL_BUILD ) && \ !defined(CONFIG_SPL_WATCHDOG ) -#define WATCHDOG_RESET () {} +#define WATCHDOG_RESET () { \ + cyclic_run(); \ + }#else extern void watchdog_reset (void );
Quoted 7 lines
include/watchdog.h int init_func_watchdog_reset(void); · line 73
Quoted 4 lines
include/watchdog.h +3
-1-#define WATCHDOG_RESET watchdog_reset +#define WATCHDOG_RESET () { \ + watchdog_reset(); \ + cyclic_run(); \Doesn't this create two function calls from every reset site? I worry about code size.
Good point. Even though the world build did not trigger any new problems with oversized images.
Quoted 4 lines
I suggest creating a new function like
check_watchdog()which you can define (in the C file) withIS_ENABLED()as either empty, callingwatchdog_reset()and/or callingcyclic_run(). LTO should help here.
I tried a bit to get clean up this ugly #ifdef construct. And move this as you suggested into a C file. Just now I noticed, that we don't have a matching C file, which is compiled in all cases. wdt-uclass.c and cyclic.c are both only compiled when actually enabled in Kconfig.
So do you have some other / better idea on how to improve this?
BTW: Moving the watchdog integration into the cyclic infrastructure in some follow-up patches will make all this much cleaner AFAICT.
Thanks,
Stefan
Quoted 25 lines
Quoted 25 lines
include/watchdog.h +12
-1+ }#endif #endif #else @@ -74,11 +81,21 @@ int init_func_watchdog_reset(void);#if defined(__ASSEMBLY__)#define WATCHDOG_RESET /*XXX DO_NOT_DEL_THIS_COMMENT*/ #else -#define WATCHDOG_RESET () {} +#define WATCHDOG_RESET () { \ + cyclic_run(); \ + }#endif /* __ASSEMBLY__ */ #endif /* CONFIG_WATCHDOG && !__ASSEMBLY__ */ #endif /* CONFIG_HW_WATCHDOG */ +#if !defined(__ASSEMBLY__) +/* Currently only needed for fs/cramfs/uncompress.c */ +static inline void watchdog_reset_func (void ) +{ +WATCHDOG_RESET (); +} +#endif +/*
Quoted 8 lines
Quoted 5 lines
include/watchdog.h +0
-1* Prototypes from $(CPU)/cpu.c. */ --2.37.1
Regards,
Simon
Viele Grüße,
Stefan Roese
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Re: [PATCH v3 3/8] cyclic: Integrate cyclic infrastructure into WATCHDOG_RESET
Hi Stefan,
Quoted 90 lines · Stefan Roese
Hi Simon,
Quoted 65 lines · Simon Glass
Hi Stefan,
Quoted 18 lines · Stefan Roese
This patch integrates the main function responsible for calling all registered cyclic functions
cyclic_run()into the commonWATCHDOG_RESETmacro. This guarantees thatcyclic_run()is executed very often, which is necessary for the cyclic functions to get scheduled and executed at their configured periods.If
CONFIG_WATCHDOGis not enabled, onlycyclic_run()without callingwatchdog_reset(). This guarantees that the cyclic functionality does not rely onCONFIG_WATCHDOGbeing enabled.Signed-off-by Stefan Roese <[email protected]>---
v3:
- No change
v2:
- No changeQuoted 3 lines
fs/cramfs/uncompress.c | 2 +- include/watchdog.h | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-)Reviewed-by Simon Glass <[email protected]>Quoted 38 lines
fs/cramfs/uncompress.c +1
-1@@ -62,7 +62,7 @@ int cramfs_uncompress_init (void) stream.avail_in =0 ;#if defined(CONFIG_HW_WATCHDOG ) || defined(CONFIG_WATCHDOG ) - stream.outcb = (cb_func )WATCHDOG_RESET ; + stream.outcb = (cb_func )watchdog_reset_func;#else stream.outcb =Z_NULL ;#endif /* CONFIG_HW_WATCHDOG */ include/watchdog.h +5
-1@@ -11,6 +11,8 @@#define _WATCHDOG_H_#if !defined(__ASSEMBLY__) +#include <cyclic.h> +/* * Reset the watchdog timer, always returns 0 * @@ -60,11 +62,16 @@ int init_func_watchdog_reset(void);/* Don't require the watchdog to be enabled in SPL */ #if defined(CONFIG_SPL_BUILD ) && \ !defined(CONFIG_SPL_WATCHDOG ) -#define WATCHDOG_RESET () {} +#define WATCHDOG_RESET () { \ + cyclic_run(); \ + }#else extern void watchdog_reset (void );Quoted 7 lines
include/watchdog.h int init_func_watchdog_reset(void); · line 73
Quoted 4 lines
include/watchdog.h +3
-1-#define WATCHDOG_RESET watchdog_reset +#define WATCHDOG_RESET () { \ + watchdog_reset(); \ + cyclic_run(); \Doesn't this create two function calls from every reset site? I worry about code size.
Good point. Even though the world build did not trigger any new problems with oversized images.
Quoted 4 lines
I suggest creating a new function like
check_watchdog()which you can define (in the C file) withIS_ENABLED()as either empty, callingwatchdog_reset()and/or callingcyclic_run(). LTO should help here.I tried a bit to get clean up this ugly #ifdef construct. And move this as you suggested into a C file. Just now I noticed, that we don't have a matching C file, which is compiled in all cases.
wdt-uclass.candcyclic.care both only compiled when actually enabled inKconfig.
Quoted 4 lines
So do you have some other / better idea on how to improve this?
BTW: Moving the watchdog integration into the cyclic infrastructure in some follow-up patches will make all this much cleaner AFAICT.
If you are going to do this soon, then I suggest not working about it too much.
But you could create wdt_common.c or similar. It should be OK to always compile it since the code will be dropped if nothing calls it.
Regards,
Simon
Re: [PATCH v3 3/8] cyclic: Integrate cyclic infrastructure into WATCHDOG_RESET
Hi Simon,
Quoted 95 lines · Simon Glass
Hi Stefan,
Quoted 92 lines · Stefan Roese
Hi Simon,
Quoted 65 lines · Simon Glass
Hi Stefan,
Quoted 18 lines · Stefan Roese
This patch integrates the main function responsible for calling all registered cyclic functions
cyclic_run()into the commonWATCHDOG_RESETmacro. This guarantees thatcyclic_run()is executed very often, which is necessary for the cyclic functions to get scheduled and executed at their configured periods.If
CONFIG_WATCHDOGis not enabled, onlycyclic_run()without callingwatchdog_reset(). This guarantees that the cyclic functionality does not rely onCONFIG_WATCHDOGbeing enabled.Signed-off-by Stefan Roese <[email protected]>---
v3:
- No change
v2:
- No changeQuoted 3 lines
fs/cramfs/uncompress.c | 2 +- include/watchdog.h | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-)Reviewed-by Simon Glass <[email protected]>Quoted 38 lines
fs/cramfs/uncompress.c +1
-1@@ -62,7 +62,7 @@ int cramfs_uncompress_init (void) stream.avail_in =0 ;#if defined(CONFIG_HW_WATCHDOG ) || defined(CONFIG_WATCHDOG ) - stream.outcb = (cb_func )WATCHDOG_RESET ; + stream.outcb = (cb_func )watchdog_reset_func;#else stream.outcb =Z_NULL ;#endif /* CONFIG_HW_WATCHDOG */ include/watchdog.h +5
-1@@ -11,6 +11,8 @@#define _WATCHDOG_H_#if !defined(__ASSEMBLY__) +#include <cyclic.h> +/* * Reset the watchdog timer, always returns 0 * @@ -60,11 +62,16 @@ int init_func_watchdog_reset(void);/* Don't require the watchdog to be enabled in SPL */ #if defined(CONFIG_SPL_BUILD ) && \ !defined(CONFIG_SPL_WATCHDOG ) -#define WATCHDOG_RESET () {} +#define WATCHDOG_RESET () { \ + cyclic_run(); \ + }#else extern void watchdog_reset (void );Quoted 7 lines
include/watchdog.h int init_func_watchdog_reset(void); · line 73
Quoted 4 lines
include/watchdog.h +3
-1-#define WATCHDOG_RESET watchdog_reset +#define WATCHDOG_RESET () { \ + watchdog_reset(); \ + cyclic_run(); \Doesn't this create two function calls from every reset site? I worry about code size.
Good point. Even though the world build did not trigger any new problems with oversized images.
Quoted 4 lines
I suggest creating a new function like
check_watchdog()which you can define (in the C file) withIS_ENABLED()as either empty, callingwatchdog_reset()and/or callingcyclic_run(). LTO should help here.I tried a bit to get clean up this ugly #ifdef construct. And move this as you suggested into a C file. Just now I noticed, that we don't have a matching C file, which is compiled in all cases.
wdt-uclass.candcyclic.care both only compiled when actually enabled inKconfig.So do you have some other / better idea on how to improve this?
Quoted 7 lines
Quoted 2 lines
BTW: Moving the watchdog integration into the cyclic infrastructure in some follow-up patches will make all this much cleaner AFAICT.
If you are going to do this soon, then I suggest not working about it too much.
But you could create
wdt_common.cor similar. It should be OK to always compile it since the code will be dropped if nothing calls it.
Yes, this would be one potential intermediate "solution". I'll try to work on the WDT migration to cyclic IF soon and will keep the code in this header as-is for now.
Thanks,
Stefan
PATCH v3 4/8 cyclic: Integrate cyclic functionality at bootup in board_r/f
In reply to Stefan RoeseThis patch adds a call to cyclic_init() to board_f/r.c, enabling the common cyclic infrastructure. After this it's possible to add cyclic functions via cyclic_register().
---
v3:
- No change
v2:
- No change
common/board_f.c | 2 ++ common/board_r.c | 2 ++ 2 files changed, 4 insertions(+)
common/board_f.c +2 -0
@@ -16,6 +16,7 @@#include <console.h> #include <cpu.h> #include <cpu_func.h> +#include <cyclic.h> #include <dm.h> #include <env.h> #include <env_internal.h>
@@ -827,6 +828,7 @@ static const init_fnc_t init_sequence_f[] = { initf_malloc, log_init, initf_bootstage,/* uses its own timer, so does not need DM */ + cyclic_init, event_init, #ifdef CONFIG_BLOBLIST bloblist_init,
common/board_r.c +2 -0
@@ -13,6 +13,7 @@#include <api.h> #include <bootstage.h> #include <cpu_func.h> +#include <cyclic.h> #include <exports.h> #include <flash.h> #include <hang.h>
@@ -588,6 +589,7 @@ static int run_main_loop(void)static init_fnc_t init_sequence_r[] = { initr_trace, initr_reloc, + cyclic_init, event_init,/* TODO: could x86/PPC have this also perhaps? */ #if defined(CONFIG_ARM) || defined(CONFIG_RISCV)
Signature · 1 line
2.37.1
Re: [PATCH v3 4/8] cyclic: Integrate cyclic functionality at bootup in board_r/f
Quoted 12 lines · Stefan Roese
This patch adds a call to
cyclic_init()toboard_f/r.c, enabling the common cyclic infrastructure. After this it's possible to add cyclic functions viacyclic_register().Signed-off-by Stefan Roese <[email protected]>---
v3:
- No change
v2:
- No change
Quoted 3 lines
common/board_f.c | 2 ++ common/board_r.c | 2 ++ 2 files changed, 4 insertions(+)
PATCH v3 5/8 cyclic: Add 'cyclic list' command
In reply to Stefan RoeseThis 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.
---
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
MAINTAINERS +1 -0
@@ -791,6 +791,7 @@ F: doc/arch/m68k.rst CYCLIC M: Stefan Roese <[email protected]> S: Maintained +F: cmd/cyclic.c F: common/cyclic.c F: include/cyclic.h
cmd/Kconfig +7 -0
@@ -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 + help + This enables the 'cyclic' command which provides information about + cyclic excution functions. + config CMD_DIAG bool "diag - Board diagnostics" help
cmd/Makefile +1 -0
@@ -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
cmd/cyclic.c new file +40 -0
@@ -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 <[email protected]> +*/ + +#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));
Signature · 1 line
2.37.1
Re: [PATCH v3 5/8] cyclic: Add 'cyclic list' command
Quoted 20 lines · Stefan Roese
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/sAs 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 <[email protected]>---
v3:
- No change
v2:
- Add depends on CYCLIC inKconfig
Quoted 6 lines
MAINTAINERS | 1 + cmd/Kconfig | 7 +++++++ cmd/Makefile | 1 + cmd/cyclic.c | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 cmd/cyclic.c
Quoted 18 lines
MAINTAINERS +1
-0@@ -791,6 +791,7 @@ F: doc/arch/m68k.rst CYCLIC M: Stefan Roese <[email protected]> S: Maintained +F: cmd/cyclic.c F: common/cyclic.c F: include/cyclic.hcmd/Kconfig +0
-0
cmd/Kconfig config CMD_CBSYSINFO · line 2499
Quoted 6 lines
cmd/Kconfig +3
-0@@ -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.
cmd/Kconfig config CMD_CBSYSINFO · line 2502
Quoted 3 lines
cmd/Kconfig +3
-0+ 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?
Quoted 63 lines
cmd/Kconfig +1
-0+ config CMD_DIAG bool "diag - Board diagnostics" helpcmd/Makefile +1
-0@@ -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.ocmd/cyclic.c new file +40
-1@@ -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 <[email protected]> +*/ + +#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)); --
Quoted 2 lines
2.37.1
Regards,
Simon
Re: [PATCH v3 5/8] cyclic: Add 'cyclic list' command
Hi Simon,
Quoted 51 lines · Simon Glass
Quoted 20 lines · Stefan Roese
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/sAs 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 <[email protected]>---
v3:
- No change
v2:
- Add depends on CYCLIC inKconfigQuoted 6 lines
MAINTAINERS | 1 + cmd/Kconfig | 7 +++++++ cmd/Makefile | 1 + cmd/cyclic.c | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+)create mode 100644
cmd/cyclic.cReviewed-by Simon Glass <[email protected]>Quoted 21 lines
MAINTAINERS +1
-0@@ -791,6 +791,7 @@ F: doc/arch/m68k.rst CYCLIC M: Stefan Roese <[email protected]> S: Maintained +F: cmd/cyclic.c F: common/cyclic.c F: include/cyclic.hcmd/Kconfig +0
-0@@ -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.
Quoted 8 lines
cmd/Kconfig config CMD_CBSYSINFO · line 2499
Quoted 3 lines
cmd/Kconfig +3
-0+config CMD_CYCLIC + bool "cyclic - Show information about cyclic functions" + depends on CYCLICdefault y ?
It is nice for people to get the command by default rather than having to hunt for it.
Good idea.
Quoted 8 lines
cmd/Kconfig config CMD_CBSYSINFO · line 2502
Quoted 3 lines
cmd/Kconfig +3
-0+ 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?
Will change in the next version.
Thanks,
Stefan
Quoted 60 lines
Quoted 60 lines
cmd/Kconfig +1
-0+ config CMD_DIAG bool "diag - Board diagnostics" helpcmd/Makefile +1
-0@@ -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.ocmd/cyclic.c new file +38
-0@@ -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 <[email protected]> +*/ + +#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 +
Quoted 8 lines
Quoted 5 lines
cmd/cyclic.c new file +2
-1+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
Viele Grüße,
Stefan Roese
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
PATCH v3 6/8 sandbox: Add cyclic demo function
In reply to Stefan RoeseThis patch enables the cyclic infrastructure on sandbox and also adds one simple example/demo functions using this cyclic functionality.
---
v3:
- No change
v2:
- Extend CONFIG_CYCLIC_MAX_CPU_TIME_US to 10000ms as running this in CI might take a bit longer
board/sandbox/sandbox.c | 15 +++++++++++++++ configs/sandbox_defconfig | 3 +++ 2 files changed, 18 insertions(+)
board/sandbox/sandbox.c +15 -0
@@ -7,6 +7,7 @@#include <addr_map.h> #include <cpu_func.h> #include <cros_ec.h> +#include <cyclic.h> #include <dm.h> #include <efi.h> #include <efi_loader.h>
@@ -17,6 +18,7 @@#include <asm/global_data.h> #include <asm/test.h> #include <asm/u-boot-sandbox.h> +#include <linux/delay.h> #include <linux/kernel.h> #include <malloc.h>
@@ -106,8 +108,21 @@ int dram_init(void)return 0 ; } +static void cyclic_demo (void *ctx) +{ +/* Just a small dummy delay here */ +udelay (10 ); +} +int board_init (void ) { +struct cyclic_struct *cyclic; + +/* Register demo cyclic function */ + cyclic =cyclic_register (cyclic_demo,10 *1000 ,"cyclic_demo" ,NULL ); +if (!cyclic) +printf ("Registering of cyclic_demo failed\n" ); +return 0 ; }
configs/sandbox_defconfig +3 -0
@@ -34,6 +34,8 @@ CONFIG_LOG=y CONFIG_LOG_MAX_LEVEL=9 CONFIG_LOG_DEFAULT_LEVEL=6 CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_CYCLIC=y +CONFIG_CYCLIC_MAX_CPU_TIME_US=10000 CONFIG_STACKPROTECTOR=y CONFIG_ANDROID_AB=y CONFIG_CMD_CPU=y
@@ -114,6 +116,7 @@ CONFIG_CMD_EROFS=y CONFIG_CMD_EXT4_WRITE=y CONFIG_CMD_SQUASHFS=y CONFIG_CMD_MTDPARTS=y +CONFIG_CMD_CYCLIC=y CONFIG_CMD_STACKPROTECTOR_TEST=y CONFIG_MAC_PARTITION=y CONFIG_AMIGA_PARTITION=y
Signature · 1 line
2.37.1
Re: [PATCH v3 6/8] sandbox: Add cyclic demo function
Hi Stefan,
Quoted 12 lines · Stefan Roese
This patch enables the cyclic infrastructure on sandbox and also adds one simple example/demo functions using this cyclic functionality.
Signed-off-by Stefan Roese <[email protected]>---
v3:
- No change
v2:
- ExtendCONFIG_CYCLIC_MAX_CPU_TIME_USto 10000ms as running this in CI might take a bit longer
Quoted 3 lines
board/sandbox/sandbox.c | 15 +++++++++++++++ configs/sandbox_defconfig | 3 +++ 2 files changed, 18 insertions(+)
This should have a test in test/common - e.g. using timer_test_add_offset()
Quoted 65 lines
board/sandbox/sandbox.c +15
-0@@ -7,6 +7,7 @@#include <addr_map.h> #include <cpu_func.h> #include <cros_ec.h> +#include <cyclic.h> #include <dm.h> #include <efi.h> #include <efi_loader.h> @@ -17,6 +18,7 @@#include <asm/global_data.h> #include <asm/test.h> #include <asm/u-boot-sandbox.h> +#include <linux/delay.h> #include <linux/kernel.h> #include <malloc.h> @@ -106,8 +108,21 @@ int dram_init(void)return 0 ; } +static void cyclic_demo (void *ctx) +{ +/* Just a small dummy delay here */ +udelay (10 ); +} +int board_init (void ) { +struct cyclic_struct *cyclic; + +/* Register demo cyclic function */ + cyclic =cyclic_register (cyclic_demo,10 *1000 ,"cyclic_demo" ,NULL ); +if (!cyclic) +printf ("Registering of cyclic_demo failed\n" ); +return 0 ; }configs/sandbox_defconfig +3
-1@@ -34,6 +34,8 @@ CONFIG_LOG=y CONFIG_LOG_MAX_LEVEL=9 CONFIG_LOG_DEFAULT_LEVEL=6 CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_CYCLIC=y +CONFIG_CYCLIC_MAX_CPU_TIME_US=10000 CONFIG_STACKPROTECTOR=y CONFIG_ANDROID_AB=y CONFIG_CMD_CPU=y@@ -114,6 +116,7 @@ CONFIG_CMD_EROFS=y CONFIG_CMD_EXT4_WRITE=y CONFIG_CMD_SQUASHFS=y CONFIG_CMD_MTDPARTS=y +CONFIG_CMD_CYCLIC=y CONFIG_CMD_STACKPROTECTOR_TEST=y CONFIG_MAC_PARTITION=y CONFIG_AMIGA_PARTITION=y --
Quoted 2 lines
2.37.1
Regards,
SImon
Re: [PATCH v3 6/8] sandbox: Add cyclic demo function
Hi Simon,
Quoted 15 lines · Simon Glass
Hi Stefan,
Quoted 12 lines · Stefan Roese
This patch enables the cyclic infrastructure on sandbox and also adds one simple example/demo functions using this cyclic functionality.
Signed-off-by Stefan Roese <[email protected]>---
v3:
- No change
v2:
- ExtendCONFIG_CYCLIC_MAX_CPU_TIME_USto 10000ms as running this in CI might take a bit longer
Quoted 5 lines
Quoted 3 lines
board/sandbox/sandbox.c | 15 +++++++++++++++ configs/sandbox_defconfig | 3 +++ 2 files changed, 18 insertions(+)This should have a test in test/common - e.g. using
timer_test_add_offset()
Ok. I'll add a small test for the cyclic IF this in the next patchset version.
Thanks,
Stefan
Quoted 62 lines
Quoted 62 lines
board/sandbox/sandbox.c +15
-0@@ -7,6 +7,7 @@#include <addr_map.h> #include <cpu_func.h> #include <cros_ec.h> +#include <cyclic.h> #include <dm.h> #include <efi.h> #include <efi_loader.h> @@ -17,6 +18,7 @@#include <asm/global_data.h> #include <asm/test.h> #include <asm/u-boot-sandbox.h> +#include <linux/delay.h> #include <linux/kernel.h> #include <malloc.h> @@ -106,8 +108,21 @@ int dram_init(void)return 0 ; } +static void cyclic_demo (void *ctx) +{ +/* Just a small dummy delay here */ +udelay (10 ); +} +int board_init (void ) { +struct cyclic_struct *cyclic; + +/* Register demo cyclic function */ + cyclic =cyclic_register (cyclic_demo,10 *1000 ,"cyclic_demo" ,NULL ); +if (!cyclic) +printf ("Registering of cyclic_demo failed\n" ); +return 0 ; }configs/sandbox_defconfig +3
-0@@ -34,6 +34,8 @@ CONFIG_LOG=y CONFIG_LOG_MAX_LEVEL=9 CONFIG_LOG_DEFAULT_LEVEL=6 CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_CYCLIC=y +CONFIG_CYCLIC_MAX_CPU_TIME_US=10000 CONFIG_STACKPROTECTOR=y CONFIG_ANDROID_AB=y CONFIG_CMD_CPU=y@@ -114,6 +116,7 @@ CONFIG_CMD_EROFS=y CONFIG_CMD_EXT4_WRITE=y CONFIG_CMD_SQUASHFS=y CONFIG_CMD_MTDPARTS=y +CONFIG_CMD_CYCLIC=y CONFIG_CMD_STACKPROTECTOR_TEST=y
Quoted 8 lines
Quoted 5 lines
configs/sandbox_defconfig +0
-1CONFIG_MAC_PARTITION=y CONFIG_AMIGA_PARTITION=y --2.37.1
Regards,
SImon
Viele Grüße,
Stefan Roese
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
PATCH v3 7/8 mips: octeon_nic23: Add PCIe FLR fixup via cyclic infrastructure
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
This patch adds a fixup function related to a PCIe FLR (Function Level Reset) problem on the NIC23 PCIe board. This function is imported from the Marvell Octeon 2013 U-Boot version as a (nearly) verbatim copy. It uses the newly introduced cyclic infrastructure, so that this function gets called every 100us, which is needed to detect this FLR issue.
---
v3:
- No change
v2:
- No change
board/Marvell/octeon_nic23/board.c | 197 +++++++++++++++++++++++++++++ configs/octeon_nic23_defconfig | 3 + 2 files changed, 200 insertions(+)
board/Marvell/octeon_nic23/board.c +197 -0
@@ -3,8 +3,10 @@* Copyright (C) 2021-2022 Stefan Roese <[email protected]> */ +#include <cyclic.h> #include <dm.h> #include <ram.h> +#include <time.h> #include <asm/gpio.h> #include <mach/octeon_ddr.h>
@@ -15,11 +17,90 @@#include <mach/cvmx-helper-cfg.h> #include <mach/cvmx-helper-util.h> #include <mach/cvmx-bgxx-defs.h> +#include <mach/cvmx-dtx-defs.h> #include "board_ddr.h" +/** +* cvmx_spem#_cfg_rd +* +* This register allows read access to the configuration in the PCIe core. +* +*/ +union cvmx_spemx_cfg_rd { +u64 u64; +struct cvmx_spemx_cfg_rd_s { +u64 data :32 ; +u64 addr :32 ; + } s; +struct cvmx_spemx_cfg_rd_s cn73xx; +}; + +/** +* cvmx_spem#_cfg_wr +* +* This register allows write access to the configuration in the PCIe core. +* +*/ +union cvmx_spemx_cfg_wr { +u64 u64; +struct cvmx_spemx_cfg_wr_s { +u64 data :32 ; +u64 addr :32 ; + } s; +struct cvmx_spemx_cfg_wr_s cn73xx; +}; + +/** +* cvmx_spem#_flr_pf_stopreq +* +* PF function level reset stop outbound requests register. +* Hardware automatically sets the STOPREQ bit for the PF when it enters a +* function level reset (FLR). Software is responsible for clearing the STOPREQ +* bit but must not do so prior to hardware taking down the FLR, which could be +* as long as 100ms. It may be appropriate for software to wait longer before clearing +* STOPREQ, software may need to drain deep DPI queues for example. +* Whenever SPEM receives a PF or child VF request mastered by CNXXXX over S2M (i.e. P or NP), +* when STOPREQ is set for the function, SPEM will discard the outgoing request +* before sending it to the PCIe core. If a NP, SPEM will schedule an immediate +* SWI_RSP_ERROR completion for the request - no timeout is required. +* In both cases, SPEM()_DBG_PF()_INFO[P()_BMD_E] will be set and a error +* interrupt is generated. +* +* STOPREQ mimics the behavior of PCIEEP()_CFG001[ME] for outbound requests that will +* master the PCIe bus (P and NP). +* +* STOPREQ will have no effect on completions returned by CNXXXX over the S2M, +* nor on M2S traffic. +* +* When a PF()_STOPREQ is set, none of the associated +* PEM()_FLR_PF()_VF_STOPREQ[VF_STOPREQ] will be set. +* +* STOPREQ is reset when the MAC is reset, and is not reset after a chip soft reset. +*/ +union cvmx_spemx_flr_pf_stopreq { +u64 u64; +struct cvmx_spemx_flr_pf_stopreq_s { +u64 reserved_3_63 :61 ; +u64 pf2_stopreq :1 ; +u64 pf1_stopreq :1 ; +u64 pf0_stopreq :1 ; + } s; +struct cvmx_spemx_flr_pf_stopreq_s cn73xx; +}; + +#define CVMX_SPEMX_CFG_WR (offset) 0x00011800C0000028ull +#define CVMX_SPEMX_CFG_RD (offset) 0x00011800C0000030ull +#define CVMX_SPEMX_FLR_PF_STOPREQ (offset) 0x00011800C0000218ull + +#define DTX_SELECT_LTSSM 0x0 +#define DTX_SELECT_LTSSM_ENA 0x3ff +#define LTSSM_L0 0x11 +#define NIC23_DEF_DRAM_FREQ 800 +static u32 pci_cfgspace_reg0[2 ] = {0 ,0 }; +static u8 octeon_nic23_cfg0_spd_values[512 ] = {OCTEON_NIC23_CFG0_SPD_VALUES };
@@ -145,8 +226,118 @@ void board_configure_qlms(void) cvmx_qlm_measure_clock(4), cvmx_qlm_measure_clock(5)); } +/** +* If there is a PF FLR then the PCI EEPROM is not re-read. In this case +* we need to re-program the vendor and device ID immediately after hardware +* completes FLR. +* +* PCI spec requires FLR to be completed within 100ms. The user who triggered +* FLR expects hardware to finish FLR within 100ms, otherwise the user will +* end up reading DEVICE_ID incorrectly from the reset value. +* CN23XX exits FLR at any point between 66 and 99ms, so U-Boot has to wait +* 99ms to let hardware finish its part, then finish reprogramming the +* correct device ID before the end of 100ms. +* +* Note: this solution only works properly when there is no other activity +* within U-Boot for 100ms from the time FLR is triggered. +* +* This function gets called every 100usec. If FLR happens during any +* other activity like bootloader/image update then it is possible that +* this function does not get called for more than the FLR period which will +* cause the PF device ID restore to happen after whoever initiated the FLR to +* read the incorrect device ID 0x9700 (reset value) instead of 0x9702 +* (restored value). +*/ +static void octeon_board_restore_pf (void *ctx) +{ +union cvmx_spemx_flr_pf_stopreq stopreq; +static bool start_initialized[2 ] = {false, false}; +bool pf0_flag, pf1_flag; +u64 ltssm_bits; +const u64 pf_flr_wait_usecs =99700 ; +u64 elapsed_usecs; +union cvmx_spemx_cfg_wr cfg_wr; +union cvmx_spemx_cfg_rd cfg_rd; +static u64 start_us[2 ]; +int pf_num; + +csr_wr (CVMX_DTX_SPEM_SELX (0 ),DTX_SELECT_LTSSM ); +csr_rd (CVMX_DTX_SPEM_SELX (0 )); +csr_wr (CVMX_DTX_SPEM_ENAX (0 ),DTX_SELECT_LTSSM_ENA ); +csr_rd (CVMX_DTX_SPEM_ENAX (0 )); + ltssm_bits =csr_rd (CVMX_DTX_SPEM_DATX (0 )); +if (((ltssm_bits >>3 ) &0x3f ) !=LTSSM_L0 ) +return ; + + stopreq.u64 =csr_rd (CVMX_SPEMX_FLR_PF_STOPREQ (0 )); + pf0_flag = stopreq.s.pf0_stopreq; + pf1_flag = stopreq.s.pf1_stopreq; +/* See if PF interrupt happened */ +if (!(pf0_flag || pf1_flag)) +return ; + +if (pf0_flag && !start_initialized[0 ]) { + start_initialized[0 ] = true; + start_us[0 ] =get_timer_us (0 ); + } + +/* Store programmed PCIe DevID SPEM0 PF0 */ +if (pf0_flag && !pci_cfgspace_reg0[0 ]) { + cfg_rd.s.addr = (0 <<24 ) |0x0 ; +csr_wr (CVMX_SPEMX_CFG_RD (0 ), cfg_rd.u64); + cfg_rd.u64 =csr_rd (CVMX_SPEMX_CFG_RD (0 )); + pci_cfgspace_reg0[0 ] = cfg_rd.s.data; + } + +if (pf1_flag && !start_initialized[1 ]) { + start_initialized[1 ] = true; + start_us[1 ] =get_timer_us (0 ); + } + +/* Store programmed PCIe DevID SPEM0 PF1 */ +if (pf1_flag && !pci_cfgspace_reg0[1 ]) { + cfg_rd.s.addr = (1 <<24 ) |0x0 ; +csr_wr (CVMX_SPEMX_CFG_RD (0 ), cfg_rd.u64); + cfg_rd.u64 =csr_rd (CVMX_SPEMX_CFG_RD (0 )); + pci_cfgspace_reg0[1 ] = cfg_rd.s.data; + } + +/* For PF, rewrite pci config space reg 0 */ +for (pf_num =0 ; pf_num <2 ; pf_num++) { +if (!start_initialized[pf_num]) +continue ; + + elapsed_usecs =get_timer_us (0 ) - start_us[pf_num]; + +if (elapsed_usecs > pf_flr_wait_usecs) { +/* Here, our measured FLR duration has passed; +* check if device ID has been reset, +* which indicates FLR completion (per MA team). +*/ + cfg_rd.s.addr = (pf_num <<24 ) |0x0 ; +csr_wr (CVMX_SPEMX_CFG_RD (0 ), cfg_rd.u64); + cfg_rd.u64 =csr_rd (CVMX_SPEMX_CFG_RD (0 )); +/* if DevID has NOT been reset, FLR is not yet +* complete +*/ +if (cfg_rd.s.data != pci_cfgspace_reg0[pf_num]) { + stopreq.s.pf0_stopreq = (pf_num ==0 ) ?1 :0 ; + stopreq.s.pf1_stopreq = (pf_num ==1 ) ?1 :0 ; +csr_wr (CVMX_SPEMX_FLR_PF_STOPREQ (0 ), stopreq.u64); + + cfg_wr.u64 =0 ; + cfg_wr.s.addr = (pf_num <<24 ) |0 ; + cfg_wr.s.data = pci_cfgspace_reg0[pf_num]; +csr_wr (CVMX_SPEMX_CFG_WR (0 ), cfg_wr.u64); + start_initialized[pf_num] = false; + } + } + } +} +int board_late_init (void ) { +struct cyclic_struct *cyclic;struct gpio_desc gpio = {};ofnode node;
@@ -164,6 +355,12 @@ int board_late_init(void)board_configure_qlms (); +/* Register cyclic function for PCIe FLR fixup */ + cyclic =cyclic_register (octeon_board_restore_pf,100 , +"pcie_flr_fix" ,NULL ); +if (!cyclic) +printf ("Registering of cyclic function failed\n" ); +return 0 ; }
configs/octeon_nic23_defconfig +3 -0
@@ -20,6 +20,8 @@ CONFIG_AHCI=y CONFIG_OF_BOARD_FIXUP=y CONFIG_SYS_CONSOLE_ENV_OVERWRITE=y # CONFIG_SYS_DEVICE_NULLDEV is not set +CONFIG_CYCLIC=y +CONFIG_CYCLIC_MAX_CPU_TIME_US=5000 CONFIG_ARCH_MISC_INIT=y CONFIG_BOARD_EARLY_INIT_F=y CONFIG_BOARD_LATE_INIT=y
@@ -41,6 +43,7 @@ CONFIG_CMD_TIME=y CONFIG_CMD_EXT4=y CONFIG_CMD_FAT=y CONFIG_CMD_FS_GENERIC=y +CONFIG_CMD_CYCLIC=y CONFIG_EFI_PARTITION=y CONFIG_ENV_IS_IN_SPI_FLASH=y CONFIG_TFTP_TSIZE=y
Signature · 1 line
2.37.1
PATCH v3 8/8 cyclic: Add documentation
In reply to Stefan RoeseAdd documentation for the cyclic function infrastructure, including the cyclic command.
---
v3:
- New patch
doc/develop/cyclic.rst | 50 ++++++++++++++++++++++++++++++++++++++++ doc/develop/index.rst | 1 + doc/usage/cmd/cyclic.rst | 45 ++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 4 files changed, 97 insertions(+) create mode 100644 doc/develop/cyclic.rst create mode 100644 doc/usage/cmd/cyclic.rst
doc/develop/cyclic.rst new file +50 -0
@@ -0,0 +1,50 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +Cyclic functions +================ + +The cyclic function execution infrastruture provides a way to periodically +execute code, e.g. all 100ms. Examples for such functions might be LED +blinking etc. The functions that are hooked into this cyclic list should +be small timewise as otherwise the execution of the other code that relies +on a high frequent polling (e.g. UART rx char ready check) might be +delayed too much. To detect cyclic functions with a too long execution +time, the Kconfig option `CONFIG_CYCLIC_MAX_CPU_TIME_US` is introduced, +which configures the max allowed time for such a cyclic function. If it's +execution time exceeds this time, this cyclic function will get removed +from the cyclic list. + +Registering a cyclic function +----------------------------- + +To register a cyclic function, use something like this:: + + static void cyclic_demo(void *ctx) + { + /* Just a small dummy delay here */ + udelay(10); + } + + int board_init(void) + { + struct cyclic_struct *cyclic; + + /* Register demo cyclic function */ + cyclic = cyclic_register(cyclic_demo, 10 * 1000, "cyclic_demo", NULL); + if (!cyclic) + printf("Registering of cyclic_demo failed\n"); + + return 0; + } + +This will register the function `cyclic_demo()` to be periodically +executed all 10ms. + +How is this cyclic functionality integrated / executed? +-------------------------------------------------------- + +The cyclic infrastructure integrates the main function responsible for +calling all registered cyclic functions cyclic_run() into the common +WATCHDOG_RESET macro. This guarantees that cyclic_run() is executed +very often, which is necessary for the cyclic functions to get scheduled +and executed at their configured periods.
doc/develop/index.rst +1 -0
@@ -26,6 +26,7 @@ Implementation ci_testing commands config_binding + cyclic devicetree/index distro driver-model/index
doc/usage/cmd/cyclic.rst new file +45 -0
45 lines not on this page · raw message
doc/usage/index.rst +1 -0
@@ -33,6 +33,7 @@ Shell commands cmd/bootz cmd/cbsysinfo cmd/conitrace + cmd/cyclic cmd/dm cmd/echo cmd/env
Signature · 1 line
2.37.1
Re: [PATCH v3 8/8] cyclic: Add documentation
Hi Stefan,
Quoted 9 lines · Stefan Roese
Add documentation for the cyclic function infrastructure, including the cyclic command.
Signed-off-by Stefan Roese <[email protected]>---
v3:
- New patch
Quoted 7 lines
doc/develop/cyclic.rst | 50 ++++++++++++++++++++++++++++++++++++++++ doc/develop/index.rst | 1 + doc/usage/cmd/cyclic.rst | 45 ++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 4 files changed, 97 insertions(+) create mode 100644 doc/develop/cyclic.rst create mode 100644 doc/usage/cmd/cyclic.rst
Quoted 7 lines
doc/develop/cyclic.rst new file +0
-0
doc/develop/cyclic.rst line 7
Quoted 7 lines
doc/develop/cyclic.rst new file +7
-0@@ -0,0 +1,50 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +Cyclic functions +================ + +The cyclic function execution infrastruture provides a way to periodically +execute code, e.g. all 100ms. Examples for such functions might be LED
s/all/every/ ?
doc/develop/cyclic.rst line 15
Quoted 8 lines
doc/develop/cyclic.rst new file +8
-0+blinking etc. The functions that are hooked into this cyclic list should +be small timewise as otherwise the execution of the other code that relies +on a high frequent polling (e.g. UART rx char ready check) might be +delayed too much. To detect cyclic functions with a too long execution +time, the Kconfig option `CONFIG_CYCLIC_MAX_CPU_TIME_US` is introduced, +which configures the max allowed time for such a cyclic function. If it's +execution time exceeds this time, this cyclic function will get removed +from the cyclic list.
[..]
Regards,
SImon
Re: [PATCH v3 8/8] cyclic: Add documentation
Hi Simon.
Quoted 23 lines · Simon Glass
Hi Stefan,
Quoted 9 lines · Stefan Roese
Add documentation for the cyclic function infrastructure, including the cyclic command.
Signed-off-by Stefan Roese <[email protected]>---
v3:
- New patchQuoted 7 lines
doc/develop/cyclic.rst | 50 ++++++++++++++++++++++++++++++++++++++++ doc/develop/index.rst | 1 + doc/usage/cmd/cyclic.rst | 45 ++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 4 files changed, 97 insertions(+)create mode 100644
doc/develop/cyclic.rst
create mode 100644doc/usage/cmd/cyclic.rstReviewed-by Simon Glass <[email protected]>Quoted 1 line
Quoted 15 lines
doc/develop/cyclic.rst line 7
Quoted 13 lines
doc/develop/cyclic.rst new file +7
-0@@ -0,0 +1,50 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +Cyclic functions +================ + +The cyclic function execution infrastruture provides a way to periodically +execute code, e.g. all 100ms. Examples for such functions might be LEDs/all/every/ ?
Thanks, changed in the next version.
Thanks,
Stefan
Quoted 11 lines
Quoted 8 lines
doc/develop/cyclic.rst new file +8
-0+blinking etc. The functions that are hooked into this cyclic list should +be small timewise as otherwise the execution of the other code that relies +on a high frequent polling (e.g. UART rx char ready check) might be +delayed too much. To detect cyclic functions with a too long execution +time, the Kconfig option `CONFIG_CYCLIC_MAX_CPU_TIME_US` is introduced, +which configures the max allowed time for such a cyclic function. If it's +execution time exceeds this time, this cyclic function will get removed +from the cyclic list.[..]
Quoted 2 lines
Regards,
SImon
Viele Grüße,
Stefan Roese
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]