linux时钟管理
ref
https://access.redhat.com/solutions/18627
在el5中
如何查看系统现在使用的clock source是什么?
答:
方式1:需要说明的是不能保证这个两个文件中的准确性!
#cat /sys/devices/system/clocksource/clocksource0/current_clocksource
tsc
#cat /sys/devices/system/clocksource/clocksource0/available_clocksource
tsc hpet acpi_pm
方式2:比较推荐这个方式
# grep "time" /var/log/dmesg
...
time.c: Using 3.579545 MHz WALL PM GTOD PIT/TSC timer.
time.c: Detected 3200.238 MHz processor.
...
clock source可以使用哪些内核参数?
答:
/usr/share/doc/kernel-doc-2.6.18/Documentation/kernel-parameters.txt:
clock= [BUGS=IA-32, HW] gettimeofday clocksource override.
[Deprecated]
Forces specified clocksource (if available) to be used
when calculating gettimeofday(). If specified
clocksource is not available, it defaults to PIT.
Format: { pit | tsc | cyclone | acpi_pm | tsccount | notsccount }
clocksource= [GENERIC_TIME] Override the default clocksource
Override the default clocksource and use the clocksource
with the name specified.
hpet= [IA-32,HPET] option to disable HPET and use PIT.
Format: disable
notsc [BUGS=IA-32] Disable Time Stamp Counter
如何修改clock sourcede配置?
动态临时的:(重启实效)
# echo "acpi_pm" > /sys/devices/system/clocksource/clocksource0/current_clocksource
永久的:
添加clocksource= 这个字段到kernel启动文件中:
title Red Hat Enterprise Linux (2.6.18-128.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-128.el5 ro root=LABEL=/ rhgb quiet clocksource=acpi_pm
initrd /initrd-2.6.18-128.el5.img
在el6中:
如何查看系统现在使用的clock source是什么?
# cat /sys/devices/system/clocksource/clocksource0/current_clocksource
hpet
# cat /sys/devices/system/clocksource/clocksource0/available_clocksource
hpet acpi_pm
clock source可以使用哪些内核参数?
/usr/share/doc/kernel-doc-2.6.32/Documentation/kernel-parameters.txt
Raw
clocksource= [GENERIC_TIME] Override the default clocksource
Format: Override the default clocksource and use the clocksource
with the name specified.
Some clocksource names to choose from, depending on
the platform:
[all] jiffies (this is the base, fallback clocksource)
[ACPI] acpi_pm
[ARM] imx_timer1,OSTS,netx_timer,mpu_timer2,
pxa_timer,timer3,32k_counter,timer0_1
[AVR32] avr32
[X86-32] pit,hpet,tsc,vmi-timer;
scx200_hrt on Geode; cyclone on IBM x440
[MIPS] MIPS
[PARISC] cr16
[S390] tod
[SH] SuperH
[SPARC64] tick
[X86-64] hpet,tsc
hpet= [X86-32,HPET] option to control HPET usage
Format: { enable (default) | disable | force |
verbose }
disable: disable HPET and use PIT instead
force: allow force enabled of undocumented chips (ICH4,
VIA, nVidia)
verbose: show contents of HPET registers during setup
notsc [BUGS=X86-32] Disable Time Stamp Counter
如何修改clock source配置?
动态临时的:(重启实效)
# echo "acpi_pm" > /sys/devices/system/clocksource/clocksource0/current_clocksource
永久的:
添加clocksource= 这个字段到kernel启动文件中:
title Red Hat Enterprise Linux Server (2.6.32-71.18.2.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-71.18.2.el6.x86_64 ro root=LABEL=/ crashkernel=auto clocksource=acpi_pm
initrd /initramfs-2.6.32-71.18.2.el6.x86_64.img
下面让我们看看现在的系统架构中都是使用了什么time circuits ?
参考:https://access.redhat.com/solutions/18627,下面的翻译均来自这里。
Real Time Clock (RTC): RTC是一个独立于CPU的一个芯片,RTC有一个小小的电池,即使机器关机了,RTC电路也会不断的在2 Hz and8,192 Hz频率之间
去发送中断,Linux使用RTC只在启动时获得的时间和日期。
Programmable Interrupt Timer (PIT):
Time Stamp Counter (TSC):80 x86微处理器包括一个时钟输入插口,用来接收来自外部振荡器(external oscillator)的时钟信号(clock signal),从奔腾80 x86微处理器开始,增加了一个计数器(counter),随着每增加一个时钟信号(clock signal),通过rdtsc汇编指也可以去读TSC寄存器(TSC register),当使用这个寄存器(TSC register),内核必须考虑时钟信号(clock signal)的频率,举例:如果CPU的频率(专业点就是clock ticks或者clock cycles)是1GHz,即CPU一秒钟1000000000次clock cycle,TCS寄存器每一纳秒(nanosecond)增加一次,Linux可能利用这个寄存器来获得更精确的时间测量。
CPU Local Timer
High Precision Event Timer (HPET):HPET定时器芯片,也是一种PIT,在未来的某个时间将完全取代,
ACPI Power Management Timer (ACPI PMT)
什么是clock circuits,和timer circuits? (学习一下数电)
clock circuits:http://minecraft.gamepedia.com/Clock_circuit
http://www.learnabout-electronics.org/Digital/dig51.php
http://www.emmicroelectronic.com/products/timing/timing-clock-circuits
http://www.minecraft101.net/redstone/redstone-clocks.html
什么是clock signal和timing signals?
答:其实这是两个相同的概念,在http://www.learnabout-electronics.org/Digital/dig51.php中这么描述的:
Most sequential logic circuits are driven by a clock oscillator. This usually consists of an astable circuit producing regular pulses that should ideally:
大多数时序逻辑电路(sequential logic circuits)是由一个时钟振荡器(clock oscillator.)在驱动,按照我的理解就是说,时钟振荡器(clock oscillator.)在产生脉冲信号(从0到1)或者叫clock signals,另外又有Crystal Controlled Clock Oscillator:晶体控制的时钟振荡器(简称“晶振”)存在,很多的时钟振荡器使用晶体来控制振荡器的频率,比如1GHz,就是说一秒钟内有产生100000000 (9个0,1GHz=1000000000Hz=1000MHz)个脉冲信号(clock signals ),这个概念和CPU中的clock cycle不一样,首先,这是两个不同的电路!但是,可以说是一类的东西,clock cycle(即CPU的频率,是用来描述CPU的运行速度的),而我认为clock signal和CPU的频率没有什么关系。
在http://www.designcabana.com/knowledge/electrical/electronics/digital/clock/中描述了:
一个数字时钟信号(digital clock signal)基本上是一个方波电压类似如下所示:
http://www.designcabana.com/knowledge/electrical/electronics/digital/clock/ 中描述:The frequency of the clock can be anything as needed by the digital circuit that is using it.数字电路(Digital circuits)总是有一些输入并生成相应的数字输出,
what is a clock used for?
http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Overall/clock.html 中描述了:
We use a clock to synchronize the events of a CPU. Devices in a CPU can be categorized as sequential circuits or combinational circuits. Sequential logic devices use a clock. Basically, sequential logic devices can only change outputs once a period, usually during a positive or a negative edge. We'll assume that a sequential device can only change outputs on positive clock edges.
To give you an analogy, imagine a music conductor tapping a beat with a baton (a stick) at regular intervals. Suppose you are playing a piano, and you're told to play a new note each time he taps his baton. Thus, how fast the conductor taps the baton controls how often you play notes.
Similarly, the rate at which the positive clock edge appears controls how fast a sequential logic device can change outputs.
It turns out that by using a clock, we can design a CPU more easily than if we don't use a clock. This is primary reason to use a clock.
http://www.designcabana.com/knowledge/electrical/electronics/digital/clock/中描述了:
Digital circuits always have some input and generate digital outputs accordingly. Some digital circuits are not clocked, meaning that the input applied to the circuit flows through digital gates without any timing or storage and generates the output. It only takes a time equal to the propagation delay time to reach the output.
On the other hand most of the digital circuits that do more complex processing on the digital inputs such as controllers, processors or state machines are timed and the signal can't just go through. In these circuits a clock with a fixed frequency is used for timing. A clock plays very important role as it is used to open and close digital paths, allow or stop a process and in general provide timing for the circuit. You can compare a clock with the traffic lights. They stop and allow the traffic in a timely manner so that the traffic can flow smoothly with the least delays. If you just let the traffic through there will be a big jam and the output is unpredictable.
Clocks are especially used for digital circuits with feedbacks and also to avoid glitches in a circuit. What is a glitch? A glitch is an unpredictable output. Say you have some input and for those you expect a known output, but before the output settles to what you expect, you might have one or more transitions that are not suppose to be there. These are called glitches. They happen because the inputs have to go through different gates and the propagation delay of each can be different. Therefore the results arrive to the final gates in different times. This difference in data arrival results in changes in the output until all signals settle and the output is valid. If glitches are not eliminated, they will go to the next stage of the circuit and generate more unpredictable results. To avoid them a clock can be used to time the signals. Assume the inputs to the circuit are provided with one rising edge of the clock and the output of the circuit is read by the next rising edge of the clock. If the period of the clock signal is higher than the total propagation delay of the circuit, the output will be read when it is completely settled and therefore no glitch happens.
How to Generate a Clock
http://www.designcabana.com/knowledge/electrical/electronics/digital/clock/
A clock generator is used to generate a clock, which is an oscillator that provides a square wave output. An oscillator circuit always has a feedback that makes the circuit oscillate. This feedback also provides parameters that can make a certain frequency. There are many different ways to make an oscillator. Below you can see two of the famous ones. First is to use a simple Inverter plus a feedback component which usually is a crystal.
什么是Clock Oscillator和Crystal Controlled Clock Oscillator?(学习一下模电)
Clock Oscillator:时钟振荡器
Crystal Controlled Clock Oscillator:晶体控制的时钟振荡器(简称“晶振”)
上述这两个概念看似高大上,其实就是大学中模电里学的类似放大器一样的东东,http://www.learnabout-electronics.org/Digital/dig51.php 在这里你可以看到这个模电概念中的”振荡器”究竟是什么样的。这两个振荡器可以产生脉冲信号(clock signal):
http://www.learnabout-electronics.org/Digital/dig51.php 这篇文章中介绍了,Many clock oscillators use a crystal to control the frequency.很多的的时钟振荡器使用晶体来控制振荡器的频率。http://www.designcabana.com/knowledge/electrical/electronics/digital/clock/ 中描述了晶体其实就是一个元器件,可以很好的过滤frequency。
clock circuits(时钟电路)和timer circurls计时器电路,首先这两个都是主板上的两个电路,clock circuits主要是用来keep track of the current time of the day and to make precise time measurements,timer circuits are programmed by the kernel!
举例:IA-32 and AMD64 系统至少有一个 programmable interrupt timer (PIT) 作为该系统的classical timer circuit!which is usually implemented by an 8254 CMOS chip(芯片)
时钟漂移:
Clock cycle: http://www.computerhope.com/jargon/c/clockcyc.htm
clock cycle表示,CPU的速度, 振荡器在两次脉冲之间的时间越长,即,每秒钟脉冲次数越多,表示CPU处理速度越快,速度的单位是Hz,比如:4GHz的处理器,表示每秒钟有4000000000次clock cycle。
https://www.youtube.com/watch?v=rch2HAtGaMQ
[http://techterms.com/definition/clockcycle
http://searchwindowsserver.techtarget.com/definition/clock-cycle
How a CPU Works: http://www.hardwaresecrets.com/how-a-cpu-works/2/
](http://techterms.com/definition/clockcycle
http://searchwindowsserver.techtarget.com/definition/clock-cycle
How a CPU Works: http://www.hardwaresecrets.com/how-a-cpu-works/2/
)
什么是clock tick(clock cycle)?
参考:http://www.webopedia.com/TERM/C/clock_tick.html
吐血推荐看CPU是如何工作的?http://www.hardwaresecrets.com/how-a-cpu-works/
什么是clock cycle?
首先你要知道,CPU可以在每个clock cycle之间做处理和计算工作。那么什么是clock cycle呢?
有人将这个clock cycle翻译成晶振周期,其实你要先知道,在主板上有一个晶振电路的东西,会不断的往CPU发送脉冲信号(0或1),触发CPU,CPU就会根据这个脉冲信号产生
clock cycle,其次,CPU的速度是按照这个概念得出的,比如我的CPU是4GHz的处理器,也就是说一秒钟CPU会得到有4000000000次clock cycle,即主板上的晶振电路会向CPU发送4000000000次脉冲信号,CPU其实一点也不聪明,只会傻傻的处理指令,比如你现在有指令A,指令B,有意思的是CPU知道 指令A在第几次 clock cycle处执行!比如,一个指令A在第一个到第八个clock cycle处执行,指令B在第九个clock cycle处开始执行,那么在一秒内,CPU会得到晶振电路的400000000次触法,CPU就会在第1-8个clock cycle执行指令A,参考:http://www.hardwaresecrets.com/how-a-cpu-works/2/ ;但是CPU只会傻傻的执行指令,CPU知道在第几个cycle执行指令A,但是不是说CPU知道在第几个clock cycle执行程序A,程序A有很多的指令,操作系统需要做的就是将程序A的所有的指令按照顺序放在内存里,然后,将这些指令按照顺序放到CPU里,CPU里面也会有那么一个队列(寄存器)保存指令的执行顺序。
在下面你可以看到3个完整的clock cycle(ticks),每一个click cycle的开始都是以一个clock signal从0到1的信号跳跃(触法这个信号的是 晶振电路),衡量这个clock signals的单位是赫兹!即CPU一秒钟内有多少个这样的clock cycle!
CPU是如何知道指令A指令B分别在第几个clock cycle执行的?
答:这就是操作系统的工作了,操作系统将程序A的所有指令按照顺序告诉CPU中一个一个寄存器,CPU中的执行单元就会根据这个寄存器中的指令的顺序去处理指令!
现在CPU多核是啥意思(多个执行单元)?
答:现在你经常听说一个CPU是双核,就是说这个CPU有两个执行单元(execution unit)可以并发处理两个指令
另外现在的CPU的频率也是可以变化的,目的是为了节能省电等,比如你的CPU是4GHz的,并不是说你的CPU只能按照这个速度去执行,如果任务不多,你也会按照 800MHz的速度跑。
如果你对比两个CPU的速度?
答:
同架构的:
比如都是Intel架构的,CPU A,CPU B;假如CPU A 的频率是3GHz,CPU B的频率是4GHz,那么同样一个指令A需要7个clock cycle,CPU B在一秒钟内的clock cycle 是4000000000次的从0到1的跳变,CPU A一秒钟有3000000000个clock cycle,那么指令A在CPU B中执行使用的时间短。
不同架构的:
如果你对比不同架构的intel和AMD的那么这么比较就不准确了。正如前面所说一个指令在CPU中执行完毕,需要的clock cycle数量是确定的!但是 在不同的架构中指令A 在intel的CPU中需要7个clock cycle,但是在AMD中需要5个clock cycle,那你就很难说 Intel的4GHz的CPU 和AMD 4GHz的CPU这个两个对比哪个更好了!
linux时钟管理的更多相关文章
- Linux的时钟管理
本文转自博客园zhenwenxian的Linux时间管理,很详细,写得很不错,对初学者还是有很大帮助的. 时间管理在内核中占有非常重要的地位.相对于事件驱动,内核中有大量的函数都是基于时间驱动的.内核 ...
- Linux时间管理涉及数据结构和传统低分辨率时钟的实现
上篇文章大致描述了Linux时间管理的基本情况,看了一些大牛们的博客感觉自己写的内容很匮乏,但是没办法,只能通过这种方式提升自己……闲话不说,本节介绍下时间管理下重要的数据结构 设备相关数据结构 // ...
- Linux 时钟与计时器
对 Linux 系统来说,时钟和计时器是两个十分重要的概念.时钟反应的是绝对时间,也可认为是实时时间.计时器反应的则是相对时间,即相对于系统启动后的计时.操作系统内核需要管理运行时间(uptime)和 ...
- linux电源管理系列(一)
本系列将逐步介绍linux电源管理相关的知识,涉及到常见电源管理机制.linux电源管理机制.linux驱动中有关电源管理的相关接口.内核文档中关于Linux电源管理架构文档的分析.以下将以此来介绍相 ...
- 5 个在 Linux 中管理文件类型和系统时间的有用命令
对于想学习 Linux 的初学者来说要适应使用命令行或者终端可能非常困难.由于终端比图形用户界面程序更能帮助用户控制 Linux 系统,我们必须习惯在终端中运行命令.因此为了有效记忆 Linux 不同 ...
- Linux中断管理 (1)Linux中断管理机制
目录: <Linux中断管理> <Linux中断管理 (1)Linux中断管理机制> <Linux中断管理 (2)软中断和tasklet> <Linux中断管 ...
- Linux进程管理 (2)CFS调度器
关键词: 目录: Linux进程管理 (1)进程的诞生 Linux进程管理 (2)CFS调度器 Linux进程管理 (3)SMP负载均衡 Linux进程管理 (4)HMP调度器 Linux进程管理 ( ...
- Linux进程管理与调度-之-目录导航【转】
转自:http://blog.csdn.net/gatieme/article/details/51456569 版权声明:本文为博主原创文章 && 转载请著名出处 @ http:// ...
- Linux电源管理(1)-整体架构【转】
本文转载自:http://www.wowotech.net/pm_subsystem/pm_architecture.html 1. 前言 在这个世界中,任何系统的运转都需要能量.如树木依靠光能生长, ...
随机推荐
- 基于PCA的特征提取
图像处理方面的知识也学了一段时间了,总是光看理论的话,感觉联系不上实际,第一次把理论综合的实现出来,对这些理论的印象才感觉的更深刻,也能够为后续的学习打下良好的基础. PCA是比较老的算法,但是可靠性 ...
- JavaScript学习笔记:检测数组方法
检查数组的方法 很多时候我们需要对JavaScript中数据类型(Function.String.Number.Undefined.Boolean和Object)做判断.在JavaScript中提供了 ...
- linux 终止用户会话
第一步使用 tty 命令 查看自己会话id:本例中会话id为1[root@localhost ~]# tty/dev/pts/1[root@localhost ~]# 第二步 使用 w 命令 查看当前 ...
- 虚拟现实,增强现实,VR,AR
现在的热点不止VR,还有AR和披着MR.HR.CR外衣的各种高级AR们,所以比较着一起说.以下知乎上一网友观点,放几条结论:1.近期(未来两三年)看,VR能火,AR尚待成熟: 2.VR设备中,插片式是 ...
- SuperSocket学习笔记(二)
上一篇博客SuperSocket学习笔记(一)说明了怎么快速搭建一个服务器端,这篇文章我想深挖一下SuperSocket 1. 每一个客户端连接到服务器端时,服务器端会将客户端的信息保存到一个Sess ...
- EF数据建模(一)
大中型软件开发过程中常会使用ORM技术,ORM全称是“对象-关系映射Object-Relation-Mappping”.是将数据库中的数据对象的形式表现出来,并将通过面向对象的方式将这些对象组织起来, ...
- JSP 实现 之 调用java方法实现MySQL数据库备份和恢复
package cn.qm.db; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.IOEx ...
- angular.js学习
1.第一个小例子 <!DOCTYPE html> <html> <body> <div ng-app=""> <p>在输 ...
- linux查看磁盘空间
首先如果需要查看整个磁盘还剩多少空间,可以使用命令: df -h 如果你并不关心磁盘还剩余多少空间,只是需要知道当前的文件夹下的磁盘使用情况,可以使用如下命令: -h 上面使用du --max-dep ...
- git教程 入门
快速上传已有代码到github 如何将最新代码上传到github,这里讲本地已有项目文件的情况(假如本地有一个helloworld的工程目录,目录中有很多项目文件.),步骤如下: 前提:已安装git客 ...