cache_blk.hh revision 13477
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 10813477Sodanrc@yahoo.com.br /** 10913477Sodanrc@yahoo.com.br * Which curTick() will this block be accessible. Its value is only 11013477Sodanrc@yahoo.com.br * meaningful if the block is valid. 11113477Sodanrc@yahoo.com.br */ 11213223Sodanrc@yahoo.com.br Tick whenReady; 11313223Sodanrc@yahoo.com.br 11413223Sodanrc@yahoo.com.br /** Number of references to this block since it was brought in. */ 11513223Sodanrc@yahoo.com.br unsigned refCount; 11613223Sodanrc@yahoo.com.br 11713223Sodanrc@yahoo.com.br /** holds the source requestor ID for this block. */ 11813223Sodanrc@yahoo.com.br int srcMasterId; 11913223Sodanrc@yahoo.com.br 12013477Sodanrc@yahoo.com.br /** 12113477Sodanrc@yahoo.com.br * Tick on which the block was inserted in the cache. Its value is only 12213477Sodanrc@yahoo.com.br * meaningful if the block is valid. 12313477Sodanrc@yahoo.com.br */ 12413223Sodanrc@yahoo.com.br Tick tickInserted; 12513223Sodanrc@yahoo.com.br 12613223Sodanrc@yahoo.com.br protected: 12713223Sodanrc@yahoo.com.br /** 12813223Sodanrc@yahoo.com.br * Represents that the indicated thread context has a "lock" on 12913223Sodanrc@yahoo.com.br * the block, in the LL/SC sense. 13013223Sodanrc@yahoo.com.br */ 13113223Sodanrc@yahoo.com.br class Lock { 13213223Sodanrc@yahoo.com.br public: 13313223Sodanrc@yahoo.com.br ContextID contextId; // locking context 13413223Sodanrc@yahoo.com.br Addr lowAddr; // low address of lock range 13513223Sodanrc@yahoo.com.br Addr highAddr; // high address of lock range 13613223Sodanrc@yahoo.com.br 13713223Sodanrc@yahoo.com.br // check for matching execution context, and an address that 13813223Sodanrc@yahoo.com.br // is within the lock 13913223Sodanrc@yahoo.com.br bool matches(const RequestPtr &req) const 14013223Sodanrc@yahoo.com.br { 14113223Sodanrc@yahoo.com.br Addr req_low = req->getPaddr(); 14213223Sodanrc@yahoo.com.br Addr req_high = req_low + req->getSize() -1; 14313223Sodanrc@yahoo.com.br return (contextId == req->contextId()) && 14413223Sodanrc@yahoo.com.br (req_low >= lowAddr) && (req_high <= highAddr); 14513223Sodanrc@yahoo.com.br } 14613223Sodanrc@yahoo.com.br 14713223Sodanrc@yahoo.com.br // check if a request is intersecting and thus invalidating the lock 14813223Sodanrc@yahoo.com.br bool intersects(const RequestPtr &req) const 14913223Sodanrc@yahoo.com.br { 15013223Sodanrc@yahoo.com.br Addr req_low = req->getPaddr(); 15113223Sodanrc@yahoo.com.br Addr req_high = req_low + req->getSize() - 1; 15213223Sodanrc@yahoo.com.br 15313223Sodanrc@yahoo.com.br return (req_low <= highAddr) && (req_high >= lowAddr); 15413223Sodanrc@yahoo.com.br } 15513223Sodanrc@yahoo.com.br 15613223Sodanrc@yahoo.com.br Lock(const RequestPtr &req) 15713223Sodanrc@yahoo.com.br : contextId(req->contextId()), 15813223Sodanrc@yahoo.com.br lowAddr(req->getPaddr()), 15913223Sodanrc@yahoo.com.br highAddr(lowAddr + req->getSize() - 1) 16013223Sodanrc@yahoo.com.br { 16113223Sodanrc@yahoo.com.br } 16213223Sodanrc@yahoo.com.br }; 16313223Sodanrc@yahoo.com.br 16413223Sodanrc@yahoo.com.br /** List of thread contexts that have performed a load-locked (LL) 16513223Sodanrc@yahoo.com.br * on the block since the last store. */ 16613223Sodanrc@yahoo.com.br std::list<Lock> lockList; 16713223Sodanrc@yahoo.com.br 16813223Sodanrc@yahoo.com.br public: 16913477Sodanrc@yahoo.com.br CacheBlk() : data(nullptr), tickInserted(0) 17013223Sodanrc@yahoo.com.br { 17113223Sodanrc@yahoo.com.br invalidate(); 17213223Sodanrc@yahoo.com.br } 17313223Sodanrc@yahoo.com.br 17413223Sodanrc@yahoo.com.br CacheBlk(const CacheBlk&) = delete; 17513223Sodanrc@yahoo.com.br CacheBlk& operator=(const CacheBlk&) = delete; 17613223Sodanrc@yahoo.com.br virtual ~CacheBlk() {}; 17713223Sodanrc@yahoo.com.br 17813223Sodanrc@yahoo.com.br /** 17913223Sodanrc@yahoo.com.br * Checks the write permissions of this block. 18013223Sodanrc@yahoo.com.br * @return True if the block is writable. 18113223Sodanrc@yahoo.com.br */ 18213223Sodanrc@yahoo.com.br bool isWritable() const 18313223Sodanrc@yahoo.com.br { 18413223Sodanrc@yahoo.com.br const State needed_bits = BlkWritable | BlkValid; 18513223Sodanrc@yahoo.com.br return (status & needed_bits) == needed_bits; 18613223Sodanrc@yahoo.com.br } 18713223Sodanrc@yahoo.com.br 18813223Sodanrc@yahoo.com.br /** 18913223Sodanrc@yahoo.com.br * Checks the read permissions of this block. Note that a block 19013223Sodanrc@yahoo.com.br * can be valid but not readable if there is an outstanding write 19113223Sodanrc@yahoo.com.br * upgrade miss. 19213223Sodanrc@yahoo.com.br * @return True if the block is readable. 19313223Sodanrc@yahoo.com.br */ 19413223Sodanrc@yahoo.com.br bool isReadable() const 19513223Sodanrc@yahoo.com.br { 19613223Sodanrc@yahoo.com.br const State needed_bits = BlkReadable | BlkValid; 19713223Sodanrc@yahoo.com.br return (status & needed_bits) == needed_bits; 19813223Sodanrc@yahoo.com.br } 19913223Sodanrc@yahoo.com.br 20013223Sodanrc@yahoo.com.br /** 20113223Sodanrc@yahoo.com.br * Checks that a block is valid. 20213223Sodanrc@yahoo.com.br * @return True if the block is valid. 20313223Sodanrc@yahoo.com.br */ 20413223Sodanrc@yahoo.com.br bool isValid() const 20513223Sodanrc@yahoo.com.br { 20613223Sodanrc@yahoo.com.br return (status & BlkValid) != 0; 20713223Sodanrc@yahoo.com.br } 20813223Sodanrc@yahoo.com.br 20913223Sodanrc@yahoo.com.br /** 21013223Sodanrc@yahoo.com.br * Invalidate the block and clear all state. 21113223Sodanrc@yahoo.com.br */ 21213223Sodanrc@yahoo.com.br virtual void invalidate() 21313223Sodanrc@yahoo.com.br { 21413223Sodanrc@yahoo.com.br tag = MaxAddr; 21513223Sodanrc@yahoo.com.br task_id = ContextSwitchTaskId::Unknown; 21613223Sodanrc@yahoo.com.br status = 0; 21713223Sodanrc@yahoo.com.br whenReady = MaxTick; 21813223Sodanrc@yahoo.com.br refCount = 0; 21913223Sodanrc@yahoo.com.br srcMasterId = Request::invldMasterId; 22013223Sodanrc@yahoo.com.br lockList.clear(); 22113223Sodanrc@yahoo.com.br } 22213223Sodanrc@yahoo.com.br 22313223Sodanrc@yahoo.com.br /** 22413223Sodanrc@yahoo.com.br * Check to see if a block has been written. 22513223Sodanrc@yahoo.com.br * @return True if the block is dirty. 22613223Sodanrc@yahoo.com.br */ 22713223Sodanrc@yahoo.com.br bool isDirty() const 22813223Sodanrc@yahoo.com.br { 22913223Sodanrc@yahoo.com.br return (status & BlkDirty) != 0; 23013223Sodanrc@yahoo.com.br } 23113223Sodanrc@yahoo.com.br 23213223Sodanrc@yahoo.com.br /** 23313223Sodanrc@yahoo.com.br * Check if this block was the result of a hardware prefetch, yet to 23413223Sodanrc@yahoo.com.br * be touched. 23513223Sodanrc@yahoo.com.br * @return True if the block was a hardware prefetch, unaccesed. 23613223Sodanrc@yahoo.com.br */ 23713223Sodanrc@yahoo.com.br bool wasPrefetched() const 23813223Sodanrc@yahoo.com.br { 23913223Sodanrc@yahoo.com.br return (status & BlkHWPrefetched) != 0; 24013223Sodanrc@yahoo.com.br } 24113223Sodanrc@yahoo.com.br 24213223Sodanrc@yahoo.com.br /** 24313223Sodanrc@yahoo.com.br * Check if this block holds data from the secure memory space. 24413223Sodanrc@yahoo.com.br * @return True if the block holds data from the secure memory space. 24513223Sodanrc@yahoo.com.br */ 24613223Sodanrc@yahoo.com.br bool isSecure() const 24713223Sodanrc@yahoo.com.br { 24813223Sodanrc@yahoo.com.br return (status & BlkSecure) != 0; 24913223Sodanrc@yahoo.com.br } 25013223Sodanrc@yahoo.com.br 25113223Sodanrc@yahoo.com.br /** 25213445Sodanrc@yahoo.com.br * Set valid bit. 25313445Sodanrc@yahoo.com.br */ 25413445Sodanrc@yahoo.com.br virtual void setValid() 25513445Sodanrc@yahoo.com.br { 25613445Sodanrc@yahoo.com.br assert(!isValid()); 25713445Sodanrc@yahoo.com.br status |= BlkValid; 25813445Sodanrc@yahoo.com.br } 25913445Sodanrc@yahoo.com.br 26013445Sodanrc@yahoo.com.br /** 26113445Sodanrc@yahoo.com.br * Set secure bit. 26213445Sodanrc@yahoo.com.br */ 26313445Sodanrc@yahoo.com.br virtual void setSecure() 26413445Sodanrc@yahoo.com.br { 26513445Sodanrc@yahoo.com.br status |= BlkSecure; 26613445Sodanrc@yahoo.com.br } 26713445Sodanrc@yahoo.com.br 26813445Sodanrc@yahoo.com.br /** 26913477Sodanrc@yahoo.com.br * Get tick at which block's data will be available for access. 27013477Sodanrc@yahoo.com.br * 27113477Sodanrc@yahoo.com.br * @return Data ready tick. 27213477Sodanrc@yahoo.com.br */ 27313477Sodanrc@yahoo.com.br Tick getWhenReady() const 27413477Sodanrc@yahoo.com.br { 27513477Sodanrc@yahoo.com.br return whenReady; 27613477Sodanrc@yahoo.com.br } 27713477Sodanrc@yahoo.com.br 27813477Sodanrc@yahoo.com.br /** 27913477Sodanrc@yahoo.com.br * Set tick at which block's data will be available for access. The new 28013477Sodanrc@yahoo.com.br * tick must be chronologically sequential with respect to previous 28113477Sodanrc@yahoo.com.br * accesses. 28213477Sodanrc@yahoo.com.br * 28313477Sodanrc@yahoo.com.br * @param tick New data ready tick. 28413477Sodanrc@yahoo.com.br */ 28513477Sodanrc@yahoo.com.br void setWhenReady(const Tick tick) 28613477Sodanrc@yahoo.com.br { 28713477Sodanrc@yahoo.com.br assert((whenReady == MaxTick) || (tick >= whenReady)); 28813477Sodanrc@yahoo.com.br assert(tick >= tickInserted); 28913477Sodanrc@yahoo.com.br whenReady = tick; 29013477Sodanrc@yahoo.com.br } 29113477Sodanrc@yahoo.com.br 29213477Sodanrc@yahoo.com.br /** 29313223Sodanrc@yahoo.com.br * Set member variables when a block insertion occurs. Resets reference 29413223Sodanrc@yahoo.com.br * count to 1 (the insertion counts as a reference), and touch block if 29513223Sodanrc@yahoo.com.br * it hadn't been touched previously. Sets the insertion tick to the 29613445Sodanrc@yahoo.com.br * current tick. Marks the block valid. 29713223Sodanrc@yahoo.com.br * 29813223Sodanrc@yahoo.com.br * @param tag Block address tag. 29913223Sodanrc@yahoo.com.br * @param is_secure Whether the block is in secure space or not. 30013223Sodanrc@yahoo.com.br * @param src_master_ID The source requestor ID. 30113223Sodanrc@yahoo.com.br * @param task_ID The new task ID. 30213223Sodanrc@yahoo.com.br */ 30313223Sodanrc@yahoo.com.br virtual void insert(const Addr tag, const bool is_secure, 30413223Sodanrc@yahoo.com.br const int src_master_ID, const uint32_t task_ID); 30513223Sodanrc@yahoo.com.br 30613223Sodanrc@yahoo.com.br /** 30713223Sodanrc@yahoo.com.br * Track the fact that a local locked was issued to the 30813223Sodanrc@yahoo.com.br * block. Invalidate any previous LL to the same address. 30913223Sodanrc@yahoo.com.br */ 31013223Sodanrc@yahoo.com.br void trackLoadLocked(PacketPtr pkt) 31113223Sodanrc@yahoo.com.br { 31213223Sodanrc@yahoo.com.br assert(pkt->isLLSC()); 31313223Sodanrc@yahoo.com.br auto l = lockList.begin(); 31413223Sodanrc@yahoo.com.br while (l != lockList.end()) { 31513223Sodanrc@yahoo.com.br if (l->intersects(pkt->req)) 31613223Sodanrc@yahoo.com.br l = lockList.erase(l); 31713223Sodanrc@yahoo.com.br else 31813223Sodanrc@yahoo.com.br ++l; 31913223Sodanrc@yahoo.com.br } 32013223Sodanrc@yahoo.com.br 32113223Sodanrc@yahoo.com.br lockList.emplace_front(pkt->req); 32213223Sodanrc@yahoo.com.br } 32313223Sodanrc@yahoo.com.br 32413223Sodanrc@yahoo.com.br /** 32513223Sodanrc@yahoo.com.br * Clear the any load lock that intersect the request, and is from 32613223Sodanrc@yahoo.com.br * a different context. 32713223Sodanrc@yahoo.com.br */ 32813223Sodanrc@yahoo.com.br void clearLoadLocks(const RequestPtr &req) 32913223Sodanrc@yahoo.com.br { 33013223Sodanrc@yahoo.com.br auto l = lockList.begin(); 33113223Sodanrc@yahoo.com.br while (l != lockList.end()) { 33213223Sodanrc@yahoo.com.br if (l->intersects(req) && l->contextId != req->contextId()) { 33313223Sodanrc@yahoo.com.br l = lockList.erase(l); 33413223Sodanrc@yahoo.com.br } else { 33513223Sodanrc@yahoo.com.br ++l; 33613223Sodanrc@yahoo.com.br } 33713223Sodanrc@yahoo.com.br } 33813223Sodanrc@yahoo.com.br } 33913223Sodanrc@yahoo.com.br 34013223Sodanrc@yahoo.com.br /** 34113223Sodanrc@yahoo.com.br * Pretty-print tag, set and way, and interpret state bits to readable form 34213223Sodanrc@yahoo.com.br * including mapping to a MOESI state. 34313223Sodanrc@yahoo.com.br * 34413223Sodanrc@yahoo.com.br * @return string with basic state information 34513223Sodanrc@yahoo.com.br */ 34613223Sodanrc@yahoo.com.br virtual std::string print() const 34713223Sodanrc@yahoo.com.br { 34813223Sodanrc@yahoo.com.br /** 34913223Sodanrc@yahoo.com.br * state M O E S I 35013223Sodanrc@yahoo.com.br * writable 1 0 1 0 0 35113223Sodanrc@yahoo.com.br * dirty 1 1 0 0 0 35213223Sodanrc@yahoo.com.br * valid 1 1 1 1 0 35313223Sodanrc@yahoo.com.br * 35413223Sodanrc@yahoo.com.br * state writable dirty valid 35513223Sodanrc@yahoo.com.br * M 1 1 1 35613223Sodanrc@yahoo.com.br * O 0 1 1 35713223Sodanrc@yahoo.com.br * E 1 0 1 35813223Sodanrc@yahoo.com.br * S 0 0 1 35913223Sodanrc@yahoo.com.br * I 0 0 0 36013223Sodanrc@yahoo.com.br * 36113223Sodanrc@yahoo.com.br * Note that only one cache ever has a block in Modified or 36213223Sodanrc@yahoo.com.br * Owned state, i.e., only one cache owns the block, or 36313223Sodanrc@yahoo.com.br * equivalently has the BlkDirty bit set. However, multiple 36413223Sodanrc@yahoo.com.br * caches on the same path to memory can have a block in the 36513223Sodanrc@yahoo.com.br * Exclusive state (despite the name). Exclusive means this 36613223Sodanrc@yahoo.com.br * cache has the only copy at this level of the hierarchy, 36713223Sodanrc@yahoo.com.br * i.e., there may be copies in caches above this cache (in 36813223Sodanrc@yahoo.com.br * various states), but there are no peers that have copies on 36913223Sodanrc@yahoo.com.br * this branch of the hierarchy, and no caches at or above 37013223Sodanrc@yahoo.com.br * this level on any other branch have copies either. 37113223Sodanrc@yahoo.com.br **/ 37213223Sodanrc@yahoo.com.br unsigned state = isWritable() << 2 | isDirty() << 1 | isValid(); 37313223Sodanrc@yahoo.com.br char s = '?'; 37413223Sodanrc@yahoo.com.br switch (state) { 37513223Sodanrc@yahoo.com.br case 0b111: s = 'M'; break; 37613223Sodanrc@yahoo.com.br case 0b011: s = 'O'; break; 37713223Sodanrc@yahoo.com.br case 0b101: s = 'E'; break; 37813223Sodanrc@yahoo.com.br case 0b001: s = 'S'; break; 37913223Sodanrc@yahoo.com.br case 0b000: s = 'I'; break; 38013223Sodanrc@yahoo.com.br default: s = 'T'; break; // @TODO add other types 38113223Sodanrc@yahoo.com.br } 38213223Sodanrc@yahoo.com.br return csprintf("state: %x (%c) valid: %d writable: %d readable: %d " 38313223Sodanrc@yahoo.com.br "dirty: %d | tag: %#x set: %#x way: %#x", status, s, 38413223Sodanrc@yahoo.com.br isValid(), isWritable(), isReadable(), isDirty(), tag, 38513223Sodanrc@yahoo.com.br getSet(), getWay()); 38613223Sodanrc@yahoo.com.br } 38713223Sodanrc@yahoo.com.br 38813223Sodanrc@yahoo.com.br /** 38913223Sodanrc@yahoo.com.br * Handle interaction of load-locked operations and stores. 39013223Sodanrc@yahoo.com.br * @return True if write should proceed, false otherwise. Returns 39113223Sodanrc@yahoo.com.br * false only in the case of a failed store conditional. 39213223Sodanrc@yahoo.com.br */ 39313223Sodanrc@yahoo.com.br bool checkWrite(PacketPtr pkt) 39413223Sodanrc@yahoo.com.br { 39513223Sodanrc@yahoo.com.br assert(pkt->isWrite()); 39613223Sodanrc@yahoo.com.br 39713223Sodanrc@yahoo.com.br // common case 39813223Sodanrc@yahoo.com.br if (!pkt->isLLSC() && lockList.empty()) 39913223Sodanrc@yahoo.com.br return true; 40013223Sodanrc@yahoo.com.br 40113223Sodanrc@yahoo.com.br const RequestPtr &req = pkt->req; 40213223Sodanrc@yahoo.com.br 40313223Sodanrc@yahoo.com.br if (pkt->isLLSC()) { 40413223Sodanrc@yahoo.com.br // it's a store conditional... have to check for matching 40513223Sodanrc@yahoo.com.br // load locked. 40613223Sodanrc@yahoo.com.br bool success = false; 40713223Sodanrc@yahoo.com.br 40813223Sodanrc@yahoo.com.br auto l = lockList.begin(); 40913223Sodanrc@yahoo.com.br while (!success && l != lockList.end()) { 41013223Sodanrc@yahoo.com.br if (l->matches(pkt->req)) { 41113223Sodanrc@yahoo.com.br // it's a store conditional, and as far as the 41213223Sodanrc@yahoo.com.br // memory system can tell, the requesting 41313223Sodanrc@yahoo.com.br // context's lock is still valid. 41413223Sodanrc@yahoo.com.br success = true; 41513223Sodanrc@yahoo.com.br lockList.erase(l); 41613223Sodanrc@yahoo.com.br } else { 41713223Sodanrc@yahoo.com.br ++l; 41813223Sodanrc@yahoo.com.br } 41913223Sodanrc@yahoo.com.br } 42013223Sodanrc@yahoo.com.br 42113223Sodanrc@yahoo.com.br req->setExtraData(success ? 1 : 0); 42213223Sodanrc@yahoo.com.br // clear any intersected locks from other contexts (our LL 42313223Sodanrc@yahoo.com.br // should already have cleared them) 42413223Sodanrc@yahoo.com.br clearLoadLocks(req); 42513223Sodanrc@yahoo.com.br return success; 42613223Sodanrc@yahoo.com.br } else { 42713223Sodanrc@yahoo.com.br // a normal write, if there is any lock not from this 42813223Sodanrc@yahoo.com.br // context we clear the list, thus for a private cache we 42913223Sodanrc@yahoo.com.br // never clear locks on normal writes 43013223Sodanrc@yahoo.com.br clearLoadLocks(req); 43113223Sodanrc@yahoo.com.br return true; 43213223Sodanrc@yahoo.com.br } 43313223Sodanrc@yahoo.com.br } 43413223Sodanrc@yahoo.com.br}; 43513223Sodanrc@yahoo.com.br 43613223Sodanrc@yahoo.com.br/** 43713223Sodanrc@yahoo.com.br * Special instance of CacheBlk for use with tempBlk that deals with its 43813223Sodanrc@yahoo.com.br * block address regeneration. 43913223Sodanrc@yahoo.com.br * @sa Cache 44013223Sodanrc@yahoo.com.br */ 44113223Sodanrc@yahoo.com.brclass TempCacheBlk final : public CacheBlk 44213223Sodanrc@yahoo.com.br{ 44313223Sodanrc@yahoo.com.br private: 44413223Sodanrc@yahoo.com.br /** 44513223Sodanrc@yahoo.com.br * Copy of the block's address, used to regenerate tempBlock's address. 44613223Sodanrc@yahoo.com.br */ 44713223Sodanrc@yahoo.com.br Addr _addr; 44813223Sodanrc@yahoo.com.br 44913223Sodanrc@yahoo.com.br public: 45013223Sodanrc@yahoo.com.br /** 45113223Sodanrc@yahoo.com.br * Creates a temporary cache block, with its own storage. 45213223Sodanrc@yahoo.com.br * @param size The size (in bytes) of this cache block. 45313223Sodanrc@yahoo.com.br */ 45413223Sodanrc@yahoo.com.br TempCacheBlk(unsigned size) : CacheBlk() 45513223Sodanrc@yahoo.com.br { 45613223Sodanrc@yahoo.com.br data = new uint8_t[size]; 45713223Sodanrc@yahoo.com.br } 45813223Sodanrc@yahoo.com.br TempCacheBlk(const TempCacheBlk&) = delete; 45913223Sodanrc@yahoo.com.br TempCacheBlk& operator=(const TempCacheBlk&) = delete; 46013223Sodanrc@yahoo.com.br ~TempCacheBlk() { delete [] data; }; 46113223Sodanrc@yahoo.com.br 46213223Sodanrc@yahoo.com.br /** 46313223Sodanrc@yahoo.com.br * Invalidate the block and clear all state. 46413223Sodanrc@yahoo.com.br */ 46513223Sodanrc@yahoo.com.br void invalidate() override { 46613223Sodanrc@yahoo.com.br CacheBlk::invalidate(); 46713223Sodanrc@yahoo.com.br 46813223Sodanrc@yahoo.com.br _addr = MaxAddr; 46913223Sodanrc@yahoo.com.br } 47013223Sodanrc@yahoo.com.br 47113223Sodanrc@yahoo.com.br void insert(const Addr addr, const bool is_secure, 47213223Sodanrc@yahoo.com.br const int src_master_ID=0, const uint32_t task_ID=0) override 47313223Sodanrc@yahoo.com.br { 47413445Sodanrc@yahoo.com.br // Make sure that the block has been properly invalidated 47513445Sodanrc@yahoo.com.br assert(status == 0); 47613445Sodanrc@yahoo.com.br 47713223Sodanrc@yahoo.com.br // Set block address 47813223Sodanrc@yahoo.com.br _addr = addr; 47913223Sodanrc@yahoo.com.br 48013223Sodanrc@yahoo.com.br // Set secure state 48113223Sodanrc@yahoo.com.br if (is_secure) { 48213445Sodanrc@yahoo.com.br setSecure(); 48313223Sodanrc@yahoo.com.br } 48413445Sodanrc@yahoo.com.br 48513445Sodanrc@yahoo.com.br // Validate block 48613445Sodanrc@yahoo.com.br setValid(); 48713223Sodanrc@yahoo.com.br } 48813223Sodanrc@yahoo.com.br 48913223Sodanrc@yahoo.com.br /** 49013223Sodanrc@yahoo.com.br * Get block's address. 49113223Sodanrc@yahoo.com.br * 49213223Sodanrc@yahoo.com.br * @return addr Address value. 49313223Sodanrc@yahoo.com.br */ 49413223Sodanrc@yahoo.com.br Addr getAddr() const 49513223Sodanrc@yahoo.com.br { 49613223Sodanrc@yahoo.com.br return _addr; 49713223Sodanrc@yahoo.com.br } 49813223Sodanrc@yahoo.com.br}; 49913223Sodanrc@yahoo.com.br 50013223Sodanrc@yahoo.com.br/** 50113223Sodanrc@yahoo.com.br * Simple class to provide virtual print() method on cache blocks 50213223Sodanrc@yahoo.com.br * without allocating a vtable pointer for every single cache block. 50313223Sodanrc@yahoo.com.br * Just wrap the CacheBlk object in an instance of this before passing 50413223Sodanrc@yahoo.com.br * to a function that requires a Printable object. 50513223Sodanrc@yahoo.com.br */ 50613223Sodanrc@yahoo.com.brclass CacheBlkPrintWrapper : public Printable 50713223Sodanrc@yahoo.com.br{ 50813223Sodanrc@yahoo.com.br CacheBlk *blk; 50913223Sodanrc@yahoo.com.br public: 51013223Sodanrc@yahoo.com.br CacheBlkPrintWrapper(CacheBlk *_blk) : blk(_blk) {} 51113223Sodanrc@yahoo.com.br virtual ~CacheBlkPrintWrapper() {} 51213223Sodanrc@yahoo.com.br void print(std::ostream &o, int verbosity = 0, 51313223Sodanrc@yahoo.com.br const std::string &prefix = "") const; 51413223Sodanrc@yahoo.com.br}; 51513223Sodanrc@yahoo.com.br 51613223Sodanrc@yahoo.com.br#endif //__MEM_CACHE_CACHE_BLK_HH__ 517