irregular_stream_buffer.hh revision 13669
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" 4413669Sjavier.bueno@metempsy.com#include "mem/cache/prefetch/associative_set.hh" 4513669Sjavier.bueno@metempsy.com#include "mem/cache/prefetch/queued.hh" 4613669Sjavier.bueno@metempsy.com 4713669Sjavier.bueno@metempsy.comstruct IrregularStreamBufferPrefetcherParams; 4813669Sjavier.bueno@metempsy.com 4913669Sjavier.bueno@metempsy.comclass IrregularStreamBufferPrefetcher : public QueuedPrefetcher 5013669Sjavier.bueno@metempsy.com{ 5113669Sjavier.bueno@metempsy.com /** Maximum value of the confidence counters */ 5213669Sjavier.bueno@metempsy.com const unsigned maxCounterValue; 5313669Sjavier.bueno@metempsy.com /** Size in bytes of a temporal stream */ 5413669Sjavier.bueno@metempsy.com const size_t chunkSize; 5513669Sjavier.bueno@metempsy.com /** Number of prefetch candidates per Physical-to-Structural entry */ 5613669Sjavier.bueno@metempsy.com const unsigned prefetchCandidatesPerEntry; 5713669Sjavier.bueno@metempsy.com /** Number of maximum prefetches requests created when predicting */ 5813669Sjavier.bueno@metempsy.com const unsigned degree; 5913669Sjavier.bueno@metempsy.com 6013669Sjavier.bueno@metempsy.com /** 6113669Sjavier.bueno@metempsy.com * Training Unit Entry datatype, it holds the last accessed address and 6213669Sjavier.bueno@metempsy.com * its secure flag 6313669Sjavier.bueno@metempsy.com */ 6413669Sjavier.bueno@metempsy.com struct TrainingUnitEntry : public TaggedEntry { 6513669Sjavier.bueno@metempsy.com Addr lastAddress; 6613669Sjavier.bueno@metempsy.com bool lastAddressSecure; 6713669Sjavier.bueno@metempsy.com }; 6813669Sjavier.bueno@metempsy.com /** Map of PCs to Training unit entries */ 6913669Sjavier.bueno@metempsy.com AssociativeSet<TrainingUnitEntry> trainingUnit; 7013669Sjavier.bueno@metempsy.com 7113669Sjavier.bueno@metempsy.com /** Address Mapping entry, holds an address and a confidence counter */ 7213669Sjavier.bueno@metempsy.com struct AddressMapping { 7313669Sjavier.bueno@metempsy.com Addr address; 7413669Sjavier.bueno@metempsy.com unsigned counter; 7513669Sjavier.bueno@metempsy.com AddressMapping() : address(0), counter(0) 7613669Sjavier.bueno@metempsy.com {} 7713669Sjavier.bueno@metempsy.com }; 7813669Sjavier.bueno@metempsy.com 7913669Sjavier.bueno@metempsy.com /** 8013669Sjavier.bueno@metempsy.com * Maps a set of contiguous addresses to another set of (not necessarily 8113669Sjavier.bueno@metempsy.com * contiguos) addresses, with their corresponding confidence counters 8213669Sjavier.bueno@metempsy.com */ 8313669Sjavier.bueno@metempsy.com struct AddressMappingEntry : public TaggedEntry { 8413669Sjavier.bueno@metempsy.com std::vector<AddressMapping> mappings; 8513669Sjavier.bueno@metempsy.com AddressMappingEntry(size_t num_mappings) : mappings(num_mappings) 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; 9113669Sjavier.bueno@metempsy.com entry.counter = 0; 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