change the serialization of a packet so that we don't

do a nameOut.  This fixes a subtle bug in serialization that
can pop up.

--HG--
extra : convert_revision : b52df977dcbef1c9bd0d4405ba0b36dff3737cdf
This commit is contained in:
Nathan Binkert 2004-11-13 16:46:56 -05:00
parent acb98fb0f6
commit 8922d69953
4 changed files with 27 additions and 33 deletions

View file

@ -185,10 +185,8 @@ EtherLink::Link::serialize(ostream &os)
SERIALIZE_SCALAR(event_time); SERIALIZE_SCALAR(event_time);
} }
if (packet_exists) { if (packet_exists)
nameOut(os, csprintf("%s.packet", name())); packet->serialize("packet", os);
packet->serialize(os);
}
} }
void void
@ -198,7 +196,7 @@ EtherLink::Link::unserialize(Checkpoint *cp, const string &section)
UNSERIALIZE_SCALAR(packet_exists); UNSERIALIZE_SCALAR(packet_exists);
if (packet_exists) { if (packet_exists) {
packet = new PacketData; packet = new PacketData;
packet->unserialize(cp, csprintf("%s.packet", section)); packet->unserialize("packet", cp, section);
} }
bool event_scheduled; bool event_scheduled;
@ -238,8 +236,7 @@ LinkDelayEvent::serialize(ostream &os)
Event::serialize(os); Event::serialize(os);
SERIALIZE_OBJPTR(link); SERIALIZE_OBJPTR(link);
nameOut(os, csprintf("%s.packet", name())); packet->serialize("packet", os);
packet->serialize(os);
} }
@ -248,7 +245,7 @@ LinkDelayEvent::unserialize(Checkpoint *cp, const string &section)
{ {
Event::unserialize(cp, section); Event::unserialize(cp, section);
packet = new PacketData; packet = new PacketData;
packet->unserialize(cp, csprintf("%s.packet", section)); packet->unserialize("packet", cp, section);
} }

View file

@ -28,22 +28,23 @@
#include <iostream> #include <iostream>
#include "base/misc.hh"
#include "dev/etherpkt.hh" #include "dev/etherpkt.hh"
#include "sim/serialize.hh" #include "sim/serialize.hh"
using namespace std; using namespace std;
void void
PacketData::serialize(ostream &os) PacketData::serialize(const string &base, ostream &os)
{ {
SERIALIZE_SCALAR(length); paramOut(os, base + ".length", length);
SERIALIZE_ARRAY(data, length); arrayParamOut(os, base + ".data", data, length);
} }
void void
PacketData::unserialize(Checkpoint *cp, const string &section) PacketData::unserialize(const string &base, Checkpoint *cp,
const string &section)
{ {
UNSERIALIZE_SCALAR(length); paramIn(cp, section, base + ".length", length);
data = new uint8_t[length]; arrayParamIn(cp, section, base + ".data", data, length);
UNSERIALIZE_ARRAY(data, length);
} }

View file

@ -52,13 +52,15 @@ class PacketData : public RefCounted
public: public:
PacketData() : data(NULL), length(0) { } PacketData() : data(NULL), length(0) { }
explicit PacketData(size_t size) : data(new uint8_t[size]), length(0) { }
PacketData(std::auto_ptr<uint8_t> d, int l) PacketData(std::auto_ptr<uint8_t> d, int l)
: data(d.release()), length(l) { } : data(d.release()), length(l) { }
~PacketData() { if (data) delete [] data; } ~PacketData() { if (data) delete [] data; }
public: public:
void serialize(std::ostream &os); void serialize(const std::string &base, std::ostream &os);
void unserialize(Checkpoint *cp, const std::string &section); void unserialize(const std::string &base, Checkpoint *cp,
const std::string &section);
}; };
typedef RefCountingPtr<PacketData> PacketPtr; typedef RefCountingPtr<PacketData> PacketPtr;

View file

