Use this_cpu_inc_return in one place and avoid ugly __raw_get_cpu in another.
Cc: Michael Holzheu <[email protected]>
Signed-off-by: Christoph Lameter <[email protected]>
---
kernel/taskstats.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
Index: linux-2.6/kernel/taskstats.c
===================================================================
--- linux-2.6.orig/kernel/taskstats.c 2010-11-30 10:06:35.000000000 -0600
+++ linux-2.6/kernel/taskstats.c 2010-11-30 10:10:14.000000000 -0600
@@ -89,8 +89,7 @@ static int prepare_reply(struct genl_inf
return -ENOMEM;
if (!info) {
- int seq = get_cpu_var(taskstats_seqnum)++;
- put_cpu_var(taskstats_seqnum);
+ int seq = this_cpu_inc_return(taskstats_seqnum);
reply = genlmsg_put(skb, 0, seq, &family, 0, cmd);
} else
@@ -581,7 +580,7 @@ void taskstats_exit(struct task_struct *
fill_tgid_exit(tsk);
}
- listeners = &__raw_get_cpu_var(listener_array);
+ listeners = __this_cpu_ptr(listener_array);
if (list_empty(&listeners->list))
return;
Hello Christoph,
On Tue, 2010-11-30 at 13:07 -0600, Christoph Lameter wrote:
> plain text document attachment (this_cpu_taskstats)
> Use this_cpu_inc_return in one place and avoid ugly __raw_get_cpu in another.
>
> Cc: Michael Holzheu <[email protected]>
> Signed-off-by: Christoph Lameter <[email protected]>
>
> ---
> kernel/taskstats.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> Index: linux-2.6/kernel/taskstats.c
> ===================================================================
> --- linux-2.6.orig/kernel/taskstats.c 2010-11-30 10:06:35.000000000 -0600
> +++ linux-2.6/kernel/taskstats.c 2010-11-30 10:10:14.000000000 -0600
> @@ -89,8 +89,7 @@ static int prepare_reply(struct genl_inf
> return -ENOMEM;
>
> if (!info) {
> - int seq = get_cpu_var(taskstats_seqnum)++;
> - put_cpu_var(taskstats_seqnum);
> + int seq = this_cpu_inc_return(taskstats_seqnum);
Hmmm, wouldn't seq now always be one more than before?
I think that "seq = get_cpu_var(taskstats_seqnum)++" first assigns
taskstats_seqnum to seq and then increases the value in contrast to
this_cpu_inc_return() that returns the already increased value, correct?
Maybe that does not hurt here, Balbir?
> reply = genlmsg_put(skb, 0, seq, &family, 0, cmd);
> } else
> @@ -581,7 +580,7 @@ void taskstats_exit(struct task_struct *
> fill_tgid_exit(tsk);
> }
>
> - listeners = &__raw_get_cpu_var(listener_array);
> + listeners = __this_cpu_ptr(listener_array);
> if (list_empty(&listeners->list))
> return;
>
>
On Wed, 1 Dec 2010, Michael Holzheu wrote:
> > return -ENOMEM;
> >
> > if (!info) {
> > - int seq = get_cpu_var(taskstats_seqnum)++;
> > - put_cpu_var(taskstats_seqnum);
> > + int seq = this_cpu_inc_return(taskstats_seqnum);
>
> Hmmm, wouldn't seq now always be one more than before?
>
> I think that "seq = get_cpu_var(taskstats_seqnum)++" first assigns
> taskstats_seqnum to seq and then increases the value in contrast to
> this_cpu_inc_return() that returns the already increased value, correct?
Correct. We need to subtract one from that (which will eliminate the minus
-1 that the inline this_cpu_inc_return creates).
* Christoph Lameter <[email protected]> [2010-12-01 12:13:44]:
> On Wed, 1 Dec 2010, Michael Holzheu wrote:
>
> > > return -ENOMEM;
> > >
> > > if (!info) {
> > > - int seq = get_cpu_var(taskstats_seqnum)++;
> > > - put_cpu_var(taskstats_seqnum);
> > > + int seq = this_cpu_inc_return(taskstats_seqnum);
> >
> > Hmmm, wouldn't seq now always be one more than before?
> >
> > I think that "seq = get_cpu_var(taskstats_seqnum)++" first assigns
> > taskstats_seqnum to seq and then increases the value in contrast to
> > this_cpu_inc_return() that returns the already increased value, correct?
>
> Correct. We need to subtract one from that (which will eliminate the minus
> -1 that the inline this_cpu_inc_return creates).
>
But that breaks current behaviour, we should probably initialize all
of the array to -1?
--
Three Cheers,
Balbir
On Mon, 6 Dec 2010, Balbir Singh wrote:
> > Correct. We need to subtract one from that (which will eliminate the minus
> > -1 that the inline this_cpu_inc_return creates).
> >
>
> But that breaks current behaviour, we should probably initialize all
> of the array to -1?
Not necessary. This_cpu_inc() uses an xadd instruction which retrieves
the value and then increments the memory location. Then it adds 1. The -1
eliminates that add.