summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib
diff options
context:
space:
mode:
authorJosh Morman <jmorman@perspectalabs.com>2021-03-02 08:04:18 -0500
committermormj <34754695+mormj@users.noreply.github.com>2021-03-08 06:33:09 -0500
commit032ac81a4cddc36f7d184500a5bb2e7d8419014b (patch)
tree1c4f92f719a2d0ae6570647c01dec11296177c90 /gnuradio-runtime/lib
parentc85b2eeffb235b085bd8f934cb52e073510fd3ad (diff)
runtime: clean up realtime impl namespace
Signed-off-by: Josh Morman <jmorman@perspectalabs.com>
Diffstat (limited to 'gnuradio-runtime/lib')
-rw-r--r--gnuradio-runtime/lib/realtime.cc3
-rw-r--r--gnuradio-runtime/lib/realtime_impl.cc28
-rw-r--r--gnuradio-runtime/lib/realtime_impl.h67
3 files changed, 83 insertions, 15 deletions
diff --git a/gnuradio-runtime/lib/realtime.cc b/gnuradio-runtime/lib/realtime.cc
index 95ff75df20..29caf7fd66 100644
--- a/gnuradio-runtime/lib/realtime.cc
+++ b/gnuradio-runtime/lib/realtime.cc
@@ -12,13 +12,14 @@
#include <config.h>
#endif
+#include "realtime_impl.h"
#include <gnuradio/realtime.h>
namespace gr {
rt_status_t enable_realtime_scheduling()
{
- return gr::impl::enable_realtime_scheduling();
+ return gr::realtime::enable_realtime_scheduling();
}
} /* namespace gr */
diff --git a/gnuradio-runtime/lib/realtime_impl.cc b/gnuradio-runtime/lib/realtime_impl.cc
index 6cbb52ff8e..6820a63660 100644
--- a/gnuradio-runtime/lib/realtime_impl.cc
+++ b/gnuradio-runtime/lib/realtime_impl.cc
@@ -12,9 +12,9 @@
#include <config.h>
#endif
+#include "realtime_impl.h"
#include <gnuradio/logger.h>
#include <gnuradio/prefs.h>
-#include <gnuradio/realtime_impl.h>
#ifdef HAVE_SCHED_H
#include <sched.h>
@@ -32,7 +32,7 @@
#include <pthread.h>
namespace gr {
-namespace impl {
+namespace realtime {
/*!
* Rescale our virtual priority so that it maps to the middle 1/2 of
@@ -42,13 +42,13 @@ static int rescale_virtual_pri(int virtual_pri, int min_real_pri, int max_real_p
{
float rmin = min_real_pri + (0.25 * (max_real_pri - min_real_pri));
float rmax = min_real_pri + (0.75 * (max_real_pri - min_real_pri));
- float m = (rmax - rmin) / (rt_priority_max() - rt_priority_min());
- float y = m * (virtual_pri - rt_priority_min()) + rmin;
+ float m = (rmax - rmin) / (s_rt_priority_max - s_rt_priority_min);
+ float y = m * (virtual_pri - s_rt_priority_min) + rmin;
int y_int = static_cast<int>(rintf(y));
return std::max(min_real_pri, std::min(max_real_pri, y_int));
}
-} // namespace impl
+} // namespace realtime
} // namespace gr
#endif
@@ -59,7 +59,7 @@ static int rescale_virtual_pri(int virtual_pri, int min_real_pri, int max_real_p
#include <windows.h>
namespace gr {
-namespace impl {
+namespace realtime {
rt_status_t enable_realtime_scheduling(rt_sched_param p)
{
@@ -73,7 +73,7 @@ rt_status_t enable_realtime_scheduling(rt_sched_param p)
THREAD_PRIORITY_BELOW_NORMAL, THREAD_PRIORITY_NORMAL,
THREAD_PRIORITY_ABOVE_NORMAL, THREAD_PRIORITY_HIGHEST,
THREAD_PRIORITY_TIME_CRITICAL };
- const double priority = double(p.priority) / (rt_priority_max() - rt_priority_min());
+ const double priority = double(p.priority) / (s_rt_priority_max - s_rt_priority_min);
size_t pri_index = size_t((priority + 1.0) * 6 / 2.0); // -1 -> 0, +1 -> 6
pri_index %= sizeof(priorities) / sizeof(*priorities); // range check
@@ -85,13 +85,13 @@ rt_status_t enable_realtime_scheduling(rt_sched_param p)
return RT_OK;
}
-} // namespace impl
+} // namespace realtime
} // namespace gr
#elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
namespace gr {
-namespace impl {
+namespace realtime {
rt_status_t enable_realtime_scheduling(rt_sched_param p)
{
@@ -126,14 +126,14 @@ rt_status_t enable_realtime_scheduling(rt_sched_param p)
return RT_OK;
}
-} // namespace impl
+} // namespace realtime
} // namespace gr
#elif defined(HAVE_SCHED_SETSCHEDULER)
namespace gr {
-namespace impl {
+namespace realtime {
rt_status_t enable_realtime_scheduling(rt_sched_param p)
{
@@ -167,17 +167,17 @@ rt_status_t enable_realtime_scheduling(rt_sched_param p)
return RT_OK;
}
-} // namespace impl
+} // namespace realtime
} // namespace gr
#else
namespace gr {
-namespace impl {
+namespace realtime {
rt_status_t enable_realtime_scheduling(rt_sched_param p) { return RT_NOT_IMPLEMENTED; }
-} // namespace impl
+} // namespace realtime
} // namespace gr
#endif
diff --git a/gnuradio-runtime/lib/realtime_impl.h b/gnuradio-runtime/lib/realtime_impl.h
new file mode 100644
index 0000000000..6194f9236c
--- /dev/null
+++ b/gnuradio-runtime/lib/realtime_impl.h
@@ -0,0 +1,67 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2008,2013 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#ifndef INCLUDED_GNURADIO_REALTIME_H
+#define INCLUDED_GNURADIO_REALTIME_H
+
+#include <gnuradio/api.h>
+#include <gnuradio/realtime.h>
+#include <stdexcept>
+
+/*!
+ * \brief System independent way to ask for realtime scheduling
+ */
+namespace gr {
+namespace realtime {
+/*
+ * Define the range for our virtual priorities (don't change
+ * these)
+ *
+ * Processes (or threads) with numerically higher priority values
+ * are scheduled before processes with numerically lower priority
+ * values. Thus, the value returned by s_rt_priority_max will be
+ * greater than the value returned by s_rt_priority_min.
+ */
+static const int s_rt_priority_min = 0;
+static const int s_rt_priority_max = 15;
+static const int s_rt_priority_default = 1;
+
+struct GR_RUNTIME_API rt_sched_param {
+ int priority;
+ rt_sched_policy policy;
+
+ rt_sched_param() : priority(s_rt_priority_default), policy(RT_SCHED_RR) {}
+
+ rt_sched_param(int priority_, rt_sched_policy policy_ = RT_SCHED_RR)
+ {
+ if (priority_ < s_rt_priority_min || priority_ > s_rt_priority_max)
+ throw std::invalid_argument("rt_sched_param: priority out of range");
+
+ priority = priority_;
+ policy = policy_;
+ }
+};
+
+/*!
+ * \brief If possible, enable "realtime" scheduling.
+ * \ingroup misc
+ *
+ * In general, this means that the code will be scheduled before
+ * any non-realtime (normal) processes. Note that if your code
+ * contains an non-blocking infinite loop and you enable realtime
+ * scheduling, it's possible to hang the system.
+ */
+
+GR_RUNTIME_API rt_status_t enable_realtime_scheduling(rt_sched_param = rt_sched_param());
+
+} /* namespace realtime */
+} /* namespace gr */
+
+#endif /* INCLUDED_GNURADIO_REALTIME_H */