diff options
author | Josh Morman <jmorman@perspectalabs.com> | 2021-03-02 08:04:18 -0500 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-03-08 06:33:09 -0500 |
commit | 032ac81a4cddc36f7d184500a5bb2e7d8419014b (patch) | |
tree | 1c4f92f719a2d0ae6570647c01dec11296177c90 | |
parent | c85b2eeffb235b085bd8f934cb52e073510fd3ad (diff) |
runtime: clean up realtime impl namespace
Signed-off-by: Josh Morman <jmorman@perspectalabs.com>
-rw-r--r-- | gnuradio-runtime/include/gnuradio/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gnuradio-runtime/include/gnuradio/realtime.h | 8 | ||||
-rw-r--r-- | gnuradio-runtime/lib/realtime.cc | 3 | ||||
-rw-r--r-- | gnuradio-runtime/lib/realtime_impl.cc | 28 | ||||
-rw-r--r-- | gnuradio-runtime/lib/realtime_impl.h (renamed from gnuradio-runtime/include/gnuradio/realtime_impl.h) | 27 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gr/bindings/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gr/bindings/python_bindings.cc | 2 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gr/bindings/realtime_impl_python.cc | 81 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gr/bindings/realtime_python.cc | 16 |
9 files changed, 44 insertions, 123 deletions
diff --git a/gnuradio-runtime/include/gnuradio/CMakeLists.txt b/gnuradio-runtime/include/gnuradio/CMakeLists.txt index d8e9c193ee..4789a71bbe 100644 --- a/gnuradio-runtime/include/gnuradio/CMakeLists.txt +++ b/gnuradio-runtime/include/gnuradio/CMakeLists.txt @@ -44,7 +44,6 @@ install(FILES pycallback_object.h random.h realtime.h - realtime_impl.h runtime_types.h tags.h tagged_stream_block.h diff --git a/gnuradio-runtime/include/gnuradio/realtime.h b/gnuradio-runtime/include/gnuradio/realtime.h index 0d639aedcd..50a99f4b4d 100644 --- a/gnuradio-runtime/include/gnuradio/realtime.h +++ b/gnuradio-runtime/include/gnuradio/realtime.h @@ -12,10 +12,16 @@ #define INCLUDED_GR_REALTIME_H #include <gnuradio/api.h> -#include <gnuradio/realtime_impl.h> namespace gr { +typedef enum { RT_OK = 0, RT_NOT_IMPLEMENTED, RT_NO_PRIVS, RT_OTHER_ERROR } rt_status_t; + +enum rt_sched_policy { + RT_SCHED_RR = 0, // round robin + RT_SCHED_FIFO = 1, // first in first out +}; + /*! * \brief If possible, enable high-priority "real time" scheduling. * \ingroup misc 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/include/gnuradio/realtime_impl.h b/gnuradio-runtime/lib/realtime_impl.h index 741302af99..6194f9236c 100644 --- a/gnuradio-runtime/include/gnuradio/realtime_impl.h +++ b/gnuradio-runtime/lib/realtime_impl.h @@ -12,43 +12,36 @@ #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 { - -typedef enum { RT_OK = 0, RT_NOT_IMPLEMENTED, RT_NO_PRIVS, RT_OTHER_ERROR } rt_status_t; - -enum rt_sched_policy { - RT_SCHED_RR = 0, // round robin - RT_SCHED_FIFO = 1, // first in first out -}; - -namespace impl { +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 rt_priority_max() will be - * greater than the value returned by rt_priority_min(). + * values. Thus, the value returned by s_rt_priority_max will be + * greater than the value returned by s_rt_priority_min. */ -static inline int rt_priority_min() { return 0; } -static inline int rt_priority_max() { return 15; } -static inline int rt_priority_default() { return 1; } +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(rt_priority_default()), policy(RT_SCHED_RR) {} + 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_ < rt_priority_min() || priority_ > rt_priority_max()) + if (priority_ < s_rt_priority_min || priority_ > s_rt_priority_max) throw std::invalid_argument("rt_sched_param: priority out of range"); priority = priority_; @@ -68,7 +61,7 @@ struct GR_RUNTIME_API rt_sched_param { GR_RUNTIME_API rt_status_t enable_realtime_scheduling(rt_sched_param = rt_sched_param()); -} /* namespace impl */ +} /* namespace realtime */ } /* namespace gr */ #endif /* INCLUDED_GNURADIO_REALTIME_H */ diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/CMakeLists.txt b/gnuradio-runtime/python/gnuradio/gr/bindings/CMakeLists.txt index 1ad05942e9..17b1a30590 100644 --- a/gnuradio-runtime/python/gnuradio/gr/bindings/CMakeLists.txt +++ b/gnuradio-runtime/python/gnuradio/gr/bindings/CMakeLists.txt @@ -46,7 +46,6 @@ messages/msg_queue_python.cc # pycallback_object_python.cc random_python.cc realtime_python.cc - realtime_impl_python.cc # rpcbufferedget_python.cc # rpccallbackregister_base_python.cc # rpcmanager_python.cc diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/python_bindings.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/python_bindings.cc index 8c8fe73c17..8307fa8790 100644 --- a/gnuradio-runtime/python/gnuradio/gr/bindings/python_bindings.cc +++ b/gnuradio-runtime/python/gnuradio/gr/bindings/python_bindings.cc @@ -56,7 +56,6 @@ void bind_prefs(py::module&); // void bind_pycallback_object(py::module&); void bind_random(py::module&); void bind_realtime(py::module&); -void bind_realtime_impl(py::module&); // void bind_rpcbufferedget(py::module&); // void bind_rpccallbackregister_base(py::module&); // void bind_rpcmanager(py::module&); @@ -157,7 +156,6 @@ PYBIND11_MODULE(gr_python, m) // // bind_pycallback_object(m); bind_random(m); bind_realtime(m); - bind_realtime_impl(m); // // bind_rpcbufferedget(m); // // bind_rpccallbackregister_base(m); // // bind_rpcmanager(m); diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/realtime_impl_python.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/realtime_impl_python.cc deleted file mode 100644 index 9ed1664ac3..0000000000 --- a/gnuradio-runtime/python/gnuradio/gr/bindings/realtime_impl_python.cc +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2020 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -/***********************************************************************************/ -/* This file is automatically generated using bindtool and can be manually edited */ -/* The following lines can be configured to regenerate this file during cmake */ -/* If manual edits are made, the following tags should be modified accordingly. */ -/* BINDTOOL_GEN_AUTOMATIC(0) */ -/* BINDTOOL_USE_PYGCCXML(0) */ -/* BINDTOOL_HEADER_FILE(realtime_impl.h) */ -/* BINDTOOL_HEADER_FILE_HASH(8b8e4e0cddb41c563e239c4f532d06e1) */ -/***********************************************************************************/ - -#include <pybind11/complex.h> -#include <pybind11/pybind11.h> -#include <pybind11/stl.h> - -namespace py = pybind11; - -#include <gnuradio/realtime_impl.h> -// pydoc.h is automatically generated in the build directory -#include <realtime_impl_pydoc.h> - -void bind_realtime_impl(py::module& m) -{ - - - py::enum_<::gr::rt_status_t>(m, "rt_status_t") - .value("RT_OK", ::gr::RT_OK) // 0 - .value("RT_NOT_IMPLEMENTED", ::gr::RT_NOT_IMPLEMENTED) // 1 - .value("RT_NO_PRIVS", ::gr::RT_NO_PRIVS) // 2 - .value("RT_OTHER_ERROR", ::gr::RT_OTHER_ERROR) // 3 - .export_values(); - py::enum_<::gr::rt_sched_policy>(m, "rt_sched_policy") - .value("RT_SCHED_RR", ::gr::RT_SCHED_RR) // 0 - .value("RT_SCHED_FIFO", ::gr::RT_SCHED_FIFO) // 1 - .export_values(); - - - py::module m_impl = m.def_submodule("impl"); - - using rt_sched_param = ::gr::impl::rt_sched_param; - - - py::class_<rt_sched_param, std::shared_ptr<rt_sched_param>>( - m_impl, "rt_sched_param", D(impl, rt_sched_param)) - - .def(py::init<>(), D(impl, rt_sched_param, rt_sched_param, 0)) - .def(py::init<int, gr::rt_sched_policy>(), - py::arg("priority_"), - py::arg("policy_") = ::gr::rt_sched_policy::RT_SCHED_RR, - D(impl, rt_sched_param, rt_sched_param, 1)) - .def(py::init<gr::impl::rt_sched_param const&>(), - py::arg("arg0"), - D(impl, rt_sched_param, rt_sched_param, 2)) - - ; - - - m_impl.def("rt_priority_min", &::gr::impl::rt_priority_min, D(impl, rt_priority_min)); - - - m_impl.def("rt_priority_max", &::gr::impl::rt_priority_max, D(impl, rt_priority_max)); - - - m_impl.def("rt_priority_default", - &::gr::impl::rt_priority_default, - D(impl, rt_priority_default)); - - - m_impl.def("enable_realtime_scheduling", - &::gr::impl::enable_realtime_scheduling, - py::arg("arg0") = gr::impl::rt_sched_param(), - D(impl, enable_realtime_scheduling)); -} diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/realtime_python.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/realtime_python.cc index 5efd134281..3770ee9aa1 100644 --- a/gnuradio-runtime/python/gnuradio/gr/bindings/realtime_python.cc +++ b/gnuradio-runtime/python/gnuradio/gr/bindings/realtime_python.cc @@ -14,7 +14,7 @@ /* BINDTOOL_GEN_AUTOMATIC(0) */ /* BINDTOOL_USE_PYGCCXML(0) */ /* BINDTOOL_HEADER_FILE(realtime.h) */ -/* BINDTOOL_HEADER_FILE_HASH(3a8add4fc688853c32e8c4c8f8e51d0e) */ +/* BINDTOOL_HEADER_FILE_HASH(4fe8778231103a1a91b8032daec80655) */ /***********************************************************************************/ #include <pybind11/complex.h> @@ -29,12 +29,18 @@ namespace py = pybind11; void bind_realtime(py::module& m) { - + py::enum_<::gr::rt_status_t>(m, "rt_status_t") + .value("RT_OK", ::gr::RT_OK) // 0 + .value("RT_NOT_IMPLEMENTED", ::gr::RT_NOT_IMPLEMENTED) // 1 + .value("RT_NO_PRIVS", ::gr::RT_NO_PRIVS) // 2 + .value("RT_OTHER_ERROR", ::gr::RT_OTHER_ERROR) // 3 + .export_values(); + py::enum_<::gr::rt_sched_policy>(m, "rt_sched_policy") + .value("RT_SCHED_RR", ::gr::RT_SCHED_RR) // 0 + .value("RT_SCHED_FIFO", ::gr::RT_SCHED_FIFO) // 1 + .export_values(); m.def("enable_realtime_scheduling", &::gr::enable_realtime_scheduling, D(enable_realtime_scheduling)); - - - py::module m_impl = m.def_submodule("impl"); } |