From: Nathan Binkert Date: Mon, 27 Feb 2006 01:31:08 +0000 (-0500) Subject: add some support for random access of data in packet fifos X-Git-Tag: m5_2.0_beta1~87^2~35^2~3 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9b18c0e87272b35a34e39ce2a9924963402e5b29;p=gem5.git add some support for random access of data in packet fifos dev/pktfifo.cc: add support for copying arbitrary data out of a packet fifo dev/pktfifo.hh: add support for copying arbitrary data out of a packet fifo. Add functions to determine where in the fifo a particular packet is --HG-- extra : convert_revision : f8ddc994ce8577f29af0de3fa418a01e4e2cb0f1 --- diff --git a/dev/pktfifo.cc b/dev/pktfifo.cc index b4fab2d6f..639009be9 100644 --- a/dev/pktfifo.cc +++ b/dev/pktfifo.cc @@ -31,6 +31,36 @@ using namespace std; +bool +PacketFifo::copyout(void *dest, int offset, int len) +{ + char *data = (char *)dest; + if (offset + len >= size()) + return false; + + list::iterator p = fifo.begin(); + list::iterator end = fifo.end(); + while (len > 0) { + while (offset >= (*p)->length) { + offset -= (*p)->length; + ++p; + } + + if (p == end) + panic("invalid fifo"); + + int size = min((*p)->length - offset, len); + memcpy(data, (*p)->data, size); + offset = 0; + len -= size; + data += size; + ++p; + } + + return true; +} + + void PacketFifo::serialize(const string &base, ostream &os) { @@ -40,8 +70,8 @@ PacketFifo::serialize(const string &base, ostream &os) paramOut(os, base + ".packets", fifo.size()); int i = 0; - std::list::iterator p = fifo.begin(); - std::list::iterator end = fifo.end(); + list::iterator p = fifo.begin(); + list::iterator end = fifo.end(); while (p != end) { (*p)->serialize(csprintf("%s.packet%d", base, i), os); ++p; diff --git a/dev/pktfifo.hh b/dev/pktfifo.hh index e63fd291f..e245840a8 100644 --- a/dev/pktfifo.hh +++ b/dev/pktfifo.hh @@ -127,6 +127,35 @@ class PacketFifo fifo.erase(i); } + bool copyout(void *dest, int offset, int len); + + int countPacketsBefore(iterator end) + { + iterator i = fifo.begin(); + int count = 0; + + while (i != end) { + ++count; + ++i; + } + + return count; + } + + int countPacketsAfter(iterator i) + { + iterator end = fifo.end(); + int count = 0; + + while (i != end) { + ++count; + ++i; + } + + return count; + } + + /** * Serialization stuff */