All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Marcin Cieslak <saper@saper.info>, xen-devel@lists.xensource.com
Subject: Re: [PATCH v2] x86/current: Provide additional information to optimise get_cpu_info()
Date: Mon, 15 Sep 2014 09:16:24 +0100	[thread overview]
Message-ID: <5416A058.9040305@citrix.com> (raw)
In-Reply-To: <slrnm18r4j.25q3.saper@saper.info>

On 13/09/2014 17:10, Marcin Cieslak wrote:
>>> Andrew Cooper<andrew.cooper3@citrix.com>  wrote:
>> Exactly as with c/s d55c5eefe "x86: use compiler visible "add" instead of
>> inline assembly "or" in get_cpu_info()", this is achieved by providing more
>> information to the compiler.
>>
>> This causes a net drop of almost 4K of .text
>>
>> Signed-off-by: Andrew Cooper<andrew.cooper3@citrix.com>
>> CC: Jan Beulich<JBeulich@suse.com>
>>
>> ---
>> v2: Less speculation about generated code in the comment
>> ---
>>   xen/include/asm-x86/current.h |    6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/xen/include/asm-x86/current.h b/xen/include/asm-x86/current.h
>> index 2081015..b95fd79 100644
>> --- a/xen/include/asm-x86/current.h
>> +++ b/xen/include/asm-x86/current.h
>> @@ -25,9 +25,9 @@ struct cpu_info {
>>   
>>   static inline struct cpu_info *get_cpu_info(void)
>>   {
>> -    unsigned long tos;
>> -    __asm__ ( "and %%rsp,%0" : "=r" (tos) : "0" (~(STACK_SIZE-1)) );
>> -    return (struct cpu_info *)(tos + STACK_SIZE) - 1;
>> +    register unsigned long sp asm("rsp");
>> +
>> +    return (struct cpu_info *)((sp & ~(STACK_SIZE-1)) + STACK_SIZE) - 1;
>>   }
> Hello, it seems to me that the above code fails on me with clang 3.4
> on FreeBSD-CURRENT:
>
> xen/include/asm/current.h:30:33:
> 	error: variable 'sp' is uninitialized when used here [-Werror,-Wuninitialized]

That is rather unfortunate for clang.  The stack pointer has an 
initialised and perfectly good value anywhere this function can be used.

> Reverting df0ae94fd56d5f9c64089364efecb1793442360b helps.
>
> There is a workaround suggested inhttp://llvm.org/devmtg/2014-02/slides/moller-llvmlinux.pdf:
>
> diff --git a/xen/include/asm-x86/current.h b/xen/include/asm-x86/current.h
> index b95fd79..e133d9d 100644
> --- a/xen/include/asm-x86/current.h
> +++ b/xen/include/asm-x86/current.h
> @@ -26,6 +26,7 @@ struct cpu_info {
>   static inline struct cpu_info *get_cpu_info(void)
>   {
>       register unsigned long sp asm("rsp");
> +    asm("" : "=r" (sp));
>   
>       return (struct cpu_info *)((sp & ~(STACK_SIZE-1)) + STACK_SIZE) - 1;
>   }
>
> That silences the warning (not sure it it works).

It functions under GCC as well, but undoes some (but not all of) the 
improvements introduced as a result of df0ae94f.

It would probably be acceptable in a suitable #ifdef, along with comment 
why this seemingly redundant statement is present.

~Andrew

      reply	other threads:[~2014-09-15  8:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-01 10:58 [PATCH] x86/current: Provide additional information to optimise get_cpu_info() Andrew Cooper
2014-09-01 11:24 ` Jan Beulich
2014-09-01 12:18   ` Andrew Cooper
2014-09-01 12:32     ` Jan Beulich
2014-09-01 15:27       ` [PATCH v2] " Andrew Cooper
2014-09-13 16:10         ` Marcin Cieslak
2014-09-15  8:16           ` Andrew Cooper [this message]

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=5416A058.9040305@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=saper@saper.info \
    --cc=xen-devel@lists.xensource.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.