Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
4570478a
Commit
4570478a
authored
Feb 13, 2001
by
James Abbatiello
Committed by
Alexandre Julliard
Feb 13, 2001
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the Pentium's rdtsc instruction (if available) to implement
QueryPerformanceCounter.
parent
2859af90
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
5 deletions
+99
-5
winnt.h
include/winnt.h
+3
-0
cpu.c
misc/cpu.c
+2
-0
newfns.c
win32/newfns.c
+94
-5
No files found.
include/winnt.h
View file @
4570478a
...
...
@@ -518,6 +518,9 @@ typedef struct _SINGLE_LIST_ENTRY {
#define PF_MMX_INSTRUCTIONS_AVAILABLE 3
#define PF_PPC_MOVEMEM_64BIT_OK 4
#define PF_ALPHA_BYTE_INSTRUCTIONS 5
#define PF_XMMI_INSTRUCTIONS_AVAILABLE 6
#define PF_AMD3D_INSTRUCTIONS_AVAILABLE 7
#define PF_RDTSC_INSTRUCTION_AVAILABLE 8
/* The Win32 register context */
...
...
misc/cpu.c
View file @
4570478a
...
...
@@ -198,6 +198,8 @@ VOID WINAPI GetSystemInfo(
PF
[
PF_COMPARE_EXCHANGE_DOUBLE
]
=
TRUE
;
if
(
strstr
(
value
,
"mmx"
))
PF
[
PF_MMX_INSTRUCTIONS_AVAILABLE
]
=
TRUE
;
if
(
strstr
(
value
,
"tsc"
))
PF
[
PF_RDTSC_INSTRUCTION_AVAILABLE
]
=
TRUE
;
}
}
...
...
win32/newfns.c
View file @
4570478a
...
...
@@ -7,6 +7,7 @@
/* Misc. new functions - they should be moved into appropriate files
at a later date. */
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
...
...
@@ -19,6 +20,69 @@ DEFAULT_DEBUG_CHANNEL(win32);
DECLARE_DEBUG_CHANNEL
(
debug
);
static
BOOL
QUERYPERF_Initialized
=
0
;
#if defined(__i386__) && defined(__GNUC__)
static
BOOL
QUERYPERF_RDTSC_Use
=
0
;
static
LONGLONG
QUERYPERF_RDTSC_Frequency
=
0
;
#endif
static
void
QUERYPERF_Init
(
void
)
{
#if defined(__i386__) && defined(__GNUC__)
/* We are running on i386 and compiling on GCC.
* Do a runtime check to see if we have the rdtsc instruction available
*/
FILE
*
fp
;
char
line
[
256
],
*
s
,
*
value
;
double
cpuMHz
;
TRACE
(
"()
\n
"
);
if
(
IsProcessorFeaturePresent
(
PF_RDTSC_INSTRUCTION_AVAILABLE
))
{
/* rdtsc is available. However, in order to use it
* we also need to be able to get the processor's
* speed. Currently we do this by reading /proc/cpuinfo
* which makes it Linux-specific.
*/
TRACE
(
"rdtsc available
\n
"
);
fp
=
fopen
(
"/proc/cpuinfo"
,
"r"
);
if
(
fp
)
{
while
(
fgets
(
line
,
sizeof
(
line
),
fp
))
{
/* NOTE: the ':' is the only character we can rely on */
if
(
!
(
value
=
strchr
(
line
,
':'
)))
continue
;
/* terminate the valuename */
*
value
++
=
'\0'
;
/* skip any leading spaces */
while
(
*
value
==
' '
)
value
++
;
if
((
s
=
strchr
(
value
,
'\n'
)))
*
s
=
'\0'
;
if
(
!
strncasecmp
(
line
,
"cpu MHz"
,
strlen
(
"cpu MHz"
)
))
{
if
(
sscanf
(
value
,
"%lf"
,
&
cpuMHz
)
==
1
)
{
QUERYPERF_RDTSC_Frequency
=
(
LONGLONG
)(
cpuMHz
*
1000000
.
0
);
QUERYPERF_RDTSC_Use
=
TRUE
;
TRACE
(
"using frequency: %lldHz
\n
"
,
QUERYPERF_RDTSC_Frequency
);
break
;
}
}
}
fclose
(
fp
);
}
}
#endif
QUERYPERF_Initialized
=
TRUE
;
}
/****************************************************************************
* QueryPerformanceCounter (KERNEL32.564)
*/
...
...
@@ -26,9 +90,23 @@ BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
{
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
counter
->
s
.
LowPart
=
tv
.
tv_usec
+
tv
.
tv_sec
*
1000000
;
counter
->
s
.
HighPart
=
0
;
if
(
!
QUERYPERF_Initialized
)
QUERYPERF_Init
();
#if defined(__i386__) && defined(__GNUC__)
if
(
QUERYPERF_RDTSC_Use
)
{
/* i586 optimized version */
__asm__
__volatile__
(
"rdtsc"
:
"=a"
(
counter
->
s
.
LowPart
),
"=d"
(
counter
->
s
.
HighPart
)
);
return
TRUE
;
}
/* fall back to generic routine (ie, for i386, i486) */
#endif
/* generic routine */
gettimeofday
(
&
tv
,
NULL
);
counter
->
QuadPart
=
(
LONGLONG
)
tv
.
tv_usec
+
(
LONGLONG
)
tv
.
tv_sec
*
1000000LL
;
return
TRUE
;
}
...
...
@@ -37,9 +115,20 @@ BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
*/
BOOL
WINAPI
QueryPerformanceFrequency
(
PLARGE_INTEGER
frequency
)
{
frequency
->
s
.
LowPart
=
1000000
;
frequency
->
s
.
HighPart
=
0
;
if
(
!
QUERYPERF_Initialized
)
QUERYPERF_Init
();
#if defined(__i386__) && defined(__GNUC__)
if
(
QUERYPERF_RDTSC_Use
)
{
frequency
->
QuadPart
=
QUERYPERF_RDTSC_Frequency
;
return
TRUE
;
}
#endif
frequency
->
s
.
LowPart
=
1000000
;
frequency
->
s
.
HighPart
=
0
;
return
TRUE
;
}
/****************************************************************************
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment