3 * Politecnico di Torino. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the Politecnico
13 * di Torino, and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 #include "time_calls.h"
27 void TIME_DESYNCHRONIZE(struct time_conv
*data
)
31 data
->start
.tv_sec
= 0;
32 data
->start
.tv_usec
= 0;
38 /* KeQueryPerformanceCounter TimeStamps */
40 VOID
TIME_SYNCHRONIZE(struct time_conv
*data
)
44 LARGE_INTEGER SystemTime
;
47 LARGE_INTEGER TimeFreq
,PTime
;
49 if (data
->reference
!=0)
52 // get the absolute value of the system boot time.
53 PTime
=KeQueryPerformanceCounter(&TimeFreq
);
54 KeQuerySystemTime(&SystemTime
);
55 tmp
.tv_sec
=(LONG
)(SystemTime
.QuadPart
/10000000-11644473600);
56 tmp
.tv_usec
=(LONG
)((SystemTime
.QuadPart
%10000000)/10);
57 tmp
.tv_sec
-=(ULONG
)(PTime
.QuadPart
/TimeFreq
.QuadPart
);
58 tmp
.tv_usec
-=(LONG
)((PTime
.QuadPart
%TimeFreq
.QuadPart
)*1000000/TimeFreq
.QuadPart
);
68 void FORCE_TIME(struct timeval
*src
, struct time_conv
*dest
)
73 void GET_TIME(struct timeval
*dst
, struct time_conv
*data
)
76 LARGE_INTEGER PTime
, TimeFreq
;
79 PTime
=KeQueryPerformanceCounter(&TimeFreq
);
80 tmp
=(LONG
)(PTime
.QuadPart
/TimeFreq
.QuadPart
);
81 dst
->tv_sec
=data
->start
.tv_sec
+tmp
;
82 dst
->tv_usec
=data
->start
.tv_usec
+(LONG
)((PTime
.QuadPart
%TimeFreq
.QuadPart
)*1000000/TimeFreq
.QuadPart
);
83 if (dst
->tv_usec
>=1000000) {
85 dst
->tv_usec
-=1000000;
94 /* callers must be at IRQL=PASSIVE_LEVEL */
95 VOID
TIME_SYNCHRONIZE(struct time_conv
*data
)
99 LARGE_INTEGER system_time
;
100 ULONGLONG curr_ticks
;
102 LARGE_INTEGER start_kqpc
,stop_kqpc
,start_freq
,stop_freq
;
103 ULONGLONG start_ticks
,stop_ticks
;
104 ULONGLONG delta
,delta2
;
109 if (data
->reference
!=0)
112 KeInitializeEvent(&event
,NotificationEvent
,FALSE
);
114 KeRaiseIrql(HIGH_LEVEL
,&old
);
115 start_kqpc
=KeQueryPerformanceCounter(&start_freq
);
133 KeWaitForSingleObject(&event
,UserRequest
,KernelMode
,TRUE
,&i
);
134 KeRaiseIrql(HIGH_LEVEL
,&old
);
135 stop_kqpc
=KeQueryPerformanceCounter(&stop_freq
);
153 delta
=stop_ticks
-start_ticks
;
154 delta2
=stop_kqpc
.QuadPart
-start_kqpc
.QuadPart
;
155 if (delta
>10000000000) {
159 reference
=delta
*(start_freq
.QuadPart
)/delta2
;
160 data
->reference
=reference
/1000;
161 if (reference
%1000>500)
163 data
->reference
*=1000;
164 reference
=data
->reference
;
165 KeQuerySystemTime(&system_time
);
182 tmp
.tv_sec
=-(LONG
)(curr_ticks
/reference
);
183 tmp
.tv_usec
=-(LONG
)((curr_ticks
%reference
)*1000000/reference
);
184 system_time
.QuadPart
-=116444736000000000;
185 tmp
.tv_sec
+=(LONG
)(system_time
.QuadPart
/10000000);
186 tmp
.tv_usec
+=(LONG
)((system_time
.QuadPart
%10000000)/10);
189 tmp
.tv_usec
+=1000000;
192 IF_LOUD(DbgPrint("Frequency %I64u MHz\n",data
->reference
);)
197 void FORCE_TIME(struct timeval
*src
, struct time_conv
*dest
)
202 void GET_TIME(struct timeval
*dst
, struct time_conv
*data
)
222 if (data
->reference
==0) {
225 dst
->tv_sec
=(LONG
)(tmp
/data
->reference
);
226 dst
->tv_usec
=(LONG
)((tmp
-dst
->tv_sec
*data
->reference
)*1000000/data
->reference
);
227 dst
->tv_sec
+=data
->start
.tv_sec
;
228 dst
->tv_usec
+=data
->start
.tv_usec
;
229 if (dst
->tv_usec
>=1000000) {
231 dst
->tv_usec
-=1000000;