Open moiri opened 5 years ago
zlog
uses pthread_rwlock
to handle multi-threaded applications. It looks like priority inversion is indeed a problem here.
I can think of three ways to solve this problem:
The first and the third option might have a serious impact on performance (has to be tested) and the second option calls for disaster because the output log files can be defined in the config file. The fourth option might be sufficient following the arguments:
Note that in order to grant a user the permission to run RT threads at a given priority the file /etc/security/limits.conf
needs to be adapted. The following line must be added:
<domain> - rtprio 99
where <domain>
can be:
@group
syntaxIn a non-rt Linux kernel, kernel threads are not pre-empted by threads of higher priority.
Several options exist to enable kernel thread pre-emption. This Article talks about this topic.
This Post describes how to install a RT patch in Ubuntu.
Currently, logs are protected with a mutex to prevent priority inversion. Unfortunately, this lock is done before the log level check. This means that even if only errors are activated, the system will still lock on each debug message even if debug is disabled.
Right now I cannot see a solution for this problem. Maybe just ignore the priority inversion problem because it is very unlikely to happen?
In order to improve the predictability of time-triggered nets I plan to use the SCHED_FIFO policy as follows:
prio_tf
prio_net_1
N
whereN
is surrounded by by a temporal firewall uses SCHED_FIFO with priorityprio_net_n
~Not to worry about priority inversion as temporal firewalls only block on a timer but not on read and write operations. Further, nets that are "guarded" by temporal firewalls run with the same priority~.
Observation: priority inversion is also possible in Streamix, as also FIFO resources are protected with mutexes (which can be locked by threads with lower priority)
Observation: zlog and Priority inversion: If a log file is locked by an event-triggered net
et
andet
is then preempted by a temporal firewalltf
which in turn is pre-empted by a time-triggered nettt
we have a problem of priority inversion (untiltt
reaches a log instruction).Note: Priority inversion requires three priority levels. A mutex is able to cope with only two levels.
How to avoid priority inversion:
prio_tf
>prio_net_1
>prio_net_n
prio_tf
=prio_net_1
=prio_net_n
no priority inversion can occur