Executable gives different FPS values ​in Yocto and Raspbian(everything looks the same in terms of configuration) - linux

In Yocto project, built my project which is running on Raspbian OS. When i run executable, i get half FPS compared to executable running on Raspbian OS.
The libraries i use:
OpenCV
Tensorflow-Lite, Flatbuffer, Libedgetpu
I use Libedgetpu1-std, Tensorflow-lite 2.4.0 on Raspbian and Libedgetpu 2.5.0, Tensorflow-lite 2.5.0 on Yocto.
Thinking that the problem is that the versions or configurations of the libraries are not the same, i followed these steps:
I ran the executable which i built in Raspbian directly in the runtime of the Yocto project.(I have set the required library versions to the same library versions available in raspbian for it to work in runtime.)
But i still got low FPS. Here is how i calculate that i get half the FPS:
I am using TFLite's interpreter invoke function. I set a timer when entering and exiting the function, i calculate FPS over it. I can exemplify like this:
Timer_Begin();
m_tf_interpreter->Invoke();
Timer_End();
Somehow i think the Interpreter Invoke function is running slower on the Yocto side. I checked Kernel versions, CPU speeds, /boot/config.txt contents, USB power consumes of Raspbian and Yocto. However, I couldn't catch anything from anywhere.
Note : Using RPI4 and Coral-TPU(Plugged into USB 2.0).

We spoke with #Paulo Neves. He recommend Perf profiling and i did . In the perf profiling, i noticed that the CPU is running slowly. Although the frequencies are the same.
When i check the "scaling_governor", i saw that it was in "powersave" mode. The problem solved when i switched from "powersave" to "performance" mode from virtual kernel.
In addition, if you want to make the governor change permanent, you need to create a kernel config fragment.

Related

Raspberry pi 4 - with custom GUI interface and fast boot speed

I'm trying to achieve this on a Raspberry Pi 4:
Less then 10 seconds boot time
Custom UI ( build with python/Gtk for example )
I already tried editing the /boot/config.txt with
# Disable the rainbow splash screen
disable_splash=1
# Disable bluetooth
dtoverlay=pi3-disable-bt
#Disable Wifi
dtoverlay=pi3-disable-wifi
dtoverlay=sdtweak,overclock_50=100
# Set the bootloader delay to 0 seconds. The default is 1s if not specified.
boot_delay=0
# Overclock the raspberry pi. This voids its warranty. Make sure you have a good power supply.
force_turbo=1
Also I have an A2 class 10 SdCard and I have disabled almost every service that I don't need.
My best results are 14 seconds boot time until my app started, but I need to make it faster....
I would like to achieve something like this in terms of speed, but using GTK, not QT:
https://www.youtube.com/watch?v=TTcP3xeLrEY
I am also currently trying to reach fast boot time with my Raspberry Pi 4, but I cannot breach the wall of 10s without radical solutions such as buildroot or unikernel.
What do you need on your system ? On Raspbian you can use those two commands to verify what is slowing down the boot process :
systemd-analyze critical-chain
and
systemd-analyze blame
Critical chain will show in red the services blocking the boot.
On my setup I could desactivate all those services :
hciuart #GPIOs
nmbd
smbd
wpa_supplicant
systemd-timesyncd
rpi-eeprom-update.service
raspi-config.service
networking
Just use sudo systemctl disable SERVICE , I guess there are others that are not critical for your application.
Also, in the cmdline.txt file in /boot you can add quiet fastboot , it will decrease boot time further
GTK is a toolkit coded in C and callable from C code.
In practice, Python can be 10x slower than equivalent C code.
Did you consider starting Xorg with a minimal window manager and a single client coded in C? Without a single line of Python? Of course, read more about X windows systems protocols and architecture then about EWMH.
So, remove the Python interpreter on your RaspBerryPi (probably /usr/bin/python) and replace every old Python script by an equivalent ELF executable coded in C or in C++ and compiled with optimizations (so gcc -O3 with GCC). See also linuxfromscratch.org for inspiration and guidance.
I would like to achieve something like this in terms of speed, but using GTK
Of course, you want to use a GCC cross-compiler.
If that still does not work (after weeks of effort), replace your hardware by something more powerful.
It would be easier for you to install a Linux distribution such as Debian on your development laptop or desktop. Because most of what you would learn on your development computer (e.g. Advanced Linux Programming) can be applied to the RaspBerrry Pi. And cross-building on a Debian laptop for a Raspbian RaspBerryPi is really easy. Focus on learning low-level things starting from their C code. E.g. code your GUI directly with Xlib (no GTK, no Qt) in C. The same C code is very likely to be easily portable -if you write it carefully- from x86/Debian to your Raspberry Pi.
You could read the From powerup to to bash prompt howto; most of that document is relevant for a RaspBerryPi running RaspBian.
You could even avoid starting any Xorg or other display server (e.g. WayLand) on your RaspBerryPi. That certainly would make it boot faster.
You could replace your /sbin/init program by your own one coded in C entirely. That process starts within less than a second, and forks all other processes. Your custom GUI could be just Xorg with your single X11 client coded in C.
Observe that you could have the source code (millions of source lines) of all the code running on RaspBian. Then download it, study it, and optimize it. Of course this could take decades.
First, this is a poorly formed question. You've provided no details on what your boot process is or what OS/configuration you're running with for people to help.
Regardless, you appear primarily focused on a short boot time. So since your question is generic... here is a generic answer: there is nothing magical about the boot process. There is no config file with a fast_boot=1 option that gets you up in 0 seconds instead of 15. You want to boot faster? Do less.
Throw out slow crap like Python
Remove unnecessary application loading from your init system (sysvinit/systemd/whatever)
Remove unnecessary driver loading from the kernel startup. Start by trimming down your device tree to only the hardware you really need to initialize.
Optimize your bootloader (u-boot?) to only initialize the hardware you really need (obviously turn off any prompt and timer it may implement)
That's how you boot faster.

using BCM2835 with RT-PREEMPT kernel

I am making a project which send out 40khz signal from antenna.
I have found the signal is not too accurate so I have decided to try a real-time kernel.
I run Raspbian Jessie on my Raspberry-Pi 2B.
After clean install, the script run without any problem.
bcm2835_delayMicroseconds could be run.
I follow this tutorial http://www.frank-durr.de/?p=203 compiled and installed the RT kernal.
However, the script could no longer be run successfully.
After showing "HIGH SLEEP", and it is held up.
This is the code snippet:
fprintf(stdout , "HIGH\n");
bcm2835_gpio_write(PIN, HIGH);
fprintf(stdout , "SLEEP\n");
bcm2835_delayMicroseconds(12);
fprintf(stdout , "LOW\n");
bcm2835_gpio_write(PIN, LOW);
fprintf(stdout , "SLEEP\n");
bcm2835_delayMicroseconds(12);
Do I miss anything when compiling the kernel?
To use PREEMPT_RT you just have to:
retrieve the configuration of your current kernel
retrieve the kernel sources
patch the kernel sources with the PREEMPT_RT patch (or obtain an already patched kernel)
configure the new kernel as the current kernel (i.e., using make oldconfig)
enable full preemtability in kernel config (e.g., by running make menuconfig).
compile the kernel in the standard way
install the new kernel
Therefore, no particular action is needed.
Then, if performance is still not sufficient, you may want to tune priorities of specific IRQ threads.
From your specific error, it seems that the new kernel has been conpiled with a different configuration than the current kernel (e.g., GPIOs not enabled).
I have just seen and remembered this thread.
About half year ago, I want to generate 40khz from a Raspberry.
But finally I found I am using the wrong tool.
I believe Raspberry cannot handle such a task, since it is running an OS.
I switched to Arduino, and the problem is solved immediately without any problem.
Using the right tool for your task is very important!

Embedded Linux Boot Optimization

