[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8563 - in usrp2/trunk/host-ng: apps lib
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8563 - in usrp2/trunk/host-ng: apps lib |
Date: |
Sat, 7 Jun 2008 16:41:10 -0600 (MDT) |
Author: jcorgan
Date: 2008-06-07 16:41:09 -0600 (Sat, 07 Jun 2008)
New Revision: 8563
Added:
usrp2/trunk/host-ng/apps/test_eth.cc
Modified:
usrp2/trunk/host-ng/apps/
usrp2/trunk/host-ng/apps/Makefile.am
usrp2/trunk/host-ng/apps/test.sh
usrp2/trunk/host-ng/apps/test_usrp2.cc
usrp2/trunk/host-ng/lib/eth_buffer.cc
usrp2/trunk/host-ng/lib/eth_buffer.h
Log:
work-in-progress
Property changes on: usrp2/trunk/host-ng/apps
___________________________________________________________________
Name: svn:ignore
- Makefile
Makefile.in
.libs
.deps
test_usrp2
cerr
+ Makefile
Makefile.in
.libs
.deps
test_eth
test_usrp2
cerr
*.sh
Modified: usrp2/trunk/host-ng/apps/Makefile.am
===================================================================
--- usrp2/trunk/host-ng/apps/Makefile.am 2008-06-07 21:42:05 UTC (rev
8562)
+++ usrp2/trunk/host-ng/apps/Makefile.am 2008-06-07 22:41:09 UTC (rev
8563)
@@ -24,10 +24,14 @@
$(GNURADIO_CORE_LIBS)
noinst_PROGRAMS = \
- test_usrp2
+ test_usrp2 \
+ test_eth
test_usrp2_SOURCES = \
test_usrp2.cc
+test_eth_SOURCES = \
+ test_eth.cc
+
TESTS = \
- test_usrp2
+ test_eth
Modified: usrp2/trunk/host-ng/apps/test.sh
===================================================================
--- usrp2/trunk/host-ng/apps/test.sh 2008-06-07 21:42:05 UTC (rev 8562)
+++ usrp2/trunk/host-ng/apps/test.sh 2008-06-07 22:41:09 UTC (rev 8563)
@@ -1,5 +1,5 @@
#!/bin/sh
-sudo ./test_usrp2 2>cerr
+sudo ./test_eth 2>cerr
Added: usrp2/trunk/host-ng/apps/test_eth.cc
===================================================================
--- usrp2/trunk/host-ng/apps/test_eth.cc (rev 0)
+++ usrp2/trunk/host-ng/apps/test_eth.cc 2008-06-07 22:41:09 UTC (rev
8563)
@@ -0,0 +1,38 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <../lib/eth_buffer.h>
+#include <gr_realtime.h>
+#include <iostream>
+
+int
+main(int argc, char **argv)
+{
+ gr_rt_status_t rt = gr_enable_realtime_scheduling();
+ if (rt != RT_OK)
+ std::cerr << "Failed to enable realtime scheduling" << std::endl;
+
+ usrp2::eth_buffer buf(16e6);
+ bool ok = buf.open("eth0", 0xBEEF);
+
+ return ok ? 0 : 1;
+}
Modified: usrp2/trunk/host-ng/apps/test_usrp2.cc
===================================================================
--- usrp2/trunk/host-ng/apps/test_usrp2.cc 2008-06-07 21:42:05 UTC (rev
8562)
+++ usrp2/trunk/host-ng/apps/test_usrp2.cc 2008-06-07 22:41:09 UTC (rev
8563)
@@ -33,8 +33,8 @@
usrp2::usrp2::sptr u2 = usrp2::usrp2::make("eth0");
-// u2->set_rx_gain(1.0);
-// u2->set_rx_freq(0.0, NULL);
+ u2->set_rx_gain(1.0);
+ u2->set_rx_freq(0.0, NULL);
u2->set_rx_decim(5);
u2->start_rx_streaming();
Modified: usrp2/trunk/host-ng/lib/eth_buffer.cc
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.cc 2008-06-07 21:42:05 UTC (rev
8562)
+++ usrp2/trunk/host-ng/lib/eth_buffer.cc 2008-06-07 22:41:09 UTC (rev
8563)
@@ -22,8 +22,19 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+
#include "eth_buffer.h"
+#include "ethernet.h"
+#include <linux/if_packet.h> // FIXME autoconf
+#include <iostream>
+#include <cmath>
+#define ETH_BUFFER_DEBUG 1 // define to 0 or 1
+
+#define MAX_MEM_SIZE 25e6 // ~0.25s @ 100 MB/s
+#define MAX_SLAB_SIZE 131702 // 128 KB (FIXME fish out of /proc/slabinfo)
+#define MAX_PKT_SIZE 1512 // we don't do jumbo frames
+
namespace usrp2 {
eth_buffer::handler::~handler()
@@ -31,4 +42,76 @@
// default nop destructor
}
-};
+ eth_buffer::eth_buffer(size_t rx_bufsize)
+ : d_fd(0),
+ d_ethernet(new ethernet())
+ {
+ if (ETH_BUFFER_DEBUG)
+ std::cerr << "eth_buffer: constructor" << std::endl;
+
+ if (rx_bufsize == 0)
+ d_buflen = MAX_MEM_SIZE;
+ else
+ d_buflen = std::min((size_t)MAX_MEM_SIZE, rx_bufsize);
+
+ d_fd = d_ethernet->fd();
+ memset(d_mac, 0, sizeof(d_mac));
+ }
+
+ eth_buffer::~eth_buffer()
+ {
+ if (ETH_BUFFER_DEBUG)
+ std::cerr << "eth_buffer: destructor" << std::endl;
+
+ d_ethernet->close();
+ }
+
+ bool eth_buffer::open(const std::string &ifname, int protocol)
+ {
+ if (ETH_BUFFER_DEBUG)
+ std::cerr << "eth_buffer: using interface " << ifname
+ << ", protocol=" << protocol << std::endl;
+
+ if (!d_ethernet->open(ifname, protocol)) {
+ std::cerr << "eth_buffer: unable to open interface "
+ << ifname << std::endl;
+ return false;
+ }
+
+ struct tpacket_req req;
+ size_t page_size = getpagesize();
+
+ // Calculate minimum power-of-two aligned size for frames
+ req.tp_frame_size = pow(2,
ceil(log2(TPACKET_ALIGN(TPACKET_HDRLEN)+TPACKET_ALIGN(MAX_PKT_SIZE))));
+
+ // Calculate minimum contiguous pages needed to enclose a frame
+ int npages = (page_size > req.tp_frame_size) ? 1 :
ceil(req.tp_frame_size/page_size);
+ req.tp_block_size = page_size << (int)ceil(log2(npages));
+
+ // Calculate maximum number of blocks kernel can handle
+ int max_blocks = MAX_SLAB_SIZE/sizeof(void *);
+
+ // Calculate actual number of blocks
+ req.tp_block_nr = std::min((int)(MAX_SLAB_SIZE/sizeof(void*)),
+ (int)(d_buflen/req.tp_block_size));
+
+ // Recalculate buffer length
+ d_buflen = req.tp_block_nr*req.tp_block_size;
+
+ // Finally, calculate total number of frames
+ req.tp_frame_nr = d_buflen/req.tp_frame_size;
+
+ if (ETH_BUFFER_DEBUG)
+ std::cerr << "eth_buffer:"
+ << " frame_size=" << req.tp_frame_size
+ << " block_size=" << req.tp_block_size
+ << " block_nr=" << req.tp_block_nr
+ << " frame_nr=" << req.tp_frame_nr
+ << " buflen=" << d_buflen
+ << std::endl;
+
+ return true;
+ }
+
+} // namespace usrp2
+
Modified: usrp2/trunk/host-ng/lib/eth_buffer.h
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.h 2008-06-07 21:42:05 UTC (rev
8562)
+++ usrp2/trunk/host-ng/lib/eth_buffer.h 2008-06-07 22:41:09 UTC (rev
8563)
@@ -26,9 +26,10 @@
#include "pktfilter.h"
#include "eth_common.h"
-
namespace usrp2 {
+ class ethernet;
+
/*!
* \brief high-performance interface to send and receive raw
* ethernet frames with out-of-order retirement of received frames.
@@ -41,7 +42,10 @@
int d_fd; // socket file descriptor
uint8_t d_mac[6]; // our mac address
+ size_t d_buflen; // length of our buffer
+ std::auto_ptr<ethernet> d_ethernet; // our underlying interface
+
public:
//
----------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8563 - in usrp2/trunk/host-ng: apps lib,
jcorgan <=