Subject: [cpuops inc_return V1 8/9] random: Use this_cpu_inc_return

__this_cpu_inc can create a single instruction to do the same as
__get_cpu_var()++.

Cc: Richard Kennedy <[email protected]>
Cc: Matt Mackall <[email protected]>
Signed-off-by: Christoph Lameter <[email protected]>

---
drivers/char/random.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6/drivers/char/random.c
===================================================================
--- linux-2.6.orig/drivers/char/random.c 2010-12-06 11:01:06.000000000 -0600
+++ linux-2.6/drivers/char/random.c 2010-12-06 11:19:38.000000000 -0600
@@ -626,7 +626,7 @@ static void add_timer_randomness(struct
preempt_disable();
/* if over the trickle threshold, use only 1 in 4096 samples */
if (input_pool.entropy_count > trickle_thresh &&
- (__get_cpu_var(trickle_count)++ & 0xfff))
+ ((__this_cpu_inc_return(trickle_count) - 1) & 0xfff))
goto out;

sample.jiffies = jiffies;


2010-12-06 18:11:46

by Matt Mackall

[permalink] [raw]
Subject: Re: [cpuops inc_return V1 8/9] random: Use this_cpu_inc_return

On Mon, 2010-12-06 at 11:40 -0600, Christoph Lameter wrote:
> plain text document attachment (cpuops_inc_return_random)
> __this_cpu_inc can create a single instruction to do the same as
> __get_cpu_var()++.

> - (__get_cpu_var(trickle_count)++ & 0xfff))
> + ((__this_cpu_inc_return(trickle_count) - 1) & 0xfff))

I see you've added a "- 1" to mimic the post-increment ++ semantic.

The goal of this code to add only 1 sample in every 4096, but we don't
really care which, so this semantic isn't actually important here.

--
Mathematics is the supreme nostalgia of our time.

Subject: Re: [cpuops inc_return V1 8/9] random: Use this_cpu_inc_return

On Mon, 6 Dec 2010, Matt Mackall wrote:

> On Mon, 2010-12-06 at 11:40 -0600, Christoph Lameter wrote:
> > plain text document attachment (cpuops_inc_return_random)
> > __this_cpu_inc can create a single instruction to do the same as
> > __get_cpu_var()++.
>
> > - (__get_cpu_var(trickle_count)++ & 0xfff))
> > + ((__this_cpu_inc_return(trickle_count) - 1) & 0xfff))
>
> I see you've added a "- 1" to mimic the post-increment ++ semantic.
>
> The goal of this code to add only 1 sample in every 4096, but we don't
> really care which, so this semantic isn't actually important here.

-1 also removes the + 1 that the inc_return() semantics require because we
use xadd on x86. -1 will generate more compact code.