aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorAndrej Rode <andrej.rode@ettus.com>2017-04-18 16:46:44 -0700
committerMartin Braun <martin.braun@ettus.com>2017-06-29 13:43:05 -0700
commitc33928d2bbdd27688c3475e77fc461e7d16eba5a (patch)
treed5bffc49696e2bc03c9b8576864e387373b950fb /host/lib
parent47cdd6319c74a7b823843aad5ff3fa370ed1e6ef (diff)
downloaduhd-c33928d2bbdd27688c3475e77fc461e7d16eba5a.tar.gz
uhd-c33928d2bbdd27688c3475e77fc461e7d16eba5a.tar.bz2
uhd-c33928d2bbdd27688c3475e77fc461e7d16eba5a.zip
utils: add set_thread_name API call, move thread_priority to thread
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/transport/super_send_packet_handler.hpp1
-rw-r--r--host/lib/transport/zero_copy_recv_offload.cpp2
-rw-r--r--host/lib/usrp/common/fifo_ctrl_excelsior.cpp2
-rw-r--r--host/lib/usrp/device3/device3_io_impl.cpp3
-rw-r--r--host/lib/usrp/usrp2/io_impl.cpp2
-rw-r--r--host/lib/usrp/x300/x300_impl.cpp2
-rw-r--r--host/lib/utils/CMakeLists.txt36
-rw-r--r--host/lib/utils/tasks.cpp13
-rw-r--r--host/lib/utils/thread.cpp (renamed from host/lib/utils/thread_priority.cpp)14
-rw-r--r--host/lib/utils/thread_priority_c.cpp2
10 files changed, 64 insertions, 13 deletions
diff --git a/host/lib/transport/super_send_packet_handler.hpp b/host/lib/transport/super_send_packet_handler.hpp
index 12c053efb..75ba7260b 100644
--- a/host/lib/transport/super_send_packet_handler.hpp
+++ b/host/lib/transport/super_send_packet_handler.hpp
@@ -26,6 +26,7 @@
#include <uhd/utils/log.hpp>
#include <uhd/utils/tasks.hpp>
#include <uhd/utils/byteswap.hpp>
+#include <uhd/utils/thread.hpp>
#include <uhd/types/metadata.hpp>
#include <uhd/transport/vrt_if_packet.hpp>
#include <uhd/transport/zero_copy.hpp>
diff --git a/host/lib/transport/zero_copy_recv_offload.cpp b/host/lib/transport/zero_copy_recv_offload.cpp
index 5de2cd44d..e8f75be84 100644
--- a/host/lib/transport/zero_copy_recv_offload.cpp
+++ b/host/lib/transport/zero_copy_recv_offload.cpp
@@ -21,6 +21,7 @@
#include <uhd/utils/log.hpp>
#include <uhd/utils/safe_call.hpp>
+#include <uhd/utils/thread.hpp>
#include <boost/format.hpp>
#include <boost/make_shared.hpp>
#include <boost/thread/mutex.hpp>
@@ -54,6 +55,7 @@ public:
_recv_thread = boost::thread(
boost::bind(&zero_copy_recv_offload_impl::enqueue_recv, this)
);
+ set_thread_name(&_recv_thread, "zero_copy_recv");
}
// Receive thread flags
diff --git a/host/lib/usrp/common/fifo_ctrl_excelsior.cpp b/host/lib/usrp/common/fifo_ctrl_excelsior.cpp
index c86380354..0a93f44e8 100644
--- a/host/lib/usrp/common/fifo_ctrl_excelsior.cpp
+++ b/host/lib/usrp/common/fifo_ctrl_excelsior.cpp
@@ -22,7 +22,7 @@
#include <uhd/utils/byteswap.hpp>
#include <uhd/utils/tasks.hpp>
#include <uhd/utils/safe_call.hpp>
-#include <uhd/utils/thread_priority.hpp>
+#include <uhd/utils/thread.hpp>
#include <uhd/transport/vrt_if_packet.hpp>
#include <uhd/transport/bounded_buffer.hpp>
#include <boost/thread/mutex.hpp>
diff --git a/host/lib/usrp/device3/device3_io_impl.cpp b/host/lib/usrp/device3/device3_io_impl.cpp
index 374232972..9795afae5 100644
--- a/host/lib/usrp/device3/device3_io_impl.cpp
+++ b/host/lib/usrp/device3/device3_io_impl.cpp
@@ -849,7 +849,8 @@ tx_streamer::sptr device3_impl::get_tx_stream(const uhd::stream_args_t &args_)
my_streamer->_async_xport.recv,
xport.endianness,
tick_rate_retriever
- )
+ ),
+ "tx_async_msgs_task"
);
blk_ctrl->sr_write(uhd::rfnoc::SR_CLEAR_RX_FC, 0xc1ea12, block_port);
diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp
index 8f6a67453..967b53c88 100644
--- a/host/lib/usrp/usrp2/io_impl.cpp
+++ b/host/lib/usrp/usrp2/io_impl.cpp
@@ -27,7 +27,7 @@
#include <uhd/utils/tasks.hpp>
#include <uhd/exception.hpp>
#include <uhd/utils/byteswap.hpp>
-#include <uhd/utils/thread_priority.hpp>
+#include <uhd/utils/thread.hpp>
#include <uhd/transport/bounded_buffer.hpp>
#include <boost/thread/thread.hpp>
#include <boost/format.hpp>
diff --git a/host/lib/usrp/x300/x300_impl.cpp b/host/lib/usrp/x300/x300_impl.cpp
index 40288b54c..1c8eeab51 100644
--- a/host/lib/usrp/x300/x300_impl.cpp
+++ b/host/lib/usrp/x300/x300_impl.cpp
@@ -712,7 +712,7 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr)
if (not try_to_claim(mb.zpu_ctrl)) {
throw uhd::runtime_error("Failed to claim device");
}
- mb.claimer_task = uhd::task::make(boost::bind(&x300_impl::claimer_loop, this, mb.zpu_ctrl));
+ mb.claimer_task = uhd::task::make(boost::bind(&x300_impl::claimer_loop, this, mb.zpu_ctrl), "x300_claimer");
//extract the FW path for the X300
//and live load fw over ethernet link
diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt
index f76c5763a..a053846c6 100644
--- a/host/lib/utils/CMakeLists.txt
+++ b/host/lib/utils/CMakeLists.txt
@@ -51,9 +51,11 @@ CHECK_CXX_SOURCE_COMPILES("
" HAVE_WIN_SETTHREADPRIORITY
)
+
+
IF(HAVE_PTHREAD_SETSCHEDPARAM)
MESSAGE(STATUS " Priority scheduling supported through pthread_setschedparam.")
- SET(THREAD_PRIO_DEFS HAVE_PTHREAD_SETSCHEDPARAM)
+ LIST(APPEND THREAD_PRIO_DEFS HAVE_PTHREAD_SETSCHEDPARAM)
LIBUHD_APPEND_LIBS(pthread)
ELSEIF(HAVE_WIN_SETTHREADPRIORITY)
MESSAGE(STATUS " Priority scheduling supported through windows SetThreadPriority.")
@@ -63,8 +65,36 @@ ELSE()
SET(THREAD_PRIO_DEFS HAVE_THREAD_PRIO_DUMMY)
ENDIF()
+SET(CMAKE_REQUIRED_LIBRARIES "pthread")
+
+CHECK_CXX_SOURCE_COMPILES("
+ #include <pthread.h>
+ int main(){
+ pthread_t pt;
+ const char* pt_name = \"test\";
+ pthread_setname_np(pt, pt_name);
+ return 0;
+ }
+ " HAVE_PTHREAD_SETNAME
+)
+
+IF(CYGWIN)
+ #SCHED_RR non-operational on cygwin
+ SET(HAVE_PTHREAD_SETNAME False)
+ENDIF(CYGWIN)
+
+IF(HAVE_PTHREAD_SETNAME)
+ MESSAGE(STATUS " Setting thread names is supported through pthread_setname_np.")
+ LIST(APPEND THREAD_PRIO_DEFS HAVE_PTHREAD_SETNAME)
+ LIBUHD_APPEND_LIBS(pthread)
+ELSE()
+ MESSAGE(STATUS " Setting thread names is not supported.")
+ LIST(APPEND THREAD_PRIO_DEFS HAVE_THREAD_SETNAME_DUMMY)
+ENDIF()
+
+
SET_SOURCE_FILES_PROPERTIES(
- ${CMAKE_CURRENT_SOURCE_DIR}/thread_priority.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/thread.cpp
PROPERTIES COMPILE_DEFINITIONS "${THREAD_PRIO_DEFS}"
)
@@ -146,7 +176,7 @@ LIBUHD_APPEND_SOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/platform.cpp
${CMAKE_CURRENT_SOURCE_DIR}/static.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tasks.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/thread_priority.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/thread.cpp
)
IF(ENABLE_C_API)
diff --git a/host/lib/utils/tasks.cpp b/host/lib/utils/tasks.cpp
index 38d19502e..fb9a3052e 100644
--- a/host/lib/utils/tasks.cpp
+++ b/host/lib/utils/tasks.cpp
@@ -17,6 +17,7 @@
#include <uhd/utils/tasks.hpp>
#include <uhd/utils/msg_task.hpp>
+#include <uhd/utils/thread.hpp>
#include <uhd/utils/log.hpp>
#include <uhd/exception.hpp>
#include <boost/thread/thread.hpp>
@@ -32,10 +33,15 @@ using namespace uhd;
class task_impl : public task{
public:
- task_impl(const task_fcn_type &task_fcn):
+ task_impl(const task_fcn_type &task_fcn, const std::string &name):
_exit(false)
{
_task = std::thread([this, task_fcn](){ this->task_loop(task_fcn); });
+ if (not name.empty()) {
+#ifdef HAVE_PTHREAD_SETNAME
+ pthread_setname_np(_task->native_handle(), name.substr(0,16).c_str());
+#endif /* HAVE_PTHREAD_SETNAME */
+ }
}
~task_impl(void){
@@ -46,7 +52,6 @@ public:
}
private:
-
void task_loop(const task_fcn_type &task_fcn){
try{
while (!_exit){
@@ -73,8 +78,8 @@ private:
std::thread _task;
};
-task::sptr task::make(const task_fcn_type &task_fcn){
- return task::sptr(new task_impl(task_fcn));
+task::sptr task::make(const task_fcn_type &task_fcn, const std::string &name){
+ return task::sptr(new task_impl(task_fcn, name));
}
msg_task::~msg_task(void){
diff --git a/host/lib/utils/thread_priority.cpp b/host/lib/utils/thread.cpp
index 729edcf0a..9100cfd7b 100644
--- a/host/lib/utils/thread_priority.cpp
+++ b/host/lib/utils/thread.cpp
@@ -15,7 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-#include <uhd/utils/thread_priority.hpp>
+#include <uhd/utils/thread.hpp>
#include <uhd/utils/log.hpp>
#include <uhd/exception.hpp>
#include <boost/format.hpp>
@@ -108,3 +108,15 @@ static void check_priority_range(float priority){
}
#endif /* HAVE_THREAD_PRIO_DUMMY */
+
+void uhd::set_thread_name(
+ boost::thread *thrd,
+ const std::string &name
+) {
+#ifdef HAVE_PTHREAD_SETNAME
+ pthread_setname_np(thrd->native_handle(), name.substr(0,16).c_str());
+#endif /* HAVE_PTHREAD_SETNAME */
+#ifdef HAVE_THREAD_SETNAME_DUMMY
+ UHD_LOG_DEBUG("UHD", "Setting thread name is not implemented; wanted to set to " << name);
+#endif /* HAVE_THREAD_SETNAME_DUMMY */
+}
diff --git a/host/lib/utils/thread_priority_c.cpp b/host/lib/utils/thread_priority_c.cpp
index b2de9970d..822126d4a 100644
--- a/host/lib/utils/thread_priority_c.cpp
+++ b/host/lib/utils/thread_priority_c.cpp
@@ -17,7 +17,7 @@
#include <uhd/error.h>
#include <uhd/utils/thread_priority.h>
-#include <uhd/utils/thread_priority.hpp>
+#include <uhd/utils/thread.hpp>
#include <uhd/utils/log.hpp>
#include <uhd/exception.hpp>
#include <boost/format.hpp>