Apply Juha Vierinen patch to allow variable USRP2 rx buffer size
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Mon, 11 May 2009 15:31:33 +0000 (15:31 +0000)
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Mon, 11 May 2009 15:31:33 +0000 (15:31 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11000 221aa14e-8319-0410-a670-987f0aec2ac5

usrp2/host/include/usrp2/usrp2.h
usrp2/host/lib/eth_buffer.cc
usrp2/host/lib/usrp2.cc
usrp2/host/lib/usrp2_impl.cc
usrp2/host/lib/usrp2_impl.h

index e80eda3e404d2aadfb5e4bfefb4616bea95c3139..f4086440ec2413979386a9748b2390cd7a2377f0 100644 (file)
@@ -86,7 +86,7 @@ namespace usrp2 {
      *              If \p addr is HH:HH, it's treated as if it were 00:50:c2:85:HH:HH
      *              "" will autoselect a USRP2 if there is only a single one on the local ethernet.
      */
-    static sptr make(const std::string &ifc, const std::string &addr="");
+    static sptr make(const std::string &ifc, const std::string &addr="", size_t rx_bufsize=0);
 
     /*!
      * Class destructor
@@ -578,10 +578,10 @@ namespace usrp2 {
 
   private:
     // Static function to retrieve or create usrp2 instance
-    static sptr find_existing_or_make_new(const std::string &ifc, props *p);
+    static sptr find_existing_or_make_new(const std::string &ifc, props *p, size_t rx_bufsize);
 
     // Only class members can instantiate this class
-    usrp2(const std::string &ifc, props *p);
+    usrp2(const std::string &ifc, props *p, size_t rx_bufsize);
   
     // All private state is held in opaque pointer
     std::auto_ptr<impl> d_impl;
index 7970ab87a50ceb707d8022f90d212d359b875386..1042868f38c60ce054eaa242e9fe19ec56e6e235 100644 (file)
@@ -44,8 +44,9 @@
 #define DEBUG_LOG(X)
 #endif
 
-#define MAX_MEM_SIZE       25e6 // ~0.25s @ 100 MB/s
-#define MAX_SLAB_SIZE    131702 // 128 KB (FIXME fish out of /proc/slabinfo)
+#define DEFAULT_MEM_SIZE   25e6 // ~0.25s @ 100 MB/s
+#define MAX_MEM_SIZE     1000e6 // ~10.00s @ 100 MB/s. 
+#define MAX_SLAB_SIZE    131072 // 128 KB (FIXME fish out of /proc/slabinfo)
 #define MAX_PKT_SIZE       1512 // we don't do jumbo frames
 
 namespace usrp2 {
@@ -55,7 +56,7 @@ namespace usrp2 {
       d_frame_size(0), d_head(0), d_ring(0), d_ethernet(new ethernet())
   {
     if (rx_bufsize == 0)
-      d_buflen = (size_t)MAX_MEM_SIZE;
+      d_buflen = (size_t)DEFAULT_MEM_SIZE;
     else
       d_buflen = std::min((size_t)MAX_MEM_SIZE, rx_bufsize);
        
@@ -92,8 +93,8 @@ namespace usrp2 {
     req.tp_block_size = page_size << (int)ceil(log2(npages));
 
     // Calculate number of blocks
-    req.tp_block_nr = std::min((int)(MAX_SLAB_SIZE/sizeof(void*)),
-                              (int)(d_buflen/req.tp_block_size));
+    req.tp_block_nr = (int)(d_buflen/req.tp_block_size);
+                              
 
     // Recalculate buffer length
     d_buflen = req.tp_block_nr*req.tp_block_size;
index 8160d01fa3e94ea9e1b5c07e3e96e79b4fd100f1..f48d467cac6491f5127e0056d0f19d1b7ca3978e 100644 (file)
@@ -49,7 +49,7 @@ namespace usrp2 {
   static usrp_table s_table;
 
   usrp2::sptr
-  usrp2::find_existing_or_make_new(const std::string &ifc, props *pr)
+  usrp2::find_existing_or_make_new(const std::string &ifc, props *pr, size_t rx_bufsize)
   {
     std::string key = ifc + ":" + pr->addr;
 
@@ -69,7 +69,7 @@ namespace usrp2 {
     // We don't have the USRP2 we're looking for
 
     // create a new one and stick it in the table.
-    usrp2::sptr r(new usrp2::usrp2(ifc, pr));
+    usrp2::sptr r(new usrp2::usrp2(ifc, pr, rx_bufsize));
     usrp_table_entry t(key, r);
     s_table.push_back(t);
 
@@ -119,7 +119,7 @@ namespace usrp2 {
   }
 
   usrp2::sptr
-  usrp2::make(const std::string &ifc, const std::string &addr)
+  usrp2::make(const std::string &ifc, const std::string &addr, size_t rx_bufsize)
   {
     std::string naddr = "";
     if (addr != "" && !parse_mac_addr(addr, naddr))
@@ -138,12 +138,12 @@ namespace usrp2 {
     if (n > 1)
       throw std::runtime_error("Multiple USRPs found on interface; must select by MAC address.");
 
-    return find_existing_or_make_new(ifc, &u2s[0]);
+    return find_existing_or_make_new(ifc, &u2s[0], rx_bufsize);
   }
 
   // Private constructor.  Sole function is to create an impl.
-  usrp2::usrp2(const std::string &ifc, props *p)
-    : d_impl(new usrp2::impl(ifc, p))
+  usrp2::usrp2(const std::string &ifc, props *p, size_t rx_bufsize)
+    : d_impl(new usrp2::impl(ifc, p, rx_bufsize))
   {
     // NOP
   }
index ae8735c1378e7b941c9ed90c3db3d08acdb243af..1ecfd7348e65a5bf79b521591b69f49ff8e725fc 100644 (file)
@@ -128,8 +128,8 @@ namespace usrp2 {
   }
 
 
-  usrp2::impl::impl(const std::string &ifc, props *p)
-    : d_eth_buf(new eth_buffer()), d_interface_name(ifc), d_pf(0), d_bg_thread(0),
+  usrp2::impl::impl(const std::string &ifc, props *p, size_t rx_bufsize)
+    : d_eth_buf(new eth_buffer(rx_bufsize)), d_interface_name(ifc), d_pf(0), d_bg_thread(0),
       d_bg_running(false), d_rx_seqno(-1), d_tx_seqno(0), d_next_rid(0),
       d_num_rx_frames(0), d_num_rx_missing(0), d_num_rx_overruns(0), d_num_rx_bytes(0), 
       d_num_enqueued(0), d_enqueued_mutex(), d_bg_pending_cond(&d_enqueued_mutex),
index c96a6fad3616dd50be4c37a29540bd0ccbd0dc5d..ec96f3a7095d8692c0c9c8ec4ff73d33072d227c 100644 (file)
@@ -113,7 +113,7 @@ namespace usrp2 {
     bool reset_db();
 
   public:
-    impl(const std::string &ifc, props *p);
+    impl(const std::string &ifc, props *p, size_t rx_bufsize);
     ~impl();
     
     void bg_loop();