mshr_queue.hh revision 11377:a06a4debe272
15086Sgblack@eecs.umich.edu/*
25086Sgblack@eecs.umich.edu * Copyright (c) 2012-2013, 2015-2016 ARM Limited
38466Snilay@cs.wisc.edu * All rights reserved.
45086Sgblack@eecs.umich.edu *
55086Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall
67087Snate@binkert.org * not be construed as granting a license to any other intellectual
77087Snate@binkert.org * property including but not limited to intellectual property relating
87087Snate@binkert.org * to a hardware implementation of the functionality of the software
97087Snate@binkert.org * licensed hereunder.  You may use the software subject to the license
107087Snate@binkert.org * terms below provided that you ensure that this notice is replicated
117087Snate@binkert.org * unmodified and in its entirety in all distributions of the software,
127087Snate@binkert.org * modified or unmodified, in source code or in binary form.
137087Snate@binkert.org *
145086Sgblack@eecs.umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan
157087Snate@binkert.org * All rights reserved.
167087Snate@binkert.org *
177087Snate@binkert.org * Redistribution and use in source and binary forms, with or without
187087Snate@binkert.org * modification, are permitted provided that the following conditions are
197087Snate@binkert.org * met: redistributions of source code must retain the above copyright
207087Snate@binkert.org * notice, this list of conditions and the following disclaimer;
217087Snate@binkert.org * redistributions in binary form must reproduce the above copyright
227087Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
235086Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
247087Snate@binkert.org * neither the name of the copyright holders nor the names of its
255086Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
265086Sgblack@eecs.umich.edu * this software without specific prior written permission.
275086Sgblack@eecs.umich.edu *
285086Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
295086Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
305086Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
315086Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
325086Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
335086Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
345086Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
355086Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
365086Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
375086Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
385086Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
395086Sgblack@eecs.umich.edu *
405086Sgblack@eecs.umich.edu * Authors: Erik Hallnor
415647Sgblack@eecs.umich.edu *          Andreas Sandberg
428466Snilay@cs.wisc.edu */
438466Snilay@cs.wisc.edu
445086Sgblack@eecs.umich.edu/** @file
455135Sgblack@eecs.umich.edu * Declaration of a structure to manage MSHRs.
465647Sgblack@eecs.umich.edu */
475234Sgblack@eecs.umich.edu
485086Sgblack@eecs.umich.edu#ifndef __MEM_CACHE_MSHR_QUEUE_HH__
495086Sgblack@eecs.umich.edu#define __MEM_CACHE_MSHR_QUEUE_HH__
505086Sgblack@eecs.umich.edu
517707Sgblack@eecs.umich.edu#include <vector>
527707Sgblack@eecs.umich.edu
537707Sgblack@eecs.umich.edu#include "mem/cache/mshr.hh"
545086Sgblack@eecs.umich.edu#include "mem/cache/queue.hh"
555086Sgblack@eecs.umich.edu
565086Sgblack@eecs.umich.edu/**
575135Sgblack@eecs.umich.edu * A Class for maintaining a list of pending and allocated memory requests.
585135Sgblack@eecs.umich.edu */
595135Sgblack@eecs.umich.educlass MSHRQueue : public Queue<MSHR>
606048Sgblack@eecs.umich.edu{
616048Sgblack@eecs.umich.edu  private:
626048Sgblack@eecs.umich.edu
636048Sgblack@eecs.umich.edu    /**
646048Sgblack@eecs.umich.edu     * The number of entries to reserve for future demand accesses.
656048Sgblack@eecs.umich.edu     * Prevent prefetcher from taking all mshr entries
667720Sgblack@eecs.umich.edu     */
677720Sgblack@eecs.umich.edu    const int demandReserve;
687720Sgblack@eecs.umich.edu
697720Sgblack@eecs.umich.edu  public:
705135Sgblack@eecs.umich.edu
715135Sgblack@eecs.umich.edu    /**
725135Sgblack@eecs.umich.edu     * Create a queue with a given number of entries.
735135Sgblack@eecs.umich.edu     * @param num_entrys The number of entries in this queue.
745135Sgblack@eecs.umich.edu     * @param reserve The minimum number of entries needed to satisfy
755135Sgblack@eecs.umich.edu     * any access.
765135Sgblack@eecs.umich.edu     * @param demand_reserve The minimum number of entries needed to satisfy
775135Sgblack@eecs.umich.edu     * demand accesses.
785135Sgblack@eecs.umich.edu     */
795135Sgblack@eecs.umich.edu    MSHRQueue(const std::string &_label, int num_entries, int reserve,
805135Sgblack@eecs.umich.edu              int demand_reserve);
815135Sgblack@eecs.umich.edu
825135Sgblack@eecs.umich.edu    /**
835135Sgblack@eecs.umich.edu     * Allocates a new MSHR for the request and size. This places the request
845135Sgblack@eecs.umich.edu     * as the first target in the MSHR.
855135Sgblack@eecs.umich.edu     *
865135Sgblack@eecs.umich.edu     * @param blk_addr The address of the block.
875264Sgblack@eecs.umich.edu     * @param blk_size The number of bytes to request.
885135Sgblack@eecs.umich.edu     * @param pkt The original miss.
895135Sgblack@eecs.umich.edu     * @param when_ready When should the MSHR be ready to act upon.
905135Sgblack@eecs.umich.edu     * @param order The logical order of this MSHR
915135Sgblack@eecs.umich.edu     * @param alloc_on_fill Should the cache allocate a block on fill
925141Sgblack@eecs.umich.edu     *
935141Sgblack@eecs.umich.edu     * @return The a pointer to the MSHR allocated.
945141Sgblack@eecs.umich.edu     *
955141Sgblack@eecs.umich.edu     * @pre There are free entries.
965141Sgblack@eecs.umich.edu     */
975141Sgblack@eecs.umich.edu    MSHR *allocate(Addr blk_addr, unsigned blk_size, PacketPtr pkt,
985141Sgblack@eecs.umich.edu                   Tick when_ready, Counter order, bool alloc_on_fill);
995141Sgblack@eecs.umich.edu
1005141Sgblack@eecs.umich.edu    /**
1015182Sgblack@eecs.umich.edu     * Moves the MSHR to the front of the pending list if it is not
1025141Sgblack@eecs.umich.edu     * in service.
1035141Sgblack@eecs.umich.edu     * @param mshr The entry to move.
1045141Sgblack@eecs.umich.edu     */
1055141Sgblack@eecs.umich.edu    void moveToFront(MSHR *mshr);
1065141Sgblack@eecs.umich.edu
1075141Sgblack@eecs.umich.edu    /**
1085135Sgblack@eecs.umich.edu     * Mark the given MSHR as in service. This removes the MSHR from the
1095141Sgblack@eecs.umich.edu     * readyList or deallocates the MSHR if it does not expect a response.
1105141Sgblack@eecs.umich.edu     *
1115141Sgblack@eecs.umich.edu     * @param mshr The MSHR to mark in service.
1125141Sgblack@eecs.umich.edu     * @param pending_modified_resp Whether we expect a modified response
1135141Sgblack@eecs.umich.edu     *                              from another cache
1145141Sgblack@eecs.umich.edu     */
1155141Sgblack@eecs.umich.edu    void markInService(MSHR *mshr, bool pending_modified_resp);
1165141Sgblack@eecs.umich.edu
1175141Sgblack@eecs.umich.edu    /**
1185141Sgblack@eecs.umich.edu     * Mark an in service entry as pending, used to resend a request.
1195141Sgblack@eecs.umich.edu     * @param mshr The MSHR to resend.
1205141Sgblack@eecs.umich.edu     */
1215135Sgblack@eecs.umich.edu    void markPending(MSHR *mshr);
1225141Sgblack@eecs.umich.edu
1235141Sgblack@eecs.umich.edu    /**
1245135Sgblack@eecs.umich.edu     * Deallocate top target, possibly freeing the MSHR
1255141Sgblack@eecs.umich.edu     * @return if MSHR queue is no longer full
1265141Sgblack@eecs.umich.edu     */
1275141Sgblack@eecs.umich.edu    bool forceDeallocateTarget(MSHR *mshr);
1285141Sgblack@eecs.umich.edu
1295135Sgblack@eecs.umich.edu    /**
1305141Sgblack@eecs.umich.edu     * Returns true if the pending list is not empty.
1315141Sgblack@eecs.umich.edu     * @return True if there are outstanding requests.
1325141Sgblack@eecs.umich.edu     */
1335141Sgblack@eecs.umich.edu    bool havePending() const
1345141Sgblack@eecs.umich.edu    {
1355141Sgblack@eecs.umich.edu        return !readyList.empty();
1365141Sgblack@eecs.umich.edu    }
1375141Sgblack@eecs.umich.edu
1385141Sgblack@eecs.umich.edu    /**
1395141Sgblack@eecs.umich.edu     * Returns true if sufficient mshrs for prefetch.
1405141Sgblack@eecs.umich.edu     * @return True if sufficient mshrs for prefetch.
1415141Sgblack@eecs.umich.edu     */
1425264Sgblack@eecs.umich.edu    bool canPrefetch() const
1435141Sgblack@eecs.umich.edu    {
1445141Sgblack@eecs.umich.edu        // @todo we may want to revisit the +1, currently added to
1455141Sgblack@eecs.umich.edu        // keep regressions unchanged
1465141Sgblack@eecs.umich.edu        return (allocated < numEntries - (numReserve + 1 + demandReserve));
1475141Sgblack@eecs.umich.edu    }
1485141Sgblack@eecs.umich.edu};
1495141Sgblack@eecs.umich.edu
1505141Sgblack@eecs.umich.edu#endif //__MEM_CACHE_MSHR_QUEUE_HH__
1515141Sgblack@eecs.umich.edu