<feed xmlns='http://www.w3.org/2005/Atom'>
<title>u-boot.git/common/cyclic.c, branch main</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.</subtitle>
<id>http://cgit.235523.xyz/u-boot.git/atom/common/cyclic.c?h=main</id>
<link rel='self' href='http://cgit.235523.xyz/u-boot.git/atom/common/cyclic.c?h=main'/>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/'/>
<updated>2026-07-16T22:11:19Z</updated>
<entry>
<title>cyclic: reduce get_timer_us() calls inside hlist_for_each_entry_safe()</title>
<updated>2026-07-16T22:11:19Z</updated>
<author>
<name>Patrice Chotard</name>
<email>patrice.chotard@foss.st.com</email>
</author>
<published>2026-07-06T16:06:09Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=9c1b13b3fd271500cd8a61f86816d822e4852a90'/>
<id>urn:sha1:9c1b13b3fd271500cd8a61f86816d822e4852a90</id>
<content type='text'>
On STM32MP157C-DK2, when using the "ums" command, in sleep_thread(),
ctrlc() is called every ~640ms which doesn't allows high reactivity when
user press CTRL+C in U-Boot console.

In sleep_thread() loop, ctrlc() is called every 200000 iterations.
But schedule is called on each loop iteration.

Optimize cyclic_run() in order to not call get_timer_us() on each entry.

This allow to save computation time :
  _ before : ctrlc() is called every ~640ms
  _ after  : ctrlc() is called every ~230ms

Signed-off-by: Rasmus Villemoes &lt;rv@rasmusvillemoes.dk&gt;
Signed-off-by: Patrice Chotard &lt;patrice.chotard@foss.st.com&gt;
Cc: Marek Vasut &lt;marek.vasut@mailbox.org&gt;
</content>
</entry>
<entry>
<title>cyclic: replace uint64_t by u64 suggested by b4</title>
<updated>2026-07-16T22:11:11Z</updated>
<author>
<name>Patrice Chotard</name>
<email>patrice.chotard@foss.st.com</email>
</author>
<published>2026-07-06T16:06:08Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=08af4faa0f0eac4622e52e699729bd157d6d806a'/>
<id>urn:sha1:08af4faa0f0eac4622e52e699729bd157d6d806a</id>
<content type='text'>
For new patch, b4 is suggested to replace type 'uint64_t' by 'u64' :
      CHECK: Prefer kernel type 'u64' over 'uint64_t'

Update cyclic.c accordingly in order to be coherent with following commit.

Signed-off-by: Patrice Chotard &lt;patrice.chotard@foss.st.com&gt;
Reviewed-by: Marek Vasut &lt;marek.vasut@mailbox.org&gt;
</content>
</entry>
<entry>
<title>cyclic: make cyclic_register safe to call on already-registered info</title>
<updated>2025-05-16T11:44:19Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>ravi@prevas.dk</email>
</author>
<published>2025-05-07T10:58:20Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=5265143ac7356b94ace3e26a9fd6df17774b189b'/>
<id>urn:sha1:5265143ac7356b94ace3e26a9fd6df17774b189b</id>
<content type='text'>
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 &lt;ravi@prevas.dk&gt;
Reviewed-by: Stefan Roese &lt;sr@denx.de&gt;
</content>
</entry>
<entry>
<title>cyclic: make cyclic_unregister() idempotent</title>
<updated>2025-05-16T11:44:19Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>ravi@prevas.dk</email>
</author>
<published>2025-05-07T10:58:19Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=2dbd9101b9910fe2c0fc2c23bc4d13a2604e9cca'/>
<id>urn:sha1:2dbd9101b9910fe2c0fc2c23bc4d13a2604e9cca</id>
<content type='text'>
Make cyclic_unregister() safe to call with an already unregistered, or
possibly never registered, struct cyclic_info. This is similar to how
the various timer APIs in the linux kernel work (they all allow
calling delete/cancel/... on an inactive timer object).

This means callers don't have to separately keep track of whether
their cyclic callback is registered or not, and avoids them trying to
peek into the struct cyclic_info for that information - which leads to
somewhat ugly code as it would have to be guarded by ifdef
CONFIG_CYCLIC.

Signed-off-by: Rasmus Villemoes &lt;ravi@prevas.dk&gt;
Reviewed-by: Stefan Roese &lt;sr@denx.de&gt;
</content>
</entry>
<entry>
<title>cyclic: invoke uthread_schedule() from schedule()</title>
<updated>2025-04-23T19:19:44Z</updated>
<author>
<name>Jerome Forissier</name>
<email>jerome.forissier@linaro.org</email>
</author>
<published>2025-04-18T14:09:36Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=e831370af5102d8059d4f20d3317e2c39565e9af'/>
<id>urn:sha1:e831370af5102d8059d4f20d3317e2c39565e9af</id>
<content type='text'>
Make the schedule() call from the CYCLIC framework a uthread scheduling
point too. This makes sense since schedule() is called from a lot of
places where uthread_schedule() needs to be called.

Signed-off-by: Jerome Forissier &lt;jerome.forissier@linaro.org&gt;
Reviewed-by: Ilias Apalodimas &lt;ilias.apalodimas@linaro.org&gt;
Reviewed-by: Stefan Roese &lt;sr@denx.de&gt;
</content>
</entry>
<entry>
<title>cyclic: Fix rollover every 72 min on 32 bits platforms</title>
<updated>2025-01-22T09:22:34Z</updated>
<author>
<name>Patrice Chotard</name>
<email>patrice.chotard@foss.st.com</email>
</author>
<published>2025-01-14T13:28:13Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=302f866e5c2671919f4900983a59476966c84156'/>
<id>urn:sha1:302f866e5c2671919f4900983a59476966c84156</id>
<content type='text'>
On 32 bits platforms, timer_get_us() returns an unsigned long which
is a 32 bits. timer_get_us() wraps around every 72 minutes
(2 ^ 32 / 1000000 =~ 4295 sec =~ 72 min).

So the test "if time_after_eq64(now, cyclic-&gt;next_call)" is no more
true when cyclic-&gt;next_call becomes above 32 bits max value (4294967295).

At this point after 72 min, no more cyclic function are
executed included watchdog one.

Instead of using timer_get_us(), use get_timer_us() which returns a
uint64_t, this allows a rollover every 584942 years.

Signed-off-by: Patrice Chotard &lt;patrice.chotard@foss.st.com&gt;
Reviewed-by: Stefan Roese &lt;sr@denx.de&gt;
</content>
</entry>
<entry>
<title>cyclic: make cyclic_run static</title>
<updated>2024-10-23T04:52:38Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>ravi@prevas.dk</email>
</author>
<published>2024-10-03T21:27:56Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=307449de9058657eef544043013e8655468b3032'/>
<id>urn:sha1:307449de9058657eef544043013e8655468b3032</id>
<content type='text'>
The only caller left is schedule(); everybody outside cyclic.c now
calls or references schedule().

Signed-off-by: Rasmus Villemoes &lt;ravi@prevas.dk&gt;
Reviewed-by: Simon Glass &lt;sjg@chromium.org&gt;
Reviewed-by: Stefan Roese &lt;sr@denx.de&gt;
</content>
</entry>
<entry>
<title>cyclic: introduce u-boot/schedule.h</title>
<updated>2024-10-23T04:52:38Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>ravi@prevas.dk</email>
</author>
<published>2024-10-03T21:27:51Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=4457e5c61d825a2673547e4cd60570a77fbcc3cd'/>
<id>urn:sha1:4457e5c61d825a2673547e4cd60570a77fbcc3cd</id>
<content type='text'>
I noticed an "unnecessary" include of &lt;cyclic.h&gt; in
global_data.h, in the sense that nothing in cyclic.h is needed in
order to define 'struct global_data'.

Well, it's not unnecessary, as it implicitly ensures that everybody
gets a declaration of schedule(), and schedule() is (obviously) called
all over the tree. Almost none of those places directly include
&lt;cyclic.h&gt;, but for historical reasons, many do include
&lt;watchdog.h&gt; (most schedule() instances are replacements of
WATCHDOG_RESET()).

