45 #if defined( MBG_TGT_POSIX ) 47 #if defined( MBG_TGT_KERNEL ) 49 #if defined( MBG_TGT_LINUX ) 51 #define LINUX_KERNEL_HAS_MSLEEP ( LINUX_VERSION_CODE >= KERNEL_VERSION( 2, 6, 16 ) ) 52 #define LINUX_KERNEL_HAS_GETNSTIMEOFDAY ( LINUX_VERSION_CODE >= KERNEL_VERSION( 2, 6, 22 ) ) 53 #define LINUX_KERNEL_HAS_KTIME_H ( LINUX_VERSION_CODE >= KERNEL_VERSION( 2, 6, 16 ) ) 55 #if !LINUX_KERNEL_HAS_MSLEEP 56 #include <linux/wait.h> 57 #include <linux/sched.h> 63 #if LINUX_KERNEL_HAS_KTIME_H 64 #include <linux/ktime.h> 69 #include <linux/time.h> 71 #include <linux/delay.h> 72 #include <linux/jiffies.h> 74 #elif defined( MBG_TGT_BSD ) 76 #if defined( MBG_TGT_FREEBSD ) 77 #include <sys/libkern.h> 80 #if defined( MBG_TGT_NETBSD ) 81 #include <sys/param.h> 82 #include <sys/kernel.h> 90 #else // POSIX user space 94 #if defined( MBG_TGT_LINUX ) 95 #include <sys/sysinfo.h> 100 #elif defined( MBG_TGT_WIN32 ) 102 #if defined( MBG_TGT_KERNEL ) 110 #elif defined( MBG_TGT_DOS ) 135 #if defined( MBG_TGT_POSIX ) 140 #elif defined( MBG_TGT_WIN32 ) 145 #elif defined( MBG_TGT_OS2 ) 150 #elif defined( MBG_TGT_DOS ) 155 #else // other target OSs which access the hardware directly 165 #define _mbg_swab_mbg_sys_time( _p ) \ 173 #if defined( MBG_TGT_POSIX ) 175 #if defined( MBG_TGT_KERNEL ) // kernel space functions even differ for POSIX systems 177 #if defined( MBG_TGT_LINUX ) // Linux kernel space 179 #if ( LINUX_KERNEL_HAS_GETNSTIMEOFDAY ) 184 getnstimeofday( &ts );
194 do_gettimeofday( &tv );
201 #elif defined( MBG_TGT_BSD ) // BSD kernel space 212 #else // POSIX user space 216 #if defined( CLOCK_REALTIME_PRECISE ) // at least available in FreeBSD 217 clock_gettime( CLOCK_REALTIME_PRECISE, &ts );
219 clock_gettime( CLOCK_REALTIME, &ts );
227 #elif defined( MBG_TGT_WIN32 ) 229 #if defined( MBG_TGT_KERNEL ) // Windows kernel space 230 ke_query_system_time_fnc( (LARGE_INTEGER *) p );
231 #else // Windows user space 250 #if defined( MBG_TGT_WIN32 ) 252 #if defined( MBG_TGT_KERNEL ) // kernel space 254 ULONGLONG time_increment = KeQueryTimeIncrement();
255 LARGE_INTEGER tick_count;
257 KeQueryTickCount( &tick_count );
261 *p = ( tick_count.QuadPart * time_increment ) /
HNS_PER_SEC;
266 DWORD timeAdjustment;
268 BOOL timeAdjustmentDisabled;
270 if ( !GetSystemTimeAdjustment( &timeAdjustment, &timeIncrement, &timeAdjustmentDisabled ) )
278 tickCount = GetTickCount();
284 #elif defined( MBG_TGT_LINUX ) 286 #if defined( MBG_TGT_KERNEL ) 294 uint64_t tmp = get_jiffies_64() - INITIAL_JIFFIES;
301 int rc = sysinfo( &si );
302 *p = ( rc == 0 ) ? si.uptime : -1;
306 #elif defined( MBG_TGT_BSD ) 308 #if defined( MBG_TGT_KERNEL ) 317 printf(
"binuptime: %lli.%09lli\n",
319 (
long long) bt.frac );
326 printf(
"nanouptime: %lli.%09lli\n",
327 (
long long) ts.tv_sec,
328 (
long long) ts.tv_nsec );
332 #elif defined( MBG_TGT_FREEBSD ) 336 int rc = clock_gettime( CLOCK_UPTIME_FAST, &ts );
337 *p = ( rc == 0 ) ? ts.tv_sec : -1;
339 #else // MBG_TGT_NETBSD, ... 366 #if defined( MBG_TGT_POSIX ) 367 long dt = ( t2->
secs - t1->
secs ) * 1000;
368 #if defined ( MBG_TGT_LINUX ) && defined( MBG_TGT_KERNEL ) 370 do_div( tmp64, 1000000 );
376 #elif defined( MBG_TGT_WIN32 ) 389 #if defined( MBG_TGT_POSIX ) 391 #if defined( MBG_TGT_KERNEL ) // kernel space functions even differ for POSIX systems 393 #if defined( MBG_TGT_LINUX ) // Linux kernel space 397 #if LINUX_KERNEL_HAS_MSLEEP 398 msleep( sec * 1000 );
401 DECLARE_WAIT_QUEUE_HEAD( tmp_wait );
402 wait_event_interruptible_timeout( tmp_wait, 0, sec * HZ + 1 );
406 #elif defined( MBG_TGT_FREEBSD ) 408 struct timeval tv = { 0 };
411 ticks = tvtohz( &tv );
414 printf(
"pause: %lli.%06lli (%i ticks)\n",
415 (
long long) tv.tv_sec,
416 (
long long) tv.tv_usec,
420 pause(
"pause", ticks );
422 #elif defined( MBG_TGT_NETBSD ) 424 int timeo = mstohz( sec * 1000 );
427 printf(
"kpause: %i s (%i ticks)\n", sec, timeo );
430 kpause(
"pause", 1, timeo, NULL );
434 #else // POSIX user space 440 #elif defined( MBG_TGT_WIN32 ) 442 #if defined( MBG_TGT_KERNEL ) // kernel space 451 KeDelayExecutionThread( KernelMode, FALSE, &delay );
460 #elif defined( MBG_TGT_DOS ) 462 delay( (
unsigned) ( sec * 1000 ) );
A timestamp with nanosecond resolution, but 64 bit size.
static __mbg_inline void mbg_get_sys_uptime(MBG_SYS_UPTIME *p)
static __mbg_inline void mbg_get_sys_time(MBG_SYS_TIME *p)
static __mbg_inline long mbg_delta_sys_time_ms(const MBG_SYS_TIME *t2, const MBG_SYS_TIME *t1)
Compute delta between two MBG_SYS_TIME times, in milliseconds.
static __mbg_inline void mbg_sleep_sec(long sec)
NANO_TIME_64 MBG_SYS_TIME
int64_t nano_secs
[nanoseconds]
int64_t secs
[seconds], usually since 1970-01-01 00:00:00
unsigned __int64 uint64_t