lsq_unit_impl.hh revision 10333
19814Sandreas.hansson@arm.com 22292SN/A/* 310333Smitch.hayenga@arm.com * Copyright (c) 2010-2014 ARM Limited 410239Sbinhpham@cs.rutgers.edu * Copyright (c) 2013 Advanced Micro Devices, Inc. 57597Sminkyu.jeong@arm.com * All rights reserved 67597Sminkyu.jeong@arm.com * 77597Sminkyu.jeong@arm.com * The license below extends only to copyright in the software and shall 87597Sminkyu.jeong@arm.com * not be construed as granting a license to any other intellectual 97597Sminkyu.jeong@arm.com * property including but not limited to intellectual property relating 107597Sminkyu.jeong@arm.com * to a hardware implementation of the functionality of the software 117597Sminkyu.jeong@arm.com * licensed hereunder. You may use the software subject to the license 127597Sminkyu.jeong@arm.com * terms below provided that you ensure that this notice is replicated 137597Sminkyu.jeong@arm.com * unmodified and in its entirety in all distributions of the software, 147597Sminkyu.jeong@arm.com * modified or unmodified, in source code or in binary form. 157597Sminkyu.jeong@arm.com * 162292SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 172292SN/A * All rights reserved. 182292SN/A * 192292SN/A * Redistribution and use in source and binary forms, with or without 202292SN/A * modification, are permitted provided that the following conditions are 212292SN/A * met: redistributions of source code must retain the above copyright 222292SN/A * notice, this list of conditions and the following disclaimer; 232292SN/A * redistributions in binary form must reproduce the above copyright 242292SN/A * notice, this list of conditions and the following disclaimer in the 252292SN/A * documentation and/or other materials provided with the distribution; 262292SN/A * neither the name of the copyright holders nor the names of its 272292SN/A * contributors may be used to endorse or promote products derived from 282292SN/A * this software without specific prior written permission. 292292SN/A * 302292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 312292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 322292SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 332292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 342292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 352292SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 362292SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 372292SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 382292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 392292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 402292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 412689Sktlim@umich.edu * 422689Sktlim@umich.edu * Authors: Kevin Lim 432689Sktlim@umich.edu * Korey Sewell 442292SN/A */ 452292SN/A 469944Smatt.horsnell@ARM.com#ifndef __CPU_O3_LSQ_UNIT_IMPL_HH__ 479944Smatt.horsnell@ARM.com#define __CPU_O3_LSQ_UNIT_IMPL_HH__ 489944Smatt.horsnell@ARM.com 498591Sgblack@eecs.umich.edu#include "arch/generic/debugfaults.hh" 503326Sktlim@umich.edu#include "arch/locked_mem.hh" 518229Snate@binkert.org#include "base/str.hh" 526658Snate@binkert.org#include "config/the_isa.hh" 538887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh" 542907Sktlim@umich.edu#include "cpu/o3/lsq.hh" 552292SN/A#include "cpu/o3/lsq_unit.hh" 568232Snate@binkert.org#include "debug/Activity.hh" 578232Snate@binkert.org#include "debug/IEW.hh" 588232Snate@binkert.org#include "debug/LSQUnit.hh" 599527SMatt.Horsnell@arm.com#include "debug/O3PipeView.hh" 602722Sktlim@umich.edu#include "mem/packet.hh" 612669Sktlim@umich.edu#include "mem/request.hh" 622292SN/A 632669Sktlim@umich.edutemplate<class Impl> 642678Sktlim@umich.eduLSQUnit<Impl>::WritebackEvent::WritebackEvent(DynInstPtr &_inst, PacketPtr _pkt, 652678Sktlim@umich.edu LSQUnit *lsq_ptr) 668581Ssteve.reinhardt@amd.com : Event(Default_Pri, AutoDelete), 678581Ssteve.reinhardt@amd.com inst(_inst), pkt(_pkt), lsqPtr(lsq_ptr) 682292SN/A{ 692292SN/A} 702292SN/A 712669Sktlim@umich.edutemplate<class Impl> 722292SN/Avoid 732678Sktlim@umich.eduLSQUnit<Impl>::WritebackEvent::process() 742292SN/A{ 759444SAndreas.Sandberg@ARM.com assert(!lsqPtr->cpu->switchedOut()); 769444SAndreas.Sandberg@ARM.com 779444SAndreas.Sandberg@ARM.com lsqPtr->writeback(inst, pkt); 784319Sktlim@umich.edu 794319Sktlim@umich.edu if (pkt->senderState) 804319Sktlim@umich.edu delete pkt->senderState; 814319Sktlim@umich.edu 824319Sktlim@umich.edu delete pkt->req; 832678Sktlim@umich.edu delete pkt; 842678Sktlim@umich.edu} 852292SN/A 862678Sktlim@umich.edutemplate<class Impl> 872678Sktlim@umich.educonst char * 885336Shines@cs.fsu.eduLSQUnit<Impl>::WritebackEvent::description() const 892678Sktlim@umich.edu{ 904873Sstever@eecs.umich.edu return "Store writeback"; 912678Sktlim@umich.edu} 922292SN/A 932678Sktlim@umich.edutemplate<class Impl> 942678Sktlim@umich.eduvoid 952678Sktlim@umich.eduLSQUnit<Impl>::completeDataAccess(PacketPtr pkt) 962678Sktlim@umich.edu{ 972678Sktlim@umich.edu LSQSenderState *state = dynamic_cast<LSQSenderState *>(pkt->senderState); 982678Sktlim@umich.edu DynInstPtr inst = state->inst; 997852SMatt.Horsnell@arm.com DPRINTF(IEW, "Writeback event [sn:%lli].\n", inst->seqNum); 1007852SMatt.Horsnell@arm.com DPRINTF(Activity, "Activity: Writeback event [sn:%lli].\n", inst->seqNum); 1012344SN/A 10210333Smitch.hayenga@arm.com if (state->cacheBlocked) { 10310333Smitch.hayenga@arm.com // This is the first half of a previous split load, 10410333Smitch.hayenga@arm.com // where the 2nd half blocked, ignore this response 10510333Smitch.hayenga@arm.com DPRINTF(IEW, "[sn:%lli]: Response from first half of earlier " 10610333Smitch.hayenga@arm.com "blocked split load recieved. Ignoring.\n", inst->seqNum); 10710333Smitch.hayenga@arm.com delete state; 10810333Smitch.hayenga@arm.com delete pkt->req; 10910333Smitch.hayenga@arm.com delete pkt; 11010333Smitch.hayenga@arm.com return; 11110333Smitch.hayenga@arm.com } 1122678Sktlim@umich.edu 1136974Stjones1@inf.ed.ac.uk // If this is a split access, wait until all packets are received. 1146974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && !state->complete()) { 1156974Stjones1@inf.ed.ac.uk delete pkt->req; 1166974Stjones1@inf.ed.ac.uk delete pkt; 1176974Stjones1@inf.ed.ac.uk return; 1186974Stjones1@inf.ed.ac.uk } 1196974Stjones1@inf.ed.ac.uk 1209444SAndreas.Sandberg@ARM.com assert(!cpu->switchedOut()); 12110327Smitch.hayenga@arm.com if (!inst->isSquashed()) { 1222678Sktlim@umich.edu if (!state->noWB) { 1236974Stjones1@inf.ed.ac.uk if (!TheISA::HasUnalignedMemAcc || !state->isSplit || 1246974Stjones1@inf.ed.ac.uk !state->isLoad) { 1256974Stjones1@inf.ed.ac.uk writeback(inst, pkt); 1266974Stjones1@inf.ed.ac.uk } else { 1276974Stjones1@inf.ed.ac.uk writeback(inst, state->mainPkt); 1286974Stjones1@inf.ed.ac.uk } 1292678Sktlim@umich.edu } 1302678Sktlim@umich.edu 1312678Sktlim@umich.edu if (inst->isStore()) { 1322678Sktlim@umich.edu completeStore(state->idx); 1332678Sktlim@umich.edu } 1342344SN/A } 1352307SN/A 1366974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && state->isSplit && state->isLoad) { 1376974Stjones1@inf.ed.ac.uk delete state->mainPkt->req; 1386974Stjones1@inf.ed.ac.uk delete state->mainPkt; 1396974Stjones1@inf.ed.ac.uk } 14010020Smatt.horsnell@ARM.com 14110020Smatt.horsnell@ARM.com pkt->req->setAccessLatency(); 14210023Smatt.horsnell@ARM.com cpu->ppDataAccessComplete->notify(std::make_pair(inst, pkt)); 14310023Smatt.horsnell@ARM.com 1442678Sktlim@umich.edu delete state; 1454032Sktlim@umich.edu delete pkt->req; 1462678Sktlim@umich.edu delete pkt; 1472292SN/A} 1482292SN/A 1492292SN/Atemplate <class Impl> 1502292SN/ALSQUnit<Impl>::LSQUnit() 1518545Ssaidi@eecs.umich.edu : loads(0), stores(0), storesToWB(0), cacheBlockMask(0), stalled(false), 15210333Smitch.hayenga@arm.com isStoreBlocked(false), storeInFlight(false), hasPendingPkt(false) 1532292SN/A{ 1542292SN/A} 1552292SN/A 1562292SN/Atemplate<class Impl> 1572292SN/Avoid 1585529Snate@binkert.orgLSQUnit<Impl>::init(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params, 1595529Snate@binkert.org LSQ *lsq_ptr, unsigned maxLQEntries, unsigned maxSQEntries, 1605529Snate@binkert.org unsigned id) 1612292SN/A{ 1624329Sktlim@umich.edu cpu = cpu_ptr; 1634329Sktlim@umich.edu iewStage = iew_ptr; 1644329Sktlim@umich.edu 1652907Sktlim@umich.edu lsq = lsq_ptr; 1662907Sktlim@umich.edu 1672292SN/A lsqID = id; 1682292SN/A 16910175SMitch.Hayenga@ARM.com DPRINTF(LSQUnit, "Creating LSQUnit%i object.\n",id); 17010175SMitch.Hayenga@ARM.com 1712329SN/A // Add 1 for the sentinel entry (they are circular queues). 1722329SN/A LQEntries = maxLQEntries + 1; 1732329SN/A SQEntries = maxSQEntries + 1; 1742292SN/A 1759936SFaissal.Sleiman@arm.com //Due to uint8_t index in LSQSenderState 1769936SFaissal.Sleiman@arm.com assert(LQEntries <= 256); 1779936SFaissal.Sleiman@arm.com assert(SQEntries <= 256); 1789936SFaissal.Sleiman@arm.com 1792292SN/A loadQueue.resize(LQEntries); 1802292SN/A storeQueue.resize(SQEntries); 1812292SN/A 1828199SAli.Saidi@ARM.com depCheckShift = params->LSQDepCheckShift; 1838199SAli.Saidi@ARM.com checkLoads = params->LSQCheckLoads; 1849444SAndreas.Sandberg@ARM.com cachePorts = params->cachePorts; 1859444SAndreas.Sandberg@ARM.com needsTSO = params->needsTSO; 1869444SAndreas.Sandberg@ARM.com 1879444SAndreas.Sandberg@ARM.com resetState(); 1889444SAndreas.Sandberg@ARM.com} 1899444SAndreas.Sandberg@ARM.com 1909444SAndreas.Sandberg@ARM.com 1919444SAndreas.Sandberg@ARM.comtemplate<class Impl> 1929444SAndreas.Sandberg@ARM.comvoid 1939444SAndreas.Sandberg@ARM.comLSQUnit<Impl>::resetState() 1949444SAndreas.Sandberg@ARM.com{ 1959444SAndreas.Sandberg@ARM.com loads = stores = storesToWB = 0; 1968199SAli.Saidi@ARM.com 1972292SN/A loadHead = loadTail = 0; 1982292SN/A 1992292SN/A storeHead = storeWBIdx = storeTail = 0; 2002292SN/A 2012292SN/A usedPorts = 0; 2022292SN/A 2033492Sktlim@umich.edu retryPkt = NULL; 2042329SN/A memDepViolator = NULL; 2052292SN/A 2069444SAndreas.Sandberg@ARM.com stalled = false; 2079444SAndreas.Sandberg@ARM.com 2089814Sandreas.hansson@arm.com cacheBlockMask = ~(cpu->cacheLineSize() - 1); 2092292SN/A} 2102292SN/A 2112292SN/Atemplate<class Impl> 2122292SN/Astd::string 2132292SN/ALSQUnit<Impl>::name() const 2142292SN/A{ 2152292SN/A if (Impl::MaxThreads == 1) { 2162292SN/A return iewStage->name() + ".lsq"; 2172292SN/A } else { 2188247Snate@binkert.org return iewStage->name() + ".lsq.thread" + to_string(lsqID); 2192292SN/A } 2202292SN/A} 2212292SN/A 2222292SN/Atemplate<class Impl> 2232292SN/Avoid 2242727Sktlim@umich.eduLSQUnit<Impl>::regStats() 2252727Sktlim@umich.edu{ 2262727Sktlim@umich.edu lsqForwLoads 2272727Sktlim@umich.edu .name(name() + ".forwLoads") 2282727Sktlim@umich.edu .desc("Number of loads that had data forwarded from stores"); 2292727Sktlim@umich.edu 2302727Sktlim@umich.edu invAddrLoads 2312727Sktlim@umich.edu .name(name() + ".invAddrLoads") 2322727Sktlim@umich.edu .desc("Number of loads ignored due to an invalid address"); 2332727Sktlim@umich.edu 2342727Sktlim@umich.edu lsqSquashedLoads 2352727Sktlim@umich.edu .name(name() + ".squashedLoads") 2362727Sktlim@umich.edu .desc("Number of loads squashed"); 2372727Sktlim@umich.edu 2382727Sktlim@umich.edu lsqIgnoredResponses 2392727Sktlim@umich.edu .name(name() + ".ignoredResponses") 2402727Sktlim@umich.edu .desc("Number of memory responses ignored because the instruction is squashed"); 2412727Sktlim@umich.edu 2422361SN/A lsqMemOrderViolation 2432361SN/A .name(name() + ".memOrderViolation") 2442361SN/A .desc("Number of memory ordering violations"); 2452361SN/A 2462727Sktlim@umich.edu lsqSquashedStores 2472727Sktlim@umich.edu .name(name() + ".squashedStores") 2482727Sktlim@umich.edu .desc("Number of stores squashed"); 2492727Sktlim@umich.edu 2502727Sktlim@umich.edu invAddrSwpfs 2512727Sktlim@umich.edu .name(name() + ".invAddrSwpfs") 2522727Sktlim@umich.edu .desc("Number of software prefetches ignored due to an invalid address"); 2532727Sktlim@umich.edu 2542727Sktlim@umich.edu lsqBlockedLoads 2552727Sktlim@umich.edu .name(name() + ".blockedLoads") 2562727Sktlim@umich.edu .desc("Number of blocked loads due to partial load-store forwarding"); 2572727Sktlim@umich.edu 2582727Sktlim@umich.edu lsqRescheduledLoads 2592727Sktlim@umich.edu .name(name() + ".rescheduledLoads") 2602727Sktlim@umich.edu .desc("Number of loads that were rescheduled"); 2612727Sktlim@umich.edu 2622727Sktlim@umich.edu lsqCacheBlocked 2632727Sktlim@umich.edu .name(name() + ".cacheBlocked") 2642727Sktlim@umich.edu .desc("Number of times an access to memory failed due to the cache being blocked"); 2652727Sktlim@umich.edu} 2662727Sktlim@umich.edu 2672727Sktlim@umich.edutemplate<class Impl> 2682727Sktlim@umich.eduvoid 2698922Swilliam.wang@arm.comLSQUnit<Impl>::setDcachePort(MasterPort *dcache_port) 2704329Sktlim@umich.edu{ 2714329Sktlim@umich.edu dcachePort = dcache_port; 2724329Sktlim@umich.edu} 2734329Sktlim@umich.edu 2744329Sktlim@umich.edutemplate<class Impl> 2754329Sktlim@umich.eduvoid 2762292SN/ALSQUnit<Impl>::clearLQ() 2772292SN/A{ 2782292SN/A loadQueue.clear(); 2792292SN/A} 2802292SN/A 2812292SN/Atemplate<class Impl> 2822292SN/Avoid 2832292SN/ALSQUnit<Impl>::clearSQ() 2842292SN/A{ 2852292SN/A storeQueue.clear(); 2862292SN/A} 2872292SN/A 2882292SN/Atemplate<class Impl> 2892292SN/Avoid 2909444SAndreas.Sandberg@ARM.comLSQUnit<Impl>::drainSanityCheck() const 2912307SN/A{ 2929444SAndreas.Sandberg@ARM.com for (int i = 0; i < loadQueue.size(); ++i) 2932367SN/A assert(!loadQueue[i]); 2942307SN/A 2952329SN/A assert(storesToWB == 0); 2969444SAndreas.Sandberg@ARM.com assert(!retryPkt); 2972307SN/A} 2982307SN/A 2992307SN/Atemplate<class Impl> 3002307SN/Avoid 3012307SN/ALSQUnit<Impl>::takeOverFrom() 3022307SN/A{ 3039444SAndreas.Sandberg@ARM.com resetState(); 3042307SN/A} 3052307SN/A 3062307SN/Atemplate<class Impl> 3072307SN/Avoid 3082292SN/ALSQUnit<Impl>::resizeLQ(unsigned size) 3092292SN/A{ 3102329SN/A unsigned size_plus_sentinel = size + 1; 3112329SN/A assert(size_plus_sentinel >= LQEntries); 3122292SN/A 3132329SN/A if (size_plus_sentinel > LQEntries) { 3142329SN/A while (size_plus_sentinel > loadQueue.size()) { 3152292SN/A DynInstPtr dummy; 3162292SN/A loadQueue.push_back(dummy); 3172292SN/A LQEntries++; 3182292SN/A } 3192292SN/A } else { 3202329SN/A LQEntries = size_plus_sentinel; 3212292SN/A } 3222292SN/A 3239936SFaissal.Sleiman@arm.com assert(LQEntries <= 256); 3242292SN/A} 3252292SN/A 3262292SN/Atemplate<class Impl> 3272292SN/Avoid 3282292SN/ALSQUnit<Impl>::resizeSQ(unsigned size) 3292292SN/A{ 3302329SN/A unsigned size_plus_sentinel = size + 1; 3312329SN/A if (size_plus_sentinel > SQEntries) { 3322329SN/A while (size_plus_sentinel > storeQueue.size()) { 3332292SN/A SQEntry dummy; 3342292SN/A storeQueue.push_back(dummy); 3352292SN/A SQEntries++; 3362292SN/A } 3372292SN/A } else { 3382329SN/A SQEntries = size_plus_sentinel; 3392292SN/A } 3409936SFaissal.Sleiman@arm.com 3419936SFaissal.Sleiman@arm.com assert(SQEntries <= 256); 3422292SN/A} 3432292SN/A 3442292SN/Atemplate <class Impl> 3452292SN/Avoid 3462292SN/ALSQUnit<Impl>::insert(DynInstPtr &inst) 3472292SN/A{ 3482292SN/A assert(inst->isMemRef()); 3492292SN/A 3502292SN/A assert(inst->isLoad() || inst->isStore()); 3512292SN/A 3522292SN/A if (inst->isLoad()) { 3532292SN/A insertLoad(inst); 3542292SN/A } else { 3552292SN/A insertStore(inst); 3562292SN/A } 3572292SN/A 3582292SN/A inst->setInLSQ(); 3592292SN/A} 3602292SN/A 3612292SN/Atemplate <class Impl> 3622292SN/Avoid 3632292SN/ALSQUnit<Impl>::insertLoad(DynInstPtr &load_inst) 3642292SN/A{ 3652329SN/A assert((loadTail + 1) % LQEntries != loadHead); 3662329SN/A assert(loads < LQEntries); 3672292SN/A 3687720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Inserting load PC %s, idx:%i [sn:%lli]\n", 3697720Sgblack@eecs.umich.edu load_inst->pcState(), loadTail, load_inst->seqNum); 3702292SN/A 3712292SN/A load_inst->lqIdx = loadTail; 3722292SN/A 3732292SN/A if (stores == 0) { 3742292SN/A load_inst->sqIdx = -1; 3752292SN/A } else { 3762292SN/A load_inst->sqIdx = storeTail; 3772292SN/A } 3782292SN/A 3792292SN/A loadQueue[loadTail] = load_inst; 3802292SN/A 3812292SN/A incrLdIdx(loadTail); 3822292SN/A 3832292SN/A ++loads; 3842292SN/A} 3852292SN/A 3862292SN/Atemplate <class Impl> 3872292SN/Avoid 3882292SN/ALSQUnit<Impl>::insertStore(DynInstPtr &store_inst) 3892292SN/A{ 3902292SN/A // Make sure it is not full before inserting an instruction. 3912292SN/A assert((storeTail + 1) % SQEntries != storeHead); 3922292SN/A assert(stores < SQEntries); 3932292SN/A 3947720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Inserting store PC %s, idx:%i [sn:%lli]\n", 3957720Sgblack@eecs.umich.edu store_inst->pcState(), storeTail, store_inst->seqNum); 3962292SN/A 3972292SN/A store_inst->sqIdx = storeTail; 3982292SN/A store_inst->lqIdx = loadTail; 3992292SN/A 4002292SN/A storeQueue[storeTail] = SQEntry(store_inst); 4012292SN/A 4022292SN/A incrStIdx(storeTail); 4032292SN/A 4042292SN/A ++stores; 4052292SN/A} 4062292SN/A 4072292SN/Atemplate <class Impl> 4082292SN/Atypename Impl::DynInstPtr 4092292SN/ALSQUnit<Impl>::getMemDepViolator() 4102292SN/A{ 4112292SN/A DynInstPtr temp = memDepViolator; 4122292SN/A 4132292SN/A memDepViolator = NULL; 4142292SN/A 4152292SN/A return temp; 4162292SN/A} 4172292SN/A 4182292SN/Atemplate <class Impl> 4192292SN/Aunsigned 42010239Sbinhpham@cs.rutgers.eduLSQUnit<Impl>::numFreeLoadEntries() 4212292SN/A{ 42210239Sbinhpham@cs.rutgers.edu //LQ has an extra dummy entry to differentiate 42310239Sbinhpham@cs.rutgers.edu //empty/full conditions. Subtract 1 from the free entries. 42410239Sbinhpham@cs.rutgers.edu DPRINTF(LSQUnit, "LQ size: %d, #loads occupied: %d\n", LQEntries, loads); 42510239Sbinhpham@cs.rutgers.edu return LQEntries - loads - 1; 42610239Sbinhpham@cs.rutgers.edu} 4272292SN/A 42810239Sbinhpham@cs.rutgers.edutemplate <class Impl> 42910239Sbinhpham@cs.rutgers.eduunsigned 43010239Sbinhpham@cs.rutgers.eduLSQUnit<Impl>::numFreeStoreEntries() 43110239Sbinhpham@cs.rutgers.edu{ 43210239Sbinhpham@cs.rutgers.edu //SQ has an extra dummy entry to differentiate 43310239Sbinhpham@cs.rutgers.edu //empty/full conditions. Subtract 1 from the free entries. 43410239Sbinhpham@cs.rutgers.edu DPRINTF(LSQUnit, "SQ size: %d, #stores occupied: %d\n", SQEntries, stores); 43510239Sbinhpham@cs.rutgers.edu return SQEntries - stores - 1; 43610239Sbinhpham@cs.rutgers.edu 43710239Sbinhpham@cs.rutgers.edu } 4382292SN/A 4392292SN/Atemplate <class Impl> 4408545Ssaidi@eecs.umich.eduvoid 4418545Ssaidi@eecs.umich.eduLSQUnit<Impl>::checkSnoop(PacketPtr pkt) 4428545Ssaidi@eecs.umich.edu{ 4438545Ssaidi@eecs.umich.edu int load_idx = loadHead; 44410030SAli.Saidi@ARM.com DPRINTF(LSQUnit, "Got snoop for address %#x\n", pkt->getAddr()); 4458545Ssaidi@eecs.umich.edu 4469383SAli.Saidi@ARM.com // Unlock the cpu-local monitor when the CPU sees a snoop to a locked 4479383SAli.Saidi@ARM.com // address. The CPU can speculatively execute a LL operation after a pending 4489383SAli.Saidi@ARM.com // SC operation in the pipeline and that can make the cache monitor the CPU 4499383SAli.Saidi@ARM.com // is connected to valid while it really shouldn't be. 45010030SAli.Saidi@ARM.com for (int x = 0; x < cpu->numContexts(); x++) { 4519383SAli.Saidi@ARM.com ThreadContext *tc = cpu->getContext(x); 4529383SAli.Saidi@ARM.com bool no_squash = cpu->thread[x]->noSquashFromTC; 4539383SAli.Saidi@ARM.com cpu->thread[x]->noSquashFromTC = true; 4549383SAli.Saidi@ARM.com TheISA::handleLockedSnoop(tc, pkt, cacheBlockMask); 4559383SAli.Saidi@ARM.com cpu->thread[x]->noSquashFromTC = no_squash; 4569383SAli.Saidi@ARM.com } 4579383SAli.Saidi@ARM.com 45810030SAli.Saidi@ARM.com Addr invalidate_addr = pkt->getAddr() & cacheBlockMask; 45910030SAli.Saidi@ARM.com 46010030SAli.Saidi@ARM.com DynInstPtr ld_inst = loadQueue[load_idx]; 46110030SAli.Saidi@ARM.com if (ld_inst) { 46210030SAli.Saidi@ARM.com Addr load_addr = ld_inst->physEffAddr & cacheBlockMask; 46310030SAli.Saidi@ARM.com // Check that this snoop didn't just invalidate our lock flag 46410030SAli.Saidi@ARM.com if (ld_inst->effAddrValid() && load_addr == invalidate_addr && 46510030SAli.Saidi@ARM.com ld_inst->memReqFlags & Request::LLSC) 46610030SAli.Saidi@ARM.com TheISA::handleLockedSnoopHit(ld_inst.get()); 46710030SAli.Saidi@ARM.com } 46810030SAli.Saidi@ARM.com 4698545Ssaidi@eecs.umich.edu // If this is the only load in the LSQ we don't care 4708545Ssaidi@eecs.umich.edu if (load_idx == loadTail) 4718545Ssaidi@eecs.umich.edu return; 47210030SAli.Saidi@ARM.com 4738545Ssaidi@eecs.umich.edu incrLdIdx(load_idx); 4748545Ssaidi@eecs.umich.edu 47510149Smarco.elver@ed.ac.uk bool force_squash = false; 47610149Smarco.elver@ed.ac.uk 4778545Ssaidi@eecs.umich.edu while (load_idx != loadTail) { 4788545Ssaidi@eecs.umich.edu DynInstPtr ld_inst = loadQueue[load_idx]; 4798545Ssaidi@eecs.umich.edu 4809046SAli.Saidi@ARM.com if (!ld_inst->effAddrValid() || ld_inst->uncacheable()) { 4818545Ssaidi@eecs.umich.edu incrLdIdx(load_idx); 4828545Ssaidi@eecs.umich.edu continue; 4838545Ssaidi@eecs.umich.edu } 4848545Ssaidi@eecs.umich.edu 4858545Ssaidi@eecs.umich.edu Addr load_addr = ld_inst->physEffAddr & cacheBlockMask; 4868545Ssaidi@eecs.umich.edu DPRINTF(LSQUnit, "-- inst [sn:%lli] load_addr: %#x to pktAddr:%#x\n", 4878545Ssaidi@eecs.umich.edu ld_inst->seqNum, load_addr, invalidate_addr); 4888545Ssaidi@eecs.umich.edu 48910149Smarco.elver@ed.ac.uk if (load_addr == invalidate_addr || force_squash) { 49010149Smarco.elver@ed.ac.uk if (needsTSO) { 49110149Smarco.elver@ed.ac.uk // If we have a TSO system, as all loads must be ordered with 49210149Smarco.elver@ed.ac.uk // all other loads, this load as well as *all* subsequent loads 49310149Smarco.elver@ed.ac.uk // need to be squashed to prevent possible load reordering. 49410149Smarco.elver@ed.ac.uk force_squash = true; 49510149Smarco.elver@ed.ac.uk } 49610149Smarco.elver@ed.ac.uk if (ld_inst->possibleLoadViolation() || force_squash) { 4978545Ssaidi@eecs.umich.edu DPRINTF(LSQUnit, "Conflicting load at addr %#x [sn:%lli]\n", 49810030SAli.Saidi@ARM.com pkt->getAddr(), ld_inst->seqNum); 4998545Ssaidi@eecs.umich.edu 5008545Ssaidi@eecs.umich.edu // Mark the load for re-execution 5018545Ssaidi@eecs.umich.edu ld_inst->fault = new ReExec; 5028545Ssaidi@eecs.umich.edu } else { 50310030SAli.Saidi@ARM.com DPRINTF(LSQUnit, "HitExternal Snoop for addr %#x [sn:%lli]\n", 50410030SAli.Saidi@ARM.com pkt->getAddr(), ld_inst->seqNum); 50510030SAli.Saidi@ARM.com 50610030SAli.Saidi@ARM.com // Make sure that we don't lose a snoop hitting a LOCKED 50710030SAli.Saidi@ARM.com // address since the LOCK* flags don't get updated until 50810030SAli.Saidi@ARM.com // commit. 50910030SAli.Saidi@ARM.com if (ld_inst->memReqFlags & Request::LLSC) 51010030SAli.Saidi@ARM.com TheISA::handleLockedSnoopHit(ld_inst.get()); 51110030SAli.Saidi@ARM.com 5128545Ssaidi@eecs.umich.edu // If a older load checks this and it's true 5138545Ssaidi@eecs.umich.edu // then we might have missed the snoop 5148545Ssaidi@eecs.umich.edu // in which case we need to invalidate to be sure 5159046SAli.Saidi@ARM.com ld_inst->hitExternalSnoop(true); 5168545Ssaidi@eecs.umich.edu } 5178545Ssaidi@eecs.umich.edu } 5188545Ssaidi@eecs.umich.edu incrLdIdx(load_idx); 5198545Ssaidi@eecs.umich.edu } 5208545Ssaidi@eecs.umich.edu return; 5218545Ssaidi@eecs.umich.edu} 5228545Ssaidi@eecs.umich.edu 5238545Ssaidi@eecs.umich.edutemplate <class Impl> 5242292SN/AFault 5258199SAli.Saidi@ARM.comLSQUnit<Impl>::checkViolations(int load_idx, DynInstPtr &inst) 5268199SAli.Saidi@ARM.com{ 5278199SAli.Saidi@ARM.com Addr inst_eff_addr1 = inst->effAddr >> depCheckShift; 5288199SAli.Saidi@ARM.com Addr inst_eff_addr2 = (inst->effAddr + inst->effSize - 1) >> depCheckShift; 5298199SAli.Saidi@ARM.com 5308199SAli.Saidi@ARM.com /** @todo in theory you only need to check an instruction that has executed 5318199SAli.Saidi@ARM.com * however, there isn't a good way in the pipeline at the moment to check 5328199SAli.Saidi@ARM.com * all instructions that will execute before the store writes back. Thus, 5338199SAli.Saidi@ARM.com * like the implementation that came before it, we're overly conservative. 5348199SAli.Saidi@ARM.com */ 5358199SAli.Saidi@ARM.com while (load_idx != loadTail) { 5368199SAli.Saidi@ARM.com DynInstPtr ld_inst = loadQueue[load_idx]; 5379046SAli.Saidi@ARM.com if (!ld_inst->effAddrValid() || ld_inst->uncacheable()) { 5388199SAli.Saidi@ARM.com incrLdIdx(load_idx); 5398199SAli.Saidi@ARM.com continue; 5408199SAli.Saidi@ARM.com } 5418199SAli.Saidi@ARM.com 5428199SAli.Saidi@ARM.com Addr ld_eff_addr1 = ld_inst->effAddr >> depCheckShift; 5438199SAli.Saidi@ARM.com Addr ld_eff_addr2 = 5448199SAli.Saidi@ARM.com (ld_inst->effAddr + ld_inst->effSize - 1) >> depCheckShift; 5458199SAli.Saidi@ARM.com 5468272SAli.Saidi@ARM.com if (inst_eff_addr2 >= ld_eff_addr1 && inst_eff_addr1 <= ld_eff_addr2) { 5478545Ssaidi@eecs.umich.edu if (inst->isLoad()) { 5488545Ssaidi@eecs.umich.edu // If this load is to the same block as an external snoop 5498545Ssaidi@eecs.umich.edu // invalidate that we've observed then the load needs to be 5508545Ssaidi@eecs.umich.edu // squashed as it could have newer data 5519046SAli.Saidi@ARM.com if (ld_inst->hitExternalSnoop()) { 5528545Ssaidi@eecs.umich.edu if (!memDepViolator || 5538545Ssaidi@eecs.umich.edu ld_inst->seqNum < memDepViolator->seqNum) { 5548545Ssaidi@eecs.umich.edu DPRINTF(LSQUnit, "Detected fault with inst [sn:%lli] " 5558592Sgblack@eecs.umich.edu "and [sn:%lli] at address %#x\n", 5568592Sgblack@eecs.umich.edu inst->seqNum, ld_inst->seqNum, ld_eff_addr1); 5578545Ssaidi@eecs.umich.edu memDepViolator = ld_inst; 5588199SAli.Saidi@ARM.com 5598545Ssaidi@eecs.umich.edu ++lsqMemOrderViolation; 5608199SAli.Saidi@ARM.com 5618591Sgblack@eecs.umich.edu return new GenericISA::M5PanicFault( 5628591Sgblack@eecs.umich.edu "Detected fault with inst [sn:%lli] and " 5638591Sgblack@eecs.umich.edu "[sn:%lli] at address %#x\n", 5648591Sgblack@eecs.umich.edu inst->seqNum, ld_inst->seqNum, ld_eff_addr1); 5658545Ssaidi@eecs.umich.edu } 5668545Ssaidi@eecs.umich.edu } 5678199SAli.Saidi@ARM.com 5688545Ssaidi@eecs.umich.edu // Otherwise, mark the load has a possible load violation 5698545Ssaidi@eecs.umich.edu // and if we see a snoop before it's commited, we need to squash 5709046SAli.Saidi@ARM.com ld_inst->possibleLoadViolation(true); 5718545Ssaidi@eecs.umich.edu DPRINTF(LSQUnit, "Found possible load violaiton at addr: %#x" 5728545Ssaidi@eecs.umich.edu " between instructions [sn:%lli] and [sn:%lli]\n", 5738545Ssaidi@eecs.umich.edu inst_eff_addr1, inst->seqNum, ld_inst->seqNum); 5748545Ssaidi@eecs.umich.edu } else { 5758545Ssaidi@eecs.umich.edu // A load/store incorrectly passed this store. 5768545Ssaidi@eecs.umich.edu // Check if we already have a violator, or if it's newer 5778545Ssaidi@eecs.umich.edu // squash and refetch. 5788545Ssaidi@eecs.umich.edu if (memDepViolator && ld_inst->seqNum > memDepViolator->seqNum) 5798545Ssaidi@eecs.umich.edu break; 5808545Ssaidi@eecs.umich.edu 5818592Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Detected fault with inst [sn:%lli] and " 5828592Sgblack@eecs.umich.edu "[sn:%lli] at address %#x\n", 5838592Sgblack@eecs.umich.edu inst->seqNum, ld_inst->seqNum, ld_eff_addr1); 5848545Ssaidi@eecs.umich.edu memDepViolator = ld_inst; 5858545Ssaidi@eecs.umich.edu 5868545Ssaidi@eecs.umich.edu ++lsqMemOrderViolation; 5878545Ssaidi@eecs.umich.edu 5888591Sgblack@eecs.umich.edu return new GenericISA::M5PanicFault("Detected fault with " 5898591Sgblack@eecs.umich.edu "inst [sn:%lli] and [sn:%lli] at address %#x\n", 5908591Sgblack@eecs.umich.edu inst->seqNum, ld_inst->seqNum, ld_eff_addr1); 5918545Ssaidi@eecs.umich.edu } 5928199SAli.Saidi@ARM.com } 5938199SAli.Saidi@ARM.com 5948199SAli.Saidi@ARM.com incrLdIdx(load_idx); 5958199SAli.Saidi@ARM.com } 5968199SAli.Saidi@ARM.com return NoFault; 5978199SAli.Saidi@ARM.com} 5988199SAli.Saidi@ARM.com 5998199SAli.Saidi@ARM.com 6008199SAli.Saidi@ARM.com 6018199SAli.Saidi@ARM.com 6028199SAli.Saidi@ARM.comtemplate <class Impl> 6038199SAli.Saidi@ARM.comFault 6042292SN/ALSQUnit<Impl>::executeLoad(DynInstPtr &inst) 6052292SN/A{ 6064032Sktlim@umich.edu using namespace TheISA; 6072292SN/A // Execute a specific load. 6082292SN/A Fault load_fault = NoFault; 6092292SN/A 6107720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Executing load PC %s, [sn:%lli]\n", 6117944SGiacomo.Gabrielli@arm.com inst->pcState(), inst->seqNum); 6122292SN/A 6134032Sktlim@umich.edu assert(!inst->isSquashed()); 6144032Sktlim@umich.edu 6152669Sktlim@umich.edu load_fault = inst->initiateAcc(); 6162292SN/A 6177944SGiacomo.Gabrielli@arm.com if (inst->isTranslationDelayed() && 6187944SGiacomo.Gabrielli@arm.com load_fault == NoFault) 6197944SGiacomo.Gabrielli@arm.com return load_fault; 6207944SGiacomo.Gabrielli@arm.com 6217597Sminkyu.jeong@arm.com // If the instruction faulted or predicated false, then we need to send it 6227597Sminkyu.jeong@arm.com // along to commit without the instruction completing. 62310231Ssteve.reinhardt@amd.com if (load_fault != NoFault || !inst->readPredicate()) { 6242329SN/A // Send this instruction to commit, also make sure iew stage 6252329SN/A // realizes there is activity. 6262367SN/A // Mark it as executed unless it is an uncached load that 6272367SN/A // needs to hit the head of commit. 62810231Ssteve.reinhardt@amd.com if (!inst->readPredicate()) 6297848SAli.Saidi@ARM.com inst->forwardOldRegs(); 6307600Sminkyu.jeong@arm.com DPRINTF(LSQUnit, "Load [sn:%lli] not executed from %s\n", 6317600Sminkyu.jeong@arm.com inst->seqNum, 6327600Sminkyu.jeong@arm.com (load_fault != NoFault ? "fault" : "predication")); 6334032Sktlim@umich.edu if (!(inst->hasRequest() && inst->uncacheable()) || 6343731Sktlim@umich.edu inst->isAtCommit()) { 6352367SN/A inst->setExecuted(); 6362367SN/A } 6372292SN/A iewStage->instToCommit(inst); 6382292SN/A iewStage->activityThisCycle(); 63910333Smitch.hayenga@arm.com } else { 6409046SAli.Saidi@ARM.com assert(inst->effAddrValid()); 6414032Sktlim@umich.edu int load_idx = inst->lqIdx; 6424032Sktlim@umich.edu incrLdIdx(load_idx); 6434032Sktlim@umich.edu 6448199SAli.Saidi@ARM.com if (checkLoads) 6458199SAli.Saidi@ARM.com return checkViolations(load_idx, inst); 6462292SN/A } 6472292SN/A 6482292SN/A return load_fault; 6492292SN/A} 6502292SN/A 6512292SN/Atemplate <class Impl> 6522292SN/AFault 6532292SN/ALSQUnit<Impl>::executeStore(DynInstPtr &store_inst) 6542292SN/A{ 6552292SN/A using namespace TheISA; 6562292SN/A // Make sure that a store exists. 6572292SN/A assert(stores != 0); 6582292SN/A 6592292SN/A int store_idx = store_inst->sqIdx; 6602292SN/A 6617720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Executing store PC %s [sn:%lli]\n", 6627720Sgblack@eecs.umich.edu store_inst->pcState(), store_inst->seqNum); 6632292SN/A 6644032Sktlim@umich.edu assert(!store_inst->isSquashed()); 6654032Sktlim@umich.edu 6662292SN/A // Check the recently completed loads to see if any match this store's 6672292SN/A // address. If so, then we have a memory ordering violation. 6682292SN/A int load_idx = store_inst->lqIdx; 6692292SN/A 6702292SN/A Fault store_fault = store_inst->initiateAcc(); 6712292SN/A 6727944SGiacomo.Gabrielli@arm.com if (store_inst->isTranslationDelayed() && 6737944SGiacomo.Gabrielli@arm.com store_fault == NoFault) 6747944SGiacomo.Gabrielli@arm.com return store_fault; 6757944SGiacomo.Gabrielli@arm.com 67610231Ssteve.reinhardt@amd.com if (!store_inst->readPredicate()) 6777848SAli.Saidi@ARM.com store_inst->forwardOldRegs(); 6787848SAli.Saidi@ARM.com 6792329SN/A if (storeQueue[store_idx].size == 0) { 6807782Sminkyu.jeong@arm.com DPRINTF(LSQUnit,"Fault on Store PC %s, [sn:%lli], Size = 0\n", 6817720Sgblack@eecs.umich.edu store_inst->pcState(), store_inst->seqNum); 6822292SN/A 6832292SN/A return store_fault; 68410231Ssteve.reinhardt@amd.com } else if (!store_inst->readPredicate()) { 6857782Sminkyu.jeong@arm.com DPRINTF(LSQUnit, "Store [sn:%lli] not executed from predication\n", 6867782Sminkyu.jeong@arm.com store_inst->seqNum); 6877782Sminkyu.jeong@arm.com return store_fault; 6882292SN/A } 6892292SN/A 6902292SN/A assert(store_fault == NoFault); 6912292SN/A 6922336SN/A if (store_inst->isStoreConditional()) { 6932336SN/A // Store conditionals need to set themselves as able to 6942336SN/A // writeback if we haven't had a fault by here. 6952329SN/A storeQueue[store_idx].canWB = true; 6962292SN/A 6972329SN/A ++storesToWB; 6982292SN/A } 6992292SN/A 7008199SAli.Saidi@ARM.com return checkViolations(load_idx, store_inst); 7012292SN/A 7022292SN/A} 7032292SN/A 7042292SN/Atemplate <class Impl> 7052292SN/Avoid 7062292SN/ALSQUnit<Impl>::commitLoad() 7072292SN/A{ 7082292SN/A assert(loadQueue[loadHead]); 7092292SN/A 7107720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Committing head load instruction, PC %s\n", 7117720Sgblack@eecs.umich.edu loadQueue[loadHead]->pcState()); 7122292SN/A 7132292SN/A loadQueue[loadHead] = NULL; 7142292SN/A 7152292SN/A incrLdIdx(loadHead); 7162292SN/A 7172292SN/A --loads; 7182292SN/A} 7192292SN/A 7202292SN/Atemplate <class Impl> 7212292SN/Avoid 7222292SN/ALSQUnit<Impl>::commitLoads(InstSeqNum &youngest_inst) 7232292SN/A{ 7242292SN/A assert(loads == 0 || loadQueue[loadHead]); 7252292SN/A 7262292SN/A while (loads != 0 && loadQueue[loadHead]->seqNum <= youngest_inst) { 7272292SN/A commitLoad(); 7282292SN/A } 7292292SN/A} 7302292SN/A 7312292SN/Atemplate <class Impl> 7322292SN/Avoid 7332292SN/ALSQUnit<Impl>::commitStores(InstSeqNum &youngest_inst) 7342292SN/A{ 7352292SN/A assert(stores == 0 || storeQueue[storeHead].inst); 7362292SN/A 7372292SN/A int store_idx = storeHead; 7382292SN/A 7392292SN/A while (store_idx != storeTail) { 7402292SN/A assert(storeQueue[store_idx].inst); 7412329SN/A // Mark any stores that are now committed and have not yet 7422329SN/A // been marked as able to write back. 7432292SN/A if (!storeQueue[store_idx].canWB) { 7442292SN/A if (storeQueue[store_idx].inst->seqNum > youngest_inst) { 7452292SN/A break; 7462292SN/A } 7472292SN/A DPRINTF(LSQUnit, "Marking store as able to write back, PC " 7487720Sgblack@eecs.umich.edu "%s [sn:%lli]\n", 7497720Sgblack@eecs.umich.edu storeQueue[store_idx].inst->pcState(), 7502292SN/A storeQueue[store_idx].inst->seqNum); 7512292SN/A 7522292SN/A storeQueue[store_idx].canWB = true; 7532292SN/A 7542292SN/A ++storesToWB; 7552292SN/A } 7562292SN/A 7572292SN/A incrStIdx(store_idx); 7582292SN/A } 7592292SN/A} 7602292SN/A 7612292SN/Atemplate <class Impl> 7622292SN/Avoid 7636974Stjones1@inf.ed.ac.ukLSQUnit<Impl>::writebackPendingStore() 7646974Stjones1@inf.ed.ac.uk{ 7656974Stjones1@inf.ed.ac.uk if (hasPendingPkt) { 7666974Stjones1@inf.ed.ac.uk assert(pendingPkt != NULL); 7676974Stjones1@inf.ed.ac.uk 7686974Stjones1@inf.ed.ac.uk // If the cache is blocked, this will store the packet for retry. 7696974Stjones1@inf.ed.ac.uk if (sendStore(pendingPkt)) { 7706974Stjones1@inf.ed.ac.uk storePostSend(pendingPkt); 7716974Stjones1@inf.ed.ac.uk } 7726974Stjones1@inf.ed.ac.uk pendingPkt = NULL; 7736974Stjones1@inf.ed.ac.uk hasPendingPkt = false; 7746974Stjones1@inf.ed.ac.uk } 7756974Stjones1@inf.ed.ac.uk} 7766974Stjones1@inf.ed.ac.uk 7776974Stjones1@inf.ed.ac.uktemplate <class Impl> 7786974Stjones1@inf.ed.ac.ukvoid 7792292SN/ALSQUnit<Impl>::writebackStores() 7802292SN/A{ 7816974Stjones1@inf.ed.ac.uk // First writeback the second packet from any split store that didn't 7826974Stjones1@inf.ed.ac.uk // complete last cycle because there weren't enough cache ports available. 7836974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc) { 7846974Stjones1@inf.ed.ac.uk writebackPendingStore(); 7856974Stjones1@inf.ed.ac.uk } 7866974Stjones1@inf.ed.ac.uk 7872292SN/A while (storesToWB > 0 && 7882292SN/A storeWBIdx != storeTail && 7892292SN/A storeQueue[storeWBIdx].inst && 7902292SN/A storeQueue[storeWBIdx].canWB && 7918727Snilay@cs.wisc.edu ((!needsTSO) || (!storeInFlight)) && 7922292SN/A usedPorts < cachePorts) { 7932292SN/A 79410333Smitch.hayenga@arm.com if (isStoreBlocked) { 7952678Sktlim@umich.edu DPRINTF(LSQUnit, "Unable to write back any more stores, cache" 7962678Sktlim@umich.edu " is blocked!\n"); 7972678Sktlim@umich.edu break; 7982678Sktlim@umich.edu } 7992678Sktlim@umich.edu 8002329SN/A // Store didn't write any data so no need to write it back to 8012329SN/A // memory. 8022292SN/A if (storeQueue[storeWBIdx].size == 0) { 8032292SN/A completeStore(storeWBIdx); 8042292SN/A 8052292SN/A incrStIdx(storeWBIdx); 8062292SN/A 8072292SN/A continue; 8082292SN/A } 8092678Sktlim@umich.edu 8102292SN/A ++usedPorts; 8112292SN/A 8122292SN/A if (storeQueue[storeWBIdx].inst->isDataPrefetch()) { 8132292SN/A incrStIdx(storeWBIdx); 8142292SN/A 8152292SN/A continue; 8162292SN/A } 8172292SN/A 8182292SN/A assert(storeQueue[storeWBIdx].req); 8192292SN/A assert(!storeQueue[storeWBIdx].committed); 8202292SN/A 8216974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && storeQueue[storeWBIdx].isSplit) { 8226974Stjones1@inf.ed.ac.uk assert(storeQueue[storeWBIdx].sreqLow); 8236974Stjones1@inf.ed.ac.uk assert(storeQueue[storeWBIdx].sreqHigh); 8246974Stjones1@inf.ed.ac.uk } 8256974Stjones1@inf.ed.ac.uk 8262669Sktlim@umich.edu DynInstPtr inst = storeQueue[storeWBIdx].inst; 8272669Sktlim@umich.edu 8282669Sktlim@umich.edu Request *req = storeQueue[storeWBIdx].req; 8298481Sgblack@eecs.umich.edu RequestPtr sreqLow = storeQueue[storeWBIdx].sreqLow; 8308481Sgblack@eecs.umich.edu RequestPtr sreqHigh = storeQueue[storeWBIdx].sreqHigh; 8318481Sgblack@eecs.umich.edu 8322292SN/A storeQueue[storeWBIdx].committed = true; 8332292SN/A 8342669Sktlim@umich.edu assert(!inst->memData); 83510031SAli.Saidi@ARM.com inst->memData = new uint8_t[req->getSize()]; 8363772Sgblack@eecs.umich.edu 83710031SAli.Saidi@ARM.com if (storeQueue[storeWBIdx].isAllZeros) 83810031SAli.Saidi@ARM.com memset(inst->memData, 0, req->getSize()); 83910031SAli.Saidi@ARM.com else 84010031SAli.Saidi@ARM.com memcpy(inst->memData, storeQueue[storeWBIdx].data, req->getSize()); 8412669Sktlim@umich.edu 8424878Sstever@eecs.umich.edu MemCmd command = 8434878Sstever@eecs.umich.edu req->isSwap() ? MemCmd::SwapReq : 8446102Sgblack@eecs.umich.edu (req->isLLSC() ? MemCmd::StoreCondReq : MemCmd::WriteReq); 8456974Stjones1@inf.ed.ac.uk PacketPtr data_pkt; 8466974Stjones1@inf.ed.ac.uk PacketPtr snd_data_pkt = NULL; 8472292SN/A 8482678Sktlim@umich.edu LSQSenderState *state = new LSQSenderState; 8492678Sktlim@umich.edu state->isLoad = false; 8502678Sktlim@umich.edu state->idx = storeWBIdx; 8512678Sktlim@umich.edu state->inst = inst; 8526974Stjones1@inf.ed.ac.uk 8536974Stjones1@inf.ed.ac.uk if (!TheISA::HasUnalignedMemAcc || !storeQueue[storeWBIdx].isSplit) { 8546974Stjones1@inf.ed.ac.uk 8556974Stjones1@inf.ed.ac.uk // Build a single data packet if the store isn't split. 8568949Sandreas.hansson@arm.com data_pkt = new Packet(req, command); 8576974Stjones1@inf.ed.ac.uk data_pkt->dataStatic(inst->memData); 8586974Stjones1@inf.ed.ac.uk data_pkt->senderState = state; 8596974Stjones1@inf.ed.ac.uk } else { 8606974Stjones1@inf.ed.ac.uk // Create two packets if the store is split in two. 8618949Sandreas.hansson@arm.com data_pkt = new Packet(sreqLow, command); 8628949Sandreas.hansson@arm.com snd_data_pkt = new Packet(sreqHigh, command); 8636974Stjones1@inf.ed.ac.uk 8646974Stjones1@inf.ed.ac.uk data_pkt->dataStatic(inst->memData); 8656974Stjones1@inf.ed.ac.uk snd_data_pkt->dataStatic(inst->memData + sreqLow->getSize()); 8666974Stjones1@inf.ed.ac.uk 8676974Stjones1@inf.ed.ac.uk data_pkt->senderState = state; 8686974Stjones1@inf.ed.ac.uk snd_data_pkt->senderState = state; 8696974Stjones1@inf.ed.ac.uk 8706974Stjones1@inf.ed.ac.uk state->isSplit = true; 8716974Stjones1@inf.ed.ac.uk state->outstanding = 2; 8726974Stjones1@inf.ed.ac.uk 8736974Stjones1@inf.ed.ac.uk // Can delete the main request now. 8746974Stjones1@inf.ed.ac.uk delete req; 8756974Stjones1@inf.ed.ac.uk req = sreqLow; 8766974Stjones1@inf.ed.ac.uk } 8772678Sktlim@umich.edu 8787720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "D-Cache: Writing back store idx:%i PC:%s " 8792292SN/A "to Addr:%#x, data:%#x [sn:%lli]\n", 8807720Sgblack@eecs.umich.edu storeWBIdx, inst->pcState(), 8813797Sgblack@eecs.umich.edu req->getPaddr(), (int)*(inst->memData), 8823221Sktlim@umich.edu inst->seqNum); 8832292SN/A 8842693Sktlim@umich.edu // @todo: Remove this SC hack once the memory system handles it. 8854350Sgblack@eecs.umich.edu if (inst->isStoreConditional()) { 8866974Stjones1@inf.ed.ac.uk assert(!storeQueue[storeWBIdx].isSplit); 8873326Sktlim@umich.edu // Disable recording the result temporarily. Writing to 8883326Sktlim@umich.edu // misc regs normally updates the result, but this is not 8893326Sktlim@umich.edu // the desired behavior when handling store conditionals. 8909046SAli.Saidi@ARM.com inst->recordResult(false); 89110030SAli.Saidi@ARM.com bool success = TheISA::handleLockedWrite(inst.get(), req, cacheBlockMask); 8929046SAli.Saidi@ARM.com inst->recordResult(true); 8933326Sktlim@umich.edu 8943326Sktlim@umich.edu if (!success) { 8953326Sktlim@umich.edu // Instantly complete this store. 8963326Sktlim@umich.edu DPRINTF(LSQUnit, "Store conditional [sn:%lli] failed. " 8973326Sktlim@umich.edu "Instantly completing it.\n", 8983326Sktlim@umich.edu inst->seqNum); 8993326Sktlim@umich.edu WritebackEvent *wb = new WritebackEvent(inst, data_pkt, this); 9007823Ssteve.reinhardt@amd.com cpu->schedule(wb, curTick() + 1); 9018887Sgeoffrey.blake@arm.com if (cpu->checker) { 9028887Sgeoffrey.blake@arm.com // Make sure to set the LLSC data for verification 9038887Sgeoffrey.blake@arm.com // if checker is loaded 9048887Sgeoffrey.blake@arm.com inst->reqToVerify->setExtraData(0); 9058887Sgeoffrey.blake@arm.com inst->completeAcc(data_pkt); 9068887Sgeoffrey.blake@arm.com } 9073326Sktlim@umich.edu completeStore(storeWBIdx); 9083326Sktlim@umich.edu incrStIdx(storeWBIdx); 9093326Sktlim@umich.edu continue; 9102693Sktlim@umich.edu } 9112693Sktlim@umich.edu } else { 9122693Sktlim@umich.edu // Non-store conditionals do not need a writeback. 9132693Sktlim@umich.edu state->noWB = true; 9142693Sktlim@umich.edu } 9152693Sktlim@umich.edu 9168481Sgblack@eecs.umich.edu bool split = 9178481Sgblack@eecs.umich.edu TheISA::HasUnalignedMemAcc && storeQueue[storeWBIdx].isSplit; 9188481Sgblack@eecs.umich.edu 9198481Sgblack@eecs.umich.edu ThreadContext *thread = cpu->tcBase(lsqID); 9208481Sgblack@eecs.umich.edu 9218481Sgblack@eecs.umich.edu if (req->isMmappedIpr()) { 9228481Sgblack@eecs.umich.edu assert(!inst->isStoreConditional()); 9238481Sgblack@eecs.umich.edu TheISA::handleIprWrite(thread, data_pkt); 9248481Sgblack@eecs.umich.edu delete data_pkt; 9258481Sgblack@eecs.umich.edu if (split) { 9268481Sgblack@eecs.umich.edu assert(snd_data_pkt->req->isMmappedIpr()); 9278481Sgblack@eecs.umich.edu TheISA::handleIprWrite(thread, snd_data_pkt); 9288481Sgblack@eecs.umich.edu delete snd_data_pkt; 9298481Sgblack@eecs.umich.edu delete sreqLow; 9308481Sgblack@eecs.umich.edu delete sreqHigh; 9318481Sgblack@eecs.umich.edu } 9328481Sgblack@eecs.umich.edu delete state; 9338481Sgblack@eecs.umich.edu delete req; 9348481Sgblack@eecs.umich.edu completeStore(storeWBIdx); 9358481Sgblack@eecs.umich.edu incrStIdx(storeWBIdx); 9368481Sgblack@eecs.umich.edu } else if (!sendStore(data_pkt)) { 9374032Sktlim@umich.edu DPRINTF(IEW, "D-Cache became blocked when writing [sn:%lli], will" 9383221Sktlim@umich.edu "retry later\n", 9393221Sktlim@umich.edu inst->seqNum); 9406974Stjones1@inf.ed.ac.uk 9416974Stjones1@inf.ed.ac.uk // Need to store the second packet, if split. 9428481Sgblack@eecs.umich.edu if (split) { 9436974Stjones1@inf.ed.ac.uk state->pktToSend = true; 9446974Stjones1@inf.ed.ac.uk state->pendingPacket = snd_data_pkt; 9456974Stjones1@inf.ed.ac.uk } 9462669Sktlim@umich.edu } else { 9476974Stjones1@inf.ed.ac.uk 9486974Stjones1@inf.ed.ac.uk // If split, try to send the second packet too 9498481Sgblack@eecs.umich.edu if (split) { 9506974Stjones1@inf.ed.ac.uk assert(snd_data_pkt); 9516974Stjones1@inf.ed.ac.uk 9526974Stjones1@inf.ed.ac.uk // Ensure there are enough ports to use. 9536974Stjones1@inf.ed.ac.uk if (usedPorts < cachePorts) { 9546974Stjones1@inf.ed.ac.uk ++usedPorts; 9556974Stjones1@inf.ed.ac.uk if (sendStore(snd_data_pkt)) { 9566974Stjones1@inf.ed.ac.uk storePostSend(snd_data_pkt); 9576974Stjones1@inf.ed.ac.uk } else { 9586974Stjones1@inf.ed.ac.uk DPRINTF(IEW, "D-Cache became blocked when writing" 9596974Stjones1@inf.ed.ac.uk " [sn:%lli] second packet, will retry later\n", 9606974Stjones1@inf.ed.ac.uk inst->seqNum); 9616974Stjones1@inf.ed.ac.uk } 9626974Stjones1@inf.ed.ac.uk } else { 9636974Stjones1@inf.ed.ac.uk 9646974Stjones1@inf.ed.ac.uk // Store the packet for when there's free ports. 9656974Stjones1@inf.ed.ac.uk assert(pendingPkt == NULL); 9666974Stjones1@inf.ed.ac.uk pendingPkt = snd_data_pkt; 9676974Stjones1@inf.ed.ac.uk hasPendingPkt = true; 9686974Stjones1@inf.ed.ac.uk } 9696974Stjones1@inf.ed.ac.uk } else { 9706974Stjones1@inf.ed.ac.uk 9716974Stjones1@inf.ed.ac.uk // Not a split store. 9726974Stjones1@inf.ed.ac.uk storePostSend(data_pkt); 9736974Stjones1@inf.ed.ac.uk } 9742292SN/A } 9752292SN/A } 9762292SN/A 9772292SN/A // Not sure this should set it to 0. 9782292SN/A usedPorts = 0; 9792292SN/A 9802292SN/A assert(stores >= 0 && storesToWB >= 0); 9812292SN/A} 9822292SN/A 9832292SN/A/*template <class Impl> 9842292SN/Avoid 9852292SN/ALSQUnit<Impl>::removeMSHR(InstSeqNum seqNum) 9862292SN/A{ 9872292SN/A list<InstSeqNum>::iterator mshr_it = find(mshrSeqNums.begin(), 9882292SN/A mshrSeqNums.end(), 9892292SN/A seqNum); 9902292SN/A 9912292SN/A if (mshr_it != mshrSeqNums.end()) { 9922292SN/A mshrSeqNums.erase(mshr_it); 9932292SN/A DPRINTF(LSQUnit, "Removing MSHR. count = %i\n",mshrSeqNums.size()); 9942292SN/A } 9952292SN/A}*/ 9962292SN/A 9972292SN/Atemplate <class Impl> 9982292SN/Avoid 9992292SN/ALSQUnit<Impl>::squash(const InstSeqNum &squashed_num) 10002292SN/A{ 10012292SN/A DPRINTF(LSQUnit, "Squashing until [sn:%lli]!" 10022329SN/A "(Loads:%i Stores:%i)\n", squashed_num, loads, stores); 10032292SN/A 10042292SN/A int load_idx = loadTail; 10052292SN/A decrLdIdx(load_idx); 10062292SN/A 10072292SN/A while (loads != 0 && loadQueue[load_idx]->seqNum > squashed_num) { 10087720Sgblack@eecs.umich.edu DPRINTF(LSQUnit,"Load Instruction PC %s squashed, " 10092292SN/A "[sn:%lli]\n", 10107720Sgblack@eecs.umich.edu loadQueue[load_idx]->pcState(), 10112292SN/A loadQueue[load_idx]->seqNum); 10122292SN/A 10132292SN/A if (isStalled() && load_idx == stallingLoadIdx) { 10142292SN/A stalled = false; 10152292SN/A stallingStoreIsn = 0; 10162292SN/A stallingLoadIdx = 0; 10172292SN/A } 10182292SN/A 10192329SN/A // Clear the smart pointer to make sure it is decremented. 10202731Sktlim@umich.edu loadQueue[load_idx]->setSquashed(); 10212292SN/A loadQueue[load_idx] = NULL; 10222292SN/A --loads; 10232292SN/A 10242292SN/A // Inefficient! 10252292SN/A loadTail = load_idx; 10262292SN/A 10272292SN/A decrLdIdx(load_idx); 10282727Sktlim@umich.edu ++lsqSquashedLoads; 10292292SN/A } 10302292SN/A 10314032Sktlim@umich.edu if (memDepViolator && squashed_num < memDepViolator->seqNum) { 10324032Sktlim@umich.edu memDepViolator = NULL; 10334032Sktlim@umich.edu } 10344032Sktlim@umich.edu 10352292SN/A int store_idx = storeTail; 10362292SN/A decrStIdx(store_idx); 10372292SN/A 10382292SN/A while (stores != 0 && 10392292SN/A storeQueue[store_idx].inst->seqNum > squashed_num) { 10402329SN/A // Instructions marked as can WB are already committed. 10412292SN/A if (storeQueue[store_idx].canWB) { 10422292SN/A break; 10432292SN/A } 10442292SN/A 10457720Sgblack@eecs.umich.edu DPRINTF(LSQUnit,"Store Instruction PC %s squashed, " 10462292SN/A "idx:%i [sn:%lli]\n", 10477720Sgblack@eecs.umich.edu storeQueue[store_idx].inst->pcState(), 10482292SN/A store_idx, storeQueue[store_idx].inst->seqNum); 10492292SN/A 10502329SN/A // I don't think this can happen. It should have been cleared 10512329SN/A // by the stalling load. 10522292SN/A if (isStalled() && 10532292SN/A storeQueue[store_idx].inst->seqNum == stallingStoreIsn) { 10542292SN/A panic("Is stalled should have been cleared by stalling load!\n"); 10552292SN/A stalled = false; 10562292SN/A stallingStoreIsn = 0; 10572292SN/A } 10582292SN/A 10592329SN/A // Clear the smart pointer to make sure it is decremented. 10602731Sktlim@umich.edu storeQueue[store_idx].inst->setSquashed(); 10612292SN/A storeQueue[store_idx].inst = NULL; 10622292SN/A storeQueue[store_idx].canWB = 0; 10632292SN/A 10644032Sktlim@umich.edu // Must delete request now that it wasn't handed off to 10654032Sktlim@umich.edu // memory. This is quite ugly. @todo: Figure out the proper 10664032Sktlim@umich.edu // place to really handle request deletes. 10674032Sktlim@umich.edu delete storeQueue[store_idx].req; 10686974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && storeQueue[store_idx].isSplit) { 10696974Stjones1@inf.ed.ac.uk delete storeQueue[store_idx].sreqLow; 10706974Stjones1@inf.ed.ac.uk delete storeQueue[store_idx].sreqHigh; 10716974Stjones1@inf.ed.ac.uk 10726974Stjones1@inf.ed.ac.uk storeQueue[store_idx].sreqLow = NULL; 10736974Stjones1@inf.ed.ac.uk storeQueue[store_idx].sreqHigh = NULL; 10746974Stjones1@inf.ed.ac.uk } 10754032Sktlim@umich.edu 10762292SN/A storeQueue[store_idx].req = NULL; 10772292SN/A --stores; 10782292SN/A 10792292SN/A // Inefficient! 10802292SN/A storeTail = store_idx; 10812292SN/A 10822292SN/A decrStIdx(store_idx); 10832727Sktlim@umich.edu ++lsqSquashedStores; 10842292SN/A } 10852292SN/A} 10862292SN/A 10872292SN/Atemplate <class Impl> 10882292SN/Avoid 10893349Sbinkertn@umich.eduLSQUnit<Impl>::storePostSend(PacketPtr pkt) 10902693Sktlim@umich.edu{ 10912693Sktlim@umich.edu if (isStalled() && 10922693Sktlim@umich.edu storeQueue[storeWBIdx].inst->seqNum == stallingStoreIsn) { 10932693Sktlim@umich.edu DPRINTF(LSQUnit, "Unstalling, stalling store [sn:%lli] " 10942693Sktlim@umich.edu "load idx:%i\n", 10952693Sktlim@umich.edu stallingStoreIsn, stallingLoadIdx); 10962693Sktlim@umich.edu stalled = false; 10972693Sktlim@umich.edu stallingStoreIsn = 0; 10982693Sktlim@umich.edu iewStage->replayMemInst(loadQueue[stallingLoadIdx]); 10992693Sktlim@umich.edu } 11002693Sktlim@umich.edu 11012693Sktlim@umich.edu if (!storeQueue[storeWBIdx].inst->isStoreConditional()) { 11022693Sktlim@umich.edu // The store is basically completed at this time. This 11032693Sktlim@umich.edu // only works so long as the checker doesn't try to 11042693Sktlim@umich.edu // verify the value in memory for stores. 11052693Sktlim@umich.edu storeQueue[storeWBIdx].inst->setCompleted(); 11068887Sgeoffrey.blake@arm.com 11072693Sktlim@umich.edu if (cpu->checker) { 11082732Sktlim@umich.edu cpu->checker->verify(storeQueue[storeWBIdx].inst); 11092693Sktlim@umich.edu } 11102693Sktlim@umich.edu } 11112693Sktlim@umich.edu 11128727Snilay@cs.wisc.edu if (needsTSO) { 11138727Snilay@cs.wisc.edu storeInFlight = true; 11148727Snilay@cs.wisc.edu } 11158727Snilay@cs.wisc.edu 11162693Sktlim@umich.edu incrStIdx(storeWBIdx); 11172693Sktlim@umich.edu} 11182693Sktlim@umich.edu 11192693Sktlim@umich.edutemplate <class Impl> 11202693Sktlim@umich.eduvoid 11212678Sktlim@umich.eduLSQUnit<Impl>::writeback(DynInstPtr &inst, PacketPtr pkt) 11222678Sktlim@umich.edu{ 11232678Sktlim@umich.edu iewStage->wakeCPU(); 11242678Sktlim@umich.edu 11252678Sktlim@umich.edu // Squashed instructions do not need to complete their access. 11262678Sktlim@umich.edu if (inst->isSquashed()) { 11272678Sktlim@umich.edu assert(!inst->isStore()); 11282727Sktlim@umich.edu ++lsqIgnoredResponses; 11292678Sktlim@umich.edu return; 11302678Sktlim@umich.edu } 11312678Sktlim@umich.edu 11322678Sktlim@umich.edu if (!inst->isExecuted()) { 11332678Sktlim@umich.edu inst->setExecuted(); 11342678Sktlim@umich.edu 11352678Sktlim@umich.edu // Complete access to copy data to proper place. 11362678Sktlim@umich.edu inst->completeAcc(pkt); 11372678Sktlim@umich.edu } 11382678Sktlim@umich.edu 11392678Sktlim@umich.edu // Need to insert instruction into queue to commit 11402678Sktlim@umich.edu iewStage->instToCommit(inst); 11412678Sktlim@umich.edu 11422678Sktlim@umich.edu iewStage->activityThisCycle(); 11437598Sminkyu.jeong@arm.com 11447598Sminkyu.jeong@arm.com // see if this load changed the PC 11457598Sminkyu.jeong@arm.com iewStage->checkMisprediction(inst); 11462678Sktlim@umich.edu} 11472678Sktlim@umich.edu 11482678Sktlim@umich.edutemplate <class Impl> 11492678Sktlim@umich.eduvoid 11502292SN/ALSQUnit<Impl>::completeStore(int store_idx) 11512292SN/A{ 11522292SN/A assert(storeQueue[store_idx].inst); 11532292SN/A storeQueue[store_idx].completed = true; 11542292SN/A --storesToWB; 11552292SN/A // A bit conservative because a store completion may not free up entries, 11562292SN/A // but hopefully avoids two store completions in one cycle from making 11572292SN/A // the CPU tick twice. 11583126Sktlim@umich.edu cpu->wakeCPU(); 11592292SN/A cpu->activityThisCycle(); 11602292SN/A 11612292SN/A if (store_idx == storeHead) { 11622292SN/A do { 11632292SN/A incrStIdx(storeHead); 11642292SN/A 11652292SN/A --stores; 11662292SN/A } while (storeQueue[storeHead].completed && 11672292SN/A storeHead != storeTail); 11682292SN/A 11692292SN/A iewStage->updateLSQNextCycle = true; 11702292SN/A } 11712292SN/A 11722329SN/A DPRINTF(LSQUnit, "Completing store [sn:%lli], idx:%i, store head " 11732329SN/A "idx:%i\n", 11742329SN/A storeQueue[store_idx].inst->seqNum, store_idx, storeHead); 11752292SN/A 11769527SMatt.Horsnell@arm.com#if TRACING_ON 11779527SMatt.Horsnell@arm.com if (DTRACE(O3PipeView)) { 11789527SMatt.Horsnell@arm.com storeQueue[store_idx].inst->storeTick = 11799527SMatt.Horsnell@arm.com curTick() - storeQueue[store_idx].inst->fetchTick; 11809527SMatt.Horsnell@arm.com } 11819527SMatt.Horsnell@arm.com#endif 11829527SMatt.Horsnell@arm.com 11832292SN/A if (isStalled() && 11842292SN/A storeQueue[store_idx].inst->seqNum == stallingStoreIsn) { 11852292SN/A DPRINTF(LSQUnit, "Unstalling, stalling store [sn:%lli] " 11862292SN/A "load idx:%i\n", 11872292SN/A stallingStoreIsn, stallingLoadIdx); 11882292SN/A stalled = false; 11892292SN/A stallingStoreIsn = 0; 11902292SN/A iewStage->replayMemInst(loadQueue[stallingLoadIdx]); 11912292SN/A } 11922316SN/A 11932316SN/A storeQueue[store_idx].inst->setCompleted(); 11942329SN/A 11958727Snilay@cs.wisc.edu if (needsTSO) { 11968727Snilay@cs.wisc.edu storeInFlight = false; 11978727Snilay@cs.wisc.edu } 11988727Snilay@cs.wisc.edu 11992329SN/A // Tell the checker we've completed this instruction. Some stores 12002329SN/A // may get reported twice to the checker, but the checker can 12012329SN/A // handle that case. 12022316SN/A if (cpu->checker) { 12032732Sktlim@umich.edu cpu->checker->verify(storeQueue[store_idx].inst); 12042316SN/A } 12052292SN/A} 12062292SN/A 12072292SN/Atemplate <class Impl> 12086974Stjones1@inf.ed.ac.ukbool 12096974Stjones1@inf.ed.ac.ukLSQUnit<Impl>::sendStore(PacketPtr data_pkt) 12106974Stjones1@inf.ed.ac.uk{ 12118975Sandreas.hansson@arm.com if (!dcachePort->sendTimingReq(data_pkt)) { 12126974Stjones1@inf.ed.ac.uk // Need to handle becoming blocked on a store. 12136974Stjones1@inf.ed.ac.uk isStoreBlocked = true; 12146974Stjones1@inf.ed.ac.uk ++lsqCacheBlocked; 12156974Stjones1@inf.ed.ac.uk assert(retryPkt == NULL); 12166974Stjones1@inf.ed.ac.uk retryPkt = data_pkt; 12176974Stjones1@inf.ed.ac.uk return false; 12186974Stjones1@inf.ed.ac.uk } 12196974Stjones1@inf.ed.ac.uk return true; 12206974Stjones1@inf.ed.ac.uk} 12216974Stjones1@inf.ed.ac.uk 12226974Stjones1@inf.ed.ac.uktemplate <class Impl> 12232693Sktlim@umich.eduvoid 12242693Sktlim@umich.eduLSQUnit<Impl>::recvRetry() 12252693Sktlim@umich.edu{ 12262698Sktlim@umich.edu if (isStoreBlocked) { 12274985Sktlim@umich.edu DPRINTF(LSQUnit, "Receiving retry: store blocked\n"); 12282698Sktlim@umich.edu assert(retryPkt != NULL); 12292693Sktlim@umich.edu 12308587Snilay@cs.wisc.edu LSQSenderState *state = 12318587Snilay@cs.wisc.edu dynamic_cast<LSQSenderState *>(retryPkt->senderState); 12328587Snilay@cs.wisc.edu 12338975Sandreas.hansson@arm.com if (dcachePort->sendTimingReq(retryPkt)) { 12346974Stjones1@inf.ed.ac.uk // Don't finish the store unless this is the last packet. 12358133SAli.Saidi@ARM.com if (!TheISA::HasUnalignedMemAcc || !state->pktToSend || 12368133SAli.Saidi@ARM.com state->pendingPacket == retryPkt) { 12378133SAli.Saidi@ARM.com state->pktToSend = false; 12386974Stjones1@inf.ed.ac.uk storePostSend(retryPkt); 12396974Stjones1@inf.ed.ac.uk } 12402699Sktlim@umich.edu retryPkt = NULL; 12412693Sktlim@umich.edu isStoreBlocked = false; 12426974Stjones1@inf.ed.ac.uk 12436974Stjones1@inf.ed.ac.uk // Send any outstanding packet. 12446974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && state->pktToSend) { 12456974Stjones1@inf.ed.ac.uk assert(state->pendingPacket); 12466974Stjones1@inf.ed.ac.uk if (sendStore(state->pendingPacket)) { 12476974Stjones1@inf.ed.ac.uk storePostSend(state->pendingPacket); 12486974Stjones1@inf.ed.ac.uk } 12496974Stjones1@inf.ed.ac.uk } 12502693Sktlim@umich.edu } else { 12512693Sktlim@umich.edu // Still blocked! 12522727Sktlim@umich.edu ++lsqCacheBlocked; 12532693Sktlim@umich.edu } 12542693Sktlim@umich.edu } 12552693Sktlim@umich.edu} 12562693Sktlim@umich.edu 12572693Sktlim@umich.edutemplate <class Impl> 12582292SN/Ainline void 12599440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::incrStIdx(int &store_idx) const 12602292SN/A{ 12612292SN/A if (++store_idx >= SQEntries) 12622292SN/A store_idx = 0; 12632292SN/A} 12642292SN/A 12652292SN/Atemplate <class Impl> 12662292SN/Ainline void 12679440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::decrStIdx(int &store_idx) const 12682292SN/A{ 12692292SN/A if (--store_idx < 0) 12702292SN/A store_idx += SQEntries; 12712292SN/A} 12722292SN/A 12732292SN/Atemplate <class Impl> 12742292SN/Ainline void 12759440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::incrLdIdx(int &load_idx) const 12762292SN/A{ 12772292SN/A if (++load_idx >= LQEntries) 12782292SN/A load_idx = 0; 12792292SN/A} 12802292SN/A 12812292SN/Atemplate <class Impl> 12822292SN/Ainline void 12839440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::decrLdIdx(int &load_idx) const 12842292SN/A{ 12852292SN/A if (--load_idx < 0) 12862292SN/A load_idx += LQEntries; 12872292SN/A} 12882329SN/A 12892329SN/Atemplate <class Impl> 12902329SN/Avoid 12919440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::dumpInsts() const 12922329SN/A{ 12932329SN/A cprintf("Load store queue: Dumping instructions.\n"); 12942329SN/A cprintf("Load queue size: %i\n", loads); 12952329SN/A cprintf("Load queue: "); 12962329SN/A 12972329SN/A int load_idx = loadHead; 12982329SN/A 12992329SN/A while (load_idx != loadTail && loadQueue[load_idx]) { 13009440SAndreas.Sandberg@ARM.com const DynInstPtr &inst(loadQueue[load_idx]); 13019440SAndreas.Sandberg@ARM.com cprintf("%s.[sn:%i] ", inst->pcState(), inst->seqNum); 13022329SN/A 13032329SN/A incrLdIdx(load_idx); 13042329SN/A } 13059440SAndreas.Sandberg@ARM.com cprintf("\n"); 13062329SN/A 13072329SN/A cprintf("Store queue size: %i\n", stores); 13082329SN/A cprintf("Store queue: "); 13092329SN/A 13102329SN/A int store_idx = storeHead; 13112329SN/A 13122329SN/A while (store_idx != storeTail && storeQueue[store_idx].inst) { 13139440SAndreas.Sandberg@ARM.com const DynInstPtr &inst(storeQueue[store_idx].inst); 13149440SAndreas.Sandberg@ARM.com cprintf("%s.[sn:%i] ", inst->pcState(), inst->seqNum); 13152329SN/A 13162329SN/A incrStIdx(store_idx); 13172329SN/A } 13182329SN/A 13192329SN/A cprintf("\n"); 13202329SN/A} 13219944Smatt.horsnell@ARM.com 13229944Smatt.horsnell@ARM.com#endif//__CPU_O3_LSQ_UNIT_IMPL_HH__ 1323