I used the RT-tools again to test the latency of the Preempt-RT and the Standard Kernels on the Raspberry Pi 3 Model B and B+.
The results are the following:
Raspberry 3 Model B+
|Fig. 1 (a): Latency Using Standard Raspbian Kernel (4.14.27-v7+) on Raspberry Pi 3 B+||Fig. 1 (b): Latency Using Preempt-RT Patched Raspbian Kernel (4.14.27-rt21-v7+) on Raspberry Pi 3 B+|
Raspberry 3 Model B
|Fig. 2 (a): Latency Using Standard Raspbian Kernel (4.14.27-v7+) on Raspberry Pi 3 B||Fig. 2 (b): Latency Using Preempt-RT Patched Raspbian Kernel (4.14.27-rt21-v7+) on Raspberry Pi 3 B|
The standard kernel on the model B+ is more irregular: There are more 'samples' between 160us and 400us and the maximal latency is slightly higher (390us (B+) vs 382us (B)). The latency improvement on the Raspberry Pi 3 Model B+ using the Preempt-RT kernel is better (109us (B+) vs 136us (B)).
The N-Queens Problem/Puzzle is a well-known problem that consists of placing N chess queens on an N × N chessboard so that no two queens attack each other. For example, one possible solution to the N-queens problem for N = 4 is the following:
|Fig. 3: N-queens problem example (N = 4). Source: Google Optimization Tools|
As you can see, no two queens are on the same row, column or diagonal. Usually the problem consists to find all possible solutions, rather than one optimal solution.
https://lemariva.com/blog/2018/04/raspberry-pi-the-n-queens-problem-performance-testI wrote a script in Python that calculates the number of all possible solutions. This script can be used as Benchmark for e.g. the Raspberry Pi.
Many people use the N-queens problem to test the performance of a defined solver. But this can be cheated. In my case, the solver (script) is not optimal (I implemented the backtracking way based on this solution), but it works, and it helps me to compare different configurations of the Raspberry Pi (kernel, model B & B+ etc.). I solved the N-queens problem for N=12, in single (ST) and multi-thread (MT) configurations and repeated the tests 45 (ST) / 100 (MT) to check the result variances.
For the following Benchmark tests, I used the following hardware:
* Raspberry Pi 3 Model B
* Raspberry Pi 3 Model B+
Both boards with the following heatsink.
|Fig. 4 (a): Comparison Mean Time to find all Solution on Standard Raspbian Kernel||Fig. 4 (b): Comparison Mean Temperature on Standard Raspbian Kernel||
|Fig. 5 (a): Comparison Mean Time to find all Solution on Preempt-RT Patched Raspbian Kernel ||Fig. 5 (b): Comparison Mean Temperature on Preempt-RT Patched Raspbian Kernel||
The Raspberry Pi 3 Model B+ using standard Raspbian kernel is 12% faster than using Preempt-RT kernel in multi-thread operations. In single-thread operations, this percentage reduces to 11%.
Same relation can be seen on the Model B: The standard Raspbian kernel is 12% in multi-thread configuration while only 9% in single-thread.
The IRQ related with the USB/Network chip interrupts often, this takes about 5%-15% of CPU performance (reported using 'top'). Almost same percentages are obtained on these analysis. Temperature is the main problem, the CPU reaches faster 68°C and reduces its performance.
The USB/Network IRQ interruption reduces the performance of the Preempt-RT kernel up to 12%. To test if its influence is greater if the network/ethernet or USB ports are used, I made the following test: I run the N-queens problem solver in multi-thread configuration and on a separated thread a webserver that received POST requests, and saved these requests (images) on a USB-driver. On my computer, I run a web client and send images in a loop. For this test, I used only the Raspberry Pi 3 Model B+, and repeated the solver 100 times using Standard and Preempt-RT Patched Raspbian Kernel.
|Fig. 6 (a): Comparison Mean Time to find all Solutions||Fig. 6 (b): Comparison Mean Temperature|
The solver on the standard kernel was 17% faster than on Preempt-RT kernel! The IRQ influence increases while using the USB and network ports! The maximal temperature using Preempt-RT kernel was 70.64°C while using standard kernel was 69.81°C.
I measured also the transfer data rate from the client: It was reduced up to 34% (mean) using the Preempt-RT Raspbian kernel!
The Preempt-RT patched Raspbian kernel (4.14.y-rt) offers a solution to reduce the kernel latency. But, you lose a lot of CPU and communication performance. The data transfer over Ethernet is reduced to 34% and the CPU performance up to 12%. If your application is sampling sensors really fast and it doesn't do a lot of "math" or/and data transfers, probably you need to patch the Raspberry Pi kernel. Otherwise, you should use the standard kernel.