cache_blk.hh revision 13445
113223Sodanrc@yahoo.com.br/* 213223Sodanrc@yahoo.com.br * Copyright (c) 2012-2018 ARM Limited 313223Sodanrc@yahoo.com.br * All rights reserved. 413223Sodanrc@yahoo.com.br * 513223Sodanrc@yahoo.com.br * The license below extends only to copyright in the software and shall 613223Sodanrc@yahoo.com.br * not be construed as granting a license to any other intellectual 713223Sodanrc@yahoo.com.br * property including but not limited to intellectual property relating 813223Sodanrc@yahoo.com.br * to a hardware implementation of the functionality of the software 913223Sodanrc@yahoo.com.br * licensed hereunder. You may use the software subject to the license 1013223Sodanrc@yahoo.com.br * terms below provided that you ensure that this notice is replicated 1113223Sodanrc@yahoo.com.br * unmodified and in its entirety in all distributions of the software, 1213223Sodanrc@yahoo.com.br * modified or unmodified, in source code or in binary form. 1313223Sodanrc@yahoo.com.br * 1413223Sodanrc@yahoo.com.br * Copyright (c) 2003-2005 The Regents of The University of Michigan 1513223Sodanrc@yahoo.com.br * All rights reserved. 1613223Sodanrc@yahoo.com.br * 1713223Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 1813223Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 1913223Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 2013223Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 2113223Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 2213223Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 2313223Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 2413223Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 2513223Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 2613223Sodanrc@yahoo.com.br * this software without specific prior written permission. 2713223Sodanrc@yahoo.com.br * 2813223Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2913223Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3013223Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3113223Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3213223Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3313223Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3413223Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3513223Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3613223Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3713223Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3813223Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3913223Sodanrc@yahoo.com.br * 4013223Sodanrc@yahoo.com.br * Authors: Erik Hallnor 4113223Sodanrc@yahoo.com.br * Andreas Sandberg 4213223Sodanrc@yahoo.com.br */ 4313223Sodanrc@yahoo.com.br 4413223Sodanrc@yahoo.com.br/** @file 4513223Sodanrc@yahoo.com.br * Definitions of a simple cache block class. 4613223Sodanrc@yahoo.com.br */ 4713223Sodanrc@yahoo.com.br 4813223Sodanrc@yahoo.com.br#ifndef __MEM_CACHE_CACHE_BLK_HH__ 4913223Sodanrc@yahoo.com.br#define __MEM_CACHE_CACHE_BLK_HH__ 5013223Sodanrc@yahoo.com.br 5113223Sodanrc@yahoo.com.br#include <cassert> 5213223Sodanrc@yahoo.com.br#include <cstdint> 5313223Sodanrc@yahoo.com.br#include <iosfwd> 5413223Sodanrc@yahoo.com.br#include <list> 5513223Sodanrc@yahoo.com.br#include <string> 5613223Sodanrc@yahoo.com.br 5713223Sodanrc@yahoo.com.br#include "base/printable.hh" 5813223Sodanrc@yahoo.com.br#include "base/types.hh" 5913223Sodanrc@yahoo.com.br#include "mem/cache/replacement_policies/base.hh" 6013223Sodanrc@yahoo.com.br#include "mem/packet.hh" 6113223Sodanrc@yahoo.com.br#include "mem/request.hh" 6213223Sodanrc@yahoo.com.br 6313223Sodanrc@yahoo.com.br/** 6413223Sodanrc@yahoo.com.br * Cache block status bit assignments 6513223Sodanrc@yahoo.com.br */ 6613223Sodanrc@yahoo.com.brenum CacheBlkStatusBits : unsigned { 6713223Sodanrc@yahoo.com.br /** valid, readable */ 6813223Sodanrc@yahoo.com.br BlkValid = 0x01, 6913223Sodanrc@yahoo.com.br /** write permission */ 7013223Sodanrc@yahoo.com.br BlkWritable = 0x02, 7113223Sodanrc@yahoo.com.br /** read permission (yes, block can be valid but not readable) */ 7213223Sodanrc@yahoo.com.br BlkReadable = 0x04, 7313223Sodanrc@yahoo.com.br /** dirty (modified) */ 7413223Sodanrc@yahoo.com.br BlkDirty = 0x08, 7513223Sodanrc@yahoo.com.br /** block was a hardware prefetch yet unaccessed*/ 7613223Sodanrc@yahoo.com.br BlkHWPrefetched = 0x20, 7713223Sodanrc@yahoo.com.br /** block holds data from the secure memory space */ 7813223Sodanrc@yahoo.com.br BlkSecure = 0x40, 7913223Sodanrc@yahoo.com.br}; 8013223Sodanrc@yahoo.com.br 8113223Sodanrc@yahoo.com.br/** 8213223Sodanrc@yahoo.com.br * A Basic Cache block. 8313223Sodanrc@yahoo.com.br * Contains the tag, status, and a pointer to data. 8413223Sodanrc@yahoo.com.br */ 8513223Sodanrc@yahoo.com.brclass CacheBlk : public ReplaceableEntry 8613223Sodanrc@yahoo.com.br{ 8713223Sodanrc@yahoo.com.br public: 8813223Sodanrc@yahoo.com.br /** Task Id associated with this block */ 8913223Sodanrc@yahoo.com.br uint32_t task_id; 9013223Sodanrc@yahoo.com.br 9113223Sodanrc@yahoo.com.br /** Data block tag value. */ 9213223Sodanrc@yahoo.com.br Addr tag; 9313223Sodanrc@yahoo.com.br /** 9413223Sodanrc@yahoo.com.br * Contains a copy of the data in this block for easy access. This is used 9513223Sodanrc@yahoo.com.br * for efficient execution when the data could be actually stored in 9613223Sodanrc@yahoo.com.br * another format (COW, compressed, sub-blocked, etc). In all cases the 9713223Sodanrc@yahoo.com.br * data stored here should be kept consistant with the actual data 9813223Sodanrc@yahoo.com.br * referenced by this block. 9913223Sodanrc@yahoo.com.br */ 10013223Sodanrc@yahoo.com.br uint8_t *data; 10113223Sodanrc@yahoo.com.br 10213223Sodanrc@yahoo.com.br /** block state: OR of CacheBlkStatusBit */ 10313223Sodanrc@yahoo.com.br typedef unsigned State; 10413223Sodanrc@yahoo.com.br 10513223Sodanrc@yahoo.com.br /** The current status of this block. @sa CacheBlockStatusBits */ 10613223Sodanrc@yahoo.com.br State status; 10713223Sodanrc@yahoo.com.br 10813223Sodanrc@yahoo.com.br /** Which curTick() will this block be accessible */ 10913223Sodanrc@yahoo.com.br Tick whenReady; 11013223Sodanrc@yahoo.com.br 11113223Sodanrc@yahoo.com.br /** Number of references to this block since it was brought in. */ 11213223Sodanrc@yahoo.com.br unsigned refCount; 11313223Sodanrc@yahoo.com.br 11413223Sodanrc@yahoo.com.br /** holds the source requestor ID for this block. */ 11513223Sodanrc@yahoo.com.br int srcMasterId; 11613223Sodanrc@yahoo.com.br 11713223Sodanrc@yahoo.com.br /** Tick on which the block was inserted in the cache. */ 11813223Sodanrc@yahoo.com.br Tick tickInserted; 11913223Sodanrc@yahoo.com.br 12013223Sodanrc@yahoo.com.br protected: 12113223Sodanrc@yahoo.com.br /** 12213223Sodanrc@yahoo.com.br * Represents that the indicated thread context has a "lock" on 12313223Sodanrc@yahoo.com.br * the block, in the LL/SC sense. 12413223Sodanrc@yahoo.com.br */ 12513223Sodanrc@yahoo.com.br class Lock { 12613223Sodanrc@yahoo.com.br public: 12713223Sodanrc@yahoo.com.br ContextID contextId; // locking context 12813223Sodanrc@yahoo.com.br Addr lowAddr; // low address of lock range 12913223Sodanrc@yahoo.com.br Addr highAddr; // high address of lock range 13013223Sodanrc@yahoo.com.br 13113223Sodanrc@yahoo.com.br // check for matching execution context, and an address that 13213223Sodanrc@yahoo.com.br // is within the lock 13313223Sodanrc@yahoo.com.br bool matches(const RequestPtr &req) const 13413223Sodanrc@yahoo.com.br { 13513223Sodanrc@yahoo.com.br Addr req_low = req->getPaddr(); 13613223Sodanrc@yahoo.com.br Addr req_high = req_low + req->getSize() -1; 13713223Sodanrc@yahoo.com.br return (contextId == req->contextId()) && 13813223Sodanrc@yahoo.com.br (req_low >= lowAddr) && (req_high <= highAddr); 13913223Sodanrc@yahoo.com.br } 14013223Sodanrc@yahoo.com.br 14113223Sodanrc@yahoo.com.br // check if a request is intersecting and thus invalidating the lock 14213223Sodanrc@yahoo.com.br bool intersects(const RequestPtr &req) const 14313223Sodanrc@yahoo.com.br { 14413223Sodanrc@yahoo.com.br Addr req_low = req->getPaddr(); 14513223Sodanrc@yahoo.com.br Addr req_high = req_low + req->getSize() - 1; 14613223Sodanrc@yahoo.com.br 14713223Sodanrc@yahoo.com.br return (req_low <= highAddr) && (req_high >= lowAddr); 14813223Sodanrc@yahoo.com.br } 14913223Sodanrc@yahoo.com.br 15013223Sodanrc@yahoo.com.br Lock(const RequestPtr &req) 15113223Sodanrc@yahoo.com.br : contextId(req->contextId()), 15213223Sodanrc@yahoo.com.br lowAddr(req->getPaddr()), 15313223Sodanrc@yahoo.com.br highAddr(lowAddr + req->getSize() - 1) 15413223Sodanrc@yahoo.com.br { 15513223Sodanrc@yahoo.com.br } 15613223Sodanrc@yahoo.com.br }; 15713223Sodanrc@yahoo.com.br 15813223Sodanrc@yahoo.com.br /** List of thread contexts that have performed a load-locked (LL) 15913223Sodanrc@yahoo.com.br * on the block since the last store. */ 16013223Sodanrc@yahoo.com.br std::list<Lock> lockList; 16113223Sodanrc@yahoo.com.br 16213223Sodanrc@yahoo.com.br public: 16313223Sodanrc@yahoo.com.br CacheBlk() : data(nullptr) 16413223Sodanrc@yahoo.com.br { 16513223Sodanrc@yahoo.com.br invalidate(); 16613223Sodanrc@yahoo.com.br } 16713223Sodanrc@yahoo.com.br 16813223Sodanrc@yahoo.com.br CacheBlk(const CacheBlk&) = delete; 16913223Sodanrc@yahoo.com.br CacheBlk& operator=(const CacheBlk&) = delete; 17013223Sodanrc@yahoo.com.br virtual ~CacheBlk() {}; 17113223Sodanrc@yahoo.com.br 17213223Sodanrc@yahoo.com.br /** 17313223Sodanrc@yahoo.com.br * Checks the write permissions of this block. 17413223Sodanrc@yahoo.com.br * @return True if the block is writable. 17513223Sodanrc@yahoo.com.br */ 17613223Sodanrc@yahoo.com.br bool isWritable() const 17713223Sodanrc@yahoo.com.br { 17813223Sodanrc@yahoo.com.br const State needed_bits = BlkWritable | BlkValid; 17913223Sodanrc@yahoo.com.br return (status & needed_bits) == needed_bits; 18013223Sodanrc@yahoo.com.br } 18113223Sodanrc@yahoo.com.br 18213223Sodanrc@yahoo.com.br /** 18313223Sodanrc@yahoo.com.br * Checks the read permissions of this block. Note that a block 18413223Sodanrc@yahoo.com.br * can be valid but not readable if there is an outstanding write 18513223Sodanrc@yahoo.com.br * upgrade miss. 18613223Sodanrc@yahoo.com.br * @return True if the block is readable. 18713223Sodanrc@yahoo.com.br */ 18813223Sodanrc@yahoo.com.br bool isReadable() const 18913223Sodanrc@yahoo.com.br { 19013223Sodanrc@yahoo.com.br const State needed_bits = BlkReadable | BlkValid; 19113223Sodanrc@yahoo.com.br return (status & needed_bits) == needed_bits; 19213223Sodanrc@yahoo.com.br } 19313223Sodanrc@yahoo.com.br 19413223Sodanrc@yahoo.com.br /** 19513223Sodanrc@yahoo.com.br * Checks that a block is valid. 19613223Sodanrc@yahoo.com.br * @return True if the block is valid. 19713223Sodanrc@yahoo.com.br */ 19813223Sodanrc@yahoo.com.br bool isValid() const 19913223Sodanrc@yahoo.com.br { 20013223Sodanrc@yahoo.com.br return (status & BlkValid) != 0; 20113223Sodanrc@yahoo.com.br } 20213223Sodanrc@yahoo.com.br 20313223Sodanrc@yahoo.com.br /** 20413223Sodanrc@yahoo.com.br * Invalidate the block and clear all state. 20513223Sodanrc@yahoo.com.br */ 20613223Sodanrc@yahoo.com.br virtual void invalidate() 20713223Sodanrc@yahoo.com.br { 20813223Sodanrc@yahoo.com.br tag = MaxAddr; 20913223Sodanrc@yahoo.com.br task_id = ContextSwitchTaskId::Unknown; 21013223Sodanrc@yahoo.com.br status = 0; 21113223Sodanrc@yahoo.com.br whenReady = MaxTick; 21213223Sodanrc@yahoo.com.br refCount = 0; 21313223Sodanrc@yahoo.com.br srcMasterId = Request::invldMasterId; 21413223Sodanrc@yahoo.com.br tickInserted = MaxTick; 21513223Sodanrc@yahoo.com.br lockList.clear(); 21613223Sodanrc@yahoo.com.br } 21713223Sodanrc@yahoo.com.br 21813223Sodanrc@yahoo.com.br /** 21913223Sodanrc@yahoo.com.br * Check to see if a block has been written. 22013223Sodanrc@yahoo.com.br * @return True if the block is dirty. 22113223Sodanrc@yahoo.com.br */ 22213223Sodanrc@yahoo.com.br bool isDirty() const 22313223Sodanrc@yahoo.com.br { 22413223Sodanrc@yahoo.com.br return (status & BlkDirty) != 0; 22513223Sodanrc@yahoo.com.br } 22613223Sodanrc@yahoo.com.br 22713223Sodanrc@yahoo.com.br /** 22813223Sodanrc@yahoo.com.br * Check if this block was the result of a hardware prefetch, yet to 22913223Sodanrc@yahoo.com.br * be touched. 23013223Sodanrc@yahoo.com.br * @return True if the block was a hardware prefetch, unaccesed. 23113223Sodanrc@yahoo.com.br */ 23213223Sodanrc@yahoo.com.br bool wasPrefetched() const 23313223Sodanrc@yahoo.com.br { 23413223Sodanrc@yahoo.com.br return (status & BlkHWPrefetched) != 0; 23513223Sodanrc@yahoo.com.br } 23613223Sodanrc@yahoo.com.br 23713223Sodanrc@yahoo.com.br /** 23813223Sodanrc@yahoo.com.br * Check if this block holds data from the secure memory space. 23913223Sodanrc@yahoo.com.br * @return True if the block holds data from the secure memory space. 24013223Sodanrc@yahoo.com.br */ 24113223Sodanrc@yahoo.com.br bool isSecure() const 24213223Sodanrc@yahoo.com.br { 24313223Sodanrc@yahoo.com.br return (status & BlkSecure) != 0; 24413223Sodanrc@yahoo.com.br } 24513223Sodanrc@yahoo.com.br 24613223Sodanrc@yahoo.com.br /** 24713445Sodanrc@yahoo.com.br * Set valid bit. 24813445Sodanrc@yahoo.com.br */ 24913445Sodanrc@yahoo.com.br virtual void setValid() 25013445Sodanrc@yahoo.com.br { 25113445Sodanrc@yahoo.com.br assert(!isValid()); 25213445Sodanrc@yahoo.com.br status |= BlkValid; 25313445Sodanrc@yahoo.com.br } 25413445Sodanrc@yahoo.com.br 25513445Sodanrc@yahoo.com.br /** 25613445Sodanrc@yahoo.com.br * Set secure bit. 25713445Sodanrc@yahoo.com.br */ 25813445Sodanrc@yahoo.com.br virtual void setSecure() 25913445Sodanrc@yahoo.com.br { 26013445Sodanrc@yahoo.com.br status |= BlkSecure; 26113445Sodanrc@yahoo.com.br } 26213445Sodanrc@yahoo.com.br 26313445Sodanrc@yahoo.com.br /** 26413223Sodanrc@yahoo.com.br * Set member variables when a block insertion occurs. Resets reference 26513223Sodanrc@yahoo.com.br * count to 1 (the insertion counts as a reference), and touch block if 26613223Sodanrc@yahoo.com.br * it hadn't been touched previously. Sets the insertion tick to the 26713445Sodanrc@yahoo.com.br * current tick. Marks the block valid. 26813223Sodanrc@yahoo.com.br * 26913223Sodanrc@yahoo.com.br * @param tag Block address tag. 27013223Sodanrc@yahoo.com.br * @param is_secure Whether the block is in secure space or not. 27113223Sodanrc@yahoo.com.br * @param src_master_ID The source requestor ID. 27213223Sodanrc@yahoo.com.br * @param task_ID The new task ID. 27313223Sodanrc@yahoo.com.br */ 27413223Sodanrc@yahoo.com.br virtual void insert(const Addr tag, const bool is_secure, 27513223Sodanrc@yahoo.com.br const int src_master_ID, const uint32_t task_ID); 27613223Sodanrc@yahoo.com.br 27713223Sodanrc@yahoo.com.br /** 27813223Sodanrc@yahoo.com.br * Track the fact that a local locked was issued to the 27913223Sodanrc@yahoo.com.br * block. Invalidate any previous LL to the same address. 28013223Sodanrc@yahoo.com.br */ 28113223Sodanrc@yahoo.com.br void trackLoadLocked(PacketPtr pkt) 28213223Sodanrc@yahoo.com.br { 28313223Sodanrc@yahoo.com.br assert(pkt->isLLSC()); 28413223Sodanrc@yahoo.com.br auto l = lockList.begin(); 28513223Sodanrc@yahoo.com.br while (l != lockList.end()) { 28613223Sodanrc@yahoo.com.br if (l->intersects(pkt->req)) 28713223Sodanrc@yahoo.com.br l = lockList.erase(l); 28813223Sodanrc@yahoo.com.br else 28913223Sodanrc@yahoo.com.br ++l; 29013223Sodanrc@yahoo.com.br } 29113223Sodanrc@yahoo.com.br 29213223Sodanrc@yahoo.com.br lockList.emplace_front(pkt->req); 29313223Sodanrc@yahoo.com.br } 29413223Sodanrc@yahoo.com.br 29513223Sodanrc@yahoo.com.br /** 29613223Sodanrc@yahoo.com.br * Clear the any load lock that intersect the request, and is from 29713223Sodanrc@yahoo.com.br * a different context. 29813223Sodanrc@yahoo.com.br */ 29913223Sodanrc@yahoo.com.br void clearLoadLocks(const RequestPtr &req) 30013223Sodanrc@yahoo.com.br { 30113223Sodanrc@yahoo.com.br auto l = lockList.begin(); 30213223Sodanrc@yahoo.com.br while (l != lockList.end()) { 30313223Sodanrc@yahoo.com.br if (l->intersects(req) && l->contextId != req->contextId()) { 30413223Sodanrc@yahoo.com.br l = lockList.erase(l); 30513223Sodanrc@yahoo.com.br } else { 30613223Sodanrc@yahoo.com.br ++l; 30713223Sodanrc@yahoo.com.br } 30813223Sodanrc@yahoo.com.br } 30913223Sodanrc@yahoo.com.br } 31013223Sodanrc@yahoo.com.br 31113223Sodanrc@yahoo.com.br /** 31213223Sodanrc@yahoo.com.br * Pretty-print tag, set and way, and interpret state bits to readable form 31313223Sodanrc@yahoo.com.br * including mapping to a MOESI state. 31413223Sodanrc@yahoo.com.br * 31513223Sodanrc@yahoo.com.br * @return string with basic state information 31613223Sodanrc@yahoo.com.br */ 31713223Sodanrc@yahoo.com.br virtual std::string print() const 31813223Sodanrc@yahoo.com.br { 31913223Sodanrc@yahoo.com.br /** 32013223Sodanrc@yahoo.com.br * state M O E S I 32113223Sodanrc@yahoo.com.br * writable 1 0 1 0 0 32213223Sodanrc@yahoo.com.br * dirty 1 1 0 0 0 32313223Sodanrc@yahoo.com.br * valid 1 1 1 1 0 32413223Sodanrc@yahoo.com.br * 32513223Sodanrc@yahoo.com.br * state writable dirty valid 32613223Sodanrc@yahoo.com.br * M 1 1 1 32713223Sodanrc@yahoo.com.br * O 0 1 1 32813223Sodanrc@yahoo.com.br * E 1 0 1 32913223Sodanrc@yahoo.com.br * S 0 0 1 33013223Sodanrc@yahoo.com.br * I 0 0 0 33113223Sodanrc@yahoo.com.br * 33213223Sodanrc@yahoo.com.br * Note that only one cache ever has a block in Modified or 33313223Sodanrc@yahoo.com.br * Owned state, i.e., only one cache owns the block, or 33413223Sodanrc@yahoo.com.br * equivalently has the BlkDirty bit set. However, multiple 33513223Sodanrc@yahoo.com.br * caches on the same path to memory can have a block in the 33613223Sodanrc@yahoo.com.br * Exclusive state (despite the name). Exclusive means this 33713223Sodanrc@yahoo.com.br * cache has the only copy at this level of the hierarchy, 33813223Sodanrc@yahoo.com.br * i.e., there may be copies in caches above this cache (in 33913223Sodanrc@yahoo.com.br * various states), but there are no peers that have copies on 34013223Sodanrc@yahoo.com.br * this branch of the hierarchy, and no caches at or above 34113223Sodanrc@yahoo.com.br * this level on any other branch have copies either. 34213223Sodanrc@yahoo.com.br **/ 34313223Sodanrc@yahoo.com.br unsigned state = isWritable() << 2 | isDirty() << 1 | isValid(); 34413223Sodanrc@yahoo.com.br char s = '?'; 34513223Sodanrc@yahoo.com.br switch (state) { 34613223Sodanrc@yahoo.com.br case 0b111: s = 'M'; break; 34713223Sodanrc@yahoo.com.br case 0b011: s = 'O'; break; 34813223Sodanrc@yahoo.com.br case 0b101: s = 'E'; break; 34913223Sodanrc@yahoo.com.br case 0b001: s = 'S'; break; 35013223Sodanrc@yahoo.com.br case 0b000: s = 'I'; break; 35113223Sodanrc@yahoo.com.br default: s = 'T'; break; // @TODO add other types 35213223Sodanrc@yahoo.com.br } 35313223Sodanrc@yahoo.com.br return csprintf("state: %x (%c) valid: %d writable: %d readable: %d " 35413223Sodanrc@yahoo.com.br "dirty: %d | tag: %#x set: %#x way: %#x", status, s, 35513223Sodanrc@yahoo.com.br isValid(), isWritable(), isReadable(), isDirty(), tag, 35613223Sodanrc@yahoo.com.br getSet(), getWay()); 35713223Sodanrc@yahoo.com.br } 35813223Sodanrc@yahoo.com.br 35913223Sodanrc@yahoo.com.br /** 36013223Sodanrc@yahoo.com.br * Handle interaction of load-locked operations and stores. 36113223Sodanrc@yahoo.com.br * @return True if write should proceed, false otherwise. Returns 36213223Sodanrc@yahoo.com.br * false only in the case of a failed store conditional. 36313223Sodanrc@yahoo.com.br */ 36413223Sodanrc@yahoo.com.br bool checkWrite(PacketPtr pkt) 36513223Sodanrc@yahoo.com.br { 36613223Sodanrc@yahoo.com.br assert(pkt->isWrite()); 36713223Sodanrc@yahoo.com.br 36813223Sodanrc@yahoo.com.br // common case 36913223Sodanrc@yahoo.com.br if (!pkt->isLLSC() && lockList.empty()) 37013223Sodanrc@yahoo.com.br return true; 37113223Sodanrc@yahoo.com.br 37213223Sodanrc@yahoo.com.br const RequestPtr &req = pkt->req; 37313223Sodanrc@yahoo.com.br 37413223Sodanrc@yahoo.com.br if (pkt->isLLSC()) { 37513223Sodanrc@yahoo.com.br // it's a store conditional... have to check for matching 37613223Sodanrc@yahoo.com.br // load locked. 37713223Sodanrc@yahoo.com.br bool success = false; 37813223Sodanrc@yahoo.com.br 37913223Sodanrc@yahoo.com.br auto l = lockList.begin(); 38013223Sodanrc@yahoo.com.br while (!success && l != lockList.end()) { 38113223Sodanrc@yahoo.com.br if (l->matches(pkt->req)) { 38213223Sodanrc@yahoo.com.br // it's a store conditional, and as far as the 38313223Sodanrc@yahoo.com.br // memory system can tell, the requesting 38413223Sodanrc@yahoo.com.br // context's lock is still valid. 38513223Sodanrc@yahoo.com.br success = true; 38613223Sodanrc@yahoo.com.br lockList.erase(l); 38713223Sodanrc@yahoo.com.br } else { 38813223Sodanrc@yahoo.com.br ++l; 38913223Sodanrc@yahoo.com.br } 39013223Sodanrc@yahoo.com.br } 39113223Sodanrc@yahoo.com.br 39213223Sodanrc@yahoo.com.br req->setExtraData(success ? 1 : 0); 39313223Sodanrc@yahoo.com.br // clear any intersected locks from other contexts (our LL 39413223Sodanrc@yahoo.com.br // should already have cleared them) 39513223Sodanrc@yahoo.com.br clearLoadLocks(req); 39613223Sodanrc@yahoo.com.br return success; 39713223Sodanrc@yahoo.com.br } else { 39813223Sodanrc@yahoo.com.br // a normal write, if there is any lock not from this 39913223Sodanrc@yahoo.com.br // context we clear the list, thus for a private cache we 40013223Sodanrc@yahoo.com.br // never clear locks on normal writes 40113223Sodanrc@yahoo.com.br clearLoadLocks(req); 40213223Sodanrc@yahoo.com.br return true; 40313223Sodanrc@yahoo.com.br } 40413223Sodanrc@yahoo.com.br } 40513223Sodanrc@yahoo.com.br}; 40613223Sodanrc@yahoo.com.br 40713223Sodanrc@yahoo.com.br/** 40813223Sodanrc@yahoo.com.br * Special instance of CacheBlk for use with tempBlk that deals with its 40913223Sodanrc@yahoo.com.br * block address regeneration. 41013223Sodanrc@yahoo.com.br * @sa Cache 41113223Sodanrc@yahoo.com.br */ 41213223Sodanrc@yahoo.com.brclass TempCacheBlk final : public CacheBlk 41313223Sodanrc@yahoo.com.br{ 41413223Sodanrc@yahoo.com.br private: 41513223Sodanrc@yahoo.com.br /** 41613223Sodanrc@yahoo.com.br * Copy of the block's address, used to regenerate tempBlock's address. 41713223Sodanrc@yahoo.com.br */ 41813223Sodanrc@yahoo.com.br Addr _addr; 41913223Sodanrc@yahoo.com.br 42013223Sodanrc@yahoo.com.br public: 42113223Sodanrc@yahoo.com.br /** 42213223Sodanrc@yahoo.com.br * Creates a temporary cache block, with its own storage. 42313223Sodanrc@yahoo.com.br * @param size The size (in bytes) of this cache block. 42413223Sodanrc@yahoo.com.br */ 42513223Sodanrc@yahoo.com.br TempCacheBlk(unsigned size) : CacheBlk() 42613223Sodanrc@yahoo.com.br { 42713223Sodanrc@yahoo.com.br data = new uint8_t[size]; 42813223Sodanrc@yahoo.com.br } 42913223Sodanrc@yahoo.com.br TempCacheBlk(const TempCacheBlk&) = delete; 43013223Sodanrc@yahoo.com.br TempCacheBlk& operator=(const TempCacheBlk&) = delete; 43113223Sodanrc@yahoo.com.br ~TempCacheBlk() { delete [] data; }; 43213223Sodanrc@yahoo.com.br 43313223Sodanrc@yahoo.com.br /** 43413223Sodanrc@yahoo.com.br * Invalidate the block and clear all state. 43513223Sodanrc@yahoo.com.br */ 43613223Sodanrc@yahoo.com.br void invalidate() override { 43713223Sodanrc@yahoo.com.br CacheBlk::invalidate(); 43813223Sodanrc@yahoo.com.br 43913223Sodanrc@yahoo.com.br _addr = MaxAddr; 44013223Sodanrc@yahoo.com.br } 44113223Sodanrc@yahoo.com.br 44213223Sodanrc@yahoo.com.br void insert(const Addr addr, const bool is_secure, 44313223Sodanrc@yahoo.com.br const int src_master_ID=0, const uint32_t task_ID=0) override 44413223Sodanrc@yahoo.com.br { 44513445Sodanrc@yahoo.com.br // Make sure that the block has been properly invalidated 44613445Sodanrc@yahoo.com.br assert(status == 0); 44713445Sodanrc@yahoo.com.br 44813223Sodanrc@yahoo.com.br // Set block address 44913223Sodanrc@yahoo.com.br _addr = addr; 45013223Sodanrc@yahoo.com.br 45113223Sodanrc@yahoo.com.br // Set secure state 45213223Sodanrc@yahoo.com.br if (is_secure) { 45313445Sodanrc@yahoo.com.br setSecure(); 45413223Sodanrc@yahoo.com.br } 45513445Sodanrc@yahoo.com.br 45613445Sodanrc@yahoo.com.br // Validate block 45713445Sodanrc@yahoo.com.br setValid(); 45813223Sodanrc@yahoo.com.br } 45913223Sodanrc@yahoo.com.br 46013223Sodanrc@yahoo.com.br /** 46113223Sodanrc@yahoo.com.br * Get block's address. 46213223Sodanrc@yahoo.com.br * 46313223Sodanrc@yahoo.com.br * @return addr Address value. 46413223Sodanrc@yahoo.com.br */ 46513223Sodanrc@yahoo.com.br Addr getAddr() const 46613223Sodanrc@yahoo.com.br { 46713223Sodanrc@yahoo.com.br return _addr; 46813223Sodanrc@yahoo.com.br } 46913223Sodanrc@yahoo.com.br}; 47013223Sodanrc@yahoo.com.br 47113223Sodanrc@yahoo.com.br/** 47213223Sodanrc@yahoo.com.br * Simple class to provide virtual print() method on cache blocks 47313223Sodanrc@yahoo.com.br * without allocating a vtable pointer for every single cache block. 47413223Sodanrc@yahoo.com.br * Just wrap the CacheBlk object in an instance of this before passing 47513223Sodanrc@yahoo.com.br * to a function that requires a Printable object. 47613223Sodanrc@yahoo.com.br */ 47713223Sodanrc@yahoo.com.brclass CacheBlkPrintWrapper : public Printable 47813223Sodanrc@yahoo.com.br{ 47913223Sodanrc@yahoo.com.br CacheBlk *blk; 48013223Sodanrc@yahoo.com.br public: 48113223Sodanrc@yahoo.com.br CacheBlkPrintWrapper(CacheBlk *_blk) : blk(_blk) {} 48213223Sodanrc@yahoo.com.br virtual ~CacheBlkPrintWrapper() {} 48313223Sodanrc@yahoo.com.br void print(std::ostream &o, int verbosity = 0, 48413223Sodanrc@yahoo.com.br const std::string &prefix = "") const; 48513223Sodanrc@yahoo.com.br}; 48613223Sodanrc@yahoo.com.br 48713223Sodanrc@yahoo.com.br#endif //__MEM_CACHE_CACHE_BLK_HH__ 488