write_queue_entry.hh revision 11375:f98df9231cdd
112952Sgabeblack@google.com/*
212952Sgabeblack@google.com * Copyright (c) 2012-2013, 2015-2016 ARM Limited
312952Sgabeblack@google.com * All rights reserved.
412952Sgabeblack@google.com *
512952Sgabeblack@google.com * The license below extends only to copyright in the software and shall
612952Sgabeblack@google.com * not be construed as granting a license to any other intellectual
712952Sgabeblack@google.com * property including but not limited to intellectual property relating
812952Sgabeblack@google.com * to a hardware implementation of the functionality of the software
912952Sgabeblack@google.com * licensed hereunder.  You may use the software subject to the license
1012952Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated
1112952Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software,
1212952Sgabeblack@google.com * modified or unmodified, in source code or in binary form.
1312952Sgabeblack@google.com *
1412952Sgabeblack@google.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
1512952Sgabeblack@google.com * All rights reserved.
1612952Sgabeblack@google.com *
1712952Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
1812952Sgabeblack@google.com * modification, are permitted provided that the following conditions are
1912952Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
2012952Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
2112952Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
2212952Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
2312952Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
2412952Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
2512952Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
2612952Sgabeblack@google.com * this software without specific prior written permission.
2712952Sgabeblack@google.com *
2812952Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2912952Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3012952Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3112957Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3212957Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3312957Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3413288Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3512953Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3613317Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3713196Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3813102Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3912998Sgabeblack@google.com *
4012998Sgabeblack@google.com * Authors: Erik Hallnor
4112952Sgabeblack@google.com *          Andreas Hansson
4212952Sgabeblack@google.com */
4312952Sgabeblack@google.com
4412952Sgabeblack@google.com/**
4512952Sgabeblack@google.com * @file
4612952Sgabeblack@google.com * Write queue entry
4712952Sgabeblack@google.com */
4812995Sgabeblack@google.com
4912952Sgabeblack@google.com#ifndef __MEM_CACHE_WRITE_QUEUE_ENTRY_HH__
5012952Sgabeblack@google.com#define __MEM_CACHE_WRITE_QUEUE_ENTRY_HH__
5112952Sgabeblack@google.com
5212952Sgabeblack@google.com#include <list>
5312952Sgabeblack@google.com
5412995Sgabeblack@google.com#include "base/printable.hh"
5512952Sgabeblack@google.com#include "mem/cache/queue_entry.hh"
5612952Sgabeblack@google.com
5712952Sgabeblack@google.comclass Cache;
5812952Sgabeblack@google.com
5912952Sgabeblack@google.com/**
6012952Sgabeblack@google.com * Write queue entry
6112952Sgabeblack@google.com */
6212952Sgabeblack@google.comclass WriteQueueEntry : public QueueEntry, public Printable
6312952Sgabeblack@google.com{
6412952Sgabeblack@google.com
6512952Sgabeblack@google.com    /**
6612952Sgabeblack@google.com     * Consider the queues friends to avoid making everything public.
6712952Sgabeblack@google.com     */
6812952Sgabeblack@google.com    template<typename Entry>
6912952Sgabeblack@google.com    friend class Queue;
7012952Sgabeblack@google.com    friend class WriteQueue;
7112952Sgabeblack@google.com
7212952Sgabeblack@google.com  public:
7312952Sgabeblack@google.com
7412952Sgabeblack@google.com    class Target {
7512952Sgabeblack@google.com      public:
7612952Sgabeblack@google.com
7712952Sgabeblack@google.com        const Tick recvTime;  //!< Time when request was received (for stats)
7812952Sgabeblack@google.com        const Tick readyTime; //!< Time when request is ready to be serviced
7912952Sgabeblack@google.com        const Counter order;  //!< Global order (for memory consistency mgmt)
8012952Sgabeblack@google.com        const PacketPtr pkt;  //!< Pending request packet.
8112952Sgabeblack@google.com
8212952Sgabeblack@google.com        Target(PacketPtr _pkt, Tick _readyTime, Counter _order)
8312952Sgabeblack@google.com            : recvTime(curTick()), readyTime(_readyTime), order(_order),
8412952Sgabeblack@google.com              pkt(_pkt)
8512952Sgabeblack@google.com        {}
8612952Sgabeblack@google.com    };
8713133Sgabeblack@google.com
8812952Sgabeblack@google.com    class TargetList : public std::list<Target> {
8913133Sgabeblack@google.com
9013133Sgabeblack@google.com      public:
9113133Sgabeblack@google.com
9213133Sgabeblack@google.com        TargetList() {}
9313133Sgabeblack@google.com        void add(PacketPtr pkt, Tick readyTime, Counter order);
9413133Sgabeblack@google.com        bool checkFunctional(PacketPtr pkt);
9513133Sgabeblack@google.com        void print(std::ostream &os, int verbosity,
9613133Sgabeblack@google.com                   const std::string &prefix) const;
9712952Sgabeblack@google.com    };
9812952Sgabeblack@google.com
9912952Sgabeblack@google.com    /** A list of write queue entriess. */
10012952Sgabeblack@google.com    typedef std::list<WriteQueueEntry *> List;
10112952Sgabeblack@google.com    /** WriteQueueEntry list iterator. */
10212952Sgabeblack@google.com    typedef List::iterator Iterator;
10312952Sgabeblack@google.com
10412952Sgabeblack@google.com    bool sendPacket(Cache &cache);
10512952Sgabeblack@google.com
10612952Sgabeblack@google.com  private:
10712952Sgabeblack@google.com
10812959Sgabeblack@google.com    /**
10913133Sgabeblack@google.com     * Pointer to this entry on the ready list.
11012959Sgabeblack@google.com     * @sa MissQueue, WriteQueue::readyList
11112952Sgabeblack@google.com     */
11212952Sgabeblack@google.com    Iterator readyIter;
11312952Sgabeblack@google.com
11412952Sgabeblack@google.com    /**
11512952Sgabeblack@google.com     * Pointer to this entry on the allocated list.
11612952Sgabeblack@google.com     * @sa MissQueue, WriteQueue::allocatedList
11712952Sgabeblack@google.com     */
11812952Sgabeblack@google.com    Iterator allocIter;
11912952Sgabeblack@google.com
12012999Sgabeblack@google.com    /** List of all requests that match the address */
12113206Sgabeblack@google.com    TargetList targets;
12212999Sgabeblack@google.com
12312999Sgabeblack@google.com  public:
12413317Sgabeblack@google.com
12512999Sgabeblack@google.com    /** A simple constructor. */
12612999Sgabeblack@google.com    WriteQueueEntry() {}
12712999Sgabeblack@google.com
12812952Sgabeblack@google.com    /**
12912952Sgabeblack@google.com     * Allocate a miss to this entry.
13012952Sgabeblack@google.com     * @param blk_addr The address of the block.
13112952Sgabeblack@google.com     * @param blk_size The number of bytes to request.
13212952Sgabeblack@google.com     * @param pkt The original write.
13312952Sgabeblack@google.com     * @param when_ready When should the write be sent out.
13412952Sgabeblack@google.com     * @param _order The logical order of this write.
13512952Sgabeblack@google.com     */
13612952Sgabeblack@google.com    void allocate(Addr blk_addr, unsigned blk_size, PacketPtr pkt,
13712952Sgabeblack@google.com                  Tick when_ready, Counter _order);
13812952Sgabeblack@google.com
13912952Sgabeblack@google.com    bool markInService();
14012952Sgabeblack@google.com
14112952Sgabeblack@google.com    /**
14212952Sgabeblack@google.com     * Mark this entry as free.
14312952Sgabeblack@google.com     */
14413102Sgabeblack@google.com    void deallocate();
14513317Sgabeblack@google.com
14613102Sgabeblack@google.com    /**
14713102Sgabeblack@google.com     * Returns the current number of allocated targets.
14813102Sgabeblack@google.com     * @return The current number of allocated targets.
14912952Sgabeblack@google.com     */
15012952Sgabeblack@google.com    int getNumTargets() const
15112952Sgabeblack@google.com    { return targets.size(); }
15212952Sgabeblack@google.com
15312952Sgabeblack@google.com    /**
15412952Sgabeblack@google.com     * Returns true if there are targets left.
15512952Sgabeblack@google.com     * @return true if there are targets
15612952Sgabeblack@google.com     */
15712995Sgabeblack@google.com    bool hasTargets() const { return !targets.empty(); }
15812998Sgabeblack@google.com
15912995Sgabeblack@google.com    /**
16012995Sgabeblack@google.com     * Returns a reference to the first target.
16112998Sgabeblack@google.com     * @return A pointer to the first target.
16212998Sgabeblack@google.com     */
16312998Sgabeblack@google.com    Target *getTarget()
16412998Sgabeblack@google.com    {
16512998Sgabeblack@google.com        assert(hasTargets());
16612998Sgabeblack@google.com        return &targets.front();
16712952Sgabeblack@google.com    }
16812952Sgabeblack@google.com
16912952Sgabeblack@google.com    /**
17012952Sgabeblack@google.com     * Pop first target.
17112952Sgabeblack@google.com     */
17213102Sgabeblack@google.com    void popTarget()
17313317Sgabeblack@google.com    {
17413317Sgabeblack@google.com        targets.pop_front();
17513102Sgabeblack@google.com    }
17613102Sgabeblack@google.com
17712952Sgabeblack@google.com    bool checkFunctional(PacketPtr pkt);
17812952Sgabeblack@google.com
17912952Sgabeblack@google.com    /**
18012952Sgabeblack@google.com     * Prints the contents of this MSHR for debugging.
18112952Sgabeblack@google.com     */
18212952Sgabeblack@google.com    void print(std::ostream &os,
18312952Sgabeblack@google.com               int verbosity = 0,
18412952Sgabeblack@google.com               const std::string &prefix = "") const;
18513310Sgabeblack@google.com    /**
18613310Sgabeblack@google.com     * A no-args wrapper of print(std::ostream...)  meant to be
18712995Sgabeblack@google.com     * invoked from DPRINTFs avoiding string overheads in fast mode
18813261Sgabeblack@google.com     *
18913261Sgabeblack@google.com     * @return string with mshr fields
19012998Sgabeblack@google.com     */
19112998Sgabeblack@google.com    std::string print() const;
19212998Sgabeblack@google.com};
19312998Sgabeblack@google.com
19412998Sgabeblack@google.com#endif // __MEM_CACHE_WRITE_QUEUE_ENTRY_HH__
19512998Sgabeblack@google.com