Skip to content

Commit 915d4ad

Browse files
ubizjakKAGA-KOKO
authored andcommitted
posix-timers: Use atomic64_try_cmpxchg() in __update_gt_cputime()
Use atomic64_try_cmpxchg() instead of atomic64_cmpxchg() in __update_gt_cputime(). The x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg() (and related move instruction in front of cmpxchg()). Also, atomic64_try_cmpxchg() implicitly assigns old *ptr value to "old" when cmpxchg() fails. There is no need to re-read the value in the loop. No functional change intended. Signed-off-by: Uros Bizjak <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cbdb1f1 commit 915d4ad

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

kernel/time/posix-cpu-timers.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,12 @@ static void proc_sample_cputime_atomic(struct task_cputime_atomic *at,
243243
*/
244244
static inline void __update_gt_cputime(atomic64_t *cputime, u64 sum_cputime)
245245
{
246-
u64 curr_cputime;
247-
retry:
248-
curr_cputime = atomic64_read(cputime);
249-
if (sum_cputime > curr_cputime) {
250-
if (atomic64_cmpxchg(cputime, curr_cputime, sum_cputime) != curr_cputime)
251-
goto retry;
252-
}
246+
u64 curr_cputime = atomic64_read(cputime);
247+
248+
do {
249+
if (sum_cputime <= curr_cputime)
250+
return;
251+
} while (!atomic64_try_cmpxchg(cputime, &curr_cputime, sum_cputime));
253252
}
254253

255254
static void update_gt_cputime(struct task_cputime_atomic *cputime_atomic,

0 commit comments

Comments
 (0)