比特派新版本下载官网|1000hz realtime
比特派新版本下载官网|1000hz realtime
[技术干货]浅谈Linux内核的实时性优化 - 知乎
[技术干货]浅谈Linux内核的实时性优化 - 知乎首发于Linux内核切换模式写文章登录/注册[技术干货]浅谈Linux内核的实时性优化玩转Linux内核专注于C/C++领域技术、职业发展,公众号/深度Linux实时系统的概念1.1什么是实时操作系统什么是实时操作系统?接触过嵌入式的小伙伴可能会知道,实时操作系统是指在嵌入式领域广泛应用的各类RTOS(Real Time Operating System)。其中最具代表性的有国外的μC/OS-III、FreeRTOS、Vxworks等,国内的代表有RT-Thread和LiteOS。在这些众多的RTOS系统里面既有开源的也有商业的,同时还有一些是行业专用的,比如enea公司推出的OSE系统就是通信行业早期的基站设备应用比较广泛的系统。无论是开源或是商业,这类系统都有一个最显著的特点,就是它们都具有很高的实时性。也是因为这个特点,它们都被集中应用在了嵌入式领域,特别是工控领域,例如工业制造控制、导弹飞机导航、电力设备监控等。历史上有很多著名的航空航天设备都使用到了实时的操作系统。比如登陆火星的凤凰号、好奇号火星探测器,它们所采用的操作系统就是美国WindRiver公司推出的Vxworks。那什么是系统的实时性呢?Linux系统在嵌入式领域也有大量使用,那Linux系统支不支持实时性呢?往期回顾:2022年嵌入式开发想进互联网大厂,你技术过硬吗?嵌入式进阶从小白到大神学习全攻略(学习路线+课程+学习书籍+练习项目)从事十年嵌入式转内核开发(23K到45K),给兄弟们的一些建议腾讯首发Linux内核源码《嵌入式开发进阶笔记》差距差的不止一点点哦1.2 Linux实时性、软实时和硬实时实时性指的是一个操作系统能够在规定的时间点内完成指定的任务操作,一旦超过这个时间点会对整个系统带来不可估量的后果。与此相对的是一般操作系统,它更注重用户体验,系统偶尔卡顿不会给用户带来灾难性后果。实时性反映了一个系统行为控制的精准能力,具体体现在定时器的精准度高,中断响应及时以及系统的行为固定且可预估等。Linux系统最初是按照分时系统设计并推出的,再加上在历史版本中使用的调度算法目的是公平的分配和使用各种系统资源,保证CPU被各个进程公平的使用,所以早期并不支持实时性。但是在后来的2.6版本开始,加入了内核抢占的功能,使它的实时性得到了提升,在某种程度上具备了软实时的能力。软实时指的是系统对于时限要求并不是十分的严格,在一些情况下允许系统超限完成。举个例子,我们在PC机上使用鼠标操作,偶尔会出现卡顿延迟,这种情况除了让我们抓狂影响使用体验之外并不会给我们带来严重的影响,大家平时在使用电脑时遇到鼠标图标转圈圈同时界面不响应操作就是一个例子。再比如视频信号采集,偶尔丢失几个数据帧,并不会对视频最后的播放带来严重的画面缺失。但是硬实时就不一样,它对操作系统的行为有着严格的时限要求,超出时限往往会带来灾难性后果。比如在我们日常生活中使用的汽车都配备了安全气囊,汽车在发生激烈碰撞时可能会在0.2s内停下,那就要求气囊在0.02s内充气完毕并弹出,超出这个时间乘客可能就会面临生命危险。再比如导弹防御系统,当敌方导弹来袭时拦截系统必须做出100%的精准反应并计算出弹道轨迹进行拦截,稍有延迟就会造成拦截失败,这种后果是不可接受的。这就是硬实时系统和软实时系统的区别。但是由于Linux系统内核过于庞大且模块众多,内核中仍然有不少影响实时性的因素,比如使用大量自旋锁、中断禁止、时钟粒度等,使其距离us级别的控制精度还有很大的距离。但是也不能因此认定Linux系统今后就不能用于实时控制领域。其实Linux内核一路发展过来,在历史的版本主线中仍然有很多技术公司或者大牛为了提升Linux系统的实时性而努力着,他们或是在某个版本上发布实时补丁,或是对内核进行一定程度上的改造,具体的代表有RTLinux、RTAI(Real-Time Application Interface)和Xenomai等。RTLinux全称叫做AReal-Time Linux,它由美国新墨西哥矿业及科技学院的V. Yodaiken开发。RTLinux采用了双内核的做法,可以说是开创了双内核法的先河。简单理解就是系统中存在两个内核,实时核和非实时核。底层硬件资源和实时的内核打交道绕开非实时核,来自硬件的中断源由实时核全面接管,把非实时的Linux内核当成实时核上的一个低优先级的进程来运行,通过这种方式确保实时核上的中断和任务得到优先响应,提升了实时性。Xenomai也借鉴了RTLinux的双内核做法,内部也有实时核和非实时核。但不同的是Xenomai在底层硬件和两个内核之间还加了一层硬件抽象层ADEOS(Adoptive Domain Environment for Operating System),实时核和非实时核作为硬件抽象层的两个域而存在,Xenomai内核属于实时域,Linux内核属于非实时域。ADEOS在系统的关键路径中对中断进行拦截,优先响应Xenomai实时域的中断,当没有实时任务和中断需要处理的时候才会轮到Linux内核执行。两者对比如下。【文章福利】小编推荐自己的Linux内核技术交流群:【865977150】整理了一些个人觉得比较好的学习书籍、视频资料共享在群文件里面,有需要的可以自行添加哦!!!前100名进群领取,额外赠送一份价值699的内核资料包(含视频教程、电子书、实战项目及代码)内核资料直通车:最新Linux内核源码资料文档+视频资料学习直通车:Linux内核源码/内存调优/文件系统/进程管理/设备驱动/网络协议栈图2:RTLinux和Xenomai框架对比由于版权、技术专利等因素,RTLinux已经不再更新。而Xenomai因为注重拓展性,可移植性和可维护性,对开发者相对友好,目前还在不断推出补丁,并且在社区活跃度很高,在工控领域也有不少成功应用的案例。这些基于Linux系统去改造从而提升实时性的系统的出现,使得Linux系统在发展过程中在实时性的研究上热度不减。甚至有不少人从Linux系统实时性研究入手,深入去学习Linux内核的调度机制、中断机制、定时器机制等,逐渐发展成自己的兴趣和爱好。从我们作为普通技术族的实力来说,可能不具备像国外的公司或者一些技术组织大改并发布实时Linux的能力。而想要提升系统实时性,有的是出于自身工作的需要,有的则是带着个人的兴趣爱好去钻研,那么如果想提升Linux内核的实时性,我们该怎么做呢?Linux实时性优化2.1 实时性优化和时钟精度知其然并知其所以然,知道影响实时性的因素才能很好地优化改造它。目前影响Linux内核实时性因素主要有时钟精度、系统中断、进程调度算法和内核可抢占性等。每一块都可以深入研究并做出相应的优化。首先是时钟精度,时钟就像是一个系统的脉搏,系统进程的调度切换是按照时钟节拍来进行的。目前Linux内核支持几种不同的系统节拍,可以在用户编译内核时配置。假设当前的系统节拍是100Hz,那么系统的时钟粒度就是10ms,如果提升到1000Hz,那么时钟粒度就是1ms,精度提升了10倍。图3:编译内核系统节拍设置上面这张图是CentOS7.6发行版系统默认的系统节拍设置。时钟精度的提升最直接的影响就是系统中的调度动作加快了,进程的响应也更为及时,但随着而来的是时钟中断频率的加快,这也加大了系统的开销和压力,因为会频繁的响应系统的时钟中断。在某些CPU消耗型的进程上会由于系统频繁的进行进程切换而导致CPU资源浪费,CPU的时间会浪费在进程切换上,因为从进程切换到实际被调度执行之间有一个时间差,叫做进程切换开销,所以好和坏我们还是需要根据自己的系统表现来看待。2.2 中断其次是中断。无论是RTOS还是Linux,硬件中断在系统当中的响应优先级永远是最高的。RTOS由于支持中断优先级,在实际使用过程中可以根据产品的实际情况针对不同的外设场景设置不同的优先级,且高优先级的中断可以抢占低优先级的中断,使得RTOS的中断响应非常迅速。Linux系统中的中断模块远比RTOS系统复杂得多。通常,Linux系统在进入一个中断时候,会禁止本地CPU的中断。在处理具体某一个中断的时候,由于禁止了本地CPU中断(NMI类型的中断除外),当有新的中断到来的时候只好挂起,只有当前的中断处理完才打开本地中断并响应新的中断。如果系统中存在大量不同类型的中断,势必会有一些中断被延迟得不到及时响应,这种延迟现象在单核CPU上表现尤为明显。针对这种情况,就要求我们在编写实际中断处理函数的时候,尽量在中断处理函数中不做复杂的操作,坚守中断处理函数“快进快出”的原则。比如只读取硬件寄存器等简单操作即可,剩下的数据处理的操作放到中断下半部中去执行,这就是所谓的“中断线程化”。传统上的中断下半部有软中断、tasklet、工作队列,它们的优先级也从高到低。软中断和tasklet工作在中断上下文不允许休眠它的优先级比工作队列高,工作队列工作在进程上下文允许休眠但是优先级最低,所以在实际编程开发中需要我们根据场景选择性的使用。如果是多核CPU,那么可以根据实际的中断情况把不同类型的中断迁移绑定到不同的CPU上,避免不同中断之间的干扰。下面以I.MX6DL硬件平台为例子介绍中断迁移的使用。首先,通过#cat /proc/interrupts指令查看系统的所有中断,如下图所示:图4:绑定中断前的系统中断分布从上面图中可以看出,当前的硬件平台一共有4颗CPU,其中IMX-uart和imx-i2c的中断集中发生在CPU0和CPU3,从第一列可以知道它们的中断号分别是58和69。接下来我们可以将IMX-uart中断全部迁移到CPU1上,让CPU0只响应imx-i2c中断。通过# echo "2" > /proc/irq/58/smp_affinity指令即可完成迁移。注意,这里的数字“2”表示CPU编号,它是从1开始。迁移后IMX-uart中断情况如下:图5:绑定中断后的系统中断分布从前后两张图对比可以看出,中断迁移前,IMX-uart在CPU3上的中断次数为1824次,在CPU0上中断次数为727次。中断迁移后,CPU0和CPU3不再响应IMX-uart中断,CPU1上IMX-uart中断次数由15次增加到了115次。我曾经在一个双核硬件平台上遇到过串口和SPI同时需要响应大量中断,它们互相影响导致中断响应不及时而出现数据丢失和输出不及时的情况,最终就是通过中断绑核解决的。中断绑核其实不能完全消除对实时性的影响,只能最大程度去降低中断对进程的影响,因为系统中NMI中断和本地时钟中断无法迁移和禁止。除了中断可以绑核,应用层的进程和线程也可以改变它们与CPU的亲和性,比如迁移到中断较少的核上,也能在一定程度上提升进程的实时性。2.3进程调度算法除了前面提到的时钟和中断外,还有一个影响实时性最大的因素就是操作系统的调度算法。Linux系统目前默认采用的是完全公平调度算法(CFS),它按照各个进程的权重来分配运行时间,在默认使用CFS的情况下,我们可以给有实时性需求的进程分配更高的优先级和权重,可以看做是通过赋予更高的优先级来获得更好的实时性。 Linux内核目前支持多种调度类,每一种调度类都是同一类型调度策略的集合,目前支持的调度类有:stop、deadline、realtime、CFS、idle。通常情况下进程都可选以上的几种调度类,他们的优先级依次由高到低排序,其中deadline调度类可选的调度策略有SCHED_DEADLINE,realtime调度类可选的调度策略有SCHED_FIFO和SCHED_RR,CFS可选的调度类有SCHED_NORMAI、SCHED_BATCH和SCHED_IDLE。在实际开发过程中,如果对时间有严格要求的实时进程可以选择deadline调度类,其他情况可以参考使用对应的调度策略,改变调度策略,是最直接的一种优化方式。其中deadline调度类的使用参考如下:图6:deadline调度策略编程参考2.4 内核其他限制除了内核本身的调度算法的原因,Linux内核的调度模块当中还有其他限制因素。比如为了防止某个进程或某一个进程组长时间的占用CPU时间,Linux内核引入了一个“运行带宽”的概念,也就是说某一个进程或进程组使用CPU的总时间不能超过这个“带宽”阈值,默认值是0.95s。图7:“运行带宽”默认值实际开发过程中为了提高我们进程的实时性,需要进程长时间地占用CPU资源,我们可以把这个“运行带宽”给禁止掉。实际上不同的产品和使用场景也会有着不同的优化措施,如果设备的CPU核数比较多,我们可以从整体上去规划系统对于CPU的使用,大量的使用中断绑核和进程、线程绑核达到对CPU的独占使用。比如DPDK,它是Intel公司开发的一种高性能网络加速组件。在Linux内核中,传统的网络数据包的收发都是经过网卡驱动和内核协议栈,网卡驱动针对大数据包场景也做了大量的应对措施,但是从本质上来说,网络包的收发在内核中也还是依赖系统给我们实现好的软中断机制。而DPDK则是使用轮询代替了中断,它绕过了Linux内核的网络模块(驱动和协议栈),不需要频繁的进行数据的拷贝,使得用户空间可以直接看到硬件网卡的数据,这大大减小了数据传递路程上的开销。下面这张图就是使用轮询和DPDK独占CPU的一个例子。图8:DPDK轮询独占CPU再比如,irqbalance,它用于终端收集分配,会根据系统的负载情况自动进入性能模式和节能模式,会将中断平均分配到不同的CPU上去处理,特殊情况下我们需要禁止这个功能。还有其他比如禁止软锁、虚拟内存管理优化等。从上面可以看出,实时性优化的方法多种多样,甚至使用使用轮询代替了中断。但是关键还是在于我们要了解Linux内核模块的一些运行机制,和这些机制在实现上本身就存在的缺点,只有这样我们才能针对具体问题作出对应的优化措施。以上提到的这些方法只是从大的方向而且很浅显去分析和介绍Linux内核的实时性影响因素和对应的优化措施。总结起来有以下几点:1. 中断优先级高,要减少中断对进程的影响;2. 进程之间有优先级之分,要合理改变优先级;3. 内核模块的实现机制限制,在特殊情况下使用轮训;4. 提升系统节拍,提升定时精度;5. 禁止irqbalance,防止进入节能或休眠模式;还有其他更为深入的细节我们没有深入分析,比如Linux进程切换耗时,中断响应耗时、内存分配开销以及普通定时器精度和高精度定时器精度等,这些都是从细分的模块方向去研究并优化。进程的切换涉及到主调度器和周期调度器,它们都不可避免地涉及到定时器,目前Linux内核的高精度定时器也很难做到us级别,这也就决定了在调度的时间上也不是那么地准确,再加上内核中充斥着大量的自旋锁,而自旋锁的使用会关闭CPU的中断进而影响实时性,所以在开发过程中更加提高了对我们自身的水平要求。3.总结前面列举的这些优化措施实施起来很简单,但对于我们自身来说更要理解为什么要这么做。深入去分析Linux内核的机制,实际的去阅读内核的模块源码,才会在实时性或者Linux内核的学习道路上收获更多。比如阅读内核源码才会知道tasklet和workqueue的应用场景的不同,尽管它们都是“中断下半部”之一,但是它们在内核当中执行的优先级还是有很大区别。只有阅读内核源码,才会知道tasklet和hrtimer也是基于软中断的,而且这个软中断也有优先级之分。也只有阅读内核源码,才会知道系统目前实现了多少种软中断,甚至我们自己也可以实现软中断获得实时性的提升,尽管Linux内核不建议我们这么做。除了阅读内核的源码,掌握调试跟踪内核的工具也必不可少,比如ftrace、trace-cmd、kernelshark、perf等。俗话说,工欲善其事必先利其器,熟练掌握这些工具的使用会让我们的优化工作更高效。ftrace是一个很强大的调试工具,除了常用的函数跟踪器能让我们轻松知道一个函数的执行耗时之外,它强大的event机制,更是可以直接让我们在驱动或者内核中添加跟踪点,输出内核执行过程中的各类数据,让我们轻松洞察内核的执行过程。总之,实时性优化是一条漫长的道路,一路上也充满了各种未知,钻研越深越对它充满好奇,也越觉得Linux内核神奇。比如你可能会好奇在Linux内核中一个进程从被唤醒到真正去执行这个过程花了多长时间。又比如一个外部中断,从它被触发到真正走到用户注册的中断处理函数,这个过程又花了多长时间。只有自己亲自到设备上去调试,去尝试弄明白这些问题了才会发现Linux内核有趣的地方,也才会越走越充实。以上只是我自己在工作过程中积累的一点观点看法,如果读者面对Linux内核不知道从何处入手的话,个人建议不妨从实时性优化这个方向入手,逐渐深入。原文地址:https://mp.weixin.qq.com/s/Mq_sVpZYM3BrX2NpixBgaw 侵权请私信删除发布于 2022-06-09 21:06操作系统内核LinuxLinux 内核赞同 5添加评论分享喜欢收藏申请转载文章被以下专栏收录Linux内核一种开源电脑操作系统内核。C语
一文入门linux内核高精度定时器hrtimer机制 - 知乎
一文入门linux内核高精度定时器hrtimer机制 - 知乎首发于embedded guy切换模式写文章登录/注册一文入门linux内核高精度定时器hrtimer机制Haonan操作系统工程师,热爱底层系统与原理。 文中代码来自linux5.4-rc8内核 全文大概5000字,建议收藏阅读 0 背景timer子系统因为精度局限在毫秒级别(时钟频率可设置在100HZ到1000HZ之间),无法满足对时间要求高精度的场景(比如看门狗、usb、ethernet、块设备、kvm等子系统)。因此linux社区设计了hrtimer(High Resolution Timer,高精度定时器)子系统,提供纳秒级别的时钟精度。1 如何使用高精度定时器?先从用户的角度了解一下如何使用hrtimer,之后再逐渐深入hrtimer子系统的实现细节。以watchdog使用hrtimer的代码为例:
static void watchdog_enable(unsigned int cpu)
{
struct hrtimer *hrtimer = this_cpu_ptr(&watchdog_hrtimer);
......
/*
* Start the timer first to prevent the NMI watchdog triggering
* before the timer has a chance to fire.
*/
hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
hrtimer->function = watchdog_timer_fn;
hrtimer_start(hrtimer, ns_to_ktime(sample_period),
HRTIMER_MODE_REL_PINNED_HARD);
......
}
static void watchdog_disable(unsigned int cpu)
{
struct hrtimer *hrtimer = this_cpu_ptr(&watchdog_hrtimer);
......
hrtimer_cancel(hrtimer);
......
}
(1)定义一个struct hrtimer的instance(实例);(2)通过hrtimer_init()初始化hrtimer实例;
void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
enum hrtimer_mode mode)
{
debug_init(timer, clock_id, mode);
__hrtimer_init(timer, clock_id, mode);
}
EXPORT_SYMBOL_GPL(hrtimer_init);
其中,clock_id是时钟的种类。
/*
* The IDs of the various system clocks (for POSIX.1b interval timers):
*/
/* REALTIME记录的是从1970.1.1到当前的时间,常说的wall time(墙上时钟) */
#define CLOCK_REALTIME 0
/* MONOTIC记录的是从开机到当前的时间,suspend时不会增加 */
#define CLOCK_MONOTONIC 1
#define CLOCK_PROCESS_CPUTIME_ID 2
#define CLOCK_THREAD_CPUTIME_ID 3
#define CLOCK_MONOTONIC_RAW 4
#define CLOCK_REALTIME_COARSE 5
#define CLOCK_MONOTONIC_COARSE 6
/* BOOTTIME记录的是从开机到当前的时间,suspend时依然会增加 */
#define CLOCK_BOOTTIME 7
#define CLOCK_REALTIME_ALARM 8
#define CLOCK_BOOTTIME_ALARM 9
mode是定时器的模式。
enum hrtimer_mode {
/* 有以下5中基本模式,其他都是基本模式的组合 */
HRTIMER_MODE_ABS = 0x00, /* 定时器到期时间是绝对值 */
HRTIMER_MODE_REL = 0x01, /* 定时器到期时间是相对值 */
HRTIMER_MODE_PINNED = 0x02, /* 定时器需要绑定到某个CPU上 */
HRTIMER_MODE_SOFT = 0x04, /* 定时器是“软”的,即该定时器的回调函数在软中断上下文执行 */
HRTIMER_MODE_HARD = 0x08, /* 定时器是“硬”的,即该定时器的回调函数在硬中断上下文执行即使是PREEMPT_RT打开的情况 */
HRTIMER_MODE_ABS_PINNED = HRTIMER_MODE_ABS | HRTIMER_MODE_PINNED,
HRTIMER_MODE_REL_PINNED = HRTIMER_MODE_REL | HRTIMER_MODE_PINNED,
HRTIMER_MODE_ABS_SOFT = HRTIMER_MODE_ABS | HRTIMER_MODE_SOFT,
HRTIMER_MODE_REL_SOFT = HRTIMER_MODE_REL | HRTIMER_MODE_SOFT,
HRTIMER_MODE_ABS_PINNED_SOFT = HRTIMER_MODE_ABS_PINNED | HRTIMER_MODE_SOFT,
HRTIMER_MODE_REL_PINNED_SOFT = HRTIMER_MODE_REL_PINNED | HRTIMER_MODE_SOFT,
HRTIMER_MODE_ABS_HARD = HRTIMER_MODE_ABS | HRTIMER_MODE_HARD,
HRTIMER_MODE_REL_HARD = HRTIMER_MODE_REL | HRTIMER_MODE_HARD,
HRTIMER_MODE_ABS_PINNED_HARD = HRTIMER_MODE_ABS_PINNED | HRTIMER_MODE_HARD,
HRTIMER_MODE_REL_PINNED_HARD = HRTIMER_MODE_REL_PINNED | HRTIMER_MODE_HARD,
};
(3)hrtimer->function = xxx;通过hrtimer实例的function指定高精度定时器到期的回调函数;(4)hrtimer_start()/hrtimer_start_range_ns()开启定时器;如果定时器不需要指定到期范围就使用hrtimer_start(),如果定时器需要指定到期范围就使用hrtimer_start_range_ns()。
/* 参数tim是到期时间;参数mode是定时器模式,见前文 */
static inline void hrtimer_start(struct hrtimer *timer, ktime_t tim,
const enum hrtimer_mode mode)
{
hrtimer_start_range_ns(timer, tim, 0, mode);
}
/* 参数delta_ns是指松弛(slack)时间,可以理解为一个宽限期,定时器可以在[tim, tim + delta_ns]区间到期 */
void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
u64 delta_ns, const enum hrtimer_mode mode)
{
struct hrtimer_clock_base *base;
unsigned long flags;
/*
* Check whether the HRTIMER_MODE_SOFT bit and hrtimer.is_soft
* match on CONFIG_PREEMPT_RT = n. With PREEMPT_RT check the hard
* expiry mode because unmarked timers are moved to softirq expiry.
*/
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
WARN_ON_ONCE(!(mode & HRTIMER_MODE_SOFT) ^ !timer->is_soft);
else
WARN_ON_ONCE(!(mode & HRTIMER_MODE_HARD) ^ !timer->is_hard);
base = lock_hrtimer_base(timer, &flags);
if (__hrtimer_start_range_ns(timer, tim, delta_ns, mode, base))
hrtimer_reprogram(timer, true);
unlock_hrtimer_base(timer, &flags);
}
EXPORT_SYMBOL_GPL(hrtimer_start_range_ns);
(5)通过hrtimer_cancel()取消一个hrtimer。
/* 等hrtimer的回调运行完,再取消hrtimer */
int hrtimer_cancel(struct hrtimer *timer)
{
int ret;
do {
ret = hrtimer_try_to_cancel(timer);
if (ret < 0)
hrtimer_cancel_wait_running(timer);
} while (ret < 0);
return ret;
}
EXPORT_SYMBOL_GPL(hrtimer_cancel);
2 hrtimer的组织方式如图所示:(1)因为红黑树在查询、插入、删除时的性能优势,hrtimer的核心组织结构选择了红黑树,树的最左下节点就是最早到期的定时器;(2)每个cpu上定义了一个hrtimer_cpu_base的全局变量,用于管理属于自己的hrtimer;
struct hrtimer_cpu_base {
/* hrtimer_cpu_base每个cpu只有一个,存在并发访问,lock是用来保护该结构体的自旋锁 */
raw_spinlock_t lock;
/* 所属的cpu编号 */
unsigned int cpu;
/* 表示clock_base数组中哪些时钟基准下的红黑树中存在hrtimer */
unsigned int active_bases;
unsigned int clock_was_set_seq;
/* 标识是否处在高精度模式下 */
unsigned int hres_active : 1,
/* 标识是否正在执行hrtimer_interrupt回调函数 */
in_hrtirq : 1,
/* 标识是否上一次执行hrtimer_interrupt出现了错误 */
hang_detected : 1,
/* 标识是否正在执行软中断处理程序hrtimer_run_softirq */
softirq_activated : 1;
#ifdef CONFIG_HIGH_RES_TIMERS
/* 标识一共执行了多少次hrtimer_interrupt回调函数 */
unsigned int nr_events;
/* 标识在执行hrtimer_interrupt时对定时事件设备编程错误后重试的次数 */
unsigned short nr_retries;
/* 标识在执行hrtimer_interrupt时发生错误的次数 */
unsigned short nr_hangs;
/* 出现错误后,在hrtimer_interrupt中停留的最长时间 */
unsigned int max_hang_time;
#endif
#ifdef CONFIG_PREEMPT_RT
spinlock_t softirq_expiry_lock;
atomic_t timer_waiters;
#endif
/* 该CPU上即将到期hrtimer的到期时间,包括硬hrtimer和软hrtimer */
ktime_t expires_next;
/* 该CPU上即将到期的hrtimer,包括硬hrtimer和软hrtimer */
struct hrtimer *next_timer;
/* 该CPU上即将到期的软hrtimer的到期时间 */
ktime_t softirq_expires_next;
/* 该CPU上即将到期的软hrtimer */
struct hrtimer *softirq_next_timer;
/* hrtimer的到期时间可以基于不同的时钟类型,每个类型都对应一个hrtimer_clock_base结构体 */
struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];
} ____cacheline_aligned;
(3)每个CPU的hrtimer_cpu_base全局变量对应着HRTIMER_MAX_CLOCK_BASES(当前是8)个hrtimer_clock_base变量。每个hrtimer_clock_base对应一种不同的时钟类型。
enum hrtimer_base_type {
HRTIMER_BASE_MONOTONIC,
HRTIMER_BASE_REALTIME,
HRTIMER_BASE_BOOTTIME,
HRTIMER_BASE_TAI,
HRTIMER_BASE_MONOTONIC_SOFT,
HRTIMER_BASE_REALTIME_SOFT,
HRTIMER_BASE_BOOTTIME_SOFT,
HRTIMER_BASE_TAI_SOFT,
HRTIMER_MAX_CLOCK_BASES,
};
根据hrtimer_init时传入的clock_id,决定对应的hrtimer实例挂在哪个hrtimer_clock_base对应的红黑树下。
struct hrtimer_clock_base {
/* 标识自己属于哪个cpu的hrtimer_cpu_base */
struct hrtimer_cpu_base *cpu_base;
/* 标识自己在hrtimer_cpu_base的clock_base数组的下标 */
unsigned int index;
/* 标识当前时钟类型的id */
clockid_t clockid;
seqcount_t seq;
/* 指向当前正在处理的定时器 */
struct hrtimer *running;
/* 属于本clock_base的定时器红黑树 */
struct timerqueue_head active;
/* 获取该时间类型当前时间的回调函数 */
ktime_t (*get_time)(void);
/* 标识当前时间类型和单调时间之间的差值,因为判断定时器超时最后都会转化为单调时间进行对比 */
ktime_t offset;
} __hrtimer_clock_base_align;
3 hrtimer子系统的初始化在start_kernel()中会调用hrtimers_init()初始化hrtimer子系统。
void __init hrtimers_init(void)
{
/* 初始化当前cpu的hrtimer_cpu_base */
hrtimers_prepare_cpu(smp_processor_id());
/* 注册HRTIMER的软中断回调函数 */
open_softirq(HRTIMER_SOFTIRQ, hrtimer_run_softirq);
}
int hrtimers_prepare_cpu(unsigned int cpu)
{
struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
int i;
/* 初始化当前cpu的hrtimer_cpu_base中所有时钟类型的hrtimer_clock_base */
for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
cpu_base->clock_base[i].cpu_base = cpu_base;
/* 初始化本hrtimer_clock_base的红黑树 */
timerqueue_init_head(&cpu_base->clock_base[i].active);
}
cpu_base->cpu = cpu;
cpu_base->active_bases = 0;
cpu_base->hres_active = 0;
cpu_base->hang_detected = 0;
cpu_base->next_timer = NULL;
cpu_base->softirq_next_timer = NULL;
cpu_base->expires_next = KTIME_MAX;
cpu_base->softirq_expires_next = KTIME_MAX;
hrtimer_cpu_base_init_expiry_lock(cpu_base);
return 0;
}
4 定时事件设备clock_event_device简单介绍一下clock_event_device,它是理解timer/hrtimer子系统的关键。clock_event_device可以理解为硬件定时器的封装,它是软件可编程的,即可以控制硬件定时器什么时候触发中断。 系统中可以存在多个clock_event_device,系统会根据它们的精度和能力,选择合适的clock_event_device对系统提供时钟事件服务。在smp系统中,为了减少处理器间的通信开销,基本上每个cpu都会具备一个属于自己的本地clock_event_device,独立地为该cpu提供时钟事件服务,smp中的每个cpu基于本地的clock_event_device,建立自己的tick_device,普通定时器和高精度定时器。 ———————————————— 版权声明:本文为CSDN博主「DroidPhone」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/DroidPhone/article/details/8017604 关于clock_event_device的详细内容可参考文章Linux时间子系统之四:定时器的引擎:clock_event_device5 hrtimer的到期处理处理hrtimer的函数是__hrtimer_run_queues(),看看有谁调用该函数:因此hrtimer的处理有3个入口:在hrtimer软中断处理程序中,只处理软timer;在低精度模式下,在每个jiffies的tick中断处理函数中执行,只处理硬timer;在高精度模式下,在每个clock_event_device的到期中断处理函数hrtimer_interrupt中执行,只处理硬timer。5.1 低精度模式在系统运行早期,hrtimer子系统先运行在低精度模式,这时是在每个jiffies的tick事件中断(tick_handle_periodic())中处理到期的hrtimer,因此此时的时间精度和timer子系统是一致的,都是HZ级别的。函数调用链:tick_handle_periodic()---->tick_periodic()---->update_process_times()---->run_local_timers()---->hrtimer_run_queues()
void hrtimer_run_queues(void)
{
struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
unsigned long flags;
ktime_t now;
/* 如果当前是高精度模式,则直接退出 */
if (__hrtimer_hres_active(cpu_base))
return;
/*
* This _is_ ugly: We have to check periodically, whether we
* can switch to highres and / or nohz mode. The clocksource
* switch happens with xtime_lock held. Notification from
* there only sets the check bit in the tick_oneshot code,
* otherwise we might deadlock vs. xtime_lock.
*/
/* 检查是否可以切换到高精度模式 */
if (tick_check_oneshot_change(!hrtimer_is_hres_enabled())) {
hrtimer_switch_to_hres();
return;
}
raw_spin_lock_irqsave(&cpu_base->lock, flags);
/* 获得当前时间 */
now = hrtimer_update_base(cpu_base);
/* 如果当前时间 > 下一个到期的软timer的过期时间,表示有软timer到期了 */
if (!ktime_before(now, cpu_base->softirq_expires_next)) {
/* 将下个到期的软超时间设置为最大值,这算是默认值,等待hrtimer软中断处理函数重新更新下一个即将超时的软timer的过期时间*/
cpu_base->softirq_expires_next = KTIME_MAX;
/* 设置softirq_activated表示已经激活了本CPU的hrtimer软中断 */
cpu_base->softirq_activated = 1;
/* 触发HRTIMER软中断 */
raise_softirq_irqoff(HRTIMER_SOFTIRQ);
}
/* 处理所有到期的硬timer,用户指定的hrtimer->function会在这里执行 */
__hrtimer_run_queues(cpu_base, now, flags, HRTIMER_ACTIVE_HARD);
raw_spin_unlock_irqrestore(&cpu_base->lock, flags);
}
低精度模式下,每次执行到hrtimer_run_queues都会检查是否符合切换到高精度的条件:高精度模式没有被禁止(打开了内核选项CONFIG_HIGH_RES_TIMERS);当前存在高分辨率的时钟源设备;当前定时设备是支持单次触发(oneshot)的。当以上条件满足时,切换到高精度模式:
/*
* Switch to high resolution mode
*/
static void hrtimer_switch_to_hres(void)
{
struct hrtimer_cpu_base *base = this_cpu_ptr(&hrtimer_bases);
/*
* 将clock_event_device的中断回调函数注册为hrtimer_interrupt(之前是tick_handle_periodic),
* 同时时钟中断的触发模式从周期触发变成了oneshot模式
*/
if (tick_init_highres()) {
pr_warn("Could not switch to high resolution mode on CPU %u\n",
base->cpu);
return;
}
base->hres_active = 1;
hrtimer_resolution = HIGH_RES_NSEC;
/*
* 因为时钟中断变成了oneshot模式,但是jiffies的更新、进程调度还是依赖于低精度的tick,
* 因此专门通过一个hrtimer循环模拟低精度的tick
*/
tick_setup_sched_timer();
/* "Retrigger" the interrupt to get things going */
retrigger_next_event(NULL);
}
我们再稍微关心一下模拟tick的hrtimer的回调函数:
static enum hrtimer_restart tick_sched_timer(struct hrtimer *timer)
{
struct tick_sched *ts =
container_of(timer, struct tick_sched, sched_timer);
struct pt_regs *regs = get_irq_regs();
ktime_t now = ktime_get();
/* 主要是更新jiffies时间,注意smp系统中只有一个cpu负责更新jiffiies */
tick_sched_do_timer(ts, now);
/*
* Do not call, when we are not in irq context and have
* no valid regs pointer
*/
if (regs)
tick_sched_handle(ts, regs);
else
ts->next_tick = 0;
/* No need to reprogram if we are in idle or full dynticks mode */
if (unlikely(ts->tick_stopped))
return HRTIMER_NORESTART;
/* 将该hrtimer的到期时间推后tick_period时间 */
hrtimer_forward(timer, now, tick_period);
/* 返回HRTIMER_RESTART表示该hrtimer需要再次执行,这就实现了每tick_period时间触发一次tick中断了 */
return HRTIMER_RESTART;
}
5.2 高精度模式当系统切换到高精度定时器模式后,某个hrtimer到期后会调用中断处理函数hrtimer_interrupt()。需要强调的是,即使在开了PREEMPT_RT的系统上,hrtimer_interrupt也是在硬中断上下文中执行。
/*
* High resolution timer interrupt
* Called with interrupts disabled
*/
void hrtimer_interrupt(struct clock_event_device *dev)
{
struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
ktime_t expires_next, now, entry_time, delta;
unsigned long flags;
int retries = 0;
/* 如果当前不是高精度定时器模式,则触发oops使系统panic */
BUG_ON(!cpu_base->hres_active);
cpu_base->nr_events++;
dev->next_event = KTIME_MAX;
raw_spin_lock_irqsave(&cpu_base->lock, flags);
/* 获得当前时间 */
entry_time = now = hrtimer_update_base(cpu_base);
retry:
/* 标识当前处于hrtimer_interrupt函数中 */
cpu_base->in_hrtirq = 1;
/*
* We set expires_next to KTIME_MAX here with cpu_base->lock
* held to prevent that a timer is enqueued in our queue via
* the migration code. This does not affect enqueueing of
* timers which run their callback and need to be requeued on
* this CPU.
*/
cpu_base->expires_next = KTIME_MAX;
/* 如果当前时间 > 下一个到期的软timer的过期时间,表示有软timer到期了 */
if (!ktime_before(now, cpu_base->softirq_expires_next)) {
/* 将下个到期的软超时间设置为最大值,这算是默认值,等待hrtimer软中断处理函数重新更新下一个即将超时的软timer的过期时间*/
cpu_base->softirq_expires_next = KTIME_MAX;
/* 设置softirq_activated表示已经激活了本CPU的hrtimer软中断 */
cpu_base->softirq_activated = 1;
/* 触发HRTIMER软中断 */
raise_softirq_irqoff(HRTIMER_SOFTIRQ);
}
/* 处理所有到期的硬timer,用户指定的hrtimer->function会在这里执行 */
__hrtimer_run_queues(cpu_base, now, flags, HRTIMER_ACTIVE_HARD);
/* 更新接下来即将到期的定时器 */
/* Reevaluate the clock bases for the next expiry */
expires_next = __hrtimer_get_next_event(cpu_base, HRTIMER_ACTIVE_ALL);
/*
* Store the new expiry value so the migration code can verify
* against it.
*/
cpu_base->expires_next = expires_next;
cpu_base->in_hrtirq = 0;
raw_spin_unlock_irqrestore(&cpu_base->lock, flags);
/* 使用最新的超时时间对定时事件设备(clock_event_device)进行重新编程,即指定下一次arch_timer的中断什么时候到来 */
/* Reprogramming necessary ? */
if (!tick_program_event(expires_next, 0)) {
cpu_base->hang_detected = 0;
return;
}
/*
* The next timer was already expired due to:
* - tracing
* - long lasting callbacks
* - being scheduled away when running in a VM
*
* We need to prevent that we loop forever in the hrtimer
* interrupt routine. We give it 3 attempts to avoid
* overreacting on some spurious event.
*
* Acquire base lock for updating the offsets and retrieving
* the current time.
*/
raw_spin_lock_irqsave(&cpu_base->lock, flags);
/* 重新获取当前时间,retry处理定时器 & 对定时事件设备进行编程 */
now = hrtimer_update_base(cpu_base);
cpu_base->nr_retries++;
if (++retries < 3)
goto retry;
/*
* Give the system a chance to do something else than looping
* here. We stored the entry time, so we know exactly how long
* we spent here. We schedule the next event this amount of
* time away.
*/
/* 如果走到这里说明3次对定时事件设备编程都失败了,更新与hang有关的信息统计 */
cpu_base->nr_hangs++;
cpu_base->hang_detected = 1;
raw_spin_unlock_irqrestore(&cpu_base->lock, flags);
/* 计算在hrtimer_interrupt中花费了多少时间,更新max_hang_time */
delta = ktime_sub(now, entry_time);
if ((unsigned int)delta > cpu_base->max_hang_time)
cpu_base->max_hang_time = (unsigned int) delta;
/*
* Limit it to a sensible value as we enforce a longer
* delay. Give the CPU at least 100ms to catch up.
*/
/* 适当延后下一次到期时间,最多100毫秒 */
if (delta > 100 * NSEC_PER_MSEC)
expires_next = ktime_add_ns(now, 100 * NSEC_PER_MSEC);
else
expires_next = ktime_add(now, delta);
/* 强制对定时事件设备进程重新编程,否则收不到arch_timer中断了 */
tick_program_event(expires_next, 1);
pr_warn_once("hrtimer: interrupt took %llu ns\n", ktime_to_ns(delta));
}
5.3 软中断中处理软hrtimer前文在低精度模式/高精度模式中,在硬中断上下文中处理了硬timer们,对于软timer只是raise了HRTIMER的软中断。我们看一下软timer是怎么被处理的。软中断执行逻辑参考文章代码量很少的linux软中断机制,这里只聊HRTIMER软中断处理函数。
static __latent_entropy void hrtimer_run_softirq(struct softirq_action *h)
{
struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
unsigned long flags;
ktime_t now;
hrtimer_cpu_base_lock_expiry(cpu_base);
raw_spin_lock_irqsave(&cpu_base->lock, flags);
/* 获得当前时间 */
now = hrtimer_update_base(cpu_base);
/* 处理所有到期的软timer,用户指定的hrtimer->function会在这里执行 */
__hrtimer_run_queues(cpu_base, now, flags, HRTIMER_ACTIVE_SOFT);
/* 将本cpu的softirq_activated状态位置0,表示没有激活HRTIMER的软中断 */
cpu_base->softirq_activated = 0;
hrtimer_update_softirq_timer(cpu_base, true);
/*
* 更新即将到期的软timer,对clock_event_device重新编程,
* 同时更新cpu_base->softirq_expires_next,将其从在
* hrtimer_interrupt中置的KTIME_MAX更新为下一个到期的软timer的时间
*/
raw_spin_unlock_irqrestore(&cpu_base->lock, flags);
hrtimer_cpu_base_unlock_expiry(cpu_base);
}
结合hrtimer_run_softirq()与hrtimer_interrupt()对软中断的处理,可以看出如果某一次HRTIMER的软中断处理函数hrtimer_run_softirq()因为操作不当没有得到执行,那么所有的软hrtimer将永远不会得到执行,因此需要确保软中断子系统是稳定的。笔者在生产环境中遇到过网络驱动程序在未关中断的情况下调用raise_softirq_irqoff(NETRX_SOFTIRQ)修改软中断的pending位,此时正好来了arch_timer的中断,从而触发hrtimer_interrupt调用raise_softirq_irqoff(HRTIMER_SOFTIRQ)也来修改软中断的pending位;这种对全局变量非原子的操作,会导致变量RMW(Read-Modify-Write)过程中出现竞争,从而丢掉HRTIMER_SOFTIRQ的pending置位,在高频网络收发包情况下会必现软timer超时,且永远得不到处理的情况,因此当前对软timer的处理逻辑不得不说是十分脆弱的。原创文章,转载请注明出处。更多linux内核文章,点击传送门 Haonan:embedded guy专栏文章目录,会持续更新!参考文章Linux时间子系统之六:高精度定时器(HRTIMER)的原理和实现Linux时间子系统之高分辨率定时器层(HR Timer)arm_arch_timer代码阅读Linux时间子系统之(十七):ARM generic timer驱动代码分析Linux内核时钟系统和定时器实现Linux时间子系统之三:时间的维护者:timekeeperLinux时间子系统之四:定时器的引擎:clock_event_device编辑于 2022-04-18 00:37Linux 内核Linux定时器(程序开发)赞同 288 条评论分享喜欢收藏申请转载文章被以下专栏收录embedded guyread the code, write s
Ultra HFR: 240fps Real Time Video Now Possible Today. 1000fps Tomorrow. [UPDATED] | Blur Busters
Ultra HFR: 240fps Real Time Video Now Possible Today. 1000fps Tomorrow. [UPDATED] | Blur Busters
Official Monitor List
1000Hz Journey
Framerate Amplification
G-SYNC 101: Input Lag
BenQ Strobe Utility
Motion Blur Reduction
Login / RegisterMonitor List
View all Monitor Lists
List of Best Gaming Monitors
List of G-SYNC Monitors
List of FreeSync Monitors
List of Best Ultrawide Monitors
G-SYNC
View all G-SYNC Articles
G-SYNC 101 Series
01 — G-SYNC 101: Control Panel
02 — G-SYNC 101: Range
03 — G-SYNC 101: Input Lag & Test Methodology
04 — G-SYNC 101: G-SYNC Ceiling vs. V-SYNC
05 — G-SYNC 101: G-SYNC Ceiling vs. FPS Limit
06 — G-SYNC 101: G-SYNC vs. V-SYNC OFF w/FPS Limit
07 — G-SYNC 101: G-SYNC vs. V-SYNC w/FPS Limit
08 — G-SYNC 101: G-SYNC vs. Fast Sync
09 — G-SYNC 101: G-SYNC vs. V-SYNC OFF
10 — G-SYNC 101: G-SYNC Fullscreen vs. Borderless/Windowed
11 — G-SYNC 101: In-game vs. External FPS Limiters
12 — G-SYNC 101: External FPS Limiter HOWTO
13 — G-SYNC 101: Hidden Benefits of High Refresh Rate G-SYNC
14 — G-SYNC 101: Optimal G-SYNC Settings & Conclusion
15 — G-SYNC 101: Closing FAQ
How Does G-SYNC Fix Stutters?
Preview of NVIDIA G-SYNC, Part #1 (Fluidity)
Preview of NVIDIA G-SYNC, Part #2 (Input Lag)
List of G-SYNC Monitors
FreeSync
TestUFO
Research
Motion Blur
Company
About This Site
About Founder Mark Rejhon
Consulting Services
Display Testing Inventions
Press Releases
Contact Blur Busters
More
Input Lag
PC Gaming & Esports
Virtual Reality
Mice & Accessories
Gaming Laptops & Phones
Gaming Consoles
Televisions
GPUs
AMD
NVIDIA
HFR and UltraHFR Video
Web Browsers
Industry Standards
Menu
Light Mode
Dark Mode
OS-controlled
Login / Register
Forums
Login / RegisterMonitor List
View all Monitor Lists
List of Best Gaming Monitors
List of G-SYNC Monitors
List of FreeSync Monitors
List of Best Ultrawide Monitors
G-SYNC
View all G-SYNC Articles
G-SYNC 101 Series
01 — G-SYNC 101: Control Panel
02 — G-SYNC 101: Range
03 — G-SYNC 101: Input Lag & Test Methodology
04 — G-SYNC 101: G-SYNC Ceiling vs. V-SYNC
05 — G-SYNC 101: G-SYNC Ceiling vs. FPS Limit
06 — G-SYNC 101: G-SYNC vs. V-SYNC OFF w/FPS Limit
07 — G-SYNC 101: G-SYNC vs. V-SYNC w/FPS Limit
08 — G-SYNC 101: G-SYNC vs. Fast Sync
09 — G-SYNC 101: G-SYNC vs. V-SYNC OFF
10 — G-SYNC 101: G-SYNC Fullscreen vs. Borderless/Windowed
11 — G-SYNC 101: In-game vs. External FPS Limiters
12 — G-SYNC 101: External FPS Limiter HOWTO
13 — G-SYNC 101: Hidden Benefits of High Refresh Rate G-SYNC
14 — G-SYNC 101: Optimal G-SYNC Settings & Conclusion
15 — G-SYNC 101: Closing FAQ
How Does G-SYNC Fix Stutters?
Preview of NVIDIA G-SYNC, Part #1 (Fluidity)
Preview of NVIDIA G-SYNC, Part #2 (Input Lag)
List of G-SYNC Monitors
FreeSync
TestUFO
Research
Motion Blur
Company
About This Site
About Founder Mark Rejhon
Consulting Services
Display Testing Inventions
Press Releases
Contact Blur Busters
More
Input Lag
PC Gaming & Esports
Virtual Reality
Mice & Accessories
Gaming Laptops & Phones
Gaming Consoles
Televisions
GPUs
AMD
NVIDIA
HFR and UltraHFR Video
Web Browsers
Industry Standards
Ultra HFR: 240fps Real Time Video Now Possible Today. 1000fps Tomorrow. [UPDATED]
Posted Jun 12, 2020 by Mark Rejhon
in:
Area 51: Display Research HFR Video
Share
ORIGINALLY WRITTEN FEB 2018. Updated June 2020 with new information.
Ever since the Blur Busters Holiday Special article about the Amazing Journey to 1000Hz Displays and the earlier true 480Hz monitor tests, Blur Busters has been paying much more attention to HFR video developments.
We are the only website in the world to exclusively talk about “Better Than 60Hz”. This universe also includes 120fps HFR. However, there are also experiments with Ultra HFR — the art of displaying video at ultra high frame rates (HFR 240fps, 480fps and 1000fps) in real-time on ultra high refresh rate displays. Not slow motion!
Longtime readers are familiar with our world’s first embedded 120fps HFR web browser videos and world’s first 120fps gameplay video five years ago (Year 2013)
World’s First 1080p Embedded 120fps Video Game Recording
120fps HFR Video in Real Time
Now, we are testing video beyond 120 frames per second!
Ultra HFR: True 240 fps Real Time
Here is a method of creating 240 frame per second HFR video, for play back on today’s 240 Hz eSports monitor.
Get any favourite slo-mo camera capable of 240fps.
…From smartphones to GoPros to Phantom Flex cameras, many cameras now can do 240fps.
Get a GPU capable of 4K60 playback.
…GPUs capable of 4K 60fps playback are also able to do 1080p 240fps playback.
Get a true-240Hz gaming monitor. See List of Best Gaming Monitors.
Download and install ffmpeg.
Record video in normal 240fps slo-mo. Resulting file is 30fps.
If you need to use a video editor, edit while video is still slo-mo. Then export an .MP4 video.
Finally, run this ffmpeg command line to speed up the video back to real-time playback.
This speeds up video to play at 8 times the frame rate, converting 30fps to 240fps.
ffmpeg -i slowmo240.mp4 -r 240 -vf "setpts=(1/8)*PTS" -an realtime240.mp4
Play the video in your player (VLC, MPC-HC, Windows Media, etc) on your 240 Hz display.
…You may need to experiment with different video players to find the best 240fps experience.
High speed cameras, designed for slo-mo, often do not record audio well. At the moment, the best way to add audio is to record the audio separately, and use a command line utility to dub the audio onto the sped-up file.
The same general instructions apply to 480fps and 1000fps HFR, with different speedup factors (replace number “8” with the appropriate speedup factor).
Share your results in the new Blur Busters Forums High Frame Rate (HFR) Video discussion area!
Future 1000fps HFR: 240fps is not the final frontier
In the newly created Blur Busters HFR Forum, there is a thread worth reading about Ultra HFR.
The art of playing true 1000fps real time on true 1000Hz displays: Cinematography of 2030s: Ultra HFR (1000fps at 1000Hz!)
Experimental 1000 Hz displays are already available, and will eventually be cheap within one human generation. Now even some smartphones are also gaining ultra-high frame rate video recording capabilities too. This presents opportunities for cheap Ultra HFR in the coming years!
By doing 1000fps HFR on a 1000Hz display, you can simultaneously avoid camera motion blur and avoid display motion blur and avoid stroboscopic effects. Strobless low-persistence (blurless sample-and-hold) without flicker is successfully achieved with 1000 Hz experimental laboratory displays, and is also useful with Ultra HFR video.
But why do UltraHFR?
Source Camera Blur and Destination Display Blur is Additive
Today, modern displays are sample-and-hold, for ergonomic flicker-free reasons, which creates a Hz bottleneck. No CRT flicker, but far more motion blur than a CRT tube.
A camera shutter 1/60sec combined with common display 1/60sec persistence = creates 2/60sec worth of motion blur. That’s 1/30sec of motion blurring seen by human eyes when playing 60fps video taken with 1/60sec shutter, played onto a 60Hz sample-and-hold display! This is even assuming instant pixel response GtG 0ms, otherwise, there’s worse motion blur than 1/30sec!
To reduce camera-side motion blur massively, a content creator can use a fast sports shutter 1/1000sec on the camera. But this will always be bottlenecked by destination display blur, from the sample-and-hold effect.
This diagram below is from our Pixel Response FAQ, GtG versus MPRT (the two different pixel response benchmarks). Flickerfree displays (sample-and-hold displays such as LCDs, OLEDs, MicroLEDs) produces a mandatory guaranteed added display-side motion blur:
To see this for yourself, we have TestUFO motion animations that demonstrates enforced motion blur caused by display persistence: TestUFO animation demo #1, TestUFO animation demo #2. As a general rule of thumb, the refresh rate of a flickerfree display is typically the guaranteed minimum display motion blur: 120Hz = 1/120sec = 8.3ms of motion blur = 8.3 pixels of blurring per 1000 pixels/sec motion.
To eliminate all motion blur weak links, both source shutter (1/1000sec) and display persistence (1ms MPRT) should be fast. There are two ways to reduce display motion blur:
Shorten display’s frame visibility time via impulsing (CRT, plasma, black frames, etc)
Shorten display’s frame visibility time via higher frame rate
The problem with approach (1) is you can produce stroboscopic stepping effects (phantom arrays) for fast-camera-shutter material such as sports, see The Stroboscopic Effect of Finite Frame Rate Displays. Besides, real life doesn’t flicker or strobe, so impulsing is a humankind band-aid for simulating reality.
Solving motion blur and stroboscopic effect simultaneously requires ultra high frame rates: 1000fps at 1000Hz! One can do a 360-degree camera shutter blurlessly. A full-open shutter is only 1 millisecond during 1000fps video. A 1000Hz display is blurless sample-and-hold via sheer brute Hz.
This makes video look closer to real life, closer to a Holodeck — with no framerate-induced limitations like forced motionblur or forced stroboscopic effects. This can make 1000fps UltraHFR less nauseating than 120fps HFR.
Diminishing Curve: Next Step After 120fps HFR should be 1000fps UltraHFR
Time-wise, the difference between 120fps HFR versus 1000fps HFR is roughly as big as the difference between 60fps and 120fps. This is because 1/60sec and 1/120sec is an 8.3ms difference, while the difference between 1/120sec and 1/1000sec is a 7.3ms difference. There is a curve of diminishing points of returns, but the massive jump up to 1000fps HFR greatly compensates.
1/60sec = 16.7ms blur
1/120sec = 8.33ms blur — observe 8.3ms improvement over 1/60sec
1/1000sec = 1ms blur — observe 7.3ms improvement over 1/120sec
As a result, a large jump up the diminishing curve of returns is required to get as dramatic improvement as the jump between 60fps and 120fps HFR. Therefore we believe that the next step after 120fps HFR should now be 1000fps HFR.
Also, UltraHFR benefits higher resolution more. 1000fps UltraHFR would not be nearly as useful for standard-definition video material (less than 1 pixel of motion blur for one-screen-width-per-second motion) but would be hugely beneficial to 8K material (8 pixels of motion blur for one-screen-width-per-second panning motion)
Very Important UltraHFR Tips For Max Frame Rate Video
When trying to force a display to go maximum motion clarity, there are some best practices.
In the world of experiments with 240fps, 480fps and 1000fps real-time video playback on ultra-high Hz displays, these are very important considerations from recent research:
Display persistence is additive to camera persistence (shutter). A 1/60sec persistence display combined with a 1/60sec shutter video, generates a combined 2/60sec of human-perceived motion blur. As a rule of thumb, your common perceived blur is often at least twice the camera shutter, and often much worse (e.g. 1/1000sec shutter combined with 1/60sec display persistence). This means that on most displays, a 1/1000sec shutter at 60fps only has barely half the motion blur of 1/60sec shutter, simply because it is bottlenecked by 1/60sec display persistence! Also, a display that has a pixel response (GtG) that is a significant percentage of a refresh cycle at its max Hz — will also limit UltraHFR benefits even further.
You must be aware of how both source (Camera) and destination (Display) persistence combines in motion blur in order to understand limitations to UltraHFR benefits
Resolution reduction is a big problem at higher frame rates on current cameras. Recommended is to oversample by recording at about 2x resolution (e.g. true 4K) and then downconvert (e.g. to 1080p). For this reason, it is hugely preferable to get a superior high speed camera (e.g. Phantom Flex 4K) instead of smartphone camera (e.g. iPhone in Slo-mo) when generating source footage.
You must minimize resolution loss to preserve UltraHFR benefits
Compression is a big blur problem. Use less compression
You must minimize compression to preserve UltraHFR benefits
Lens autofocus is sometimes difficult during filming moving imagery. It is especially amplified when your motion clarity is extremely sharp, to the point where any camera focus issues begin to become visible.
You must make sure focus is sharp during fast motion to preserve UltraHFR benefits
Be aware of the vicious cycle effect where higher resolutions demands higher refresh rates to eliminate resolution limitations. The difference between static images and moving images become much more pronounced at 8K than it is for 1080p, since motion blur is time-based (e.g. same amount of blur per inch, affects more pixels on higher DPI displays). This is especially hard because current camera technology often goes lower resolution at higher frame rates.
You must use a higher resolution to preserve UltraHFR benefits
High frame rates benefits high motion material. A great example is sportsfield panning, downhill skiing, BMX racing, car racing, etc. When the first HDTVs arrived, some camera operators reported they had to intentionally slow down panning and operate slightly differently because LCD HDTV blur (of the first flat panel HDTVs) was much worse than old CRT motion clarity.
UltraHFR benefits fast motion material very significantly.
Many historical frame rate tests about frame rate benefits have often neglected to consider (1) (2) (3) (4) (5) (6) simultaneously.
Research indicates that any one of the above can be a weak link in eliminating the benefits of UltraHFR video, and one must carefully control the variables to give truly human-visible benefits of UltraHFR. If you are planning any experiments in UltraHFR at maximum frame rates for the best possible Holodeck-league motion clarity, it is very important to know and understand the above variables.
Four Simple Fixes for Temporally Accurate Reality Simulation
To eliminate all weak links, so that remaining limitations is human-vision based. No camera-based or display-based limitations above and beyond natural human vision/brain limitations.
Fix source stroboscopic effect (camera): Must use a 360-degree camera shutter;
Fix destination stroboscopic effect (display): Must use a sample-and-hold display;
Fix source motion blur (camera): Must use a short camera exposure per frame;
Fix destination motion blur (display): Must use a short persistence per refresh cycle.
Therefore;
Ultra high frame rate with 360-degree camera shutter is also short camera exposure per frame;
Ultra high refresh rate with sample-and-hold display is also short persistence per refresh cycle,
Therefor, to solve (1), (2), (3), (4) simultaneously requires ultra high frame rates at ultra high refresh rates.
We Love Hollywood Movie Maker Mode Too: Full Control Of Entire Blur Chain
1000fps UltraHFR gives the director full control of motion blur, too. 1000fps UltraHFR is a huge venn digram capable of embedding the entire range of framerates in humankind.
With such fine granularities on an ultra-high-Hz displays, refresh rates no longer need to be evenly divisible by frame rate, in order to look smooth!
When 18fps, 23.97fps, 24fps, 25fps, 50fps, 59.94fps, 48fps, 60fps, are all played to a 1000Hz display, all framerates have their original look and motion blur. They play judderlessly without noticable pulldown judder (i.e. 3:2 pulldown) because of the unnoticeable ultrafine refresh rate granularity.
In other words, 24fps video embedded inside a UltraHFR-capable video file, played on a 1000Hz display, looks exactly like a 24Hz display — all with original camera motion blur and persistence blur.
The ability to go as blurry as you want (preserve camera blur / old frame rates) — and the ability to go virtually zero-blur as you want — is an amazing property of UltraHFR video files in the quadruple-digit framerate range.
Conclusion
At Blur Busters, we are among the few people in the world to have witnessed Ultra HFR video!
Being the founder of Blur Busters (Mark Rejhon), I used to work with video processor companies (RUNCO, Key Digital, and a PCI card containing a Faroudja chip). I was the author of the world’s first open source 3:2 pulldown deinterlacer algorithm twenty years ago in dScaler (Year 2000, Internet Archive).
We believe this is very useful for many applications in the coming decade, from speciality theatre, virtual reality, amusement park rides, advanced cinema, truly immersive virtual vacations, “Holodeck” video, and other applications once more 1000 Hz displays are commercially available beginning sometime within the next decade and beyond.
Related Reading
480Hz Displays — World’s First 480Hz Monitor Review
1000Hz Displays — Blur Busters Law: The Amazing Journey To Future 1000Hz Displays
Frame Rate Amplification Technology — More Frame Rate With Less GPU Power Per Frame
Stroboscopic Effects — The Stroboscopic Effect of Finite Frame Rate Displays
Discussion Forum — High Frame Rate Video (HFR)
← LG’s UltraGear 38GN950 Priced and Released
Iiyama Announce the Curved G-Master GB3466WQSU For Gaming →
Share
About Mark Rejhon
Also known as Chief Blur Buster. Founder of Blur Busters. Inventor of TestUFO. Read more about him on the About Mark page.
View all posts by Mark Rejhon →
4 Comments For “Ultra HFR: 240fps Real Time Video Now Possible Today. 1000fps Tomorrow. [UPDATED]”
You must be logged in to post a comment.
You must be logged in to post a comment.
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Sort by:
newest |
oldest
| most liked
MemberDCGI made an older post with a game video sample at 4k 480fps.
Now I made new videos in 1080p and 1440p with higher motion scenes. Links below
1080p
https://1drv.ms/u/s!AiWtAukksSo7gxoGCKcuSwD1PsHS?e=yKRIfR
1440p
https://1drv.ms/u/s!AiWtAukksSo7gxsCD0sj5qQ4ecLO?e=DeNXF5
BRs
Like1Vote Down 3 years 8 months agoMemberPOVHFR VideosI do exactly this, only I have cameras that actually take 240fps with good sound. I have a Sony X1000v and a new GoPro Hero 6 black which take 720p and 1080p at 240fps. But I have been experimenting with higher frame rates up to 480fps and 960fps, they are on my YouTube. I even feature your website in my latest video. You are truly awesome, and it’s like we are on the same page with HFR Video and aiming to completely remove stroboscopic effects from video! Here is my Youtube Channel: https://www.youtube.com/channel/UCbevNF5HCoqWHoaotMoQMpw
Like1Vote Down 5 years 10 months agoAuthorMark RejhonGreat stuff, the problem is the best I’ve been able to get out of YouTube is 120fps — any HFR videos uploaded are downconverted, and so one has to upload 120fps slo-mo videos to YouTube, and then select “2x” YouTube playback speed.
So a lot of the 480fps and 960fps information is lost by YouTube if you speed up the videos to realtime HFR rather than slo-mo HFR. So we have to rely on *.mp4 downloads for HFR videos, rather than YouTube which decimates the framerate of non-slo-mo HFR videos.
Do you have the original 480fps and 960fps video files on disk? Maybe share them to me, so I can take a look directly at them, to see what can be done for presentation (e.g. on existing 240Hz gaming monitors, and my experimental 480Hz monitor).
Like1Vote Down 5 years 10 months agoAuthorMark RejhonOngoing UltraHFR experiments in the forums:
https://forums.blurbusters.com/viewtopic.php?f=20&t=4071&p=32839#p32838
Also a thread on reduser.net:
http://www.reduser.net/forum/showthread.php?165183-Cinematography-of-2030s-Ultra-HFR!-I-have-witnessed-realtime-1000fps-on-real-1000Hz
Test 720p 240fps realtime video:
GOOD:
MPV: Plays 720p 240fps UltraHFR fine
Windows Media Player: Plays 720p 240fps UltraHFR fine
Google Chrome embedded player: Plays 720p 240fps UltraHFR fine
BAD:
VLC: Plays but microstutters too much
FireFox embedded player: Plays but microstutters too much
We tested 540p 480fps on the Zisworks 480Hz display and it works, but only MPV succeeded. None of the other players could properly play 480fps.
Like0Vote Down 5 years 10 months ago
Recent Content
TestUFO 2.0 Display Motion Test Gaining HDR Support, Public Beta Launch on January 18th, 2024 January 10, 2024
NanoSys Exhibiting New Color Ghosting Demo on TestUFO 2.0 Beta January 10, 2024
New Blur Busters Logo Program 2.2 for OLED, LCD & Video Processors January 5, 2024
NVIDIA Announces ULMB 2 — Improved Motion Blur Reduction May 29, 2023
Blur Busters Forums
TestUFO Motion Tests
The #1 Site of Everything Better Than 60Hz™
Search for:
Best Gaming Monitors
Official Monitor List
AdvertisementFeatured Content
GtG versus MPRT: Frequently Asked Questions About Pixel Response On Displays May 7, 2019
The Basics of Network Lag – with Battle(non)sense September 27, 2017
Motion Blur Reduction (ULMB, LightBoost, etc) April 29, 2018
Test Results: 4K 120 Hz Display with bonus 1080p 240 Hz & 540p 480 Hz Modes August 16, 2017
Blur Busters Law: The Amazing Journey To Future 1000Hz Displays December 15, 2020
Home
Forums
TestUFO
About
Privacy
© 2024 Blur Busters | Theme by
jor-folio.com
1000 HZ linux kernel necessary if I have tickless and high resolution timer? - Server Fault
1000 HZ linux kernel necessary if I have tickless and high resolution timer? - Server Fault
Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Loading…
Tour
Start here for a quick overview of the site
Help Center
Detailed answers to any questions you might have
Meta
Discuss the workings and policies of this site
About Us
Learn more about Stack Overflow the company, and our products
current community
Server Fault
help
chat
Meta Server Fault
your communities
Sign up or log in to customize your list.
more stack exchange communities
company blog
Log in
Sign up
Home
Questions
Tags
Users
Companies
Unanswered
Teams
Stack Overflow for Teams
– Start collaborating and sharing organizational knowledge.
Create a free Team
Why Teams?
Teams
Create free Team
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
1000 HZ linux kernel necessary if I have tickless and high resolution timer?
Ask Question
Asked
11 years, 11 months ago
Modified
7 years, 7 months ago
Viewed
19k times
14
I am trying to improve performance on my server. I have a few processes that need low jitter (less than 10ms variance).
I have a load average of 4 maximum on an i7-920 (4 physical cores, 8 with HT). There are about 10 processes ranging from 40% to 90% of a core user mode. System usage is 3% total. Total CPU usage is 80% max.
Will setting the kernel from 100hz to 1000hz improve the jitter if tickless and high resolution timers are already set?
This page seems to indicate it still does something. https://lkml.org/lkml/2009/4/28/401
How about changing from voluntary (PREEMPT_VOLUNTARY) to preemptible (PREEMPT)?
linuxlinux-kernel
Share
Improve this question
Follow
edited Apr 9, 2012 at 21:48
Bob
asked Apr 9, 2012 at 21:40
BobBob
19522 gold badges22 silver badges88 bronze badges
4
OS distribution details/version?
– ewwhite
Apr 9, 2012 at 21:44
Ubuntu 11.10 64bit server Linux 3.3 kernel.
– Bob
Apr 9, 2012 at 21:47
You have plenty of user mode load; system time is comparatively negligible. I wouldn't suggest to dance around kernel tunables there. Or obtaining realtime-like scheduling is what you hope to achive?
– yrk
Apr 10, 2012 at 8:40
So are you saying if the system usage is low, none of this makes a difference on responsiveness?
– Bob
Apr 10, 2012 at 20:21
Add a comment
|
3 Answers
3
Sorted by:
Reset to default
Highest score (default)
Date modified (newest first)
Date created (oldest first)
4
If low jitter is important to you, yes, you may want to use both 1000hz and PREEMPT.
If those processes are really time-sensitive, thought, you will probably need
some more realtime-oriented patches/kernels, or at least some process-level
scheduling parameters, like rtprio.
Typical uses are audio servers, see for example advice from jackaudio
Share
Improve this answer
Follow
answered Apr 11, 2012 at 16:43
koollmankoollman
13122 bronze badges
Add a comment
|
4
I am trying to improve performance on my server. I have a few processes that need low jitter (less than 10ms variance).
Any real time won't improve performance, it'd make the whole system running smoother but a bit slower, in fact. In other words, it's throughput vs. latency. If it's really what you need, then several options:
Use 300 Hz or even 1KHz, PREEMPT, and don't use tickless
Use nice, schedtool to assign proper priorities/classes according to your needs
Give a try to RT or BFS
Share
Improve this answer
Follow
answered Apr 11, 2012 at 16:54
poigepoige
9,51322 gold badges2626 silver badges5252 bronze badges
2
What's wrong with using tickless?
– Bob
Apr 11, 2012 at 22:19
1
@Bob, It's good for powersaving, but in case you care about latency, it's recommended to be off, for e. g. ck.kolivas.org/patches/bfs/bfs-configuration-faq.txt
– poige
Apr 12, 2012 at 1:16
Add a comment
|
3
1) Don't use tickless, it's still highly experimental and not recommended to anyone but developers working on it, it is also meant to help to powersave.
2) Fully preemtible system is supposed to increase responsiveness of desktor, while voluntary preemptible is for general use (mix of responsiveness and troughput).
If your server got SMP (multiple cores), you should probably go for non-preemptible, since most work will be executed on their cores and without interrupts, which generally 1) take time 2) trash cache
3) 1000Hz is desktop value which introduces overhead, but allows to for example play games and stuff. 300 hz is value that is recommended for video (so stuff can reschedule and you still won't miss frames), while 100Hz provides best troughput (though not geared for lowlatency network stuff).
If you want to go as stable as it gets (without using RT patches), you should go:
periodic ticks (stability)
non-preemptible (stability)
timer-frequency (up to you, 1000 for best responsiveness and low latiencies, 100 for best troughput but 10ms resolution on timer, e.g. stuff will run at least 10ms)
Hope this somewhat helps.
Share
Improve this answer
Follow
answered Nov 24, 2013 at 15:30
Tomas PruzinaTomas Pruzina
13133 bronze badges
Add a comment
|
You must log in to answer this question.
Not the answer you're looking for? Browse other questions tagged linuxlinux-kernel.
The Overflow Blog
How Stack Overflow is partnering with Google to encourage socially...
Featured on Meta
Our partnership with Google and commitment to socially responsible AI
Shifting the data dump schedule: A proposal
Visit chat
Related
0
High %system and %si cpu time on Linux
1
Need rpcsec_gss_krb5 and Linux kernel 2.6.35+ on EC2
0
ESXi :: vmxnet3 vNIC and Linux kernel errors
4
Linux Kernel and the init process
3
Linux high load with ImageMagick convert utility and server freezes (blktrack output attached)
0
Infiniband P_Keys and the Linux kernel
2
Why does my Linux Kernel have missing directories / files that are crucial for ip_tables to run?
0
Why do some servers have /etc/sysconfig/kernel and others do not?
Hot Network Questions
What is the etymology of “Israel”
Root incursion into a pipe under our house, I'm hoping there are bandaids because I can't afford the repair
Why is a filename surrounded by double quotes with single quotes around a character when displayed in terminal?
Are spacecraft visits to Uranus and Neptune hard to plan?
What game is this featured on the MSI Claw?
How to scale the weight of a RC model aircraft?
Is there some kind of law that even if data is legally compiled from public sources, it is illegal to collect too much and share it?
Are there languages L1 ⊆ L2 ⊆ L3 when L1 and L3 are NP-Complete languages and L2 ∈ P?
Lattice points visible from the origin
Scan input for numbers and add thousands separators
Would Lesser/Greater Restoration be able to cure a mental illness?
Does the official length of a movie include the credits?
SSH parameterized config entries?
Zero set of prime ideal
Strange comb spectrum found during EMI precompliance
Stealing when it is free?
Origin of the word "Tholian" in Star Trek
Is there another way to put an age limit to Congress members without making a constitutional amendment in the U.S.?
Why would a warrior tribe be dependant on a pacifist tribe?
Are there situations where a vertical bar chart is preferable to a horizontal one?
Why are bases corrosive?
Is it legal to sell emails?
Algebraic equation of a specific six-degree polynomial
Safe, easy way to tap into taut NM cable in wall?
more hot questions
Question feed
Subscribe to RSS
Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Server Fault
Tour
Help
Chat
Contact
Feedback
Company
Stack Overflow
Teams
Advertising
Collectives
Talent
About
Press
Legal
Privacy Policy
Terms of Service
Cookie Settings
Cookie Policy
Stack Exchange Network
Technology
Culture & recreation
Life & arts
Science
Professional
Business
API
Data
Blog
Site design / logo © 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2024.3.12.6097
【FPS手柄科普】玄学?智商税?1000Hz有没有用?3分钟带你了解手柄回报率_哔哩哔哩_bilibili
【FPS手柄科普】玄学?智商税?1000Hz有没有用?3分钟带你了解手柄回报率_哔哩哔哩_bilibili 首页番剧直播游戏中心会员购漫画赛事投稿【FPS手柄科普】玄学?智商税?1000Hz有没有用?3分钟带你了解手柄回报率
1.6万
9
2023-07-19 17:51:09
未经作者授权,禁止转载311976236墨将一直以玩家需求为已任,只要玩家有需求,我们就努力做
一个好的摇杆需要综合的指标,硬件只是参数之一,包括回报率和采样精度,还要有优秀的摇杆算法
一个好的产品也不单是摇杆为评判单项,致力打造国内优秀手柄,是我们国内厂商一起努力的目标游戏知识分享官科技数码超频射击游戏APEX英雄FPS手柄手柄回报率手柄采样精度ps51000Hz墨将彩虹2pro
墨将BIGBIG-WON官方账号
发消息
PLAY BIG . WON BIG.
关注 3.0万
AI女友太香了,边玩游戏边恋爱~
接下来播放
自动连播超频1000hz的ds5手柄远距离压枪是怎么样的草苺餡餃子
7393
0
【APEX手柄】手柄超频保姆级教学丨输入延迟?检测?轮询率?统统搞定!EMC-
4.2万
7
1000hz回报率太吃性能了吧!WallyGonzalez
2.5万
1
这就是dse原生1000hz给我的自信1nfpBlue
5917
0
深夜浅试一下手柄超频的手感叭Kazephyr4
9717
0
手柄超频第二天Kazephyr4
3021
0
DPI800,回报率500,垂直1,其它全部是调的30小晗游戏解说
3206
2
【包】2023年了 4K鼠标有必要了吗?Bread包包
4.7万
56
【APEX】当我把鼠标回报率调到8000hz会怎样?-卡冈都亚-
1.9万
4
1000hz回报率的手柄,你见过吗刘玥于净又卫生
937
1
致动o+与墨将彩虹2pro到底谁更适合打apex,回报率造假风波下到底选择谁更合适?佘林SL
2.2万
6
我现在才知道1000鼠标回报率有多吃性能!MockingBird1216
24.9万
48
全方向TS!禁用steam输入的新方法,ps手柄可用,不会降低手柄回报率Iris_dantalion
4.7万
1
(APEX)原来鼠标125hz回报率跟1000回报率差距这么大?VVVZQ
3.8万
2
实测键盘回报率与输入延迟的关系:125,250,500,1000Hz USB vs PS2_问天_
3.8万
8
300起步的手柄打Apex能锁住吗?快乐滋崩在这里
15.6万
54
如何进行手柄超频,首个手柄超频教学!!Gu5enPai
4.9万
9
dualsense edge 纯纯垃圾手柄Yujraaa
2.2万
11
关于手柄回报率的个人观点-搬运测评看空间新视频鹿鸣浅夏_Official
2537
3
4000赫兹回报率能带来提升吗?带带稚宝
1.3万
4
展开
小窗
客服
顶部
赛事库 课堂 2021
赫兹到每秒帧数转换表:赫兹到每秒帧数(Hz到FPS)计算器
赫兹到每秒帧数转换表:赫兹到每秒帧数(Hz到FPS)计算器
CitizenMaths
频率
亮度
体积
力量
力量
加速
化学用量
区域
压力
发光强度
密度
扭矩
数据存储
时间
流
温度
照度
燃油经济性(里程)
电位
电流
电荷
能量、功和热
角度
货币
质量流量
资料传输率
速度
重量和质量
长度
面积密度
频率
简体中文
English
Deutsch
Nederlands
Français
Español
Italiano
Português (PT)
Norsk
Suomi
Svenska
Dansk
Čeština
Magyar
Română
日本語
简体中文
繁體中文
Polski
Ελληνικά
Русский
Türkçe
Български
العربية
한국어
עברית
Latviski
Українська
Bahasa Indonesia
ภาษาไทย
Eesti
Hrvatski
Lietuvių
Slovenčina
Srpski
Slovenščina
Tiếng Việt
Íslenska
从赫兹到每秒帧数的转换
从
赫兹
兆赫
分赫兹
十赫兹
千兆赫兹
千赫
厘赫兹
太赫兹
太赫兹
度每秒
微赫兹
每分钟动作
每分钟度数
每分钟弧度
每分钟循环
每分钟转数
每天循环
每小时度数
每小时弧度
每小时循环
每年周期
每微秒周期
每月周期
每毫秒周期
每毫秒度数
每毫秒弧度
每皮秒周期
每秒周期
每秒帧数
每秒弧度
每纳秒周期
毫赫兹
泽塔赫兹
泽普赫兹
皮赫兹
约塔赫兹
约赫兹
纳赫兹
艾赫兹
菲涅尔
赫兹
赫兹
阿托赫兹
飞赫兹
至
每秒帧数
兆赫
分赫兹
十赫兹
千兆赫兹
千赫
厘赫兹
太赫兹
太赫兹
度每秒
微赫兹
每分钟动作
每分钟度数
每分钟弧度
每分钟循环
每分钟转数
每天循环
每小时度数
每小时弧度
每小时循环
每年周期
每微秒周期
每月周期
每毫秒周期
每毫秒度数
每毫秒弧度
每皮秒周期
每秒周期
每秒帧数
每秒弧度
每纳秒周期
毫赫兹
泽塔赫兹
泽普赫兹
皮赫兹
约塔赫兹
约赫兹
纳赫兹
艾赫兹
菲涅尔
赫兹
赫兹
阿托赫兹
飞赫兹
兑换
公式 1295 Hz = 1295 / 1 FPS = 1295.0 FPS
每秒帧数 to 赫兹
如何从赫兹转换为每秒帧数
1 赫兹 相当于 1 每秒帧数:
1 Hz = 1 FPS
例如, 如果赫兹的数字为(600),则其等效的每秒帧数的数字为(600).
公式:
600 Hz = 600 / 1 FPS = 600 FPS
从赫兹到每秒帧数的转换表
赫兹 (Hz)
每秒帧数 (FPS)
1 Hz
1 FPS
2 Hz
2 FPS
3 Hz
3 FPS
4 Hz
4 FPS
5 Hz
5 FPS
6 Hz
6 FPS
7 Hz
7 FPS
8 Hz
8 FPS
9 Hz
9 FPS
10 Hz
10 FPS
11 Hz
11 FPS
12 Hz
12 FPS
13 Hz
13 FPS
14 Hz
14 FPS
15 Hz
15 FPS
16 Hz
16 FPS
17 Hz
17 FPS
18 Hz
18 FPS
19 Hz
19 FPS
20 Hz
20 FPS
21 Hz
21 FPS
22 Hz
22 FPS
23 Hz
23 FPS
24 Hz
24 FPS
25 Hz
25 FPS
26 Hz
26 FPS
27 Hz
27 FPS
28 Hz
28 FPS
29 Hz
29 FPS
30 Hz
30 FPS
31 Hz
31 FPS
32 Hz
32 FPS
33 Hz
33 FPS
34 Hz
34 FPS
35 Hz
35 FPS
36 Hz
36 FPS
37 Hz
37 FPS
38 Hz
38 FPS
39 Hz
39 FPS
40 Hz
40 FPS
41 Hz
41 FPS
42 Hz
42 FPS
43 Hz
43 FPS
44 Hz
44 FPS
45 Hz
45 FPS
46 Hz
46 FPS
47 Hz
47 FPS
48 Hz
48 FPS
49 Hz
49 FPS
50 Hz
50 FPS
51 Hz
51 FPS
52 Hz
52 FPS
53 Hz
53 FPS
54 Hz
54 FPS
55 Hz
55 FPS
56 Hz
56 FPS
57 Hz
57 FPS
58 Hz
58 FPS
59 Hz
59 FPS
60 Hz
60 FPS
61 Hz
61 FPS
62 Hz
62 FPS
63 Hz
63 FPS
64 Hz
64 FPS
65 Hz
65 FPS
66 Hz
66 FPS
67 Hz
67 FPS
68 Hz
68 FPS
69 Hz
69 FPS
70 Hz
70 FPS
71 Hz
71 FPS
72 Hz
72 FPS
73 Hz
73 FPS
74 Hz
74 FPS
75 Hz
75 FPS
76 Hz
76 FPS
77 Hz
77 FPS
78 Hz
78 FPS
79 Hz
79 FPS
80 Hz
80 FPS
81 Hz
81 FPS
82 Hz
82 FPS
83 Hz
83 FPS
84 Hz
84 FPS
85 Hz
85 FPS
86 Hz
86 FPS
87 Hz
87 FPS
88 Hz
88 FPS
89 Hz
89 FPS
90 Hz
90 FPS
91 Hz
91 FPS
92 Hz
92 FPS
93 Hz
93 FPS
94 Hz
94 FPS
95 Hz
95 FPS
96 Hz
96 FPS
97 Hz
97 FPS
98 Hz
98 FPS
99 Hz
99 FPS
100 Hz
100 FPS
200 Hz
200 FPS
300 Hz
300 FPS
400 Hz
400 FPS
500 Hz
500 FPS
600 Hz
600 FPS
700 Hz
700 FPS
800 Hz
800 FPS
900 Hz
900 FPS
1000 Hz
1000 FPS
1100 Hz
1100 FPS
赫兹转换为不同的单位
赫兹 to 兆赫
赫兹 to 分赫兹
赫兹 to 十赫兹
赫兹 to 千兆赫兹
赫兹 to 千赫
赫兹 to 厘赫兹
赫兹 to 太赫兹
赫兹 to 太赫兹
赫兹 to 度每秒
赫兹 to 微赫兹
赫兹 to 每分钟动作
赫兹 to 每分钟度数
赫兹 to 每分钟弧度
赫兹 to 每分钟循环
赫兹 to 每分钟转数
赫兹 to 每天循环
赫兹 to 每小时度数
赫兹 to 每小时弧度
赫兹 to 每小时循环
赫兹 to 每年周期
赫兹 to 每微秒周期
赫兹 to 每月周期
赫兹 to 每毫秒周期
赫兹 to 每毫秒度数
赫兹 to 每毫秒弧度
赫兹 to 每皮秒周期
赫兹 to 每秒周期
赫兹 to 每秒弧度
赫兹 to 每纳秒周期
赫兹 to 毫赫兹
赫兹 to 泽塔赫兹
赫兹 to 泽普赫兹
赫兹 to 皮赫兹
赫兹 to 约塔赫兹
赫兹 to 约赫兹
赫兹 to 纳赫兹
赫兹 to 艾赫兹
赫兹 to 菲涅尔
赫兹 to 赫兹
赫兹 to 阿托赫兹
赫兹 to 飞赫兹
家
频率
赫兹
Hz 至 FPS
版权 © UnitConverter 阅读我们的 使用条款 和 隐私政策
鼠标的技术参数:125HZ、1000HZ 和 1800dpi、3500dpi 分别是描述什么特性的?有什么参考价值? - 知乎
鼠标的技术参数:125HZ、1000HZ 和 1800dpi、3500dpi 分别是描述什么特性的?有什么参考价值? - 知乎首页知乎知学堂发现等你来答切换模式登录/注册鼠标鼠标的技术参数:125HZ、1000HZ 和 1800dpi、3500dpi 分别是描述什么特性的?有什么参考价值?关注者7被浏览89,403关注问题写回答邀请回答好问题添加评论分享3 个回答默认排序知乎用户游戏鼠标推荐前瞻篇:一些我们选购时需要考虑的技术参数 由 土老逼 发表在·游戏区 https://bbs.hupu.com/game大家好,这里是破废玩家一年N++次次次的游戏外设推荐时间啦,因为这次选购推荐是来自虎扑游戏区的大佬旧城的邀请。因此我们这次选购推荐也会从游戏角度出发,分别为FPS类游戏和MOBA类游戏推荐各自适合的外设产品。本篇是一个前瞻篇,主要目的是给大家讲解一下我们常见的游戏鼠标的参数含义和术语,目的仍然是让大家在阅读之后做到心里有谱,不仅仅知道知道我们推荐的哪些鼠标,同时也能知道我们为什么会推荐这些鼠标。同时也欢迎大家阅读我们之前的选购思路文:理清思路,如何选择一款适合自己的游戏鼠标?第一部分:常见的技术参数首先就是我们常见的技术参数啦,网上大部分鼠标在销售介绍页面都会清晰的标明自己的传感器参数,比如CPI和IPS这些技术缩写。因此我们需要知道光学鼠标基础的工作原理:光学鼠标的传感器可以理解成一个微型的相机镜头,通过高速拍照对比分析从而计算出鼠标在桌面的移动方向和距离等信息。接下来,就让我们就来了解一下这些参数分别代表什么意思,以及是如何影响我们的游戏性能。灵敏度(DPI/CPI):DPI英文全称是“dots per inch”,翻译为“每英寸像素”,意思是每英寸的像素数。(1 英寸=2.54cm),是指鼠标内的解码装置所能辨认每英寸长度内像素数。换言之就是:我们用了一款最大DPI为18000的旗舰级别游戏鼠标,那么鼠标在鼠标垫上每移动一英寸,鼠标指针便会在屏幕上移动18000个像素点。这也是为什么在1080P和4K显示器上使用同样的DPI鼠标,却会感觉到鼠标的移动速度有差别。而除了DPI之外,我们也可以经常看见一些鼠标品牌会使用CPI来描述传感器的参数,并且看起来和DPI并没有多大差别。其实CPI的英文全称是“count per inch”,翻译为“每英寸的测量次数”,指的是鼠标在物理表面上每移动1英寸(约2.54厘米)时其传感器所能接收到的坐标数量。两者的区别主要在于一个是以静态为标准计算,一个是以动态为标准计算。所以其实本质上两者仅仅是说法上的不同,在中文中都可以简单的称之为灵敏度。同时我们在选购产品的时候也都能发现,目前主流鼠标产品的最大DPI/CPI值早已远远超过我们日常使用的设置值。因此,目前鼠标宣传的最大DPI和CPI值更多是厂商对鼠标传感器级别的展示,并不是我们选购鼠标首先要考虑的刚性需求。追踪速度(IPS):IPS的英文全称是Inches Per Second,直译为每秒移动的最大英寸数。通常指的是光学鼠标传感器的最大的识别速度值。如果玩家移动鼠标的速度超过这个速度,传感器将不能识别,同时屏幕上的指针可能是跳一下,或者直接从屏幕一段飞到另一端,也就是大家常说的“跳帧”。通常情况下如今的大部分游戏鼠标即使是入门游戏鼠标的IPS值也能达到150以上,旗舰级别游戏鼠标的IPS值则普遍在400以上。同时根据原相官网与其他社区的一些相关资料可以得知:我们正常在使用鼠标的时候瞬时IPS速度在50左右,即使是职业的FPS选手在大范围甩拉瞄准时的瞬时爆发IPS往往也不会超过150。因此IPS这个参数对于大部分玩家来说也同样是一个性能相对溢出的参数。加速度值(G)鼠标加速度值指的是鼠标由慢到突然加速,然后后又慢下来的过程。整体行动过程类似于物理移动中的加速度现象。加速度是矢量的形式,即同时有数值大小与方向变化的物理量,因此加速度值的单位为G,鼠标的G值就是鼠标每秒之间移动速度变化不能超过的单位值。目前市面上的游戏鼠标加速度大多在20G-50G之间,已经能够很好的满足玩家的日常游戏需求,当然如果同样价位,选G值大一些的产品总归是不亏。响应回报速度鼠标响应速度又称报告率,是指每秒钟鼠标传送数据给计算机的次数。例如:响应500Hz即表示在一秒钟之内鼠标向计算机传送了500次数据;通常情况下次数越多则鼠标光标的移动越细腻滑顺,点击也更为精准。目前大多数主流游戏均能够支持1000hz的报告率,当然少数古代游戏如CF无法做到支持1000hz,因此专业游戏鼠标仍然可以自由切换报告率的同时响应速度均能达到1000HZ(不过也有一些高端千元鼠标只能达到500HZ的),同时大多数蓝牙鼠标则无法达到一个很好的响应速度,这也是为什么蓝牙技术往往可以用在不需要记录轨迹的机械键盘上,却无法使用在高性能游戏鼠标上的原因。灵敏度、追踪速度、加速度值与响应速度在一起被称为游戏鼠标引擎的四大参数指标。其实在如今大多数正规品牌的游戏鼠标的这些参数已经性能大幅度溢出,并不会影响我们日常的使用。不过通过对比这些参数也能够初步判断出一款鼠标引擎的级别与档次,换言之:这些参数本身并不重要,但却是我们选购鼠标时候的重要参考信息。第二部分:抖动、修正1:1追踪:1:1追踪也是我们经常见到的一些高端游戏鼠标的主打卖点,“1:1追踪在电子竞技中尤为重要,可以理解为减少鼠标移动过程中的抖动问题,并且在修正抖动算法作用下,保持鼠标的高速响应。我们可以看到很多不同类型游戏的职业选手会有“打桩”等重复性的训练,是为了训练大脑对某些特定动作做出下意识反应和肌肉记忆,而在这种操作中任何细微的偏差都会影响肌肉记忆的准确度。而1:1追踪的性能则可以对任何不准确的动作进行修正,无论是平滑修正还是直线修正都准确无误。对于职业选手来说,这种稳定的竞技性能也更适合训练肌肉记忆,把日常训练的效果更好地运用在竞技赛场上;而对于普通玩家来说,不仅能有更稳定的游戏操纵体验,而且能更畅快的投入游戏。”其实严格来说只要是光学设备都有偏差值造成的抖动,因此没有产品可以完全达到1:1追踪,所以厂商们所说的“1:1追踪”通常指的是将抖动控制在一个极小的正负偏差范围之内,无限接近1:1。(某型号鼠标追踪抖动实际测试值)直线修正与1:1追踪一同出现的往往还有另外一个名词:“直线修正”。直线修正是指通过软件算法的手段对鼠标移动过程中的抖动进行修正,通俗的说就是能让我们画的线更直,画的圆更圆。这个功能在各种办公鼠标当中大量运用,在画图做表等场景中可以起到良好的辅助作用。而在游戏鼠标中,直线修正往往就非常致命且多余,尤其是在一些FPS竞技类游戏中,会让我们的瞄准出现偏差。因此选购FPS游戏鼠标,一定要注意选择不带直线修正的产品。鼠标LODLOD即为鼠标的响应高度,为鼠标抬起多少高度以后传感器停止响应定的数值,鼠标LOD高度对于一些有抬鼠习惯的玩家来说比较重要。在早年间大部分光学引擎的LOD值都是固定的,后来的一些鼠标则能通过定制透镜来等一些手段改变引擎响应高度。近两年则出现了可以调节LOD高度的鼠标产品,而最新的顶级游戏鼠标引擎则已经发展出了非对称终止技术,即可以分别设置鼠标抬起和放下时的LOD高度,从而在抬起鼠标时保留一定工作高度避免传感器降速,再放下鼠标时则不让鼠标过早进入工作区域,避免对焦造成的抖动。第三部分:重量、尺寸、连接方式等常见参数相较于之前的一些硬件参数,鼠标的重量、尺寸、外形等相对更加主观,更多的取决于玩家主观的使用体验以及握持习惯、手掌大小,鼠标外形等等,因此这里就不过多赘述。这里放一张初筛表,更多的外型选购的思路和内容大家可以阅读之前的文章:理清思路,如何选择一款适合自己的游戏鼠标?好了,以上就是一些鼠标参数名词的解释和解读,本期相对有些枯燥乏味,主要还是科普为主,给大家分享一些鼠标选购中需要注意的参数信息。对于破废玩家而言,我们更希望让大家懂产品,能够和我们一样阅读出产品设计中的思路和亮点。接下来的后续部分则会更加简单直接的给大家推荐适合FPS和MOBA的外设产品,还请大家多多关注支持我们哟。发布于 2021-01-29 10:33赞同 723 条评论分享收藏喜欢收起庄明浩(rosicky311)2020 年度新知答主 关注 HZ那个 是相应频率 其实这个东西和你显示器的频率也有关系~现在一般好一些的鼠标 驱动里都支持125-1000HZ的调节DPI楼上的哥们已经说了 1800DPI是蝰蛇老版本的DPI 3500是新版的 具体介绍看这里:http://www.pcwaishe.cn/viewthread.php?tid=7569&highlight=DPI关于鼠标的DPI,扫描频率,像素处理能力 以及 USB报告率的一些知识专业文档 如果你需要的话~ 发布于 2011-03-14 09:29赞同 11添加评论分享收藏喜欢收起
csv - How can I increase the frequency rate of my Python programme in VSCode? Input: GSV2 Measuring amplifier 1000Hz. Realtime - Stack Overflow
csv - How can I increase the frequency rate of my Python programme in VSCode? Input: GSV2 Measuring amplifier 1000Hz. Realtime - Stack Overflow
Stack Overflow
About
Products
For Teams
Stack Overflow
Public questions & answers
Stack Overflow for Teams
Where developers & technologists share private knowledge with coworkers
Talent
Build your employer brand
Advertising
Reach developers & technologists worldwide
Labs
The future of collective knowledge sharing
About the company
Loading…
current community
Stack Overflow
help
chat
Meta Stack Overflow
your communities
Sign up or log in to customize your list.
more stack exchange communities
company blog
Log in
Sign up
Home
Questions
Tags
Users
Companies
Labs
Discussions
New
Collectives
Explore Collectives
Teams
Stack Overflow for Teams
– Start collaborating and sharing organizational knowledge.
Create a free Team
Why Teams?
Teams
Create free Team
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Get early access and see previews of new features.
Learn more about Labs
How can I increase the frequency rate of my Python programme in VSCode? Input: GSV2 Measuring amplifier 1000Hz. Realtime
Ask Question
Asked
1 year ago
Modified
1 year ago
Viewed
16 times
0
I have written a code in Python that should read a Measuring amplifier value with 1000Hz and save it with the current time in a CSV file. However, only a maximum of around 100Hz is achieved. Although the sensor/Measuring amplifier actually sends 1000Hz. Reducing the data frequency from the measuring amplifier works perfectly. Increasing it also only works up to 100Hz. Is there a way to save the 1000 measurement data per second in my CSV? Or to process it in real time in Python?
PS: Baud rate is high enough
Datasheet Measuring amplifier
import serial
import csv
import time
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as FuncAnimation
def gsvStart():
serialConnection.write(b'\x24')
def gsvStop():
serialConnection.write(b'\x23')
def gsvSetZero():
serialConnection.write(b'\x0C')
def gsvWriteSamplingRate():
serialConnection.write(b'\x8A')
# 8000 Samples per Second / 8 -- Manual Page 44
def gsvWriteSamplingRate8000():
serialConnection.write(b'\x8A\x08\xFD\xF8')
# 9765 Samples per Second / 8
def gsvWriteSamplingRate9765():
serialConnection.write(b'\x8A08FE00')
def convertMeasFrameToMeasValue(MeasFrame):
return ((MeasFrame[0] * 256 + MeasFrame[1])-32768)/32768
#Moving Average
readings=[]
max_samples=10
def mean(nums):
return float(sum(nums)) / max (len(nums), 1)
#create a csv file
now = datetime.now()
filename = now.strftime("%d-%b-%Y-%H_%M_%S")
fname = lambda : "{}.csv".format(filename)
fieldnames = ["Zeit", "Kraft ungefiltert", "Kraft AVG 0,2s"]
with open(fname(), 'w', newline='') as csv_file:
csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
csv_writer.writeheader()
if __name__ == '__main__':
serialConnection = serial.Serial("COM3", 38400, timeout=1)
serialConnection.isOpen()
gsvStop()
serialConnection.write(b'\x25')
serialConnection.flushInput()
serialConnection.flushOutput()
serialConnection.write(b'\x8A')
serialConnection.write(b'\x08\xFD\x8F')
serialConnection.write(b'\x8B')
serialConnection.write(b'\x83')
SRregcontent = serialConnection.read(2)
print("SR: ", SRregcontent)
gsvStart()
for i in range(10):
praefix = serialConnection.read(1)
if praefix == 0xA5.to_bytes(1, byteorder='big'):
MeasVal = serialConnection.read(2) # .hex()
print(convertMeasFrameToMeasValue(MeasVal))
gsvSetZero()
try:
while 1:
praefix = serialConnection.read(1)
if praefix == 0xA5.to_bytes(1, byteorder='big'):
MeasVal = serialConnection.read(2) # .hex()
#Scale in [N]
wert=999.101*convertMeasFrameToMeasValue(MeasVal)
#Moving Average
readings.append(wert)
avg = mean(readings)
if len(readings) == max_samples:
readings.pop(0)
#Time
now = datetime.now()
current_time = now.strftime("%H:%M:%S:%f")
#In Csv
with open(fname(), 'a', newline='') as csv_file:
csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
info = {
"Zeit": current_time,
"Kraft ungefiltert": wert,
"Kraft AVG 0,2s": avg
}
csv_writer.writerow(info)
except:
pass
serialConnection.close()```
Frequency reduced works.
Even if I only output the time 1000 times in another programme, I reach a maximum of 300Hz (without measuring amplifier input).
csvfrequency
Share
Improve this question
Follow
asked Mar 10, 2023 at 9:27
TinoTino
1
Add a comment
|
Related questions
315
How to skip the headers when processing a csv file using Python?
116
How can I compute a histogram (frequency table) for a single Series?
2
How can you get the sample rate frequency of the iphone accelerometer?
Related questions
315
How to skip the headers when processing a csv file using Python?
116
How can I compute a histogram (frequency table) for a single Series?
2
How can you get the sample rate frequency of the iphone accelerometer?
0
How to get the frequency of the input from mic
2
Pharo: How to increase MouseMoveEvent Frequency?
1
How can i extract the frequency from WAV file - python
0
How can I select a frequency if the frequency range is given?
1
Python-3.x Count the frequency of a specific number from user input
1
how can I find the frequency?
Load 6 more related questions
Show fewer related questions
0
Sorted by:
Reset to default
Highest score (default)
Trending (recent votes count more)
Date modified (newest first)
Date created (oldest first)
Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.
Your Answer
Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more
Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.
Draft saved
Draft discarded
Sign up or log in
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Submit
Post as a guest
Name
Required, but never shown
Post as a guest
Name
Required, but never shown
Post Your Answer
Discard
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Browse other questions tagged csvfrequency or ask your own question.
The Overflow Blog
How Stack Overflow is partnering with Google to encourage socially...
Featured on Meta
Our partnership with Google and commitment to socially responsible AI
Shifting the data dump schedule: A proposal
Temporary policy: Generative AI (e.g., ChatGPT) is banned
2024 Community Moderator Election Results
Hot Network Questions
Is it legal to sell emails?
Scan input for numbers and add thousands separators
What's the biggest hurdle that prevents the EPA from implementing stricter limits on particulate matter?
Showing inequality involving log
Would Lesser/Greater Restoration be able to cure a mental illness?
Who pays for the damages caused by the government attempting to enforce a preempted or unconstitutional law?
Regular expression to match a concatenation of fixed strings, and alternative expressions
Command for Multiplying Integers
String.join() vs. .toString() in Apex
What are Christian guidelines for making the transition from "knowing about God" to "knowing God"?
Chee Ops stations
Safe, easy way to tap into taut NM cable in wall?
Is linear regression still relevant in a mid-level DS interview?
What is the origin of the simulacrum spell?
How many hours spending learning a day
Proving the Value of a Unique Infinitely Nested Radical
Proving formula for feedback for operational amplifiers
Cut folder names out of string
Is utilizing a singleton for a cache an antipattern?
Why is a filename surrounded by double quotes with single quotes around a character when displayed in terminal?
Lattice points visible from the origin
Are there languages L1 ⊆ L2 ⊆ L3 when L1 and L3 are NP-Complete languages and L2 ∈ P?
PTIJ: Why get drunk specifically in bed?
Linking quaver and semiquaver beams over a rest with LilyPond
more hot questions
Question feed
Subscribe to RSS
Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Stack Overflow
Questions
Help
Products
Teams
Advertising
Collectives
Talent
Company
About
Press
Work Here
Legal
Privacy Policy
Terms of Service
Contact Us
Cookie Settings
Cookie Policy
Stack Exchange Network
Technology
Culture & recreation
Life & arts
Science
Professional
Business
API
Data
Blog
Site design / logo © 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2024.3.12.6097
从光电算法到1000Hz回报率:北通宙斯pro 游戏手柄的独特之处 - 知乎
从光电算法到1000Hz回报率:北通宙斯pro 游戏手柄的独特之处 - 知乎切换模式写文章登录/注册从光电算法到1000Hz回报率:北通宙斯pro 游戏手柄的独特之处时光之光专注数码产品评测与体验/商业影像图像处理从业者/人像摄影师引入最近拿到了一款新手柄,北通宙斯pro
游戏手柄——作为北通宙斯系列的旗舰手柄,这款产品的升级可谓不小。这次的升级中,最引人注目的一项就是首创的光电算法。通过对优秀手柄性能的深入探索,它为玩家提供了卓越的游戏体验。北通这次采用了顶配的1000Hz超频摇杆,此外,真六轴体感技术结合3.0算法校准,这款手柄的升级可谓是前所未有的,为游戏爱好者提供了更加出色的游戏体验。开箱宙斯Pro的包装延续了北通一贯的设计风格,外包装是坚固的硬纸盒,正面印有宙斯Pro的渲染图案,LOGO和Slogan。打开后,手柄。附件方面,随机器附赠了无线接收器、数据线以及说明书和保修卡。但是并没有配备替换用的摇杆帽与按钮,这表明它的定位应该介于宙斯和宙斯2之间,填补了中高端价位的产品。外观宙斯Pro采用了深灰色的整体设计,北通的LOGO采用了RGB灯光,以及握把两侧的小型灯带,造型简洁,不会过于炫目。背部的上半部分包括Profile配置文件、手柄电源开关、体感开关以及四个背部按键。面壳采用了PC材质,在光线下呈现出略带金属质感的光泽。整体风格延续了宙斯系列的未来机械风,硬朗的外观给人一种强烈的竞技感。摇杆宙斯Pro在众多升级中,采用了霍尔摇杆,这可以说是硬件升级的重要部分。宙斯Pro的摇杆分辨率基本都在2000级以上。同时,北通游戏厅更新后,集成了手柄测试软件,但目前仅对宙斯Pro开放,期待后续可以支持更多北通甚至其他品牌的手柄测试。宙斯Pro采用了主流的控银JH16霍尔摇杆方案,并在侧面定制了北通的LOGO。宙斯Pro的摇杆在超频模式下,有线连接的回报率达到惊人的1000Hz,摇杆分辨率达到2000级。按键宙斯Pro的XYAB四个按键键帽采用了黑透的制作工艺,这半透明的键帽真的很吸引人。此外,XYAB按键还支持位置更换。当你拆开面壳后,可以轻松地调换XYAB按键的位置。进一步拆解手柄,你会看到宙斯Pro采用了机械按键、导电胶和按键帽多段式结构组合,官方宣传显示按键的按压力度为60g,实际使用时确实触感非常轻快,触发速度很快。与宙斯2的50g按压力度相比,你可以感受到差异,但整体差距并不大。扳机霍尔扳机采用电磁感应技术,实现了扳机行程的信号输出,消除了绝大部分扳机所带来的摩擦力。由于这种纯电子工作原理,霍尔扳机提供了非常顺滑的操作手感。宙斯Pro在扳机和肩键方面也进行了改进。手柄表面的北通纹理设计使得手指与手柄之间的摩擦力得到有效增加,不容易滑动,而且扳机末端微微上翘,使整体手感更加舒适。实测宙斯Pro搭载了北通自家研发的真六轴体感+
3.0算法,具备非常高的灵敏度。此外,这套自家研发的体感算法还通过软件升级,实现了体感与右摇杆的映射不会发生冲突。这是之前北通手柄系列一直被批评的问题,而现在希望这一功能可以在未来的固件升级中应用到其他系列手柄上。在Switch上的体验几乎没有延迟,同时体感的精度也非常高,几乎可以媲美原厂的水准。作为一个多平台手柄,宙斯Pro自然适用于Switch。在Switch上,大多数游戏需要使用体感功能进行操作。至于电池,宙斯Pro搭载了一颗1000毫安时的电池。由于整体RGB灯光的节制,充满电后,你完全可以高强度游戏两天而无需担心电池耗尽。总结总的来说,宙斯Pro提供了一种非常独特的游戏体验。特别是在霍尔摇杆、最高1000Hz回报率、霍尔扳机和机械按键等方面,这款手柄表现出了极高的操作灵敏度。通过科学的调教,它成功地达到了速度、准确性和适应性的平衡点。无论是玩动作、FPS还是赛车游戏,都能够显著提升响应速度,并且实现更加精细化的操控。可以说,宙斯Pro将电竞的理念融入了其中,尽管需要玩家们花一些时间来适应,但这种游戏体验是独一无二的。发布于 2023-10-20 22:29・IP 属地广东游戏手柄游戏电竞选手赞同添加评论分享喜欢收藏申请
FreeRTOS教程1 基础知识 - OSnotes - 博客园
FreeRTOS教程1 基础知识 - OSnotes - 博客园
会员
周边
新闻
博问
AI培训
云市场
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式 ...
退出登录
注册
登录
lc-guo
博客园
首页
新随笔
联系
订阅
管理
FreeRTOS教程1 基础知识
了解 FreeRTOS 相关知识,并熟悉使用 STM32CubeMX 软件配置 FreeRTOS 工程的流程
1、准备材料
正点原子stm32f407探索者开发板V2.4
STM32CubeMX软件(Version 6.10.0)
Keil µVision5 IDE(MDK-Arm)
野火DAP仿真器
2、学习目标
了解 FreeRTOS 相关知识,并熟悉使用 STM32CubeMX 软件配置 FreeRTOS 工程的流程
3、前提知识
读者须知:本系列教程中关于 FreeRTOS 的学习重点为应用,不会剖析源码内容,利用 STM32CubeMX 软件生成的 FreeRTOS 工程源代码中一般不会直接调用 FreeRTOS 的 API 函数,而是调用了 CMSIS-RTOS 封装好的上层API函数,但此系列教程主要介绍属于 FreeRTOS 的各类 API 函数及其应用,对于 CMSIS-RTOS 的 API 函数仅简单描述,读者需自行理解,另外对于常见硬件原理不再详细说明,感兴趣读者可阅读笔者的 “STM32CubeMX+STM32F4系列教程”
3.1、FreeRTOS简介
FreeRTOS是一个完全免费且开源的嵌入式实时操作系统(Real-Time Operating System,简称RTOS) ,其一般将任务称为线程,以下列表为FreeRTOS的一些特点,笔者认为学习FreeRTOS的应用正是掌握和理解下列各个特性
抢占式(pre-emptive)或合作式(co-operative)任务调度方式
非常灵活的优先级管理
灵活、快速且轻量化的任务通知机制(task notification)
消息队列(Queue)
二值信号量(Binary Semaphores)
计数信号量(Counting Semaphores)
互斥量(Mutex)
递归互斥量(Recursive Mutex)
软件定时器(Timers)
事件组(Events)
时间节拍钩子函数
空闲任务钩子函数
栈溢出检测
任务运行时间统计收集
完整的中断嵌套模型
用于低功耗的无节拍(Tickless)特性
RTOS主要应用于对实时性有要求的嵌入式系统,所谓实时性就是任务完成的时间是确定的,实时性又分为软实时和硬实时
软实时指任务完成时间是确定的,但是如果任务超时了也不会对整个系统产生破坏性影响;硬实时是指任务完成时间是确定的,但是如果任务超时未完成则会对整个系统产生灾难性影响,基于FreeRTOS开发的系统可以完成硬实时的要求
3.2、源码函数命名规律
FreeRTOS源码中函数命名规律:FreeRTOS源码中各个函数并非随机命名,而是有规律的命名,这样方便使用者看到名字就能获得该函数更多的信息,其函数名一般由 ① 函数返回值类型简写,② 函数所在文件 和 ③ 函数作用名称这三部分组成
① 函数返回值类型简写主要有:
'u'表示'unsigned'
'c'表示'char'
's'表示'int16_t(short)'
'l'表示'int32_t(long)'
'p'表示指针类型变量
'x'表示'BaseType_t'结构体和其他非标准类型的变量名
'uc'表示'UBaseType_t'结构体
'v'表示'void'
'prv'表示私有函数无返回值
这些简写可以自由组合在一起,例如 'pc' 表示 'char *' 类型,'uc' 表示 'unsigned char' 类型
② 函数所在文件:
'CoRoutine'表示该函数定义在'coroutine.c'文件中的
'EventGroup'表示该函数定义在'event_groups.c'文件中的
'List'表示该函数定义在'list.c'文件中的
'Queue'表示该函数定义在'queue.c'文件中的
'StreamBuffer'表示该函数定义在'stream_buffer.c'文件中的
'Task'表示该函数定义在'tasks.c'文件中的
'Timer'表示该函数定义在'timers.c'文件中的
'Port'表示该函数定义在'port.c'或'heap_x.c'文件中的
举几个例子:
xTaskCreate 表示函数返回值为 BaseType_t 结构体类型,函数被定义在 'tasks.c' 文件中,函数作用为“创建”
vTaskSuspend 表示函数返回值为 void 类型,函数被定义在 'tasks.c' 文件中,函数作用为“挂起”
prvTaskIsTaskSuspended 表示该函数为私有函数,仅能在 'tasks.c' 文件中使用,函数作用为“判断任务是否被挂起”
4、动手创建一个FreeRTOS空工程
4.1、CubeMX相关配置
4.1.1、工程基本配置
打开STM32CubeMX软件,单击ACCESS TO MCU SELECTOR选择开发板MCU(选择你使用开发板的主控MCU型号),选中MCU型号后单击页面右上角Start Project开始工程,具体如下图所示
开始工程之后在配置主页面System Core/RCC中配置HSE/LSE晶振,在System Core/SYS中配置Debug模式,因为系统滴答定时器SysTick要被FreeRTOS所使用,所以需要配置HAL库的时基源为除系统滴答定时器SysTick外的选项,笔者这里选择了基本定时器TIM6,这两个时基源均为1ms,具体配置如下图所示
4.1.2、时钟树配置
系统时钟使用8MHz外部高速时钟HSE,HCLK、PCLK1和PCLK2均设置为STM32F407能达到的最高时钟频率,具体如下图所示
4.1.3、外设参数配置
单击Pinout & Configuration页面左边功能分类栏目Middleware and SoftwarePacks中的FREERTOS,在模式配置栏中将其接口设置为CMSIS_V2(CMSIS_V2只是对CMSIS_V1的某些功能进行了扩展)
下方的Configuration配置页面中可以对9个选项卡关于FreeRTOS的所有参数做配置,目前均保持默认即可,具体配置如下图所示
以下列表为对上图所示这9个配置选项卡及其包含的参数做简单的介绍
Tasks and Queues:任务和队列管理
Timers and Semaphores :定时器和信号量管理
Mutexes:互斥量管理
Events:事件组管理
FreeRTOS Heap Usage:FreeRTOS内存使用详情
Config parameters:Config参数配置(对应FreeRTOSConfig.h中变量名config开始的宏定义)
Include parameters:Include参数配置(对应FreeRTOSConfig.h中变量名INCLUDE开始的宏定义)
Advanced settings:高级设置
User Constants:用户自定义常量
对于上面9个选项卡中的前4个,CubeMX都提供了图形化配置的界面,在对应的页面中可以通过按钮非常方便的增加/删除任务、队列、定时器、信号量、互斥量和事件组等实例,而不需要用户在程序中手动编程生成实例
FreeRTOS Heap Usage 选项卡提供了一个显示当前FreeRTOS内存使用详情的页面,该页面无参数可配置,仅仅显示内存占用信息和剩余可用堆大小
Config parameters 和 Include parameters 选项卡中的参数分别对应 FreeRTOSConfig.h 文件中 config 开头和 INCLUDE 开头的宏定义,用来设置FreeRTOS的相关参数及功能裁剪,下面是所有参数列表,读者可简单浏览,后面遇到需要修改的具体参数可以回过头来寻找,如下述列表所示
参数
函数功能
Config parameters/ MPU/FPU
ENABLE_MPU
设置是否使用MPU内存保护单元
ENABLE_FPU
设置是否使用FPU浮点数单元
Kernel settings
USE_PREEMPTION
设置任务调度方式,Enable 表示使用抢占式调度,Disable 表示使用合作式调度
CPU_CLOCK_HZ
设置MCU的HCLK始终频率,默认为系统时钟且不可修改
TICK_RATE_HZ
设置FreeRTOS滴答定时器中断频率,默认为1000Hz(1ms),设置范围为1-1000
MAX_PRIORITIES
设置最高优先级,值越大内核花销的内存空间就越多,总是建议将此常量设为能够用到的最小值,STM32CubeMX软件中默认为56且不可修改
MINIMAL_STACK_SIZE
设置空闲任务使用的堆栈大小,默认为128words
MAX_TASK_NAME_LEN
设置任务名的最大长度(包括'\0'结束符),如果创建任务时传入的任务名字符串长度超过该参数定义的长度,则任务名会被自动截断,默认为16
USE_16_BIT_TICKS
设置节拍数据类型TickType_t的具体类型,Enable 表示设置类型为 uint16_t,Disable 表示设置类型为 uint32_t
IDLE_SHOULD_YIELD
设置空闲任务是否对同优先级的任务主动让出CPU使用权
USE_MUTEXES
设置是否使用互斥量
USE_RECURSIVE_MUTEXES
设置是否使用递归互斥量
USE_COUNTING_SEMAPHORES
设置是否使用计数信号量
QUEUE_REGISTRY_SIZE
设置可注册队列和信号量的最大数量,默认为8,设置范围为0-255
USE_APPLICATION_TASK_TAG
设置是否使用应用程序的任务标签
ENABLE_BACKWARD_COMPATIBILITY
设置是否向后兼容旧版本
USE_PORT_OPTIMISED_TASK_SELECTION
设置任务调度时,选择下一个任务的方法,Disable 表示使用通用方法,不依赖硬件,此处使用 CMSIS-RTOS V2 时该参数默认为 Disable 且不可修改
USE_TICKLESS_IDLE
设置是否使用无节拍(tickless)低功耗模式
USE_TASK_NOTIFICATIONS
设置是否使用任务通知功能
RECORD_STACK_HIGH_ADDRESS
设置是否将栈的起始地址保存到每个任务的任务控制块中
Memory management settings
Memory_Allocation
设置内存分配方式,默认为 Dynamic / Static 且不可修改
TOTAL_HEAP_SIZE
设置FreeRTOS总的堆空间大小,设置范围为 512B~128KB
Memory_Management_scheme
设置内存管理方案,有 heap_x.h 共计5中可选方案,默认选择 heap_4.h
Hook function related definitions
USE_IDLE_HOOK
设置是否使用空闲任务钩子函数 vApplicationIdleHook()
USE_TICK_HOOK
设置是否使用滴答定时器钩子函数 vApplicationTickHook()
USE_MALLOC_FAILED_HOOK
设置是否使用内存分配失败钩子函数 vApplicationMallocFailedHook()
USE_DAEMON_TASK_STARTUP_HOOK
设置是否使用内存分配失败钩子函数 vApplicationMallocFailedHook()
CHECK_FOR_STACK_OVERFLOW
设置是否使用守护任务启动钩子函数 vApplicationDaemonTaskStartupHook()
Run time and task stats gathering related definitions
GENERATE_RUN_TIME_STATS
设置是否启动任务运行时间统计功能,启用后可以通过 vTaskGetRunTimeStats() API 函数读取这些信息
USE_TRACE_FACILITY
设置是否启用可视化和跟踪调试,默认为 Enabled
USE_STATS_FORMATTING_FUNCTIONS
设置是否编译 vTaskList() 和 vTaskGetRunTimeStats() API 函数,将 USE_TRACE_FACILITY 和 USE_STATS_FORMATTING_FUNCTIONS 设置为 1 将编译构建这两个函数,设置为 0 将不编译构建
Co-routine related definitions
USE_CO_ROUTINES
设置是否使用协程
MAX_CO_ROUTINE_PRIORITIES
设置协程最大优先级
Software timer definitions
USE_TIMERS
设置是否使用软件定时器
TIMER_TASK_PRIORITY
设置定时器服务任务优先级
TIMER_QUEUE_LENGTH
设置定时器指令队列长度
TIMER_TASK_STACK_DEPTH
设置定时器服务任务栈空间大小
Interrupt nesting behaviour configuration
LIBRARY_LOWEST_INTERRUPT_PRIORITY
设置最低中断优先级
LIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY
设置系统能管理的最高中断优先级
Added with 10.2.1 support
MESSAGE_BUFFER_LENGTH_TYPE
设置消息缓冲区长度类型
USE_POSIX_ERRNO
设置使用POSIX标准的错误编号
CMSIS-RTOS V2 flags (仅适用于 FreeRTOS >= 10.3.1 版本)
THREAD_SUSPEND_RESUME
设置是否使用 CMSIS-RTOS2 的线程挂起 osThreadSuspend() 和恢复 osThreadResume() API 函数
USE_OS2_THREAD_ENUMERATE
设置是否使用 CMSIS-RTOS2 的返回线程枚举数量 osThreadEnumerate() API 函数
USE_OS2_EVENTFLAGS_FROM_ISR
设置是否使用来自 ISR 的 CMSIS-RTOS2 函数 osEventFlagsSet() 和 osEventFlagsClear() 操作
USE_OS2_THREAD_FLAGS
设置是否从应用程序映像中排除 CMSIS-RTOS2 线程标志 API 函数
USE_OS2_TIMER
设置是否从应用程序映像中排除 CMSIS-RTOS2 定时器 API 函数
USE_OS2_MUTEX
设置是否从应用程序映像中排除 CMSIS-RTOS2 Mutex API 函数数
Include parameters/ Include definitions
vTaskPrioritySet
设置是否包含 vTaskPrioritySet() API 函数
uxTaskPriorityGet
设置是否包含 uxTaskPriorityGet() API 函数
vTaskDelete
设置是否包含 vTaskDelete() API 函数
vTaskCleanUpResources
设置是否包含 vTaskCleanUpResources() API 函数
vTaskSuspend
设置是否包含 vTaskSuspend() API 函数
vTaskDelayUntil
设置是否包含 vTaskDelayUntil() API 函数
vTaskDelay
设置是否包含 vTaskDelay() API 函数
xTaskGetSchedulerState
设置是否包含 xTaskGetSchedulerState() API 函数
xTaskResumeFromlSR
设置是否包含 xTaskResumeFromlSR() API 函数
xQueueGetMutexHolder
设置是否包含 xQueueGetMutexHolder() API 函数,默认启用(某些工具链(例如MDK-ARM)可能需要编译cmsis_os2.c)
pcTaskGetTaskName
设置是否包含 pcTaskGetTaskName() API 函数
uxTaskGetStackHighWaterMark
设置是否包含 uxTaskGetStackHighWaterMark() API 函数
xTaskGetCurrentTaskHandle
设置是否包含 xTaskGetCurrentTaskHandle() API 函数
eTaskGetState
设置是否包含 eTaskGetState() API 函数
xEventGroupSetBitFromlSR
设置是否包含 xEventGroupSetBitFromlSR() API 函数,INCLUDE_xTimerPendFunctionCall 必须设置为 1 使 xEventGroupSetBitFromISR() 函数可用
xTimerPendFunctionCall
设置是否包含 xTimerPendFunctionCall() API 函数,configUSE_TIMERS 必须设置为 1 使 xTimerPendFunctionCall() 函数可用
xTaskAbortDelay
设置是否包含 xTaskAbortDelay() API 函数
xTaskGetHandle
设置是否包含 xTaskGetHandle() API 函数
uxTaskGetStackHighWaterMark2
设置是否包含 uxTaskGetStackHighWaterMark2() API 函数,适用于支持 FreeRTOS >= 10.2.1 的系列
Advanced settings 选项卡中只有两个参数, USE_NEWLIB_REENTRANT 用于配置 Newlib 相关内容,一般不使用; Use FW pack heap file 用于配置是否使用固件包提供的堆管理文件(heap_x.c),不使用的话需要由用户自己提供堆管理文件,这里一般选择使用
User Constants 选项卡可以创建一些用户需要使用的常量参数,创建的常量将以宏定义的形式被定义在main.h文件中
4.1.4、外设中断配置
当启用了FREERTOS之后,整个系统的NVIC会自动发生一些变化,FreeRTOS使用的系统服务可挂起请求中断和系统滴答定时器中断将被强制开启,均为最低优先级且不可设置,这两个中断对于FreeRTOS来说是相当重要的,系统滴答定时器会为FreeRTOS提供时间基准,系统服务可挂起请求中断用于任务切换等管理
另外HAL库的时基源TIM6中断也会被强制打开不可关闭,但是其中断的优先级仍可调节,我们将TIM6中断设置为硬件最高优先级0,其他均按照默认中断优先级即可,具体配置如下图所示
将启用FreeRTOS之后的NVIC与启用之前的NVIC对比可以发现,在配置页面多了一列“Uses FreeRTOS functions”,在增加的这一列的某个硬件中断后面勾选选项框则会改变该硬件中断的抢占优先级,读者目前仅作了解,有关中断具体管理会在后续教程中讲到
4.2、生成代码
4.2.1、配置Project Manager页面
单击进入Project Manager页面,在左边Project分栏中修改工程名称、工程目录和工具链,然后在Code Generator中勾选“Gnerate peripheral initialization as a pair of 'c/h' files per peripheral”,最后单击页面右上角GENERATE CODE生成工程,具体如下图所示
4.2.2、工程代码结构分析
打开生成的工程代码,观察其目录结构,发现在Core目录下相比较以往的工程增加了freertos.c 和 stm32f4xx_hal_timebase_tim.c 两个文件,在工程下还增加了Middlewares/FreeRTOS的源码文件,该源码文件下所有文件均无需用户修改,生成工程代码具体工程目录结构如下图所示
为了减少在使用不同的第三方RTOS嵌入式操作系统(eg:FreeRTOS、UCOS等)对用户应用代码带来的差异,ARM公司为RTOS内核制定了一套通用的接口协议CMSIS-RTOS(cmsis_osx.c),在该文件中规定了RTOS中使用的某些功能函数的统一名称及参数等等
在应用上,用户只需要调用CMSS-RTOS规定的API函数来对任务进行操作,而CMSS-RTOS规定的API函数会使用不同第三方RTOS嵌入式操作系统的接口函数对CMSS-CORE(HAL库等函数)操作,最终控制底层MCU,其中CMSS、RTOS和MCU等的关系图如下图所示 (注释1)
接下来我们来看看空的FreeRTOS工程初始化流程,打开main.c文件,在主函数中分别执行了以下几个函数,下面简单介绍下这些空工程中就使用到的函数,读者了解即可
最后调用osKernelStart()函数时会先创建一个空闲任务,然后启动FreeRTOS调度器,将STM32内核控制权交给FreeRTOS调度器,FreeRTOS调度器启动之后必须要至少有一个任务在不断运行,之后调度器就会按照一定的任务优先级顺序执行用户定义的各种任务,每个任务都应该是一个死循环,所以程序不会运行到osKernelStart()函数之后的任何部分
读者在使用FreeRTOS时,如果需要自己手动创建某些任务、信号量、互斥量等可以直接在freertos.c文件中实现即可,也可以在CubeMX图形化配置界面中创建(推荐后者)
MX_FREERTOS_Init()函数中,ST公司也使用者贴心的提供了各种不同功能的沙箱代码段,当在CubeMX图形化配置界面中创建了对应的实例,该沙箱代码段中就会出现对应实现的程序,如下图所示
4.3、烧录验证
使用STM32CubeMX生成工程代码后,不做任何修改,直接单击KEIL软件的编译按钮应该可以顺利通过,通过编译信息可知出现0错误和0警告,如下图所示
单击魔术手,在debug选项卡中选择使用DAP下载器(该下载器无需下载驱动),单击后方的设置可以在其中看到识别到的下载器,具体如下图所示
将接入电源的开发板通过DAP下载器与PC连接,单击KEIL软件的LOAD按钮将程序烧录进入开发板MCU中,等待下方进度条走完,可以发现 Flash Load finished ,由于是空工程因此无任何现象发生,具体如下图所示
5、注释详解
注释1:图片来源 Getting Started with STM32 - Introduction to FreeRTOS
注释2:图片来源 CMSIS-Core Device Templates
参考资料
STM32Cube高效开发教程(高级篇)
posted @
2024-03-11 09:44
OSnotes
阅读(139)
评论(0)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面返回顶部
公告
Copyright © 2024 OSnotes
Powered by .NET 8.0 on Kubernetes