discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] End-to-end delay question


From: Michael Dickens
Subject: Re: [Discuss-gnuradio] End-to-end delay question
Date: Thu, 24 May 2007 10:30:10 -0400

Here's my first cut at the realtime change for pthreads. This compiles on OSX cleanly, and seems to work ... I enabled the printout for now, as feedback for anyone trying "realtime" using pthreads. I set the PRI to be 1/2 way between the current value and the max (looks like 39). I changed the config/m4 file for grc_usrp to check for "pthread_setschedparam" right after it checks for "sched_setscheduler", since this looks like only place where this routine is checked for in the GNU Radio config/m4 files. - MLD

% svn diff
Index: gnuradio-core/src/lib/runtime/gr_realtime.cc
===================================================================
--- gnuradio-core/src/lib/runtime/gr_realtime.cc        (revision 5537)
+++ gnuradio-core/src/lib/runtime/gr_realtime.cc        (working copy)
@@ -58,6 +58,42 @@
   return RT_OK;
}
+#elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
+
+#include <pthread.h>
+
+gr_rt_status_t
+gr_enable_realtime_scheduling()
+{
+  int policy = 0;
+  int pri = 0;
+  pthread_t this_thread = pthread_self ();  // this process
+  struct sched_param param;
+  memset (&param, 0, sizeof (param));
+  param.sched_priority = pri;
+  int result = pthread_getschedparam (this_thread, &policy, &param);
+  if (result == 0) { // good results
+    // set the priority half-way between the default and maximum
+    pri = (sched_get_priority_max (policy) + param.sched_priority) / 2;
+
+    int policy = SCHED_FIFO;   // desired policy
+    struct sched_param param;
+    memset (&param, 0, sizeof (struct sched_param));
+    param.sched_priority = pri;
+    result = pthread_setschedparam (this_thread, policy, &param);
+  }
+  if (result != 0) {
+    if (errno == EPERM)
+      return RT_NO_PRIVS;
+    else {
+ perror ("pthread_setschedparam: failed to set real time priority");
+      return RT_OTHER_ERROR;
+    }
+  }
+  printf ("SCHED_FIFO enabled with priority = %d\n", pri);
+  return RT_OK;
+}
+
// #elif // could try negative niceness
#else
Index: config/grc_usrp.m4
===================================================================
--- config/grc_usrp.m4  (revision 5537)
+++ config/grc_usrp.m4  (working copy)
@@ -52,7 +52,7 @@
     # These checks don't fail
     AC_C_BIGENDIAN
     AC_CHECK_HEADERS([byteswap.h linux/compiler.h])
-    AC_CHECK_FUNCS([getrusage sched_setscheduler])
+ AC_CHECK_FUNCS([getrusage sched_setscheduler pthread_setschedparam])
     AC_CHECK_FUNCS([sigaction snprintf])
     passed=yes







reply via email to

[Prev in Thread] Current Thread [Next in Thread]