zoukankan      html  css  js  c++  java
  • 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)基本上是一个方波电压类似如下所示:

    image

    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(芯片)

    时钟漂移:

    http://baike.baidu.com/link?url=mE0t1R_RhmVHzdgAaAR5gc_56P3M1bnvPemUPZ6uqQkdSiYLnudp410ra89NuJ0GA7bn90CNwmMXFUXGQUb6wa

    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就会根据这个脉冲信号产生 image
    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!

    image

    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这个两个对比哪个更好了!

  • 相关阅读:
    mysql数据库题目【杭州多测师】【杭州多测师_王sir】
    python题目:维度为(M,N)求矩阵的转置【杭州多测师】【杭州多测师_王sir】
    python题目【杭州多测师】【杭州多测师_王sir】
    购物车测试点【杭州多测师】【杭州多测师_王sir】
    史上最全软件测试工程师常见的面试题总结【杭州多测师】【面试题】【杭州多测师_王sir】
    查询"001"课程比"002"课程成绩高的所有学生的学号【杭州多测师】【杭州多测师_王sir】
    mysql数据库查询当天,最近7天,最近1个月数据【杭州多测师】【杭州多测师_王sir】
    python题目:判断一个IP地址是否合法【杭州多测师】【杭州多测师_王sir】
    sql floor()函数
    mysql左连右连
  • 原文地址:https://www.cnblogs.com/muahao/p/6003575.html
Copyright © 2011-2022 走看看