有没有办法可以获取linux开发板的硬件定时器频率

有没有办法可以获取linux开发板的硬件定时器频率,第1张

1、默认情况下系统节拍率选择100Hz。

2、设置好后在Linux内核源码根目录下的config文件中可见系统节拍率被设置为100Hz。

3、Linux内核会使用CONFIGHZ来设置自己的系统时钟,文件includeasmgenericparamh。

4、Linux内核使用全局变量jiffies来记录系统从启动以来的系统节拍数,系统启动的时候会将jiffies初始化为0,即可获取,linux开发板的硬件定时器频率。

百度, ctrlc, ctrlv。。。

c++ 毫秒,微妙级计时方法

在Windows平台下,常用的计时器有两种,一种是timeGetTime多媒体计时器,它可以提供毫秒级的计时。但这个精度对很多应用场合而言还是太粗糙了。另一种是QueryPerformanceCount计数器,随系统的不同可以提供微秒级的计数。对于实时图形处理、多媒体数据流处理、或者实时系统构造的程序员,善用QueryPerformanceCount/QueryPerformanceFrequency是一项基本功。

在Intel Pentium以上级别的CPU中,有一个称为“时间戳(Time Stamp)”的部件,它以64位无符号整型数的格式,记录了自CPU上电以来所经过的时钟周期数。由于目前的CPU主频都非常高,因此这个部件可以达到纳秒级的计时精度。这个精确性是上述两种方法所无法比拟的。

在Pentium以上的CPU中,提供了一条机器指令RDTSC(Read Time Stamp Counter)来读取这个时间戳的数字,并将其保存在EDX:EAX寄存器对中。由于EDX:EAX寄存器对恰好是Win32平台下C++语言保存函数返回值的寄存器,所以我们可以把这条指令看成是一个普通的函数调用。像这样:

inline unsigned __int64 GetCycleCount()

{

__asm RDTSC

}

但是不行,因为RDTSC不被C++的内嵌汇编器直接支持,所以我们要用_emit伪指令直接嵌入该指令的机器码形式0X0F、0X31,如下:

inline unsigned __int64 GetCycleCount()

{

__asm _emit 0x0F

__asm _emit 0x31

}

以后在需要计数器的场合,可以像使用普通的Win32 API一样,调用两次GetCycleCount函数,比较两个返回值的差,像这样:

unsigned long t;

t = (unsigned long)GetCycleCount();

//Do Something time-intensive

t -= (unsigned long)GetCycleCount();

这个方法的优点是:

1高精度。可以直接达到纳秒级的计时精度(在1GHz的CPU上每个时钟周期就是一纳秒),这是其他计时方法所难以企及的。

2成本低。timeGetTime 函数需要链接多媒体库winmmlib,QueryPerformance 函数根据MSDN的说明,需要硬件的支持(虽然我还没有见过不支持的机器)和KERNEL库的支持,所以二者都只能在Windows平台下使用(关于DOS平台下的高精度计时问题,可以参考《图形程序开发人员指南》,里面有关于控制定时器8253的详细说明)。但RDTSC指令是一条CPU指令,凡是i386平台下Pentium以上的机器均支持,甚至没有平台的限制(我相信i386版本UNIX和Linux下这个方法同样适用,但没有条件试验),而且函数调用的开销是最小的。

3具有和CPU主频直接对应的速率关系。一个计数相当于1/(CPU主频Hz数)秒,这样只要知道了CPU的主频,可以直接计算出时间。这和QueryPerformanceCount不同,后者需要通过QueryPerformanceFrequency获取当前计数器每秒的计数次数才能换算成时间。

这个方法的缺点是:

1现有的C/C++编译器多数不直接支持使用RDTSC指令,需要用直接嵌入机器码的方式编程,比较麻烦。

2数据抖动比较厉害。其实对任何计量手段而言,精度和稳定性永远是一对矛盾。如果用低精度的timeGetTime来计时,基本上每次计时的结果都是相同的;而RDTSC指令每次结果都不一样,经常有几百甚至上千的差距。这是这种方法高精度本身固有的矛盾。

下面是几个小例子,简要比较了三种计时方法的用法与精度

//Timer1cpp 使用了RDTSC指令的Timer类//KTimer类的定义可以参见《Windows图形编程》P15

//编译行:CL Timer1cpp /link USER32lib

#include <stdioh>

#include "KTimerh"

main()

{

unsigned t;

KTimer timer;

timerStart();

Sleep(1000);

t = timerStop();

printf("Lasting Time: %d\n",t);

}

//Timer2cpp 使用了timeGetTime函数

//需包含<mmsysh>,但由于Windows头文件错综复杂的关系

//简单包含<windowsh>比较偷懒:)

//编译行:CL timer2cpp /link winmmlib

#include <windowsh>

#include <stdioh>

main()

{

DWORD t1, t2;

t1 = timeGetTime();

Sleep(1000);

t2 = timeGetTime();

printf("Begin Time: %u\n", t1);

printf("End Time: %u\n", t2);

printf("Lasting Time: %u\n",(t2-t1));

}

//Timer3cpp 使用了QueryPerformanceCounter函数

//编译行:CL timer3cpp /link KERNEl32lib

#include <windowsh>

#include <stdioh>

main()

