From d9172c8f462511cde474040581063180be18540a Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 5 Oct 2006 16:26:16 -0400 Subject: Partial reimplementation of the bus. The "clock" and "width" parameters have been added, and the HasData flag has been partially added to packets. --HG-- extra : convert_revision : abb2a259fcf843457abbc0bd36f9504fbe6d7d39 --- src/mem/bus.cc | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'src/mem/bus.cc') diff --git a/src/mem/bus.cc b/src/mem/bus.cc index cf9e54e62..e3b395afc 100644 --- a/src/mem/bus.cc +++ b/src/mem/bus.cc @@ -78,6 +78,16 @@ Bus::recvTiming(Packet *pkt) pkt->getSrc(), pkt->getDest(), pkt->getAddr(), pkt->cmdString()); short dest = pkt->getDest(); + //if (pkt->isRequest() && curTick < tickAddrLastUsed || + // (pkt->isResponse() || pkt->hasData()) && curTick < tickDataLastUsed) { + //We're going to need resources that have already been committed + //Send this guy to the back of the line + //We don't need to worry about scheduling an event to deal with when the + //bus is freed because that's handled when tick*LastUsed is incremented. + // retryList.push_back(interfaces[pkt->getSrc()]); + // return false; + //} + if (dest == Packet::Broadcast) { if ( timingSnoopPhase1(pkt) ) { @@ -95,8 +105,29 @@ Bus::recvTiming(Packet *pkt) assert(dest != pkt->getSrc()); // catch infinite loops port = interfaces[dest]; } + + if (port->sendTiming(pkt)) { - // packet was successfully sent, just return true. + // Packet was successfully sent. + // Figure out what resources were used, and then return true. + //if (pkt->isRequest()) { + // The address bus will be used for one cycle + // while (tickAddrLastUsed <= curTick) + // tickAddrLastUsed += clock; + //} + //if (pkt->isResponse() || pkt->hasData()) { + // Use up the data bus for at least one bus cycle + // while (tickDataLastUsed <= curTick) + // tickDataLastUsed += clock; + // Use up the data bus for however many cycles remain + // if (pkt->hasData()) { + // int dataSize = pkt->getSize(); + // for (int transmitted = width; transmitted < dataSize; + // transmitted += width) { + // tickDataLastUsed += clock; + // } + // } + //} return true; } @@ -380,16 +411,20 @@ Bus::addressRanges(AddrRangeList &resp, AddrRangeList &snoop, int id) BEGIN_DECLARE_SIM_OBJECT_PARAMS(Bus) Param bus_id; + Param clock; + Param width; END_DECLARE_SIM_OBJECT_PARAMS(Bus) BEGIN_INIT_SIM_OBJECT_PARAMS(Bus) - INIT_PARAM(bus_id, "a globally unique bus id") + INIT_PARAM(bus_id, "a globally unique bus id"), + INIT_PARAM(clock, "bus clock speed"), + INIT_PARAM(width, "width of the bus (bits)") END_INIT_SIM_OBJECT_PARAMS(Bus) CREATE_SIM_OBJECT(Bus) { - return new Bus(getInstanceName(), bus_id); + return new Bus(getInstanceName(), bus_id, clock, width); } REGISTER_SIM_OBJECT("Bus", Bus) -- cgit v1.2.3 From 00481d1f192c832d654379c2296d5b6020c12b1a Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sun, 8 Oct 2006 14:08:58 -0400 Subject: A possible implementation of a multiplexed bus. --HG-- extra : convert_revision : 3c560eda12ffd8ca539c91024baf2770b963ede8 --- src/mem/bus.cc | 162 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 103 insertions(+), 59 deletions(-) (limited to 'src/mem/bus.cc') diff --git a/src/mem/bus.cc b/src/mem/bus.cc index e3b395afc..fff3dfed6 100644 --- a/src/mem/bus.cc +++ b/src/mem/bus.cc @@ -67,6 +67,44 @@ Bus::init() (*intIter)->sendStatusChange(Port::RangeChange); } +Bus::BusFreeEvent::BusFreeEvent(Bus *_bus) : Event(&mainEventQueue), bus(_bus) +{} + +void Bus::BusFreeEvent::process() +{ + bus->recvRetry(0); +} + +const char * Bus::BusFreeEvent::description() +{ + return "bus became available"; +} + +void +Bus::occupyBus(int numCycles) +{ + //Move up when the bus will next be free + //We avoid the use of divide by adding repeatedly + //This should be faster if the value is updated frequently, but should + //be may be slower otherwise. + + //Bring tickNextIdle up to the present tick + //There is some potential ambiguity where a cycle starts, which might make + //a difference when devices are acting right around a cycle boundary. Using + //a < allows things which happen exactly on a cycle boundary to take up only + //the following cycle. Anthing that happens later will have to "wait" for the + //end of that cycle, and then start using the bus after that. + while (tickNextIdle < curTick) + tickNextIdle += clock; + //Advance it numCycles bus cycles. + //XXX Should this use the repeating add trick as well? + tickNextIdle += (numCycles * clock); + if (!busIdle.scheduled()) { + busIdle.schedule(tickNextIdle); + } else { + busIdle.reschedule(tickNextIdle); + } +} /** Function called by the port when the bus is receiving a Timing * transaction.*/ @@ -77,83 +115,89 @@ Bus::recvTiming(Packet *pkt) DPRINTF(Bus, "recvTiming: packet src %d dest %d addr 0x%x cmd %s\n", pkt->getSrc(), pkt->getDest(), pkt->getAddr(), pkt->cmdString()); - short dest = pkt->getDest(); - //if (pkt->isRequest() && curTick < tickAddrLastUsed || - // (pkt->isResponse() || pkt->hasData()) && curTick < tickDataLastUsed) { - //We're going to need resources that have already been committed - //Send this guy to the back of the line - //We don't need to worry about scheduling an event to deal with when the - //bus is freed because that's handled when tick*LastUsed is incremented. - // retryList.push_back(interfaces[pkt->getSrc()]); - // return false; - //} + Port *pktPort = interfaces[pkt->getSrc()]; - if (dest == Packet::Broadcast) { - if ( timingSnoopPhase1(pkt) ) - { - timingSnoopPhase2(pkt); - port = findPort(pkt->getAddr(), pkt->getSrc()); - } - else - { - //Snoop didn't succeed - retryList.push_back(interfaces[pkt->getSrc()]); - return false; + // If the bus is busy, or other devices are in line ahead of the current one, + // put this device on the retry list. + if (tickNextIdle > curTick || (retryList.size() && pktPort != retryingPort)) { + addToRetryList(pktPort); + return false; + } + + // If the bus is blocked, make the device wait. + if (!(port = findDestPort(pkt, pkt->getSrc()))) { + addToRetryList(pktPort); + return false; + } + + // The packet will be sent. Figure out how long it occupies the bus. + int numCycles = 0; + // Requests need one cycle to send an address + if (pkt->isRequest()) + numCycles++; + else if (pkt->isResponse() || pkt->hasData()) { + // If a packet has data, it needs ceil(size/width) cycles to send it + // We're using the "adding instead of dividing" trick again here + if (pkt->hasData()) { + int dataSize = pkt->getSize(); + for (int transmitted = 0; transmitted < dataSize; + transmitted += width) { + numCycles++; + } + } else { + // If the packet didn't have data, it must have been a response. + // Those use the bus for one cycle to send their data. + numCycles++; } - } else { - assert(dest >= 0 && dest < interfaces.size()); - assert(dest != pkt->getSrc()); // catch infinite loops - port = interfaces[dest]; } + occupyBus(numCycles); if (port->sendTiming(pkt)) { - // Packet was successfully sent. - // Figure out what resources were used, and then return true. - //if (pkt->isRequest()) { - // The address bus will be used for one cycle - // while (tickAddrLastUsed <= curTick) - // tickAddrLastUsed += clock; - //} - //if (pkt->isResponse() || pkt->hasData()) { - // Use up the data bus for at least one bus cycle - // while (tickDataLastUsed <= curTick) - // tickDataLastUsed += clock; - // Use up the data bus for however many cycles remain - // if (pkt->hasData()) { - // int dataSize = pkt->getSize(); - // for (int transmitted = width; transmitted < dataSize; - // transmitted += width) { - // tickDataLastUsed += clock; - // } - // } - //} + // Packet was successfully sent. Return true. return true; } - // packet not successfully sent - retryList.push_back(interfaces[pkt->getSrc()]); + // Packet not successfully sent. Leave or put it on the retry list. + addToRetryList(pktPort); return false; } void Bus::recvRetry(int id) { - // Go through all the elements on the list calling sendRetry on each - // This is not very efficient at all but it works. Ultimately we should end - // up with something that is more intelligent. - int initialSize = retryList.size(); - int i; - Port *p; - - for (i = 0; i < initialSize; i++) { - assert(retryList.size() > 0); - p = retryList.front(); - retryList.pop_front(); - p->sendRetry(); + //If there's anything waiting... + if (retryList.size()) { + retryingPort = retryList.front(); + retryingPort->sendRetry(); + //If the retryingPort pointer isn't null, either sendTiming wasn't + //called, or it was and the packet was successfully sent. + if (retryingPort) { + retryList.pop_front(); + retryingPort = 0; + } } } +Port * +Bus::findDestPort(PacketPtr pkt, int id) +{ + Port * port = NULL; + short dest = pkt->getDest(); + + if (dest == Packet::Broadcast) { + if (timingSnoopPhase1(pkt)) { + timingSnoopPhase2(pkt); + port = findPort(pkt->getAddr(), pkt->getSrc()); + } + //else, port stays NULL + } else { + assert(dest >= 0 && dest < interfaces.size()); + assert(dest != pkt->getSrc()); // catch infinite loops + port = interfaces[dest]; + } + return port; +} Port * Bus::findPort(Addr addr, int id) -- cgit v1.2.3 From a82f017591ecb78cb098e38314d87d64fcaaa37f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sun, 8 Oct 2006 18:44:49 -0400 Subject: bus changes src/mem/bus.cc: src/mem/bus.hh: minor fix and some formatting changes src/python/m5/objects/Bus.py: changed bits to bytes --HG-- extra : convert_revision : dcd22205604b7a2727eaf2094084c4858f3589c5 --- src/mem/bus.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/mem/bus.cc') diff --git a/src/mem/bus.cc b/src/mem/bus.cc index 2a38cb635..4cd4dd71a 100644 --- a/src/mem/bus.cc +++ b/src/mem/bus.cc @@ -68,7 +68,9 @@ Bus::init() } Bus::BusFreeEvent::BusFreeEvent(Bus *_bus) : Event(&mainEventQueue), bus(_bus) -{} +{ + assert(!scheduled()); +} void Bus::BusFreeEvent::process() { @@ -104,6 +106,7 @@ Bus::occupyBus(int numCycles) } else { busIdle.reschedule(tickNextIdle); } + DPRINTF(Bus, "The bus is now occupied from tick %d to %d\n", curTick, tickNextIdle); } /** Function called by the port when the bus is receiving a Timing @@ -155,6 +158,11 @@ Bus::recvTiming(Packet *pkt) if (port->sendTiming(pkt)) { // Packet was successfully sent. Return true. + // Also take care of retries + if (retryingPort) { + retryList.pop_front(); + retryingPort = NULL; + } return true; } @@ -166,15 +174,15 @@ Bus::recvTiming(Packet *pkt) void Bus::recvRetry(int id) { - //If there's anything waiting... + // If there's anything waiting... if (retryList.size()) { retryingPort = retryList.front(); retryingPort->sendRetry(); - //If the retryingPort pointer isn't null, either sendTiming wasn't - //called, or it was and the packet was successfully sent. + // If the retryingPort pointer isn't null, sendTiming wasn't called if (retryingPort) { + warn("sendRetry didn't call sendTiming\n"); retryList.pop_front(); - retryingPort = 0; + retryingPort = NULL; } } } -- cgit v1.2.3