packet.hh

来自「M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作」· HH 代码 · 共 666 行 · 第 1/2 页

HH
666
字号
/* * Copyright (c) 2006 * The Regents of The University of Michigan * All Rights Reserved * * This code is part of the M5 simulator. * * Permission is granted to use, copy, create derivative works and * redistribute this software and such derivative works for any * purpose, so long as the copyright notice above, this grant of * permission, and the disclaimer below appear in all copies made; and * so long as the name of The University of Michigan is not used in * any advertising or publicity pertaining to the use or distribution * of this software without specific, written prior authorization. * * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND * WITHOUT WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE. THE REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE * LIABLE FOR ANY DAMAGES, INCLUDING DIRECT, SPECIAL, INDIRECT, * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM * ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH * DAMAGES. * * Authors: Ronald G. Dreslinski Jr *          Steven K. Reinhardt *          Ali G. Saidi *//** * @file * Declaration of the Packet class. */#ifndef __MEM_PACKET_HH__#define __MEM_PACKET_HH__#include <cassert>#include <list>#include <bitset>#include "base/compiler.hh"#include "base/fast_alloc.hh"#include "base/misc.hh"#include "base/printable.hh"#include "mem/request.hh"#include "sim/host.hh"#include "sim/core.hh"struct Packet;typedef Packet *PacketPtr;typedef uint8_t* PacketDataPtr;typedef std::list<PacketPtr> PacketList;class MemCmd{  public:    /** List of all commands associated with a packet. */    enum Command    {        InvalidCmd,        ReadReq,        ReadResp,        ReadRespWithInvalidate,        WriteReq,        WriteResp,        Writeback,        SoftPFReq,        HardPFReq,        SoftPFResp,        HardPFResp,        WriteInvalidateReq,        WriteInvalidateResp,        UpgradeReq,        UpgradeResp,        ReadExReq,        ReadExResp,        LoadLockedReq,        LoadLockedResp,        StoreCondReq,        StoreCondResp,        SwapReq,        SwapResp,        // Error responses        // @TODO these should be classified as responses rather than        // requests; coding them as requests initially for backwards        // compatibility        NetworkNackError,  // nacked at network layer (not by protocol)        InvalidDestError,  // packet dest field invalid        BadAddressError,   // memory address invalid        // Fake simulator-only commands        PrintReq,       // Print state matching address        NUM_MEM_CMDS    };  private:    /** List of command attributes. */    enum Attribute    {        IsRead,         //!< Data flows from responder to requester        IsWrite,        //!< Data flows from requester to responder        IsPrefetch,     //!< Not a demand access        IsInvalidate,        NeedsExclusive, //!< Requires exclusive copy to complete in-cache        IsRequest,      //!< Issued by requester        IsResponse,     //!< Issue by responder        NeedsResponse,  //!< Requester needs response from target        IsSWPrefetch,        IsHWPrefetch,        IsLocked,       //!< Alpha/MIPS LL or SC access        HasData,        //!< There is an associated payload        IsError,        //!< Error response        IsPrint,        //!< Print state matching address (for debugging)        NUM_COMMAND_ATTRIBUTES    };    /** Structure that defines attributes and other data associated     * with a Command. */    struct CommandInfo {        /** Set of attribute flags. */        const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;        /** Corresponding response for requests; InvalidCmd if no         * response is applicable. */        const Command response;        /** String representation (for printing) */        const std::string str;    };    /** Array to map Command enum to associated info. */    static const CommandInfo commandInfo[];  private:    Command cmd;    bool testCmdAttrib(MemCmd::Attribute attrib) const {        return commandInfo[cmd].attributes[attrib] != 0;    }  public:    bool isRead() const         { return testCmdAttrib(IsRead); }    bool isWrite()  const       { return testCmdAttrib(IsWrite); }    bool isRequest() const      { return testCmdAttrib(IsRequest); }    bool isResponse() const     { return testCmdAttrib(IsResponse); }    bool needsExclusive() const { return testCmdAttrib(NeedsExclusive); }    bool needsResponse() const  { return testCmdAttrib(NeedsResponse); }    bool isInvalidate() const   { return testCmdAttrib(IsInvalidate); }    bool hasData() const        { return testCmdAttrib(HasData); }    bool isReadWrite() const    { return isRead() && isWrite(); }    bool isLocked() const       { return testCmdAttrib(IsLocked); }    bool isError() const        { return testCmdAttrib(IsError); }    bool isPrint() const        { return testCmdAttrib(IsPrint); }    const Command responseCommand() const {        return commandInfo[cmd].response;    }    /** Return the string to a cmd given by idx. */    const std::string &toString() const {        return commandInfo[cmd].str;    }    int toInt() const { return (int)cmd; }    MemCmd(Command _cmd)        : cmd(_cmd)    { }    MemCmd(int _cmd)        : cmd((Command)_cmd)    { }    MemCmd()        : cmd(InvalidCmd)    { }    bool operator==(MemCmd c2) { return (cmd == c2.cmd); }    bool operator!=(MemCmd c2) { return (cmd != c2.cmd); }    friend class Packet;};/** * A Packet is used to encapsulate a transfer between two objects in * the memory system (e.g., the L1 and L2 cache).  (In contrast, a * single Request travels all the way from the requester to the * ultimate destination and back, possibly being conveyed by several * different Packets along the way.) */class Packet : public FastAlloc, public Printable{  public:    typedef MemCmd::Command Command;    /** The command field of the packet. */    MemCmd cmd;    /** A pointer to the original request. */    RequestPtr req;  private:   /** A pointer to the data being transfered.  It can be differnt    *    sizes at each level of the heirarchy so it belongs in the    *    packet, not request. This may or may not be populated when a    *    responder recieves the packet. If not populated it memory    *    should be allocated.    */    PacketDataPtr data;    /** Is the data pointer set to a value that shouldn't be freed     *   when the packet is destroyed? */    bool staticData;    /** The data pointer points to a value that should be freed when     *   the packet is destroyed. */    bool dynamicData;    /** the data pointer points to an array (thus delete [] ) needs to     *   be called on it rather than simply delete.*/    bool arrayData;    /** The address of the request.  This address could be virtual or     *   physical, depending on the system configuration. */    Addr addr;     /** The size of the request or transfer. */    int size;    /** Device address (e.g., bus ID) of the source of the     *   transaction. The source is not responsible for setting this     *   field; it is set implicitly by the interconnect when the     *   packet is first sent.  */    short src;    /** Device address (e.g., bus ID) of the destination of the     *   transaction. The special value Broadcast indicates that the     *   packet should be routed based on its address. This field is     *   initialized in the constructor and is thus always valid     *   (unlike * addr, size, and src). */    short dest;    /** The original value of the command field.  Only valid when the     * current command field is an error condition; in that case, the     * previous contents of the command field are copied here.  This     * field is *not* set on non-error responses.     */    MemCmd origCmd;    /** Are the 'addr' and 'size' fields valid? */    bool addrSizeValid;    /** Is the 'src' field valid? */    bool srcValid;    bool destValid;    enum Flag {        // Snoop response flags        MemInhibit,        Shared,        // Special control flags        /// Special timing-mode atomic snoop for multi-level coherence.        ExpressSnoop,        /// Does supplier have exclusive copy?        /// Useful for multi-level coherence.        SupplyExclusive,        NUM_PACKET_FLAGS    };    /** Status flags */    std::bitset<NUM_PACKET_FLAGS> flags;  public:    /** Used to calculate latencies for each packet.*/    Tick time;    /** The time at which the packet will be fully transmitted */    Tick finishTime;    /** The time at which the first chunk of the packet will be transmitted */    Tick firstWordTime;    /** The special destination address indicating that the packet     *   should be routed based on its address. */    static const short Broadcast = -1;    /** A virtual base opaque structure used to hold state associated     *    with the packet but specific to the sending device (e.g., an     *    MSHR).  A pointer to this state is returned in the packet's     *    response so that the sender can quickly look up the state     *    needed to process it.  A specific subclass would be derived     *    from this to carry state specific to a particular sending     *    device.  */    class SenderState : public FastAlloc {      public:        virtual ~SenderState() {}    };    /**     * Object used to maintain state of a PrintReq.  The senderState     * field of a PrintReq should always be of this type.     */    class PrintReqState : public SenderState {        /** An entry in the label stack. */        class LabelStackEntry {          public:            const std::string label;            std::string *prefix;            bool labelPrinted;            LabelStackEntry(const std::string &_label,                            std::string *_prefix);        };        typedef std::list<LabelStackEntry> LabelStack;        LabelStack labelStack;        std::string *curPrefixPtr;      public:        std::ostream &os;        const int verbosity;        PrintReqState(std::ostream &os, int verbosity = 0);        ~PrintReqState();        /** Returns the current line prefix. */        const std::string &curPrefix() { return *curPrefixPtr; }        /** Push a label onto the label stack, and prepend the given

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?