Skip to content

Commit 77de6e6

Browse files
huoyaoyuanjkotas
andauthored
Consolidate QueryPerformanceCounter/GetTickCount usages to minipal/time.h (#115408)
Remove the duplicated implementations and use minipal/time.h as single source of truth. Not touching a bit ifdef'd-out instances, which are supposed for local debug usages only. Co-authored-by: Jan Kotas <[email protected]>
1 parent ef640d0 commit 77de6e6

File tree

127 files changed

+404
-1316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+404
-1316
lines changed

src/coreclr/System.Private.CoreLib/src/System/Environment.CoreCLR.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,5 @@ private static unsafe string[] InitializeCommandLineArgs(char* exePath, int argc
108108

109109
// Used by VM
110110
internal static string? GetResourceStringLocal(string key) => SR.GetResourceString(key);
111-
112-
/// <summary>Gets the number of milliseconds elapsed since the system started.</summary>
113-
/// <value>A 32-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started.</value>
114-
public static extern int TickCount
115-
{
116-
[MethodImpl(MethodImplOptions.InternalCall)]
117-
get;
118-
}
119-
120-
/// <summary>Gets the number of milliseconds elapsed since the system started.</summary>
121-
/// <value>A 64-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started.</value>
122-
public static extern long TickCount64
123-
{
124-
[MethodImpl(MethodImplOptions.InternalCall)]
125-
get;
126-
}
127111
}
128112
}

src/coreclr/classlibnative/bcltype/system.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,6 @@
3232

3333
#include <minipal/cpuid.h>
3434

35-
36-
FCIMPL0(UINT32, SystemNative::GetTickCount)
37-
{
38-
FCALL_CONTRACT;
39-
40-
return ::GetTickCount();
41-
}
42-
FCIMPLEND;
43-
44-
FCIMPL0(UINT64, SystemNative::GetTickCount64)
45-
{
46-
FCALL_CONTRACT;
47-
48-
return ::GetTickCount64();
49-
}
50-
FCIMPLEND;
51-
52-
5335
extern "C" VOID QCALLTYPE Environment_Exit(INT32 exitcode)
5436
{
5537
QCALL_CONTRACT;

src/coreclr/classlibnative/bcltype/system.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ class SystemNative
3737

3838
public:
3939
// Functions on the System.Environment class
40-
static FCDECL0(UINT32, GetTickCount);
41-
static FCDECL0(UINT64, GetTickCount64);
42-
4340
static FCDECL1(VOID,SetExitCode,INT32 exitcode);
4441
static FCDECL0(INT32, GetExitCode);
4542

src/coreclr/debug/createdump/config.h.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@
44
#pragma once
55

66
#cmakedefine HAVE_PROCESS_VM_READV
7-
#cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP
8-
#cmakedefine01 HAVE_CLOCK_MONOTONIC
Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
11
check_function_exists(process_vm_readv HAVE_PROCESS_VM_READV)
22

3-
check_symbol_exists(
4-
clock_gettime_nsec_np
5-
time.h
6-
HAVE_CLOCK_GETTIME_NSEC_NP)
7-
8-
check_cxx_source_runs("
9-
#include <stdlib.h>
10-
#include <time.h>
11-
#include <sys/time.h>
12-
13-
int main()
14-
{
15-
int ret;
16-
struct timespec ts;
17-
ret = clock_gettime(CLOCK_MONOTONIC, &ts);
18-
19-
exit(ret);
20-
}" HAVE_CLOCK_MONOTONIC)
21-
223
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)

src/coreclr/debug/createdump/createdumpmain.cpp

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
#include "createdump.h"
5+
#include "minipal/time.h"
56

67
#ifdef HOST_WINDOWS
78
#define DEFAULT_DUMP_PATH "%TEMP%\\"
@@ -45,8 +46,6 @@ bool g_diagnostics = false;
4546
bool g_diagnosticsVerbose = false;
4647
uint64_t g_ticksPerMS = 0;
4748
uint64_t g_startTime = 0;
48-
uint64_t GetTickFrequency();
49-
uint64_t GetTimeStamp();
5049

5150
//
5251
// Common entry point
@@ -198,8 +197,8 @@ int createdump_main(const int argc, const char* argv[])
198197
return -1;
199198
}
200199

201-
g_ticksPerMS = GetTickFrequency() / 1000UL;
202-
g_startTime = GetTimeStamp();
200+
g_ticksPerMS = minipal_hires_tick_frequency() / 1000UL;
201+
g_startTime = minipal_hires_ticks();
203202
TRACE("TickFrequency: %d ticks per ms\n", g_ticksPerMS);
204203

205204
ArrayHolder<char> tmpPath = new char[MAX_LONGPATH];
@@ -221,11 +220,11 @@ int createdump_main(const int argc, const char* argv[])
221220

222221
if (CreateDump(options))
223222
{
224-
printf_status("Dump successfully written in %llums\n", GetTimeStamp() - g_startTime);
223+
printf_status("Dump successfully written in %llums\n", (minipal_hires_ticks() - g_startTime) / g_ticksPerMS);
225224
}
226225
else
227226
{
228-
printf_error("Failure took %llums\n", GetTimeStamp() - g_startTime);
227+
printf_error("Failure took %llums\n", (minipal_hires_ticks() - g_startTime) / g_ticksPerMS);
229228
exitCode = -1;
230229
}
231230

