From: Stefan Roese <sr@denx.de>
To: Rasmus Villemoes <ravi@prevas.dk>, u-boot@lists.denx.de
Cc: Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH 2/3] cyclic: make cyclic_register safe to call on already-registered info
Date: Thu, 8 May 2025 09:27:02 +0200 [thread overview]
Message-ID: <eec062a0-dd7a-48e7-886e-507a1345d0da@denx.de> (raw)
In-Reply-To: <20250507105821.484442-3-ravi@prevas.dk>
On 07.05.25 12:58, Rasmus Villemoes wrote:
> Now that cyclic_unregister() is safe to call on a not-registered
> cyclic_info, we can make cyclic_register() behave like the mod_timer()
> and hrtimer_start() APIs in linux, in that they don't distinguish
> between whether the timer was already enabled or not; from the point
> of the call it is, with whatever timeout/period is set in that most
> recent call.
>
> This avoids users of the cyclic API from separately keeping track of
> whether their callback is already registered or not, and even if they
> know it is, can be used for changing the period (and/or the callback
> function) without first doing unregister().
>
> See also this recent'ish message from kernel maintainer Thomas
> Gleixner on that API design for timer frameworks:
>
> https://lore.kernel.org/lkml/87ikn6sibi.ffs@tglx/
>
> First of all the question is whether add() and mod() are really
> valuable distinctions. I'm not convinced at all. Back then, when we
> introduced hrtimers, we came to the conclusion that hrtimer_start()
> is sufficient.
>
> Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
Many thanks for digging into this and improving this cyclic interface
over the time.
Reviewed-by: Stefan Roese <sr@denx.de>
Thanks,
Stefan
> ---
> common/cyclic.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/common/cyclic.c b/common/cyclic.c
> index 75662d9f613..ec952a01ee1 100644
> --- a/common/cyclic.c
> +++ b/common/cyclic.c
> @@ -43,6 +43,8 @@ static bool cyclic_is_registered(const struct cyclic_info *cyclic)
> void cyclic_register(struct cyclic_info *cyclic, cyclic_func_t func,
> uint64_t delay_us, const char *name)
> {
> + cyclic_unregister(cyclic);
> +
> memset(cyclic, 0, sizeof(*cyclic));
>
> /* Store values in struct */
Viele Grüße,
Stefan Roese
--
DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de
next prev parent reply other threads:[~2025-05-08 7:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 10:58 [PATCH 0/3] make cyclic_(un)register idempotent Rasmus Villemoes
2025-05-07 10:58 ` [PATCH 1/3] cyclic: make cyclic_unregister() idempotent Rasmus Villemoes
2025-05-08 7:26 ` Stefan Roese
2025-05-07 10:58 ` [PATCH 2/3] cyclic: make cyclic_register safe to call on already-registered info Rasmus Villemoes
2025-05-08 7:27 ` Stefan Roese [this message]
2025-05-07 10:58 ` [PATCH 3/3] cyclic: document new guarantees for cyclic_(un)register Rasmus Villemoes
2025-05-08 7:27 ` Stefan Roese
2025-05-16 16:41 ` [PATCH 0/3] make cyclic_(un)register idempotent 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=eec062a0-dd7a-48e7-886e-507a1345d0da@denx.de \
--to=sr@denx.de \
--cc=ravi@prevas.dk \
--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.