From: "Jan Beulich" Subject: Re: [PATCH] x86: optimize this_cpu() Date: Tue, 13 Jul 2010 15:43:49 +0100 Message-ID: <4C3C97C5020000780000B013@vpn.id2.novell.com> References: <4C3C87BA020000780000AF92@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: 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: Keir Fraser Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org >>> On 13.07.10 at 16:26, Keir Fraser wrote: > On 13/07/2010 14:35, "Jan Beulich" wrote: >=20 >> 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. >>=20 >> Signed-off-by: Jan Beulich >>=20 >> --- 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 >=20 > That's just nasty. If we need the structure to be 16-byte aligned then = we > should achieve it via __attribute__((__aligned__(16))). And if we add = that > we may as well not ifdef it, I'm sure the up to 12 bytes padding on i386 > won't cause stack overflow. I indeed considered this apparently cleaner alternative first, but no, __attribute__((__aligned__())) isn't the right solution here: For one, the has no effect due to the way get_cpu_info() calculates its result. Second, sizeof(struct cpu_info) would change (to a value divisible by 16), and thus offsetof(struct cpu_info, guest_cpu_user_regs.es) would become indivisible by 16 (triggering the BUG_ON((get_stack_bottom() & 15) !=3D 0) in cpu_init()) without any way of making it so again. I found it quite odd that, without any special comment to that effect, I couldn't just add a single field to struct cpu_info without causing breakage. The apparently odd extra padding field at least provides a slight hint towards issues here. A similar issue is that there is a silent requirement of "current_vcpu" being the last field... Jan