diff -r d54b7775a6b0 -r a4bda8b98b95 src/cpu/base_dyn_inst.hh --- a/src/cpu/base_dyn_inst.hh Tue Mar 29 19:36:36 2011 -0400 +++ b/src/cpu/base_dyn_inst.hh Wed Mar 30 10:38:06 2011 -0500 @@ -243,6 +243,9 @@ /** The effective virtual address (lds & stores only). */ Addr effAddr; + /** The size of the request added to the effective address */ + Addr effAddrMax; + /** Is the effective virtual address valid. */ bool effAddrValid; @@ -892,6 +895,7 @@ if (translationCompleted) { if (fault == NoFault) { effAddr = req->getVaddr(); + effAddrMax = effAddr + size - 1; effAddrValid = true; fault = cpu->read(req, sreqLow, sreqHigh, data, lqIdx); } else { @@ -962,6 +966,7 @@ if (fault == NoFault && translationCompleted) { effAddr = req->getVaddr(); + effAddrMax = effAddr + size - 1; effAddrValid = true; fault = cpu->write(req, sreqLow, sreqHigh, data, sqIdx); } diff -r d54b7775a6b0 -r a4bda8b98b95 src/cpu/o3/O3CPU.py --- a/src/cpu/o3/O3CPU.py Tue Mar 29 19:36:36 2011 -0400 +++ b/src/cpu/o3/O3CPU.py Wed Mar 30 10:38:06 2011 -0500 @@ -118,6 +118,9 @@ LQEntries = Param.Unsigned(32, "Number of load queue entries") SQEntries = Param.Unsigned(32, "Number of store queue entries") + LSQDepCheckShift = Param.Unsigned(4, "Number of places to shift addr before check") + LSQCheckLoads = Param.Bool(True, + "Should dependency violations be checked for loads & stores or just stores") LFSTSize = Param.Unsigned(1024, "Last fetched store table size") SSITSize = Param.Unsigned(1024, "Store set ID table size") diff -r d54b7775a6b0 -r a4bda8b98b95 src/cpu/o3/lsq_unit.hh --- a/src/cpu/o3/lsq_unit.hh Tue Mar 29 19:36:36 2011 -0400 +++ b/src/cpu/o3/lsq_unit.hh Wed Mar 30 10:38:06 2011 -0500 @@ -111,6 +111,12 @@ /** Inserts a store instruction. */ void insertStore(DynInstPtr &store_inst); + /** Check for ordering violations in the LSQ + * @param load_idx index to start checking at + * @param inst the instruction to check + */ + Fault checkViolations(int load_idx, DynInstPtr &inst); + /** Executes a load instruction. */ Fault executeLoad(DynInstPtr &inst); @@ -366,6 +372,14 @@ */ unsigned SQEntries; + /** The number of places to shift addresses in the LSQ before checking + * for dependency violations + */ + unsigned depCheckShift; + + /** Should loads be checked for dependency issues */ + bool checkLoads; + /** The number of load instructions in the LQ. */ int loads; /** The number of store instructions in the SQ. */ diff -r d54b7775a6b0 -r a4bda8b98b95 src/cpu/o3/lsq_unit_impl.hh --- a/src/cpu/o3/lsq_unit_impl.hh Tue Mar 29 19:36:36 2011 -0400 +++ b/src/cpu/o3/lsq_unit_impl.hh Wed Mar 30 10:38:06 2011 -0500 @@ -162,6 +162,9 @@ loadQueue.resize(LQEntries); storeQueue.resize(SQEntries); + depCheckShift = params->LSQDepCheckShift; + checkLoads = params->LSQCheckLoads; + loadHead = loadTail = 0; storeHead = storeWBIdx = storeTail = 0; @@ -438,6 +441,59 @@ template Fault +LSQUnit::checkViolations(int load_idx, DynInstPtr &inst) +{ + Addr inst_eff_addr1 = inst->effAddr >> depCheckShift; + Addr inst_eff_addr2 = inst->effAddrMax >> depCheckShift; + + // We only support checking max/min, if that crosses more than + // two boundaries we have a problem + assert((inst_eff_addr2 - inst_eff_addr1) <= 1); + + /** @todo in theory you only need to check an instruction that has executed + * however, there isn't a good way in the pipeline at the moment to check + * all instructions that will execute before the store writes back. Thus, + * like the implementation that came before it, we're overly conservative. + */ + while (load_idx != loadTail) { + DynInstPtr ld_inst = loadQueue[load_idx]; + if (!ld_inst->effAddrValid || ld_inst->uncacheable()) { + incrLdIdx(load_idx); + continue; + } + + Addr ld_eff_addr1 = ld_inst->effAddr >> depCheckShift; + Addr ld_eff_addr2 = ld_inst->effAddrMax >> depCheckShift; + assert((ld_eff_addr2 - ld_eff_addr1) <= 1); + + if ((inst_eff_addr2 > ld_eff_addr1 && inst_eff_addr1 < ld_eff_addr2) || + inst_eff_addr1 == ld_eff_addr1) { + // A load/store incorrectly passed this load/store. + // Check if we already have a violator, or if it's newer + // squash and refetch. + if (memDepViolator && ld_inst->seqNum > memDepViolator->seqNum) + break; + + DPRINTF(LSQUnit, "Detected fault with inst [sn:%lli] and [sn:%lli]" + " at address %#x\n", inst->seqNum, ld_inst->seqNum, + ld_eff_addr1); + memDepViolator = ld_inst; + + ++lsqMemOrderViolation; + + return TheISA::genMachineCheckFault(); + } + + incrLdIdx(load_idx); + } + return NoFault; +} + + + + +template +Fault LSQUnit::executeLoad(DynInstPtr &inst) { using namespace TheISA; @@ -477,39 +533,9 @@ assert(inst->effAddrValid); int load_idx = inst->lqIdx; incrLdIdx(load_idx); - while (load_idx != loadTail) { - // Really only need to check loads that have actually executed - // @todo: For now this is extra conservative, detecting a - // violation if the addresses match assuming all accesses - // are quad word accesses. - - // @todo: Fix this, magic number being used here - - // @todo: Uncachable load is not executed until it reaches - // the head of the ROB. Once this if checks only the executed - // loads(as noted above), this check can be removed - if (loadQueue[load_idx]->effAddrValid && - ((loadQueue[load_idx]->effAddr >> 8) - == (inst->effAddr >> 8)) && - !loadQueue[load_idx]->uncacheable()) { - // A load incorrectly passed this load. Squash and refetch. - // For now return a fault to show that it was unsuccessful. - DynInstPtr violator = loadQueue[load_idx]; - if (!memDepViolator || - (violator->seqNum < memDepViolator->seqNum)) { - memDepViolator = violator; - } else { - break; - } - - ++lsqMemOrderViolation; - - return genMachineCheckFault(); - } - - incrLdIdx(load_idx); - } + if (checkLoads) + return checkViolations(load_idx, inst); } return load_fault; @@ -564,44 +590,8 @@ ++storesToWB; } - assert(store_inst->effAddrValid); - while (load_idx != loadTail) { - // Really only need to check loads that have actually executed - // It's safe to check all loads because effAddr is set to - // InvalAddr when the dyn inst is created. + return checkViolations(load_idx, store_inst); - // @todo: For now this is extra conservative, detecting a - // violation if the addresses match assuming all accesses - // are quad word accesses. - - // @todo: Fix this, magic number being used here - - // @todo: Uncachable load is not executed until it reaches - // the head of the ROB. Once this if checks only the executed - // loads(as noted above), this check can be removed - if (loadQueue[load_idx]->effAddrValid && - ((loadQueue[load_idx]->effAddr >> 8) - == (store_inst->effAddr >> 8)) && - !loadQueue[load_idx]->uncacheable()) { - // A load incorrectly passed this store. Squash and refetch. - // For now return a fault to show that it was unsuccessful. - DynInstPtr violator = loadQueue[load_idx]; - if (!memDepViolator || - (violator->seqNum < memDepViolator->seqNum)) { - memDepViolator = violator; - } else { - break; - } - - ++lsqMemOrderViolation; - - return genMachineCheckFault(); - } - - incrLdIdx(load_idx); - } - - return store_fault; } template