From: "Jan Beulich" Subject: [PATCH] x86: optimize this_cpu() Date: Tue, 13 Jul 2010 14:35:22 +0100 Message-ID: <4C3C87BA020000780000AF92@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org Besides the .text space savings of over 2.5k on x86-64 (1.5k for x86-32) this removes a load (plus a lea on x86-64) from various frequently executed code paths, and finally provides a reason (other than legibility) to prefer this_cpu() over per_cpu() in all places where smp_processor_id() isn't being called anyway. Signed-off-by: Jan Beulich --- 2010-06-15.orig/xen/include/asm-x86/current.h 2010-07-13 = 14:38:21.000000000 +0200 +++ 2010-06-15/xen/include/asm-x86/current.h 2010-07-13 15:12:37.0000000= 00 +0200 @@ -17,6 +17,10 @@ struct vcpu; struct cpu_info { struct cpu_user_regs guest_cpu_user_regs; unsigned int processor_id; + unsigned long per_cpu_offset; +#ifdef __x86_64__ + unsigned long __pad_for_stack_bottom; +#endif struct vcpu *current_vcpu; }; =20 @@ -35,7 +39,12 @@ static inline struct cpu_info *get_cpu_i #define current (get_current()) =20 #define get_processor_id() (get_cpu_info()->processor_id) -#define set_processor_id(id) (get_cpu_info()->processor_id =3D (id)) +#define set_processor_id(id) do { \ + struct cpu_info *ci__ =3D get_cpu_info(); = \ + ci__->per_cpu_offset =3D __per_cpu_offset[ci__->processor_id =3D = (id)]; \ +} while (0) + +#define get_per_cpu_offset() (get_cpu_info()->per_cpu_offset) =20 #define guest_cpu_user_regs() (&get_cpu_info()->guest_cpu_user_regs) =20 --- 2010-06-15.orig/xen/include/asm-x86/percpu.h 2010-07-13 = 14:38:21.000000000 +0200 +++ 2010-06-15/xen/include/asm-x86/percpu.h 2010-07-13 13:56:38.0000000= 00 +0200 @@ -16,7 +16,7 @@ void percpu_init_areas(void); #define per_cpu(var, cpu) \ (*RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu])) #define __get_cpu_var(var) \ - (per_cpu(var, smp_processor_id())) + (*RELOC_HIDE(&per_cpu__##var, get_per_cpu_offset())) =20 #define DECLARE_PER_CPU(type, name) extern __typeof__(type) per_cpu__##nam= e =20