From: Daniel R. Carvalho Date: Mon, 11 Feb 2019 13:19:57 +0000 (+0100) Subject: mem: Add packet matching functions X-Git-Tag: v19.0.0.0~959 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d4cee4dc66e175dd6cea7e9bcbe815a7d2d35462;p=gem5.git mem: Add packet matching functions Add both block and non-block-aligned packet matching functions, so that both address and secure bits are checked when checking whether a packet matches a request. Change-Id: Id0069befb925d112e06f250741cb47d9dfa249cc Signed-off-by: Daniel R. Carvalho Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/17533 Tested-by: kokoro Reviewed-by: Jason Lowe-Power Reviewed-by: Nikos Nikoleris Maintainer: Jason Lowe-Power Maintainer: Nikos Nikoleris --- diff --git a/src/mem/cache/base.cc b/src/mem/cache/base.cc index f43c2ecf3..ddcfd80a7 100644 --- a/src/mem/cache/base.cc +++ b/src/mem/cache/base.cc @@ -2451,7 +2451,7 @@ BaseCache::CacheReqPacketQueue::sendDeferredPacket() } else { // let our snoop responses go first if there are responses to // the same addresses - if (checkConflictingSnoop(entry->blkAddr)) { + if (checkConflictingSnoop(entry->getTarget()->pkt)) { return; } waitingOnRetry = entry->sendPacket(cache); diff --git a/src/mem/cache/base.hh b/src/mem/cache/base.hh index a45dcba6f..8d5ed11d0 100644 --- a/src/mem/cache/base.hh +++ b/src/mem/cache/base.hh @@ -189,10 +189,12 @@ class BaseCache : public MemObject * send out, and if so simply stall any requests, and schedule * a send event at the same time as the next snoop response is * being sent out. + * + * @param pkt The packet to check for conflicts against. */ - bool checkConflictingSnoop(Addr addr) + bool checkConflictingSnoop(const PacketPtr pkt) { - if (snoopRespQueue.hasAddr(addr)) { + if (snoopRespQueue.checkConflict(pkt, cache.blkSize)) { DPRINTF(CachePort, "Waiting for snoop response to be " "sent\n"); Tick when = snoopRespQueue.deferredPacketReadyTime(); diff --git a/src/mem/cache/cache.cc b/src/mem/cache/cache.cc index eac278a3b..4643e1d35 100644 --- a/src/mem/cache/cache.cc +++ b/src/mem/cache/cache.cc @@ -383,7 +383,7 @@ Cache::handleTimingReqMiss(PacketPtr pkt, CacheBlk *blk, Tick forward_time, pkt->req->masterId()); pf = new Packet(req, pkt->cmd); pf->allocate(); - assert(pf->getAddr() == pkt->getAddr()); + assert(pf->matchAddr(pkt)); assert(pf->getSize() == pkt->getSize()); } @@ -781,7 +781,7 @@ Cache::serviceMSHRTargets(MSHR *mshr, const PacketPtr pkt, CacheBlk *blk) pkt->payloadDelay; if (pkt->isRead() && !is_error) { // sanity check - assert(pkt->getAddr() == tgt_pkt->getAddr()); + assert(pkt->matchAddr(tgt_pkt)); assert(pkt->getSize() >= tgt_pkt->getSize()); tgt_pkt->setData(pkt->getConstPtr()); diff --git a/src/mem/packet.cc b/src/mem/packet.cc index 7172219e6..1d1b5b8d7 100644 --- a/src/mem/packet.cc +++ b/src/mem/packet.cc @@ -396,6 +396,32 @@ Packet::print() const { return str.str(); } +bool +Packet::matchBlockAddr(const Addr addr, const bool is_secure, + const int blk_size) const +{ + return (getBlockAddr(blk_size) == addr) && (isSecure() == is_secure); +} + +bool +Packet::matchBlockAddr(const PacketPtr pkt, const int blk_size) const +{ + return matchBlockAddr(pkt->getBlockAddr(blk_size), pkt->isSecure(), + blk_size); +} + +bool +Packet::matchAddr(const Addr addr, const bool is_secure) const +{ + return (getAddr() == addr) && (isSecure() == is_secure); +} + +bool +Packet::matchAddr(const PacketPtr pkt) const +{ + return matchAddr(pkt->getAddr(), pkt->isSecure()); +} + Packet::PrintReqState::PrintReqState(std::ostream &_os, int _verbosity) : curPrefixPtr(new std::string("")), os(_os), verbosity(_verbosity) { diff --git a/src/mem/packet.hh b/src/mem/packet.hh index 4e3ea15e1..f942e8ddd 100644 --- a/src/mem/packet.hh +++ b/src/mem/packet.hh @@ -980,6 +980,45 @@ class Packet : public Printable flags.set(VALID_SIZE); } + /** + * Check if packet corresponds to a given block-aligned address and + * address space. + * + * @param addr The address to compare against. + * @param is_secure Whether addr belongs to the secure address space. + * @param blk_size Block size in bytes. + * @return Whether packet matches description. + */ + bool matchBlockAddr(const Addr addr, const bool is_secure, + const int blk_size) const; + + /** + * Check if this packet refers to the same block-aligned address and + * address space as another packet. + * + * @param pkt The packet to compare against. + * @param blk_size Block size in bytes. + * @return Whether packet matches description. + */ + bool matchBlockAddr(const PacketPtr pkt, const int blk_size) const; + + /** + * Check if packet corresponds to a given address and address space. + * + * @param addr The address to compare against. + * @param is_secure Whether addr belongs to the secure address space. + * @return Whether packet matches description. + */ + bool matchAddr(const Addr addr, const bool is_secure) const; + + /** + * Check if this packet refers to the same address and address space as + * another packet. + * + * @param pkt The packet to compare against. + * @return Whether packet matches description. + */ + bool matchAddr(const PacketPtr pkt) const; public: /** diff --git a/src/mem/packet_queue.cc b/src/mem/packet_queue.cc index 282625a76..dd1ba3dcd 100644 --- a/src/mem/packet_queue.cc +++ b/src/mem/packet_queue.cc @@ -72,12 +72,12 @@ PacketQueue::retry() } bool -PacketQueue::hasAddr(Addr addr) const +PacketQueue::checkConflict(const PacketPtr pkt, const int blk_size) const { // caller is responsible for ensuring that all packets have the // same alignment for (const auto& p : transmitList) { - if (p.pkt->getAddr() == addr) + if (p.pkt->matchBlockAddr(pkt, blk_size)) return true; } return false; @@ -138,8 +138,7 @@ PacketQueue::schedSendTiming(PacketPtr pkt, Tick when) auto it = transmitList.end(); while (it != transmitList.begin()) { --it; - if ((forceOrder && it->pkt->getAddr() == pkt->getAddr()) || - it->tick <= when) { + if ((forceOrder && it->pkt->matchAddr(pkt)) || it->tick <= when) { // emplace inserts the element before the position pointed to by // the iterator, so advance it one step transmitList.emplace(++it, when, pkt); diff --git a/src/mem/packet_queue.hh b/src/mem/packet_queue.hh index 4ac4bf349..b9c5b7554 100644 --- a/src/mem/packet_queue.hh +++ b/src/mem/packet_queue.hh @@ -172,9 +172,14 @@ class PacketQueue : public Drainable { return transmitList.empty() ? MaxTick : transmitList.front().tick; } /** - * Check if a packets address exists in the queue. + * Check if a packet corresponding to the same address exists in the + * queue. + * + * @param pkt The packet to compare against. + * @param blk_size Block size in bytes. + * @return Whether a corresponding packet is found. */ - bool hasAddr(Addr addr) const; + bool checkConflict(const PacketPtr pkt, const int blk_size) const; /** Check the list of buffered packets against the supplied * functional request. */ diff --git a/src/mem/simple_mem.cc b/src/mem/simple_mem.cc index 297aa6135..fcc1cff23 100644 --- a/src/mem/simple_mem.cc +++ b/src/mem/simple_mem.cc @@ -174,7 +174,7 @@ SimpleMemory::recvTimingReq(PacketPtr pkt) auto i = packetQueue.end(); --i; while (i != packetQueue.begin() && when_to_send < i->tick && - i->pkt->getAddr() != pkt->getAddr()) + !i->pkt->matchAddr(pkt)) --i; // emplace inserts the element before the position pointed to by