LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* questions about rd{msr|tsc|pmc} instruction with x86-64
@ 2008-10-16  6:30 Jike Song
  2008-10-16  6:39 ` H. Peter Anvin
  0 siblings, 1 reply; 5+ messages in thread
From: Jike Song @ 2008-10-16  6:30 UTC (permalink / raw)
  To: gcosta; +Cc: linux-kernel, hpa

Hi experts,

commit c210d24986dc19e387c10508c0bc2faadadc1a2e  introduced such codes
and comments in include/asm-x86/msr.h:

/*
 * i386 calling convention returns 64-bit value in edx:eax, while
 * x86_64 returns at rax. Also, the "A" constraint does not really
 * mean rdx:rax in x86_64, so we need specialized behaviour for each
 * architecture
 */
#ifdef CONFIG_X86_64
#define DECLARE_ARGS(val, low, high)	unsigned low, high
#define EAX_EDX_VAL(val, low, high)	((low) | ((u64)(high) << 32))
#define EAX_EDX_ARGS(val, low, high)	"a" (low), "d" (high)
#define EAX_EDX_RET(val, low, high)	"=a" (low), "=d" (high)
#else
#define DECLARE_ARGS(val, low, high)	unsigned long long val
#define EAX_EDX_VAL(val, low, high)	(val)
#define EAX_EDX_ARGS(val, low, high)	"A" (val)
#define EAX_EDX_RET(val, low, high)	"=A" (val)
#endif

By my reading of Intel & AMD manuals, this comment is wrong.  rdmsr of
x86-64 has the same behavior as i386, namely the high 32bit returns in
edx and the low 32bit in eax, not "returns at rax".  And the gcc
constraint "A" does mean edx:eax in x86-64 also, at least when testing
on my AMD Turion 64 processor.

So the question is, do we really need these macros? Why a single "A"
won't work?  Or do I have anything misunderstood?

-- 
Thanks,
Jike

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: questions about rd{msr|tsc|pmc} instruction with x86-64
  2008-10-16  6:30 questions about rd{msr|tsc|pmc} instruction with x86-64 Jike Song
@ 2008-10-16  6:39 ` H. Peter Anvin
  2008-10-16 16:31   ` Jike Song
  0 siblings, 1 reply; 5+ messages in thread
From: H. Peter Anvin @ 2008-10-16  6:39 UTC (permalink / raw)
  To: Jike Song; +Cc: gcosta, linux-kernel

Jike Song wrote:
> 
> By my reading of Intel & AMD manuals, this comment is wrong.  rdmsr of
> x86-64 has the same behavior as i386, namely the high 32bit returns in
> edx and the low 32bit in eax, not "returns at rax".  And the gcc
> constraint "A" does mean edx:eax in x86-64 also, at least when testing
> on my AMD Turion 64 processor.
> 

"A" means rdx:rax on x86-64, not edx:eax.  For a 64-bit number, it 
means, literally, "one of rdx or rax"!  As you correctly point out, this 
is not how rdmsr works.

	-hpa

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: questions about rd{msr|tsc|pmc} instruction with x86-64
  2008-10-16  6:39 ` H. Peter Anvin
@ 2008-10-16 16:31   ` Jike Song
       [not found]     ` <48F76FA3.1000602@zytor.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Jike Song @ 2008-10-16 16:31 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: gcosta, linux-kernel

On Thu, Oct 16, 2008 at 2:39 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> Jike Song wrote:
>> {snip}
>
> "A" means rdx:rax on x86-64, not edx:eax.  For a 64-bit number, it means,
> literally, "one of rdx or rax"!  As you correctly point out, this is not how
> rdmsr works.
>
>        -hpa
>

Thanks, Peter!  So I misunderstood the gcc constraint 'A' for x86-64,
but seems the comment "while x86_64 returns at rax" still wrong,
should this be fixed?

-- 
Thanks,
Jike

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: questions about rd{msr|tsc|pmc} instruction with x86-64
       [not found]     ` <48F76FA3.1000602@zytor.com>
@ 2008-10-17  5:25       ` Jike Song
  2008-10-20 13:47         ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Jike Song @ 2008-10-17  5:25 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: trivial, linux-kernel

