timers/timer_migration: Fix memory barrier comment

Message ID 20240222133320.43780-1-anna-maria@linutronix.de
State New
Headers
Series timers/timer_migration: Fix memory barrier comment |

Commit Message

Anna-Maria Behnsen Feb. 22, 2024, 1:33 p.m. UTC
  Comment about the required memory barrier in tmigr_inactive_up() is not
written properly. Rewrite it and add also new comments to the other memory
barrier related places. Also make clear, why a memory barrier in
tmigr_active_up() is not required.

Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
---
This is a fix for the patch 'timers: Implement the hierarchical pull model'
v11b.
---
 kernel/time/timer_migration.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
  

Comments

Frederic Weisbecker Feb. 22, 2024, 1:44 p.m. UTC | #1
Le Thu, Feb 22, 2024 at 02:33:20PM +0100, Anna-Maria Behnsen a écrit :
> Comment about the required memory barrier in tmigr_inactive_up() is not
> written properly. Rewrite it and add also new comments to the other memory
> barrier related places. Also make clear, why a memory barrier in
> tmigr_active_up() is not required.
> 
> Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
  

Patch

diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c
index 0825ccdcfae4..23cb6ea3d44e 100644
--- a/kernel/time/timer_migration.c
+++ b/kernel/time/timer_migration.c
@@ -623,6 +623,11 @@  static bool tmigr_active_up(struct tmigr_group *group,
 	u8 childmask;
 
 	childmask = data->childmask;
+	/*
+	 * No memory barrier is required here in contrast to
+	 * tmigr_inactive_up(), as the group state change does not depend on the
+	 * child state.
+	 */
 	curstate.state = atomic_read(&group->migr_state);
 
 	do {
@@ -1215,9 +1220,16 @@  static bool tmigr_inactive_up(struct tmigr_group *group,
 	u8 childmask;
 
 	childmask = data->childmask;
-	curstate.state = atomic_read_acquire(&group->migr_state);
 	childstate.state = 0;
 
+	/*
+	 * The memory barrier is paired with the cmpxchg() in tmigr_active_up()
+	 * to make sure the updates of child and group states are ordered. The
+	 * ordering is mandatory, as the group state change depends on the child
+	 * state.
+	 */
+	curstate.state = atomic_read_acquire(&group->migr_state);
+
 	for (;;) {
 		if (child)
 			childstate.state = atomic_read(&child->migr_state);
@@ -1257,10 +1269,12 @@  static bool tmigr_inactive_up(struct tmigr_group *group,
 		if (atomic_try_cmpxchg(&group->migr_state, &curstate.state,
 				       newstate.state))
 			break;
+
 		/*
-		 * Add memory barrier to make sure child and group states order
-		 * of read is preserved. This barrier is only required when
-		 * atomic_try_cmpxchg() failed.
+		 * The memory barrier is paired with the cmpxchg() in
+		 * tmigr_active_up() to make sure the updates of child and group
+		 * states are ordered. It is required only when the above
+		 * try_cmpxchg() fails.
 		 */
 		smp_mb__after_atomic();
 	}