[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 86/148: Removed the channel ring from the e
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 86/148: Removed the channel ring from the eth transport. Made the eth transport a data handler to pass directly to the eth buffer, and to strip ethernet headers/transport information. |
Date: |
Mon, 15 Aug 2016 00:47:27 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
nwest pushed a commit to annotated tag old_usrp_devel_udp
in repository gnuradio.
commit 3e3bec6e9c307644eff791457611db23fb339ff2
Author: Josh Blum <address@hidden>
Date: Wed Dec 16 12:34:39 2009 -0800
Removed the channel ring from the eth transport.
Made the eth transport a data handler to pass directly to the eth buffer,
and to strip ethernet headers/transport information.
---
usrp2/host/lib/Makefile.am | 2 -
usrp2/host/lib/eth_buffer.cc | 52 -------------
usrp2/host/lib/eth_buffer.h | 1 -
usrp2/host/lib/eth_data_transport.cc | 141 ++++++++++++++---------------------
usrp2/host/lib/eth_data_transport.h | 11 +--
usrp2/host/lib/ring.cc | 81 --------------------
usrp2/host/lib/ring.h | 88 ----------------------
usrp2/host/lib/usrp2_impl.cc | 2 +-
8 files changed, 60 insertions(+), 318 deletions(-)
diff --git a/usrp2/host/lib/Makefile.am b/usrp2/host/lib/Makefile.am
index 2a14256..cfccac3 100644
--- a/usrp2/host/lib/Makefile.am
+++ b/usrp2/host/lib/Makefile.am
@@ -43,7 +43,6 @@ libusrp2_la_SOURCES = \
find.cc \
open_usrp2_socket.cc \
pktfilter.cc \
- ring.cc \
rx_nop_handler.cc \
rx_sample_handler.cc \
strtod_si.c \
@@ -66,7 +65,6 @@ noinst_HEADERS = \
ethernet.h \
open_usrp2_socket.h \
pktfilter.h \
- ring.h \
transport.h \
usrp2_bytesex.h \
usrp2_impl.h
diff --git a/usrp2/host/lib/eth_buffer.cc b/usrp2/host/lib/eth_buffer.cc
index cba60bd..bd37061 100644
--- a/usrp2/host/lib/eth_buffer.cc
+++ b/usrp2/host/lib/eth_buffer.cc
@@ -234,58 +234,6 @@ namespace usrp2 {
return EB_OK;
}
-std::vector<iovec>
- eth_buffer::rx_framev(int timeout_in_ms)
- {
- std::vector<iovec> iovs;
- DEBUG_LOG("\n");
-
- while (!frame_available()) {
- if (timeout_in_ms == 0) {
- DEBUG_LOG("w");
- return iovs;
- }
-
- struct pollfd pfd;
- pfd.fd = d_fd;
- pfd.revents = 0;
- pfd.events = POLLIN;
-
- DEBUG_LOG("P");
-
- int pres = poll(&pfd, 1, timeout_in_ms);
- if (pres == -1) {
- perror("poll");
- return iovs;
- }
-
- if (pres == 0) {
- DEBUG_LOG("t");
- return iovs;
- }
- }
-
- // Iterate through available packets
- while (frame_available()) {
- // Get start of ethernet frame and length
- tpacket_hdr *hdr = (tpacket_hdr *)d_ring[d_head];
- void *base = (uint8_t *)hdr+hdr->tp_mac;
- size_t len = hdr->tp_len;
-
- // FYI, (base % 4 == 2) Not what we want given the current FPGA
- // code. This means that our uint32_t samples are not 4-byte
- // aligned. We'll have to deal with it downstream.
-
- iovec iov;
- iov.iov_base = base;
- iov.iov_len = len;
- iovs.push_back(iov);
-
- inc_head();
- }
- return iovs;
- }
-
eth_buffer::result
eth_buffer::tx_frame(const void *base, size_t len, int flags)
{
diff --git a/usrp2/host/lib/eth_buffer.h b/usrp2/host/lib/eth_buffer.h
index 23365c2..63aa6dd 100644
--- a/usrp2/host/lib/eth_buffer.h
+++ b/usrp2/host/lib/eth_buffer.h
@@ -147,7 +147,6 @@ namespace usrp2 {
* \returns EB_ERROR if there was an unrecoverable error.
*/
result rx_frames(data_handler *f, int timeout=-1);
- std::vector<iovec> rx_framev(int timeout_in_ms);
/*
* \brief Release frame from buffer
*
diff --git a/usrp2/host/lib/eth_data_transport.cc
b/usrp2/host/lib/eth_data_transport.cc
index ad020df..d92b132 100644
--- a/usrp2/host/lib/eth_data_transport.cc
+++ b/usrp2/host/lib/eth_data_transport.cc
@@ -37,12 +37,6 @@ usrp2::eth_data_transport::eth_data_transport(const
std::string &ifc, u2_mac_add
if (!d_pf_data || !d_eth_data->attach_pktfilter(d_pf_data))
throw std::runtime_error("Unable to attach packet filter for data
packets.");
- //setup the ring
- d_ring = ring::sptr(new ring(d_eth_data->max_frames()));
-
- //start the thread
- d_thread = new boost::thread(boost::bind(ð_data_transport::recv_loop,
this));
-
memset(d_padding, 0, sizeof(d_padding));
}
@@ -50,70 +44,6 @@ usrp2::eth_data_transport::~eth_data_transport(){
delete d_pf_data;
d_eth_data->close();
delete d_eth_data;
- //stop the recv thread
- d_recv_on = false;
- d_thread->interrupt();
- d_thread->join();
-}
-
-void usrp2::eth_data_transport::recv_bg(void){
- std::vector<iovec> iovs = d_eth_data->rx_framev(100); // FIXME magic
timeout
- for (size_t i = 0; i < iovs.size(); i++){
- void *base = iovs[i].iov_base;
- size_t len = iovs[i].iov_len;
-
- if (len <= sizeof(u2_eth_packet_t)){
- DEBUG_LOG("D");
- d_eth_data->release_frame(base);
- continue; //drop truncated packet
- }
-
- u2_eth_packet_t *hdr = (u2_eth_packet_t *)base;
- d_num_rx_frames++;
- d_num_rx_bytes += len;
-
- /* --- FIXME start of fake transport layer handler --- */
-
- if (d_rx_seqno != -1) {
- int expected_seqno = (d_rx_seqno + 1) & 0xFF;
- int seqno = hdr->thdr.seqno;
-
- if (seqno != expected_seqno) {
- DEBUG_LOG("S"); // missing sequence number
- int missing = seqno - expected_seqno;
- if (missing < 0)
- missing += 256;
- d_num_rx_overruns++;
- d_num_rx_missing += missing;
- }
- }
-
- d_rx_seqno = hdr->thdr.seqno;
-
- /* --- end of fake transport layer handler --- */
-
- ring_data rd;
- rd.base = base;
- rd.len = len;
-
- //enqueue the ring data (release the data on failure)
- DEBUG_LOG("+");
- if (not d_ring->enqueue(rd)){
- DEBUG_LOG("!");
- d_eth_data->release_frame(rd.base);
- }
- }
- d_ring->wait_for_empty(gruel::get_new_timeout(0.1)); //magic timeout in sec
-}
-
-void usrp2::eth_data_transport::recv_loop(){
- if (gruel::enable_realtime_scheduling(gruel::sys_pri::usrp2_backend()) !=
gruel::RT_OK)
- std::cerr << "usrp2: failed to enable realtime scheduling" <<
std::endl;
- d_recv_on = true;
- while (d_recv_on){
- recv_bg();
- boost::this_thread::interruption_point();
- }
}
bool usrp2::eth_data_transport::sendv(const iovec *iov, size_t iovlen){
@@ -146,22 +76,65 @@ bool usrp2::eth_data_transport::sendv(const iovec *iov,
size_t iovlen){
return (d_eth_data->tx_framev(all_iov, all_iov_len) == eth_buffer::EB_OK)?
true : false;
}
-void usrp2::eth_data_transport::recv(data_handler *handler){
- d_ring->wait_for_not_empty(gruel::get_new_timeout(0.1)); //magic timeout
in sec
- while (true){
- ring_data rd;
- DEBUG_LOG("-");
- if (not d_ring->dequeue(rd)) break; //empty ring, get out of here
- data_handler::result result = (*handler)((uint8_t*)rd.base +
sizeof(u2_eth_packet_t), rd.len - sizeof(u2_eth_packet_t));
- d_eth_data->release_frame(rd.base);
- if (result == data_handler::DONE) break; //handler is done, get out of
here
+/*
+ * rx data handler for this transport:
+ * 1) handle the transport information in the ethernet packet header
+ * 2) strip the transport header and pass the packet to the registered
handler
+ */
+usrp2::data_handler::result usrp2::eth_data_transport::operator()(const void
*base, size_t len){
+ DEBUG_LOG("H");
+ if (len <= sizeof(u2_eth_packet_t)){
+ DEBUG_LOG("D");
+ return data_handler::RELEASE; //drop truncated packet
}
+
+ u2_eth_packet_t *hdr = (u2_eth_packet_t *)base;
+ d_num_rx_frames++;
+ d_num_rx_bytes += len;
+
+ /* --- FIXME start of fake transport layer handler --- */
+
+ if (d_rx_seqno != -1) {
+ int expected_seqno = (d_rx_seqno + 1) & 0xFF;
+ int seqno = hdr->thdr.seqno;
+
+ if (seqno != expected_seqno) {
+ DEBUG_LOG("S"); // missing sequence number
+ int missing = seqno - expected_seqno;
+ if (missing < 0)
+ missing += 256;
+ d_num_rx_overruns++;
+ d_num_rx_missing += missing;
+ }
+ }
+
+ d_rx_seqno = hdr->thdr.seqno;
+
+ /* --- end of fake transport layer handler --- */
+
+ return (*d_curr_handler)((uint8_t*)base + sizeof(u2_eth_packet_t), len -
sizeof(u2_eth_packet_t));
}
-void usrp2::eth_data_transport::flush(void){
- //dequeue everything in the ring
- ring_data rd;
- while (d_ring->dequeue(rd)){
- d_eth_data->release_frame(rd.base);
+//register the handler and call rx frames
+void usrp2::eth_data_transport::recv(data_handler *handler){
+ DEBUG_LOG(":");
+ d_curr_handler = handler;
+ d_eth_data->rx_frames(this, 100); //FIXME magic timeout
+}
+
+//a nop data handler that just returns for each call
+class nop_data_handler: public usrp2::data_handler{
+ data_handler::result operator()(const void *base, size_t len){
+ return data_handler::RELEASE;
}
+};
+
+//flush all packets in the ring by registering a nop handler and calling rx
frames
+void usrp2::eth_data_transport::flush(void){
+ DEBUG_LOG("F");
+ d_curr_handler = new nop_data_handler();
+ d_eth_data->rx_frames(this, 0); //no timeout
+ delete d_curr_handler;
}
+
+
diff --git a/usrp2/host/lib/eth_data_transport.h
b/usrp2/host/lib/eth_data_transport.h
index d32159e..860bb1f 100644
--- a/usrp2/host/lib/eth_data_transport.h
+++ b/usrp2/host/lib/eth_data_transport.h
@@ -24,11 +24,10 @@
#include "eth_buffer.h"
#include "pktfilter.h"
#include "usrp2_impl.h"
-#include "ring.h"
namespace usrp2{
- class eth_data_transport: public transport{
+ class eth_data_transport: public transport, public data_handler{
private:
eth_buffer *d_eth_data; // packet ring buffered data frames
pktfilter *d_pf_data;
@@ -41,13 +40,7 @@ namespace usrp2{
unsigned int d_num_rx_overruns;
unsigned int d_num_rx_bytes;
uint8_t d_padding[eth_buffer::MIN_PKTLEN];
- ring::sptr d_ring;
-
- //for the recv thread
- bool d_recv_on;
- boost::thread *d_thread;
- void recv_bg(void);
- void recv_loop(void);
+ data_handler *d_curr_handler;
public:
eth_data_transport(const std::string &ifc, u2_mac_addr_t mac, size_t
rx_bufsize);
diff --git a/usrp2/host/lib/ring.cc b/usrp2/host/lib/ring.cc
deleted file mode 100644
index 286caa2..0000000
--- a/usrp2/host/lib/ring.cc
+++ /dev/null
@@ -1,81 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2008 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio 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, or (at your option)
- * any later version.
- *
- * GNU Radio 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, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "ring.h"
-
-namespace usrp2 {
-
- ring::ring(unsigned int entries)
- : d_max(entries), d_read_ind(0), d_write_ind(0),
- d_ring(entries),
- d_mutex(), d_empty_cond()
- {/*NOP*/}
-
- void
- ring::wait_for_empty(boost::system_time timeout)
- {
- gruel::scoped_lock l(d_mutex);
- while (not empty())
- d_empty_cond.timed_wait(l, timeout);
- }
-
- void
- ring::wait_for_not_empty(boost::system_time timeout)
- {
- gruel::scoped_lock l(d_mutex);
- while (empty())
- d_not_empty_cond.timed_wait(l, timeout);
- }
-
- bool
- ring::enqueue(const ring_data &rd)
- {
- gruel::scoped_lock l(d_mutex);
- if (full())
- return false;
-
- d_ring[d_write_ind] = rd;
-
- inc_write_ind();
- d_not_empty_cond.notify_one();
- return true;
- }
-
- bool
- ring::dequeue(ring_data &rd)
- {
- gruel::scoped_lock l(d_mutex);
- if (empty())
- return false;
-
- rd = d_ring[d_read_ind];
-
- inc_read_ind();
- d_empty_cond.notify_one();
- return true;
- }
-
-} // namespace usrp2
-
diff --git a/usrp2/host/lib/ring.h b/usrp2/host/lib/ring.h
deleted file mode 100644
index 2a91dcc..0000000
--- a/usrp2/host/lib/ring.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2008 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio 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, or (at your option)
- * any later version.
- *
- * GNU Radio 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, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-#ifndef INCLUDED_RING_H
-#define INCLUDED_RING_H
-
-#include <stddef.h>
-#include <vector>
-#include <boost/shared_ptr.hpp>
-#include <gruel/thread.h>
-
-namespace usrp2 {
-
- /* container class for data held by the ring */
- class ring_data
- {
- public:
- void *base;
- size_t len;
- };
-
- class ring
- {
- public:
- typedef boost::shared_ptr<ring> sptr;
-
- private:
-
- size_t d_max;
- size_t d_read_ind;
- size_t d_write_ind;
-
- std::vector<ring_data> d_ring;
-
- gruel::mutex d_mutex;
- gruel::condition_variable d_empty_cond;
- gruel::condition_variable d_not_empty_cond;
-
- void inc_read_ind()
- {
- if (d_read_ind + 1 >= d_max)
- d_read_ind = 0;
- else
- d_read_ind = d_read_ind + 1;
- }
-
- void inc_write_ind()
- {
- if (d_write_ind + 1 >= d_max)
- d_write_ind = 0;
- else
- d_write_ind = d_write_ind + 1;
- }
-
- bool empty() const { return d_read_ind == d_write_ind; }
- bool full() const { return (d_write_ind+1)%d_max == d_read_ind; }
-
- public:
-
- ring(unsigned int entries);
-
- void wait_for_empty(boost::system_time timeout);
- void wait_for_not_empty(boost::system_time timeout);
-
- bool enqueue(const ring_data &rd);
- bool dequeue(ring_data &rd);
- };
-
-} // namespace usrp2
-
-#endif /* INCLUDED_RING_H */
diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc
index 7c13385..0a72698 100644
--- a/usrp2/host/lib/usrp2_impl.cc
+++ b/usrp2/host/lib/usrp2_impl.cc
@@ -135,6 +135,7 @@ namespace usrp2 {
data_packet_handler(rx_sample_handler *handler): d_handler(handler){}
data_handler::result operator()(const void *base, size_t len){
+ DEBUG_LOG("h");
vrt::expanded_header hdr;
const uint32_t *payload;
size_t n32_bit_words_payload;
@@ -149,7 +150,6 @@ namespace usrp2 {
return data_handler::RELEASE;
}
bool want_more = (*d_handler)(payload, n32_bit_words_payload, &hdr);
- DEBUG_LOG("-");
return want_more? data_handler::RELEASE : data_handler::DONE;
}
- [Commit-gnuradio] [gnuradio] 77/148: Merge branch 'master' of gnuradio.org:gnuradio into vita_rx, (continued)
- [Commit-gnuradio] [gnuradio] 77/148: Merge branch 'master' of gnuradio.org:gnuradio into vita_rx, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 57/148: Removed the ring buffer from the usrp2 impl., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 67/148: reorder the memory map, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 55/148: First cut at vita tx, whole thing compiles, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 69/148: fixed memory map for split tx dsp and control, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 62/148: Add ability to clear state out when there is an underrun, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 65/148: Merge branch 'vita_rx' of gnuradio.org:matt into vita_rx, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 63/148: only pull from input fifo when really consuming or pushing into the next fifo, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 68/148: Merge branch 'vita_rx' of gnuradio.org:matt into vita_rx, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 103/148: 19-bit fifo handling for receive side of eth/udp system, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 86/148: Removed the channel ring from the eth transport. Made the eth transport a data handler to pass directly to the eth buffer, and to strip ethernet headers/transport information.,
git <=
- [Commit-gnuradio] [gnuradio] 58/148: Merge branch 'vita_rx' of http://gnuradio.org/git/matt into wip/usrp2, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 56/148: ignore save files, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 73/148: Merge branch 'vita_rx' of http://gnuradio.org/git/matt into wip/usrp2, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 61/148: Merge branch 'vita_rx' of gnuradio.org:matt into vita_rx, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 59/148: WIP host mods to send vrt packets, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 76/148: Merge branch 'master' of http://gnuradio.org/git/gnuradio into vita_rx, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 64/148: put new setting reg into the address space in the right place, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 74/148: Merge branch 'wip/usrp2' of address@hidden:jblum into wip/usrp2, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 78/148: Merge branch 'vita_rx' of gnuradio.org:matt into vita_rx, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 83/148: added timeout to ring wait calls, git, 2016/08/14