lsq_unit_impl.hh revision 10575
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 return; 10910333Smitch.hayenga@arm.com } 1102678Sktlim@umich.edu 1116974Stjones1@inf.ed.ac.uk // If this is a split access, wait until all packets are received. 1126974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && !state->complete()) { 1136974Stjones1@inf.ed.ac.uk return; 1146974Stjones1@inf.ed.ac.uk } 1156974Stjones1@inf.ed.ac.uk 1169444SAndreas.Sandberg@ARM.com assert(!cpu->switchedOut()); 11710327Smitch.hayenga@arm.com if (!inst->isSquashed()) { 1182678Sktlim@umich.edu if (!state->noWB) { 1196974Stjones1@inf.ed.ac.uk if (!TheISA::HasUnalignedMemAcc || !state->isSplit || 1206974Stjones1@inf.ed.ac.uk !state->isLoad) { 1216974Stjones1@inf.ed.ac.uk writeback(inst, pkt); 1226974Stjones1@inf.ed.ac.uk } else { 1236974Stjones1@inf.ed.ac.uk writeback(inst, state->mainPkt); 1246974Stjones1@inf.ed.ac.uk } 1252678Sktlim@umich.edu } 1262678Sktlim@umich.edu 1272678Sktlim@umich.edu if (inst->isStore()) { 1282678Sktlim@umich.edu completeStore(state->idx); 1292678Sktlim@umich.edu } 1302344SN/A } 1312307SN/A 1326974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && state->isSplit && state->isLoad) { 1336974Stjones1@inf.ed.ac.uk delete state->mainPkt->req; 1346974Stjones1@inf.ed.ac.uk delete state->mainPkt; 1356974Stjones1@inf.ed.ac.uk } 13610020Smatt.horsnell@ARM.com 13710020Smatt.horsnell@ARM.com pkt->req->setAccessLatency(); 13810023Smatt.horsnell@ARM.com cpu->ppDataAccessComplete->notify(std::make_pair(inst, pkt)); 13910023Smatt.horsnell@ARM.com 1402678Sktlim@umich.edu delete state; 1412292SN/A} 1422292SN/A 1432292SN/Atemplate <class Impl> 1442292SN/ALSQUnit<Impl>::LSQUnit() 1458545Ssaidi@eecs.umich.edu : loads(0), stores(0), storesToWB(0), cacheBlockMask(0), stalled(false), 14610333Smitch.hayenga@arm.com isStoreBlocked(false), storeInFlight(false), hasPendingPkt(false) 1472292SN/A{ 1482292SN/A} 1492292SN/A 1502292SN/Atemplate<class Impl> 1512292SN/Avoid 1525529Snate@binkert.orgLSQUnit<Impl>::init(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params, 1535529Snate@binkert.org LSQ *lsq_ptr, unsigned maxLQEntries, unsigned maxSQEntries, 1545529Snate@binkert.org unsigned id) 1552292SN/A{ 1564329Sktlim@umich.edu cpu = cpu_ptr; 1574329Sktlim@umich.edu iewStage = iew_ptr; 1584329Sktlim@umich.edu 1592907Sktlim@umich.edu lsq = lsq_ptr; 1602907Sktlim@umich.edu 1612292SN/A lsqID = id; 1622292SN/A 16310175SMitch.Hayenga@ARM.com DPRINTF(LSQUnit, "Creating LSQUnit%i object.\n",id); 16410175SMitch.Hayenga@ARM.com 1652329SN/A // Add 1 for the sentinel entry (they are circular queues). 1662329SN/A LQEntries = maxLQEntries + 1; 1672329SN/A SQEntries = maxSQEntries + 1; 1682292SN/A 1699936SFaissal.Sleiman@arm.com //Due to uint8_t index in LSQSenderState 1709936SFaissal.Sleiman@arm.com assert(LQEntries <= 256); 1719936SFaissal.Sleiman@arm.com assert(SQEntries <= 256); 1729936SFaissal.Sleiman@arm.com 1732292SN/A loadQueue.resize(LQEntries); 1742292SN/A storeQueue.resize(SQEntries); 1752292SN/A 1768199SAli.Saidi@ARM.com depCheckShift = params->LSQDepCheckShift; 1778199SAli.Saidi@ARM.com checkLoads = params->LSQCheckLoads; 1789444SAndreas.Sandberg@ARM.com cachePorts = params->cachePorts; 1799444SAndreas.Sandberg@ARM.com needsTSO = params->needsTSO; 1809444SAndreas.Sandberg@ARM.com 1819444SAndreas.Sandberg@ARM.com resetState(); 1829444SAndreas.Sandberg@ARM.com} 1839444SAndreas.Sandberg@ARM.com 1849444SAndreas.Sandberg@ARM.com 1859444SAndreas.Sandberg@ARM.comtemplate<class Impl> 1869444SAndreas.Sandberg@ARM.comvoid 1879444SAndreas.Sandberg@ARM.comLSQUnit<Impl>::resetState() 1889444SAndreas.Sandberg@ARM.com{ 1899444SAndreas.Sandberg@ARM.com loads = stores = storesToWB = 0; 1908199SAli.Saidi@ARM.com 1912292SN/A loadHead = loadTail = 0; 1922292SN/A 1932292SN/A storeHead = storeWBIdx = storeTail = 0; 1942292SN/A 1952292SN/A usedPorts = 0; 1962292SN/A 1973492Sktlim@umich.edu retryPkt = NULL; 1982329SN/A memDepViolator = NULL; 1992292SN/A 2009444SAndreas.Sandberg@ARM.com stalled = false; 2019444SAndreas.Sandberg@ARM.com 2029814Sandreas.hansson@arm.com cacheBlockMask = ~(cpu->cacheLineSize() - 1); 2032292SN/A} 2042292SN/A 2052292SN/Atemplate<class Impl> 2062292SN/Astd::string 2072292SN/ALSQUnit<Impl>::name() const 2082292SN/A{ 2092292SN/A if (Impl::MaxThreads == 1) { 2102292SN/A return iewStage->name() + ".lsq"; 2112292SN/A } else { 21210386Sandreas.hansson@arm.com return iewStage->name() + ".lsq.thread" + std::to_string(lsqID); 2132292SN/A } 2142292SN/A} 2152292SN/A 2162292SN/Atemplate<class Impl> 2172292SN/Avoid 2182727Sktlim@umich.eduLSQUnit<Impl>::regStats() 2192727Sktlim@umich.edu{ 2202727Sktlim@umich.edu lsqForwLoads 2212727Sktlim@umich.edu .name(name() + ".forwLoads") 2222727Sktlim@umich.edu .desc("Number of loads that had data forwarded from stores"); 2232727Sktlim@umich.edu 2242727Sktlim@umich.edu invAddrLoads 2252727Sktlim@umich.edu .name(name() + ".invAddrLoads") 2262727Sktlim@umich.edu .desc("Number of loads ignored due to an invalid address"); 2272727Sktlim@umich.edu 2282727Sktlim@umich.edu lsqSquashedLoads 2292727Sktlim@umich.edu .name(name() + ".squashedLoads") 2302727Sktlim@umich.edu .desc("Number of loads squashed"); 2312727Sktlim@umich.edu 2322727Sktlim@umich.edu lsqIgnoredResponses 2332727Sktlim@umich.edu .name(name() + ".ignoredResponses") 2342727Sktlim@umich.edu .desc("Number of memory responses ignored because the instruction is squashed"); 2352727Sktlim@umich.edu 2362361SN/A lsqMemOrderViolation 2372361SN/A .name(name() + ".memOrderViolation") 2382361SN/A .desc("Number of memory ordering violations"); 2392361SN/A 2402727Sktlim@umich.edu lsqSquashedStores 2412727Sktlim@umich.edu .name(name() + ".squashedStores") 2422727Sktlim@umich.edu .desc("Number of stores squashed"); 2432727Sktlim@umich.edu 2442727Sktlim@umich.edu invAddrSwpfs 2452727Sktlim@umich.edu .name(name() + ".invAddrSwpfs") 2462727Sktlim@umich.edu .desc("Number of software prefetches ignored due to an invalid address"); 2472727Sktlim@umich.edu 2482727Sktlim@umich.edu lsqBlockedLoads 2492727Sktlim@umich.edu .name(name() + ".blockedLoads") 2502727Sktlim@umich.edu .desc("Number of blocked loads due to partial load-store forwarding"); 2512727Sktlim@umich.edu 2522727Sktlim@umich.edu lsqRescheduledLoads 2532727Sktlim@umich.edu .name(name() + ".rescheduledLoads") 2542727Sktlim@umich.edu .desc("Number of loads that were rescheduled"); 2552727Sktlim@umich.edu 2562727Sktlim@umich.edu lsqCacheBlocked 2572727Sktlim@umich.edu .name(name() + ".cacheBlocked") 2582727Sktlim@umich.edu .desc("Number of times an access to memory failed due to the cache being blocked"); 2592727Sktlim@umich.edu} 2602727Sktlim@umich.edu 2612727Sktlim@umich.edutemplate<class Impl> 2622727Sktlim@umich.eduvoid 2638922Swilliam.wang@arm.comLSQUnit<Impl>::setDcachePort(MasterPort *dcache_port) 2644329Sktlim@umich.edu{ 2654329Sktlim@umich.edu dcachePort = dcache_port; 2664329Sktlim@umich.edu} 2674329Sktlim@umich.edu 2684329Sktlim@umich.edutemplate<class Impl> 2694329Sktlim@umich.eduvoid 2702292SN/ALSQUnit<Impl>::clearLQ() 2712292SN/A{ 2722292SN/A loadQueue.clear(); 2732292SN/A} 2742292SN/A 2752292SN/Atemplate<class Impl> 2762292SN/Avoid 2772292SN/ALSQUnit<Impl>::clearSQ() 2782292SN/A{ 2792292SN/A storeQueue.clear(); 2802292SN/A} 2812292SN/A 2822292SN/Atemplate<class Impl> 2832292SN/Avoid 2849444SAndreas.Sandberg@ARM.comLSQUnit<Impl>::drainSanityCheck() const 2852307SN/A{ 2869444SAndreas.Sandberg@ARM.com for (int i = 0; i < loadQueue.size(); ++i) 2872367SN/A assert(!loadQueue[i]); 2882307SN/A 2892329SN/A assert(storesToWB == 0); 2909444SAndreas.Sandberg@ARM.com assert(!retryPkt); 2912307SN/A} 2922307SN/A 2932307SN/Atemplate<class Impl> 2942307SN/Avoid 2952307SN/ALSQUnit<Impl>::takeOverFrom() 2962307SN/A{ 2979444SAndreas.Sandberg@ARM.com resetState(); 2982307SN/A} 2992307SN/A 3002307SN/Atemplate<class Impl> 3012307SN/Avoid 3022292SN/ALSQUnit<Impl>::resizeLQ(unsigned size) 3032292SN/A{ 3042329SN/A unsigned size_plus_sentinel = size + 1; 3052329SN/A assert(size_plus_sentinel >= LQEntries); 3062292SN/A 3072329SN/A if (size_plus_sentinel > LQEntries) { 3082329SN/A while (size_plus_sentinel > loadQueue.size()) { 3092292SN/A DynInstPtr dummy; 3102292SN/A loadQueue.push_back(dummy); 3112292SN/A LQEntries++; 3122292SN/A } 3132292SN/A } else { 3142329SN/A LQEntries = size_plus_sentinel; 3152292SN/A } 3162292SN/A 3179936SFaissal.Sleiman@arm.com assert(LQEntries <= 256); 3182292SN/A} 3192292SN/A 3202292SN/Atemplate<class Impl> 3212292SN/Avoid 3222292SN/ALSQUnit<Impl>::resizeSQ(unsigned size) 3232292SN/A{ 3242329SN/A unsigned size_plus_sentinel = size + 1; 3252329SN/A if (size_plus_sentinel > SQEntries) { 3262329SN/A while (size_plus_sentinel > storeQueue.size()) { 3272292SN/A SQEntry dummy; 3282292SN/A storeQueue.push_back(dummy); 3292292SN/A SQEntries++; 3302292SN/A } 3312292SN/A } else { 3322329SN/A SQEntries = size_plus_sentinel; 3332292SN/A } 3349936SFaissal.Sleiman@arm.com 3359936SFaissal.Sleiman@arm.com assert(SQEntries <= 256); 3362292SN/A} 3372292SN/A 3382292SN/Atemplate <class Impl> 3392292SN/Avoid 3402292SN/ALSQUnit<Impl>::insert(DynInstPtr &inst) 3412292SN/A{ 3422292SN/A assert(inst->isMemRef()); 3432292SN/A 3442292SN/A assert(inst->isLoad() || inst->isStore()); 3452292SN/A 3462292SN/A if (inst->isLoad()) { 3472292SN/A insertLoad(inst); 3482292SN/A } else { 3492292SN/A insertStore(inst); 3502292SN/A } 3512292SN/A 3522292SN/A inst->setInLSQ(); 3532292SN/A} 3542292SN/A 3552292SN/Atemplate <class Impl> 3562292SN/Avoid 3572292SN/ALSQUnit<Impl>::insertLoad(DynInstPtr &load_inst) 3582292SN/A{ 3592329SN/A assert((loadTail + 1) % LQEntries != loadHead); 3602329SN/A assert(loads < LQEntries); 3612292SN/A 3627720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Inserting load PC %s, idx:%i [sn:%lli]\n", 3637720Sgblack@eecs.umich.edu load_inst->pcState(), loadTail, load_inst->seqNum); 3642292SN/A 3652292SN/A load_inst->lqIdx = loadTail; 3662292SN/A 3672292SN/A if (stores == 0) { 3682292SN/A load_inst->sqIdx = -1; 3692292SN/A } else { 3702292SN/A load_inst->sqIdx = storeTail; 3712292SN/A } 3722292SN/A 3732292SN/A loadQueue[loadTail] = load_inst; 3742292SN/A 3752292SN/A incrLdIdx(loadTail); 3762292SN/A 3772292SN/A ++loads; 3782292SN/A} 3792292SN/A 3802292SN/Atemplate <class Impl> 3812292SN/Avoid 3822292SN/ALSQUnit<Impl>::insertStore(DynInstPtr &store_inst) 3832292SN/A{ 3842292SN/A // Make sure it is not full before inserting an instruction. 3852292SN/A assert((storeTail + 1) % SQEntries != storeHead); 3862292SN/A assert(stores < SQEntries); 3872292SN/A 3887720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Inserting store PC %s, idx:%i [sn:%lli]\n", 3897720Sgblack@eecs.umich.edu store_inst->pcState(), storeTail, store_inst->seqNum); 3902292SN/A 3912292SN/A store_inst->sqIdx = storeTail; 3922292SN/A store_inst->lqIdx = loadTail; 3932292SN/A 3942292SN/A storeQueue[storeTail] = SQEntry(store_inst); 3952292SN/A 3962292SN/A incrStIdx(storeTail); 3972292SN/A 3982292SN/A ++stores; 3992292SN/A} 4002292SN/A 4012292SN/Atemplate <class Impl> 4022292SN/Atypename Impl::DynInstPtr 4032292SN/ALSQUnit<Impl>::getMemDepViolator() 4042292SN/A{ 4052292SN/A DynInstPtr temp = memDepViolator; 4062292SN/A 4072292SN/A memDepViolator = NULL; 4082292SN/A 4092292SN/A return temp; 4102292SN/A} 4112292SN/A 4122292SN/Atemplate <class Impl> 4132292SN/Aunsigned 41410239Sbinhpham@cs.rutgers.eduLSQUnit<Impl>::numFreeLoadEntries() 4152292SN/A{ 41610239Sbinhpham@cs.rutgers.edu //LQ has an extra dummy entry to differentiate 41710239Sbinhpham@cs.rutgers.edu //empty/full conditions. Subtract 1 from the free entries. 41810239Sbinhpham@cs.rutgers.edu DPRINTF(LSQUnit, "LQ size: %d, #loads occupied: %d\n", LQEntries, loads); 41910239Sbinhpham@cs.rutgers.edu return LQEntries - loads - 1; 42010239Sbinhpham@cs.rutgers.edu} 4212292SN/A 42210239Sbinhpham@cs.rutgers.edutemplate <class Impl> 42310239Sbinhpham@cs.rutgers.eduunsigned 42410239Sbinhpham@cs.rutgers.eduLSQUnit<Impl>::numFreeStoreEntries() 42510239Sbinhpham@cs.rutgers.edu{ 42610239Sbinhpham@cs.rutgers.edu //SQ has an extra dummy entry to differentiate 42710239Sbinhpham@cs.rutgers.edu //empty/full conditions. Subtract 1 from the free entries. 42810239Sbinhpham@cs.rutgers.edu DPRINTF(LSQUnit, "SQ size: %d, #stores occupied: %d\n", SQEntries, stores); 42910239Sbinhpham@cs.rutgers.edu return SQEntries - stores - 1; 43010239Sbinhpham@cs.rutgers.edu 43110239Sbinhpham@cs.rutgers.edu } 4322292SN/A 4332292SN/Atemplate <class Impl> 4348545Ssaidi@eecs.umich.eduvoid 4358545Ssaidi@eecs.umich.eduLSQUnit<Impl>::checkSnoop(PacketPtr pkt) 4368545Ssaidi@eecs.umich.edu{ 4378545Ssaidi@eecs.umich.edu int load_idx = loadHead; 43810030SAli.Saidi@ARM.com DPRINTF(LSQUnit, "Got snoop for address %#x\n", pkt->getAddr()); 4398545Ssaidi@eecs.umich.edu 4409383SAli.Saidi@ARM.com // Unlock the cpu-local monitor when the CPU sees a snoop to a locked 4419383SAli.Saidi@ARM.com // address. The CPU can speculatively execute a LL operation after a pending 4429383SAli.Saidi@ARM.com // SC operation in the pipeline and that can make the cache monitor the CPU 4439383SAli.Saidi@ARM.com // is connected to valid while it really shouldn't be. 44410030SAli.Saidi@ARM.com for (int x = 0; x < cpu->numContexts(); x++) { 4459383SAli.Saidi@ARM.com ThreadContext *tc = cpu->getContext(x); 4469383SAli.Saidi@ARM.com bool no_squash = cpu->thread[x]->noSquashFromTC; 4479383SAli.Saidi@ARM.com cpu->thread[x]->noSquashFromTC = true; 4489383SAli.Saidi@ARM.com TheISA::handleLockedSnoop(tc, pkt, cacheBlockMask); 4499383SAli.Saidi@ARM.com cpu->thread[x]->noSquashFromTC = no_squash; 4509383SAli.Saidi@ARM.com } 4519383SAli.Saidi@ARM.com 45210030SAli.Saidi@ARM.com Addr invalidate_addr = pkt->getAddr() & cacheBlockMask; 45310030SAli.Saidi@ARM.com 45410030SAli.Saidi@ARM.com DynInstPtr ld_inst = loadQueue[load_idx]; 45510030SAli.Saidi@ARM.com if (ld_inst) { 45610030SAli.Saidi@ARM.com Addr load_addr = ld_inst->physEffAddr & cacheBlockMask; 45710030SAli.Saidi@ARM.com // Check that this snoop didn't just invalidate our lock flag 45810030SAli.Saidi@ARM.com if (ld_inst->effAddrValid() && load_addr == invalidate_addr && 45910030SAli.Saidi@ARM.com ld_inst->memReqFlags & Request::LLSC) 46010030SAli.Saidi@ARM.com TheISA::handleLockedSnoopHit(ld_inst.get()); 46110030SAli.Saidi@ARM.com } 46210030SAli.Saidi@ARM.com 4638545Ssaidi@eecs.umich.edu // If this is the only load in the LSQ we don't care 4648545Ssaidi@eecs.umich.edu if (load_idx == loadTail) 4658545Ssaidi@eecs.umich.edu return; 46610030SAli.Saidi@ARM.com 4678545Ssaidi@eecs.umich.edu incrLdIdx(load_idx); 4688545Ssaidi@eecs.umich.edu 46910149Smarco.elver@ed.ac.uk bool force_squash = false; 47010149Smarco.elver@ed.ac.uk 4718545Ssaidi@eecs.umich.edu while (load_idx != loadTail) { 4728545Ssaidi@eecs.umich.edu DynInstPtr ld_inst = loadQueue[load_idx]; 4738545Ssaidi@eecs.umich.edu 4749046SAli.Saidi@ARM.com if (!ld_inst->effAddrValid() || ld_inst->uncacheable()) { 4758545Ssaidi@eecs.umich.edu incrLdIdx(load_idx); 4768545Ssaidi@eecs.umich.edu continue; 4778545Ssaidi@eecs.umich.edu } 4788545Ssaidi@eecs.umich.edu 4798545Ssaidi@eecs.umich.edu Addr load_addr = ld_inst->physEffAddr & cacheBlockMask; 4808545Ssaidi@eecs.umich.edu DPRINTF(LSQUnit, "-- inst [sn:%lli] load_addr: %#x to pktAddr:%#x\n", 4818545Ssaidi@eecs.umich.edu ld_inst->seqNum, load_addr, invalidate_addr); 4828545Ssaidi@eecs.umich.edu 48310149Smarco.elver@ed.ac.uk if (load_addr == invalidate_addr || force_squash) { 48410149Smarco.elver@ed.ac.uk if (needsTSO) { 48510149Smarco.elver@ed.ac.uk // If we have a TSO system, as all loads must be ordered with 48610149Smarco.elver@ed.ac.uk // all other loads, this load as well as *all* subsequent loads 48710149Smarco.elver@ed.ac.uk // need to be squashed to prevent possible load reordering. 48810149Smarco.elver@ed.ac.uk force_squash = true; 48910149Smarco.elver@ed.ac.uk } 49010149Smarco.elver@ed.ac.uk if (ld_inst->possibleLoadViolation() || force_squash) { 4918545Ssaidi@eecs.umich.edu DPRINTF(LSQUnit, "Conflicting load at addr %#x [sn:%lli]\n", 49210030SAli.Saidi@ARM.com pkt->getAddr(), ld_inst->seqNum); 4938545Ssaidi@eecs.umich.edu 4948545Ssaidi@eecs.umich.edu // Mark the load for re-execution 49510474Sandreas.hansson@arm.com ld_inst->fault = std::make_shared<ReExec>(); 4968545Ssaidi@eecs.umich.edu } else { 49710030SAli.Saidi@ARM.com DPRINTF(LSQUnit, "HitExternal Snoop for addr %#x [sn:%lli]\n", 49810030SAli.Saidi@ARM.com pkt->getAddr(), ld_inst->seqNum); 49910030SAli.Saidi@ARM.com 50010030SAli.Saidi@ARM.com // Make sure that we don't lose a snoop hitting a LOCKED 50110030SAli.Saidi@ARM.com // address since the LOCK* flags don't get updated until 50210030SAli.Saidi@ARM.com // commit. 50310030SAli.Saidi@ARM.com if (ld_inst->memReqFlags & Request::LLSC) 50410030SAli.Saidi@ARM.com TheISA::handleLockedSnoopHit(ld_inst.get()); 50510030SAli.Saidi@ARM.com 5068545Ssaidi@eecs.umich.edu // If a older load checks this and it's true 5078545Ssaidi@eecs.umich.edu // then we might have missed the snoop 5088545Ssaidi@eecs.umich.edu // in which case we need to invalidate to be sure 5099046SAli.Saidi@ARM.com ld_inst->hitExternalSnoop(true); 5108545Ssaidi@eecs.umich.edu } 5118545Ssaidi@eecs.umich.edu } 5128545Ssaidi@eecs.umich.edu incrLdIdx(load_idx); 5138545Ssaidi@eecs.umich.edu } 5148545Ssaidi@eecs.umich.edu return; 5158545Ssaidi@eecs.umich.edu} 5168545Ssaidi@eecs.umich.edu 5178545Ssaidi@eecs.umich.edutemplate <class Impl> 5182292SN/AFault 5198199SAli.Saidi@ARM.comLSQUnit<Impl>::checkViolations(int load_idx, DynInstPtr &inst) 5208199SAli.Saidi@ARM.com{ 5218199SAli.Saidi@ARM.com Addr inst_eff_addr1 = inst->effAddr >> depCheckShift; 5228199SAli.Saidi@ARM.com Addr inst_eff_addr2 = (inst->effAddr + inst->effSize - 1) >> depCheckShift; 5238199SAli.Saidi@ARM.com 5248199SAli.Saidi@ARM.com /** @todo in theory you only need to check an instruction that has executed 5258199SAli.Saidi@ARM.com * however, there isn't a good way in the pipeline at the moment to check 5268199SAli.Saidi@ARM.com * all instructions that will execute before the store writes back. Thus, 5278199SAli.Saidi@ARM.com * like the implementation that came before it, we're overly conservative. 5288199SAli.Saidi@ARM.com */ 5298199SAli.Saidi@ARM.com while (load_idx != loadTail) { 5308199SAli.Saidi@ARM.com DynInstPtr ld_inst = loadQueue[load_idx]; 5319046SAli.Saidi@ARM.com if (!ld_inst->effAddrValid() || ld_inst->uncacheable()) { 5328199SAli.Saidi@ARM.com incrLdIdx(load_idx); 5338199SAli.Saidi@ARM.com continue; 5348199SAli.Saidi@ARM.com } 5358199SAli.Saidi@ARM.com 5368199SAli.Saidi@ARM.com Addr ld_eff_addr1 = ld_inst->effAddr >> depCheckShift; 5378199SAli.Saidi@ARM.com Addr ld_eff_addr2 = 5388199SAli.Saidi@ARM.com (ld_inst->effAddr + ld_inst->effSize - 1) >> depCheckShift; 5398199SAli.Saidi@ARM.com 5408272SAli.Saidi@ARM.com if (inst_eff_addr2 >= ld_eff_addr1 && inst_eff_addr1 <= ld_eff_addr2) { 5418545Ssaidi@eecs.umich.edu if (inst->isLoad()) { 5428545Ssaidi@eecs.umich.edu // If this load is to the same block as an external snoop 5438545Ssaidi@eecs.umich.edu // invalidate that we've observed then the load needs to be 5448545Ssaidi@eecs.umich.edu // squashed as it could have newer data 5459046SAli.Saidi@ARM.com if (ld_inst->hitExternalSnoop()) { 5468545Ssaidi@eecs.umich.edu if (!memDepViolator || 5478545Ssaidi@eecs.umich.edu ld_inst->seqNum < memDepViolator->seqNum) { 5488545Ssaidi@eecs.umich.edu DPRINTF(LSQUnit, "Detected fault with inst [sn:%lli] " 5498592Sgblack@eecs.umich.edu "and [sn:%lli] at address %#x\n", 5508592Sgblack@eecs.umich.edu inst->seqNum, ld_inst->seqNum, ld_eff_addr1); 5518545Ssaidi@eecs.umich.edu memDepViolator = ld_inst; 5528199SAli.Saidi@ARM.com 5538545Ssaidi@eecs.umich.edu ++lsqMemOrderViolation; 5548199SAli.Saidi@ARM.com 55510474Sandreas.hansson@arm.com return std::make_shared<GenericISA::M5PanicFault>( 55610474Sandreas.hansson@arm.com "Detected fault with inst [sn:%lli] and " 55710474Sandreas.hansson@arm.com "[sn:%lli] at address %#x\n", 55810474Sandreas.hansson@arm.com inst->seqNum, ld_inst->seqNum, ld_eff_addr1); 5598545Ssaidi@eecs.umich.edu } 5608545Ssaidi@eecs.umich.edu } 5618199SAli.Saidi@ARM.com 5628545Ssaidi@eecs.umich.edu // Otherwise, mark the load has a possible load violation 5638545Ssaidi@eecs.umich.edu // and if we see a snoop before it's commited, we need to squash 5649046SAli.Saidi@ARM.com ld_inst->possibleLoadViolation(true); 56510575SMarco.Elver@ARM.com DPRINTF(LSQUnit, "Found possible load violation at addr: %#x" 5668545Ssaidi@eecs.umich.edu " between instructions [sn:%lli] and [sn:%lli]\n", 5678545Ssaidi@eecs.umich.edu inst_eff_addr1, inst->seqNum, ld_inst->seqNum); 5688545Ssaidi@eecs.umich.edu } else { 5698545Ssaidi@eecs.umich.edu // A load/store incorrectly passed this store. 5708545Ssaidi@eecs.umich.edu // Check if we already have a violator, or if it's newer 5718545Ssaidi@eecs.umich.edu // squash and refetch. 5728545Ssaidi@eecs.umich.edu if (memDepViolator && ld_inst->seqNum > memDepViolator->seqNum) 5738545Ssaidi@eecs.umich.edu break; 5748545Ssaidi@eecs.umich.edu 5758592Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Detected fault with inst [sn:%lli] and " 5768592Sgblack@eecs.umich.edu "[sn:%lli] at address %#x\n", 5778592Sgblack@eecs.umich.edu inst->seqNum, ld_inst->seqNum, ld_eff_addr1); 5788545Ssaidi@eecs.umich.edu memDepViolator = ld_inst; 5798545Ssaidi@eecs.umich.edu 5808545Ssaidi@eecs.umich.edu ++lsqMemOrderViolation; 5818545Ssaidi@eecs.umich.edu 58210474Sandreas.hansson@arm.com return std::make_shared<GenericISA::M5PanicFault>( 58310474Sandreas.hansson@arm.com "Detected fault with " 58410474Sandreas.hansson@arm.com "inst [sn:%lli] and [sn:%lli] at address %#x\n", 58510474Sandreas.hansson@arm.com inst->seqNum, ld_inst->seqNum, ld_eff_addr1); 5868545Ssaidi@eecs.umich.edu } 5878199SAli.Saidi@ARM.com } 5888199SAli.Saidi@ARM.com 5898199SAli.Saidi@ARM.com incrLdIdx(load_idx); 5908199SAli.Saidi@ARM.com } 5918199SAli.Saidi@ARM.com return NoFault; 5928199SAli.Saidi@ARM.com} 5938199SAli.Saidi@ARM.com 5948199SAli.Saidi@ARM.com 5958199SAli.Saidi@ARM.com 5968199SAli.Saidi@ARM.com 5978199SAli.Saidi@ARM.comtemplate <class Impl> 5988199SAli.Saidi@ARM.comFault 5992292SN/ALSQUnit<Impl>::executeLoad(DynInstPtr &inst) 6002292SN/A{ 6014032Sktlim@umich.edu using namespace TheISA; 6022292SN/A // Execute a specific load. 6032292SN/A Fault load_fault = NoFault; 6042292SN/A 6057720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Executing load PC %s, [sn:%lli]\n", 6067944SGiacomo.Gabrielli@arm.com inst->pcState(), inst->seqNum); 6072292SN/A 6084032Sktlim@umich.edu assert(!inst->isSquashed()); 6094032Sktlim@umich.edu 6102669Sktlim@umich.edu load_fault = inst->initiateAcc(); 6112292SN/A 6127944SGiacomo.Gabrielli@arm.com if (inst->isTranslationDelayed() && 6137944SGiacomo.Gabrielli@arm.com load_fault == NoFault) 6147944SGiacomo.Gabrielli@arm.com return load_fault; 6157944SGiacomo.Gabrielli@arm.com 6167597Sminkyu.jeong@arm.com // If the instruction faulted or predicated false, then we need to send it 6177597Sminkyu.jeong@arm.com // along to commit without the instruction completing. 61810231Ssteve.reinhardt@amd.com if (load_fault != NoFault || !inst->readPredicate()) { 6192329SN/A // Send this instruction to commit, also make sure iew stage 6202329SN/A // realizes there is activity. 6212367SN/A // Mark it as executed unless it is an uncached load that 6222367SN/A // needs to hit the head of commit. 62310231Ssteve.reinhardt@amd.com if (!inst->readPredicate()) 6247848SAli.Saidi@ARM.com inst->forwardOldRegs(); 6257600Sminkyu.jeong@arm.com DPRINTF(LSQUnit, "Load [sn:%lli] not executed from %s\n", 6267600Sminkyu.jeong@arm.com inst->seqNum, 6277600Sminkyu.jeong@arm.com (load_fault != NoFault ? "fault" : "predication")); 6284032Sktlim@umich.edu if (!(inst->hasRequest() && inst->uncacheable()) || 6293731Sktlim@umich.edu inst->isAtCommit()) { 6302367SN/A inst->setExecuted(); 6312367SN/A } 6322292SN/A iewStage->instToCommit(inst); 6332292SN/A iewStage->activityThisCycle(); 63410333Smitch.hayenga@arm.com } else { 6359046SAli.Saidi@ARM.com assert(inst->effAddrValid()); 6364032Sktlim@umich.edu int load_idx = inst->lqIdx; 6374032Sktlim@umich.edu incrLdIdx(load_idx); 6384032Sktlim@umich.edu 6398199SAli.Saidi@ARM.com if (checkLoads) 6408199SAli.Saidi@ARM.com return checkViolations(load_idx, inst); 6412292SN/A } 6422292SN/A 6432292SN/A return load_fault; 6442292SN/A} 6452292SN/A 6462292SN/Atemplate <class Impl> 6472292SN/AFault 6482292SN/ALSQUnit<Impl>::executeStore(DynInstPtr &store_inst) 6492292SN/A{ 6502292SN/A using namespace TheISA; 6512292SN/A // Make sure that a store exists. 6522292SN/A assert(stores != 0); 6532292SN/A 6542292SN/A int store_idx = store_inst->sqIdx; 6552292SN/A 6567720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Executing store PC %s [sn:%lli]\n", 6577720Sgblack@eecs.umich.edu store_inst->pcState(), store_inst->seqNum); 6582292SN/A 6594032Sktlim@umich.edu assert(!store_inst->isSquashed()); 6604032Sktlim@umich.edu 6612292SN/A // Check the recently completed loads to see if any match this store's 6622292SN/A // address. If so, then we have a memory ordering violation. 6632292SN/A int load_idx = store_inst->lqIdx; 6642292SN/A 6652292SN/A Fault store_fault = store_inst->initiateAcc(); 6662292SN/A 6677944SGiacomo.Gabrielli@arm.com if (store_inst->isTranslationDelayed() && 6687944SGiacomo.Gabrielli@arm.com store_fault == NoFault) 6697944SGiacomo.Gabrielli@arm.com return store_fault; 6707944SGiacomo.Gabrielli@arm.com 67110231Ssteve.reinhardt@amd.com if (!store_inst->readPredicate()) 6727848SAli.Saidi@ARM.com store_inst->forwardOldRegs(); 6737848SAli.Saidi@ARM.com 6742329SN/A if (storeQueue[store_idx].size == 0) { 6757782Sminkyu.jeong@arm.com DPRINTF(LSQUnit,"Fault on Store PC %s, [sn:%lli], Size = 0\n", 6767720Sgblack@eecs.umich.edu store_inst->pcState(), store_inst->seqNum); 6772292SN/A 6782292SN/A return store_fault; 67910231Ssteve.reinhardt@amd.com } else if (!store_inst->readPredicate()) { 6807782Sminkyu.jeong@arm.com DPRINTF(LSQUnit, "Store [sn:%lli] not executed from predication\n", 6817782Sminkyu.jeong@arm.com store_inst->seqNum); 6827782Sminkyu.jeong@arm.com return store_fault; 6832292SN/A } 6842292SN/A 6852292SN/A assert(store_fault == NoFault); 6862292SN/A 6872336SN/A if (store_inst->isStoreConditional()) { 6882336SN/A // Store conditionals need to set themselves as able to 6892336SN/A // writeback if we haven't had a fault by here. 6902329SN/A storeQueue[store_idx].canWB = true; 6912292SN/A 6922329SN/A ++storesToWB; 6932292SN/A } 6942292SN/A 6958199SAli.Saidi@ARM.com return checkViolations(load_idx, store_inst); 6962292SN/A 6972292SN/A} 6982292SN/A 6992292SN/Atemplate <class Impl> 7002292SN/Avoid 7012292SN/ALSQUnit<Impl>::commitLoad() 7022292SN/A{ 7032292SN/A assert(loadQueue[loadHead]); 7042292SN/A 7057720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "Committing head load instruction, PC %s\n", 7067720Sgblack@eecs.umich.edu loadQueue[loadHead]->pcState()); 7072292SN/A 7082292SN/A loadQueue[loadHead] = NULL; 7092292SN/A 7102292SN/A incrLdIdx(loadHead); 7112292SN/A 7122292SN/A --loads; 7132292SN/A} 7142292SN/A 7152292SN/Atemplate <class Impl> 7162292SN/Avoid 7172292SN/ALSQUnit<Impl>::commitLoads(InstSeqNum &youngest_inst) 7182292SN/A{ 7192292SN/A assert(loads == 0 || loadQueue[loadHead]); 7202292SN/A 7212292SN/A while (loads != 0 && loadQueue[loadHead]->seqNum <= youngest_inst) { 7222292SN/A commitLoad(); 7232292SN/A } 7242292SN/A} 7252292SN/A 7262292SN/Atemplate <class Impl> 7272292SN/Avoid 7282292SN/ALSQUnit<Impl>::commitStores(InstSeqNum &youngest_inst) 7292292SN/A{ 7302292SN/A assert(stores == 0 || storeQueue[storeHead].inst); 7312292SN/A 7322292SN/A int store_idx = storeHead; 7332292SN/A 7342292SN/A while (store_idx != storeTail) { 7352292SN/A assert(storeQueue[store_idx].inst); 7362329SN/A // Mark any stores that are now committed and have not yet 7372329SN/A // been marked as able to write back. 7382292SN/A if (!storeQueue[store_idx].canWB) { 7392292SN/A if (storeQueue[store_idx].inst->seqNum > youngest_inst) { 7402292SN/A break; 7412292SN/A } 7422292SN/A DPRINTF(LSQUnit, "Marking store as able to write back, PC " 7437720Sgblack@eecs.umich.edu "%s [sn:%lli]\n", 7447720Sgblack@eecs.umich.edu storeQueue[store_idx].inst->pcState(), 7452292SN/A storeQueue[store_idx].inst->seqNum); 7462292SN/A 7472292SN/A storeQueue[store_idx].canWB = true; 7482292SN/A 7492292SN/A ++storesToWB; 7502292SN/A } 7512292SN/A 7522292SN/A incrStIdx(store_idx); 7532292SN/A } 7542292SN/A} 7552292SN/A 7562292SN/Atemplate <class Impl> 7572292SN/Avoid 7586974Stjones1@inf.ed.ac.ukLSQUnit<Impl>::writebackPendingStore() 7596974Stjones1@inf.ed.ac.uk{ 7606974Stjones1@inf.ed.ac.uk if (hasPendingPkt) { 7616974Stjones1@inf.ed.ac.uk assert(pendingPkt != NULL); 7626974Stjones1@inf.ed.ac.uk 7636974Stjones1@inf.ed.ac.uk // If the cache is blocked, this will store the packet for retry. 7646974Stjones1@inf.ed.ac.uk if (sendStore(pendingPkt)) { 7656974Stjones1@inf.ed.ac.uk storePostSend(pendingPkt); 7666974Stjones1@inf.ed.ac.uk } 7676974Stjones1@inf.ed.ac.uk pendingPkt = NULL; 7686974Stjones1@inf.ed.ac.uk hasPendingPkt = false; 7696974Stjones1@inf.ed.ac.uk } 7706974Stjones1@inf.ed.ac.uk} 7716974Stjones1@inf.ed.ac.uk 7726974Stjones1@inf.ed.ac.uktemplate <class Impl> 7736974Stjones1@inf.ed.ac.ukvoid 7742292SN/ALSQUnit<Impl>::writebackStores() 7752292SN/A{ 7766974Stjones1@inf.ed.ac.uk // First writeback the second packet from any split store that didn't 7776974Stjones1@inf.ed.ac.uk // complete last cycle because there weren't enough cache ports available. 7786974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc) { 7796974Stjones1@inf.ed.ac.uk writebackPendingStore(); 7806974Stjones1@inf.ed.ac.uk } 7816974Stjones1@inf.ed.ac.uk 7822292SN/A while (storesToWB > 0 && 7832292SN/A storeWBIdx != storeTail && 7842292SN/A storeQueue[storeWBIdx].inst && 7852292SN/A storeQueue[storeWBIdx].canWB && 7868727Snilay@cs.wisc.edu ((!needsTSO) || (!storeInFlight)) && 7872292SN/A usedPorts < cachePorts) { 7882292SN/A 78910333Smitch.hayenga@arm.com if (isStoreBlocked) { 7902678Sktlim@umich.edu DPRINTF(LSQUnit, "Unable to write back any more stores, cache" 7912678Sktlim@umich.edu " is blocked!\n"); 7922678Sktlim@umich.edu break; 7932678Sktlim@umich.edu } 7942678Sktlim@umich.edu 7952329SN/A // Store didn't write any data so no need to write it back to 7962329SN/A // memory. 7972292SN/A if (storeQueue[storeWBIdx].size == 0) { 7982292SN/A completeStore(storeWBIdx); 7992292SN/A 8002292SN/A incrStIdx(storeWBIdx); 8012292SN/A 8022292SN/A continue; 8032292SN/A } 8042678Sktlim@umich.edu 8052292SN/A ++usedPorts; 8062292SN/A 8072292SN/A if (storeQueue[storeWBIdx].inst->isDataPrefetch()) { 8082292SN/A incrStIdx(storeWBIdx); 8092292SN/A 8102292SN/A continue; 8112292SN/A } 8122292SN/A 8132292SN/A assert(storeQueue[storeWBIdx].req); 8142292SN/A assert(!storeQueue[storeWBIdx].committed); 8152292SN/A 8166974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && storeQueue[storeWBIdx].isSplit) { 8176974Stjones1@inf.ed.ac.uk assert(storeQueue[storeWBIdx].sreqLow); 8186974Stjones1@inf.ed.ac.uk assert(storeQueue[storeWBIdx].sreqHigh); 8196974Stjones1@inf.ed.ac.uk } 8206974Stjones1@inf.ed.ac.uk 8212669Sktlim@umich.edu DynInstPtr inst = storeQueue[storeWBIdx].inst; 8222669Sktlim@umich.edu 8232669Sktlim@umich.edu Request *req = storeQueue[storeWBIdx].req; 8248481Sgblack@eecs.umich.edu RequestPtr sreqLow = storeQueue[storeWBIdx].sreqLow; 8258481Sgblack@eecs.umich.edu RequestPtr sreqHigh = storeQueue[storeWBIdx].sreqHigh; 8268481Sgblack@eecs.umich.edu 8272292SN/A storeQueue[storeWBIdx].committed = true; 8282292SN/A 8292669Sktlim@umich.edu assert(!inst->memData); 83010031SAli.Saidi@ARM.com inst->memData = new uint8_t[req->getSize()]; 8313772Sgblack@eecs.umich.edu 83210031SAli.Saidi@ARM.com if (storeQueue[storeWBIdx].isAllZeros) 83310031SAli.Saidi@ARM.com memset(inst->memData, 0, req->getSize()); 83410031SAli.Saidi@ARM.com else 83510031SAli.Saidi@ARM.com memcpy(inst->memData, storeQueue[storeWBIdx].data, req->getSize()); 8362669Sktlim@umich.edu 8376974Stjones1@inf.ed.ac.uk PacketPtr data_pkt; 8386974Stjones1@inf.ed.ac.uk PacketPtr snd_data_pkt = NULL; 8392292SN/A 8402678Sktlim@umich.edu LSQSenderState *state = new LSQSenderState; 8412678Sktlim@umich.edu state->isLoad = false; 8422678Sktlim@umich.edu state->idx = storeWBIdx; 8432678Sktlim@umich.edu state->inst = inst; 8446974Stjones1@inf.ed.ac.uk 8456974Stjones1@inf.ed.ac.uk if (!TheISA::HasUnalignedMemAcc || !storeQueue[storeWBIdx].isSplit) { 8466974Stjones1@inf.ed.ac.uk 8476974Stjones1@inf.ed.ac.uk // Build a single data packet if the store isn't split. 84810342SCurtis.Dunham@arm.com data_pkt = Packet::createWrite(req); 8496974Stjones1@inf.ed.ac.uk data_pkt->dataStatic(inst->memData); 8506974Stjones1@inf.ed.ac.uk data_pkt->senderState = state; 8516974Stjones1@inf.ed.ac.uk } else { 8526974Stjones1@inf.ed.ac.uk // Create two packets if the store is split in two. 85310342SCurtis.Dunham@arm.com data_pkt = Packet::createWrite(sreqLow); 85410342SCurtis.Dunham@arm.com snd_data_pkt = Packet::createWrite(sreqHigh); 8556974Stjones1@inf.ed.ac.uk 8566974Stjones1@inf.ed.ac.uk data_pkt->dataStatic(inst->memData); 8576974Stjones1@inf.ed.ac.uk snd_data_pkt->dataStatic(inst->memData + sreqLow->getSize()); 8586974Stjones1@inf.ed.ac.uk 8596974Stjones1@inf.ed.ac.uk data_pkt->senderState = state; 8606974Stjones1@inf.ed.ac.uk snd_data_pkt->senderState = state; 8616974Stjones1@inf.ed.ac.uk 8626974Stjones1@inf.ed.ac.uk state->isSplit = true; 8636974Stjones1@inf.ed.ac.uk state->outstanding = 2; 8646974Stjones1@inf.ed.ac.uk 8656974Stjones1@inf.ed.ac.uk // Can delete the main request now. 8666974Stjones1@inf.ed.ac.uk delete req; 8676974Stjones1@inf.ed.ac.uk req = sreqLow; 8686974Stjones1@inf.ed.ac.uk } 8692678Sktlim@umich.edu 8707720Sgblack@eecs.umich.edu DPRINTF(LSQUnit, "D-Cache: Writing back store idx:%i PC:%s " 8712292SN/A "to Addr:%#x, data:%#x [sn:%lli]\n", 8727720Sgblack@eecs.umich.edu storeWBIdx, inst->pcState(), 8733797Sgblack@eecs.umich.edu req->getPaddr(), (int)*(inst->memData), 8743221Sktlim@umich.edu inst->seqNum); 8752292SN/A 8762693Sktlim@umich.edu // @todo: Remove this SC hack once the memory system handles it. 8774350Sgblack@eecs.umich.edu if (inst->isStoreConditional()) { 8786974Stjones1@inf.ed.ac.uk assert(!storeQueue[storeWBIdx].isSplit); 8793326Sktlim@umich.edu // Disable recording the result temporarily. Writing to 8803326Sktlim@umich.edu // misc regs normally updates the result, but this is not 8813326Sktlim@umich.edu // the desired behavior when handling store conditionals. 8829046SAli.Saidi@ARM.com inst->recordResult(false); 88310030SAli.Saidi@ARM.com bool success = TheISA::handleLockedWrite(inst.get(), req, cacheBlockMask); 8849046SAli.Saidi@ARM.com inst->recordResult(true); 8853326Sktlim@umich.edu 8863326Sktlim@umich.edu if (!success) { 8873326Sktlim@umich.edu // Instantly complete this store. 8883326Sktlim@umich.edu DPRINTF(LSQUnit, "Store conditional [sn:%lli] failed. " 8893326Sktlim@umich.edu "Instantly completing it.\n", 8903326Sktlim@umich.edu inst->seqNum); 8913326Sktlim@umich.edu WritebackEvent *wb = new WritebackEvent(inst, data_pkt, this); 8927823Ssteve.reinhardt@amd.com cpu->schedule(wb, curTick() + 1); 8938887Sgeoffrey.blake@arm.com if (cpu->checker) { 8948887Sgeoffrey.blake@arm.com // Make sure to set the LLSC data for verification 8958887Sgeoffrey.blake@arm.com // if checker is loaded 8968887Sgeoffrey.blake@arm.com inst->reqToVerify->setExtraData(0); 8978887Sgeoffrey.blake@arm.com inst->completeAcc(data_pkt); 8988887Sgeoffrey.blake@arm.com } 8993326Sktlim@umich.edu completeStore(storeWBIdx); 9003326Sktlim@umich.edu incrStIdx(storeWBIdx); 9013326Sktlim@umich.edu continue; 9022693Sktlim@umich.edu } 9032693Sktlim@umich.edu } else { 9042693Sktlim@umich.edu // Non-store conditionals do not need a writeback. 9052693Sktlim@umich.edu state->noWB = true; 9062693Sktlim@umich.edu } 9072693Sktlim@umich.edu 9088481Sgblack@eecs.umich.edu bool split = 9098481Sgblack@eecs.umich.edu TheISA::HasUnalignedMemAcc && storeQueue[storeWBIdx].isSplit; 9108481Sgblack@eecs.umich.edu 9118481Sgblack@eecs.umich.edu ThreadContext *thread = cpu->tcBase(lsqID); 9128481Sgblack@eecs.umich.edu 9138481Sgblack@eecs.umich.edu if (req->isMmappedIpr()) { 9148481Sgblack@eecs.umich.edu assert(!inst->isStoreConditional()); 9158481Sgblack@eecs.umich.edu TheISA::handleIprWrite(thread, data_pkt); 9168481Sgblack@eecs.umich.edu delete data_pkt; 9178481Sgblack@eecs.umich.edu if (split) { 9188481Sgblack@eecs.umich.edu assert(snd_data_pkt->req->isMmappedIpr()); 9198481Sgblack@eecs.umich.edu TheISA::handleIprWrite(thread, snd_data_pkt); 9208481Sgblack@eecs.umich.edu delete snd_data_pkt; 9218481Sgblack@eecs.umich.edu delete sreqLow; 9228481Sgblack@eecs.umich.edu delete sreqHigh; 9238481Sgblack@eecs.umich.edu } 9248481Sgblack@eecs.umich.edu delete state; 9258481Sgblack@eecs.umich.edu delete req; 9268481Sgblack@eecs.umich.edu completeStore(storeWBIdx); 9278481Sgblack@eecs.umich.edu incrStIdx(storeWBIdx); 9288481Sgblack@eecs.umich.edu } else if (!sendStore(data_pkt)) { 9294032Sktlim@umich.edu DPRINTF(IEW, "D-Cache became blocked when writing [sn:%lli], will" 9303221Sktlim@umich.edu "retry later\n", 9313221Sktlim@umich.edu inst->seqNum); 9326974Stjones1@inf.ed.ac.uk 9336974Stjones1@inf.ed.ac.uk // Need to store the second packet, if split. 9348481Sgblack@eecs.umich.edu if (split) { 9356974Stjones1@inf.ed.ac.uk state->pktToSend = true; 9366974Stjones1@inf.ed.ac.uk state->pendingPacket = snd_data_pkt; 9376974Stjones1@inf.ed.ac.uk } 9382669Sktlim@umich.edu } else { 9396974Stjones1@inf.ed.ac.uk 9406974Stjones1@inf.ed.ac.uk // If split, try to send the second packet too 9418481Sgblack@eecs.umich.edu if (split) { 9426974Stjones1@inf.ed.ac.uk assert(snd_data_pkt); 9436974Stjones1@inf.ed.ac.uk 9446974Stjones1@inf.ed.ac.uk // Ensure there are enough ports to use. 9456974Stjones1@inf.ed.ac.uk if (usedPorts < cachePorts) { 9466974Stjones1@inf.ed.ac.uk ++usedPorts; 9476974Stjones1@inf.ed.ac.uk if (sendStore(snd_data_pkt)) { 9486974Stjones1@inf.ed.ac.uk storePostSend(snd_data_pkt); 9496974Stjones1@inf.ed.ac.uk } else { 9506974Stjones1@inf.ed.ac.uk DPRINTF(IEW, "D-Cache became blocked when writing" 9516974Stjones1@inf.ed.ac.uk " [sn:%lli] second packet, will retry later\n", 9526974Stjones1@inf.ed.ac.uk inst->seqNum); 9536974Stjones1@inf.ed.ac.uk } 9546974Stjones1@inf.ed.ac.uk } else { 9556974Stjones1@inf.ed.ac.uk 9566974Stjones1@inf.ed.ac.uk // Store the packet for when there's free ports. 9576974Stjones1@inf.ed.ac.uk assert(pendingPkt == NULL); 9586974Stjones1@inf.ed.ac.uk pendingPkt = snd_data_pkt; 9596974Stjones1@inf.ed.ac.uk hasPendingPkt = true; 9606974Stjones1@inf.ed.ac.uk } 9616974Stjones1@inf.ed.ac.uk } else { 9626974Stjones1@inf.ed.ac.uk 9636974Stjones1@inf.ed.ac.uk // Not a split store. 9646974Stjones1@inf.ed.ac.uk storePostSend(data_pkt); 9656974Stjones1@inf.ed.ac.uk } 9662292SN/A } 9672292SN/A } 9682292SN/A 9692292SN/A // Not sure this should set it to 0. 9702292SN/A usedPorts = 0; 9712292SN/A 9722292SN/A assert(stores >= 0 && storesToWB >= 0); 9732292SN/A} 9742292SN/A 9752292SN/A/*template <class Impl> 9762292SN/Avoid 9772292SN/ALSQUnit<Impl>::removeMSHR(InstSeqNum seqNum) 9782292SN/A{ 9792292SN/A list<InstSeqNum>::iterator mshr_it = find(mshrSeqNums.begin(), 9802292SN/A mshrSeqNums.end(), 9812292SN/A seqNum); 9822292SN/A 9832292SN/A if (mshr_it != mshrSeqNums.end()) { 9842292SN/A mshrSeqNums.erase(mshr_it); 9852292SN/A DPRINTF(LSQUnit, "Removing MSHR. count = %i\n",mshrSeqNums.size()); 9862292SN/A } 9872292SN/A}*/ 9882292SN/A 9892292SN/Atemplate <class Impl> 9902292SN/Avoid 9912292SN/ALSQUnit<Impl>::squash(const InstSeqNum &squashed_num) 9922292SN/A{ 9932292SN/A DPRINTF(LSQUnit, "Squashing until [sn:%lli]!" 9942329SN/A "(Loads:%i Stores:%i)\n", squashed_num, loads, stores); 9952292SN/A 9962292SN/A int load_idx = loadTail; 9972292SN/A decrLdIdx(load_idx); 9982292SN/A 9992292SN/A while (loads != 0 && loadQueue[load_idx]->seqNum > squashed_num) { 10007720Sgblack@eecs.umich.edu DPRINTF(LSQUnit,"Load Instruction PC %s squashed, " 10012292SN/A "[sn:%lli]\n", 10027720Sgblack@eecs.umich.edu loadQueue[load_idx]->pcState(), 10032292SN/A loadQueue[load_idx]->seqNum); 10042292SN/A 10052292SN/A if (isStalled() && load_idx == stallingLoadIdx) { 10062292SN/A stalled = false; 10072292SN/A stallingStoreIsn = 0; 10082292SN/A stallingLoadIdx = 0; 10092292SN/A } 10102292SN/A 10112329SN/A // Clear the smart pointer to make sure it is decremented. 10122731Sktlim@umich.edu loadQueue[load_idx]->setSquashed(); 10132292SN/A loadQueue[load_idx] = NULL; 10142292SN/A --loads; 10152292SN/A 10162292SN/A // Inefficient! 10172292SN/A loadTail = load_idx; 10182292SN/A 10192292SN/A decrLdIdx(load_idx); 10202727Sktlim@umich.edu ++lsqSquashedLoads; 10212292SN/A } 10222292SN/A 10234032Sktlim@umich.edu if (memDepViolator && squashed_num < memDepViolator->seqNum) { 10244032Sktlim@umich.edu memDepViolator = NULL; 10254032Sktlim@umich.edu } 10264032Sktlim@umich.edu 10272292SN/A int store_idx = storeTail; 10282292SN/A decrStIdx(store_idx); 10292292SN/A 10302292SN/A while (stores != 0 && 10312292SN/A storeQueue[store_idx].inst->seqNum > squashed_num) { 10322329SN/A // Instructions marked as can WB are already committed. 10332292SN/A if (storeQueue[store_idx].canWB) { 10342292SN/A break; 10352292SN/A } 10362292SN/A 10377720Sgblack@eecs.umich.edu DPRINTF(LSQUnit,"Store Instruction PC %s squashed, " 10382292SN/A "idx:%i [sn:%lli]\n", 10397720Sgblack@eecs.umich.edu storeQueue[store_idx].inst->pcState(), 10402292SN/A store_idx, storeQueue[store_idx].inst->seqNum); 10412292SN/A 10422329SN/A // I don't think this can happen. It should have been cleared 10432329SN/A // by the stalling load. 10442292SN/A if (isStalled() && 10452292SN/A storeQueue[store_idx].inst->seqNum == stallingStoreIsn) { 10462292SN/A panic("Is stalled should have been cleared by stalling load!\n"); 10472292SN/A stalled = false; 10482292SN/A stallingStoreIsn = 0; 10492292SN/A } 10502292SN/A 10512329SN/A // Clear the smart pointer to make sure it is decremented. 10522731Sktlim@umich.edu storeQueue[store_idx].inst->setSquashed(); 10532292SN/A storeQueue[store_idx].inst = NULL; 10542292SN/A storeQueue[store_idx].canWB = 0; 10552292SN/A 10564032Sktlim@umich.edu // Must delete request now that it wasn't handed off to 10574032Sktlim@umich.edu // memory. This is quite ugly. @todo: Figure out the proper 10584032Sktlim@umich.edu // place to really handle request deletes. 10594032Sktlim@umich.edu delete storeQueue[store_idx].req; 10606974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && storeQueue[store_idx].isSplit) { 10616974Stjones1@inf.ed.ac.uk delete storeQueue[store_idx].sreqLow; 10626974Stjones1@inf.ed.ac.uk delete storeQueue[store_idx].sreqHigh; 10636974Stjones1@inf.ed.ac.uk 10646974Stjones1@inf.ed.ac.uk storeQueue[store_idx].sreqLow = NULL; 10656974Stjones1@inf.ed.ac.uk storeQueue[store_idx].sreqHigh = NULL; 10666974Stjones1@inf.ed.ac.uk } 10674032Sktlim@umich.edu 10682292SN/A storeQueue[store_idx].req = NULL; 10692292SN/A --stores; 10702292SN/A 10712292SN/A // Inefficient! 10722292SN/A storeTail = store_idx; 10732292SN/A 10742292SN/A decrStIdx(store_idx); 10752727Sktlim@umich.edu ++lsqSquashedStores; 10762292SN/A } 10772292SN/A} 10782292SN/A 10792292SN/Atemplate <class Impl> 10802292SN/Avoid 10813349Sbinkertn@umich.eduLSQUnit<Impl>::storePostSend(PacketPtr pkt) 10822693Sktlim@umich.edu{ 10832693Sktlim@umich.edu if (isStalled() && 10842693Sktlim@umich.edu storeQueue[storeWBIdx].inst->seqNum == stallingStoreIsn) { 10852693Sktlim@umich.edu DPRINTF(LSQUnit, "Unstalling, stalling store [sn:%lli] " 10862693Sktlim@umich.edu "load idx:%i\n", 10872693Sktlim@umich.edu stallingStoreIsn, stallingLoadIdx); 10882693Sktlim@umich.edu stalled = false; 10892693Sktlim@umich.edu stallingStoreIsn = 0; 10902693Sktlim@umich.edu iewStage->replayMemInst(loadQueue[stallingLoadIdx]); 10912693Sktlim@umich.edu } 10922693Sktlim@umich.edu 10932693Sktlim@umich.edu if (!storeQueue[storeWBIdx].inst->isStoreConditional()) { 10942693Sktlim@umich.edu // The store is basically completed at this time. This 10952693Sktlim@umich.edu // only works so long as the checker doesn't try to 10962693Sktlim@umich.edu // verify the value in memory for stores. 10972693Sktlim@umich.edu storeQueue[storeWBIdx].inst->setCompleted(); 10988887Sgeoffrey.blake@arm.com 10992693Sktlim@umich.edu if (cpu->checker) { 11002732Sktlim@umich.edu cpu->checker->verify(storeQueue[storeWBIdx].inst); 11012693Sktlim@umich.edu } 11022693Sktlim@umich.edu } 11032693Sktlim@umich.edu 11048727Snilay@cs.wisc.edu if (needsTSO) { 11058727Snilay@cs.wisc.edu storeInFlight = true; 11068727Snilay@cs.wisc.edu } 11078727Snilay@cs.wisc.edu 11082693Sktlim@umich.edu incrStIdx(storeWBIdx); 11092693Sktlim@umich.edu} 11102693Sktlim@umich.edu 11112693Sktlim@umich.edutemplate <class Impl> 11122693Sktlim@umich.eduvoid 11132678Sktlim@umich.eduLSQUnit<Impl>::writeback(DynInstPtr &inst, PacketPtr pkt) 11142678Sktlim@umich.edu{ 11152678Sktlim@umich.edu iewStage->wakeCPU(); 11162678Sktlim@umich.edu 11172678Sktlim@umich.edu // Squashed instructions do not need to complete their access. 11182678Sktlim@umich.edu if (inst->isSquashed()) { 11192678Sktlim@umich.edu assert(!inst->isStore()); 11202727Sktlim@umich.edu ++lsqIgnoredResponses; 11212678Sktlim@umich.edu return; 11222678Sktlim@umich.edu } 11232678Sktlim@umich.edu 11242678Sktlim@umich.edu if (!inst->isExecuted()) { 11252678Sktlim@umich.edu inst->setExecuted(); 11262678Sktlim@umich.edu 112710575SMarco.Elver@ARM.com if (inst->fault == NoFault) { 112810575SMarco.Elver@ARM.com // Complete access to copy data to proper place. 112910575SMarco.Elver@ARM.com inst->completeAcc(pkt); 113010575SMarco.Elver@ARM.com } else { 113110575SMarco.Elver@ARM.com // If the instruction has an outstanding fault, we cannot complete 113210575SMarco.Elver@ARM.com // the access as this discards the current fault. 113310575SMarco.Elver@ARM.com 113410575SMarco.Elver@ARM.com // If we have an outstanding fault, the fault should only be of 113510575SMarco.Elver@ARM.com // type ReExec. 113610575SMarco.Elver@ARM.com assert(dynamic_cast<ReExec*>(inst->fault.get()) != nullptr); 113710575SMarco.Elver@ARM.com 113810575SMarco.Elver@ARM.com DPRINTF(LSQUnit, "Not completing instruction [sn:%lli] access " 113910575SMarco.Elver@ARM.com "due to pending fault.\n", inst->seqNum); 114010575SMarco.Elver@ARM.com } 11412678Sktlim@umich.edu } 11422678Sktlim@umich.edu 11432678Sktlim@umich.edu // Need to insert instruction into queue to commit 11442678Sktlim@umich.edu iewStage->instToCommit(inst); 11452678Sktlim@umich.edu 11462678Sktlim@umich.edu iewStage->activityThisCycle(); 11477598Sminkyu.jeong@arm.com 11487598Sminkyu.jeong@arm.com // see if this load changed the PC 11497598Sminkyu.jeong@arm.com iewStage->checkMisprediction(inst); 11502678Sktlim@umich.edu} 11512678Sktlim@umich.edu 11522678Sktlim@umich.edutemplate <class Impl> 11532678Sktlim@umich.eduvoid 11542292SN/ALSQUnit<Impl>::completeStore(int store_idx) 11552292SN/A{ 11562292SN/A assert(storeQueue[store_idx].inst); 11572292SN/A storeQueue[store_idx].completed = true; 11582292SN/A --storesToWB; 11592292SN/A // A bit conservative because a store completion may not free up entries, 11602292SN/A // but hopefully avoids two store completions in one cycle from making 11612292SN/A // the CPU tick twice. 11623126Sktlim@umich.edu cpu->wakeCPU(); 11632292SN/A cpu->activityThisCycle(); 11642292SN/A 11652292SN/A if (store_idx == storeHead) { 11662292SN/A do { 11672292SN/A incrStIdx(storeHead); 11682292SN/A 11692292SN/A --stores; 11702292SN/A } while (storeQueue[storeHead].completed && 11712292SN/A storeHead != storeTail); 11722292SN/A 11732292SN/A iewStage->updateLSQNextCycle = true; 11742292SN/A } 11752292SN/A 11762329SN/A DPRINTF(LSQUnit, "Completing store [sn:%lli], idx:%i, store head " 11772329SN/A "idx:%i\n", 11782329SN/A storeQueue[store_idx].inst->seqNum, store_idx, storeHead); 11792292SN/A 11809527SMatt.Horsnell@arm.com#if TRACING_ON 11819527SMatt.Horsnell@arm.com if (DTRACE(O3PipeView)) { 11829527SMatt.Horsnell@arm.com storeQueue[store_idx].inst->storeTick = 11839527SMatt.Horsnell@arm.com curTick() - storeQueue[store_idx].inst->fetchTick; 11849527SMatt.Horsnell@arm.com } 11859527SMatt.Horsnell@arm.com#endif 11869527SMatt.Horsnell@arm.com 11872292SN/A if (isStalled() && 11882292SN/A storeQueue[store_idx].inst->seqNum == stallingStoreIsn) { 11892292SN/A DPRINTF(LSQUnit, "Unstalling, stalling store [sn:%lli] " 11902292SN/A "load idx:%i\n", 11912292SN/A stallingStoreIsn, stallingLoadIdx); 11922292SN/A stalled = false; 11932292SN/A stallingStoreIsn = 0; 11942292SN/A iewStage->replayMemInst(loadQueue[stallingLoadIdx]); 11952292SN/A } 11962316SN/A 11972316SN/A storeQueue[store_idx].inst->setCompleted(); 11982329SN/A 11998727Snilay@cs.wisc.edu if (needsTSO) { 12008727Snilay@cs.wisc.edu storeInFlight = false; 12018727Snilay@cs.wisc.edu } 12028727Snilay@cs.wisc.edu 12032329SN/A // Tell the checker we've completed this instruction. Some stores 12042329SN/A // may get reported twice to the checker, but the checker can 12052329SN/A // handle that case. 12062316SN/A if (cpu->checker) { 12072732Sktlim@umich.edu cpu->checker->verify(storeQueue[store_idx].inst); 12082316SN/A } 12092292SN/A} 12102292SN/A 12112292SN/Atemplate <class Impl> 12126974Stjones1@inf.ed.ac.ukbool 12136974Stjones1@inf.ed.ac.ukLSQUnit<Impl>::sendStore(PacketPtr data_pkt) 12146974Stjones1@inf.ed.ac.uk{ 12158975Sandreas.hansson@arm.com if (!dcachePort->sendTimingReq(data_pkt)) { 12166974Stjones1@inf.ed.ac.uk // Need to handle becoming blocked on a store. 12176974Stjones1@inf.ed.ac.uk isStoreBlocked = true; 12186974Stjones1@inf.ed.ac.uk ++lsqCacheBlocked; 12196974Stjones1@inf.ed.ac.uk assert(retryPkt == NULL); 12206974Stjones1@inf.ed.ac.uk retryPkt = data_pkt; 12216974Stjones1@inf.ed.ac.uk return false; 12226974Stjones1@inf.ed.ac.uk } 12236974Stjones1@inf.ed.ac.uk return true; 12246974Stjones1@inf.ed.ac.uk} 12256974Stjones1@inf.ed.ac.uk 12266974Stjones1@inf.ed.ac.uktemplate <class Impl> 12272693Sktlim@umich.eduvoid 12282693Sktlim@umich.eduLSQUnit<Impl>::recvRetry() 12292693Sktlim@umich.edu{ 12302698Sktlim@umich.edu if (isStoreBlocked) { 12314985Sktlim@umich.edu DPRINTF(LSQUnit, "Receiving retry: store blocked\n"); 12322698Sktlim@umich.edu assert(retryPkt != NULL); 12332693Sktlim@umich.edu 12348587Snilay@cs.wisc.edu LSQSenderState *state = 12358587Snilay@cs.wisc.edu dynamic_cast<LSQSenderState *>(retryPkt->senderState); 12368587Snilay@cs.wisc.edu 12378975Sandreas.hansson@arm.com if (dcachePort->sendTimingReq(retryPkt)) { 12386974Stjones1@inf.ed.ac.uk // Don't finish the store unless this is the last packet. 12398133SAli.Saidi@ARM.com if (!TheISA::HasUnalignedMemAcc || !state->pktToSend || 12408133SAli.Saidi@ARM.com state->pendingPacket == retryPkt) { 12418133SAli.Saidi@ARM.com state->pktToSend = false; 12426974Stjones1@inf.ed.ac.uk storePostSend(retryPkt); 12436974Stjones1@inf.ed.ac.uk } 12442699Sktlim@umich.edu retryPkt = NULL; 12452693Sktlim@umich.edu isStoreBlocked = false; 12466974Stjones1@inf.ed.ac.uk 12476974Stjones1@inf.ed.ac.uk // Send any outstanding packet. 12486974Stjones1@inf.ed.ac.uk if (TheISA::HasUnalignedMemAcc && state->pktToSend) { 12496974Stjones1@inf.ed.ac.uk assert(state->pendingPacket); 12506974Stjones1@inf.ed.ac.uk if (sendStore(state->pendingPacket)) { 12516974Stjones1@inf.ed.ac.uk storePostSend(state->pendingPacket); 12526974Stjones1@inf.ed.ac.uk } 12536974Stjones1@inf.ed.ac.uk } 12542693Sktlim@umich.edu } else { 12552693Sktlim@umich.edu // Still blocked! 12562727Sktlim@umich.edu ++lsqCacheBlocked; 12572693Sktlim@umich.edu } 12582693Sktlim@umich.edu } 12592693Sktlim@umich.edu} 12602693Sktlim@umich.edu 12612693Sktlim@umich.edutemplate <class Impl> 12622292SN/Ainline void 12639440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::incrStIdx(int &store_idx) const 12642292SN/A{ 12652292SN/A if (++store_idx >= SQEntries) 12662292SN/A store_idx = 0; 12672292SN/A} 12682292SN/A 12692292SN/Atemplate <class Impl> 12702292SN/Ainline void 12719440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::decrStIdx(int &store_idx) const 12722292SN/A{ 12732292SN/A if (--store_idx < 0) 12742292SN/A store_idx += SQEntries; 12752292SN/A} 12762292SN/A 12772292SN/Atemplate <class Impl> 12782292SN/Ainline void 12799440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::incrLdIdx(int &load_idx) const 12802292SN/A{ 12812292SN/A if (++load_idx >= LQEntries) 12822292SN/A load_idx = 0; 12832292SN/A} 12842292SN/A 12852292SN/Atemplate <class Impl> 12862292SN/Ainline void 12879440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::decrLdIdx(int &load_idx) const 12882292SN/A{ 12892292SN/A if (--load_idx < 0) 12902292SN/A load_idx += LQEntries; 12912292SN/A} 12922329SN/A 12932329SN/Atemplate <class Impl> 12942329SN/Avoid 12959440SAndreas.Sandberg@ARM.comLSQUnit<Impl>::dumpInsts() const 12962329SN/A{ 12972329SN/A cprintf("Load store queue: Dumping instructions.\n"); 12982329SN/A cprintf("Load queue size: %i\n", loads); 12992329SN/A cprintf("Load queue: "); 13002329SN/A 13012329SN/A int load_idx = loadHead; 13022329SN/A 13032329SN/A while (load_idx != loadTail && loadQueue[load_idx]) { 13049440SAndreas.Sandberg@ARM.com const DynInstPtr &inst(loadQueue[load_idx]); 13059440SAndreas.Sandberg@ARM.com cprintf("%s.[sn:%i] ", inst->pcState(), inst->seqNum); 13062329SN/A 13072329SN/A incrLdIdx(load_idx); 13082329SN/A } 13099440SAndreas.Sandberg@ARM.com cprintf("\n"); 13102329SN/A 13112329SN/A cprintf("Store queue size: %i\n", stores); 13122329SN/A cprintf("Store queue: "); 13132329SN/A 13142329SN/A int store_idx = storeHead; 13152329SN/A 13162329SN/A while (store_idx != storeTail && storeQueue[store_idx].inst) { 13179440SAndreas.Sandberg@ARM.com const DynInstPtr &inst(storeQueue[store_idx].inst); 13189440SAndreas.Sandberg@ARM.com cprintf("%s.[sn:%i] ", inst->pcState(), inst->seqNum); 13192329SN/A 13202329SN/A incrStIdx(store_idx); 13212329SN/A } 13222329SN/A 13232329SN/A cprintf("\n"); 13242329SN/A} 13259944Smatt.horsnell@ARM.com 13269944Smatt.horsnell@ARM.com#endif//__CPU_O3_LSQ_UNIT_IMPL_HH__ 1327