Open
Bug 707783
Opened 13 years ago
Updated 2 years ago
Check if TSC constant rate detection would simplify code of TimeStamp impl on windows
Categories
(Core :: XPCOM, defect)
Tracking
()
NEW
People
(Reporter: mayhemer, Unassigned)
References
Details
Bug 676349 comment 56 (Jeff Muizelaar):
> We should be able to use something like the following to detect situations
> where QPC is going to work reliably:
>
> #include <intrin.h>
>
> static bool
> has_stable_tsc()
> {
> int regs[4];
>
> // detect if the Advanced Power Management feature is supported
> __cpuid(regs, 0x80000000);
> if (regs[0] < 0x80000007)
> return false;
>
> __cpuid(regs, 0x80000007);
> // if bit 8 is set than TSC will run at a constant rate
> // in all ACPI P-state, C-states and T-states
> return regs[4] & (1 << 8);
> }
>
> It would be nice to use this to avoid the overhead of having to do both QPC
> and GTC for ever TimeStamp::Now()
I personally don't think this is useful for using QueryPerformanceCounter. QPC function should do these checks for the programmer it self. I don't think using RDTSC instruction directly is what we want to use at all and this code seems to be related only to direct use of that instruction.
But this is still worth to investigate on.
Comment 1•13 years ago
|
||
Well, I suppose the question is whether Windows (XP, Vista, 7, 8) makes use of rdtsc if invariant TSC is available. If it does, then the calibration code can safely be disabled on processors that support invariant TSC - otherwise, I guess the code could fairly easily use rdtsc manually, but like you said we may not want that.
Comment 2•13 years ago
|
||
(In reply to Honza Bambas (:mayhemer) from comment #0)
> Bug 676349 comment 56 (Jeff Muizelaar):
>
> > We should be able to use something like the following to detect situations
> > where QPC is going to work reliably:
> >
> > #include <intrin.h>
> >
> > static bool
> > has_stable_tsc()
> > {
> > int regs[4];
> >
> > // detect if the Advanced Power Management feature is supported
> > __cpuid(regs, 0x80000000);
> > if (regs[0] < 0x80000007)
> > return false;
> >
> > __cpuid(regs, 0x80000007);
> > // if bit 8 is set than TSC will run at a constant rate
> > // in all ACPI P-state, C-states and T-states
> > return regs[4] & (1 << 8);
> > }
> >
> > It would be nice to use this to avoid the overhead of having to do both QPC
> > and GTC for ever TimeStamp::Now()
>
>
>
> I personally don't think this is useful for using QueryPerformanceCounter.
> QPC function should do these checks for the programmer it self. I don't
> think using RDTSC instruction directly is what we want to use at all and
> this code seems to be related only to direct use of that instruction.
>
> But this is still worth to investigate on.
QPC uses RDTSC on Windows 7. If we have a constant rate tsc then we now that we can trust the results of QPC (at least on a single processor machine) which should improve the TimeStamp::Now() performance closer to the other platforms for a large chunk of users.
Comment 3•13 years ago
|
||
It looks like Intel machines with CONSTANT_TSC have a synchronized clock across all sockets:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/x86/kernel/tsc.c;h=c0dd5b603749057db73420caacc321d5d714338f;hb=HEAD#l822'
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•