mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-04 08:08:54 +00:00
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 <ubizjak@gmail.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20230116165337.5810-1-ubizjak@gmail.com
This commit is contained in:
parent
cbdb1f163a
commit
915d4ad383
1 changed files with 6 additions and 7 deletions
|
@ -243,13 +243,12 @@ static void proc_sample_cputime_atomic(struct task_cputime_atomic *at,
|
||||||
*/
|
*/
|
||||||
static inline void __update_gt_cputime(atomic64_t *cputime, u64 sum_cputime)
|
static inline void __update_gt_cputime(atomic64_t *cputime, u64 sum_cputime)
|
||||||
{
|
{
|
||||||
u64 curr_cputime;
|
u64 curr_cputime = atomic64_read(cputime);
|
||||||
retry:
|
|
||||||
curr_cputime = atomic64_read(cputime);
|
do {
|
||||||
if (sum_cputime > curr_cputime) {
|
if (sum_cputime <= curr_cputime)
|
||||||
if (atomic64_cmpxchg(cputime, curr_cputime, sum_cputime) != curr_cputime)
|
return;
|
||||||
goto retry;
|
} while (!atomic64_try_cmpxchg(cputime, &curr_cputime, sum_cputime));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_gt_cputime(struct task_cputime_atomic *cputime_atomic,
|
static void update_gt_cputime(struct task_cputime_atomic *cputime_atomic,
|
||||||
|
|
Loading…
Reference in a new issue