WireBuffer.hh revision 11116
12068SN/A/*
22068SN/A * Copyright (c) 2010 Advanced Micro Devices, Inc.
32188SN/A * All rights reserved.
42068SN/A *
52068SN/A * Redistribution and use in source and binary forms, with or without
62068SN/A * modification, are permitted provided that the following conditions are
72068SN/A * met: redistributions of source code must retain the above copyright
82068SN/A * notice, this list of conditions and the following disclaimer;
92068SN/A * redistributions in binary form must reproduce the above copyright
102068SN/A * notice, this list of conditions and the following disclaimer in the
112068SN/A * documentation and/or other materials provided with the distribution;
122068SN/A * neither the name of the copyright holders nor the names of its
132068SN/A * contributors may be used to endorse or promote products derived from
142068SN/A * this software without specific prior written permission.
152068SN/A *
162068SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172068SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182068SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192068SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202068SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212068SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222068SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232068SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242068SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252068SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262068SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272068SN/A *
282665Ssaidi@eecs.umich.edu * Author: Lisa Hsu
292665Ssaidi@eecs.umich.edu *
302068SN/A */
312649Ssaidi@eecs.umich.edu
322649Ssaidi@eecs.umich.edu#ifndef __MEM_RUBY_STRUCTURES_WIREBUFFER_HH__
332649Ssaidi@eecs.umich.edu#define __MEM_RUBY_STRUCTURES_WIREBUFFER_HH__
342649Ssaidi@eecs.umich.edu
352649Ssaidi@eecs.umich.edu#include <iostream>
362068SN/A#include <string>
372068SN/A#include <vector>
382068SN/A
392068SN/A#include "mem/ruby/common/Consumer.hh"
402068SN/A#include "mem/ruby/slicc_interface/Message.hh"
412068SN/A#include "params/RubyWireBuffer.hh"
422068SN/A#include "sim/sim_object.hh"
432068SN/A
448588Sgblack@eecs.umich.edu//////////////////////////////////////////////////////////////////////////////
458588Sgblack@eecs.umich.edu// This object was written to literally mimic a Wire in Ruby, in the sense
468588Sgblack@eecs.umich.edu// that there is no way for messages to get reordered en route on the WireBuffer.
478588Sgblack@eecs.umich.edu// With Message Buffers, even if randomization is off and ordered is on,
488588Sgblack@eecs.umich.edu// messages can arrive in different orders than they were sent because of
498588Sgblack@eecs.umich.edu// network issues. This mimics a Wire, such that that is not possible. This can
502068SN/A// allow for messages between closely coupled controllers that are not actually
512068SN/A// separated by a network in real systems to simplify coherence.
522068SN/A/////////////////////////////////////////////////////////////////////////////
538588Sgblack@eecs.umich.edu
548588Sgblack@eecs.umich.educlass Message;
552068SN/A
562068SN/Aclass WireBuffer : public SimObject
578588Sgblack@eecs.umich.edu{
582075SN/A  public:
592068SN/A    typedef RubyWireBufferParams Params;
602068SN/A    WireBuffer(const Params *p);
612068SN/A    void init();
628588Sgblack@eecs.umich.edu
638588Sgblack@eecs.umich.edu    ~WireBuffer();
648588Sgblack@eecs.umich.edu
658588Sgblack@eecs.umich.edu    void wakeup();
668588Sgblack@eecs.umich.edu
678588Sgblack@eecs.umich.edu    void setConsumer(Consumer* consumer_ptr)
688588Sgblack@eecs.umich.edu    {
692068SN/A        m_consumer_ptr = consumer_ptr;
702068SN/A    }
712068SN/A    Consumer* getConsumer() { return m_consumer_ptr; };
728588Sgblack@eecs.umich.edu    void setDescription(const std::string& name) { m_description = name; };
732068SN/A    std::string getDescription() { return m_description; };
742069SN/A
752068SN/A    void enqueue(MsgPtr message, Tick current_time, Tick delta);
762068SN/A    void dequeue(Tick current_time);
774027Sstever@eecs.umich.edu    const Message* peek();
784027Sstever@eecs.umich.edu    void recycle(Tick current_time, Tick recycle_latency);
794027Sstever@eecs.umich.edu    bool isReady(Tick current_time);
806076Sgblack@eecs.umich.edu    // infinite queue length
818588Sgblack@eecs.umich.edu    bool areNSlotsAvailable(int n, Tick current_time) { return true; };
822068SN/A
832069SN/A    void print(std::ostream& out) const;
842068SN/A    uint64_t m_msg_counter;
852068SN/A
862068SN/A  private:
872068SN/A    // Private copy constructor and assignment operator
882068SN/A    WireBuffer (const WireBuffer& obj);
892068SN/A    WireBuffer& operator=(const WireBuffer& obj);
902068SN/A
912068SN/A    // data members
924027Sstever@eecs.umich.edu    Consumer* m_consumer_ptr;  // Consumer to signal a wakeup()
934027Sstever@eecs.umich.edu    std::string m_description;
944027Sstever@eecs.umich.edu
954027Sstever@eecs.umich.edu    // queues where memory requests live
964027Sstever@eecs.umich.edu    std::vector<MsgPtr> m_message_queue;
974027Sstever@eecs.umich.edu};
986076Sgblack@eecs.umich.edu
992068SN/Astd::ostream& operator<<(std::ostream& out, const WireBuffer& obj);
1002068SN/A
1012068SN/A#endif // __MEM_RUBY_STRUCTURES_WireBuffer_HH__
1022068SN/A