Real-time programming with Linux

谁说胖子不能爱 提交于 2019-12-09 07:53:36

问题


I've just built and set up a vanilla Linux kernel with the RT patch applied. Everything went fine and I can now correctly boot into the new kernel.

What leaves me wondering is this: I have a simulator program that I've made in C, and I want it to execute in hard real time mode, as should be allowed by the new kernel. Probably the whole simulator doesn't need to be run with real-time priority, but some of the tasks inside do.

How can I accomplish this? I take it that simply running the program won't do.


回答1:


If you are asking how to run some of the threads in real-time context, and others as conventional time-sharing threads, then all you need is to set their schedulers properly using sched_setscheduler.

Time-sharing threads want to be SCHED_OTHER; real-time simulator threads want to be SCHED_FIFO or SCHED_RR.

On Linux, in order to run at real-time priorities, your user must have resource limits (man 2 rlimit) that allows this. In particular, your rtprio rlimit must be set to the highest priority you will need. Alternatively, you can run the application as root. In a linux system with PAM, this is typically accomplished by adding the appropriate line to /etc/security/limits.conf

    @realtime   -  rtprio     99

This will grant rtprio limits up to real-time priority 99 to the realtime group. Then you add a real-time group to /etc/groups and make sure your user is in the group.

(And since this appears to be your first time doing this, you may also want to have a "dead man's switch" high-priority real-time thread around to make sure that your simulator doesn't get out of hand and render the system unusable... if you are simulating high CPU load, you may get ACTUAL high CPU load and be unable to stop things without a reboot.)



来源:https://stackoverflow.com/questions/10502508/real-time-programming-with-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!