Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import os
  2. from ctypes import *
  3.  
  4. #The accuracy of various system calls that set timeouts, (e.g., select(2), sigtimedwait(2)) and measure CPU time (e.g., getrusage(2)) is limited by the resolution of the software clock, a clock maintained by the kernel which measures time in jiffies. The size of a jiffy is determined by the value of the kernel constant HZ.
  5. #The value of HZ varies across kernel versions and hardware platforms. On i386 the situation is as follows: on kernels up to and including 2.4.x, HZ was 100, giving a jiffy value of 0.01 seconds; starting with 2.6.0, HZ was raised to 1000, giving a jiffy of 0.001 seconds. Since kernel 2.6.13, the HZ value is a kernel configuration parameter and can be 100, 250 (the default) or 1000, yielding a jiffies value of, respec‐ tively, 0.01, 0.004, or 0.001 seconds. Since kernel 2.6.20, a further frequency is available: 300, a number that divides evenly for the com‐ mon video frame rates (PAL, 25 HZ; NTSC, 30 HZ).
  6. #The times(2) system call is a special case. It reports times with a granularity defined by the kernel constant USER_HZ. Userspace applica‐ tions can determine the value of this constant using sysconf(_SC_CLK_TCK).
  7.  
  8. rt = CDLL('librt.so.1')
  9. CLOCK_REALTIME = 0
  10. class timespec(Structure):
  11. _fields_ = [("tv_sec", c_long), ("tv_nsec", c_long)]
  12.  
  13. res = timespec()
  14. rt.clock_getres(CLOCK_REALTIME, byref(res))
  15. print res.tv_sec, res.tv_nsec
  16. SYSTEM_HZ = round(1/(res.tv_sec + (res.tv_nsec/10.0**9)))
  17. print SYSTEM_HZ
  18.  
  19. print os.sysconf_names['SC_CLK_TCK']
  20. print os.sysconf(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement