Using the function "usleep()" in the user-space C application and high resolution timers (hrtimer) in the kernel-space driver, Linux kernel 3.12.32 with and without the real-time patch (RT). First without touch the system (Idle) and then with the 'top' tool running while keyboard 'down' button pressed.
The table below show the results, 'Programmed Time' is the smallest time found after some tests as the stable/usable, that start makes sense with the value supplied in the functions: usleep() and hrtimer.
What happens with usleep(1) ?
The minimal value for usleep() function is 1, that give us 1 uS, right? wrong! look what happens:The table below show the results, 'Programmed Time' is the smallest time found after some tests as the stable/usable, that start makes sense with the value supplied in the functions: usleep() and hrtimer.
RT patch
|
Programmed Time(uS)
|
Result Idle(uS)
|
Variation Idle(uS)
|
Result Top(uS)
|
Variation Top(uS)
| |
user-space
|
no
|
100
|
94-104
|
10
|
110-134
|
24
|
user-space
|
yes
|
100
|
94-108
|
14
|
124-160
|
36
|
kernel-space
|
no
|
20
|
19-20
|
1
|
28-25
|
7
|
kernel-space
|
yes
|
40
|
39-42
|
3
|
36-50
|
14
|
What happens with usleep(1) ?
As we can see, there are a 'delay' of 76 uS. This explain why usleep(100) give us not 100 uS, but 176 uS, look:
So, if you want a 100 uS time, you need use usleep(100-76).
What happens with hrtimer set to 1 nanosecond?
Instability! nothing more than noise and random times! 20 uS was the smallest value found as stable/usable without the RT patch:
And with the RT patch, 40 uS:
The idea of the Linux kernel RT patch is improve the performance of user-space applications, "giving more CPU time", applications run on user-space, so where this 'extra' CPU time came from? as we could see, with the RT patch the kernel-space time increased from 20 uS to 40 uS, giving us the answer. The best scenario for GPIO speed, is the Linux kernel without the RT patch and from kernel-space, achieving 20 uS as the smallest, controllable and stable time.
0 comentários :
Post a Comment