> On Mar 1, 2023, at 2:43 PM, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote: > > On Wed, 1 Mar 2023 20:18:11 +0100 > Uros Bizjak <ubizjak@xxxxxxxxx> wrote: > >> If we want to put the definition in generic headers, then we also need >> to define acquire/release/relaxed and 64bit variants. ATM, we have two >> sites that require this definition and I think that for now we could >> live with two instances of the same definition in two separate >> subsystems. But this would definitely be a good future addition. There >> is some code in the form of >> >> if (cmpxchg (ptr, 0, 1) == 0) >> >> that can not be converted to try_cmpxchg, but can use cmpxchg_success. > > And even modify code that uses temp variables. For example, where you > modified the ring buffer code to use try_cmpxchg(), I could convert your: > > static int rb_head_page_replace(struct buffer_page *old, > struct buffer_page *new) > { > unsigned long *ptr = (unsigned long *)&old->list.prev->next; > unsigned long val; > > val = *ptr & ~RB_FLAG_MASK; > val |= RB_PAGE_HEAD; > > return try_cmpxchg(ptr, &val, (unsigned long)&new->list); > } > > Into just: > > static int rb_head_page_replace(struct buffer_page *old, > struct buffer_page *new) > { > unsigned long *ptr = (unsigned long *)&old->list.prev->next; > unsigned long val; > > val = *ptr & ~RB_FLAG_MASK; > > return cmpxchg_success(ptr, val | RB_PAGE_HEAD, (unsigned long)&new->list); > } Nice! Looks much better. Thanks, - Joel > > -- Steve