lkml.org 
[lkml]   [2012]   [Nov]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 6/9] rcu: use __this_cpu_read helper instead of per_cpu_ptr(p, raw_smp_processor_id())
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




\
 
 \ /
  Last update: 2012-11-04 12:21    [W:0.052 / U:23.628 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site