diff options
author | Michael West <michael.west@ettus.com> | 2013-11-08 15:30:03 -0800 |
---|---|---|
committer | Michael West <michael.west@ettus.com> | 2013-11-08 15:30:03 -0800 |
commit | 597e7965a7bd9a0fc76a5acbaf260b05e42c474c (patch) | |
tree | 39f0a3beaa1fe1046dabc050d3c3921aae3b292c /host/lib/transport/libusb1_base.cpp | |
parent | c357a16e21bffe61a066f62b44096eced8f7962a (diff) | |
download | uhd-597e7965a7bd9a0fc76a5acbaf260b05e42c474c.tar.gz uhd-597e7965a7bd9a0fc76a5acbaf260b05e42c474c.tar.bz2 uhd-597e7965a7bd9a0fc76a5acbaf260b05e42c474c.zip |
BUG #183: B200 High CPU Usage: Created a single thread to handle libusb events and expanded packet size to 16k
Diffstat (limited to 'host/lib/transport/libusb1_base.cpp')
-rw-r--r-- | host/lib/transport/libusb1_base.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp index 0ef53db0a..4cf3ea17d 100644 --- a/host/lib/transport/libusb1_base.cpp +++ b/host/lib/transport/libusb1_base.cpp @@ -19,10 +19,12 @@ #include <uhd/exception.hpp> #include <uhd/utils/msg.hpp> #include <uhd/utils/log.hpp> +#include <uhd/utils/tasks.hpp> #include <uhd/types/dict.hpp> #include <boost/weak_ptr.hpp> #include <boost/thread/mutex.hpp> #include <boost/foreach.hpp> +#include <boost/bind.hpp> #include <cstdlib> #include <iostream> @@ -37,9 +39,11 @@ public: libusb_session_impl(void){ UHD_ASSERT_THROW(libusb_init(&_context) == 0); libusb_set_debug(_context, debug_level); + task_handler = task::make(boost::bind(&libusb_session_impl::libusb_event_handler_task, this, _context)); } ~libusb_session_impl(void){ + task_handler.reset(); libusb_exit(_context); } @@ -49,6 +53,21 @@ public: private: libusb_context *_context; + task::sptr task_handler; + + /* + * Task to handle libusb events. There should only be one thread per libusb_context handling events. + * Using more than one thread can result in excessive CPU usage in kernel space (presumably from locking/waiting). + * The libusb documentation says it is safe, which it is, but it neglects to state the cost in CPU usage. + * Just don't do it! + */ + UHD_INLINE void libusb_event_handler_task(libusb_context *context) + { + timeval tv; + tv.tv_sec = 0; + tv.tv_usec = 100000; + libusb_handle_events_timeout(context, &tv); + } }; libusb::session::sptr libusb::session::get_global_session(void){ |