I am doing project on Pandaboard using Embedded Linux (UBUNTU 12.10 Server Prebuild image) to optimize boot time. I need techniques or tools through which I can find boot time and techniques to optimize the boot time. If anyone can help.
Just remove application which is not required from /etc/init.d/rc file also put echo after every process initialization and check which process is taking much time for starting,
if you find application which is taking more time then debug that application and so on.
There is program that can be helpful to know the approximate boot-up time. Check this link
Time Stamp.
First of all the best you have to do is to compile yourself your own made kernel, get the source on the internet and do a make xconfig and then unselected everythin you don't need.
In a second time create your own root filesystem using Buildroot and make xconfig to select/unselect everything you need or not.
Hope this help.
I had the same problem and do that way, now it's clearly not the same ;)
EDIT: Everything you need will be here
to analyze the boot process, you can use Bootchart2, its available on github: https://github.com/mmeeks/bootchart
or Bootchart, from the Ubuntu packages:
sudo apt-get update
sudo apt-get install bootchart pybootchartgui
There are broadly 3 areas where you can reduce boot time
Bootloader:
Modify the linker script to initialize only the required h/w. Also, if you are using an SD card to boot, merge kernel and bootloader image to save time.
Kernel:
Remove unwanted modules from kernel config. Also try using compressed and uncompressed image. If your CPU is good enough to handle it go compressed image and check uncompression time required for different compression types.
Filesystem:
FS size can be significantly reduced by removing the unwanted bins and libs. Check for dependencies and use only the one's that are required.
For more techniques and information on tools that help in measuring the boot time please refer to the following link.
Refer to Training Material
The basic rule is: the fastest code is code that never gets loaded and
run, so remove everything you don't need:
in U-Boot: don't load and run the full U-Boot at all; use FALCON
mode and have the SPL load the Linux kernel and DTB directly
in Linux: remove all drivers and other stuff you don't really need;
load all drivers that are not essential for your core application as
modules - and load them after your application was started. If you
take this serious, you may even want to start only one CPU core
initially (and start the remaining ones after your application is
running).
in user space: minimize the size of the root file system. throuw
out anything you don't need; configure tools (like busybox) to
contain only the really needed functionality; use efficient code
(for example, link against musl libc instead of glibc) etc.
What can be acchieved by combining all these measures can be seen in
this video - and yes, the complete code for this optimization is
available here.
Optimizing embedded Linux Boot process , needs modifications in three level of embedded Linux design.
Note: you will need the source codes of bootloader and kernel
Boot : the first step in optimizing and reducing boot time of board is optimizing boot loader. first you should know what is your bootloader is. If your bootloader is an opensource bootloader like u-boot than you have the opportunity to modify and optimize it. In u-boot we have a procedure that we can skip unnecessary system check and just upload kernel image to ram and start. the documentation and instruction for this is available in u-boot website. by doing this you will save about 4 ~ 5 second in boot.
Kernel : for having a quicker kernel , you should optimize kernel in many sections. for editing you can use on of Linux config menu. I always use a low graphic menu. it need some dependency you can use it by this command:
$ make menuconfig
our goal for Linux kernel is to have smaller kernel image and less module to load in boot. first change the algorithm of compression from gzip to LZO. the point of this action is gzip algorithm will take much time to extract kernel. by using LZO we have a quicker kernel decompression process. the second , disable any unnecessary driver or module that you don’t have it on your board or you don’t use it any more. by doing this , you will lose some device access and cannot use them in Linux but you will have two positive points: less Ram usage , quicker boot time.
but please remind that some driver are necessary for Linux and by disabling them you will lose some of main features (for example if you disable I2C driver in Linux you will no longer have a HDMI interface) that you need or in worst case you will have a boot problem (such as boot-loop). The third is to disable some of unusable filesystem to reduce kernel size and boot time. The Fourth is to remove some of compression algorithm to have smaller kernel image.
the last thing , If you are using a u-boot bootloader create a uImage instead of zImage. the following steps , are general and main actions , for having quicker boot as 1 second after power attach you should change more option.
after two base layer modifications, now we should optimize boot process in user-space (root file system). depend on witch system are you using , we have different changes to do. in abstract root file system of Linux that have necessary package and system to boot Linux we should use systemd instead of Unix systemv , because systemd have a multi-task init. system and it is faster , after that is udev that you should modify some of loading modules. if you have a graphical user-interface , we can use an easy trick to have a big boot time reduction by initing GUI first and load other module after loading GUI.
if you do all of following tasks , you can have quick boot time and fast system to work with.

ERROR: clGetPlatformIDs -1001 when running OpenCL code (Linux)

