seconds 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. .TH SECONDS 9
  2. .SH NAME
  3. seconds, ticks, fastticks, HZ, MS2HZ, MS2TK, TK2MS, TK2SEC \- kernel times and time conversions
  4. .SH SYNOPSIS
  5. .ta \w'\fL#define 'u
  6. .B
  7. long seconds(void)
  8. .PP
  9. .B
  10. m->ticks
  11. .br
  12. MACHP(0)->ticks
  13. .PP
  14. .B
  15. vlong fastticks(uvlong *hz)
  16. .PP
  17. .EX
  18. #define HZ ...
  19. #define MS2HZ(t) ...
  20. #define TK2SEC(t) ...
  21. #define TK2MS(t) ...
  22. #define MS2TK(m) ...
  23. .EE
  24. .SH DESCRIPTION
  25. .I Seconds
  26. returns the system's idea of the current time as the number of seconds
  27. since the start of the epoch
  28. (00:00:00 GMT, January 1, 1970).
  29. .PP
  30. The
  31. .B ticks
  32. field of the
  33. .B Mach
  34. structure pointed to by
  35. .B m
  36. returns the number of system-dependent clock ticks on the
  37. given processor since system boot.
  38. On a multiprocessor,
  39. .B MACHP(0)
  40. is sometimes used to provide a reference time, since the tick value
  41. might vary slightly across processors.
  42. .PP
  43. .I Fastticks
  44. returns the number of ticks since boot as measured by the
  45. fastest clock provided by the platform.
  46. The frequency of the clock, in ticks per second,
  47. is returned through
  48. .IR hz ,
  49. unless it is nil.
  50. .PP
  51. The system clock frequencies are platform-dependent.
  52. Several symbolic constants and macro functions are defined by
  53. the file
  54. .B mem.h
  55. to convert between different time units:
  56. .TF TK2SEC(t)
  57. .PD
  58. .TP
  59. .B HZ
  60. The number of clock ticks per second.
  61. .TP
  62. .B MS2HZ
  63. Milliseconds per clock tick.
  64. .TP
  65. .BI TK2SEC( t )
  66. Convert
  67. .I t
  68. clock ticks to seconds and return the result (truncating not rounding).
  69. .TP
  70. .BI TK2MS( t )
  71. Convert
  72. .I t
  73. clock ticks to milliseconds and return the result.
  74. .TP
  75. .BI MS2TK( m )
  76. Convert
  77. .I m
  78. milliseconds to clock ticks and return the result (truncating).
  79. .PP
  80. The functions are often used to calculate delays for timing functions,
  81. for instance:
  82. .IP
  83. .EX
  84. if(atactlrwait(dp->cp, DHmagic, 0, MS2TK(100))){
  85. ...
  86. }
  87. .EE
  88. .SH SOURCE
  89. .B /sys/src/9/*/mem.h
  90. .br
  91. .B /sys/src/9/*/clock.c
  92. .br
  93. .B /sys/src/9/port/tod.c