2

I am running a computer vision program on a Raspberry Pi (Linux raspberrypi 3.10.19+), and when it firsts begins, each iteration of the main loop runs in 6 ms. After a few seconds, the time per loop increases to 50 ms, and then switches between 6 and 50 ms every 10 seconds or so. Why might this be happening?

I have checked very carefully and I am pretty sure there are no memory leaks. The process remains at 3.9% memory usage the whole time. I have tried increasing the priority of the process (nice -n -19) but that didn't work.

When I take out all of my vision processing and simply pull frames from the camera, the speed of the process does not exhibit this changing behavior, so I don't think it has to do with the camera.

The only thing I can think of is that some memory (maybe the cache?) is filling up and then slowing things down, and then getting cleared out every so often, thus speeding things up again.

Thanks!

2
  • 2
    Linux is not a real time OS, and it is unrealistic to expect tasks to run in mS timeslots. It is likely that the cause is nothing to do with your software, but some other process running on the Pi.
    – Milliways
    Dec 16, 2013 at 22:39
  • This is where you learn how to create code execution analysis to work out what is going on and how to exactly solve the problem.
    – Piotr Kula
    Jul 15, 2014 at 10:02

3 Answers 3

1

Have you checked the CPU temperature? The clock speed will decrease if it overheats and this will slow down your execution speed. Once the CPU has a cooled a little then the clock speed will rise again and your code will execute faster.

0

According to your tag you are using C++. In your code are you creating objects dynamically? If you use new and delete, either explicitly or implicitly, then you will invoke garbage collection on the heap from time to time.

For this to happen every 10 seconds or so does seem a bit too frequent for this though. I would expect longer between invocations.

Try creating a static object or a fixed number of static objects and using these directly. You should find things a bit more reliable.

2
  • Thanks for the reply! I am not creating any objects anywhere actually. The frame is getting put into a char[] buffer in static memory, and I am not creating any other buffers.
    – Henry
    Dec 16, 2013 at 20:03
  • C++ does not use garbage collection.
    – mirk
    Jun 15, 2014 at 7:44
0

As Milliways suggested, it may be outside of your code. A 10 second cycle is quite long, so monitor for other processes while it's running and also if the core temperature is increasing enough for frequency scaling to kick in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.