After finally managing to get my code to compile with OpenCL, I cannot seem to get the output binary to run! This is on my linux laptop running Kubuntu 13.10 x64
The error I get is (Printed from cl::Error):
ERROR: clGetPlatformIDs
-1001
I found this post but there does not seem to be a clear solution.
I added myself to the video group but this does not seem to work.
With regards to the ICD profile... I am not sure what I need to do - shouldn't this be included with the cuda toolkit? If not, where could I download one?
EDIT: It seems I have an ICD file in my system under /usr/share/nvidia-331/nvidia.icd. It contains the following text:
libnvidia-opencl.so.1
The only file in my system that resembles this is:
/usr/lib/nvidia-331/libnvidia-opencl.so.331.20
Is my ICD profile somehow wrong? Does anyone know a way to fix it?
(Mods: I am not sure if this post should be moved to AskUbuntu seeing as it was an issue related to Linux bumblebee rather than OpenCL itself?)
Ok so I managed to solve the issue after loads of effort.
There are two things that I needed to do:
Getting ICD to work
create a symbolic link from /usr/share/nvidia-331/nvidia.icd to /etc/OpenCL/vendors
sudo ln -s /usr/share/nvidia-331/nvidia.icd /etc/OpenCL/vendors
NOTE: In most cases you would need to replace nvidia-331 with whatever driver you are using - most commonly nvidia-current
I am really curious as to why this isn't done automatically when installing the cuda toolkit - but I have noticed that OpenCL programs will not work without this step!
Nvidia Optimus with Bumblebee
The reason why this was so complicated to get working was that I have an nvidia optimus laptop with poor driver support on linux. To fix this I have bumblebee installed to allow switching between my nvidia card and intel card.
However, because I am using bumblebee - the nvidia graphics card (and nvidia driver) will be unloaded unless explicitly told so. In order to use OpenCL, we need to turn on the nvidia graphics card.
To do this we need to explicitly tell bumblebee to turn the nvidia card on by using the commands optirun or primusrun:
optirun myopenclprogram
Note however, because all that matters is that the nvidia card is turned on and the drivers are loaded, you do not need to keep using optirun myprogram to get this to work (as this always involves the initial delay of waiting for the graphics card to be initialised).
You can run optirun kate for example and this would turn on the nvidia graphics card. You can then, in a separate terminal just run you opencl program without optirun and it will work just fine since the graphics card has already been turned on (and will remain on as long as you leave e.g. kate running).
You will notice that there is no delay in starting your program this time! This saves you alot of waiting - especially if you are developing the opencl program in question.
Once again, as long as you keep the nvidia graphics card turned on, your opencl program will work.
I will probably contact the bumblebee devs to see if there is an easier way to get this to work and report what they say here. Hopefully there is some way to turn the nvidia card on and off without requiring to keep a program (like kate in my example) running.
I hope this helps anyone trying to use OpenCL on linux laptops with bumblebee in the future (I could not find any clear cut solutions myself)
EDIT2: Turning you graphics card on and off can be done as follows for bumlebee users:
Turn graphics card on and load nvidia module
sudo tee /proc/acpi/bbswitch <<< ON
sudo modprobe nvidia
Turn graphics card off (nvidia module is automatically unloaded)
sudo tee /proc/acpi/bbswitch <<< OFF
To share some add info. I have installed intel opencl version on Ubuntu 13.10 saucy. Problem has been the same: -1001 error. I solved it by link analogicly to previous post:
sudo ln -sf /opt/intel/opencl-1.2-3.2.1.16712/etc/intel64.icd /etc/OpenCL/vendors/nvidia.icd

Upgrade a specific Linux Kernel Subsystem?

Is it possible to upgrade only a specific sub-system, say I2C, of the Linux Kernel.
For example:
Is it possible to include "Support for multiplexed I2C bus topologies (introduced in Kernel 2.6.36)" in the Kernel version 2.6.31.1.
No this is not possible.
A kernel module or 'subsystem' (eg the i2c module) is build for a specific kernel image, you cannot combine different kernel(module) versions.
If you are feeling lucky (depending on your kernel skills), you could:
download the source code of your kernel
Install compiler and friends
add the updated ic2 driver
Try to compile the module for your kernel version
Cross your fingers and load it into your own kernel...\
I do not have any experience with this, so I do not know whether this works or not. Of course, if the ic2 module requires other (updated) modules, you could be ending up with updating (almost) the complete kernel...

Resources