简体   繁体   English

软实时Linux调度

[英]Soft Real Time Linux Scheduling

I have a project with some soft real-time requirements. 我有一个具有一些软实时要求的项目。 I have two processes (programs that I've written) that do some data acquisition. 我有两个进程(我编写的程序)进行一些数据采集。 In either case, I need to continuously read in data that's coming in and process it. 在任何一种情况下,我都需要不断读入正在进入并处理它的数据。

The first program is heavily threaded, and the second one uses a library which should be threaded, but I have no clue what's going on under the hood. 第一个程序是严格的线程,第二个程序使用一个应该是线程的库,但我不知道幕后发生了什么。 Each program is executed by the user and (by default) I see each with a priority of 20 and a nice value of 0. Each program uses roughly 30% of the CPU. 每个程序都由用户执行,并且(默认情况下)我看到每个程序的优先级为20,漂亮的值为0.每个程序使用大约30%的CPU。

As it stands, both processes have to contended with a few background processes, and I want to give my two programs the best shot at the CPU as possible. 就目前而言,两个进程都必须与一些后台进程争用,我想尽可能地为我的两个程序提供最好的CPU。 My main issue is that I have a device that I talk to that has a 64 byte hardware buffer, and if I don't read from it in time, I get an overflow. 我的主要问题是我有一个与之交谈的设备,它有一个64字节的硬件缓冲区,如果我没有及时读取它,我会得到溢出。 I have noted this condition occurring once every 2-3 hours of run time. 我注意到这种情况每运行2-3小时就会发生一次。

Based on my research ( http://oreilly.com/catalog/linuxkernel/chapter/ch10.html ) there appear to be three ways of playing around with the priority: 根据我的研究( http://oreilly.com/catalog/linuxkernel/chapter/ch10.html ),似乎有三种方法可以优先使用:

  1. Set the nice value to a lower number, and therefore give each process more priority. 将nice值设置为较小的数字,因此为每个进程提供更多优先级。 I can do this without any modification to my code (or use the system call) using the nice command. 我可以使用nice命令在不对代码进行任何修改(或使用系统调用)的情况下执行此操作。

  2. Use sched_setscheduler() for the entire process to a particular scheduling policy. 将sched_setscheduler()用于特定调度策略的整个过程。

  3. Use pthread_setschedparam() to individually set each pthread. 使用pthread_setschedparam()分别设置每个pthread。

I have run into the following roadblocks: 我遇到了以下障碍:

  1. Say I go with choice 3, how do I prevent lower priority threads from being starved? 假设我选择3,如何防止低优先级线程被饿死? Is there also a way to ensure that shared locks cause lower priority threads to be promoted to a higher priority? 是否还有一种方法可以确保共享锁将优先级较低的线程提升到更高的优先级? Say I have a thread that's real-time, SCHED_RR and it shared a lock with a default, SCHED_OTHER thread. 假设我有一个实时的线程,SCHED_RR并且它与默认的SCHED_OTHER线程共享一个锁。 When the SCHED_OTHER thread gets the lock, I want it to execute @ higher priority to free the lock. 当SCHED_OTHER线程获得锁定时,我希望它执行@更高优先级来释放锁定。 How do I ensure this? 我如何确保这一点?

  2. If a thread of SCHED_RR creates another thread, is the new thread automatically SCHED_RR, or do I need to specify this? 如果SCHED_RR的一个线程创建另一个线程,新线程是自动SCHED_RR,还是我需要指定它? What if I have a process that I have set to SCHED_RR, do all its threads automatically follow this policy? 如果我有一个我已设置为SCHED_RR的进程,它的所有线程是否自动遵循此策略怎么办? What if a process of SCHED_RR spawns a child process, is it too automatically SCHED_RR? 如果SCHED_RR的进程产生子进程怎么办,它是否太自动SCHED_RR?

  3. Does any of this matter given that the code only uses up 60% of the CPU? 鉴于代码仅占用CPU的60%,这是否有任何问题? Or are there still issues with the CPU being shared with background processes that I should be concerned with and could be caused my buffer overflows? 或者是否存在CPU与后台进程共享的问题,我应该关注并可能导致我的缓冲区溢出?

Sorry for the long winded question, but I felt it needed some background info. 抱歉这个冗长的问题,但我觉得它需要一些背景信息。 Thanks in advance for the help. 先谢谢您的帮助。

(1) pthread_mutex_setprioceiling (1) pthread_mutex_setprioceiling

(2) A newly created thread inherits the schedule and priority of its creating thread unless it's thread attributes (eg pthread_attr_setschedparam / pthread_attr_setschedpolicy ) are directed to do otherwise when you call pthread_create . (2)新创建的线程继承其创建线程的调度和优先级,除非在调用pthread_create时指向其他线程属性(例如pthread_attr_setschedparam / pthread_attr_setschedpolicy )。

(3) Since you don't know what causes it now it is in fairness hard for anyone say with assurance. (3)既然你现在不知道是什么原因造成的,那么任何人都应该保证公平。

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

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