@@ -332,24 +331,6 @@ printf_error(const char* format, ...)
332331
va_end(args);
333332
}
334333

335-
uint64_t
336-
GetTickFrequency()
337-
{
338-
LARGE_INTEGER ret;
339-
ZeroMemory(&ret, sizeof(LARGE_INTEGER));
340-
QueryPerformanceFrequency(&ret);
341-
return ret.QuadPart;
342-
}
343-
344-
uint64_t
345-
GetTimeStamp()
346-
{
347-
LARGE_INTEGER ret;
348-
ZeroMemory(&ret, sizeof(LARGE_INTEGER));
349-
QueryPerformanceCounter(&ret);
350-
return ret.QuadPart / g_ticksPerMS;
351-
}
352-
353334
#ifdef HOST_UNIX
354335

355336
static void
@@ -360,7 +341,7 @@ trace_prefix(const char* format, va_list args)
360341
{
361342
fprintf(g_stdout, "[createdump] ");
362343
}
363-
fprintf(g_stdout, "%08" PRIx64 " ", GetTimeStamp());
344+
fprintf(g_stdout, "%08" PRIx64 " ", minipal_hires_ticks() / g_ticksPerMS);
364345
vfprintf(g_stdout, format, args);
365346
fflush(g_stdout);
366347
}

src/coreclr/debug/createdump/createdumppal.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -96,52 +96,6 @@ UninitializePAL(
9696
}
9797
}
9898

99-
#define tccSecondsToNanoSeconds 1000000000 // 10^9
100-
101-
BOOL
102-
PALAPI
103-
QueryPerformanceCounter(
104-
OUT LARGE_INTEGER* lpPerformanceCount)
105-
{
106-
#if HAVE_CLOCK_GETTIME_NSEC_NP
107-
lpPerformanceCount->QuadPart = (LONGLONG)clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
108-
#elif HAVE_CLOCK_MONOTONIC
109-
struct timespec ts;
110-
int result = clock_gettime(CLOCK_MONOTONIC, &ts);
111-
if (result != 0)
112-
{
113-
return TRUE;
114-
}
115-
else
116-
{
117-
lpPerformanceCount->QuadPart = ((LONGLONG)(ts.tv_sec) * (LONGLONG)(tccSecondsToNanoSeconds)) + (LONGLONG)(ts.tv_nsec);
118-
}
119-
#else
120-
#error "The createdump requires either mach_absolute_time() or clock_gettime(CLOCK_MONOTONIC) to be supported."
121-
#endif
122-
return TRUE;
123-
}
124-
125-
BOOL
126-
PALAPI
127-
QueryPerformanceFrequency(
128-
OUT LARGE_INTEGER* lpFrequency)
129-
{
130-
#if HAVE_CLOCK_GETTIME_NSEC_NP
131-
lpFrequency->QuadPart = (LONGLONG)(tccSecondsToNanoSeconds);
132-
#elif HAVE_CLOCK_MONOTONIC
133-
// clock_gettime() returns a result in terms of nanoseconds rather than a count. This
134-
// means that we need to either always scale the result by the actual resolution (to
135-
// get a count) or we need to say the resolution is in terms of nanoseconds. We prefer
136-
// the latter since it allows the highest throughput and should minimize error propagated
137-
// to the user.
138-
lpFrequency->QuadPart = (LONGLONG)(tccSecondsToNanoSeconds);
139-
#else
140-
#error "The createdump requires either mach_absolute_time() or clock_gettime(CLOCK_MONOTONIC) to be supported."
141-
#endif
142-
return TRUE;
143-
}
144-
14599
#define TEMP_DIRECTORY_PATH "/tmp/"
146100

147101
DWORD

src/coreclr/dlls/mscordac/mscordac_unixexports.src

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ nativeStringResourceTable_mscorrc
113113
#OutputDebugStringW
114114
#OpenEventW
115115
#OutputDebugStringA
116-
#QueryPerformanceCounter
117-
#QueryPerformanceFrequency
118116
#RaiseException
119117
#RaiseFailFastException
120118
#ReadFile

src/coreclr/gc/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,14 @@ if(CLR_CMAKE_HOST_WIN32)
8585
advapi32.lib)
8686
endif(CLR_CMAKE_HOST_WIN32)
8787

88-
set (GC_LINK_LIBRARIES ${GC_LINK_LIBRARIES} gc_pal)
88+
set (GC_LINK_LIBRARIES
89+
${GC_LINK_LIBRARIES}
90+
gc_pal
91+
minipal)
8992

9093
if(CLR_CMAKE_TARGET_ARCH_AMD64)
9194
list(APPEND GC_LINK_LIBRARIES
9295
gc_vxsort
93-
minipal
9496
)
9597
endif(CLR_CMAKE_TARGET_ARCH_AMD64)
9698

src/coreclr/gc/unix/config.gc.h.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#cmakedefine01 HAVE_SYSCTLBYNAME
1818
#cmakedefine01 HAVE_PTHREAD_CONDATTR_SETCLOCK
1919
#cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP
20-
#cmakedefine01 HAVE_CLOCK_MONOTONIC
2120
#cmakedefine01 HAVE_SCHED_GETAFFINITY
2221
#cmakedefine01 HAVE_SCHED_SETAFFINITY
2322
#cmakedefine01 HAVE_PTHREAD_SETAFFINITY_NP

0 commit comments

Comments
 (0)