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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/