Python:如何获取每吉夫秒的英里数 [英] Python: How to get number of mili seconds per jiffy

查看:101
本文介绍了Python:如何获取每吉夫秒的英里数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道系统的HZ,即从Python代码中抽出几毫秒即可.

I'd like to know the HZ of the system, i.e. how many mili seconds is one jiffy from Python code.

推荐答案

有USER_HZ

>>> import os
>>> os.sysconf_names['SC_CLK_TCK']
2
>>> os.sysconf(2)
100

这是内核用来报告/proc中的时间的内容.

which is what the kernel uses to report time in /proc.

time(7)手册页上:

软件时钟,HZ和Jiffies

设置超时的各种系统调用的准确性,例如 select(2),sigtimedwait(2))并测量CPU时间(例如getrusage(2)) 受软件时钟的分辨率限制,保持的时钟 由内核来衡量时间.硬糖的大小是 由内核常数HZ的值确定.

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.

HZ的值因内核版本和硬件平台而异. 在i386上,情况如下:在包含以下内核的内核上 2.4.x,HZ为100,给定值为0.01秒;从...开始 2.6.0,将HZ提升至1000,产生0.001秒的跳动.自从 内核2.6.13,HZ值是内核配置参数,可以 可以是100、250(默认值)或1000,产生的jiffies值分别为 分别为0.01、0.004或0.001秒.从2.6.20内核开始, 可用频率:300,该数字平均分配给计算机 mon视频帧速率(PAL,25 HZ; NTSC,30 HZ).

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).

times(2)系统调用是一个特例.它用一个报告时间 内核常量USER_HZ定义的粒度.用户空间应用程序 可以使用以下命令确定此常数的值 sysconf(_SC_CLK_TCK).

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).

如果您绝对必须了解SYSTEM_HZ:

If you absolutely must know SYSTEM_HZ:

>>> from ctypes import *
>>> rt = CDLL('librt.so')
>>> CLOCK_REALTIME = 0
>>> class timespec(Structure):
...     _fields_ = [("tv_sec", c_long), ("tv_nsec", c_long)]
... 
>>> res = timespec()
>>> rt.clock_getres(CLOCK_REALTIME, byref(res))
0
>>> res.tv_sec, res.tv_nsec
(0, 4000250)
>>> SYSTEM_HZ = round(1/(res.tv_sec + (res.tv_nsec/10.0**9)))

在笔记本电脑上提供250(听起来不错),在虚拟机中提供1000000000 ...

Gives 250 on my laptop (which sounds about right) and 1000000000 in a VM…

这篇关于Python:如何获取每吉夫秒的英里数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