However, very few TUs actually need the declarations of the
cyclic_register() and struct cyclic_info, and they also don't really
need anything from the watchdog.h header.

So introduce a new header which just contains a declaration of
schedule(), which can then be included from all the places that do
call schedule(). I removed the direct reference to cyclic_run(),
because we shouldn't have two public functions for doing roughly the
same without being very explicit about when one should call one or the
other.

Testing of later patches that explicitly include &lt;schedule.h&gt; when
schedule() is used revealed a problem with host tool build on win32,
which apparently picked up a host &lt;schedule.h&gt;. To avoid that problem,
put the new header in include/u-boot/ and hence make the include
statements say &lt;u-boot/schedule.h&gt;.

Signed-off-by: Rasmus Villemoes &lt;ravi@prevas.dk&gt;
Reviewed-by: Simon Glass &lt;sjg@chromium.org&gt;
Reviewed-by: Stefan Roese &lt;sr@denx.de&gt;
</content>
</entry>
<entry>
<title>cyclic: make clients embed a struct cyclic_info in their own data structure</title>
<updated>2024-06-16T10:13:44Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>rasmus.villemoes@prevas.dk</email>
</author>
<published>2024-05-21T08:46:52Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=008c4b3c3115f7f95467773f12bad0db7649e786'/>
<id>urn:sha1:008c4b3c3115f7f95467773f12bad0db7649e786</id>
<content type='text'>
There are of course not a whole lot of examples in-tree yet, but
before they appear, let's make this API change: Instead of separately
allocating a 'struct cyclic_info', make the users embed such an
instance in their own structure, and make the convention that the
callback simply receives the 'struct cyclic_info *', from which the
clients can get their own data using the container_of() macro.

This has a number of advantages.

First, it means cyclic_register() simply cannot fail, simplifying the
code. The necessary storage will simply be allocated automatically
when the client's own structure is allocated (often via
uclass_priv_auto or similar).

Second, code for which CONFIG_CYCLIC is just an option can more easily
be written without #ifdefs, if we just provide an empty struct
cyclic_info {}. For example, the nested CONFIG_IS_ENABLED()s in
https://lore.kernel.org/u-boot/20240316201416.211480-1-marek.vasut+renesas@mailbox.org/
are mostly due to the existence of the 'struct cyclic_info *' member
being guarded by #ifdef CONFIG_CYCLIC.

And we do probably want to avoid the extra memory overhead of that
member when !CONFIG_CYCLIC. But that is automatic if, instead of a
'struct cyclic_info *', one simply embeds a 'struct cyclic_info',
which will have size 0 when !CONFIG_CYCLIC. Also, the no-op
cyclic_register() function can just unconditionally be called, and the
compiler will see that (1) the callback is referenced, so not emit a
warning for a maybe-unused function and (2) see that it can actually
never be reached, so not emit any code for it.

Reviewed-by: Stefan Roese &lt;sr@denx.de&gt;
Signed-off-by: Rasmus Villemoes &lt;rasmus.villemoes@prevas.dk&gt;
</content>
</entry>
<entry>
<title>cyclic: stop strdup'ing name in cyclic_register()</title>
<updated>2024-06-16T10:13:38Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>rasmus.villemoes@prevas.dk</email>
</author>
<published>2024-05-21T08:46:50Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/u-boot.git/commit/?id=3a11eada38efbbe1517662d196d11c2e20d2b5ca'/>
<id>urn:sha1:3a11eada38efbbe1517662d196d11c2e20d2b5ca</id>
<content type='text'>
We are not checking the return value of strdup(), nor
freeing the string in cyclic_unregister().

However, all current users either pass a string literal or the
dev-&gt;name of the client device. So in all cases the name string will
live at least as long as the cyclic_info is registered, so just make
that a requirement.

Reviewed-by: Stefan Roese &lt;sr@denx.de&gt;
Signed-off-by: Rasmus Villemoes &lt;rasmus.villemoes@prevas.dk&gt;
</content>
</entry>
</feed>
