Skip to contentSkip to conversation

cyclic: update and optimization

PATCH In review Patrice Chotard 3 participants 5 messages Jul 6 – Jul 16

lore
Share & tools
lore
#0 lore raw

v3 cover cyclic: update and optimization

First patch is replacing uint64_t by u64 as suggested by b4 Second patch optimizes cyclic_run() to parse cyclic list only if a cyclic function's timestamp is elapsed.

To: [email protected]
Cc: Stefan Roese <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Marek Vasut <[email protected]>

---
Changes in v3:
- Rework cyclic_run() to not call get_timer_us() on each entry.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- move cyclic with nearest deadline on list's head.
- Link to v1: https://patch.msgid.link/[email protected]

To: [email protected]
Cc: Stefan Roese <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Rasmus Villemoes <[email protected]>

---
Patrice Chotard (2):
cyclic: replace uint64_t by u64 suggested by b4
cyclic: reduce get_timer_us() calls inside hlist_for_each_entry_safe()

 common/cyclic.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

---
base-commit: 1296a428c67cf103eca482d4a63349661c1b799f
change-id: 20260702-optimize_cyclic_run-ecdc46f12829

Best regards,

Signature · 1 line
Patrice Chotard <[email protected]>
#1 lore raw

PATCH v3 1/2 cyclic: replace uint64_t by u64 suggested by b4

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.

Cc Marek Vasut <[email protected]>
---
 common/cyclic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
common/cyclic.c +2 -2
index ec952a01ee1..b37cd6d8ff0 100644
@@ -41,7 +41,7 @@ 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)
+		     u64 delay_us, const char *name)
 {
 	cyclic_unregister(cyclic);
 
@@ -67,7 +67,7 @@ static void cyclic_run(void)
 {
 	struct cyclic_info *cyclic;
 	struct hlist_node *tmp;
-	uint64_t now, cpu_time;
+	u64 now, cpu_time;
 
 	/* Prevent recursion */
 	if (gd->flags & GD_FLG_CYCLIC_RUNNING)
Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/2 cyclic: reduce get_timer_us() calls inside hlist_for_each_entry_safe()

In reply to Patrice Chotard

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

---
 common/cyclic.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
common/cyclic.c +5 -3
index b37cd6d8ff0..573e715587d 100644
@@ -67,26 +67,28 @@ static void cyclic_run(void)
 {
 	struct cyclic_info *cyclic;
 	struct hlist_node *tmp;
-	u64 now, cpu_time;
+	u64 now, after, cpu_time;
 
 	/* Prevent recursion */
 	if (gd->flags & GD_FLG_CYCLIC_RUNNING)
 		return;
 
 	gd->flags |= GD_FLG_CYCLIC_RUNNING;
+	now = get_timer_us(0);
 	hlist_for_each_entry_safe(cyclic, tmp, cyclic_get_list(), list) {
 		/*
 		 * Check if this cyclic function needs to get called, e.g.
 		 * do not call the cyclic func too often
 		 */
-		now = get_timer_us(0);
 		if (time_after_eq64(now, cyclic->next_call)) {
 			/* Call cyclic function and account it's cpu-time */
 			cyclic->next_call = now + cyclic->delay_us;
 			cyclic->func(cyclic);
+			after = get_timer_us(0);
 			cyclic->run_cnt++;
-			cpu_time = get_timer_us(0) - now;
+			cpu_time = after - now;
 			cyclic->cpu_time_us += cpu_time;
+			now = after;
 
 			/* Check if cpu-time exceeds max allowed time */
 			if ((cpu_time > CONFIG_CYCLIC_MAX_CPU_TIME_US) &&
Signature · 1 line
2.43.0
#3 lore raw
In reply to Patrice Chotard
Quoted 3 lines · Patrice Chotard

First patch is replacing uint64_t by u64 as suggested by b4 Second patch optimizes cyclic_run() to parse cyclic list only if a cyclic function's timestamp is elapsed.

In case the cover letter is used as a merge commit message, note that the latter description is no longer accurate.

Rasmus

#4 lore raw
In reply to Patrice Chotard
Quoted 10 lines · Patrice Chotard

First patch is replacing uint64_t by u64 as suggested by b4 Second patch optimizes cyclic_run() to parse cyclic list only if a cyclic function's timestamp is elapsed.

To: [email protected]
Cc: Stefan Roese <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Marek Vasut <[email protected]>

[...]

Applied to u-boot/main, thanks!

[1/2] cyclic: replace uint64_t by u64 suggested by b4

      commit: 08af4faa0f0eac4622e52e699729bd157d6d806a
[2/2] cyclic: reduce get_timer_us() calls inside hlist_for_each_entry_safe()
      commit: 9c1b13b3fd271500cd8a61f86816d822e4852a90
Signature · 1 line
Tom