lkml.org 
[lkml]   [2022]   [Jul]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH RESEND] sched/core: Use try_cmpxchg in set_nr_{and_not,if}_polling
On Wed, 29 Jun 2022 17:15:52 +0200
Uros Bizjak <ubizjak@gmail.com> wrote:

> +++ b/kernel/sched/core.c
> @@ -873,15 +873,11 @@ static inline void hrtick_rq_init(struct rq *rq)
> ({ \
> typeof(ptr) _ptr = (ptr); \
> typeof(mask) _mask = (mask); \
> - typeof(*_ptr) _old, _val = *_ptr; \
> + typeof(*_ptr) _val = *_ptr; \
> \
> - for (;;) { \
> - _old = cmpxchg(_ptr, _val, _val | _mask); \
> - if (_old == _val) \
> - break; \
> - _val = _old; \
> - } \
> - _old; \
> + do { \
> + } while (!try_cmpxchg(_ptr, &_val, _val | _mask)); \

I'm curious to why use a do { } while() and not just:

while (!try_cmpxchg(_ptr, &_val, _val | _mask))
;

I see that this is Peter's recommended way from commit a9ebf306f52c75
("locking/atomic: Introduce atomic_try_cmpxchg()")

Peter, why the do { } while() ?

Does it generate better asm than while () ; ?

-- Steve

> + _val; \
> })

\
 
 \ /
  Last update: 2022-07-09 00:40    [W:0.065 / U:0.088 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site