osaf/libs/core/common/daemon.c |  11 ++++++++++-
 osaf/libs/core/leap/os_defs.c  |  21 +++++++++++++++++++--
 2 files changed, 29 insertions(+), 3 deletions(-)


OpenSAF will now fall back to the SCHED_OTHER scheduling policy when it fails
to set a real-time scheduling policy.

diff --git a/osaf/libs/core/common/daemon.c b/osaf/libs/core/common/daemon.c
--- a/osaf/libs/core/common/daemon.c
+++ b/osaf/libs/core/common/daemon.c
@@ -254,7 +254,16 @@ void daemonize(int argc, char *argv[])
                policy = strtol(thread_policy, NULL, 0);
 
        param.sched_priority = prio_val;
-       if (sched_setscheduler(0, policy, &param) == -1) {
+       int result = sched_setscheduler(0, policy, &param);
+       if (result == -1 && errno == EPERM && policy != SCHED_OTHER) {
+               LOG_WA("sched_setscheduler failed with EPERM, falling back to "
+                       "SCHED_OTHER policy for %s", basename(argv[0]));
+               policy = SCHED_OTHER;
+               prio_val = sched_get_priority_min(policy);
+               param.sched_priority = prio_val;
+               result = sched_setscheduler(0, policy, &param);
+       }
+       if (result == -1) {
                syslog(LOG_ERR, "Could not set scheduling class for %s", 
strerror(errno));
                if( (!strncmp("osafamfwd", basename(argv[0]), 9)) || 
(!strncmp("osafamfnd", basename(argv[0]), 9))) 
                {
diff --git a/osaf/libs/core/leap/os_defs.c b/osaf/libs/core/leap/os_defs.c
--- a/osaf/libs/core/leap/os_defs.c
+++ b/osaf/libs/core/leap/os_defs.c
@@ -52,6 +52,7 @@
 #include "ncssysf_def.h"
 #include "osaf_utility.h"
 #include "osaf_time.h"
+#include "logtrace.h"
 
 NCS_OS_LOCK gl_ncs_atomic_mtx;
 #ifndef NDEBUG
@@ -222,12 +223,28 @@ unsigned int ncs_os_task(NCS_OS_TASK *ta
                        rc = pthread_create(task->info.create.o_handle, &attr,
                                            (void *(*)(void 
*))task->info.create.i_entry_point,
                                            task->info.create.i_ep_arg);
+                       if (rc == EPERM && policy != SCHED_OTHER) {
+                               LOG_WA("pthread_create failed with EPERM, "
+                                       "falling back to SCHED_OTHER policy "
+                                       "for %s", task->info.create.i_name);
+                               policy = SCHED_OTHER;
+                               sp.sched_priority = 
sched_get_priority_min(policy);
+                               rc = pthread_attr_setschedpolicy(&attr, policy);
+                               if (rc != 0) osaf_abort(rc);
+                               rc = pthread_attr_setschedparam(&attr, &sp);
+                               if (rc != 0) osaf_abort(rc);
+                               rc = pthread_create(task->info.create.o_handle,
+                                       &attr,
+                                       (void *(*)(void *))task->info.create.
+                                       i_entry_point,
+                                       task->info.create.i_ep_arg);
+                       }
                        if (rc != 0) {
                                if (policy == SCHED_RR || policy == SCHED_FIFO)
-                                       syslog(LOG_ERR, "Creation of real-time 
thread '%s' FAILED - '%s'",
+                                       LOG_ER("Creation of real-time thread 
'%s' FAILED - %s",
                                                        
task->info.create.i_name, strerror(rc));
                                else
-                                       syslog(LOG_ERR, "Creation of thread 
'%s' FAILED - '%s'",
+                                       LOG_ER("Creation of thread '%s' FAILED 
- %s",
                                                        
task->info.create.i_name, strerror(rc));
                                free(task->info.create.o_handle);
                                return NCSCC_RC_FAILURE;

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to