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.
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/manpages/sched.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/util-linux/ionice.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).
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.
I’m just searching for some RPi real-time Linux resources, is there even an official package available? http://www.machinekit.io/docs/getting-started/install-rt-kernel-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-on-the-Raspberry-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.
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.
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
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
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
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.
1 Like
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?
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.
Hi @MichaIng
Is it possible to replace the stock kernel with “lowlatency” kernel on DietPi?
64-it Armv8 on NanoPi R4S
We don’t create own kernel. If you like to use a different kernel, you would need to do it yourself.
1 Like
Thanks @Joulinar ! I have found the debian realtime kernel that I would like to install on my NanoPi R4S (5.10)

But there’s no monitor on R4S
On my RPi i used the below to select custom kernel and on boot I selected the kernel i want from Grub menu - I only had to do this once. Until I wanted to change kernel.
How would I manually select custom kernel in the case of no monitor ?
The *simplest* solution might be to enable Grub's GRUB_SAVEDEFAULT feature. Try this:
1. Open the Terminal
2. Edit the /etc/default/grub file: **sudo nano /etc/default/grub**
3. Change GRUB_DEFAULT=0 to GRUB_DEFAULT=saved
4. Add GRUB_SAVEDEFAULT=true
5. Save the file
6. Update Grub with: **sudo update-grub**
These settings will ensure that your system boots with the last kernel you chose during boot.
Now reboot, hold the LEFT shift key when your system comes back up.
Or press ESCAPE to enter GRUB
You should then see the Grub menu.
Choose the Kernel that works for you. That will now be "default".
Check Kernel version with uname -a
GRUB bootloader on RPi?
However, the R4S uses U-Boot. Adjust /boot/boot.cmd
to load the correct device tree at /usr/lib/linux-image-*
and the correct kernel image and initramfs. If I’m not mistaken, by default the Debian kernel creates two symlinks named vmlinuz
and initrd
in /
and/or /boot
directory. These can be used in /boot/boot.cmd
, then recompile it via:
mkimage -C none -A arm64 -T script -d /boot/boot.cmd /boot/boot.scr
And I just checked, you need to install the kernel from backports, since the 5.10 one does not have an R4S device tree yet:
apt update
apt install -t bullseye-backports linux-image-rt-arm64
Be careful, when the kernel gets an upgrade, you need to adjust the device tree entry in /boot/boot.cmd
. Probably best is to create an /etc/kernel/postinst.d
script to update a symlink at a fixed location.
1 Like