From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Dave Jones <davej@redhat.com>,
cl@linux.com, linux-kernel@vger.kernel.org, mingo@kernel.org,
tj@kernel.org, grygorii.strashko@ti.com, peterz@infradead.org
Subject: Re: How do I increment a per-CPU variable without warning?
Date: Tue, 15 Apr 2014 15:47:26 -0700 [thread overview]
Message-ID: <20140415224725.GS4496@linux.vnet.ibm.com> (raw)
In-Reply-To: <20140415222951.GA742@redhat.com>
On Tue, Apr 15, 2014 at 06:29:51PM -0400, Dave Jones wrote:
> On Tue, Apr 15, 2014 at 03:17:55PM -0700, Paul E. McKenney wrote:
>
> > My current admittedly crude workaround is as follows:
> >
> > static inline bool rcu_should_resched(void)
> > {
> > int t;
> >
> > #ifdef CONFIG_DEBUG_PREEMPT
> > preempt_disable();
> > #endif /* #ifdef CONFIG_DEBUG_PREEMPT */
> > t = __this_cpu_read(rcu_cond_resched_count) + 1;
> > if (t < RCU_COND_RESCHED_LIM) {
> > __this_cpu_write(rcu_cond_resched_count, t);
> > #ifdef CONFIG_DEBUG_PREEMPT
> > preempt_enable();
> > #endif /* #ifdef CONFIG_DEBUG_PREEMPT */
> > return false;
> > }
> > #ifdef CONFIG_DEBUG_PREEMPT
> > preempt_enable();
> > #endif /* #ifdef CONFIG_DEBUG_PREEMPT */
> > return true;
> > }
>
> Won't using DEBUG_PREEMPT instead of just CONFIG_PREEMPT here make this
> silently do the wrong thing if preemption is enabled, but debugging isn't ?
If preemption is enabled, but debugging is not, then yes, the above code
might force an unnecessary schedule() if the above code was preempted
between the __this_cpu_read() and the __this_cpu_write(). Which does
not cause a problem, especially given that it won't happen very often.
> I'm not seeing why you need the ifdefs at all, unless the implied
> barrier() is a problem ?
I don't think that Peter Zijlstra would be too happy about an extra
unneeded preempt_disable()/preempt_enable() pair in the cond_resched()
fastpath. Not that I necessarily expect him to be particularly happy
with the above, but perhaps someone has a better approach.
Thanx, Paul
next prev parent reply other threads:[~2014-04-15 22:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-15 22:17 How do I increment a per-CPU variable without warning? Paul E. McKenney
2014-04-15 22:29 ` Dave Jones
2014-04-15 22:47 ` Paul E. McKenney [this message]
2014-04-16 3:54 ` Paul E. McKenney
2014-04-16 5:21 ` Peter Zijlstra
2014-04-16 13:03 ` Paul E. McKenney
2014-04-16 15:12 ` Christoph Lameter
2014-04-16 5:19 ` Peter Zijlstra
2014-04-16 15:08 ` Christoph Lameter
2014-04-16 16:06 ` Paul E. McKenney
2014-04-16 17:12 ` Paul E. McKenney
2014-04-16 18:29 ` Christoph Lameter
2014-04-16 18:47 ` Paul E. McKenney
2014-04-17 17:36 ` Christoph Lameter
2014-04-17 17:46 ` Paul E. McKenney
2014-04-17 17:53 ` Christoph Lameter
2014-04-17 18:21 ` Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140415224725.GS4496@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=cl@linux.com \
--cc=davej@redhat.com \
--cc=grygorii.strashko@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.