博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TSC: Intro & Comments
阅读量:5945 次
发布时间:2019-06-19

本文共 2749 字,大约阅读时间需要 9 分钟。

From  quote:

The Time Stamp Counter (TSC) is a 64-bit  present on all  processors since the . It counts the number of  since reset. The instruction RDTSC returns the TSC in EDX:EAX. In  mode, RDTSC also clears the higher 32 bits of  and . Its  is 0F 31.  competitors such as the   did not always have a TSC and may consider RDTSC an illegal instruction. Cyrix included a Time Stamp Counter in their .

The Time Stamp Counter was once an excellent high-resolution, low-overhead way for a program to get CPU timing information. With the advent of / CPUs, systems with , and  , the TSC cannot be relied upon to provide accurate results — unless great care is taken to correct the possible flaws: rate of tick and whether all cores (processors) have identical values in their time-keeping registers. There is no promise that the timestamp counters of multiple CPUs on a single motherboard will be synchronized. Therefore, a program can get reliable results only by limiting itself to run on one specific CPU. Even then, the CPU speed may change because of power-saving measures taken by the OS or , or the system may be hibernated and later resumed, resetting the TSC. In those latter cases, to stay relevant, the program must re-calibrate the counter periodically.

Relying on the TSC also reduces portability, as other processors may not have a similar feature. Recent Intel processors include a constant rate TSC (identified by the kern.timecounter.invariant_tsc sysctl on FreeBSD or by the "constant_tsc" flag in Linux's /proc/cpuinfo). With these processors, the TSC ticks at the processor's nominal frequency, regardless of the actual CPU clock frequency due to turbo or power saving states. Hence TSC ticks are counting the passage of time, not the number of CPU clock cycles elapsed.

Starting with the , Intel processors have practiced , where instructions are not necessarily performed in the order they appear in the program. This can cause the processor to execute RDTSC later than a simple program expects, producing a misleading cycle count. The programmer can solve this problem by inserting a serializing instruction, such as , to force every preceding instruction to complete before allowing the program to continue, or by using the RDTSCP instruction, which is a serializing variant of the RDTSC instruction.

And from , if constant_tsc exist for cpu flag, TSC rate is the maximum CPU frequency.

Detailed kernel document about time-keeping is .

A detailed intro is .

And to note: constant_tsc + invariant_tsc = nonstop_tsc

Related kernel constant: CONFIG_HZ, HZ

Accoding to  and , no matter what_tsc is capable of the cpu, hpet is better. So in user space program development, use hpet to record time!

转载于:https://www.cnblogs.com/sansna/p/8320328.html

你可能感兴趣的文章
填一填用了半个月 ionic 遇到的坑
查看>>
[译] 用 Haskell 写简单的 Monadic Parser
查看>>
bling_hash——Node.js 字符串哈希的包
查看>>
谷歌 .dev 顶级域名正式开放
查看>>
Android Q 将获得大量的隐私保护功能
查看>>
Android Volley库源码简析(Image Request部分)
查看>>
Firefox 密码管理器 Lockbox 推出 Android 版
查看>>
视频点播-资源用量
查看>>
好程序员分享大势所趋 HTML5成Web开发者最关心的技术 ...
查看>>
北汽集团荣辉:抓不住自动驾驶 就抓不住车企的命脉 | 自动驾驶这十年 ...
查看>>
豆瓣评分8.8,这本程序员案头必备宝典,10年沉淀,新版再现 ...
查看>>
运行 Spring Boot 应用的 3 种方式!
查看>>
【内容安全】虚拟化及云环境下数据库审计优缺点分析
查看>>
crmeb电商系统
查看>>
xttprep.tmpl
查看>>
mycat垂直分库
查看>>
无需停机,手把手教您将 Docker CE 切换为 Docker EE
查看>>
Ubuntu 14.04 Web服务器,Apache的安装和配置
查看>>
MaxCompute 图计算用户手册(上)
查看>>
自带科技基因,打造纯原创IP,“燃烧小宇宙”获数千万A轮融资
查看>>