| ︙ | | | ︙ | |
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
* virtTimeBase + (currentPerfCounter - perfCounter)
* * 10000000 / nominalFreq
*/
typedef struct TimeCalibInfo {
LONGLONG perfCounter; /* QPC value of last calibrated virtual time */
Tcl_WideInt virtTimeBase; /* Last virtual time base (in 100-ns) */
Tcl_WideInt sysTime; /* Last real system time (in 100-ns),
truncated to VT_SYSTMR_DIST (100ms) */
} TimeCalibInfo;
/* Milliseconds <-> 100-ns ticks */
#define MsToT100ns(ms) (ms * 10000)
#define T100nsToMs(ms) (ms / 10000)
/* Microseconds <-> 100-ns ticks */
#define UsToT100ns(ms) (ms * 10)
#define T100nsToUs(ms) (ms / 10)
/*
* Use factor 1000 for the frequencies of QPC if it ascertained in Hz:
* frequency = nominal frequency / 1000
* native perf-counter = original perf-counter * 1000
*/
|
|
|
|
|
|
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
* virtTimeBase + (currentPerfCounter - perfCounter)
* * 10000000 / nominalFreq
*/
typedef struct TimeCalibInfo {
LONGLONG perfCounter; /* QPC value of last calibrated virtual time */
Tcl_WideInt virtTimeBase; /* Last virtual time base (in 100-ns) */
Tcl_WideInt sysTime; /* Last real system time (in 100-ns),
truncated to VT_SYSTMR_DIST (100ms) */
} TimeCalibInfo;
/* Milliseconds <-> 100-ns ticks */
#define MsToT100ns(ms) ((ms) * 10000)
#define T100nsToMs(ms) ((ms) / 10000)
/* Microseconds <-> 100-ns ticks */
#define UsToT100ns(ms) ((ms) * 10)
#define T100nsToUs(ms) ((ms) / 10)
/*
* Use factor 1000 for the frequencies of QPC if it ascertained in Hz:
* frequency = nominal frequency / 1000
* native perf-counter = original perf-counter * 1000
*/
|
| ︙ | | | ︙ | |
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
* the windows epoch. */
TimeCalibInfo lastCI; /* Last virtual timer-data updated in the
* calibration process. */
volatile LONG lastCIEpoch; /* Calibration epoch (increased each 100ms) */
size_t lastUsedTime; /* Last known (caller) offset to virtual time
* (used to avoid back-drifts after calibrate) */
} TimeInfo;
static TimeInfo timeInfo = {
{ NULL, 0, 0, NULL, NULL, 0 },
0,
0,
(LONGLONG) 0,
|
|
>
|
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
* the windows epoch. */
TimeCalibInfo lastCI; /* Last virtual timer-data updated in the
* calibration process. */
volatile LONG lastCIEpoch; /* Calibration epoch (increased each 100ms) */
size_t lastUsedTime; /* Last known (caller) offset to virtual time
* (used to avoid back-drifts after calibrate) */
size_t lastTimeJumpEpoch; /* Last known epoch since last time-jump. */
Tcl_WideInt lastTimeJump; /* Last known time-jump of thread. */
} TimeInfo;
static TimeInfo timeInfo = {
{ NULL, 0, 0, NULL, NULL, 0 },
0,
0,
(LONGLONG) 0,
|
| ︙ | | | ︙ | |
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
*
*----------------------------------------------------------------------
*/
Tcl_WideInt
TclpGetMicroseconds(void)
{
#if 0
/* Use high resolution timer if possible */
if (tclGetTimeProcPtr == NativeGetTime) {
return NativeGetMicroseconds();
} else {
/*
* Use the Tcl_GetTime abstraction to get the time in microseconds, as
* nearly as we can, and return it.
*/
Tcl_Time now;
tclGetTimeProcPtr(&now, tclTimeClientData); /* Tcl_GetTime inlined */
return (((Tcl_WideInt)now.sec) * 1000000) + now.usec;
}
#else
static Tcl_WideInt prevUS = 0;
Tcl_WideInt usecSincePosixEpoch;
|
|
|
|
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
|
*
*----------------------------------------------------------------------
*/
Tcl_WideInt
TclpGetMicroseconds(void)
{
#if 1
/* Use high resolution timer if possible */
if (tclGetTimeProcPtr == NativeGetTime) {
return NativeGetMicroseconds();
} else {
/*
* Use the Tcl_GetTime abstraction to get the time in microseconds, as
* nearly as we can, and return it.
*/
Tcl_Time now;
tclGetTimeProcPtr(&now, tclTimeClientData); /* Tcl_GetTime inlined */
return TCL_TIME_TO_USEC(now);
}
#else
static Tcl_WideInt prevUS = 0;
Tcl_WideInt usecSincePosixEpoch;
|
| ︙ | | | ︙ | |
555
556
557
558
559
560
561
562
563
564
565
566
567
568
|
Tcl_Time *timePtr,
ClientData clientData)
{
/*
* Native scale is 1:1. Nothing is done.
*/
}
/*
*----------------------------------------------------------------------
*
* NativeGetMicroseconds --
*
* Gets the current system time in microseconds since the beginning
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
|
Tcl_Time *timePtr,
ClientData clientData)
{
/*
* Native scale is 1:1. Nothing is done.
*/
}
/*
*----------------------------------------------------------------------
*
* TclpScaleUTime --
*
* This procedure scales number of microseconds if expected.
*
* Results:
* Number of microseconds scaled using tclScaleTimeProcPtr.
*
*----------------------------------------------------------------------
*/
Tcl_WideInt
TclpScaleUTime(
Tcl_WideInt usec)
{
/* Native scale is 1:1. */
if (tclScaleTimeProcPtr == NativeScaleTime) {
return usec;
} else {
Tcl_Time scTime;
scTime.sec = usec / 1000000;
scTime.usec = usec % 1000000;
tclScaleTimeProcPtr(&scTime, tclTimeClientData);
return ((Tcl_WideInt)scTime.sec) * 1000000 + scTime.usec;
}
}
/*
*----------------------------------------------------------------------
*
* NativeGetMicroseconds --
*
* Gets the current system time in microseconds since the beginning
|
| ︙ | | | ︙ | |
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
|
if (timeInfo.perfCounterAvailable) {
InitializeCriticalSection(&timeInfo.cs);
timeInfo.lastCI.perfCounter = NativePerformanceCounter();
timeInfo.lastCI.sysTime =
timeInfo.lastCI.virtTimeBase = GetSystemTimeAsVirtual();
}
timeInfo.initialized = TRUE;
}
TclpInitUnlock();
}
if (timeInfo.perfCounterAvailable) {
|
|
|
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
|
if (timeInfo.perfCounterAvailable) {
InitializeCriticalSection(&timeInfo.cs);
timeInfo.lastCI.perfCounter = NativePerformanceCounter();
timeInfo.lastCI.sysTime =
timeInfo.lastCI.virtTimeBase = GetSystemTimeAsVirtual();
timeInfo.lastTimeJumpEpoch = 1; /* let the caller know we've epoch */
}
timeInfo.initialized = TRUE;
}
TclpInitUnlock();
}
if (timeInfo.perfCounterAvailable) {
|
| ︙ | | | ︙ | |
822
823
824
825
826
827
828
829
830
831
832
833
834
835
|
}
} else {
/*
* The time-jump (reset or initial), we should use system time
* instead of virtual to recalibrate offsets (let the time jump).
*/
vt0 = sysTime;
//!!! printf("************* reset time: %I64d *****************\n", vt0);
}
/*
* Adjustment of current base for virtual time. This will also
* prevent too large counter difference (resp. max distance ~ 100ms).
|
>
>
|
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
|
}
} else {
/*
* The time-jump (reset or initial), we should use system time
* instead of virtual to recalibrate offsets (let the time jump).
*/
timeInfo.lastTimeJump = T100nsToUs(sysTime - vt0); /* 100-ns */;
timeInfo.lastTimeJumpEpoch++;
vt0 = sysTime;
//!!! printf("************* reset time: %I64d *****************\n", vt0);
}
/*
* Adjustment of current base for virtual time. This will also
* prevent too large counter difference (resp. max distance ~ 100ms).
|
| ︙ | | | ︙ | |
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
|
if (scaleProc) {
*scaleProc = tclScaleTimeProcPtr;
}
if (clientData) {
*clientData = tclTimeClientData;
}
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
|
if (scaleProc) {
*scaleProc = tclScaleTimeProcPtr;
}
if (clientData) {
*clientData = tclTimeClientData;
}
}
Tcl_WideInt
TclpGetLastTimeJump(size_t *epoch)
{
if (timeInfo.lastTimeJumpEpoch > *epoch) {
*epoch = timeInfo.lastTimeJumpEpoch;
return timeInfo.lastTimeJump;
};
return 0;
}
size_t
TclpGetLastTimeJumpEpoch(void)
{
return timeInfo.lastTimeJumpEpoch;
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/
|