H. Peter Anvin wrote:
>  Jike Song wrote:
> > Thanks, Peter!  So I misunderstood the gcc constraint 'A' for x86-64,
> > but seems the comment "while x86_64 returns at rax" still wrong,
> > should this be fixed?
>
>  Yes, feel free to submit a patch.
>
>     -hpa
Here you go... CC trivial@kernel.org as well.

 From 6eed2948d41f959dc113eb3ff30927bcacf34d08 Mon Sep 17 00:00:00 2001
From: Jike Song <albcamus@gmail.com>
Date: Fri, 17 Oct 2008 10:51:13 +0800
Subject: [PATCH] x86: correct wrong comment

The rdmsr instruction(et al) for i386 and x86-64 are semantically same.
The only difference is how gcc interpret constraint "A" for these targets.

Signed-off-by: Jike Song <albcamus@gmail.com>
---
 include/asm-x86/msr.h |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/asm-x86/msr.h b/include/asm-x86/msr.h
index 530af1f..fd0e1a1 100644
--- a/include/asm-x86/msr.h
+++ b/include/asm-x86/msr.h
@@ -22,10 +22,10 @@ static inline unsigned long long 
native_read_tscp(unsigned int *aux)
 }
 
 /*
- * i386 calling convention returns 64-bit value in edx:eax, while
- * x86_64 returns at rax. Also, the "A" constraint does not really
- * mean rdx:rax in x86_64, so we need specialized behaviour for each
- * architecture
+ * both i386 and x86_64 returns 64-bit value in edx:eax, but gcc's "A"
+ * constraint has different meanings. For i386, "A" means exactly
+ * edx:eax, while for x86_64 it doesn't mean rdx:rax or edx:eax. Instead,
+ * it means rax *or* rdx.
  */
 #ifdef CONFIG_X86_64
 #define DECLARE_ARGS(val, low, high)    unsigned low, high
-- 
1.6.0.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: questions about rd{msr|tsc|pmc} instruction with x86-64
  2008-10-17  5:25       ` Jike Song
@ 2008-10-20 13:47         ` Ingo Molnar
  0 siblings, 0 replies; 5+ messages in thread
From: Ingo Molnar @ 2008-10-20 13:47 UTC (permalink / raw)
  To: Jike Song; +Cc: H. Peter Anvin, trivial, linux-kernel


* Jike Song <albcamus@gmail.com> wrote:

> H. Peter Anvin wrote:
>>  Jike Song wrote:
>> > Thanks, Peter!  So I misunderstood the gcc constraint 'A' for x86-64,
>> > but seems the comment "while x86_64 returns at rax" still wrong,
>> > should this be fixed?
>>
>>  Yes, feel free to submit a patch.
>>
>>     -hpa
> Here you go... CC trivial@kernel.org as well.
>
> From 6eed2948d41f959dc113eb3ff30927bcacf34d08 Mon Sep 17 00:00:00 2001
> From: Jike Song <albcamus@gmail.com>
> Date: Fri, 17 Oct 2008 10:51:13 +0800
> Subject: [PATCH] x86: correct wrong comment
>
> The rdmsr instruction(et al) for i386 and x86-64 are semantically same.
> The only difference is how gcc interpret constraint "A" for these targets.
>
> Signed-off-by: Jike Song <albcamus@gmail.com>
> ---
> include/asm-x86/msr.h |    8 ++++----
> 1 files changed, 4 insertions(+), 4 deletions(-)

applied to tip/x86/cleanups, thanks!

	Ingo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-10-20 13:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-16  6:30 questions about rd{msr|tsc|pmc} instruction with x86-64 Jike Song
2008-10-16  6:39 ` H. Peter Anvin
2008-10-16 16:31   ` Jike Song
     [not found]     ` <48F76FA3.1000602@zytor.com>
2008-10-17  5:25       ` Jike Song
2008-10-20 13:47         ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).