SYS_NICE is a capability that allows a process to set thread affinity
and priority, among other things (see capabilities(7) for more info).
In this commit, add a function that allows to determine if the process
has this capability, and try to change the thread affinity and priority,
if requested. If the capability does not exist, the function will simply
not attempt to change the corresponding thread attributes.
To determine if the process has SYS_NICE, libcap can be used. However,
it might not be installed by default. To avoid requiring another
dependency, if we detect that libcap is not present, use a workaround by
try to set a real-time scheduling policy; if it's present, or can be
changed, we assume that the process has SYS_NICE (and clean up, if
relevant).
Simplify reading of capabilities
set_latency_target() attempts to set keep "low latency" by
- writing a specific latency to /dev/cpu_dma_latency
- setting manually the minimum CPU processor frequency to be the maximum
There is no functionality to undo this after stopping the softmodem(s),
and most users are probably not even aware that OAI does this. It is
generally preferable to set this beforehand using a governor or by
disabling sleep states (as outlined in the tutorial, and in a follow-up
commit in the performance tuning docs).
The previous mlockall() call, to lock memory to RAM, is retained in a
new function. There were additional mlockall() calls, which have been
replaced with lock_memory_to_ram(), where necessary.
A detached thread cannot be joined with pthread_join(). However, this
is crucial for correct resetting of the nr-softmodem. Therefore, do not
create threads in detached state.
This work is based on feedback from Thomas Schlichter.
His comments and suggestions were made just after the original MR was merged.
Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr>
It looks like :
- when running on a Fedora-host
- with generic kernel
- in a container
- even in privileged mode
That is not enough and priority/schedule settings is not allowed.
So at runtime, we check and in case, we don't set up priorities.
Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr>
see https://gitlab.eurecom.fr/oai/openairinterface5g/issues/227
When the UE connects to the eNodeB and receives its IP address from the
network, it calls system() to set it in the linux kernel world. This call
is not done in a realtime thread, but in the NAS, which uses its own thread,
independent of the realtime processing.
In some situations this totally disrupts realtime processing.
It is difficult to know precisely why that happens, but it seems that calling
fork(), as system() does, in a multi-threaded program is not a good idea. (So
say several people on the internet.) It is not clear why the softmodem is
impacted, but it seems that fork() is really what triggers the disruption.
Several tests lead to that conclusion.
To fix the problem, we create a child background process very early in main()
(before anything else basically). Then instead of calling system(), the main
process sends the string to the background process. The background process
gets the string, passes it to system() and reports the success/failure back
to the main process.
This solution involves a lot of system calls, but calling system() in the
first place is not cheap either. As long as no realtime thread uses this
mechanism, things should be fine. Time will tell.