关于dpdk timer跨越CPU core调度的准确性问题

首先dpdk的timer接口里边使用 cpu cycle来比较时间。根据之前的内容

[dpdk] dpdk --lcores参数

当一个EAL thread映射在多个processor上的时候,cpu cycle有可能在不同的CPU core上面获得,

又因为cpu cycle是使用rdtsc指令获取的,这样会造成拿到的cpu cycle不准的问题。

首先,调查一下 rdtsc 指令:

https://stackoverflow.com/questions/3388134/rdtsc-accuracy-across-cpu-cores?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

Invariant TSC

X86_FEATURE_CONSTANT_TSC + X86_FEATURE_NONSTOP_TSC

"16.11.1 Invariant TSC

The time stamp counter in newer processors may support an enhancement, referred to as invariant TSC. Processor's support for
invariant TSC is indicated by CPUID.80000007H:EDX[8]. The invariant TSC will run at a constant rate in all ACPI P-, C-. and T-states. This is the architectural behavior moving
forward. On processors with invariant TSC support, the OS may use the TSC for wall clock timer services (instead of ACPI or
HPET timers). TSC reads are much more efficient and do not incur the overhead associated with a ring transition or
access to a platform resource."
[root@D128 ~]# cat /proc/cpuinfo |grep tsc
constant_tsc nonstop_tsc

只能保证在单个core 改变频率或挂起的时候的tsc准确性,不能保证跨CPU core的同步问题。

https://software.intel.com/en-us/forums/software-tuning-performance-optimization-platform-monitoring/topic/388964

Hello Samuel,

The 'Invariant TSC' means that the TSC runs at a fixed frequency and doesn't stop when the cpu halts.
The TSCs are not guaranteed to be synchronized although the OS usually does try to synchronize the TSC at boot time. This is one reason
for the rdtscp instruction. On Nehalem and later cpus, the rdtscp instruction returns the TSC and an identifier indicating on which cpu
you read the TSC. RDTSCP is a serializing instruction... unlike the regular rdtsc instruction. Pat

HPET

https://en.wikipedia.org/wiki/High_Precision_Event_Timer

An HPET chip consists of a -bit up-counter (main counter) counting at a frequency of at least  MHz, 
and a set of (at least three, up to ) comparators. These comparators are - or -bit-wide. The HPET
is programmed via a memory mapped I/O window that is discoverable via Advanced Configuration and Power
Interface (ACPI). The HPET circuit in modern PCs is integrated into the southbridge chip.[a]

HPET是一个芯片全局的计数器,最小精度为10纳秒,一般集成在南桥。

HPET提供最少3最多256个独立的计数器。

The Linux kernel can also use HPET as its clock source. The documentation of Red Hat MRG version  states that TSC is the preferred 
clock source due to its much lower overhead, but it uses HPET as a fallback. A benchmark in that environment for 10 million event
counts found that TSC took about 0.6 seconds, HPET took slightly over 12 seconds, and ACPI Power Management Timer took around 24 seconds.[]

虽然精度高,到底有性能损耗,linux Kernel仍然推荐TSC作为首选计数器,HPET作为备选。

查看HPET是否启用:

[root@D129 cli]# grep hpet /proc/timer_list
Clock Event Device: hpet
set_next_event: hpet_legacy_next_event
set_mode: hpet_legacy_set_mode
[root@D129 haha-walawala]# cat /sys/devices/system/clocksource/clocksource0/available_clocksource
kvm-clock hpet acpi_pm
[root@D129 haha-walawala]# cat /sys/devices/system/clocksource/clocksource0/current_clocksource
kvm-clock
[root@D129 haha-walawala]# ll /dev/hpet
crw-------. root root , May : /dev/hpet
[root@D129 haha-walawala]#

dpdk如何配置生效:

https://dpdk.org/doc/guides/linux_gsg/enable_func.html#high-precision-event-timer-hpet-functionality

rdtscp 

ACPI

略。

Event Timer Adapter Library

https://dpdk.org/doc/guides/prog_guide/event_timer_adapter.html#id1

看完以上文档,读一下代码,确定两个问题:

1. RDTSC的调用时机

2. Event Timer backend的hardware是什么?

官方没有Event Timer的例子,看一下Event Device library库的用法:

http://dpdk.org/doc/guides/prog_guide/eventdev.html

其他参考阅读:

https://www.ibm.com/developerworks/cn/linux/l-cn-timerm/

