简体   繁体   English

在linux中调度任务

[英]scheduling tasks in linux

Can we schedule a program to execute every 5 ms or 10 ms etc? 我们可以安排程序每5毫秒或10毫秒等执行一次吗? I need to generate a pulse through the serial port for 1 khz and 15 khz. 我需要通过串口产生1 khz和15 khz的脉冲。 But the program should only toggle the pins in the serial port , so the frequency has to be produced by a scheduler. 但程序只应切换串口中的引脚,因此频率必须由调度程序产生。 is this possible in linux with a rt patch? 这是否可以在Linux中使用rt补丁?

I believe a better solution is to put your "generate a pulse" function in a loop, for example: 我相信更好的解决方案是将“生成脉冲”函数放在循环中,例如:

for (;;) {
    generate_pulse(); /* generate a pulse */
    sleep(5ms);       /* or 10ms */
}

is this possible in linux with a rt patch?

I suggest to go for RT patch, if timing is critical. 如果时间关键,我建议去RT补丁。

Xenomai is a RT patch which I used on 2.6 kernel some days back. Xenomai是一个RT补丁,我在几天前在2.6内核上使用过它。

Here is an example which runs every 1 second. 这是一个每1秒运行一次的例子。 http://www.xenomai.org/documentation/trunk/html/api/trivial-periodic_8c-example.html http://www.xenomai.org/documentation/trunk/html/api/trivial-periodic_8c-example.html

There is the PPS project that is now part ( at least a portion of it for the 2.6 branch, but in the latest 3.x kernel branch it looks like there is a full integration ) of the mainline linux kernel . PPS项目现在是主要Linux内核的一部分(至少是2.6分支的一部分,但在最新的3.x内核分支中看起来有完全集成)。

There is also an explicit reference to using this PPS implementation with a serial port in the linked txt file 还有一个明确的参考,将此PPS实现与链接的txt文件中的串行端口一起使用

A PPS source can be connected to a serial port (usually to the Data Carrier Detect pin) or to a parallel port (ACK-pin) or to a special CPU's GPIOs (this is the common case in embedded systems) but in each case when a new pulse arrives the system must apply to it a timestamp and record it for userland. PPS源可以连接到串行端口 (通常连接到数据载波检测引脚)或并行端口(ACK引脚)或特殊CPU的GPIO(这是嵌入式系统中的常见情况),但在每种情况下都可以新脉冲到达系统必须向其应用时间戳并将其记录到用户区。

Apparently good examples / tutorials / guides, are not even that hard to find , I'm sure that you'll find a lot of good resources while just using search engine. 显然很好的例子/教程/指南,甚至都难以找到 ,我相信你会在使用搜索引擎的同时找到很多好的资源。

The header for the APIs is usually under /usr/include/linux/pps.h . API的标头通常位于/usr/include/linux/pps.h下。

I have finally found a way to get it done. 我终于找到了完成它的方法。 The best way to do it is to first create a timer with the required amount of time. 最好的方法是首先创建一个具有所需时间的计时器。 and then to call the task( which is the pulse generating program) every time the timer overflows. 然后在每次定时器溢出时调用任务(这是脉冲生成程序)。 The program for the timer can be run in the background. 计时器的程序可以在后台运行。 the timer can be created and set using the timer_create() and timer_settime() respectively. 可以分别使用timer_create()和timer_settime()创建和设置定时器。 A different program can be called from one program using fork() and execl(). 可以使用fork()和execl()从一个程序调用另一个程序。 The program can be run in the background using the daemon(). 该程序可以使用守护进程()在后台运行。 By using all these things we can create our own scheduler. 通过使用所有这些东西,我们可以创建自己的调度程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM