copperplate/mercury: introduce weak function to get OS max thread priority
PATCH 1/1 copperplate/mercury: introduce weak function to get OS max thread priority
This patch introduces a weak function in the mercury copperplate code that allows to put an upper limit on the priority used by the created thread objects.
Before this patch the complete OS scheduler's FIFO range was used and it was not possible to restrict it. Restricting it can be useful in case other activities (typically platform related things) need to get a higher priority than the application threads.
The example below shows what needs to be implemented in the application to restrict the range.
#include <copperplate/threadobj.h>
int threadobj_sched_get_priority_max()
{
return 92;
}NOTE: if the value returned by the function is not in the range supported by the OS, the OS value will be used anyhow.
include/copperplate/threadobj.h +2 -0
@@ -136,6 +136,8 @@ void threadobj_save_timeout(struct threa corespec->timeout = *timeout; } +int threadobj_sched_get_priority_max (void ); +#endif /* CONFIG_XENO_MERCURY */ /*
lib/copperplate/threadobj.c +11 -1
@@ -539,9 +539,16 @@ static void nop_sighandler(int sig)/* nop */ } +__weak int threadobj_sched_get_priority_max (void ) +{ +return sched_get_priority_max (SCHED_FIFO ); +} +static inline void pkg_init_corespec (void ) {struct sigaction sa; +int max_prio; +int max_sched_prio;/* * We don't have builtin scheduler-lock feature over Mercury,
@@ -555,7 +562,10 @@ static inline void pkg_init_corespec(voi* holding the scheduler lock, unless the latter has to block * for some reason, defeating the purpose of such lock anyway. */ - threadobj_irq_prio =sched_get_priority_max (SCHED_FIFO ); + max_prio =threadobj_sched_get_priority_max (); + max_sched_prio =sched_get_priority_max (SCHED_FIFO ); + + threadobj_irq_prio = ((max_prio > max_sched_prio)? max_sched_prio:max_prio); threadobj_lock_prio = threadobj_irq_prio -1 ; threadobj_high_prio = threadobj_irq_prio -2 ; threadobj_agent_prio = threadobj_high_prio;
Quoted 11 lines · Ronny Meeus
This patch introduces a weak function in the mercury copperplate code that allows to put an upper limit on the priority used by the created thread objects.
Before this patch the complete OS scheduler's FIFO range was used and it was not possible to restrict it. Restricting it can be useful in case other activities (typically platform related things) need to get a higher priority than the application threads.
The example below shows what needs to be implemented in the application to restrict the range.
This looks weird. Any reason not to fix up the priority of your application threads?
Signature · 1 line
Philippe.
Quoted 10 lines · Philippe Gerum
Quoted 9 lines · Ronny Meeus
This patch introduces a weak function in the mercury copperplate code that allows to put an upper limit on the priority used by the created thread objects.
Before this patch the complete OS scheduler's FIFO range was used and it was not possible to restrict it. Restricting it can be useful in case other activities (typically platform related things) need to get a higher priority than the application threads.
Quoted 6 lines
Quoted 2 lines
The example below shows what needs to be implemented in the application to restrict the range.
This looks weird. Any reason not to fix up the priority of your application threads?
Philippe,
this is not only about the application threads. We also need to lower the priorities
used by the copperplate for the timer-thread and the task-lock priority. The reason for this is that we need to run certain Linux kernel threads at a higher
priority than any of the application threads, including Xenomai.
Ronny
Quoted 2 lines
--
Philippe.
Quoted 18 lines · Ronny Meeus
Quoted 10 lines · Philippe Gerum
Quoted 9 lines · Ronny Meeus
This patch introduces a weak function in the mercury copperplate code that allows to put an upper limit on the priority used by the created thread objects.
Before this patch the complete OS scheduler's FIFO range was used and it was not possible to restrict it. Restricting it can be useful in case other activities (typically platform related things) need to get a higher priority than the application threads.
Quoted 6 lines
Quoted 2 lines
The example below shows what needs to be implemented in the application to restrict the range.
This looks weird. Any reason not to fix up the priority of your application threads?
Quoted 9 lines
Philippe,
this is not only about the application threads. We also need to lower the priorities
used by the copperplate for the timer-thread and the task-lock priority. The reason for this is that we need to run certain Linux kernel threads at a higher
priority than any of the application threads, including Xenomai.
That means that your system is running in some sort of sandboxed non-rt environment that may be subject to priority throttling by other parts of the system even for critical events, which is an interesting concept, but makes the Xenomai system inherently non-rt in this case. Such approach is not transposable to the Cobalt core running natively on the hw, and that is another issue in my eyes.
I don't like the idea at all, but I will think of it anyway, to figure out whether this is compatible with some basic assumptions in Mercury. Bottom line is that adding yet another weak routine to get this is not the way to go, that would prevent multiple tuning points to co-exist into a single executable. At the very least, that would have to be a copperplate tunable.
On a general note, let's reserve weak bindings for alternate versions of internal code or data, not part of the user interface.
Signature · 1 line
Philippe.
Quoted 29 lines · Philippe Gerum
Quoted 18 lines · Ronny Meeus
Quoted 10 lines · Philippe Gerum
Quoted 9 lines · Ronny Meeus
This patch introduces a weak function in the mercury copperplate code that allows to put an upper limit on the priority used by the created thread objects.
Before this patch the complete OS scheduler's FIFO range was used and it was not possible to restrict it. Restricting it can be useful in case other activities (typically platform related things) need to get a higher priority than the application threads.
Quoted 6 lines
Quoted 2 lines
The example below shows what needs to be implemented in the application to restrict the range.
This looks weird. Any reason not to fix up the priority of your application threads?
Quoted 9 lines
Philippe,
this is not only about the application threads. We also need to lower the priorities
used by the copperplate for the timer-thread and the task-lock priority. The reason for this is that we need to run certain Linux kernel threads at a higher
priority than any of the application threads, including Xenomai.
Quoted 7 lines
That means that your system is running in some sort of sandboxed non-rt environment that may be subject to priority throttling by other parts of the system even for critical events, which is an interesting concept, but makes the Xenomai system inherently non-rt in this case. Such approach is not transposable to the Cobalt core running natively on the hw, and that is another issue in my eyes.
Philippe,
our use-case is a system that is ported from a native pSOS system so we are actually after the pSOS interface. The RT aspect is less important for us since we only have a 'soft' real-time systems, e.g. no strict deadlines.
We also had issues in the past that Linux RCU handling caused kernel issues and we had to enable the CONFIG_RCU_BOOST option. To be on the safe side, we configured the RCU_BOOST priority to be higher than the prios used by the application, including the Xenomai threads. For this to work we needed to create some "gap" between the MAX prio supported by the scheduler and the max prio used by the apps.
Note that the critical events in our case are not handled by the Xenomai applications, but by the Linux kernel event handlers (running in kernel threads).
Quoted 6 lines
I don't like the idea at all, but I will think of it anyway, to figure out whether this is compatible with some basic assumptions in Mercury. Bottom line is that adding yet another weak routine to get this is not the way to go, that would prevent multiple tuning points to co-exist into a single executable. At the very least, that would have to be a copperplate tunable.
I will provide a patch later that uses a tunable to configure this. The weak implementation was inspired by the prio mapping function that exists for the pSOS skin ...
Quoted 5 lines
On a general note, let's reserve weak bindings for alternate versions of internal code or data, not part of the user interface.
--
Philippe.
Quoted 51 lines · Ronny Meeus
Quoted 29 lines · Philippe Gerum
Quoted 18 lines · Ronny Meeus
Quoted 10 lines · Philippe Gerum
Quoted 9 lines · Ronny Meeus
This patch introduces a weak function in the mercury copperplate code that allows to put an upper limit on the priority used by the created thread objects.
Before this patch the complete OS scheduler's FIFO range was used and it was not possible to restrict it. Restricting it can be useful in case other activities (typically platform related things) need to get a higher priority than the application threads.
Quoted 6 lines
Quoted 2 lines
The example below shows what needs to be implemented in the application to restrict the range.
This looks weird. Any reason not to fix up the priority of your application threads?
Quoted 9 lines
Philippe,
this is not only about the application threads. We also need to lower the priorities
used by the copperplate for the timer-thread and the task-lock priority. The reason for this is that we need to run certain Linux kernel threads at a higher
priority than any of the application threads, including Xenomai.Quoted 7 lines
That means that your system is running in some sort of sandboxed non-rt environment that may be subject to priority throttling by other parts of the system even for critical events, which is an interesting concept, but makes the Xenomai system inherently non-rt in this case. Such approach is not transposable to the Cobalt core running natively on the hw, and that is another issue in my eyes.
Philippe,
our use-case is a system that is ported from a native pSOS system so we are actually after the pSOS interface. The RT aspect is less important for us since we only have a 'soft' real-time systems, e.g. no strict deadlines.
We also had issues in the past that Linux RCU handling caused kernel issues and we had to enable the
CONFIG_RCU_BOOSToption. To be on the safe side, we configured theRCU_BOOSTpriority to be higher than the prios used by the application, including the Xenomai threads. For this to work we needed to create some "gap" between the MAX prio supported by the scheduler and the max prio used by the apps.
Quoted 3 lines
Note that the critical events in our case are not handled by the Xenomai applications, but by the Linux kernel event handlers (running in kernel threads).
Ok, for Mercury this may make sense after all.
Quoted 8 lines
Quoted 7 lines
I don't like the idea at all, but I will think of it anyway, to figure out whether this is compatible with some basic assumptions in Mercury. Bottom line is that adding yet another weak routine to get this is not the way to go, that would prevent multiple tuning points to co-exist into a single executable. At the very least, that would have to be a copperplate tunable.
Quoted 4 lines
I will provide a patch later that uses a tunable to configure this. The weak implementation was inspired by the prio mapping function that exists for the pSOS skin ...
The priority mapping routine operates on an input value which is call-specific, so you need an actual routine there. Besides, providing different implementations of it within the same pSOS application process would make no sense, so the restriction I mentioned does not apply for this one anyway.
Signature · 1 line
Philippe.