[dpdk] TSC , HPET, Timer, Event Timer,RDTSCP的更多相关文章

  1. qt下的时钟程序(简单美丽,继承自QWidget的Clock,用timer调用update刷新,然后使用paintEvent作画就行了,超详细中文注释)good

    最近抽空又看了下qt,发现用它来实现一些东西真的很容易比如下面这个例子,绘制了个圆形的时钟,但代码却清晰易懂[例子源自奇趣科技提供的例子]因为清晰,所以就只写注释了,吼吼其实也就这么几行代码头文件 / ...

  2. Python之网路编程之死锁,递归锁,信号量,Event事件,线程Queue

    一.死锁现象与递归锁 进程也是有死锁的 所谓死锁: 是指两个或两个以上的进程或线程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用, 它们都将无法推进下去.此时称系统处于死锁状态或系统 ...

  3. event.srcElement ,event.fromElement,event.toElement

    自然,我们都习惯了 IE,在 IE 中要在函数中获得各事件对象很容易,直接用 event.event.srcElemtn.event.fromElement.event.toElement 就行了.在 ...

  4. 阻止事件冒泡,阻止默认事件,event.stopPropagation()和event.preventDefault(),return fal的区别

    今天来看看前端的冒泡和事件默认事件如何处理 1.event.stopPropagation()方法 这是阻止事件的冒泡方法,不让事件向documen上蔓延,但是默认事件任然会执行,当你掉用这个方法的时 ...

  5. event.keyCode ,event.which ,event.charCode (2016-12-27 16:17:16)

    javascript判断是否按回车键 <input id="chatMsg" name="chatMsg" type="text" s ...

  6. 第二十四课:jQuery.event.remove,dispatch的源码解读

    本课还是来讲解一下jQuery是如何实现它的事件系统的.这一课我们先来讲一下jQuery.event.remove的源码解读. remove方法的目的是,根据用户传参,找到事件队列,从里面把匹配的ha ...

  7. 如何更好的理解(pageX,pageY,clientX,clientY,eventX,eventY,scrollX,scrollY,screenX,screenY,event.offsetX,event.offsetY,offsetLeft,style.left)

    1 pageX,pageY:鼠标指针相对于当前窗口的X,Y坐标,计算区域包括窗口自身的控件和滚动条.(火狐特有) 2 event.clientX,event.clientY:鼠标指针相对于当前窗口的X ...

  8. mysql定时脚本(event),类似oracle的job

    mysql定时脚本(event),类似oracle的job   我有2张表:tb_push_data 和 tb_push_data_log 现在需要每隔一段时间将tb_push_data 符合条件的 ...

  9. Qt中事件处理的方法(三种处理方法,四种覆盖event函数,notify函数,event过滤,事件处理器。然后继续传递给父窗口。可观察QWidget::event的源码,它是虚拟保护函数,可改写)

    一.Qt中事件处理的方式   1.事件处理模式一 首先是事件源产生事件,最后是事件处理器对这些事件进行处理.然而也许大家会问, Qt中有这么多类的事件,我们怎么样比较简便的处理每个事件呢?设想,如果是 ...

随机推荐

  1. SSH免登录及原理

    1.免登陆实现 1)在本机生成公钥/私钥对 ssh-keygen 执行成功后,在.ssh文件夹下,会多出两个文件 id_rsa和id_rsa.pub 2)将公钥写入远端服务器.ssh文件夹下的auth ...

  2. 在view source页面保存下来的网页源码和保存网页得到的源码不同

    前言 以前抓网页都是直接requests+bs4直接刚的,今天想拿一下拉钩的数据,就继续按照以下步骤来了: 先找个想爬的网页,然后写解析功能 批量爬,然后解析 入库 探究 结果发现行不通了,用bs4去 ...

  3. 《CLR via C#》读书笔记 之 泛型

    第十二章 泛型 2014-06-15 初始泛型 12.3 泛型基础结构 12.3.1 开放类型与封闭类型 12.3.2 泛型类型和继承 12.3.3 泛型类型同一性 12.3.4 代码爆炸 12.6 ...

  4. TP支持菜单动态生成RBAC权限系统数据库结构设计方案

    最简单基于RBAC权限系统数据库结构设计 包括如下几个表 1. 用户表 -- Table "t_user" DDL CREATE TABLE `t_user` ( `id` int ...

  5. Asp.net Daily Build by MsBuild

    :: 目录结构:: +GW.Point.BLL --dir dll:: +GW.Point.IBLL --dir dll:: +GW.Point.DAL --dir dll:: +GW.Point.I ...

  6. jquery 选择对象随心所欲,遍历数组更是易如反掌

    jquery只要研究总结透彻了,那选择对象就会随心所欲,遍历数组更是易如反掌.选对对象,才能“娶妻生子”,才能有后续的数据处理.呵呵遍历对很关键. 怕只怕,学东西浅尝辄止一知半解.本篇特别研究总结jq ...

  7. 嵌入式开发之精确延时---多线程延时阻塞精度asm("nop") nanosleep usleep sleep select

    http://blog.csdn.net/lile777/article/details/45503087

  8. VMware 虚拟机磁盘

    创建磁盘时,会进行两个操作:分配空间.置零 1.厚置备延迟置零: 默认的创建格式,创建磁盘时,直接从磁盘分配空间,但对磁盘保留数据不 置零.所以当有I/O操作时,只需要做置零的操作. 磁盘性能较好,时 ...

  9. python mysql redis mongodb selneium requests二次封装为什么大都是使用类的原因,一点见解

    1.python mysql  redis mongodb selneium requests举得这5个库里面的主要被用户使用的东西全都是面向对象的,包括requests.get函数是里面每次都是实例 ...

  10. [Python] 08 - Classes --> Objects

    故事背景 一.阶级关系 1. Programs are composed of modules.2. Modules contain statements.3. Statements contain ...