Skip to contentSkip to conversation

sched/fair: Use try_cmpxchg in task_numa_work

PATCH Applied Uros Bizjak 1 participant 1 message Aug 22, 2022 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/fair: Use try_cmpxchg in task_numa_work

Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in task_numa_work. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg).

No functional change intended.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Juri Lelli <[email protected]>
Cc Vincent Guittot <[email protected]>
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
index 914096c5b1ae..efe73ee89989 100644
@@ -2802,7 +2802,7 @@ static void task_numa_work(struct callback_head *work)
 	}
 
 	next_scan = now + msecs_to_jiffies(p->numa_scan_period);
-	if (cmpxchg(&mm->numa_next_scan, migrate, next_scan) != migrate)
+	if (!try_cmpxchg(&mm->numa_next_scan, &migrate, next_scan))
 		return;
 
 	/*
Signature · 1 line
2.37.1