public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Shan Wei <shanwei88@gmail.com>
To: paulmck@linux.vnet.ibm.com
Cc: Christoph Lameter <cl@linux.com>,
	dipankar@in.ibm.com,
	Kernel-Maillist <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 6/9] rcu: use __this_cpu_read helper instead of per_cpu_ptr(p, raw_smp_processor_id())
Date: Sun, 04 Nov 2012 18:38:29 +0800	[thread overview]
Message-ID: <509645A5.5070901@gmail.com> (raw)
In-Reply-To: <20121103091909.GI3027@linux.vnet.ibm.com>

Paul E. McKenney said, at 2012/11/3 17:19:
> OK, I do understand why it happens to work.  My question is instead why
> it is considered a good idea.  

Maybe objdump gives the answer.
 __this_cpu_read which read member pointer of per-cpu variable
can reduce two instructions on x86-64 arch.


*test code:* 
struct eater_state {
        u32 state;
        struct eater __percpu *eater_info;
};

struct eater {
        char name[4];
        u32 age;
};

static u32 test_func(struct eater_state *tstas)
{
        struct eater *aeater;

        //aeater = __this_cpu_ptr(tstas->eater_info);   <-----------------1
        //return aeater->age;
        return  __this_cpu_read(tstas->eater_info->age); <-----------------2
}

static int __init demo_init(void)
{
        int ret = 0 ;
        int age;
        struct eater_state as;
        struct eater david;

        as.state = 1;
        as.eater_info = &david;

        age = test_func(&as);

        return ret;
}


__this_cpu_ptr <-----------------1
0000000000000000 <init_module>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 83 ec 10             sub    $0x10,%rsp
   8:   48 8d 45 f0             lea    -0x10(%rbp),%rax
   c:   65 48 03 04 25 00 00 00 00      add    %gs:0x0,%rax
  15:   31 c0                   xor    %eax,%eax
  17:   c9                      leaveq 
  18:   c3                      retq   


 __this_cpu_read<-----------------2
0000000000000000 <init_module>:
   0:   55                      push   %rbp
   1:   31 c0                   xor    %eax,%eax
   3:   48 89 e5                mov    %rsp,%rbp
   6:   48 83 ec 10             sub    $0x10,%rsp
   a:   c9                      leaveq 
   b:   c3                      retq   



  reply	other threads:[~2012-11-04 10:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-02 16:01 [PATCH v2 6/9] rcu: use __this_cpu_read helper instead of per_cpu_ptr(p, raw_smp_processor_id()) Shan Wei
2012-11-02 17:46 ` Christoph Lameter
2012-11-02 18:10 ` Paul E. McKenney
2012-11-02 20:19   ` Christoph Lameter
2012-11-03  9:19     ` Paul E. McKenney
2012-11-04 10:38       ` Shan Wei [this message]
2012-11-05 14:49         ` Christoph Lameter
     [not found]           ` <CAPYxyx+eJUWxDJrbOHVRtCchszmj8+BgSkNhpH3gGBJK87OikA@mail.gmail.com>
2012-11-05 15:55             ` Christoph Lameter
2012-11-05 15:23       ` Christoph Lameter

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=509645A5.5070901@gmail.com \
    --to=shanwei88@gmail.com \
    --cc=cl@linux.com \
    --cc=dipankar@in.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox