lkml.org 
[lkml]   [2014]   [Apr]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: How do I increment a per-CPU variable without warning?
On Tue, Apr 15, 2014 at 08:54:19PM -0700, Paul E. McKenney wrote:
> But falling back on the old ways of doing this at least looks a bit
> nicer:
>
> static inline bool rcu_should_resched(void)
> {
> int t;
> int *tp = &per_cpu(rcu_cond_resched_count, raw_smp_processor_id());
>
> t = ACCESS_ONCE(*tp) + 1;
> if (t < RCU_COND_RESCHED_LIM) {

<here>

> ACCESS_ONCE(*tp) = t;
> return false;
> }
> return true;
> }
>
> Other thoughts?

Still broken, if A starts out on CPU1, gets migrated to CPU0 at <here>,
then B starts the same on CPU1. It is possible for both CPU0 and CPU1 to
write a different value into your rcu_cond_resched_count.

You really want to disable preemption around there. The proper old way
would've been get_cpu_var()/put_cpu_var().



\
 
 \ /
  Last update: 2014-04-16 07:41    [W:0.059 / U:3.740 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site