diff -r 894cef590e8d -r 03e01e750285 src/mem/bridge.hh --- a/src/mem/bridge.hh Fri May 25 10:46:19 2012 +0100 +++ b/src/mem/bridge.hh Fri May 25 12:38:32 2012 +0100 @@ -91,7 +91,7 @@ public: Packet::SenderState *origSenderState; - Packet::NodeID origSrc; + Packet::PortId origSrc; RequestState(PacketPtr _pkt) : origSenderState(_pkt->senderState), diff -r 894cef590e8d -r 03e01e750285 src/mem/bus.hh --- a/src/mem/bus.hh Fri May 25 10:46:19 2012 +0100 +++ b/src/mem/bus.hh Fri May 25 12:38:32 2012 +0100 @@ -66,6 +66,10 @@ class Bus : public MemObject { + + /** Use the same port id as the packet class. */ + typedef Packet::PortId PortId; + /** * Declaration of the bus slave port type, one will be * instantiated for each of the master interfaces connecting to @@ -80,7 +84,7 @@ public: /** Constructor for the BusSlavePort.*/ - BusSlavePort(const std::string &_name, Bus *_bus, Port::PortId _id) + BusSlavePort(const std::string &_name, Bus *_bus, PortId _id) : SlavePort(_name, _bus, _id), bus(_bus) { } @@ -145,7 +149,7 @@ public: /** Constructor for the BusMasterPort.*/ - BusMasterPort(const std::string &_name, Bus *_bus, Port::PortId _id) + BusMasterPort(const std::string &_name, Bus *_bus, PortId _id) : MasterPort(_name, _bus, _id), bus(_bus) { } @@ -213,8 +217,8 @@ Event * drainEvent; - typedef range_map::iterator PortIter; - range_map portMap; + typedef range_map::iterator PortIter; + range_map portMap; AddrRangeList defaultRange; @@ -251,7 +255,7 @@ * @param pkt Packet to forward * @param exclude_slave_port_id Id of slave port to exclude */ - void forwardTiming(PacketPtr pkt, Port::PortId exclude_slave_port_id); + void forwardTiming(PacketPtr pkt, PortId exclude_slave_port_id); /** * Determine if the bus is to be considered occupied when being @@ -293,7 +297,7 @@ * @return a pair containing the snoop response and snoop latency */ std::pair forwardAtomic(PacketPtr pkt, - Port::PortId exclude_slave_port_id); + PortId exclude_slave_port_id); /** Function called by the port when the bus is recieving a Functional transaction.*/ @@ -311,26 +315,26 @@ * @param pkt Packet to forward * @param exclude_slave_port_id Id of slave port to exclude */ - void forwardFunctional(PacketPtr pkt, Port::PortId exclude_slave_port_id); + void forwardFunctional(PacketPtr pkt, PortId exclude_slave_port_id); /** Timing function called by port when it is once again able to process * requests. */ - void recvRetry(Port::PortId id); + void recvRetry(PortId id); /** Function called by the port when the bus is recieving a range change.*/ - void recvRangeChange(Port::PortId id); + void recvRangeChange(PortId id); /** Find which port connected to this bus (if any) should be given a packet * with this address. * @param addr Address to find port for. * @return id of port that the packet should be sent out of. */ - int findPort(Addr addr); + PortId findPort(Addr addr); // Cache for the findPort function storing recently used ports from portMap struct PortCache { bool valid; - Port::PortId id; + PortId id; Addr start; Addr end; }; @@ -339,7 +343,7 @@ // Checks the cache and returns the id of the port that has the requested // address within its range - inline int checkPortCache(Addr addr) { + inline PortId checkPortCache(Addr addr) { if (portCache[0].valid && addr >= portCache[0].start && addr < portCache[0].end) { return portCache[0].id; @@ -353,7 +357,7 @@ return portCache[2].id; } - return Port::INVALID_PORT_ID; + return Packet::INVALID_PORT_ID; } // Clears the earliest entry of the cache and inserts a new port entry @@ -388,7 +392,7 @@ * * @return a list of non-overlapping address ranges */ - AddrRangeList getAddrRanges(Port::PortId id); + AddrRangeList getAddrRanges(PortId id); /** * Determine if the bus port is snooping or not. @@ -397,7 +401,7 @@ * * @return a boolean indicating if this port is snooping or not */ - bool isSnooping(Port::PortId id) const; + bool isSnooping(PortId id) const; /** Calculate the timing parameters for the packet. Updates the * firstWordTime and finishTime fields of the packet object. @@ -426,13 +430,13 @@ * @param id id of the busport that made the request * @return the max of all the sizes */ - unsigned findBlockSize(Port::PortId id); + unsigned findBlockSize(PortId id); // event used to schedule a release of the bus EventWrapper busIdleEvent; bool inRetry; - std::set inRecvRangeChange; + std::set inRecvRangeChange; /** The master and slave ports of the bus */ std::vector slavePorts; @@ -465,7 +469,7 @@ } /** Port that handles requests that don't match any of the interfaces.*/ - short defaultPortId; + PortId defaultPortId; /** If true, use address range provided by default device. Any address not handled by another port and not in default device's diff -r 894cef590e8d -r 03e01e750285 src/mem/bus.cc --- a/src/mem/bus.cc Fri May 25 10:46:19 2012 +0100 +++ b/src/mem/bus.cc Fri May 25 12:38:32 2012 +0100 @@ -57,7 +57,7 @@ : MemObject(p), clock(p->clock), headerCycles(p->header_cycles), width(p->width), tickNextIdle(0), drainEvent(NULL), busIdleEvent(this), inRetry(false), - defaultPortId(Port::INVALID_PORT_ID), + defaultPortId(Packet::INVALID_PORT_ID), useDefaultRange(p->use_default_range), defaultBlockSize(p->block_size), cachedBlockSize(0), cachedBlockSizeValid(false) @@ -318,7 +318,7 @@ assert(pkt->isExpressSnoop()); // forward to all snoopers - forwardTiming(pkt, Port::INVALID_PORT_ID); + forwardTiming(pkt, Packet::INVALID_PORT_ID); // a snoop request came from a connected slave device (one of // our master ports), and if it is not coming from the slave @@ -347,7 +347,7 @@ src_port->name(), pkt->cmdString(), pkt->getAddr()); // get the destination from the packet - Packet::NodeID dest = pkt->getDest(); + PortId dest = pkt->getDest(); // responses are never express snoops assert(!pkt->isExpressSnoop()); @@ -410,7 +410,7 @@ } void -Bus::forwardTiming(PacketPtr pkt, int exclude_slave_port_id) +Bus::forwardTiming(PacketPtr pkt, PortId exclude_slave_port_id) { for (SlavePortIter s = snoopPorts.begin(); s != snoopPorts.end(); ++s) { SlavePort *p = *s; @@ -418,7 +418,7 @@ // (corresponding to our own slave port that is also in // snoopPorts) and should not send it back to where it came // from - if (exclude_slave_port_id == Port::INVALID_PORT_ID || + if (exclude_slave_port_id == Packet::INVALID_PORT_ID || p->getId() != exclude_slave_port_id) { // cache is not allowed to refuse snoop p->sendTimingSnoopReq(pkt); @@ -481,7 +481,7 @@ } void -Bus::recvRetry(Port::PortId id) +Bus::recvRetry(PortId id) { // we got a retry from a peer that we tried to send something to // and failed, but we sent it on the account of someone else, and @@ -500,14 +500,12 @@ } } -int +Packet::PortId Bus::findPort(Addr addr) { /* An interval tree would be a better way to do this. --ali. */ - int dest_id; - - dest_id = checkPortCache(addr); - if (dest_id != Port::INVALID_PORT_ID) + PortId dest_id = checkPortCache(addr); + if (dest_id != Packet::INVALID_PORT_ID) return dest_id; // Check normal port ranges @@ -527,7 +525,7 @@ return defaultPortId; } } - } else if (defaultPortId != Port::INVALID_PORT_ID) { + } else if (defaultPortId != Packet::INVALID_PORT_ID) { DPRINTF(Bus, "Unable to find destination for addr %#llx, " "will use default port\n", addr); return defaultPortId; @@ -560,7 +558,7 @@ // even if we had a snoop response, we must continue and also // perform the actual request at the destination - int dest_id = findPort(pkt->getAddr()); + PortId dest_id = findPort(pkt->getAddr()); // forward the request to the appropriate destination Tick response_latency = masterPorts[dest_id]->sendAtomic(pkt); @@ -586,7 +584,7 @@ // forward to all snoopers std::pair snoop_result = - forwardAtomic(pkt, Port::INVALID_PORT_ID); + forwardAtomic(pkt, Packet::INVALID_PORT_ID); MemCmd snoop_response_cmd = snoop_result.first; Tick snoop_response_latency = snoop_result.second; @@ -598,12 +596,12 @@ } std::pair -Bus::forwardAtomic(PacketPtr pkt, int exclude_slave_port_id) +Bus::forwardAtomic(PacketPtr pkt, PortId exclude_slave_port_id) { // the packet may be changed on snoops, record the original source // and command to enable us to restore it between snoops so that // additional snoops can take place properly - Packet::NodeID orig_src_id = pkt->getSrc(); + PortId orig_src_id = pkt->getSrc(); MemCmd orig_cmd = pkt->cmd; MemCmd snoop_response_cmd = MemCmd::InvalidCmd; Tick snoop_response_latency = 0; @@ -614,7 +612,7 @@ // (corresponding to our own slave port that is also in // snoopPorts) and should not send it back to where it came // from - if (exclude_slave_port_id == Port::INVALID_PORT_ID || + if (exclude_slave_port_id == Packet::INVALID_PORT_ID || p->getId() != exclude_slave_port_id) { Tick latency = p->sendAtomicSnoop(pkt); // in contrast to a functional access, we have to keep on @@ -662,7 +660,7 @@ // there is no need to continue if the snooping has found what we // were looking for and the packet is already a response if (!pkt->isResponse()) { - int dest_id = findPort(pkt->getAddr()); + PortId dest_id = findPort(pkt->getAddr()); masterPorts[dest_id]->sendFunctional(pkt); } @@ -680,11 +678,11 @@ } // forward to all snoopers - forwardFunctional(pkt, Port::INVALID_PORT_ID); + forwardFunctional(pkt, Packet::INVALID_PORT_ID); } void -Bus::forwardFunctional(PacketPtr pkt, int exclude_slave_port_id) +Bus::forwardFunctional(PacketPtr pkt, PortId exclude_slave_port_id) { for (SlavePortIter s = snoopPorts.begin(); s != snoopPorts.end(); ++s) { SlavePort *p = *s; @@ -692,7 +690,7 @@ // (corresponding to our own slave port that is also in // snoopPorts) and should not send it back to where it came // from - if (exclude_slave_port_id == Port::INVALID_PORT_ID || + if (exclude_slave_port_id == Packet::INVALID_PORT_ID || p->getId() != exclude_slave_port_id) p->sendFunctionalSnoop(pkt); @@ -705,7 +703,7 @@ /** Function called by the port when the bus is receiving a range change.*/ void -Bus::recvRangeChange(Port::PortId id) +Bus::recvRangeChange(PortId id) { AddrRangeList ranges; AddrRangeIter iter; @@ -749,7 +747,7 @@ DPRINTF(BusAddrRanges, "Adding range %#llx - %#llx for id %d\n", iter->start, iter->end, id); if (portMap.insert(*iter, id) == portMap.end()) { - int conflict_id = portMap.find(*iter)->second; + PortId conflict_id = portMap.find(*iter)->second; fatal("%s has two ports with same range:\n\t%s\n\t%s\n", name(), masterPorts[id]->getSlavePort().name(), masterPorts[conflict_id]->getSlavePort().name()); @@ -768,7 +766,7 @@ } AddrRangeList -Bus::getAddrRanges(Port::PortId id) +Bus::getAddrRanges(PortId id) { AddrRangeList ranges; @@ -809,14 +807,14 @@ } bool -Bus::isSnooping(Port::PortId id) const +Bus::isSnooping(PortId id) const { // in essence, answer the question if there are snooping ports return !snoopPorts.empty(); } unsigned -Bus::findBlockSize(Port::PortId id) +Bus::findBlockSize(PortId id) { if (cachedBlockSizeValid) return cachedBlockSize; diff -r 894cef590e8d -r 03e01e750285 src/mem/cache/cache_impl.hh --- a/src/mem/cache/cache_impl.hh Fri May 25 10:46:19 2012 +0100 +++ b/src/mem/cache/cache_impl.hh Fri May 25 12:38:32 2012 +0100 @@ -352,7 +352,7 @@ class ForwardResponseRecord : public Packet::SenderState, public FastAlloc { Packet::SenderState *prevSenderState; - Packet::NodeID prevSrc; + Packet::PortId prevSrc; #ifndef NDEBUG BaseCache *cache; #endif @@ -1193,7 +1193,7 @@ pkt->assertShared(); } } else { - Packet::NodeID origSrc = pkt->getSrc(); + Packet::PortId origSrc = pkt->getSrc(); cpuSidePort->sendAtomicSnoop(pkt); if (!alreadyResponded && pkt->memInhibitAsserted()) { // cache-to-cache response from some upper cache: diff -r 894cef590e8d -r 03e01e750285 src/mem/packet.hh --- a/src/mem/packet.hh Fri May 25 10:46:19 2012 +0100 +++ b/src/mem/packet.hh Fri May 25 12:38:32 2012 +0100 @@ -41,6 +41,7 @@ * Authors: Ron Dreslinski * Steve Reinhardt * Ali Saidi + * Andreas Hansson */ /** @@ -231,7 +232,12 @@ public: typedef uint32_t FlagsType; typedef ::Flags Flags; - typedef short NodeID; + + /** A type name for the port identifier. */ + typedef int PortId; + + /** A symbolic name for the absence of a port id. */ + static const PortId INVALID_PORT_ID = -1; private: static const FlagsType PUBLIC_FLAGS = 0x00000000; @@ -250,9 +256,6 @@ /// Are the 'addr' and 'size' fields valid? static const FlagsType VALID_ADDR = 0x00000100; static const FlagsType VALID_SIZE = 0x00000200; - /// Is the 'src' field valid? - static const FlagsType VALID_SRC = 0x00000400; - static const FlagsType VALID_DST = 0x00000800; /// Is the data pointer set to a value that shouldn't be freed /// when the packet is destroyed? static const FlagsType STATIC_DATA = 0x00001000; @@ -306,7 +309,7 @@ * for example by using an appropriate sender state. The latter is * done in the cache and bridge. */ - NodeID src; + PortId src; /** * Destination port identifier that is present on all response @@ -316,7 +319,7 @@ * response, and the destination is used, e.g. by the bus, to * select the appropriate path through the interconnect. */ - NodeID dest; + PortId dest; /** * The original value of the command field. Only valid when the @@ -487,21 +490,21 @@ bool hadBadAddress() const { return cmd == MemCmd::BadAddressError; } void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; } - bool isSrcValid() { return flags.isSet(VALID_SRC); } + bool isSrcValid() const { return src != INVALID_PORT_ID; } /// Accessor function to get the source index of the packet. - NodeID getSrc() const { assert(flags.isSet(VALID_SRC)); return src; } + PortId getSrc() const { assert(isSrcValid()); return src; } /// Accessor function to set the source index of the packet. - void setSrc(NodeID _src) { src = _src; flags.set(VALID_SRC); } + void setSrc(PortId _src) { src = _src; } /// Reset source field, e.g. to retransmit packet on different bus. - void clearSrc() { flags.clear(VALID_SRC); } + void clearSrc() { src = INVALID_PORT_ID; } - bool isDestValid() { return flags.isSet(VALID_DST); } + bool isDestValid() const { return dest != INVALID_PORT_ID; } /// Accessor function for the destination index of the packet. - NodeID getDest() const { assert(flags.isSet(VALID_DST)); return dest; } + PortId getDest() const { assert(isDestValid()); return dest; } /// Accessor function to set the destination index of the packet. - void setDest(NodeID _dest) { dest = _dest; flags.set(VALID_DST); } + void setDest(PortId _dest) { dest = _dest; } /// Reset destination field, e.g. to turn a response into a request again. - void clearDest() { flags.clear(VALID_DST); } + void clearDest() { dest = INVALID_PORT_ID; } Addr getAddr() const { assert(flags.isSet(VALID_ADDR)); return addr; } unsigned getSize() const { assert(flags.isSet(VALID_SIZE)); return size; } @@ -538,6 +541,7 @@ */ Packet(Request *_req, MemCmd _cmd) : cmd(_cmd), req(_req), data(NULL), + src(INVALID_PORT_ID), dest(INVALID_PORT_ID), bytesValidStart(0), bytesValidEnd(0), time(curTick()), senderState(NULL) { @@ -558,6 +562,7 @@ */ Packet(Request *_req, MemCmd _cmd, int _blkSize) : cmd(_cmd), req(_req), data(NULL), + src(INVALID_PORT_ID), dest(INVALID_PORT_ID), bytesValidStart(0), bytesValidEnd(0), time(curTick()), senderState(NULL) { @@ -586,7 +591,7 @@ if (!clearFlags) flags.set(pkt->flags & COPY_FLAGS); - flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE|VALID_SRC|VALID_DST)); + flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE)); flags.set(pkt->flags & STATIC_DATA); } @@ -644,8 +649,7 @@ flags.clear(EXPRESS_SNOOP); dest = src; - flags.set(VALID_DST, flags.isSet(VALID_SRC)); - flags.clear(VALID_SRC); + clearSrc(); } void diff -r 894cef590e8d -r 03e01e750285 src/mem/port.hh --- a/src/mem/port.hh Fri May 25 10:46:19 2012 +0100 +++ b/src/mem/port.hh Fri May 25 12:38:32 2012 +0100 @@ -78,14 +78,6 @@ class Port { - public: - - /** A type name for the port identifier. */ - typedef int PortId; - - /** A symbolic name for the absence of a port id. */ - static const PortId INVALID_PORT_ID = -1; - private: /** Descriptive name (for DPRINTF output) */ @@ -93,6 +85,9 @@ protected: + /** Use the same port id as the packet class. */ + typedef Packet::PortId PortId; + /** * A numeric identifier to distinguish ports in a vector, and set * to INVALID_PORT_ID in case this port is not part of a vector. @@ -167,7 +162,7 @@ public: MasterPort(const std::string& name, MemObject* owner, - PortId id = INVALID_PORT_ID); + PortId id = Packet::INVALID_PORT_ID); virtual ~MasterPort(); void bind(SlavePort& slave_port); @@ -305,7 +300,7 @@ public: SlavePort(const std::string& name, MemObject* owner, - PortId id = INVALID_PORT_ID); + PortId id = Packet::INVALID_PORT_ID); virtual ~SlavePort(); void bind(MasterPort& master_port);