{

LARGE_INTEGER t1, t2, tc;

QueryPerformanceFrequency(&tc);

printf("Frequency: %u\n", tcQuadPart);

QueryPerformanceCounter(&t1);

Sleep(1000);

QueryPerformanceCounter(&t2);

printf("Begin Time: %u\n", t1QuadPart);

printf("End Time: %u\n", t2QuadPart);

printf("Lasting Time: %u\n",( t2QuadPart- t1QuadPart));

}

Lm_sensors是一个 命令 行工具,用于显示所有芯片传感器数据的当前读数,包括CPU温度。默认情况下,Ubuntu LInux没有安装Lm_Sensors,因此,我们必须自己安装它们。

bob@bob-PC:~$ sudo apt install lm-sensors

检测硬件

接下来,我们需要检测安装在电脑上的硬件监控芯片。现在我们可以开始检测电脑的硬件传感器了:

bob@bob-PC:~$ sudo sensors-detect

# sensors-detect revision 6284 (2015-05-31 14:00:33 +0200)

# System: VMware, Inc VMware Virtual Platform [None]

# Board: Intel Corporation 440BX Desktop Reference Platform

# Kernel: 4150-30Ubuntu-generic x86_64

# Processor: Intel(R) Core(TM) i7-8700 CPU @ 320GHz (6/158/10)

This program will help you determine which kernel modules you need

to load to use lm_sensors most effectively It is generally safe

and recommended to accept the default answers to all questions,

unless you know what you're doing

Some south bridges, CPUs or memory controllers contain embedded sensors

Do you want to scan for them This is totally safe (YES/no): yes

Silicon Integrated Systems SIS5595                      No

VIA VT82C686 Integrated Sensors                          No

VIA VT8231 Integrated Sensors                            No

AMD K8 thermal sensors                                  No

AMD Family 10h thermal sensors                          No

AMD Family 11h thermal sensors                          No

AMD Family 12h and 14h thermal sensors                  No

AMD Family 15h thermal sensors                          No

AMD Family 16h thermal sensors                          No

AMD Family 17h thermal sensors                          No

AMD Family 15h power sensors                            No

AMD Family 16h power sensors                            No

Intel digital thermal sensor                            Success!

    (driver `coretemp')

Intel AMB FB-DIMM thermal sensor                        No

Intel 5500/5520/X58 thermal sensor                      No

VIA C7 thermal sensor                                    No

VIA Nano thermal sensor                                  No

Some Super I/O chips contain embedded sensors We have to write to

standard I/O ports to probe them This is usually safe

Do you want to scan for Super I/O sensors (YES/no): yes

显示cpu温度

可以通过一下命令查看温度数据了:

bob@bob-PC:~$ sensors

iwlwifi_1-virtual-0

Adapter: Virtual device

temp1:        +330°C 

pch_skylake-virtual-0

Adapter: Virtual device

temp1:        +385°C 

BAT0-acpi-0

Adapter: ACPI interface

in0:        +1245 V 

coretemp-isa-0000

Adapter: ISA adapter

Package id 0:  +390°C  (high = +1000°C, crit = +1000°C)

Core 0:        +390°C  (high = +1000°C, crit = +1000°C)

Core 1:        +380°C  (high = +1000°C, crit = +1000°C)

thinkpad-isa-0000

Adapter: ISA adapter

fan1:          0 RPM

temp1:        +380°C 

temp2:            N/A 

temp3:        +00°C 

temp4:        +00°C 

temp5:        +00°C 

temp6:        +00°C 

temp7:        +00°C 

temp8:        +00°C 

BAT1-acpi-0

Adapter: ACPI interface

in0:        +1249 V 

acpitz-acpi-0

Adapter: ACPI interface

temp1:        +380°C  (crit = +1280°C)

还可以使用watch命令实时关注:

bob@bob-PC:~$ watch sensors

使用图形化工具psensor显示cpu温度

使用Psensor,您可以检查以下各项:

主板、CPU传感器和NVidia GPU的温度

硬盘驱动器的温度

风扇的转速

监视CPU使用情况

最新版本的Psensor还为Ubuntu提供了一个applet指示器,因此在Ubuntu上更容易监控硬件温度。您可以选择在顶部面板中显示温度。它甚至可以在温度超过极限时发送桌面通知。

我们可以使用下面的命令安装Psensor:

bob@bob-PC:~/Desktop$ sudo apt install -y psensor

打开ubuntu的launchpad,在里面找到psensor,打开该应用就可以看到多个传感器:

使用图形化工具hardinfo

Hardinfo是Linux中用于在图形化界面中显示硬件信息的工具。可以使用它检测cpu的温度。以下命令安装hardinfo:

bob@bob-PC:~/Desktop$ sudo apt install hardinfo

# 运行一下命令打开hardinfo

bob@bob-PC:~/Desktop$ sudo hardinfo

总结

在本教程中,我们将学习如何从命令行和桌面获取Ubuntu Linux上的CPU温度。

1首先打开linux系统 的终端 在终端输入route命令行命令 ,这样会出现如下现象

[root@machine1 /sbin]#route

route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]] 这是该命令的语法

其中以Gateway就是默认网关,如果想设置默认网关需要输入命令route add default gw 后面跟网关地址 ,

2在输入之后可能会出现,网关上有号 这是因为本地连接不需要网关的

以上就是关于有没有办法可以获取linux开发板的硬件定时器频率全部的内容,包括:有没有办法可以获取linux开发板的硬件定时器频率、如何在C++中如何编写得到微妙单位的时间的代码、如何在Ubuntu Linux中获取CPU温度等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9307471.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存