aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-05-14 17:11:05 -0700
committerJosh Blum <josh@joshknows.com>2011-05-14 20:28:20 -0700
commitea5ce50a465e714c63196f52df97fb3e927e701c (patch)
treed69b081995d483ebb43d0971e48e401cd35c1a53
parent4b772ff4f3b1e388e150402beaf6567f3ea29e1c (diff)
downloaduhd-ea5ce50a465e714c63196f52df97fb3e927e701c.tar.gz
uhd-ea5ce50a465e714c63196f52df97fb3e927e701c.tar.bz2
uhd-ea5ce50a465e714c63196f52df97fb3e927e701c.zip
uhd: replace managed buffer shared pointer w/ intrusive pointer to reduce overhead
-rw-r--r--host/include/uhd/transport/zero_copy.hpp31
-rw-r--r--host/lib/CMakeLists.txt4
-rw-r--r--host/lib/transport/libusb1_zero_copy.cpp12
-rw-r--r--host/lib/transport/udp_zero_copy.cpp12
-rw-r--r--host/lib/usrp/usrp1/io_impl.cpp19
-rw-r--r--host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp12
6 files changed, 39 insertions, 51 deletions
diff --git a/host/include/uhd/transport/zero_copy.hpp b/host/include/uhd/transport/zero_copy.hpp
index 092028d09..f80c738aa 100644
--- a/host/include/uhd/transport/zero_copy.hpp
+++ b/host/include/uhd/transport/zero_copy.hpp
@@ -21,9 +21,16 @@
#include <uhd/config.hpp>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
+#include <boost/intrusive_ptr.hpp>
namespace uhd{ namespace transport{
+ //! Create smart pointer to a reusable managed buffer
+ template <typename T> UHD_INLINE boost::intrusive_ptr<T> make_managed_buffer(T *p){
+ p->_ref_count = 1; //reset the count to 1 reference
+ return boost::intrusive_ptr<T>(p, false);
+ }
+
/*!
* A managed receive buffer:
* Contains a reference to transport-managed memory,
@@ -31,7 +38,7 @@ namespace uhd{ namespace transport{
*/
class UHD_API managed_recv_buffer{
public:
- typedef boost::shared_ptr<managed_recv_buffer> sptr;
+ typedef boost::intrusive_ptr<managed_recv_buffer> sptr;
/*!
* Signal to the transport that we are done with the buffer.
@@ -59,8 +66,18 @@ namespace uhd{ namespace transport{
private:
virtual const void *get_buff(void) const = 0;
virtual size_t get_size(void) const = 0;
+
+ public: int _ref_count;
};
+ UHD_INLINE void intrusive_ptr_add_ref(managed_recv_buffer *p){
+ ++(p->_ref_count);
+ }
+
+ UHD_INLINE void intrusive_ptr_release(managed_recv_buffer *p){
+ if (--(p->_ref_count) == 0) p->release();
+ }
+
/*!
* A managed send buffer:
* Contains a reference to transport-managed memory,
@@ -68,7 +85,7 @@ namespace uhd{ namespace transport{
*/
class UHD_API managed_send_buffer{
public:
- typedef boost::shared_ptr<managed_send_buffer> sptr;
+ typedef boost::intrusive_ptr<managed_send_buffer> sptr;
/*!
* Signal to the transport that we are done with the buffer.
@@ -97,8 +114,18 @@ namespace uhd{ namespace transport{
private:
virtual void *get_buff(void) const = 0;
virtual size_t get_size(void) const = 0;
+
+ public: int _ref_count;
};
+ UHD_INLINE void intrusive_ptr_add_ref(managed_send_buffer *p){
+ ++(p->_ref_count);
+ }
+
+ UHD_INLINE void intrusive_ptr_release(managed_send_buffer *p){
+ if (--(p->_ref_count) == 0) p->commit(0);
+ }
+
/*!
* A zero-copy interface for transport objects.
* Provides a way to get send and receive buffers
diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt
index fca4730d8..ebb211566 100644
--- a/host/lib/CMakeLists.txt
+++ b/host/lib/CMakeLists.txt
@@ -15,10 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-#Creating a shared pointer itself has allocation overhead.
-#Define the quick allocator to reduce fast-path overhead.
-ADD_DEFINITIONS(-DBOOST_SP_USE_QUICK_ALLOCATOR)
-
########################################################################
# Helpful Macros
########################################################################
diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp
index d4cfab422..28bea978b 100644
--- a/host/lib/transport/libusb1_zero_copy.cpp
+++ b/host/lib/transport/libusb1_zero_copy.cpp
@@ -73,14 +73,10 @@ public:
sptr get_new(void){
_expired = false;
- return sptr(this, &libusb_zero_copy_mrb::fake_deleter);
+ return make_managed_buffer(this);
}
private:
- static void fake_deleter(void *obj){
- static_cast<libusb_zero_copy_mrb *>(obj)->release();
- }
-
const void *get_buff(void) const{return _lut->buffer;}
size_t get_size(void) const{return _lut->actual_length;}
@@ -108,14 +104,10 @@ public:
sptr get_new(void){
_expired = false;
- return sptr(this, &libusb_zero_copy_msb::fake_deleter);
+ return make_managed_buffer(this);
}
private:
- static void fake_deleter(void *obj){
- static_cast<libusb_zero_copy_msb *>(obj)->commit(0);
- }
-
void *get_buff(void) const{return _lut->buffer;}
size_t get_size(void) const{return _lut->length;}
diff --git a/host/lib/transport/udp_zero_copy.cpp b/host/lib/transport/udp_zero_copy.cpp
index c3ba085bf..8c97e1e99 100644
--- a/host/lib/transport/udp_zero_copy.cpp
+++ b/host/lib/transport/udp_zero_copy.cpp
@@ -52,16 +52,12 @@ public:
sptr get_new(size_t len){
_len = len;
- return sptr(this, &udp_zero_copy_asio_mrb::fake_deleter);
+ return make_managed_buffer(this);
}
template <class T> T cast(void) const{return static_cast<T>(_mem);}
private:
- static void fake_deleter(void *obj){
- static_cast<udp_zero_copy_asio_mrb *>(obj)->release();
- }
-
const void *get_buff(void) const{return _mem;}
size_t get_size(void) const{return _len;}
@@ -90,14 +86,10 @@ public:
sptr get_new(size_t len){
_len = len;
- return sptr(this, &udp_zero_copy_asio_msb::fake_deleter);
+ return make_managed_buffer(this);
}
private:
- static void fake_deleter(void *obj){
- static_cast<udp_zero_copy_asio_msb *>(obj)->commit(0);
- }
-
void *get_buff(void) const{return _mem;}
size_t get_size(void) const{return _len;}
diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp
index 7252ac587..8ac2696eb 100644
--- a/host/lib/usrp/usrp1/io_impl.cpp
+++ b/host/lib/usrp/usrp1/io_impl.cpp
@@ -61,39 +61,28 @@ class offset_managed_send_buffer : public managed_send_buffer{
public:
typedef boost::function<void(offset_send_buffer&, offset_send_buffer&, size_t)> commit_cb_type;
offset_managed_send_buffer(const commit_cb_type &commit_cb):
- _expired(true), _commit_cb(commit_cb)
+ _commit_cb(commit_cb)
{
/* NOP */
}
- bool expired(void){return _expired;}
-
void commit(size_t size){
- if (_expired) return;
- this->_commit_cb(_curr_buff, _next_buff, size);
- _expired = true;
+ if (size != 0) this->_commit_cb(_curr_buff, _next_buff, size);
}
sptr get_new(
offset_send_buffer &curr_buff,
offset_send_buffer &next_buff
){
- _expired = false;
_curr_buff = curr_buff;
_next_buff = next_buff;
- return sptr(this, &offset_managed_send_buffer::fake_deleter);
+ return make_managed_buffer(this);
}
private:
- static void fake_deleter(void *){
- //dont do anything and assume the bastard committed it
- //static_cast<offset_managed_send_buffer *>(obj)->commit(0);
- }
-
void *get_buff(void) const{return _curr_buff.buff->cast<char *>() + _curr_buff.offset;}
size_t get_size(void) const{return _curr_buff.buff->size() - _curr_buff.offset;}
- bool _expired;
offset_send_buffer _curr_buff, _next_buff;
commit_cb_type _commit_cb;
};
@@ -210,7 +199,7 @@ void usrp1_impl::io_impl::flush_send_buff(void){
bool usrp1_impl::io_impl::get_send_buffs(
vrt_packet_handler::managed_send_buffs_t &buffs
){
- UHD_ASSERT_THROW(omsb.expired() and buffs.size() == 1);
+ UHD_ASSERT_THROW(buffs.size() == 1);
//try to get a new managed buffer with timeout
offset_send_buffer next_buff(data_transport->get_send_buff(send_timeout));
diff --git a/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp b/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp
index 26774aeda..bb421507a 100644
--- a/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp
+++ b/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp
@@ -51,14 +51,10 @@ public:
sptr get_new(void){
if (fp_verbose) UHD_LOGV(always) << " make_recv_buff: " << get_size() << std::endl;
_info->flags = RB_USER_PROCESS; //claim the frame
- return sptr(this, &usrp_e100_mmap_zero_copy_mrb::fake_deleter);
+ return make_managed_buffer(this);
}
private:
- static void fake_deleter(void *obj){
- static_cast<usrp_e100_mmap_zero_copy_mrb *>(obj)->release();
- }
-
const void *get_buff(void) const{return _mem;}
size_t get_size(void) const{return _info->len;}
@@ -90,14 +86,10 @@ public:
sptr get_new(void){
if (fp_verbose) UHD_LOGV(always) << " make_send_buff: " << get_size() << std::endl;
_info->flags = RB_USER_PROCESS; //claim the frame
- return sptr(this, &usrp_e100_mmap_zero_copy_msb::fake_deleter);
+ return make_managed_buffer(this);
}
private:
- static void fake_deleter(void *obj){
- static_cast<usrp_e100_mmap_zero_copy_msb *>(obj)->commit(0);
- }
-
void *get_buff(void) const{return _mem;}
size_t get_size(void) const{return _len;}