summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim O'Shea <tim.oshea753@gmail.com>2013-06-05 10:52:22 -0400
committerTim O'Shea <tim.oshea753@gmail.com>2013-06-05 14:20:37 -0400
commit2df6f769ce2cd026d92778ded780941ac3a0da0c (patch)
tree6ae067e8e75fdd65f97755690cd483fe592304ba
parent9c154832f1db9a7cc0a8ebe33e8798541335caf1 (diff)
runtime: adding thread priority methods to gr::block
-rw-r--r--gnuradio-runtime/include/gnuradio/block.h16
-rw-r--r--gnuradio-runtime/include/gnuradio/block_detail.h12
-rw-r--r--gnuradio-runtime/include/gnuradio/thread/thread.h12
-rw-r--r--gnuradio-runtime/lib/block.cc28
-rw-r--r--gnuradio-runtime/lib/block_detail.cc16
-rw-r--r--gnuradio-runtime/lib/thread/thread.cc50
-rw-r--r--gnuradio-runtime/lib/tpb_thread_body.cc5
-rw-r--r--gnuradio-runtime/swig/block.i5
8 files changed, 143 insertions, 1 deletions
diff --git a/gnuradio-runtime/include/gnuradio/block.h b/gnuradio-runtime/include/gnuradio/block.h
index fd6c48c29b..114f68ddcf 100644
--- a/gnuradio-runtime/include/gnuradio/block.h
+++ b/gnuradio-runtime/include/gnuradio/block.h
@@ -542,6 +542,21 @@ namespace gr {
*/
std::vector<int> processor_affinity() { return d_affinity; }
+ /*!
+ * \brief Get the current thread priority in use
+ */
+ int active_thread_priority();
+
+ /*!
+ * \brief Get the current thread priority stored
+ */
+ int thread_priority();
+
+ /*!
+ * \brief Set the current thread priority
+ */
+ int set_thread_priority(int priority);
+
// ----------------------------------------------------------------------------
private:
@@ -558,6 +573,7 @@ namespace gr {
int d_min_noutput_items;
tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream
std::vector<int> d_affinity; // thread affinity proc. mask
+ int d_priority; // thread priority level
bool d_pc_rpc_set;
protected:
diff --git a/gnuradio-runtime/include/gnuradio/block_detail.h b/gnuradio-runtime/include/gnuradio/block_detail.h
index a76874a9be..b7531baf6d 100644
--- a/gnuradio-runtime/include/gnuradio/block_detail.h
+++ b/gnuradio-runtime/include/gnuradio/block_detail.h
@@ -184,6 +184,18 @@ namespace gr {
*/
void unset_processor_affinity();
+ /*!
+ * \brief Get the current thread priority
+ */
+ int thread_priority();
+
+ /*!
+ * \brief Set the current thread priority
+ *
+ * \param priority the new thread priority to set
+ */
+ int set_thread_priority(int priority);
+
bool threaded; // set if thread is currently running.
gr::thread::gr_thread_t thread; // portable thread handle
diff --git a/gnuradio-runtime/include/gnuradio/thread/thread.h b/gnuradio-runtime/include/gnuradio/thread/thread.h
index 04d67d0821..a0c9e4f09d 100644
--- a/gnuradio-runtime/include/gnuradio/thread/thread.h
+++ b/gnuradio-runtime/include/gnuradio/thread/thread.h
@@ -138,6 +138,18 @@ namespace gr {
*/
GR_RUNTIME_API void thread_unbind(gr_thread_t thread);
+ /*! \brief get current thread priority for a given thread ID
+ *
+ * Note: this does not work on OSX
+ */
+ GR_RUNTIME_API int thread_priority(gr_thread_t thread);
+
+ /*! \brief get current thread priority for a given thread ID
+ *
+ * Note: this does not work on OSX
+ */
+ GR_RUNTIME_API int set_thread_priority(gr_thread_t thread, int priority);
+
} /* namespace thread */
} /* namespace gr */
diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc
index 4246180d80..0165365b9e 100644
--- a/gnuradio-runtime/lib/block.cc
+++ b/gnuradio-runtime/lib/block.cc
@@ -50,7 +50,8 @@ namespace gr {
d_tag_propagation_policy(TPP_ALL_TO_ALL),
d_pc_rpc_set(false),
d_max_output_buffer(std::max(output_signature->max_streams(),1), -1),
- d_min_output_buffer(std::max(output_signature->max_streams(),1), -1)
+ d_min_output_buffer(std::max(output_signature->max_streams(),1), -1),
+ d_priority(-1)
{
global_block_registry.register_primitive(alias(), this);
@@ -318,6 +319,31 @@ namespace gr {
}
}
+ int
+ block::active_thread_priority()
+ {
+ if(d_detail) {
+ return d_detail->thread_priority();
+ }
+ return -1;
+ }
+
+ int
+ block::thread_priority()
+ {
+ return d_priority;
+ }
+
+ int
+ block::set_thread_priority(int priority)
+ {
+ d_priority = priority;
+ if(d_detail) {
+ return d_detail->set_thread_priority(priority);
+ }
+ return d_priority;
+ }
+
float
block::pc_noutput_items()
{
diff --git a/gnuradio-runtime/lib/block_detail.cc b/gnuradio-runtime/lib/block_detail.cc
index 8d149be848..0be22bf5b7 100644
--- a/gnuradio-runtime/lib/block_detail.cc
+++ b/gnuradio-runtime/lib/block_detail.cc
@@ -240,6 +240,22 @@ namespace gr {
}
}
+ int
+ block_detail::thread_priority(){
+ if(threaded) {
+ return gr::thread::thread_priority(thread);
+ }
+ return -1;
+ }
+
+ int
+ block_detail::set_thread_priority(int priority){
+ if(threaded) {
+ return gr::thread::set_thread_priority(thread,priority);
+ }
+ return -1;
+ }
+
void
block_detail::start_perf_counters()
{
diff --git a/gnuradio-runtime/lib/thread/thread.cc b/gnuradio-runtime/lib/thread/thread.cc
index 1727dc6621..d79d1a0129 100644
--- a/gnuradio-runtime/lib/thread/thread.cc
+++ b/gnuradio-runtime/lib/thread/thread.cc
@@ -97,6 +97,20 @@ namespace gr {
}
}
+ int
+ thread_priority(gr_thread_t thread)
+ {
+ // Not implemented on Windows
+ return -1;
+ }
+
+ int
+ set_thread_priority(gr_thread_t thread, int priority)
+ {
+ // Not implemented on Windows
+ return -1;
+ }
+
} /* namespace thread */
} /* namespace gr */
@@ -148,6 +162,20 @@ namespace gr {
// Not implemented on OSX
}
+ int
+ thread_priority(gr_thread_t thread)
+ {
+ // Not implemented on OSX
+ return -1;
+ }
+
+ int
+ set_thread_priority(gr_thread_t thread, int priority)
+ {
+ // Not implemented on OSX
+ return -1;
+ }
+
} /* namespace thread */
} /* namespace gr */
@@ -232,6 +260,28 @@ namespace gr {
}
}
+ int
+ thread_priority(gr_thread_t thread)
+ {
+ sched_param param;
+ int priority;
+ int policy;
+ int ret;
+ ret = pthread_getschedparam (thread, &policy, &param);
+ priority = param.sched_priority;
+ return (ret==0)?priority:ret;
+ }
+
+ int
+ set_thread_priority(gr_thread_t thread, int priority)
+ {
+ int policy;
+ struct sched_param param;
+ pthread_getschedparam (thread, &policy, &param);
+ param.sched_priority = priority;
+ return pthread_setschedparam(thread, policy, &param);
+ }
+
} /* namespace thread */
} /* namespace gr */
diff --git a/gnuradio-runtime/lib/tpb_thread_body.cc b/gnuradio-runtime/lib/tpb_thread_body.cc
index ceb94fbb2a..c49594c931 100644
--- a/gnuradio-runtime/lib/tpb_thread_body.cc
+++ b/gnuradio-runtime/lib/tpb_thread_body.cc
@@ -52,6 +52,11 @@ namespace gr {
gr::thread::thread_bind_to_processor(d->thread, block->processor_affinity());
}
+ // Set thread priority if it was set before fg was started
+ if(block->thread_priority() > 0) {
+ gr::thread::set_thread_priority(d->thread, block->thread_priority());
+ }
+
while(1) {
boost::this_thread::interruption_point();
diff --git a/gnuradio-runtime/swig/block.i b/gnuradio-runtime/swig/block.i
index f697089185..0ad5825bbe 100644
--- a/gnuradio-runtime/swig/block.i
+++ b/gnuradio-runtime/swig/block.i
@@ -88,6 +88,11 @@ class gr::block : public gr::basic_block
void unset_processor_affinity();
std::vector<int> processor_affinity();
+ // Methods to manage thread priority
+ int active_thread_priority();
+ int thread_priority();
+ int set_thread_priority(int priority);
+
// internal use
//block_detail_sptr detail () const { return d_detail; }
//void set_detail (block_detail_sptr detail) { d_detail = detail; }