113669Sjavier.bueno@metempsy.com/** 213669Sjavier.bueno@metempsy.com * Copyright (c) 2018 Metempsy Technology Consulting 313669Sjavier.bueno@metempsy.com * All rights reserved. 413669Sjavier.bueno@metempsy.com * 513669Sjavier.bueno@metempsy.com * Redistribution and use in source and binary forms, with or without 613669Sjavier.bueno@metempsy.com * modification, are permitted provided that the following conditions are 713669Sjavier.bueno@metempsy.com * met: redistributions of source code must retain the above copyright 813669Sjavier.bueno@metempsy.com * notice, this list of conditions and the following disclaimer; 913669Sjavier.bueno@metempsy.com * redistributions in binary form must reproduce the above copyright 1013669Sjavier.bueno@metempsy.com * notice, this list of conditions and the following disclaimer in the 1113669Sjavier.bueno@metempsy.com * documentation and/or other materials provided with the distribution; 1213669Sjavier.bueno@metempsy.com * neither the name of the copyright holders nor the names of its 1313669Sjavier.bueno@metempsy.com * contributors may be used to endorse or promote products derived from 1413669Sjavier.bueno@metempsy.com * this software without specific prior written permission. 1513669Sjavier.bueno@metempsy.com * 1613669Sjavier.bueno@metempsy.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1713669Sjavier.bueno@metempsy.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1813669Sjavier.bueno@metempsy.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1913669Sjavier.bueno@metempsy.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2013669Sjavier.bueno@metempsy.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2113669Sjavier.bueno@metempsy.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2213669Sjavier.bueno@metempsy.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2313669Sjavier.bueno@metempsy.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2413669Sjavier.bueno@metempsy.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2513669Sjavier.bueno@metempsy.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2613669Sjavier.bueno@metempsy.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2713669Sjavier.bueno@metempsy.com * 2813669Sjavier.bueno@metempsy.com * Authors: Javier Bueno 2913669Sjavier.bueno@metempsy.com */ 3013669Sjavier.bueno@metempsy.com 3113669Sjavier.bueno@metempsy.com/** 3213669Sjavier.bueno@metempsy.com * Implementation of the Irregular Stream Buffer prefetcher 3313669Sjavier.bueno@metempsy.com * Reference: 3413669Sjavier.bueno@metempsy.com * Jain, A., & Lin, C. (2013, December). Linearizing irregular memory 3513669Sjavier.bueno@metempsy.com * accesses for improved correlated prefetching. In Proceedings of the 3613669Sjavier.bueno@metempsy.com * 46th Annual IEEE/ACM International Symposium on Microarchitecture 3713669Sjavier.bueno@metempsy.com * (pp. 247-259). ACM. 3813669Sjavier.bueno@metempsy.com */ 3913669Sjavier.bueno@metempsy.com 4013669Sjavier.bueno@metempsy.com#ifndef __MEM_CACHE_PREFETCH_IRREGULAR_STREAM_BUFFER_HH__ 4113669Sjavier.bueno@metempsy.com#define __MEM_CACHE_PREFETCH_IRREGULAR_STREAM_BUFFER_HH__ 4213669Sjavier.bueno@metempsy.com 4313669Sjavier.bueno@metempsy.com#include "base/callback.hh" 4413963Sodanrc@yahoo.com.br#include "base/sat_counter.hh" 4513669Sjavier.bueno@metempsy.com#include "mem/cache/prefetch/associative_set.hh" 4613669Sjavier.bueno@metempsy.com#include "mem/cache/prefetch/queued.hh" 4713669Sjavier.bueno@metempsy.com 4813669Sjavier.bueno@metempsy.comstruct IrregularStreamBufferPrefetcherParams; 4913669Sjavier.bueno@metempsy.com 5013669Sjavier.bueno@metempsy.comclass IrregularStreamBufferPrefetcher : public QueuedPrefetcher 5113669Sjavier.bueno@metempsy.com{ 5213669Sjavier.bueno@metempsy.com /** Size in bytes of a temporal stream */ 5313669Sjavier.bueno@metempsy.com const size_t chunkSize; 5413669Sjavier.bueno@metempsy.com /** Number of prefetch candidates per Physical-to-Structural entry */ 5513669Sjavier.bueno@metempsy.com const unsigned prefetchCandidatesPerEntry; 5613669Sjavier.bueno@metempsy.com /** Number of maximum prefetches requests created when predicting */ 5713669Sjavier.bueno@metempsy.com const unsigned degree; 5813669Sjavier.bueno@metempsy.com 5913669Sjavier.bueno@metempsy.com /** 6013669Sjavier.bueno@metempsy.com * Training Unit Entry datatype, it holds the last accessed address and 6113669Sjavier.bueno@metempsy.com * its secure flag 6213669Sjavier.bueno@metempsy.com */ 6313669Sjavier.bueno@metempsy.com struct TrainingUnitEntry : public TaggedEntry { 6413669Sjavier.bueno@metempsy.com Addr lastAddress; 6513669Sjavier.bueno@metempsy.com bool lastAddressSecure; 6613669Sjavier.bueno@metempsy.com }; 6713669Sjavier.bueno@metempsy.com /** Map of PCs to Training unit entries */ 6813669Sjavier.bueno@metempsy.com AssociativeSet<TrainingUnitEntry> trainingUnit; 6913669Sjavier.bueno@metempsy.com 7013669Sjavier.bueno@metempsy.com /** Address Mapping entry, holds an address and a confidence counter */ 7113669Sjavier.bueno@metempsy.com struct AddressMapping { 7213669Sjavier.bueno@metempsy.com Addr address; 7313963Sodanrc@yahoo.com.br SatCounter counter; 7413963Sodanrc@yahoo.com.br AddressMapping(unsigned bits) : address(0), counter(bits) 7513669Sjavier.bueno@metempsy.com {} 7613669Sjavier.bueno@metempsy.com }; 7713669Sjavier.bueno@metempsy.com 7813669Sjavier.bueno@metempsy.com /** 7913669Sjavier.bueno@metempsy.com * Maps a set of contiguous addresses to another set of (not necessarily 8013669Sjavier.bueno@metempsy.com * contiguos) addresses, with their corresponding confidence counters 8113669Sjavier.bueno@metempsy.com */ 8213669Sjavier.bueno@metempsy.com struct AddressMappingEntry : public TaggedEntry { 8313669Sjavier.bueno@metempsy.com std::vector<AddressMapping> mappings; 8413963Sodanrc@yahoo.com.br AddressMappingEntry(size_t num_mappings, unsigned counter_bits) 8513963Sodanrc@yahoo.com.br : mappings(num_mappings, counter_bits) 8613669Sjavier.bueno@metempsy.com {} 8713669Sjavier.bueno@metempsy.com void reset() override 8813669Sjavier.bueno@metempsy.com { 8913669Sjavier.bueno@metempsy.com for (auto &entry : mappings) { 9013669Sjavier.bueno@metempsy.com entry.address = 0; 9113963Sodanrc@yahoo.com.br entry.counter.reset(); 9213669Sjavier.bueno@metempsy.com } 9313669Sjavier.bueno@metempsy.com } 9413669Sjavier.bueno@metempsy.com }; 9513669Sjavier.bueno@metempsy.com 9613669Sjavier.bueno@metempsy.com /** Physical-to-Structured mappings table */ 9713669Sjavier.bueno@metempsy.com AssociativeSet<AddressMappingEntry> psAddressMappingCache; 9813669Sjavier.bueno@metempsy.com /** Structured-to-Physical mappings table */ 9913669Sjavier.bueno@metempsy.com AssociativeSet<AddressMappingEntry> spAddressMappingCache; 10013669Sjavier.bueno@metempsy.com /** 10113669Sjavier.bueno@metempsy.com * Counter of allocated structural addresses, increased by "chunkSize", 10213669Sjavier.bueno@metempsy.com * each time a new structured address is allocated 10313669Sjavier.bueno@metempsy.com */ 10413669Sjavier.bueno@metempsy.com uint64_t structuralAddressCounter; 10513669Sjavier.bueno@metempsy.com 10613669Sjavier.bueno@metempsy.com /** 10713669Sjavier.bueno@metempsy.com * Add a mapping to the Structured-to-Physica mapping table 10813669Sjavier.bueno@metempsy.com * @param structuralAddress structural address 10913669Sjavier.bueno@metempsy.com * @param is_secure whether this page is inside the secure memory area 11013669Sjavier.bueno@metempsy.com * @param physical_address corresponding physical address 11113669Sjavier.bueno@metempsy.com */ 11213669Sjavier.bueno@metempsy.com void addStructuralToPhysicalEntry(Addr structuralAddress, bool is_secure, 11313669Sjavier.bueno@metempsy.com Addr physical_address); 11413669Sjavier.bueno@metempsy.com 11513669Sjavier.bueno@metempsy.com /** 11613669Sjavier.bueno@metempsy.com * Obtain the Physical-to-Structured mapping entry of the given physical 11713669Sjavier.bueno@metempsy.com * address. If the entry does not exist a new one is allocated, replacing 11813669Sjavier.bueno@metempsy.com * an existing one if needed. 11913669Sjavier.bueno@metempsy.com * @param paddr physical address 12013669Sjavier.bueno@metempsy.com * @param is_secure whether this page is inside the secure memory area 12113669Sjavier.bueno@metempsy.com * @result reference to the entry 12213669Sjavier.bueno@metempsy.com */ 12313669Sjavier.bueno@metempsy.com AddressMapping& getPSMapping(Addr paddr, bool is_secure); 12413669Sjavier.bueno@metempsy.com public: 12513669Sjavier.bueno@metempsy.com IrregularStreamBufferPrefetcher( 12613669Sjavier.bueno@metempsy.com const IrregularStreamBufferPrefetcherParams *p); 12713669Sjavier.bueno@metempsy.com ~IrregularStreamBufferPrefetcher() {} 12813669Sjavier.bueno@metempsy.com void calculatePrefetch(const PrefetchInfo &pfi, 12913669Sjavier.bueno@metempsy.com std::vector<AddrPriority> &addresses) override; 13013669Sjavier.bueno@metempsy.com}; 13113669Sjavier.bueno@metempsy.com#endif//__MEM_CACHE_PREFETCH_IRREGULAR_STREAM_BUFFER_HH__ 132