lsq_unit_impl.hh revision 10030
19814Sandreas.hansson@arm.com 22292SN/A/* 310030SAli.Saidi@ARM.com * Copyright (c) 2010-2013 ARM Limited 47597Sminkyu.jeong@arm.com * All rights reserved 57597Sminkyu.jeong@arm.com * 67597Sminkyu.jeong@arm.com * The license below extends only to copyright in the software and shall 77597Sminkyu.jeong@arm.com * not be construed as granting a license to any other intellectual 87597Sminkyu.jeong@arm.com * property including but not limited to intellectual property relating 97597Sminkyu.jeong@arm.com * to a hardware implementation of the functionality of the software 107597Sminkyu.jeong@arm.com * licensed hereunder. You may use the software subject to the license 117597Sminkyu.jeong@arm.com * terms below provided that you ensure that this notice is replicated 127597Sminkyu.jeong@arm.com * unmodified and in its entirety in all distributions of the software, 137597Sminkyu.jeong@arm.com * modified or unmodified, in source code or in binary form. 147597Sminkyu.jeong@arm.com * 152292SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 162292SN/A * All rights reserved. 172292SN/A * 182292SN/A * Redistribution and use in source and binary forms, with or without 192292SN/A * modification, are permitted provided that the following conditions are 202292SN/A * met: redistributions of source code must retain the above copyright 212292SN/A * notice, this list of conditions and the following disclaimer; 222292SN/A * redistributions in binary form must reproduce the above copyright 232292SN/A * notice, this list of conditions and the following disclaimer in the 242292SN/A * documentation and/or other materials provided with the distribution; 252292SN/A * neither the name of the copyright holders nor the names of its 262292SN/A * contributors may be used to endorse or promote products derived from 272292SN/A * this software without specific prior written permission. 282292SN/A * 292292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312292SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 332292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342292SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352292SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362292SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 382292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402689Sktlim@umich.edu * 412689Sktlim@umich.edu * Authors: Kevin Lim 422689Sktlim@umich.edu * Korey Sewell 432292SN/A */ 442292SN/A 459944Smatt.horsnell@ARM.com#ifndef __CPU_O3_LSQ_UNIT_IMPL_HH__ 469944Smatt.horsnell@ARM.com#define __CPU_O3_LSQ_UNIT_IMPL_HH__ 479944Smatt.horsnell@ARM.com 488591Sgblack@eecs.umich.edu#include "arch/generic/debugfaults.hh" 493326Sktlim@umich.edu#include "arch/locked_mem.hh" 508229Snate@binkert.org#include "base/str.hh" 516658Snate@binkert.org#include "config/the_isa.hh" 528887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh" 532907Sktlim@umich.edu#include "cpu/o3/lsq.hh" 542292SN/A#include "cpu/o3/lsq_unit.hh" 558232Snate@binkert.org#include "debug/Activity.hh" 568232Snate@binkert.org#include "debug/IEW.hh" 578232Snate@binkert.org#include "debug/LSQUnit.hh" 589527SMatt.Horsnell@arm.com#include "debug/O3PipeView.hh" 592722Sktlim@umich.edu#include "mem/packet.hh" 602669Sktlim@umich.edu#include "mem/request.hh" 612292SN/A 622669Sktlim@umich.edutemplate<class Impl> 632678Sktlim@umich.eduLSQUnit<Impl>::WritebackEvent::WritebackEvent(DynInstPtr &_inst, PacketPtr _pkt, 642678Sktlim@umich.edu LSQUnit *lsq_ptr) 658581Ssteve.reinhardt@amd.com : Event(Default_Pri, AutoDelete), 668581Ssteve.reinhardt@amd.com inst(_inst), pkt(_pkt), lsqPtr(lsq_ptr) 672292SN/A{ 682292SN/A} 692292SN/A 702669Sktlim@umich.edutemplate<class Impl> 712292SN/Avoid 722678Sktlim@umich.eduLSQUnit<Impl>::WritebackEvent::process() 732292SN/A{ 749444SAndreas.Sandberg@ARM.com assert(!lsqPtr->cpu->switchedOut()); 759444SAndreas.Sandberg@ARM.com 769444SAndreas.Sandberg@ARM.com lsqPtr->writeback(inst, pkt); 774319Sktlim@umich.edu 784319Sktlim@umich.edu if (pkt->senderState) 794319Sktlim@umich.edu delete pkt->senderState; 804319Sktlim@umich.edu 814319Sktlim@umich.edu delete pkt->req; 822678Sktlim@umich.edu delete pkt; 832678Sktlim@umich.edu} 842292SN/A 852678Sktlim@umich.edutemplate<class Impl> 862678Sktlim@umich.educonst char * 875336Shines@cs.fsu.eduLSQUnit<Impl>::WritebackEvent::description() const 882678Sktlim@umich.edu{ 894873Sstever@eecs.umich.edu return "Store writeback"; 902678Sktlim@umich.edu} 912292SN/A 922678Sktlim@umich.edutemplate<class Impl> 932678Sktlim@umich.eduvoid 942678Sktlim@umich.eduLSQUnit<Impl>::completeDataAccess(PacketPtr pkt) 952678Sktlim@umich.edu{ 962678Sktlim@umich.edu LSQSenderState *state = dynamic_cast<LSQSenderState *>(pkt->senderState); 972678Sktlim@umich.edu DynInstPtr inst = state->inst; 987852SMatt.Horsnell@arm.com DPRINTF(IEW, "Writeback event [sn:%lli].\n", inst->seqNum); 997852SMatt.Horsnell@arm.com DPRINTF(Activity, "Activity: Writeback event [sn:%lli].\n", inst->seqNum); 1002344SN/A 1012678Sktlim@umich.edu //iewStage->ldstQueue.removeMSHR(inst->threadNumber,inst->seqNum); 1022678Sktlim@umich.edu 1036974Stjones1@inf.ed.ac.uk // If this is a split access, wait until all packets are received. 1046974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && !state->complete()) { 1056974Stjones1@inf.ed.ac.uk delete pkt->req; 1066974Stjones1@inf.ed.ac.uk delete pkt; 1076974Stjones1@inf.ed.ac.uk return; 1086974Stjones1@inf.ed.ac.uk } 1096974Stjones1@inf.ed.ac.uk 1109444SAndreas.Sandberg@ARM.com assert(!cpu->switchedOut()); 1119444SAndreas.Sandberg@ARM.com if (inst->isSquashed()) { 1122820Sktlim@umich.edu iewStage->decrWb(inst->seqNum); 1132678Sktlim@umich.edu } else { 1142678Sktlim@umich.edu if (!state->noWB) { 1156974Stjones1@inf.ed.ac.uk if (!TheISA::HasUnalignedMemAcc || !state->isSplit || 1166974Stjones1@inf.ed.ac.uk !state->isLoad) { 1176974Stjones1@inf.ed.ac.uk writeback(inst, pkt); 1186974Stjones1@inf.ed.ac.uk } else { 1196974Stjones1@inf.ed.ac.uk writeback(inst, state->mainPkt); 1206974Stjones1@inf.ed.ac.uk } 1212678Sktlim@umich.edu } 1222678Sktlim@umich.edu 1232678Sktlim@umich.edu if (inst->isStore()) { 1242678Sktlim@umich.edu completeStore(state->idx); 1252678Sktlim@umich.edu } 1262344SN/A } 1272307SN/A 1286974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && state->isSplit && state->isLoad) { 1296974Stjones1@inf.ed.ac.uk delete state->mainPkt->req; 1306974Stjones1@inf.ed.ac.uk delete state->mainPkt; 1316974Stjones1@inf.ed.ac.uk } 13210020Smatt.horsnell@ARM.com 13310020Smatt.horsnell@ARM.com pkt->req->setAccessLatency(); 13410023Smatt.horsnell@ARM.com cpu->ppDataAccessComplete->notify(std::make_pair(inst, pkt)); 13510023Smatt.horsnell@ARM.com 1362678Sktlim@umich.edu delete state; 1374032Sktlim@umich.edu delete pkt->req; 1382678Sktlim@umich.edu delete pkt; 1392292SN/A} 1402292SN/A 1412292SN/Atemplate <class Impl> 1422292SN/ALSQUnit<Impl>::LSQUnit() 1438545Ssaidi@eecs.umich.edu : loads(0), stores(0), storesToWB(0), cacheBlockMask(0), stalled(false), 1442678Sktlim@umich.edu isStoreBlocked(false), isLoadBlocked(false), 1458727Snilay@cs.wisc.edu loadBlockedHandled(false), storeInFlight(false), hasPendingPkt(false) 1462292SN/A{ 1472292SN/A} 1482292SN/A 1492292SN/Atemplate<class Impl> 1502292SN/Avoid 1515529Snate@binkert.orgLSQUnit<Impl>::init(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params, 1525529Snate@binkert.org LSQ *lsq_ptr, unsigned maxLQEntries, unsigned maxSQEntries, 1535529Snate@binkert.org unsigned id) 1542292SN/A{ 1554329Sktlim@umich.edu cpu = cpu_ptr; 1564329Sktlim@umich.edu iewStage = iew_ptr; 1574329Sktlim@umich.edu 1584329Sktlim@umich.edu DPRINTF(LSQUnit, "Creating LSQUnit%i object.\n",id); 1592292SN/A 1602907Sktlim@umich.edu lsq = lsq_ptr; 1612907Sktlim@umich.edu 1622292SN/A lsqID = id; 1632292SN/A 1642329SN/A // Add 1 for the sentinel entry (they are circular queues). 1652329SN/A LQEntries = maxLQEntries + 1; 1662329SN/A SQEntries = maxSQEntries + 1; 1672292SN/A 1689936SFaissal.Sleiman@arm.com //Due to uint8_t index in LSQSenderState 1699936SFaissal.Sleiman@arm.com assert(LQEntries <= 256); 1709936SFaissal.Sleiman@arm.com assert(SQEntries <= 256); 1719936SFaissal.Sleiman@arm.com 1722292SN/A loadQueue.resize(LQEntries); 1732292SN/A storeQueue.resize(SQEntries); 1742292SN/A 1758199SAli.Saidi@ARM.com depCheckShift = params->LSQDepCheckShift; 1768199SAli.Saidi@ARM.com checkLoads = params->LSQCheckLoads; 1779444SAndreas.Sandberg@ARM.com cachePorts = params->cachePorts; 1789444SAndreas.Sandberg@ARM.com needsTSO = params->needsTSO; 1799444SAndreas.Sandberg@ARM.com 1809444SAndreas.Sandberg@ARM.com resetState(); 1819444SAndreas.Sandberg@ARM.com} 1829444SAndreas.Sandberg@ARM.com 1839444SAndreas.Sandberg@ARM.com 1849444SAndreas.Sandberg@ARM.comtemplate<class Impl> 1859444SAndreas.Sandberg@ARM.comvoid 1869444SAndreas.Sandberg@ARM.comLSQUnit<Impl>::resetState() 1879444SAndreas.Sandberg@ARM.com{ 1889444SAndreas.Sandberg@ARM.com loads = stores = storesToWB = 0; 1898199SAli.Saidi@ARM.com 1902292SN/A loadHead = loadTail = 0; 1912292SN/A 1922292SN/A storeHead = storeWBIdx = storeTail = 0; 1932292SN/A 1942292SN/A usedPorts = 0; 1952292SN/A 1963492Sktlim@umich.edu retryPkt = NULL; 1972329SN/A memDepViolator = NULL; 1982292SN/A 1992292SN/A blockedLoadSeqNum = 0; 2009444SAndreas.Sandberg@ARM.com 2019444SAndreas.Sandberg@ARM.com stalled = false; 2029444SAndreas.Sandberg@ARM.com isLoadBlocked = false; 2039444SAndreas.Sandberg@ARM.com loadBlockedHandled = false; 2049444SAndreas.Sandberg@ARM.com 2059814Sandreas.hansson@arm.com cacheBlockMask = ~(cpu->cacheLineSize() - 1); 2062292SN/A} 2072292SN/A 2082292SN/Atemplate<class Impl> 2092292SN/Astd::string 2102292SN/ALSQUnit<Impl>::name() const 2112292SN/A{ 2122292SN/A if (Impl::MaxThreads == 1) { 2132292SN/A return iewStage->name() + ".lsq"; 2142292SN/A } else { 2158247Snate@binkert.org return iewStage->name() + ".lsq.thread" + to_string(lsqID); 2162292SN/A } 2172292SN/A} 2182292SN/A 2192292SN/Atemplate<class Impl> 2202292SN/Avoid 2212727Sktlim@umich.eduLSQUnit<Impl>::regStats() 2222727Sktlim@umich.edu{ 2232727Sktlim@umich.edu lsqForwLoads 2242727Sktlim@umich.edu .name(name() + ".forwLoads") 2252727Sktlim@umich.edu .desc("Number of loads that had data forwarded from stores"); 2262727Sktlim@umich.edu 2272727Sktlim@umich.edu invAddrLoads 2282727Sktlim@umich.edu .name(name() + ".invAddrLoads") 2292727Sktlim@umich.edu .desc("Number of loads ignored due to an invalid address"); 2302727Sktlim@umich.edu 2312727Sktlim@umich.edu lsqSquashedLoads 2322727Sktlim@umich.edu .name(name() + ".squashedLoads") 2332727Sktlim@umich.edu .desc("Number of loads squashed"); 2342727Sktlim@umich.edu 2352727Sktlim@umich.edu lsqIgnoredResponses 2362727Sktlim@umich.edu .name(name() + ".ignoredResponses") 2372727Sktlim@umich.edu .desc("Number of memory responses ignored because the instruction is squashed"); 2382727Sktlim@umich.edu 2392361SN/A lsqMemOrderViolation 2402361SN/A .name(name() + ".memOrderViolation") 2412361SN/A .desc("Number of memory ordering violations"); 2422361SN/A 2432727Sktlim@umich.edu lsqSquashedStores 2442727Sktlim@umich.edu .name(name() + ".squashedStores") 2452727Sktlim@umich.edu .desc("Number of stores squashed"); 2462727Sktlim@umich.edu 2472727Sktlim@umich.edu invAddrSwpfs 2482727Sktlim@umich.edu .name(name() + ".invAddrSwpfs") 2492727Sktlim@umich.edu .desc("Number of software prefetches ignored due to an invalid address"); 2502727Sktlim@umich.edu 2512727Sktlim@umich.edu lsqBlockedLoads 2522727Sktlim@umich.edu .name(name() + ".blockedLoads") 2532727Sktlim@umich.edu .desc("Number of blocked loads due to partial load-store forwarding"); 2542727Sktlim@umich.edu 2552727Sktlim@umich.edu lsqRescheduledLoads 2562727Sktlim@umich.edu .name(name() + ".rescheduledLoads") 2572727Sktlim@umich.edu .desc("Number of loads that were rescheduled"); 2582727Sktlim@umich.edu 2592727Sktlim@umich.edu lsqCacheBlocked 2602727Sktlim@umich.edu .name(name() + ".cacheBlocked") 2612727Sktlim@umich.edu .desc("Number of times an access to memory failed due to the cache being blocked"); 2622727Sktlim@umich.edu} 2632727Sktlim@umich.edu 2642727Sktlim@umich.edutemplate<class Impl> 2652727Sktlim@umich.eduvoid 2668922Swilliam.wang@arm.comLSQUnit<Impl>::setDcachePort(MasterPort *dcache_port) 2674329Sktlim@umich.edu{ 2684329Sktlim@umich.edu dcachePort = dcache_port; 2694329Sktlim@umich.edu} 2704329Sktlim@umich.edu 2714329Sktlim@umich.edutemplate<class Impl> 2724329Sktlim@umich.eduvoid 2732292SN/ALSQUnit<Impl>::clearLQ() 2742292SN/A{ 2752292SN/A loadQueue.clear(); 2762292SN/A} 2772292SN/A 2782292SN/Atemplate<class Impl> 2792292SN/Avoid 2802292SN/ALSQUnit<Impl>::clearSQ() 2812292SN/A{ 2822292SN/A storeQueue.clear(); 2832292SN/A} 2842292SN/A 2852292SN/Atemplate<class Impl> 2862292SN/Avoid 2879444SAndreas.Sandberg@ARM.comLSQUnit<Impl>::drainSanityCheck() const 2882307SN/A{ 2899444SAndreas.Sandberg@ARM.com for (int i = 0; i < loadQueue.size(); ++i) 2902367SN/A assert(!loadQueue[i]); 2912307SN/A 2922329SN/A assert(storesToWB == 0); 2939444SAndreas.Sandberg@ARM.com assert(!retryPkt); 2942307SN/A} 2952307SN/A 2962307SN/Atemplate<class Impl> 2972307SN/Avoid 2982307SN/ALSQUnit<Impl>::takeOverFrom() 2992307SN/A{ 3009444SAndreas.Sandberg@ARM.com resetState(); 3012307SN/A} 3022307SN/A 3032307SN/Atemplate<class Impl> 3042307SN/Avoid 3052292SN/ALSQUnit<Impl>::resizeLQ(unsigned size) 3062292SN/A{ 3072329SN/A unsigned size_plus_sentinel = size + 1; 3082329SN/A assert(size_plus_sentinel >= LQEntries); 3092292SN/A 3102329SN/A if (size_plus_sentinel > LQEntries) { 3112329SN/A while (size_plus_sentinel > loadQueue.size()) { 3122292SN/A DynInstPtr dummy; 3132292SN/A loadQueue.push_back(dummy); 3142292SN/A LQEntries++; 3152292SN/A } 3162292SN/A } else { 3172329SN/A LQEntries = size_plus_sentinel; 3182292SN/A } 3192292SN/A 3209936SFaissal.Sleiman@arm.com assert(LQEntries <= 256); 3212292SN/A} 3222292SN/A 3232292SN/Atemplate<class Impl> 3242292SN/Avoid 3252292SN/ALSQUnit<Impl>::resizeSQ(unsigned size) 3262292SN/A{ 3272329SN/A unsigned size_plus_sentinel = size + 1; 3282329SN/A if (size_plus_sentinel > SQEntries) { 3292329SN/A while (size_plus_sentinel > storeQueue.size()) { 3302292SN/A SQEntry dummy; 3312292SN/A storeQueue.push_back(dummy); 3322292SN/A SQEntries++; 3332292SN/A } 3342292SN/A } else { 3352329SN/A SQEntries = size_plus_sentinel; 3362292SN/A } 3379936SFaissal.Sleiman@arm.com 3389936SFaissal.Sleiman@arm.com assert(SQEntries <= 256); 3392292SN/A} 3402292SN/A 3412292SN/Atemplate <class Impl> 3422292SN/Avoid 3432292SN/ALSQUnit<Impl>::insert(DynInstPtr &inst) 3442292SN/A{ 3452292SN/A assert(inst->isMemRef()); 3462292SN/A 3472292SN/A assert(inst->isLoad() || inst->isStore()); 3482292SN/A 3492292SN/A if (inst->isLoad()) { 3502292SN/A insertLoad(inst); 3512292SN/A } else { 3522292SN/A insertStore(inst); 3532292SN/A } 3542292SN/A 3552292SN/A inst->setInLSQ(); 3562292SN/A} 3572292SN/A 3582292SN/Atemplate <class Impl> 3592292SN/Avoid 3602292SN/ALSQUnit<Impl>::insertLoad(DynInstPtr &load_inst) 3612292SN/A{ 3622329SN/A assert((loadTail + 1) % LQEntries != loadHead); 3632329SN/A assert(loads < LQEntries); 3642292SN/A 3657720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Inserting load PC %s, idx:%i [sn:%lli]\n", 3667720Sgblack@eecs.umich.edu load_inst->pcState(), loadTail, load_inst->seqNum); 3672292SN/A 3682292SN/A load_inst->lqIdx = loadTail; 3692292SN/A 3702292SN/A if (stores == 0) { 3712292SN/A load_inst->sqIdx = -1; 3722292SN/A } else { 3732292SN/A load_inst->sqIdx = storeTail; 3742292SN/A } 3752292SN/A 3762292SN/A loadQueue[loadTail] = load_inst; 3772292SN/A 3782292SN/A incrLdIdx(loadTail); 3792292SN/A 3802292SN/A ++loads; 3812292SN/A} 3822292SN/A 3832292SN/Atemplate <class Impl> 3842292SN/Avoid 3852292SN/ALSQUnit<Impl>::insertStore(DynInstPtr &store_inst) 3862292SN/A{ 3872292SN/A // Make sure it is not full before inserting an instruction. 3882292SN/A assert((storeTail + 1) % SQEntries != storeHead); 3892292SN/A assert(stores < SQEntries); 3902292SN/A 3917720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Inserting store PC %s, idx:%i [sn:%lli]\n", 3927720Sgblack@eecs.umich.edu store_inst->pcState(), storeTail, store_inst->seqNum); 3932292SN/A 3942292SN/A store_inst->sqIdx = storeTail; 3952292SN/A store_inst->lqIdx = loadTail; 3962292SN/A 3972292SN/A storeQueue[storeTail] = SQEntry(store_inst); 3982292SN/A 3992292SN/A incrStIdx(storeTail); 4002292SN/A 4012292SN/A ++stores; 4022292SN/A} 4032292SN/A 4042292SN/Atemplate <class Impl> 4052292SN/Atypename Impl::DynInstPtr 4062292SN/ALSQUnit<Impl>::getMemDepViolator() 4072292SN/A{ 4082292SN/A DynInstPtr temp = memDepViolator; 4092292SN/A 4102292SN/A memDepViolator = NULL; 4112292SN/A 4122292SN/A return temp; 4132292SN/A} 4142292SN/A 4152292SN/Atemplate <class Impl> 4162292SN/Aunsigned 4172292SN/ALSQUnit<Impl>::numFreeEntries() 4182292SN/A{ 4192292SN/A unsigned free_lq_entries = LQEntries - loads; 4202292SN/A unsigned free_sq_entries = SQEntries - stores; 4212292SN/A 4222292SN/A // Both the LQ and SQ entries have an extra dummy entry to differentiate 4232292SN/A // empty/full conditions. Subtract 1 from the free entries. 4242292SN/A if (free_lq_entries < free_sq_entries) { 4252292SN/A return free_lq_entries - 1; 4262292SN/A } else { 4272292SN/A return free_sq_entries - 1; 4282292SN/A } 4292292SN/A} 4302292SN/A 4312292SN/Atemplate <class Impl> 4328545Ssaidi@eecs.umich.eduvoid 4338545Ssaidi@eecs.umich.eduLSQUnit<Impl>::checkSnoop(PacketPtr pkt) 4348545Ssaidi@eecs.umich.edu{ 4358545Ssaidi@eecs.umich.edu int load_idx = loadHead; 43610030SAli.Saidi@ARM.com DPRINTF(LSQUnit, "Got snoop for address %#x\n", pkt->getAddr()); 4378545Ssaidi@eecs.umich.edu 4389383SAli.Saidi@ARM.com // Unlock the cpu-local monitor when the CPU sees a snoop to a locked 4399383SAli.Saidi@ARM.com // address. The CPU can speculatively execute a LL operation after a pending 4409383SAli.Saidi@ARM.com // SC operation in the pipeline and that can make the cache monitor the CPU 4419383SAli.Saidi@ARM.com // is connected to valid while it really shouldn't be. 44210030SAli.Saidi@ARM.com for (int x = 0; x < cpu->numContexts(); x++) { 4439383SAli.Saidi@ARM.com ThreadContext *tc = cpu->getContext(x); 4449383SAli.Saidi@ARM.com bool no_squash = cpu->thread[x]->noSquashFromTC; 4459383SAli.Saidi@ARM.com cpu->thread[x]->noSquashFromTC = true; 4469383SAli.Saidi@ARM.com TheISA::handleLockedSnoop(tc, pkt, cacheBlockMask); 4479383SAli.Saidi@ARM.com cpu->thread[x]->noSquashFromTC = no_squash; 4489383SAli.Saidi@ARM.com } 4499383SAli.Saidi@ARM.com 45010030SAli.Saidi@ARM.com Addr invalidate_addr = pkt->getAddr() & cacheBlockMask; 45110030SAli.Saidi@ARM.com 45210030SAli.Saidi@ARM.com DynInstPtr ld_inst = loadQueue[load_idx]; 45310030SAli.Saidi@ARM.com if (ld_inst) { 45410030SAli.Saidi@ARM.com Addr load_addr = ld_inst->physEffAddr & cacheBlockMask; 45510030SAli.Saidi@ARM.com // Check that this snoop didn't just invalidate our lock flag 45610030SAli.Saidi@ARM.com if (ld_inst->effAddrValid() && load_addr == invalidate_addr && 45710030SAli.Saidi@ARM.com ld_inst->memReqFlags & Request::LLSC) 45810030SAli.Saidi@ARM.com TheISA::handleLockedSnoopHit(ld_inst.get()); 45910030SAli.Saidi@ARM.com } 46010030SAli.Saidi@ARM.com 4618545Ssaidi@eecs.umich.edu // If this is the only load in the LSQ we don't care 4628545Ssaidi@eecs.umich.edu if (load_idx == loadTail) 4638545Ssaidi@eecs.umich.edu return; 46410030SAli.Saidi@ARM.com 4658545Ssaidi@eecs.umich.edu incrLdIdx(load_idx); 4668545Ssaidi@eecs.umich.edu 4678545Ssaidi@eecs.umich.edu while (load_idx != loadTail) { 4688545Ssaidi@eecs.umich.edu DynInstPtr ld_inst = loadQueue[load_idx]; 4698545Ssaidi@eecs.umich.edu 4709046SAli.Saidi@ARM.com if (!ld_inst->effAddrValid() || ld_inst->uncacheable()) { 4718545Ssaidi@eecs.umich.edu incrLdIdx(load_idx); 4728545Ssaidi@eecs.umich.edu continue; 4738545Ssaidi@eecs.umich.edu } 4748545Ssaidi@eecs.umich.edu 4758545Ssaidi@eecs.umich.edu Addr load_addr = ld_inst->physEffAddr & cacheBlockMask; 4768545Ssaidi@eecs.umich.edu DPRINTF(LSQUnit, "-- inst [sn:%lli] load_addr: %#x to pktAddr:%#x\n", 4778545Ssaidi@eecs.umich.edu ld_inst->seqNum, load_addr, invalidate_addr); 4788545Ssaidi@eecs.umich.edu 4798545Ssaidi@eecs.umich.edu if (load_addr == invalidate_addr) { 4809046SAli.Saidi@ARM.com if (ld_inst->possibleLoadViolation()) { 4818545Ssaidi@eecs.umich.edu DPRINTF(LSQUnit, "Conflicting load at addr %#x [sn:%lli]\n", 48210030SAli.Saidi@ARM.com pkt->getAddr(), ld_inst->seqNum); 4838545Ssaidi@eecs.umich.edu 4848545Ssaidi@eecs.umich.edu // Mark the load for re-execution 4858545Ssaidi@eecs.umich.edu ld_inst->fault = new ReExec; 4868545Ssaidi@eecs.umich.edu } else { 48710030SAli.Saidi@ARM.com DPRINTF(LSQUnit, "HitExternal Snoop for addr %#x [sn:%lli]\n", 48810030SAli.Saidi@ARM.com pkt->getAddr(), ld_inst->seqNum); 48910030SAli.Saidi@ARM.com 49010030SAli.Saidi@ARM.com // Make sure that we don't lose a snoop hitting a LOCKED 49110030SAli.Saidi@ARM.com // address since the LOCK* flags don't get updated until 49210030SAli.Saidi@ARM.com // commit. 49310030SAli.Saidi@ARM.com if (ld_inst->memReqFlags & Request::LLSC) 49410030SAli.Saidi@ARM.com TheISA::handleLockedSnoopHit(ld_inst.get()); 49510030SAli.Saidi@ARM.com 4968545Ssaidi@eecs.umich.edu // If a older load checks this and it's true 4978545Ssaidi@eecs.umich.edu // then we might have missed the snoop 4988545Ssaidi@eecs.umich.edu // in which case we need to invalidate to be sure 4999046SAli.Saidi@ARM.com ld_inst->hitExternalSnoop(true); 5008545Ssaidi@eecs.umich.edu } 5018545Ssaidi@eecs.umich.edu } 5028545Ssaidi@eecs.umich.edu incrLdIdx(load_idx); 5038545Ssaidi@eecs.umich.edu } 5048545Ssaidi@eecs.umich.edu return; 5058545Ssaidi@eecs.umich.edu} 5068545Ssaidi@eecs.umich.edu 5078545Ssaidi@eecs.umich.edutemplate <class Impl> 5082292SN/AFault 5098199SAli.Saidi@ARM.comLSQUnit<Impl>::checkViolations(int load_idx, DynInstPtr &inst) 5108199SAli.Saidi@ARM.com{ 5118199SAli.Saidi@ARM.com Addr inst_eff_addr1 = inst->effAddr >> depCheckShift; 5128199SAli.Saidi@ARM.com Addr inst_eff_addr2 = (inst->effAddr + inst->effSize - 1) >> depCheckShift; 5138199SAli.Saidi@ARM.com 5148199SAli.Saidi@ARM.com /** @todo in theory you only need to check an instruction that has executed 5158199SAli.Saidi@ARM.com * however, there isn't a good way in the pipeline at the moment to check 5168199SAli.Saidi@ARM.com * all instructions that will execute before the store writes back. Thus, 5178199SAli.Saidi@ARM.com * like the implementation that came before it, we're overly conservative. 5188199SAli.Saidi@ARM.com */ 5198199SAli.Saidi@ARM.com while (load_idx != loadTail) { 5208199SAli.Saidi@ARM.com DynInstPtr ld_inst = loadQueue[load_idx]; 5219046SAli.Saidi@ARM.com if (!ld_inst->effAddrValid() || ld_inst->uncacheable()) { 5228199SAli.Saidi@ARM.com incrLdIdx(load_idx); 5238199SAli.Saidi@ARM.com continue; 5248199SAli.Saidi@ARM.com } 5258199SAli.Saidi@ARM.com 5268199SAli.Saidi@ARM.com Addr ld_eff_addr1 = ld_inst->effAddr >> depCheckShift; 5278199SAli.Saidi@ARM.com Addr ld_eff_addr2 = 5288199SAli.Saidi@ARM.com (ld_inst->effAddr + ld_inst->effSize - 1) >> depCheckShift; 5298199SAli.Saidi@ARM.com 5308272SAli.Saidi@ARM.com if (inst_eff_addr2 >= ld_eff_addr1 && inst_eff_addr1 <= ld_eff_addr2) { 5318545Ssaidi@eecs.umich.edu if (inst->isLoad()) { 5328545Ssaidi@eecs.umich.edu // If this load is to the same block as an external snoop 5338545Ssaidi@eecs.umich.edu // invalidate that we've observed then the load needs to be 5348545Ssaidi@eecs.umich.edu // squashed as it could have newer data 5359046SAli.Saidi@ARM.com if (ld_inst->hitExternalSnoop()) { 5368545Ssaidi@eecs.umich.edu if (!memDepViolator || 5378545Ssaidi@eecs.umich.edu ld_inst->seqNum < memDepViolator->seqNum) { 5388545Ssaidi@eecs.umich.edu DPRINTF(LSQUnit, "Detected fault with inst [sn:%lli] " 5398592Sgblack@eecs.umich.edu "and [sn:%lli] at address %#x\n", 5408592Sgblack@eecs.umich.edu inst->seqNum, ld_inst->seqNum, ld_eff_addr1); 5418545Ssaidi@eecs.umich.edu memDepViolator = ld_inst; 5428199SAli.Saidi@ARM.com 5438545Ssaidi@eecs.umich.edu ++lsqMemOrderViolation; 5448199SAli.Saidi@ARM.com 5458591Sgblack@eecs.umich.edu return new GenericISA::M5PanicFault( 5468591Sgblack@eecs.umich.edu "Detected fault with inst [sn:%lli] and " 5478591Sgblack@eecs.umich.edu "[sn:%lli] at address %#x\n", 5488591Sgblack@eecs.umich.edu inst->seqNum, ld_inst->seqNum, ld_eff_addr1); 5498545Ssaidi@eecs.umich.edu } 5508545Ssaidi@eecs.umich.edu } 5518199SAli.Saidi@ARM.com 5528545Ssaidi@eecs.umich.edu // Otherwise, mark the load has a possible load violation 5538545Ssaidi@eecs.umich.edu // and if we see a snoop before it's commited, we need to squash 5549046SAli.Saidi@ARM.com ld_inst->possibleLoadViolation(true); 5558545Ssaidi@eecs.umich.edu DPRINTF(LSQUnit, "Found possible load violaiton at addr: %#x" 5568545Ssaidi@eecs.umich.edu " between instructions [sn:%lli] and [sn:%lli]\n", 5578545Ssaidi@eecs.umich.edu inst_eff_addr1, inst->seqNum, ld_inst->seqNum); 5588545Ssaidi@eecs.umich.edu } else { 5598545Ssaidi@eecs.umich.edu // A load/store incorrectly passed this store. 5608545Ssaidi@eecs.umich.edu // Check if we already have a violator, or if it's newer 5618545Ssaidi@eecs.umich.edu // squash and refetch. 5628545Ssaidi@eecs.umich.edu if (memDepViolator && ld_inst->seqNum > memDepViolator->seqNum) 5638545Ssaidi@eecs.umich.edu break; 5648545Ssaidi@eecs.umich.edu 5658592Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Detected fault with inst [sn:%lli] and " 5668592Sgblack@eecs.umich.edu "[sn:%lli] at address %#x\n", 5678592Sgblack@eecs.umich.edu inst->seqNum, ld_inst->seqNum, ld_eff_addr1); 5688545Ssaidi@eecs.umich.edu memDepViolator = ld_inst; 5698545Ssaidi@eecs.umich.edu 5708545Ssaidi@eecs.umich.edu ++lsqMemOrderViolation; 5718545Ssaidi@eecs.umich.edu 5728591Sgblack@eecs.umich.edu return new GenericISA::M5PanicFault("Detected fault with " 5738591Sgblack@eecs.umich.edu "inst [sn:%lli] and [sn:%lli] at address %#x\n", 5748591Sgblack@eecs.umich.edu inst->seqNum, ld_inst->seqNum, ld_eff_addr1); 5758545Ssaidi@eecs.umich.edu } 5768199SAli.Saidi@ARM.com } 5778199SAli.Saidi@ARM.com 5788199SAli.Saidi@ARM.com incrLdIdx(load_idx); 5798199SAli.Saidi@ARM.com } 5808199SAli.Saidi@ARM.com return NoFault; 5818199SAli.Saidi@ARM.com} 5828199SAli.Saidi@ARM.com 5838199SAli.Saidi@ARM.com 5848199SAli.Saidi@ARM.com 5858199SAli.Saidi@ARM.com 5868199SAli.Saidi@ARM.comtemplate <class Impl> 5878199SAli.Saidi@ARM.comFault 5882292SN/ALSQUnit<Impl>::executeLoad(DynInstPtr &inst) 5892292SN/A{ 5904032Sktlim@umich.edu using namespace TheISA; 5912292SN/A // Execute a specific load. 5922292SN/A Fault load_fault = NoFault; 5932292SN/A 5947720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Executing load PC %s, [sn:%lli]\n", 5957944SGiacomo.Gabrielli@arm.com inst->pcState(), inst->seqNum); 5962292SN/A 5974032Sktlim@umich.edu assert(!inst->isSquashed()); 5984032Sktlim@umich.edu 5992669Sktlim@umich.edu load_fault = inst->initiateAcc(); 6002292SN/A 6017944SGiacomo.Gabrielli@arm.com if (inst->isTranslationDelayed() && 6027944SGiacomo.Gabrielli@arm.com load_fault == NoFault) 6037944SGiacomo.Gabrielli@arm.com return load_fault; 6047944SGiacomo.Gabrielli@arm.com 6057597Sminkyu.jeong@arm.com // If the instruction faulted or predicated false, then we need to send it 6067597Sminkyu.jeong@arm.com // along to commit without the instruction completing. 6077597Sminkyu.jeong@arm.com if (load_fault != NoFault || inst->readPredicate() == false) { 6082329SN/A // Send this instruction to commit, also make sure iew stage 6092329SN/A // realizes there is activity. 6102367SN/A // Mark it as executed unless it is an uncached load that 6112367SN/A // needs to hit the head of commit. 6127848SAli.Saidi@ARM.com if (inst->readPredicate() == false) 6137848SAli.Saidi@ARM.com inst->forwardOldRegs(); 6147600Sminkyu.jeong@arm.com DPRINTF(LSQUnit, "Load [sn:%lli] not executed from %s\n", 6157600Sminkyu.jeong@arm.com inst->seqNum, 6167600Sminkyu.jeong@arm.com (load_fault != NoFault ? "fault" : "predication")); 6174032Sktlim@umich.edu if (!(inst->hasRequest() && inst->uncacheable()) || 6183731Sktlim@umich.edu inst->isAtCommit()) { 6192367SN/A inst->setExecuted(); 6202367SN/A } 6212292SN/A iewStage->instToCommit(inst); 6222292SN/A iewStage->activityThisCycle(); 6234032Sktlim@umich.edu } else if (!loadBlocked()) { 6249046SAli.Saidi@ARM.com assert(inst->effAddrValid()); 6254032Sktlim@umich.edu int load_idx = inst->lqIdx; 6264032Sktlim@umich.edu incrLdIdx(load_idx); 6274032Sktlim@umich.edu 6288199SAli.Saidi@ARM.com if (checkLoads) 6298199SAli.Saidi@ARM.com return checkViolations(load_idx, inst); 6302292SN/A } 6312292SN/A 6322292SN/A return load_fault; 6332292SN/A} 6342292SN/A 6352292SN/Atemplate <class Impl> 6362292SN/AFault 6372292SN/ALSQUnit<Impl>::executeStore(DynInstPtr &store_inst) 6382292SN/A{ 6392292SN/A using namespace TheISA; 6402292SN/A // Make sure that a store exists. 6412292SN/A assert(stores != 0); 6422292SN/A 6432292SN/A int store_idx = store_inst->sqIdx; 6442292SN/A 6457720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Executing store PC %s [sn:%lli]\n", 6467720Sgblack@eecs.umich.edu store_inst->pcState(), store_inst->seqNum); 6472292SN/A 6484032Sktlim@umich.edu assert(!store_inst->isSquashed()); 6494032Sktlim@umich.edu 6502292SN/A // Check the recently completed loads to see if any match this store's 6512292SN/A // address. If so, then we have a memory ordering violation. 6522292SN/A int load_idx = store_inst->lqIdx; 6532292SN/A 6542292SN/A Fault store_fault = store_inst->initiateAcc(); 6552292SN/A 6567944SGiacomo.Gabrielli@arm.com if (store_inst->isTranslationDelayed() && 6577944SGiacomo.Gabrielli@arm.com store_fault == NoFault) 6587944SGiacomo.Gabrielli@arm.com return store_fault; 6597944SGiacomo.Gabrielli@arm.com 6607848SAli.Saidi@ARM.com if (store_inst->readPredicate() == false) 6617848SAli.Saidi@ARM.com store_inst->forwardOldRegs(); 6627848SAli.Saidi@ARM.com 6632329SN/A if (storeQueue[store_idx].size == 0) { 6647782Sminkyu.jeong@arm.com DPRINTF(LSQUnit,"Fault on Store PC %s, [sn:%lli], Size = 0\n", 6657720Sgblack@eecs.umich.edu store_inst->pcState(), store_inst->seqNum); 6662292SN/A 6672292SN/A return store_fault; 6687782Sminkyu.jeong@arm.com } else if (store_inst->readPredicate() == false) { 6697782Sminkyu.jeong@arm.com DPRINTF(LSQUnit, "Store [sn:%lli] not executed from predication\n", 6707782Sminkyu.jeong@arm.com store_inst->seqNum); 6717782Sminkyu.jeong@arm.com return store_fault; 6722292SN/A } 6732292SN/A 6742292SN/A assert(store_fault == NoFault); 6752292SN/A 6762336SN/A if (store_inst->isStoreConditional()) { 6772336SN/A // Store conditionals need to set themselves as able to 6782336SN/A // writeback if we haven't had a fault by here. 6792329SN/A storeQueue[store_idx].canWB = true; 6802292SN/A 6812329SN/A ++storesToWB; 6822292SN/A } 6832292SN/A 6848199SAli.Saidi@ARM.com return checkViolations(load_idx, store_inst); 6852292SN/A 6862292SN/A} 6872292SN/A 6882292SN/Atemplate <class Impl> 6892292SN/Avoid 6902292SN/ALSQUnit<Impl>::commitLoad() 6912292SN/A{ 6922292SN/A assert(loadQueue[loadHead]); 6932292SN/A 6947720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Committing head load instruction, PC %s\n", 6957720Sgblack@eecs.umich.edu loadQueue[loadHead]->pcState()); 6962292SN/A 6972292SN/A loadQueue[loadHead] = NULL; 6982292SN/A 6992292SN/A incrLdIdx(loadHead); 7002292SN/A 7012292SN/A --loads; 7022292SN/A} 7032292SN/A 7042292SN/Atemplate <class Impl> 7052292SN/Avoid 7062292SN/ALSQUnit<Impl>::commitLoads(InstSeqNum &youngest_inst) 7072292SN/A{ 7082292SN/A assert(loads == 0 || loadQueue[loadHead]); 7092292SN/A 7102292SN/A while (loads != 0 && loadQueue[loadHead]->seqNum <= youngest_inst) { 7112292SN/A commitLoad(); 7122292SN/A } 7132292SN/A} 7142292SN/A 7152292SN/Atemplate <class Impl> 7162292SN/Avoid 7172292SN/ALSQUnit<Impl>::commitStores(InstSeqNum &youngest_inst) 7182292SN/A{ 7192292SN/A assert(stores == 0 || storeQueue[storeHead].inst); 7202292SN/A 7212292SN/A int store_idx = storeHead; 7222292SN/A 7232292SN/A while (store_idx != storeTail) { 7242292SN/A assert(storeQueue[store_idx].inst); 7252329SN/A // Mark any stores that are now committed and have not yet 7262329SN/A // been marked as able to write back. 7272292SN/A if (!storeQueue[store_idx].canWB) { 7282292SN/A if (storeQueue[store_idx].inst->seqNum > youngest_inst) { 7292292SN/A break; 7302292SN/A } 7312292SN/A DPRINTF(LSQUnit, "Marking store as able to write back, PC " 7327720Sgblack@eecs.umich.edu "%s [sn:%lli]\n", 7337720Sgblack@eecs.umich.edu storeQueue[store_idx].inst->pcState(), 7342292SN/A storeQueue[store_idx].inst->seqNum); 7352292SN/A 7362292SN/A storeQueue[store_idx].canWB = true; 7372292SN/A 7382292SN/A ++storesToWB; 7392292SN/A } 7402292SN/A 7412292SN/A incrStIdx(store_idx); 7422292SN/A } 7432292SN/A} 7442292SN/A 7452292SN/Atemplate <class Impl> 7462292SN/Avoid 7476974Stjones1@inf.ed.ac.ukLSQUnit<Impl>::writebackPendingStore() 7486974Stjones1@inf.ed.ac.uk{ 7496974Stjones1@inf.ed.ac.uk if (hasPendingPkt) { 7506974Stjones1@inf.ed.ac.uk assert(pendingPkt != NULL); 7516974Stjones1@inf.ed.ac.uk 7526974Stjones1@inf.ed.ac.uk // If the cache is blocked, this will store the packet for retry. 7536974Stjones1@inf.ed.ac.uk if (sendStore(pendingPkt)) { 7546974Stjones1@inf.ed.ac.uk storePostSend(pendingPkt); 7556974Stjones1@inf.ed.ac.uk } 7566974Stjones1@inf.ed.ac.uk pendingPkt = NULL; 7576974Stjones1@inf.ed.ac.uk hasPendingPkt = false; 7586974Stjones1@inf.ed.ac.uk } 7596974Stjones1@inf.ed.ac.uk} 7606974Stjones1@inf.ed.ac.uk 7616974Stjones1@inf.ed.ac.uktemplate <class Impl> 7626974Stjones1@inf.ed.ac.ukvoid 7632292SN/ALSQUnit<Impl>::writebackStores() 7642292SN/A{ 7656974Stjones1@inf.ed.ac.uk // First writeback the second packet from any split store that didn't 7666974Stjones1@inf.ed.ac.uk // complete last cycle because there weren't enough cache ports available. 7676974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc) { 7686974Stjones1@inf.ed.ac.uk writebackPendingStore(); 7696974Stjones1@inf.ed.ac.uk } 7706974Stjones1@inf.ed.ac.uk 7712292SN/A while (storesToWB > 0 && 7722292SN/A storeWBIdx != storeTail && 7732292SN/A storeQueue[storeWBIdx].inst && 7742292SN/A storeQueue[storeWBIdx].canWB && 7758727Snilay@cs.wisc.edu ((!needsTSO) || (!storeInFlight)) && 7762292SN/A usedPorts < cachePorts) { 7772292SN/A 7782907Sktlim@umich.edu if (isStoreBlocked || lsq->cacheBlocked()) { 7792678Sktlim@umich.edu DPRINTF(LSQUnit, "Unable to write back any more stores, cache" 7802678Sktlim@umich.edu " is blocked!\n"); 7812678Sktlim@umich.edu break; 7822678Sktlim@umich.edu } 7832678Sktlim@umich.edu 7842329SN/A // Store didn't write any data so no need to write it back to 7852329SN/A // memory. 7862292SN/A if (storeQueue[storeWBIdx].size == 0) { 7872292SN/A completeStore(storeWBIdx); 7882292SN/A 7892292SN/A incrStIdx(storeWBIdx); 7902292SN/A 7912292SN/A continue; 7922292SN/A } 7932678Sktlim@umich.edu 7942292SN/A ++usedPorts; 7952292SN/A 7962292SN/A if (storeQueue[storeWBIdx].inst->isDataPrefetch()) { 7972292SN/A incrStIdx(storeWBIdx); 7982292SN/A 7992292SN/A continue; 8002292SN/A } 8012292SN/A 8022292SN/A assert(storeQueue[storeWBIdx].req); 8032292SN/A assert(!storeQueue[storeWBIdx].committed); 8042292SN/A 8056974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && storeQueue[storeWBIdx].isSplit) { 8066974Stjones1@inf.ed.ac.uk assert(storeQueue[storeWBIdx].sreqLow); 8076974Stjones1@inf.ed.ac.uk assert(storeQueue[storeWBIdx].sreqHigh); 8086974Stjones1@inf.ed.ac.uk } 8096974Stjones1@inf.ed.ac.uk 8102669Sktlim@umich.edu DynInstPtr inst = storeQueue[storeWBIdx].inst; 8112669Sktlim@umich.edu 8122669Sktlim@umich.edu Request *req = storeQueue[storeWBIdx].req; 8138481Sgblack@eecs.umich.edu RequestPtr sreqLow = storeQueue[storeWBIdx].sreqLow; 8148481Sgblack@eecs.umich.edu RequestPtr sreqHigh = storeQueue[storeWBIdx].sreqHigh; 8158481Sgblack@eecs.umich.edu 8162292SN/A storeQueue[storeWBIdx].committed = true; 8172292SN/A 8182669Sktlim@umich.edu assert(!inst->memData); 8192669Sktlim@umich.edu inst->memData = new uint8_t[64]; 8203772Sgblack@eecs.umich.edu 8214326Sgblack@eecs.umich.edu memcpy(inst->memData, storeQueue[storeWBIdx].data, req->getSize()); 8222669Sktlim@umich.edu 8234878Sstever@eecs.umich.edu MemCmd command = 8244878Sstever@eecs.umich.edu req->isSwap() ? MemCmd::SwapReq : 8256102Sgblack@eecs.umich.edu (req->isLLSC() ? MemCmd::StoreCondReq : MemCmd::WriteReq); 8266974Stjones1@inf.ed.ac.uk PacketPtr data_pkt; 8276974Stjones1@inf.ed.ac.uk PacketPtr snd_data_pkt = NULL; 8282292SN/A 8292678Sktlim@umich.edu LSQSenderState *state = new LSQSenderState; 8302678Sktlim@umich.edu state->isLoad = false; 8312678Sktlim@umich.edu state->idx = storeWBIdx; 8322678Sktlim@umich.edu state->inst = inst; 8336974Stjones1@inf.ed.ac.uk 8346974Stjones1@inf.ed.ac.uk if (!TheISA::HasUnalignedMemAcc || !storeQueue[storeWBIdx].isSplit) { 8356974Stjones1@inf.ed.ac.uk 8366974Stjones1@inf.ed.ac.uk // Build a single data packet if the store isn't split. 8378949Sandreas.hansson@arm.com data_pkt = new Packet(req, command); 8386974Stjones1@inf.ed.ac.uk data_pkt->dataStatic(inst->memData); 8396974Stjones1@inf.ed.ac.uk data_pkt->senderState = state; 8406974Stjones1@inf.ed.ac.uk } else { 8416974Stjones1@inf.ed.ac.uk // Create two packets if the store is split in two. 8428949Sandreas.hansson@arm.com data_pkt = new Packet(sreqLow, command); 8438949Sandreas.hansson@arm.com snd_data_pkt = new Packet(sreqHigh, command); 8446974Stjones1@inf.ed.ac.uk 8456974Stjones1@inf.ed.ac.uk data_pkt->dataStatic(inst->memData); 8466974Stjones1@inf.ed.ac.uk snd_data_pkt->dataStatic(inst->memData + sreqLow->getSize()); 8476974Stjones1@inf.ed.ac.uk 8486974Stjones1@inf.ed.ac.uk data_pkt->senderState = state; 8496974Stjones1@inf.ed.ac.uk snd_data_pkt->senderState = state; 8506974Stjones1@inf.ed.ac.uk 8516974Stjones1@inf.ed.ac.uk state->isSplit = true; 8526974Stjones1@inf.ed.ac.uk state->outstanding = 2; 8536974Stjones1@inf.ed.ac.uk 8546974Stjones1@inf.ed.ac.uk // Can delete the main request now. 8556974Stjones1@inf.ed.ac.uk delete req; 8566974Stjones1@inf.ed.ac.uk req = sreqLow; 8576974Stjones1@inf.ed.ac.uk } 8582678Sktlim@umich.edu 8597720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "D-Cache: Writing back store idx:%i PC:%s " 8602292SN/A "to Addr:%#x, data:%#x [sn:%lli]\n", 8617720Sgblack@eecs.umich.edu storeWBIdx, inst->pcState(), 8623797Sgblack@eecs.umich.edu req->getPaddr(), (int)*(inst->memData), 8633221Sktlim@umich.edu inst->seqNum); 8642292SN/A 8652693Sktlim@umich.edu // @todo: Remove this SC hack once the memory system handles it. 8664350Sgblack@eecs.umich.edu if (inst->isStoreConditional()) { 8676974Stjones1@inf.ed.ac.uk assert(!storeQueue[storeWBIdx].isSplit); 8683326Sktlim@umich.edu // Disable recording the result temporarily. Writing to 8693326Sktlim@umich.edu // misc regs normally updates the result, but this is not 8703326Sktlim@umich.edu // the desired behavior when handling store conditionals. 8719046SAli.Saidi@ARM.com inst->recordResult(false); 87210030SAli.Saidi@ARM.com bool success = TheISA::handleLockedWrite(inst.get(), req, cacheBlockMask); 8739046SAli.Saidi@ARM.com inst->recordResult(true); 8743326Sktlim@umich.edu 8753326Sktlim@umich.edu if (!success) { 8763326Sktlim@umich.edu // Instantly complete this store. 8773326Sktlim@umich.edu DPRINTF(LSQUnit, "Store conditional [sn:%lli] failed. " 8783326Sktlim@umich.edu "Instantly completing it.\n", 8793326Sktlim@umich.edu inst->seqNum); 8803326Sktlim@umich.edu WritebackEvent *wb = new WritebackEvent(inst, data_pkt, this); 8817823Ssteve.reinhardt@amd.com cpu->schedule(wb, curTick() + 1); 8828887Sgeoffrey.blake@arm.com if (cpu->checker) { 8838887Sgeoffrey.blake@arm.com // Make sure to set the LLSC data for verification 8848887Sgeoffrey.blake@arm.com // if checker is loaded 8858887Sgeoffrey.blake@arm.com inst->reqToVerify->setExtraData(0); 8868887Sgeoffrey.blake@arm.com inst->completeAcc(data_pkt); 8878887Sgeoffrey.blake@arm.com } 8883326Sktlim@umich.edu completeStore(storeWBIdx); 8893326Sktlim@umich.edu incrStIdx(storeWBIdx); 8903326Sktlim@umich.edu continue; 8912693Sktlim@umich.edu } 8922693Sktlim@umich.edu } else { 8932693Sktlim@umich.edu // Non-store conditionals do not need a writeback. 8942693Sktlim@umich.edu state->noWB = true; 8952693Sktlim@umich.edu } 8962693Sktlim@umich.edu 8978481Sgblack@eecs.umich.edu bool split = 8988481Sgblack@eecs.umich.edu TheISA::HasUnalignedMemAcc && storeQueue[storeWBIdx].isSplit; 8998481Sgblack@eecs.umich.edu 9008481Sgblack@eecs.umich.edu ThreadContext *thread = cpu->tcBase(lsqID); 9018481Sgblack@eecs.umich.edu 9028481Sgblack@eecs.umich.edu if (req->isMmappedIpr()) { 9038481Sgblack@eecs.umich.edu assert(!inst->isStoreConditional()); 9048481Sgblack@eecs.umich.edu TheISA::handleIprWrite(thread, data_pkt); 9058481Sgblack@eecs.umich.edu delete data_pkt; 9068481Sgblack@eecs.umich.edu if (split) { 9078481Sgblack@eecs.umich.edu assert(snd_data_pkt->req->isMmappedIpr()); 9088481Sgblack@eecs.umich.edu TheISA::handleIprWrite(thread, snd_data_pkt); 9098481Sgblack@eecs.umich.edu delete snd_data_pkt; 9108481Sgblack@eecs.umich.edu delete sreqLow; 9118481Sgblack@eecs.umich.edu delete sreqHigh; 9128481Sgblack@eecs.umich.edu } 9138481Sgblack@eecs.umich.edu delete state; 9148481Sgblack@eecs.umich.edu delete req; 9158481Sgblack@eecs.umich.edu completeStore(storeWBIdx); 9168481Sgblack@eecs.umich.edu incrStIdx(storeWBIdx); 9178481Sgblack@eecs.umich.edu } else if (!sendStore(data_pkt)) { 9184032Sktlim@umich.edu DPRINTF(IEW, "D-Cache became blocked when writing [sn:%lli], will" 9193221Sktlim@umich.edu "retry later\n", 9203221Sktlim@umich.edu inst->seqNum); 9216974Stjones1@inf.ed.ac.uk 9226974Stjones1@inf.ed.ac.uk // Need to store the second packet, if split. 9238481Sgblack@eecs.umich.edu if (split) { 9246974Stjones1@inf.ed.ac.uk state->pktToSend = true; 9256974Stjones1@inf.ed.ac.uk state->pendingPacket = snd_data_pkt; 9266974Stjones1@inf.ed.ac.uk } 9272669Sktlim@umich.edu } else { 9286974Stjones1@inf.ed.ac.uk 9296974Stjones1@inf.ed.ac.uk // If split, try to send the second packet too 9308481Sgblack@eecs.umich.edu if (split) { 9316974Stjones1@inf.ed.ac.uk assert(snd_data_pkt); 9326974Stjones1@inf.ed.ac.uk 9336974Stjones1@inf.ed.ac.uk // Ensure there are enough ports to use. 9346974Stjones1@inf.ed.ac.uk if (usedPorts < cachePorts) { 9356974Stjones1@inf.ed.ac.uk ++usedPorts; 9366974Stjones1@inf.ed.ac.uk if (sendStore(snd_data_pkt)) { 9376974Stjones1@inf.ed.ac.uk storePostSend(snd_data_pkt); 9386974Stjones1@inf.ed.ac.uk } else { 9396974Stjones1@inf.ed.ac.uk DPRINTF(IEW, "D-Cache became blocked when writing" 9406974Stjones1@inf.ed.ac.uk " [sn:%lli] second packet, will retry later\n", 9416974Stjones1@inf.ed.ac.uk inst->seqNum); 9426974Stjones1@inf.ed.ac.uk } 9436974Stjones1@inf.ed.ac.uk } else { 9446974Stjones1@inf.ed.ac.uk 9456974Stjones1@inf.ed.ac.uk // Store the packet for when there's free ports. 9466974Stjones1@inf.ed.ac.uk assert(pendingPkt == NULL); 9476974Stjones1@inf.ed.ac.uk pendingPkt = snd_data_pkt; 9486974Stjones1@inf.ed.ac.uk hasPendingPkt = true; 9496974Stjones1@inf.ed.ac.uk } 9506974Stjones1@inf.ed.ac.uk } else { 9516974Stjones1@inf.ed.ac.uk 9526974Stjones1@inf.ed.ac.uk // Not a split store. 9536974Stjones1@inf.ed.ac.uk storePostSend(data_pkt); 9546974Stjones1@inf.ed.ac.uk } 9552292SN/A } 9562292SN/A } 9572292SN/A 9582292SN/A // Not sure this should set it to 0. 9592292SN/A usedPorts = 0; 9602292SN/A 9612292SN/A assert(stores >= 0 && storesToWB >= 0); 9622292SN/A} 9632292SN/A 9642292SN/A/*template <class Impl> 9652292SN/Avoid 9662292SN/ALSQUnit<Impl>::removeMSHR(InstSeqNum seqNum) 9672292SN/A{ 9682292SN/A list<InstSeqNum>::iterator mshr_it = find(mshrSeqNums.begin(), 9692292SN/A mshrSeqNums.end(), 9702292SN/A seqNum); 9712292SN/A 9722292SN/A if (mshr_it != mshrSeqNums.end()) { 9732292SN/A mshrSeqNums.erase(mshr_it); 9742292SN/A DPRINTF(LSQUnit, "Removing MSHR. count = %i\n",mshrSeqNums.size()); 9752292SN/A } 9762292SN/A}*/ 9772292SN/A 9782292SN/Atemplate <class Impl> 9792292SN/Avoid 9802292SN/ALSQUnit<Impl>::squash(const InstSeqNum &squashed_num) 9812292SN/A{ 9822292SN/A DPRINTF(LSQUnit, "Squashing until [sn:%lli]!" 9832329SN/A "(Loads:%i Stores:%i)\n", squashed_num, loads, stores); 9842292SN/A 9852292SN/A int load_idx = loadTail; 9862292SN/A decrLdIdx(load_idx); 9872292SN/A 9882292SN/A while (loads != 0 && loadQueue[load_idx]->seqNum > squashed_num) { 9897720Sgblack@eecs.umich.edu DPRINTF(LSQUnit,"Load Instruction PC %s squashed, " 9902292SN/A "[sn:%lli]\n", 9917720Sgblack@eecs.umich.edu loadQueue[load_idx]->pcState(), 9922292SN/A loadQueue[load_idx]->seqNum); 9932292SN/A 9942292SN/A if (isStalled() && load_idx == stallingLoadIdx) { 9952292SN/A stalled = false; 9962292SN/A stallingStoreIsn = 0; 9972292SN/A stallingLoadIdx = 0; 9982292SN/A } 9992292SN/A 10002329SN/A // Clear the smart pointer to make sure it is decremented. 10012731Sktlim@umich.edu loadQueue[load_idx]->setSquashed(); 10022292SN/A loadQueue[load_idx] = NULL; 10032292SN/A --loads; 10042292SN/A 10052292SN/A // Inefficient! 10062292SN/A loadTail = load_idx; 10072292SN/A 10082292SN/A decrLdIdx(load_idx); 10092727Sktlim@umich.edu ++lsqSquashedLoads; 10102292SN/A } 10112292SN/A 10122292SN/A if (isLoadBlocked) { 10132292SN/A if (squashed_num < blockedLoadSeqNum) { 10142292SN/A isLoadBlocked = false; 10152292SN/A loadBlockedHandled = false; 10162292SN/A blockedLoadSeqNum = 0; 10172292SN/A } 10182292SN/A } 10192292SN/A 10204032Sktlim@umich.edu if (memDepViolator && squashed_num < memDepViolator->seqNum) { 10214032Sktlim@umich.edu memDepViolator = NULL; 10224032Sktlim@umich.edu } 10234032Sktlim@umich.edu 10242292SN/A int store_idx = storeTail; 10252292SN/A decrStIdx(store_idx); 10262292SN/A 10272292SN/A while (stores != 0 && 10282292SN/A storeQueue[store_idx].inst->seqNum > squashed_num) { 10292329SN/A // Instructions marked as can WB are already committed. 10302292SN/A if (storeQueue[store_idx].canWB) { 10312292SN/A break; 10322292SN/A } 10332292SN/A 10347720Sgblack@eecs.umich.edu DPRINTF(LSQUnit,"Store Instruction PC %s squashed, " 10352292SN/A "idx:%i [sn:%lli]\n", 10367720Sgblack@eecs.umich.edu storeQueue[store_idx].inst->pcState(), 10372292SN/A store_idx, storeQueue[store_idx].inst->seqNum); 10382292SN/A 10392329SN/A // I don't think this can happen. It should have been cleared 10402329SN/A // by the stalling load. 10412292SN/A if (isStalled() && 10422292SN/A storeQueue[store_idx].inst->seqNum == stallingStoreIsn) { 10432292SN/A panic("Is stalled should have been cleared by stalling load!\n"); 10442292SN/A stalled = false; 10452292SN/A stallingStoreIsn = 0; 10462292SN/A } 10472292SN/A 10482329SN/A // Clear the smart pointer to make sure it is decremented. 10492731Sktlim@umich.edu storeQueue[store_idx].inst->setSquashed(); 10502292SN/A storeQueue[store_idx].inst = NULL; 10512292SN/A storeQueue[store_idx].canWB = 0; 10522292SN/A 10534032Sktlim@umich.edu // Must delete request now that it wasn't handed off to 10544032Sktlim@umich.edu // memory. This is quite ugly. @todo: Figure out the proper 10554032Sktlim@umich.edu // place to really handle request deletes. 10564032Sktlim@umich.edu delete storeQueue[store_idx].req; 10576974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && storeQueue[store_idx].isSplit) { 10586974Stjones1@inf.ed.ac.uk delete storeQueue[store_idx].sreqLow; 10596974Stjones1@inf.ed.ac.uk delete storeQueue[store_idx].sreqHigh; 10606974Stjones1@inf.ed.ac.uk 10616974Stjones1@inf.ed.ac.uk storeQueue[store_idx].sreqLow = NULL; 10626974Stjones1@inf.ed.ac.uk storeQueue[store_idx].sreqHigh = NULL; 10636974Stjones1@inf.ed.ac.uk } 10644032Sktlim@umich.edu 10652292SN/A storeQueue[store_idx].req = NULL; 10662292SN/A --stores; 10672292SN/A 10682292SN/A // Inefficient! 10692292SN/A storeTail = store_idx; 10702292SN/A 10712292SN/A decrStIdx(store_idx); 10722727Sktlim@umich.edu ++lsqSquashedStores; 10732292SN/A } 10742292SN/A} 10752292SN/A 10762292SN/Atemplate <class Impl> 10772292SN/Avoid 10783349Sbinkertn@umich.eduLSQUnit<Impl>::storePostSend(PacketPtr pkt) 10792693Sktlim@umich.edu{ 10802693Sktlim@umich.edu if (isStalled() && 10812693Sktlim@umich.edu storeQueue[storeWBIdx].inst->seqNum == stallingStoreIsn) { 10822693Sktlim@umich.edu DPRINTF(LSQUnit, "Unstalling, stalling store [sn:%lli] " 10832693Sktlim@umich.edu "load idx:%i\n", 10842693Sktlim@umich.edu stallingStoreIsn, stallingLoadIdx); 10852693Sktlim@umich.edu stalled = false; 10862693Sktlim@umich.edu stallingStoreIsn = 0; 10872693Sktlim@umich.edu iewStage->replayMemInst(loadQueue[stallingLoadIdx]); 10882693Sktlim@umich.edu } 10892693Sktlim@umich.edu 10902693Sktlim@umich.edu if (!storeQueue[storeWBIdx].inst->isStoreConditional()) { 10912693Sktlim@umich.edu // The store is basically completed at this time. This 10922693Sktlim@umich.edu // only works so long as the checker doesn't try to 10932693Sktlim@umich.edu // verify the value in memory for stores. 10942693Sktlim@umich.edu storeQueue[storeWBIdx].inst->setCompleted(); 10958887Sgeoffrey.blake@arm.com 10962693Sktlim@umich.edu if (cpu->checker) { 10972732Sktlim@umich.edu cpu->checker->verify(storeQueue[storeWBIdx].inst); 10982693Sktlim@umich.edu } 10992693Sktlim@umich.edu } 11002693Sktlim@umich.edu 11018727Snilay@cs.wisc.edu if (needsTSO) { 11028727Snilay@cs.wisc.edu storeInFlight = true; 11038727Snilay@cs.wisc.edu } 11048727Snilay@cs.wisc.edu 11052693Sktlim@umich.edu incrStIdx(storeWBIdx); 11062693Sktlim@umich.edu} 11072693Sktlim@umich.edu 11082693Sktlim@umich.edutemplate <class Impl> 11092693Sktlim@umich.eduvoid 11102678Sktlim@umich.eduLSQUnit<Impl>::writeback(DynInstPtr &inst, PacketPtr pkt) 11112678Sktlim@umich.edu{ 11122678Sktlim@umich.edu iewStage->wakeCPU(); 11132678Sktlim@umich.edu 11142678Sktlim@umich.edu // Squashed instructions do not need to complete their access. 11152678Sktlim@umich.edu if (inst->isSquashed()) { 11162927Sktlim@umich.edu iewStage->decrWb(inst->seqNum); 11172678Sktlim@umich.edu assert(!inst->isStore()); 11182727Sktlim@umich.edu ++lsqIgnoredResponses; 11192678Sktlim@umich.edu return; 11202678Sktlim@umich.edu } 11212678Sktlim@umich.edu 11222678Sktlim@umich.edu if (!inst->isExecuted()) { 11232678Sktlim@umich.edu inst->setExecuted(); 11242678Sktlim@umich.edu 11252678Sktlim@umich.edu // Complete access to copy data to proper place. 11262678Sktlim@umich.edu inst->completeAcc(pkt); 11272678Sktlim@umich.edu } 11282678Sktlim@umich.edu 11292678Sktlim@umich.edu // Need to insert instruction into queue to commit 11302678Sktlim@umich.edu iewStage->instToCommit(inst); 11312678Sktlim@umich.edu 11322678Sktlim@umich.edu iewStage->activityThisCycle(); 11337598Sminkyu.jeong@arm.com 11347598Sminkyu.jeong@arm.com // see if this load changed the PC 11357598Sminkyu.jeong@arm.com iewStage->checkMisprediction(inst); 11362678Sktlim@umich.edu} 11372678Sktlim@umich.edu 11382678Sktlim@umich.edutemplate <class Impl> 11392678Sktlim@umich.eduvoid 11402292SN/ALSQUnit<Impl>::completeStore(int store_idx) 11412292SN/A{ 11422292SN/A assert(storeQueue[store_idx].inst); 11432292SN/A storeQueue[store_idx].completed = true; 11442292SN/A --storesToWB; 11452292SN/A // A bit conservative because a store completion may not free up entries, 11462292SN/A // but hopefully avoids two store completions in one cycle from making 11472292SN/A // the CPU tick twice. 11483126Sktlim@umich.edu cpu->wakeCPU(); 11492292SN/A cpu->activityThisCycle(); 11502292SN/A 11512292SN/A if (store_idx == storeHead) { 11522292SN/A do { 11532292SN/A incrStIdx(storeHead); 11542292SN/A 11552292SN/A --stores; 11562292SN/A } while (storeQueue[storeHead].completed && 11572292SN/A storeHead != storeTail); 11582292SN/A 11592292SN/A iewStage->updateLSQNextCycle = true; 11602292SN/A } 11612292SN/A 11622329SN/A DPRINTF(LSQUnit, "Completing store [sn:%lli], idx:%i, store head " 11632329SN/A "idx:%i\n", 11642329SN/A storeQueue[store_idx].inst->seqNum, store_idx, storeHead); 11652292SN/A 11669527SMatt.Horsnell@arm.com#if TRACING_ON 11679527SMatt.Horsnell@arm.com if (DTRACE(O3PipeView)) { 11689527SMatt.Horsnell@arm.com storeQueue[store_idx].inst->storeTick = 11699527SMatt.Horsnell@arm.com curTick() - storeQueue[store_idx].inst->fetchTick; 11709527SMatt.Horsnell@arm.com } 11719527SMatt.Horsnell@arm.com#endif 11729527SMatt.Horsnell@arm.com 11732292SN/A if (isStalled() && 11742292SN/A storeQueue[store_idx].inst->seqNum == stallingStoreIsn) { 11752292SN/A DPRINTF(LSQUnit, "Unstalling, stalling store [sn:%lli] " 11762292SN/A "load idx:%i\n", 11772292SN/A stallingStoreIsn, stallingLoadIdx); 11782292SN/A stalled = false; 11792292SN/A stallingStoreIsn = 0; 11802292SN/A iewStage->replayMemInst(loadQueue[stallingLoadIdx]); 11812292SN/A } 11822316SN/A 11832316SN/A storeQueue[store_idx].inst->setCompleted(); 11842329SN/A 11858727Snilay@cs.wisc.edu if (needsTSO) { 11868727Snilay@cs.wisc.edu storeInFlight = false; 11878727Snilay@cs.wisc.edu } 11888727Snilay@cs.wisc.edu 11892329SN/A // Tell the checker we've completed this instruction. Some stores 11902329SN/A // may get reported twice to the checker, but the checker can 11912329SN/A // handle that case. 11922316SN/A if (cpu->checker) { 11932732Sktlim@umich.edu cpu->checker->verify(storeQueue[store_idx].inst); 11942316SN/A } 11952292SN/A} 11962292SN/A 11972292SN/Atemplate <class Impl> 11986974Stjones1@inf.ed.ac.ukbool 11996974Stjones1@inf.ed.ac.ukLSQUnit<Impl>::sendStore(PacketPtr data_pkt) 12006974Stjones1@inf.ed.ac.uk{ 12018975Sandreas.hansson@arm.com if (!dcachePort->sendTimingReq(data_pkt)) { 12026974Stjones1@inf.ed.ac.uk // Need to handle becoming blocked on a store. 12036974Stjones1@inf.ed.ac.uk isStoreBlocked = true; 12046974Stjones1@inf.ed.ac.uk ++lsqCacheBlocked; 12056974Stjones1@inf.ed.ac.uk assert(retryPkt == NULL); 12066974Stjones1@inf.ed.ac.uk retryPkt = data_pkt; 12076974Stjones1@inf.ed.ac.uk lsq->setRetryTid(lsqID); 12086974Stjones1@inf.ed.ac.uk return false; 12096974Stjones1@inf.ed.ac.uk } 12106974Stjones1@inf.ed.ac.uk return true; 12116974Stjones1@inf.ed.ac.uk} 12126974Stjones1@inf.ed.ac.uk 12136974Stjones1@inf.ed.ac.uktemplate <class Impl> 12142693Sktlim@umich.eduvoid 12152693Sktlim@umich.eduLSQUnit<Impl>::recvRetry() 12162693Sktlim@umich.edu{ 12172698Sktlim@umich.edu if (isStoreBlocked) { 12184985Sktlim@umich.edu DPRINTF(LSQUnit, "Receiving retry: store blocked\n"); 12192698Sktlim@umich.edu assert(retryPkt != NULL); 12202693Sktlim@umich.edu 12218587Snilay@cs.wisc.edu LSQSenderState *state = 12228587Snilay@cs.wisc.edu dynamic_cast<LSQSenderState *>(retryPkt->senderState); 12238587Snilay@cs.wisc.edu 12248975Sandreas.hansson@arm.com if (dcachePort->sendTimingReq(retryPkt)) { 12256974Stjones1@inf.ed.ac.uk // Don't finish the store unless this is the last packet. 12268133SAli.Saidi@ARM.com if (!TheISA::HasUnalignedMemAcc || !state->pktToSend || 12278133SAli.Saidi@ARM.com state->pendingPacket == retryPkt) { 12288133SAli.Saidi@ARM.com state->pktToSend = false; 12296974Stjones1@inf.ed.ac.uk storePostSend(retryPkt); 12306974Stjones1@inf.ed.ac.uk } 12312699Sktlim@umich.edu retryPkt = NULL; 12322693Sktlim@umich.edu isStoreBlocked = false; 12336221Snate@binkert.org lsq->setRetryTid(InvalidThreadID); 12346974Stjones1@inf.ed.ac.uk 12356974Stjones1@inf.ed.ac.uk // Send any outstanding packet. 12366974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && state->pktToSend) { 12376974Stjones1@inf.ed.ac.uk assert(state->pendingPacket); 12386974Stjones1@inf.ed.ac.uk if (sendStore(state->pendingPacket)) { 12396974Stjones1@inf.ed.ac.uk storePostSend(state->pendingPacket); 12406974Stjones1@inf.ed.ac.uk } 12416974Stjones1@inf.ed.ac.uk } 12422693Sktlim@umich.edu } else { 12432693Sktlim@umich.edu // Still blocked! 12442727Sktlim@umich.edu ++lsqCacheBlocked; 12452907Sktlim@umich.edu lsq->setRetryTid(lsqID); 12462693Sktlim@umich.edu } 12472693Sktlim@umich.edu } else if (isLoadBlocked) { 12482693Sktlim@umich.edu DPRINTF(LSQUnit, "Loads squash themselves and all younger insts, " 12492693Sktlim@umich.edu "no need to resend packet.\n"); 12502693Sktlim@umich.edu } else { 12512693Sktlim@umich.edu DPRINTF(LSQUnit, "Retry received but LSQ is no longer blocked.\n"); 12522693Sktlim@umich.edu } 12532693Sktlim@umich.edu} 12542693Sktlim@umich.edu 12552693Sktlim@umich.edutemplate <class Impl> 12562292SN/Ainline void 12579440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::incrStIdx(int &store_idx) const 12582292SN/A{ 12592292SN/A if (++store_idx >= SQEntries) 12602292SN/A store_idx = 0; 12612292SN/A} 12622292SN/A 12632292SN/Atemplate <class Impl> 12642292SN/Ainline void 12659440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::decrStIdx(int &store_idx) const 12662292SN/A{ 12672292SN/A if (--store_idx < 0) 12682292SN/A store_idx += SQEntries; 12692292SN/A} 12702292SN/A 12712292SN/Atemplate <class Impl> 12722292SN/Ainline void 12739440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::incrLdIdx(int &load_idx) const 12742292SN/A{ 12752292SN/A if (++load_idx >= LQEntries) 12762292SN/A load_idx = 0; 12772292SN/A} 12782292SN/A 12792292SN/Atemplate <class Impl> 12802292SN/Ainline void 12819440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::decrLdIdx(int &load_idx) const 12822292SN/A{ 12832292SN/A if (--load_idx < 0) 12842292SN/A load_idx += LQEntries; 12852292SN/A} 12862329SN/A 12872329SN/Atemplate <class Impl> 12882329SN/Avoid 12899440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::dumpInsts() const 12902329SN/A{ 12912329SN/A cprintf("Load store queue: Dumping instructions.\n"); 12922329SN/A cprintf("Load queue size: %i\n", loads); 12932329SN/A cprintf("Load queue: "); 12942329SN/A 12952329SN/A int load_idx = loadHead; 12962329SN/A 12972329SN/A while (load_idx != loadTail && loadQueue[load_idx]) { 12989440SAndreas.Sandberg@ARM.com const DynInstPtr &inst(loadQueue[load_idx]); 12999440SAndreas.Sandberg@ARM.com cprintf("%s.[sn:%i] ", inst->pcState(), inst->seqNum); 13002329SN/A 13012329SN/A incrLdIdx(load_idx); 13022329SN/A } 13039440SAndreas.Sandberg@ARM.com cprintf("\n"); 13042329SN/A 13052329SN/A cprintf("Store queue size: %i\n", stores); 13062329SN/A cprintf("Store queue: "); 13072329SN/A 13082329SN/A int store_idx = storeHead; 13092329SN/A 13102329SN/A while (store_idx != storeTail && storeQueue[store_idx].inst) { 13119440SAndreas.Sandberg@ARM.com const DynInstPtr &inst(storeQueue[store_idx].inst); 13129440SAndreas.Sandberg@ARM.com cprintf("%s.[sn:%i] ", inst->pcState(), inst->seqNum); 13132329SN/A 13142329SN/A incrStIdx(store_idx); 13152329SN/A } 13162329SN/A 13172329SN/A cprintf("\n"); 13182329SN/A} 13199944Smatt.horsnell@ARM.com 13209944Smatt.horsnell@ARM.com#endif//__CPU_O3_LSQ_UNIT_IMPL_HH__ 1321