@ -2123,19 +2123,15 @@ NSGigE::serialize(ostream &os)
SERIALIZE_SCALAR(txNumPkts); SERIALIZE_SCALAR(txNumPkts);
int i = 0; int i = 0;
pktiter_t end = txFifo.end(); pktiter_t end = txFifo.end();
for (pktiter_t p = txFifo.begin(); p != end; ++p) { for (pktiter_t p = txFifo.begin(); p != end; ++p)
nameOut(os, csprintf("%s.txFifo%d", name(), i++)); (*p)->serialize(csprintf("txFifo%d", i++), os);
(*p)->serialize(os);
}
int rxNumPkts = rxFifo.size(); int rxNumPkts = rxFifo.size();
SERIALIZE_SCALAR(rxNumPkts); SERIALIZE_SCALAR(rxNumPkts);
i = 0; i = 0;
end = rxFifo.end(); end = rxFifo.end();
for (pktiter_t p = rxFifo.begin(); p != end; ++p) { for (pktiter_t p = rxFifo.begin(); p != end; ++p)
nameOut(os, csprintf("%s.rxFifo%d", name(), i++)); (*p)->serialize(csprintf("rxFifo%d", i++), os);
(*p)->serialize(os);
}
/* /*
* Serialize the various helper variables * Serialize the various helper variables
@ -2143,8 +2139,7 @@ NSGigE::serialize(ostream &os)
bool txPacketExists = txPacket; bool txPacketExists = txPacket;
SERIALIZE_SCALAR(txPacketExists); SERIALIZE_SCALAR(txPacketExists);
if (txPacketExists) { if (txPacketExists) {
nameOut(os, csprintf("%s.txPacket", name())); txPacket->serialize("txPacket", os);
txPacket->serialize(os);
uint32_t txPktBufPtr = (uint32_t) (txPacketBufPtr - txPacket->data); uint32_t txPktBufPtr = (uint32_t) (txPacketBufPtr - txPacket->data);
SERIALIZE_SCALAR(txPktBufPtr); SERIALIZE_SCALAR(txPktBufPtr);
} }
@ -2152,8 +2147,7 @@ NSGigE::serialize(ostream &os)
bool rxPacketExists = rxPacket; bool rxPacketExists = rxPacket;
SERIALIZE_SCALAR(rxPacketExists); SERIALIZE_SCALAR(rxPacketExists);
if (rxPacketExists) { if (rxPacketExists) {
nameOut(os, csprintf("%s.rxPacket", name())); rxPacket->serialize("rxPacket", os);
rxPacket->serialize(os);
uint32_t rxPktBufPtr = (uint32_t) (rxPacketBufPtr - rxPacket->data); uint32_t rxPktBufPtr = (uint32_t) (rxPacketBufPtr - rxPacket->data);
SERIALIZE_SCALAR(rxPktBufPtr); SERIALIZE_SCALAR(rxPktBufPtr);
} }
@ -2281,7 +2275,7 @@ NSGigE::unserialize(Checkpoint *cp, const std::string &section)
int i; int i;
for (i = 0; i < txNumPkts; ++i) { for (i = 0; i < txNumPkts; ++i) {
PacketPtr p = new PacketData; PacketPtr p = new PacketData;
p->unserialize(cp, csprintf("%s.rxFifo%d", section, i)); p->unserialize(csprintf("rxFifo%d", i), cp, section);
txFifo.push_back(p); txFifo.push_back(p);
} }
@ -2289,7 +2283,7 @@ NSGigE::unserialize(Checkpoint *cp, const std::string &section)
UNSERIALIZE_SCALAR(rxNumPkts); UNSERIALIZE_SCALAR(rxNumPkts);
for (i = 0; i < rxNumPkts; ++i) { for (i = 0; i < rxNumPkts; ++i) {
PacketPtr p = new PacketData; PacketPtr p = new PacketData;
p->unserialize(cp, csprintf("%s.rxFifo%d", section, i)); p->unserialize(csprintf("rxFifo%d", i), cp, section);
rxFifo.push_back(p); rxFifo.push_back(p);
} }
@ -2300,7 +2294,7 @@ NSGigE::unserialize(Checkpoint *cp, const std::string &section)
UNSERIALIZE_SCALAR(txPacketExists); UNSERIALIZE_SCALAR(txPacketExists);
if (txPacketExists) { if (txPacketExists) {
txPacket = new PacketData; txPacket = new PacketData;
txPacket->unserialize(cp, csprintf("%s.txPacket", section)); txPacket->unserialize("txPacket", cp, section);
uint32_t txPktBufPtr; uint32_t txPktBufPtr;
UNSERIALIZE_SCALAR(txPktBufPtr); UNSERIALIZE_SCALAR(txPktBufPtr);
txPacketBufPtr = (uint8_t *) txPacket->data + txPktBufPtr; txPacketBufPtr = (uint8_t *) txPacket->data + txPktBufPtr;
@ -2312,7 +2306,7 @@ NSGigE::unserialize(Checkpoint *cp, const std::string &section)
rxPacket = 0; rxPacket = 0;
if (rxPacketExists) { if (rxPacketExists) {
rxPacket = new PacketData; rxPacket = new PacketData;
rxPacket->unserialize(cp, csprintf("%s.rxPacket", section)); rxPacket->unserialize("rxPacket", cp, section);
uint32_t rxPktBufPtr; uint32_t rxPktBufPtr;
UNSERIALIZE_SCALAR(rxPktBufPtr); UNSERIALIZE_SCALAR(rxPktBufPtr);
rxPacketBufPtr = (uint8_t *) rxPacket->data + rxPktBufPtr; rxPacketBufPtr = (uint8_t *) rxPacket->data + rxPktBufPtr;