- 浏览: 171589 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
boz.lee:
不错, 好多地方因为这里而出错
全局变量和局部变量在内存里的区别 -
issllx:
看到此文后对iteye深表遗憾
Yahoo S4 -
wohenshuaiba:
请问你有这个的代码吗?
k均值聚类(K-means) -
yxwang0615:
大神:
apr-1.3.3.tar.bz2
apr-util- ...
log4cxx编译方法 -
yxwang0615:
比csdn上的说的清楚干练,早看到这个就好了,我编了一天
p ...
log4cxx编译方法
IA-PC HPET (High Precision Event Timer) is a specification which was jointly developed by Intel and Microsoft in the early part of this decade.. The latest version is dated October 2004. It’s stated purpose is to The HPET architecture defines a set of timers that can be used by the operating system. A timer block is a combination of a single counter and up to 32 comparators and match registers. The comparator compares the contents of the match register against the value of a free running monotonic up-counter. When the output of the up-counter equals the value in the match register an interrupt is generated. Each of the comparators can output an interrupt. A maximum of 8 timer blocks are supported for a total of 256 timers. Each timer block can have different clocking attributes. Specific implementations may include only a subset of these timers. A minimum of three timers is required. The specification contains the following block diagram of the HPET architecture.
Some of the timers may be enabled to generate a periodic interrupt. If a timer is set to be periodic, its period is added to the match register each time a match occurs, thus computing the next time for this timer to generate an interrupt.. An up-counter is usually 64 bits wide but 32-bit implementations are permitted by the specification and 64-bit up-counters can also be driven in 32-bit mode. Up-counters run at a minimum of 10 MHz. which is much faster than the older RTC (Real Time Clock) and can thus produce periodic interrupts at a much higher resolution. The registers associated with these timers are mapped to memory space. The BIOS uses ACPI ( Advanced Configuration and Power Interface) functionality to inform the operating system of the location of the HPET memory-mapped register space. Here is an example of a disassembled ACPI HPET table from an Intel DX48BT2 (AKA BoneTrail) motherboard. Other Event Time Blocks are described in the ACPI namespace. Here is the relevant section from the disassembled ACPI DSDT table. Here is a list of the HPET-related messages outputted when this particular motherboard is booted up under Fedora 11. Here is the relevant part of the output from /proc/time_list as it relates to HPET: The HPET driver (/dev/hpet) has a similar API to the Real Time Clock driver. It is a character device which can support any number of HPET devices. The kernel API has three interfaces exported from the driver: By the way, not all VMware products support HPET. Currently ESX does not provide a virtual HPET to guest operating systems and in some cases it may be necessary to disable HPET altogether because of timer drift in virtual machines. See VMware TimeKeeping for more information. P.S. I tested the the above example on an Intel DX48BT2 motherboard running a 2.6.29.5-191 kernel.Linux HPET Support
initially supplement and eventually replace the legacy 8254 Programmable Interval Timer and the Real Time Clock Periodic Interrupt generation functions that are currently used as the ‘de-facto’ timer hardware for IA-PCs.
$ cat /sys/firmware/acpi/tables/HPET > /var/tmp/hpet.out
$ iasl -d /var/tmp/hpet.out
$ cat /var/tmp/hpet.dsl
/*
* Intel ACPI Component Architecture
* AML Disassembler version 20090123
*
* Disassembly of /var/tmp/hpet.out, Sun Jul 5 19:34:47 2009
*
* ACPI Data Table [HPET]
*
* Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue
*/
[000h 000 4] Signature : "HPET" /* High Precision Event Timer table */
[004h 004 4] Table Length : 00000038
[008h 008 1] Revision : 01
[009h 009 1] Checksum : CE
[00Ah 010 6] Oem ID : "INTEL "
[010h 016 8] Oem Table ID : "DX48BT2 "
[018h 024 4] Oem Revision : 0000076E
[01Ch 028 4] Asl Compiler ID : "MSFT"
[020h 032 4] Asl Compiler Revision : 01000013
[024h 036 4] Hardware Block ID : 8086A301
[028h 040 12] Timer Block Register :
[028h 040 1] Space ID : 00 (SystemMemory)
[029h 041 1] Bit Width : 00
[02Ah 042 1] Bit Offset : 00
[02Bh 043 1] Access Width : 00
[02Ch 044 8] Address : 00000000FED00000
[034h 052 1] Sequence Number : 00
[035h 053 2] Minimum Clock Ticks : 0001
[037h 055 1] Flags (decoded below) : 00
Page Protect : 0
4K Page Protect : 0
64K Page Protect : 0
Raw Table Data
0000: 48 50 45 54 38 00 00 00 01 CE 49 4E 54 45 4C 20 HPET8.....INTEL
0010: 44 58 34 38 42 54 32 20 6E 07 00 00 4D 53 46 54 DX48BT2 n...MSFT
0020: 13 00 00 01 01 A3 86 80 00 00 00 00 00 00 D0 FE ................
0030: 00 00 00 00 00 01 00 00 ........
$
See page 30 of the HPET v1.0a specification for a detailed breakdown of the individual bits in the Event Time Block (called Hardware Block by the AML disassember). Note that only one Event Timer Block need be described in the HPET table in order to bootstrap an operating system. This is the case here. For non-legacy platforms, the Event Timer Block described in the HPET is the one that provides functionality to replace the 8254/RTC Periodic Interrupt Logic. Device (HPET)
{
Name (_HID, EisaId ("PNP0103"))
Name (_CRS, ResourceTemplate ()
{
Memory32Fixed (ReadOnly,
0xFED00000, // Address Base
0x00004000, // Address Length
)
})
Method (_STA, 0, NotSerialized)
{
If (HPEE)
{
Return (0x0F)
}
Else
{
Return (Zero)
}
}
}
Note the assigned PNPID (PNP0103) for the HPET. Because no _UID is specified it means that there are no other HPET timer blocks.$ dmesg | grep -i HPET
ACPI: HPET CFBF2000, 0038 (r1 INTEL DX48BT2 76E MSFT 1000013)
ACPI: HPET id: 0x8086a301 base: 0xfed00000
hpet clockevent registered
HPET: 4 timers in total, 0 timers will be used for per-cpu timer
hpet0: at MMIO 0xfed00000, IRQs 2, 8, 0, 0
hpet0: 4 comparators, 64-bit 14.318180 MHz counter
rtc0: alarms up to one month, 114 bytes nvram, hpet irqs
$
The first line is outputted when the ACPI HPET table is read. The second line is outputted when the ACPI HPET table is mapped into memory by …/arch/x86/kernel/acpi/boot.c. The next line is outputted when the HPET legacy interrupts are started and HPET is registered as the global clock. The following line is outputted when the kernel checks to ensure that at least one timer is reserved for userspace (/dev/hpet.) The next two lines of output comes from the HPET device driver (…/drivers/char/hpet.c.) It shows that 2 timers have allocated interrupts and two do not..Tick Device: mode: 1
Broadcast device
Clock Event Device: hpet
max_delta_ns: 149983005959
min_delta_ns: 5000
mult: 61496114
shift: 32
mode: 3
next_event: 9223372036854775807 nsecs
set_next_event: hpet_legacy_next_event
set_mode: hpet_legacy_set_mode
event_handler: tick_handle_oneshot_broadcast
tick_broadcast_mask: 00000000
tick_broadcast_oneshot_mask: 00000000
Here is the output from /proc/sys/dev/hpet and /proc/driver/rtc:$ cat /proc/sys/dev/hpet/max-user-freq
64
$ cat /proc/driver/rtc
rtc_time : 06:34:31
rtc_date : 2009-07-06
alrm_time : **:24:40
alrm_date : ****-**-**
alarm_IRQ : no
alrm_pending : no
24hr : yes
periodic_IRQ : no
update_IRQ : no
HPET_emulated : yes
DST_enable : no
periodic_freq : 1024
batt_status : okay
hpet_register( struct hpet_task *tp, int periodic )
hpet_unregister( struct hpet_task *tp )
hpet_control( struct hpet_task *tp, unsigned int cmd, unsigned long arg )
The userspace interface to HPET is defined in the header /usr/include/linux/hpet.h. The current set of supported operations is:#define HPET_IE_ON _IO('h', 0x01) /* interrupt on */
#define HPET_IE_OFF _IO('h', 0x02) /* interrupt off */
#define HPET_INFO _IOR('h', 0x03, struct hpet_info) /* get information */
#define HPET_EPI _IO('h', 0x04) /* enable periodic */
#define HPET_DPI _IO('h', 0x05) /* disable periodic */
#define HPET_IRQFREQ _IOW('h', 0x6, unsigned long) /* set frequency */
The following example shows how to use the published interface to access a HPET and call a simple periodic signal handler hpet_alarm between 2 and 99 times a second.#include <stdio.h>
#include <stdlib.h;>
#include <fcntl.h>
#include <time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/time.h>
#include <linux/hpet.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <signal.h>
static uint16_t hpet_sigio_count;
static uint64_t secs;
static void
hpet_alarm(int val)
{
struct timespec t;
clock_gettime(CLOCK_REALTIME, &t);
if (!secs) secs = t.tv_sec;
fprintf(stderr, "hpet_alarm called. iteration: %2d secs: %ld nsecs: %ld \n",
hpet_sigio_count, (t.tv_sec - secs) , t.tv_sec * 100000 + t.tv_nsec );
hpet_sigio_count++;
}
int
main(int argc, const char **argv)
{
struct sigaction old, new;
struct hpet_info info;
int frequency;
int iterations;
int retval = 0;
int fd;
int r, i, value;
if (argc != 3) {
fprintf(stderr, "Usage: %s frequency(1-64) iterations(10-99)\n", argv[0]);
return -1;
}
frequency = atoi(argv[1]);
iterations = atoi(argv[2]);
if (frequency > 64 || frequency < 1 ) {
fprintf(stderr, "ERROR: Invalid value for frequency\n");
return -1;
}
if (iterations < 10 || iterations > 99 ) {
fprintf(stderr, "ERROR: Invalid value for iterations\n");
return -1;
}
hpet_sigio_count = 0;
sigemptyset(&new.sa_mask);
new.sa_flags = 0;
new.sa_handler = hpet_alarm;
sigaction(SIGIO, NULL, &old);
sigaction(SIGIO, &new, NULL);
fd = open("/dev/hpet", O_RDONLY);
if (fd < 0) {
fprintf(stderr, "ERROR: Failed to open /dev/hpet\n");
return -1;
}
if ((fcntl(fd, F_SETOWN, getpid()) == 1) ||
((value = fcntl(fd, F_GETFL)) == 1) ||
(fcntl(fd, F_SETFL, value | O_ASYNC) == 1)) {
fprintf(stderr, "ERROR: fcntl failed\n");
retval = 1;
goto fail;
}
if (ioctl(fd, HPET_IRQFREQ, frequency) < 0) {
fprintf(stderr, "ERROR: Could not set /dev/hpet to have a %2dHz timer\n", frequency);
retval = 2;
goto fail;
}
if (ioctl(fd, HPET_INFO, &info) < 0) {
fprintf(stderr, "ERROR: failed to get info\n");
retval = 3;
goto fail;
}
fprintf(stdout, "\nhi_ireqfreq: 0x%lx hi_flags: %0x%lx hi_hpet: 0x%x hi_timer: 0x%x\n\n",
info.hi_ireqfreq, info.hi_flags, info.hi_hpet, info.hi_timer);
r = ioctl(fd, HPET_EPI, 0);
if (info.hi_flags && (r < 0)) {
fprintf(stderr, "ERROR: HPET_EPI failed\n");
retval = 4;
goto fail;
}
if (ioctl(fd, HPET_IE_ON, 0) < 0) {
fprintf(stderr, "ERROR: HPET_IE_ON failed\n");
retval = 5;
goto fail;
}
/* wait for specified number of signal interrupts */
for (i = 0; i < iterations; i++) {
(void) pause();
}
if (ioctl(fd, HPET_IE_OFF, 0) < 0) {
fprintf(stderr, "ERROR: HPET_IE_OFF failed\n");
retval = 6;
}
fail:
sigaction(SIGIO, &old, NULL);
if (fd > 0)
close(fd);
return retval;
}
Here is the output from this example when it is invoked with a frequency of 32 and an iteration count of 64.$ sudo ./hpet_example 32 64
hi_ireqfreq: 0x20 hi_flags: 00 hi_hpet: 0x2 hi_timer: 0x4a1cb9c8
hpet_alarm called. iteration: 0 secs: 0 nsecs: 124683205055050
hpet_alarm called. iteration: 1 secs: 0 nsecs: 124683236313149
hpet_alarm called. iteration: 2 secs: 0 nsecs: 124683267566342
hpet_alarm called. iteration: 3 secs: 0 nsecs: 124683298821905
hpet_alarm called. iteration: 4 secs: 0 nsecs: 124683330077493
hpet_alarm called. iteration: 5 secs: 0 nsecs: 124683361341893
hpet_alarm called. iteration: 6 secs: 0 nsecs: 124683392590764
hpet_alarm called. iteration: 7 secs: 0 nsecs: 124683423849157
hpet_alarm called. iteration: 8 secs: 0 nsecs: 124683455101917
hpet_alarm called. iteration: 9 secs: 0 nsecs: 124683486357683
hpet_alarm called. iteration: 10 secs: 0 nsecs: 124683517617931
hpet_alarm called. iteration: 11 secs: 0 nsecs: 124683548872198
hpet_alarm called. iteration: 12 secs: 1 nsecs: 124682580229541
hpet_alarm called. iteration: 13 secs: 1 nsecs: 124682611481235
hpet_alarm called. iteration: 14 secs: 1 nsecs: 124682642740016
hpet_alarm called. iteration: 15 secs: 1 nsecs: 124682673992697
hpet_alarm called. iteration: 16 secs: 1 nsecs: 124682705247479
hpet_alarm called. iteration: 17 secs: 1 nsecs: 124682736504664
hpet_alarm called. iteration: 18 secs: 1 nsecs: 124682767758840
hpet_alarm called. iteration: 19 secs: 1 nsecs: 124682799014280
hpet_alarm called. iteration: 20 secs: 1 nsecs: 124682830270129
hpet_alarm called. iteration: 21 secs: 1 nsecs: 124682861530334
hpet_alarm called. iteration: 22 secs: 1 nsecs: 124682892784577
hpet_alarm called. iteration: 23 secs: 1 nsecs: 124682924038220
hpet_alarm called. iteration: 24 secs: 1 nsecs: 124682955294110
hpet_alarm called. iteration: 25 secs: 1 nsecs: 124682986550572
hpet_alarm called. iteration: 26 secs: 1 nsecs: 124683017805756
hpet_alarm called. iteration: 27 secs: 1 nsecs: 124683049061117
hpet_alarm called. iteration: 28 secs: 1 nsecs: 124683080318331
hpet_alarm called. iteration: 29 secs: 1 nsecs: 124683111576954
hpet_alarm called. iteration: 30 secs: 1 nsecs: 124683142828988
hpet_alarm called. iteration: 31 secs: 1 nsecs: 124683174083954
hpet_alarm called. iteration: 32 secs: 1 nsecs: 124683205337967
hpet_alarm called. iteration: 33 secs: 1 nsecs: 124683236593144
hpet_alarm called. iteration: 34 secs: 1 nsecs: 124683267851530
hpet_alarm called. iteration: 35 secs: 1 nsecs: 124683299104054
hpet_alarm called. iteration: 36 secs: 1 nsecs: 124683330358748
hpet_alarm called. iteration: 37 secs: 1 nsecs: 124683361617445
hpet_alarm called. iteration: 38 secs: 1 nsecs: 124683392870249
hpet_alarm called. iteration: 39 secs: 1 nsecs: 124683424124489
hpet_alarm called. iteration: 40 secs: 1 nsecs: 124683455379717
hpet_alarm called. iteration: 41 secs: 1 nsecs: 124683486634424
hpet_alarm called. iteration: 42 secs: 1 nsecs: 124683517889149
hpet_alarm called. iteration: 43 secs: 1 nsecs: 124683549144315
hpet_alarm called. iteration: 44 secs: 2 nsecs: 124682580500695
hpet_alarm called. iteration: 45 secs: 2 nsecs: 124682611761325
hpet_alarm called. iteration: 46 secs: 2 nsecs: 124682643011863
hpet_alarm called. iteration: 47 secs: 2 nsecs: 124682674265864
hpet_alarm called. iteration: 48 secs: 2 nsecs: 124682705521034
hpet_alarm called. iteration: 49 secs: 2 nsecs: 124682736776049
hpet_alarm called. iteration: 50 secs: 2 nsecs: 124682768030654
hpet_alarm called. iteration: 51 secs: 2 nsecs: 124682799285398
hpet_alarm called. iteration: 52 secs: 2 nsecs: 124682830544701
hpet_alarm called. iteration: 53 secs: 2 nsecs: 124682861797319
hpet_alarm called. iteration: 54 secs: 2 nsecs: 124682893051578
hpet_alarm called. iteration: 55 secs: 2 nsecs: 124682924306748
hpet_alarm called. iteration: 56 secs: 2 nsecs: 124682955562132
hpet_alarm called. iteration: 57 secs: 2 nsecs: 124682986823545
hpet_alarm called. iteration: 58 secs: 2 nsecs: 124683018073636
hpet_alarm called. iteration: 59 secs: 2 nsecs: 124683049327560
hpet_alarm called. iteration: 60 secs: 2 nsecs: 124683080586707
hpet_alarm called. iteration: 61 secs: 2 nsecs: 124683111841132
hpet_alarm called. iteration: 62 secs: 2 nsecs: 124683143095147
hpet_alarm called. iteration: 63 secs: 2 nsecs: 124683174349985
hpet_alarm called. iteration: 64 secs: 2 nsecs: 124683205607103
$
Well, I think that I have provided you with enough information so that you should now be able to go away and experiment with the HPET interface yourself.
发表评论
-
sed 简介
2010-12-07 19:14 6571. Sed简介 sed 是一种在线编辑器,它一 ... -
valgrind的使用
2010-09-14 09:49 890Valgrind是一个GPL的软件,用于Linux(Fo ... -
开发过程中需要注意的一些问题
2010-09-14 09:27 796编码要求 1. 命名规范(文件,函数 ... -
Linux下程序的Profile工具
2010-09-14 09:19 3808我们在写程序,特别是嵌入式程序的时候,通常需要对程序的性能 ... -
浅析Linux下core文件
2010-09-13 15:02 1433当我们的程序崩溃时,内核有可能把该程序当前内存映射到core文 ... -
SHELL 命令行参数简介
2010-09-13 11:35 1112我们对于普通脚本语言诸如perl python等,写一个脚 ... -
Linux 线程模型的比较:LinuxThreads 和 NPTL
2010-08-25 14:14 917LinuxThreads 项目最初将 ... -
[转]SELECT、POOL、EPOLL的特性对比
2010-08-25 14:06 1672select()系统调用提供一个机制来实现同步多元I/O: ... -
shell字符串比较、判断是否为数字
2010-07-14 19:47 1884二元比较操作符,比较变 ... -
GDB常用命令
2010-05-13 21:12 743gdb的命令很多,本文不 ... -
[转自X哥]fedora 上安装 codeblocks
2010-05-01 14:57 2570关于安装过程总结起来可以分为以下几个步骤: 1. ... -
Linux 编程经典书籍推荐
2010-04-12 22:52 1750成为一名精通 Linux 程序设计的高级程序员一直是不少朋友孜 ...
相关推荐
Linux定时器(Linux timer)是Linux内核中的一个重要组件,用于在特定时间点或周期性地触发回调函数。在Linux驱动开发中,理解和熟练运用定时器机制是至关重要的,因为许多驱动程序都需要根据时间事件来执行某些操作...
标题"Base_Timer.tar.gz_C++ Linux timer_linux basic timer_linux ms ti"表明这是一个基于C++的Linux定时器实现,精确到毫秒级别,其设计灵感可能来源于Windows下的`SetTimer`接口。在描述中提到,这个定时器提供了...
在嵌入式系统开发中,恩智浦i.MX6ULL处理器是一款广泛应用的微处理器,尤其在物联网和工业控制...通过学习这个教程,开发者能够深入了解如何在Linux环境中高效地利用EPIT定时器,从而实现精确的定时和中断控制功能。
在Linux操作系统中,由于内核并不直接提供一个与Qt中类似的多线程安全的定时器,因此在开发多线程程序时,如果需要在不同...对于学习Linux系统编程、多线程编程以及自定义定时器的实现原理,这是一个很好的参考案例。
Linux中的tick timer(也称为时钟滴答或调度滴答)是操作系统内核的一个关键组件,它负责在系统中提供时间基准和定时功能。在早期的Linux版本中,tick timer每秒会产生一次中断(通常为100Hz,即每毫秒一次),用于...
### Linux内核中的`check_timer()`与`timer_irq_works()`函数详解 ...通过以上分析,我们可以更好地理解Linux内核中定时器中断处理的核心逻辑,这对于深入学习Linux内核或进行相关开发工作都非常有帮助。
总的来说,这个"linux-char-driver-by-timer.zip"资源为学习和实践Linux驱动开发提供了一个很好的起点,特别是对于想要了解如何结合使用字符驱动和定时器的开发者来说。通过对源码的研究,我们可以深入理解Linux内核...
在Linux操作系统中,定时器(Timer)是一种非常重要的机制,它允许程序在特定的时间间隔后执行某些操作。...通过这个压缩包中的教程,你可以系统地学习Linux Timer的原理和实践,提升你的Linux编程技能。
Linux下Timer的一种实现,主要利用Linux下的信号机制实现,有兴趣的可以使用虚拟时间机制。
**标题解析:** ...通过深入研究这个示例,开发者不仅可以学习到HPET的使用方法,还能了解到如何在Linux环境下编写高效的设备驱动程序,这对于嵌入式系统开发、实时操作系统理解和性能调优等领域都有重要价值。
Linux Timer子系统是一种在Linux操作系统中管理定时器的机制,它为应用程序提供了一种通用的接口来处理时间相关的任务。这个子系统的核心功能是创建、修改、查询和删除定时器,以及处理定时器到期后的回调操作。以下...
例如,Linux系统中的hrtimer(High Resolution Timer)和hpet等,它们提供高精度的时间间隔管理,用于调度任务、计时器中断以及周期性工作。操作系统会根据硬件Timer发出的中断进行上下文切换,执行相应的定时任务。...
Timer_list 结构体是 Linux 内核中用来描述一个内核定时器的数据结构,它包括四个成员变量:list、expires、data 和 function。其中,list 是一个双向链表元素,用来将多个定时器连接成一条双向循环队列;expires ...
在Linux操作系统中,定时器是实现程序定时执行或者周期性任务的重要工具。本文将深入探讨两种常见的Linux定时器——`alarm()`和`setitimer()`,以及它们在Linux定时和计时器系统中的应用。 首先,`alarm()`函数是...
总结来说,这个“Msg_Timer.rar_C++ Linux timer_minigui_minigui timer”项目是学习C++在Linux环境下使用MinigUI开发定时器功能的理想实践案例。通过研究源代码,我们可以深入理解如何在嵌入式系统中结合C++和...
本篇将详细探讨Zynq-Linux中的timer中断源码以及axi-timer的相关知识。 首先,让我们理解Linux内核中的定时器架构。在Linux内核中,存在两种主要类型的定时器:软定时器(software timers)和硬定时器(hardware ...
高精度定时器的实现利用了现代硬件提供的更精确的时钟源,如HPET(High Precision Event Timer)或TSC(Time Stamp Counter)。这些硬件定时器可以提供比系统心跳更精细的时间基准,从而实现纳秒级别的计时精度。 ...
C语言02-Timer0-Timer1-Timer2-Timer3-Timer4测试程序(STC32G-DEMO-CODE-220311kw)C语言02-Timer0-Timer1-Timer2-Timer3-Timer4测试程序(STC32G-DEMO-CODE-220311kw)C语言02-Timer0-Timer1-Timer2-Timer3-Timer4...
本文实例讲述了C#中Forms.Timer、Timers.Timer、Threading.Timer的用法分析,分享给大家供大家参考。具体分析如下: 在.NET Framework里面提供了三种Timer ① System.Windows.Forms.Timer ② System.Timers.Timer ③...
根据提供的文档信息,我们可以深入探讨ARM Generic Timer的相关知识点。标题和描述均提到“ARM Generic Timer Prelim Data”,这意味着文档提供的是关于ARM通用定时器的一些初步数据和技术规范。下面将详细介绍ARM ...