diff options
author | Benny Prijono <bennylp@teluu.com> | 2005-11-21 16:59:47 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2005-11-21 16:59:47 +0000 |
commit | 483dfa9a40e1818c9fd1cc1dd82884ddbf243778 (patch) | |
tree | abc1e115673177003f0ad0d51ba495e4d9f05238 /pjlib/src/pj/os_timestamp_win32.c | |
parent | 4a4fe6471b8a930ec49a28cced2f7a5ea55aee26 (diff) |
Added rdtsc option for win32 timestamp and added pj_elapsed_msec
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@70 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src/pj/os_timestamp_win32.c')
-rw-r--r-- | pjlib/src/pj/os_timestamp_win32.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/pjlib/src/pj/os_timestamp_win32.c b/pjlib/src/pj/os_timestamp_win32.c index eeff6c00..757a3000 100644 --- a/pjlib/src/pj/os_timestamp_win32.c +++ b/pjlib/src/pj/os_timestamp_win32.c @@ -20,6 +20,75 @@ #include <pj/errno.h> #include <windows.h> +#if defined(PJ_TIMESTAMP_USE_RDTSC) && PJ_TIMESTAMP_USE_RDTSC!=0 && \ + defined(PJ_M_I386) && PJ_M_I386 != 0 && \ + defined(_MSC_VER) +/* + * Use rdtsc to get the OS timestamp. + */ +static LONG CpuMhz; +static pj_int64_t CpuHz; + +static pj_status_t GetCpuHz(void) +{ + HKEY key; + LONG rc; + DWORD size; + + rc = RegOpenKey( HKEY_LOCAL_MACHINE, + "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", + &key); + if (rc != ERROR_SUCCESS) + return PJ_RETURN_OS_ERROR(rc); + + size = sizeof(CpuMhz); + rc = RegQueryValueEx(key, "~MHz", NULL, NULL, (BYTE*)&CpuMhz, &size); + RegCloseKey(key); + + if (rc != ERROR_SUCCESS) { + return PJ_RETURN_OS_ERROR(rc); + } + + CpuHz = CpuMhz; + CpuHz = CpuHz * 1000000; + + return PJ_SUCCESS; +} + +/* __int64 is nicely returned in EDX:EAX */ +__declspec(naked) __int64 rdtsc() +{ + __asm + { + RDTSC + RET + } +} + +PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts) +{ + ts->u64 = rdtsc(); + return PJ_SUCCESS; +} + +PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq) +{ + pj_status_t status; + + if (CpuHz == 0) { + status = GetCpuHz(); + if (status != PJ_SUCCESS) + return status; + } + + freq->u64 = CpuHz; + return PJ_SUCCESS; +} + +#else +/* + * Use QueryPerformanceCounter and QueryPerformanceFrequency. + */ PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts) { LARGE_INTEGER val; @@ -42,3 +111,5 @@ PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq) return PJ_SUCCESS; } +#endif /* PJ_TIMESTAMP_USE_RDTSC */ + |