How to limit the time that Linux takes per action?

The question may look blurry, since it is difficult to describe the problem in one line, so here it is. I use Debian on the Raspberry Pi to run the PID controller, which means that dt (time difference between cycles) is obtained every time the PID output is output. Basically, dt is calculated like this.

oldtime_ = time_; clock_gettime(CLOCK_MONOTONIC, &time_); Timer.dt = ((static_cast<int64_t>(time_.tv_sec) * 1000000000 + static_cast<int64_t>(time_.tv_nsec)) - (static_cast<int64_t>(oldtime_.tv_sec) * 1000000000 + static_cast<int64_t>(oldtime_.tv_nsec))) / 1000000000.0; 

The PID is updated about 400 times per second and it runs fine, but sometimes Linux decides to take a lot more time to do the action. The result is a large number of dt, say, not 1/400 = 0.0025, but 0.8, which is 320 times more than necessary. The result is an incorrect PID calculation. It looks like this. enter image description here

I would like an answer on how to move raspbian a little closer to the real-time system.

EDIT

Thanks, anaken78 and everyone who helped. Using the RR_FIFO graph worked fine, and the processing speed is always 380-400 Hz. enter image description here

+5
source share
1 answer

I assume that you are using the original raspberry pi, not raspberry pi 2. The problem with the original raspberry pi is that it uses a single-core ARM11 processor, which in fact means that any kind of RT calculation (the way you do it) is related with errors due to hardware interrupts. For example, packets passing through Wifi can interrupt your system, causing a problem.

One possible thing that you could try if you're okay with no network connection is to increase the priority of the process and disable your wifi and eth interfaces. These, I would say, are the main sources of asynchronous interrupts that can lead to disruption of your process. There will be other interrupts that keep firing, you can look at / proc / interrupts and / proc / softirq to get an idea of ​​shelling interrupts, but on a platform like raspberry pi, they should either be piodic (timer), or they will be very a short one (for example, USB interrupts) should not cause delays in your process, on the order of several ms.

+2
source

Source: https://habr.com/ru/post/1215396/


All Articles