Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

531 lines
18 KiB

  1. This directory and its subdirectories contain source and
  2. binary files for the timer support packages that can
  3. be run across multiple platforms.
  4. NOTE: The dll under CR286 can be run under Cruiser only,
  5. since it uses the PerfView "thunked" timer. For Sloop/Cutter
  6. programs, use the dll under the Sloop directory. This uses
  7. the new 16BitTmr.sys, a timer driver. For using the Sloop/Cutter
  8. timer, read the section titled "Using the Cutter Timer".
  9. The directory is organized as follows:
  10. 1) .\ ->
  11. a) timer.c (single c source)
  12. b) makefile.rst (common for windows, CR286, Sloop and
  13. OS2 386 and WOW)
  14. c) makefile (for Windows NT)
  15. d) sources ( -do- )
  16. e) The header file, timing.h, is under .\inc\.
  17. 2) .\win (FOR WINDOWS)
  18. a) .\src (contains the .asm files for init and 8253io, and the
  19. module def file)
  20. b) .\bin (the binary timerwin.dll file)
  21. 3) .\WIN32 (FOR Win32 NT)
  22. a) .\src (contains the .def file and an i386 sub-dir.
  23. that has an asm file)
  24. b) .\bin (the binary file)
  25. 4) .\Sloop (FOR Sloop apps)
  26. a) .\src (contains the initializing .asm file, and the
  27. module def file)
  28. b) .\bin (the binary timerslp.dll file)
  29. 5) .\cr286 (FOR 16 bit OS/2 Cruiser apps)
  30. a) .\src (contains the initializing asm file
  31. and the module def file)
  32. b) .\bin (the binary timer286.dll file)
  33. 6) .\os2386 (FOR 32 bit OS/2 Cruiser apps)
  34. a) .\src (contains the initializing and math .asm
  35. files, and the module def file)
  36. b) .\bin (the binary timer386.dll file)
  37. 7) .\wow (FOR 16 bit WOW on Windows NT - built for Win 3.0)
  38. a) .\src (contains the .asm and the
  39. module def file)
  40. b) .\bin (the binary timerwow.dll file)
  41. **********************************************************************
  42. To Use a timer DLL:
  43. ------------------
  44. To use one of the above binaries, please read the USAGE NOTES at the
  45. end of this document. Please copy the timing.h file from this
  46. directory to the directory where you are building your application.
  47. Copy the relevant .dll to your libpath.
  48. It is essential that you define the type of system you are building
  49. your application for, since the header file uses some special types
  50. that are dependent on the system. While compiling your application,
  51. add the following flag: -DXXX where XXX stands for one of:
  52. WIN - for Windows applications on Windows 3.x.
  53. WIN32 - for Win32 applications.
  54. WOW16 - for Windows applications on Windows NT.
  55. SLOOP - for 16 bit Sloop (OS/2 1.2, 1.3) applications
  56. OS2286 - for 16 bit Cruiser (OS/2 2.0) applications
  57. OS2386 - for 32 bit OS/2 applications
  58. **********************************************************************
  59. To build one of the dlls:
  60. ------------------------
  61. If building a Windows, WOW, Sloop, Cutter, CR286 or OS/2 32 bit dll:
  62. --------------------------------------------------------------
  63. NOTE: To build for Wow on NT, you must be setup to build for Win 3.0
  64. and not Win 3.1. Also, you need the special Windows libraries.
  65. These need to be built on NT.
  66. a) Copy the timer.c from this dir. and the timing.h from ..\inc\.
  67. to a local directory.
  68. b) Also copy the "makefile.rst" from here to the same directory.
  69. c) From ???\src copy the remaining files to the local directory,
  70. where ??? represents win, Sloop, cr286 or os2386.
  71. d) Edit makefile.rst to define the system that you are making the
  72. dll for. Eg. if you are making the dll for windows, remove
  73. the comment sign (#) from the line "WIN=TRUE" in the makefile
  74. and ensure that the other system defines (WOW16, SLOOP, OS2286
  75. and OS2386) are commented out.
  76. f) Type "nmake -f makefile.rst" and the dll will be created for
  77. you. (Ensure that your development environment is set up for
  78. the right system).
  79. If building the Win32 dll:
  80. -------------------------
  81. a) Copy timer.c, makefile and sources files found under this
  82. directory and timing.h from ..\inc\. to a local directory.
  83. b) tc the win32\src directory to your local directory. This
  84. will create an i386 sub-directory containing an asm file on
  85. your local machine.
  86. c) From the directory where you have your sources file, type
  87. "build -xxx timerw32" from the command line, where xxx represents
  88. your target system. It is 386 by default.
  89. c) A binary file "timerw32.dll" will be created along with the
  90. .obj file under .\xxx\obj where xxx is your target system.
  91. It is i386 by default.
  92. Using the Cutter Timer: (For use on machines running OS/2 1.2x, 1.3x)
  93. ----------------------
  94. Note: This driver cannot be used when the DOS box is running.
  95. So edit your config.sys file so that the line "PROTECTONLY=YES"
  96. is present.
  97. a) Copy the 16BitTmr.* files from the .\sloop\bin directory
  98. to your machine.
  99. b) Edit your Config.sys file to add the line
  100. "DEVICE=xxx\16BitTmr.sys, where xxx is the full path name where
  101. the driver resides.
  102. c) Copy the timerslp.dll from the .\sloop\bin directory to your
  103. libpath.
  104. c) Reboot your machine and use the timerslp.dll as explained
  105. elsewhere.
  106. In case you have any questions, or if you run into any problems,
  107. contact vaidy (936-7812).
  108. *****************************************************************
  109. USAGE NOTES
  110. -----------
  111. This document describes the usage of the functions available
  112. through the Timer.dll. This dll can be used by all application
  113. programs that require a microsecond timer. Send all
  114. comments/suggestions to vaidy (ph. 936-7812) or
  115. JohnOw (ph. 936-5557).
  116. 1) TimerOpen:
  117. ---------
  118. Description: Opens a timer object and returns a handle for use
  119. in timing operations.
  120. #include "timing.h" /* for error codes */
  121. SHORT FAR PASCAL
  122. TimerOpen (
  123. SHORT far * phTimer,
  124. _TimerUnits TimerUnits
  125. );
  126. phTimer - Address to which to return the handle to the
  127. timer.
  128. TimerUnits - Will be one of the enumerated types listed below, that
  129. determines the units for the elapsed time values
  130. returned by TimerRead. The selected units may be
  131. greater or less than the underlying clock frequency:
  132. typedef enum {
  133. KILOSECONDS,
  134. SECONDS,
  135. MILLISECONDS,
  136. MICROSECONDS,
  137. TENTHMICROSECS,
  138. NANOSECONDS,
  139. TIMER_FREE
  140. } _TimerUnits;
  141. Remarks: This call should be made by each application, every time
  142. a new timer is required. This call should precede any
  143. other timer function calls. Each call to TimerOpen will
  144. return a new handle, so that multiple threads within a
  145. process may use different timers for measuring time.
  146. The handle obtained from this call should be used by
  147. the other timing functions, viz. TimerOpen and TimerRead.
  148. The handle is an index into an array of timer objects that
  149. are made available by this function.
  150. The number of timers will depend upon the implementation,
  151. but will usually be in the order of 100's or 1000's per
  152. process. Use TimerClose to release unused timers in case
  153. there is a need to reuse a large number of timers. Any
  154. opened timers will be automatically closed when the process
  155. using them terminates.
  156. The scaling factor decides the units of the time returned
  157. by TimerRead. The calling application should be careful
  158. over the choice of units, to avoid possible overflow
  159. and consequently, incorrect results.
  160. Return: 0 if a timer handle is made available.
  161. An error code, on failure, which may be one of:
  162. TIMERERR_TIMER_NOT_AVAILABLE
  163. TIMERERR_NO_MORE_HANDLES
  164. TIMERERR_INVALID_UNITS
  165. See also: TimerInit, TimerRead, TimerClose.
  166. 2) TimerInit:
  167. ---------
  168. Description: Initializes the elements of an internal structure
  169. to the current time, obtained from the low level
  170. timer.
  171. #include "timing.h" /* for error codes */
  172. SHORT FAR PASCAL
  173. TimerInit (
  174. SHORT hTimer
  175. );
  176. hTimer - The handle, to the timer, that was made available by
  177. a call to TimerOpen.
  178. Remarks: This function should be called after opening the timer
  179. object. Each call to this function should just precede
  180. the operation that is being timed. Passing a handle
  181. to a timer object that has not been opened, will result
  182. in an error code being returned.
  183. Return: 0 if the call is successful.
  184. An error code is returned, if the call failed. The error code is:
  185. TIMERERR_INVALID_HANDLE
  186. See also: TimerOpen, TimerRead, TimerClose.
  187. 3) TimerRead:
  188. ---------
  189. Description: Returns the elapsed time since the previous call to
  190. TimerInit.
  191. #include "timing.h" /* for error codes */
  192. ULONG FAR PASCAL
  193. TimerRead (
  194. SHORT hTimer
  195. );
  196. hTimer - handle to the timer object that was opened with a call
  197. to TimerOpen and initialized by calling TimerInit.
  198. Remarks: This call should have been preceded by a call to TimerOpen
  199. and TimerInit. This call gets the current time from the
  200. low level timer and, using the initialized values in the
  201. internal structure, computes the elapsed time from the
  202. previous call to TimerInit. Any number of calls to
  203. TimerRead may be made, as long they are preceded by at least
  204. one call to TimerInit. A timer overflow error code is
  205. returned if the scaling factor was so chosen as to
  206. cause an overflow in the time being returned. A bad
  207. handle to this call will also result in an error code
  208. being returned.
  209. Return: A successful call returns the elapsed time since the last
  210. call to TimerInit.
  211. A failure, either invalid handle or overflow, is indicated
  212. by returning the maximum ULONG value (0xffffffff).
  213. See also: TimerOpen, TimerInit, TimerClose.
  214. 4) TimerClose:
  215. ----------
  216. Description: Closes a timer object that was opened with a call to
  217. TimerInit.
  218. #include "timing.h"
  219. SHORT FAR PASCAL
  220. TimerClose (
  221. SHORT hTimer
  222. );
  223. hTimer - Handle to the timer object that was opened with a call to
  224. TimerInit.
  225. Remarks: This function closes the specfied timer object and returns
  226. it to the pool of available timer objects. The object then
  227. is considered as available for use, when a call to TimerOpen is
  228. made.
  229. Return: 0 if the timer was successfully closed.
  230. An error code on failure:
  231. TIMERERR_INVALID_HANDLE
  232. See also: TimerOpen, TimerInit, TimerRead.
  233. ----------------------------------------------------------------------
  234. Usage:
  235. -----
  236. Test Application Body:
  237. {
  238. SHORT hTimerHandle1;
  239. SHORT sRetVal;
  240. if ((sRetVal = TimerOpen ((SHORT far *) &hTimerHandle1, MICROSECONDS)) {
  241. could not open timer
  242. Do not perform any timing operation
  243. }
  244. :
  245. :
  246. Do Stuff
  247. :
  248. :
  249. /* Commence timing operations */
  250. for (some conditions) {
  251. TimerInit (hTimerHandle1);
  252. Do Timed Operation
  253. ulElapsedTime = TimerRead (hTimerHandle1);
  254. }
  255. if (TimerClose (hTimerHandle1)) {
  256. Could not close timer. Check handle and take corrective
  257. action
  258. }
  259. :
  260. :
  261. }
  262. --------------------------------------------------------------------
  263. Debugging Routine
  264. -----------------
  265. 5) TimerReport:
  266. -----------
  267. Description: Used as a debugging tool, this routine fetches the
  268. the time from the last call to TimerInit and TimerRead.
  269. #include "timing.h" /* for error codes */
  270. SHORT BOOL PASCAL
  271. TimerReport (
  272. PSZ pszReportString,
  273. SHORT hHandleHandle;
  274. );
  275. pszReportString - Address to which to return the string containing
  276. the time obtained in the last call to
  277. TimerInit, TimerRead and the time returned
  278. from the last call to TimerRead.
  279. hTimerHandle - Handle to the timer from whom the information is
  280. sought.
  281. Remarks: This call can be used as a debugging device in case there
  282. is a doubt as to what values are being returned by the
  283. timer. This routine should normally be called after a call
  284. to TimerRead. The routines TimerInit and TimerRead call an
  285. underlying timer to obtain clock tics/time. The call
  286. to TimerRead uses this information and returns the
  287. time (clock tics are converted to time using the clock
  288. frequency on NT) as a ULONG. TimerReport obtains the
  289. information stored by the last call to TimerInit and
  290. last call to TimerRead. It also obtains the time that
  291. is returned by TimerRead (after converting clock tics
  292. to time whereever applicable, and subtracting the
  293. overhead) and prints the information into a string whose
  294. address is passed in as the first parameter to this routine.
  295. The format of the string is as follows:
  296. "Init Time %lu:%lu Current Time %lu:%lu Returned Time %lu".
  297. Both the times are printed as 64 bit values (high:low).
  298. On NT, the init and current times are clock tics while
  299. the returned time is in time units. The returned time
  300. will be about 0.8 times the difference between the clock
  301. tics.
  302. Note that the returned time takes into account the calling
  303. overhead also and hence, is not exactly the difference
  304. between the current time and init time.
  305. Return: TRUE if timer exists and has been opened.
  306. FALSE otherwise.
  307. See also: TimerOpen, TimerInit, TimerRead, TimerClose.
  308. -------------------------------------------------------------------------
  309. Additional Routines:
  310. -------------------
  311. 6) TimerQueryPerformanceCounter:
  312. ----------------------------
  313. Description: Makes the raw counts, (tics), and the timer frequency
  314. available.
  315. #include "timing.h" /* for error codes */
  316. VOID BOOL PASCAL
  317. TimerQueryPerformanceCounter (
  318. PQWORD pCurrentTic,
  319. PQWORD pFrequency [OPTIONAL]
  320. );
  321. pCurrentTic - Address to a 64-bit location to which the raw
  322. tic count is written on returning from the call.
  323. PQWORD is defined a PLARGE_INTEGER for the Win32
  324. platform in timing.h. PQWORD is a pointer to a
  325. QWORD structure (consisting of two ULONG
  326. elements), on Win 3.x and OS/2 platforms.
  327. pFrequency - Address to a 64-bit location to which the
  328. timer frequency is written on returning from
  329. the call, if this pointer is not NULL. This
  330. is OPTIONAL. If NULL, only the current tic
  331. count is written to the location pointed by
  332. pCurrentTic.
  333. Remarks: This call can be used by any application to return the
  334. timer frequency and current tic count. The frequency needs
  335. to be obtained only once. All other calls to this routine
  336. can have NULL as the second parameter.
  337. The calling application should perform its own calibration
  338. to determine the overhead when this routine is called
  339. back-to-back.
  340. To time an operation, this routine should immediately
  341. precede and follow the operation. The difference of
  342. the tic counts should be computed. The overhead for
  343. calling this routine back to back should be subtracted from
  344. this difference, and then divided by the frequency to
  345. obtain the time in seconds. (To obtain the time in
  346. microseconds, multiply the raw tics by a million before
  347. dividing by the frequency. To convert the time to units
  348. other than seconds, the conversion factor should be applied
  349. before performing the division by the frequency, to
  350. avoid loss of precision).
  351. There is no need to open or initialize the timer if this
  352. routine is used to obtain the tic count.
  353. Return: None.
  354. See also: TimerOpen, TimerInit, TimerRead, TimerClose.
  355. 7) TimerConvertTicsToUSec:
  356. ----------------------
  357. Description: Used as a utility tool, this routine returns
  358. the time in microseconds when the tic difference and
  359. timer frequency are passed in.
  360. #include "timing.h" /* for error codes */
  361. ULONG BOOL PASCAL
  362. TimerConvertTicsToUSec (
  363. ULONG ulTicDifference,
  364. ULONG ulTimerFreq;
  365. );
  366. ulTicDifference - The duration of an operation in tics. This is
  367. obtained by calling
  368. TimerQueryPerformanceCounter immediately before
  369. and following the desired operation and
  370. subtracting the overhead of calling
  371. TimerQueryPerformanceCounter back to back.
  372. ulTimerFreq - The timer frequency. This is obtained by
  373. calling TimerQueryPerformanceCounter.
  374. Remarks: This routine just accepts the duration of an operation in
  375. timer counts and the timer frequency. It returns the
  376. actual time in microseconds corresponding to the tic
  377. count.
  378. There is no need to open or initialize the timer if this
  379. routine is used to obtain the tic count.
  380. Return: The time in microseconds that corresponds to the input
  381. tics and frequency.
  382. A zero if the frequency is zero.
  383. See also: TimerOpen, TimerInit, TimerRead, TimerClose.