linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* How do I increment a per-CPU variable without warning?
@ 2014-04-15 22:17 Paul E. McKenney
  2014-04-15 22:29 ` Dave Jones
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Paul E. McKenney @ 2014-04-15 22:17 UTC (permalink / raw)
  To: cl; +Cc: linux-kernel, mingo, tj, grygorii.strashko, peterz

Hello, Christoph,

I have a patch that currently uses __this_cpu_inc_return() to increment a
per-CPU variable, but without preemption disabled.  Of course, given that
preemption is enabled, it might well end up picking up one CPU's counter,
adding one to it, then storing the result into some other CPU's counter.
But this is OK, the test can be probabilistic.  And when I run this
against v3.14 and earlier, it works fine.

But now there is 188a81409ff7 (percpu: add preemption checks to
__this_cpu ops), which gives me lots of splats.

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;
	}

This is arguably better than the original __this_cpu_read() because it
avoids overflow, but I thought I should check to see if there was some
better way to do this.

							Thanx, Paul


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2014-04-17 18:21 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).