[Ace-users] [ace-bugs] ACE_OS::gethrtime produces inconsistent results onx86_64 architecture
Nathan.Ernst at citadelgroup.com
Fri Nov 9 13:10:13 CST 2007
I stand corrected, and appreciate the additional information. The
thought had crossed my mind that this could produce suboptimal code on
x86, but I'd not the opportunity to investigate further.
Re: the gcc code generation, was this with, or without optimizations,
and, if with, at what level (piqued curiosity)?
I won't argue with the subtleties that surround rdtsc usage and its
default exclusion; I would tend to agree that functionality that can
produce sporadic errors ought to be avoided by default. That being
said, I'd (as I'm sure we all would) like to see usage of rdtsc be, when
enabled, correct regardless of x86 or x86_64 architectures.
Thanks again. I appreciate the attention this is being given and the
From: J.T. Conklin [mailto:jtc at acorntoolworks.com]
Sent: Friday, November 09, 2007 12:22 PM
To: Ernst, Nathan
Cc: Johnny Willemsen; ace-bugs at cs.wustl.edu
Subject: Re: [ace-bugs] ACE_OS::gethrtime produces inconsistent results
"Ernst, Nathan" <Nathan.Ernst at citadelgroup.com> writes:
> Regarding the thought that this fix is only from AMD64, I don't
> that is necessarily true. That the existing code works on x86 to
> with is a coincidence of the register layout. I don't mean to be
> pedantic (I am trying more to avoid unnecessary forking of the code),
> but the proposed fix of explicitly referring to both eax and edx is
> correct implementation, according the assembler reference.
I think I disagree. From the gcc manual, the i386's 'A' constraint:
Specifies the `a' or `d' registers. This is primarily useful
for 64-bit integer values (when in 32-bit mode) intended to
be returned with the `d' register holding the most
significant bits and the `a' register holding the least
asm volatile ("rdtsc" : "=A" (now) : : "memory");
Says that rdtsc insn writes %eax and %edx, and (if necessary) to copy
that to 64 bit integer "now". Since the next thing we do is return,
and the ABI also says that 64 bit integers are also returned in %eax
and %edx, it's more than a coincidence.
All that being said, your fix is needed for the AMD64. I thought that
gcc might be smart enough able to recognize putting the 32 halves back
together into the 64 bit whole on the 386, so the same code could be
used on both x86 and x86_64, but from quick tests it appears to generate
substantially worse code. So I think we'll really want two versions.
Unless Johnny wants to fight me for it, I'll take this on. Although I
will caution that using rdtsc has subtle issues, and I'll argue it
probably should *not* be enabled in any ACE config-*.h or binary ACE
distribution because the end user/integrator needs to carefully
consider whether those issues are going to effect their deployment.
(This may be some of the contraversial aspects Robert alluded to
earlier in this thread).
CONFIDENTIALITY AND SECURITY NOTICE
The contents of this message and any attachments may be privileged, confidential and proprietary and also may be covered by the Electronic Communications Privacy Act. This message is not intended to be used by, and should not be relied upon in any way by, any third party. If you are not an intended recipient, please inform the sender of the transmission error and delete this message immediately without reading, disseminating, distributing or copying the contents. Citadel makes no assurances that this e-mail and any attachments are free of viruses and other harmful code.
More information about the Ace-users