u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: Stefan Roese <sr@denx.de>, u-boot@lists.denx.de
Cc: trini@konsulko.com, sjg@chromium.org
Subject: Re: [RFC PATCH 2/8] watchdog: Integrate watchdog triggering into the cyclic framework
Date: Mon, 29 Aug 2022 09:38:40 +0200	[thread overview]
Message-ID: <5bcfe2be-8f1b-8e8c-e122-bc0dad517a11@prevas.dk> (raw)
In-Reply-To: <20220829062313.32654-3-sr@denx.de>

On 29/08/2022 08.23, Stefan Roese wrote:
> This patch integrates the watchdog triggering into the recently added
> cyclic infrastructure. Each watchdog device that shall be triggered
> registers it's own cyclic function. This way, multiple watchdog devices
> are still supported, each via a cyclic function with separate trigger
> intervals.
> 
> Signed-off-by: Stefan Roese <sr@denx.de>
> ---
>  drivers/watchdog/Kconfig      |  2 +
>  drivers/watchdog/wdt-uclass.c | 80 +++++++++++++++++++++--------------
>  2 files changed, 50 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> index 50e6a1efba51..e55deaf906b5 100644
> --- a/drivers/watchdog/Kconfig
> +++ b/drivers/watchdog/Kconfig
> @@ -3,6 +3,7 @@ menu "Watchdog Timer Support"
>  config WATCHDOG
>  	bool "Enable U-Boot watchdog reset"
>  	depends on !HW_WATCHDOG
> +	select CYCLIC
>  	help
>  	  This option enables U-Boot watchdog support where U-Boot is using
>  	  watchdog_reset function to service watchdog device in U-Boot. Enable
> @@ -74,6 +75,7 @@ config WDT
>  	bool "Enable driver model for watchdog timer drivers"
>  	depends on DM
>  	imply WATCHDOG
> +	select CYCLIC
>  	help
>  	  Enable driver model for watchdog timer. At the moment the API
>  	  is very simple and only supports four operations:
> diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c
> index dbf556467d3c..1bf1298d0ecf 100644
> --- a/drivers/watchdog/wdt-uclass.c
> +++ b/drivers/watchdog/wdt-uclass.c
> @@ -6,6 +6,7 @@
>  #define LOG_CATEGORY UCLASS_WDT
>  
>  #include <common.h>
> +#include <cyclic.h>
>  #include <dm.h>
>  #include <errno.h>
>  #include <hang.h>
> @@ -38,8 +39,33 @@ struct wdt_priv {
>  	bool running;
>  	/* No autostart */
>  	bool noautostart;
> +
> +	struct cyclic_info *cyclic;
>  };
>  
> +static void wdt_cyclic(void *ctx)
> +{
> +	struct udevice *dev = ctx;
> +	struct wdt_priv *priv;
> +	struct uclass *uc;
> +
> +	/* Exit if GD is not ready or watchdog is not initialized yet */
> +	if (!gd || !(gd->flags & GD_FLG_WDT_READY))
> +		return;

Hm, by the time this callback can get called, which is certainly not
before it has been registered, aren't we sure that these conditions are
met? They were clearly needed in the "old" watchdog_reset because that
could end up being invoked more or less from _everywhere_. But here I
think it's redundant.

>  int initr_watchdog(void)
> @@ -105,8 +128,28 @@ int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
>  	ret = ops->start(dev, timeout_ms, flags);
>  	if (ret == 0) {
>  		struct wdt_priv *priv = dev_get_uclass_priv(dev);
> +		char str[16];
>  
>  		priv->running = true;
> +
> +		memset(str, 0, 16);
> +		if (IS_ENABLED(CONFIG_WATCHDOG)) {
> +			/* Register the watchdog driver as a cyclic function */
> +			priv->cyclic = cyclic_register(wdt_cyclic,
> +						       priv->reset_period * 1000,
> +						       dev->name, dev);
> +			if (!priv->cyclic) {
> +				printf("cyclic_register for %s failed\n",
> +				       dev->name);
> +			} else {
> +				snprintf(str, 16, "all %ldms",
> +					 priv->reset_period);
> +			}
> +		}
> +
> +		printf("WDT:   Started %s with%s servicing %s (%ds timeout)\n",

"servicing all 50ms" doesn't sound right to me. "servicing every 50ms"
perhaps? Also, even if !priv->cyclic we still seem to end here, which
doesn't seem right.

Rasmus

  reply	other threads:[~2022-08-29  7:38 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-29  6:23 [RFC PATCH 0/8] Migrate watchdog reset to cyclic infrastructure Stefan Roese
2022-08-29  6:23 ` [RFC PATCH 1/8] cmd/cyclic: Use div64 macros for division and remainder Stefan Roese
2022-08-30  2:31   ` Simon Glass
2022-08-29  6:23 ` [RFC PATCH 2/8] watchdog: Integrate watchdog triggering into the cyclic framework Stefan Roese
2022-08-29  7:38   ` Rasmus Villemoes [this message]
2022-08-29  8:09     ` Stefan Roese
2022-08-29  6:23 ` [RFC PATCH 3/8] cyclic: Introduce schedule() function Stefan Roese
2022-08-30  2:31   ` Simon Glass
2022-08-29  6:23 ` [RFC PATCH 4/8] cyclic: Use schedule() instead of WATCHDOG_RESET() Stefan Roese
2022-08-30  2:31   ` Simon Glass
2022-08-29  6:23 ` [RFC PATCH 5/8] watchdog: Get rid of ASSEMBLY hacks Stefan Roese
2022-08-29  7:50   ` Rasmus Villemoes
2022-08-29  8:31     ` Stefan Roese
2022-08-29  6:23 ` [RFC PATCH 6/8] watchdog: Remove WATCHDOG_RESET macro Stefan Roese
2022-08-30  2:31   ` Simon Glass
2022-08-29  6:23 ` [RFC PATCH 7/8] watchdog: Further cleanup Stefan Roese
2022-08-30  2:31   ` Simon Glass
2022-08-29  6:23 ` [RFC PATCH 8/8] WIP: .azure-pipelines.yml: Remove evb-ast2600 Stefan Roese
2022-09-02  4:09   ` Joel Stanley
2022-09-02  6:00     ` Joel Stanley
2022-09-02  6:14       ` Stefan Roese
2022-09-02  7:44         ` 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=5bcfe2be-8f1b-8e8c-e122-bc0dad517a11@prevas.dk \
    --to=rasmus.villemoes@prevas.dk \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).