DietPi for Real Time application Topic is solved

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
Post Reply
somenrs
Posts: 11
Joined: Fri Jul 03, 2020 11:08 am

DietPi for Real Time application

Post by somenrs »

Hi.

I searched this forum in case anybody had the same problem but I didn't found anything relevant (or I didn't search hard enough).

I have on my RPi 4B 6 accelerometer sensors via SPI + PiJuice. DietPi runs only 1 simple C program and nothing else, data is written to USB or SD card. Sampling frequency is 1 kHz and here lies the problem. Nice level for the program is set to -20. Most of the time (90%+) works fine and reading/writing function executes every 1000 us. But here and there this value rises, mostly below 2000 us but sometimes to 700 000 us and that is unacceptable because later data has to be synchronized wit other systems.

I am well aware that RPi is not the best choice for RT applications but for now I have to work with that. Is there any way, except buying RT clock hat, that I can make system more "reliable", so sensor readings are 1 ms apart and not 1.1 ms or worse, more that 2 ms? Thanks for your help!

EDIT: Acc sensor provides time stamp but since sampling frequency varies we cannot use it.
User avatar
MichaIng
Site Admin
Posts: 2323
Joined: Sat Nov 18, 2017 6:21 pm

Re: DietPi for Real Time application

Post by MichaIng »

Hi, many thanks for your interesting question. I read here and there about real-time requirements and not only DietPi, but more the underlying kernel or even Linux at all :). But lately Linux got some new features and of course it is all about the required precision level. Little article about what is possible: https://www.redhat.com/sysadmin/real-time-kernel

However, lets see what we can do. Nice -20 is already good. But the CPU scheduling policy for the process is probably not optimal: https://manpages.debian.org/stretch/man ... .7.en.html
For real-time processes switch to FIFO (first in-first out) or RR (round-robin). If you run it as systemd service, dietpi-services can change it on service-level. To be true right now I don't know the command to switch this outside systemd, but should be not difficult to find. The CPU priority can then be set as kinda replacement for nice.

Does your process as well read and/or write to disk? In this case, the same as for CPU scheduler applies for I/O scheduler: https://manpages.debian.org/stretch/uti ... .1.en.html
Ah, its the ionice command. Use realtime for scheduling class and the I/O scheduling priority, although AFAIK that is raised automatically together with nice.

And of course take care to disable all unnecessary background services that might disturb, like cron and probably some others (systemd timers). Check via systemctl command whats running and in case which timers are active (similar to cron).
somenrs
Posts: 11
Joined: Fri Jul 03, 2020 11:08 am

Re: DietPi for Real Time application

Post by somenrs »

Thanks for the detailed post.
I've tried all of that and the best it can do is just a little over 2 ms which is still not acceptable.
User avatar
MichaIng
Site Admin
Posts: 2323
Joined: Sat Nov 18, 2017 6:21 pm

Re: DietPi for Real Time application

Post by MichaIng »

I'm just searching for some RPi real-time Linux resources, is there even an official package available? http://www.machinekit.io/docs/getting-s ... rnel-RPi2/

Ah nope, another 3rd party RT kernel implementation. Found many of them but mostly outdated.

Better source: https://www.get-edi.io/Real-Time-Linux- ... pberry-Pi/
This can be done as well on the RPi directly. Simply grab the newest kernel or the latest stable version instead of 4.19. And it seems it runs better with the 64-bit version, then it makes sense to to use our RPi 64-bit image.
somenrs
Posts: 11
Joined: Fri Jul 03, 2020 11:08 am

Re: DietPi for Real Time application

Post by somenrs »

I've found the same page and I'm gonna try it (not a linux person btw). I also ordered RTC module. If it helps in any way with real time data logging that's a plus.
somenrs
Posts: 11
Joined: Fri Jul 03, 2020 11:08 am

Re: DietPi for Real Time application

Post by somenrs »

I have a problem: cannot instal edi (edi packet not found). And without it I cannot proceed with kernel update.
https://docs.get-edi.io/en/latest/getting_started.html
I changed my OS to 64-bit (aarch64). I get this message when using

Code: Select all

sudo snap install edi
error: snap "edi" is not available on stable for this architecture (armhf) but exists on other architectures (amd64).
I followed the instructions on the second link you provided and I'm stuck at this. I'm not a linux guy and upgrading linux with command lines is new and super confusing to me.

EDIT: using command

Code: Select all

uname -a
I get this
Linux DietPi 5.4.51-v8+ #1327 SMP PREEMPT Thu Jul 23 11:11:34 BST 2020 aarch64 GNU/Linux
User avatar
Joulinar
Posts: 2277
Joined: Sat Nov 16, 2019 12:49 am

Re: DietPi for Real Time application

Post by Joulinar »

well you system is still a 32bit system using 32bit architecture. The only thing you did, is to force kernel into 64bit mode. If needed you would need to use a native 64bit image I guess.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
somenrs
Posts: 11
Joined: Fri Jul 03, 2020 11:08 am

Re: DietPi for Real Time application

Post by somenrs »

I set my program in dietpi-sevices as fifo with level 99, running clean DietPi OS. It works kinda OK but much better than before.

Second thing is I cannot in no way install edi on my DietPi (I can't use realtimepi buster light image because of both non-working HDMI outoputs) to update it with realtime kernel mentioned by MichaIng. No matter which tutorial I follow I always get the same message:
error: snap "edi" is not available on stable for this architecture (armhf) but exists on other architectures (amd64).
So the questions are:
  • is it possible to somehow enable SSH on SD card from Windows? So when SD is put in RPi it is ready for SSH without enabling it on RPi?
    To simplify: I want to put SD card into my RPi for the first time, turn RPi on and access it over SSH.
  • Why edi cannot be installed on latest DietPi? Is there any other way to do it?
User avatar
Joulinar
Posts: 2277
Joined: Sat Nov 16, 2019 12:49 am

Re: DietPi for Real Time application

Post by Joulinar »

Just to avoid a missunderstanding, DietPi is not an own OS or destro. It's a set of scripts on top of a Debian base image. In case of Raspberry Pi devices, base image is a Raspberry OS.

Coming back to your questions:
is it possible to somehow enable SSH on SD card from Windows? So when SD is put in RPi it is ready for SSH without enabling it on RPi?
To simplify: I want to put SD card into my RPi for the first time, turn RPi on and access it over SSH.
  • SSH is activated by default on DietPi. No need to do anything manual.
Why edi cannot be installed on latest DietPi? Is there any other way to do it?
  • I guess it's more a challenge of the Raspberry OS 32bit. Looks like, edi is not available on Raspberry OS 32bit (architecture armhf). Maybe you could test the DietPi - Raspberry OS 64bit BETA image. But this is still under development by Raspberry Foundation. There might be thinks not working and still needs to be implemented by the Raspberry Foundation.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Post Reply