WireBuffer.hh revision 9554
12810SN/A/*
29614Srene.dejong@arm.com * Copyright (c) 2010 Advanced Micro Devices, Inc.
38856Sandreas.hansson@arm.com * All rights reserved.
48856Sandreas.hansson@arm.com *
58856Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without
68856Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are
78856Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright
88856Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer;
98856Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright
108856Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the
118856Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution;
128856Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its
138856Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from
142810SN/A * this software without specific prior written permission.
152810SN/A *
162810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272810SN/A *
282810SN/A * Author: Lisa Hsu
292810SN/A *
302810SN/A */
312810SN/A
322810SN/A#ifndef __MEM_RUBY_SYSTEM_WIREBUFFER_HH__
332810SN/A#define __MEM_RUBY_SYSTEM_WIREBUFFER_HH__
342810SN/A
352810SN/A#include <iostream>
362810SN/A#include <string>
372810SN/A#include <vector>
382810SN/A
392810SN/A#include "mem/ruby/buffers/MessageBufferNode.hh"
402810SN/A#include "mem/ruby/common/Consumer.hh"
412810SN/A#include "params/RubyWireBuffer.hh"
422810SN/A#include "sim/sim_object.hh"
432810SN/A
442810SN/A//////////////////////////////////////////////////////////////////////////////
452810SN/A// This object was written to literally mimic a Wire in Ruby, in the sense
462810SN/A// that there is no way for messages to get reordered en route on the WireBuffer.
472810SN/A// With Message Buffers, even if randomization is off and ordered is on,
488232Snate@binkert.org// messages can arrive in different orders than they were sent because of
499152Satgutier@umich.edu// network issues. This mimics a Wire, such that that is not possible. This can
509795Sandreas.hansson@arm.com// allow for messages between closely coupled controllers that are not actually
519795Sandreas.hansson@arm.com// separated by a network in real systems to simplify coherence.
5210263Satgutier@umich.edu/////////////////////////////////////////////////////////////////////////////
535338Sstever@gmail.com
549795Sandreas.hansson@arm.comclass Message;
555338Sstever@gmail.com
568786Sgblack@eecs.umich.educlass WireBuffer : public SimObject
572810SN/A{
582810SN/A  public:
592810SN/A    typedef RubyWireBufferParams Params;
608856Sandreas.hansson@arm.com    WireBuffer(const Params *p);
618856Sandreas.hansson@arm.com    void init();
628856Sandreas.hansson@arm.com
638922Swilliam.wang@arm.com    ~WireBuffer();
648914Sandreas.hansson@arm.com
658856Sandreas.hansson@arm.com    void wakeup();
668856Sandreas.hansson@arm.com
674475SN/A    void setConsumer(Consumer* consumer_ptr)
685034SN/A    {
695034SN/A        m_consumer_ptr = consumer_ptr;
7010360Sandreas.hansson@arm.com    }
7110622Smitch.hayenga@arm.com    Consumer* getConsumer() { return m_consumer_ptr; };
7210622Smitch.hayenga@arm.com    void setDescription(const std::string& name) { m_description = name; };
734628SN/A    std::string getDescription() { return m_description; };
749814Sandreas.hansson@arm.com
7510693SMarco.Balboni@ARM.com    void enqueue(MsgPtr message, Cycles latency);
7610693SMarco.Balboni@ARM.com    void dequeue();
7710693SMarco.Balboni@ARM.com    const Message* peek();
789263Smrinmoy.ghosh@arm.com    MessageBufferNode peekNode();
795034SN/A    void recycle();
806122SSteve.Reinhardt@amd.com    bool isReady();
818134SAli.Saidi@ARM.com    bool areNSlotsAvailable(int n) { return true; };  // infinite queue length
824626SN/A
8310360Sandreas.hansson@arm.com    void print(std::ostream& out) const;
844626SN/A    void clearStats() const;
855034SN/A    void printStats(std::ostream& out) const;
868883SAli.Saidi@ARM.com
878833Sdam.sunwoo@arm.com    uint64_t m_msg_counter;
884458SN/A
892810SN/A  private:
902810SN/A    // Private copy constructor and assignment operator
913013SN/A    WireBuffer (const WireBuffer& obj);
928856Sandreas.hansson@arm.com    WireBuffer& operator=(const WireBuffer& obj);
932810SN/A
943013SN/A    // data members
9510714Sandreas.hansson@arm.com    Consumer* m_consumer_ptr;  // Consumer to signal a wakeup()
962810SN/A    std::string m_description;
979614Srene.dejong@arm.com
989614Srene.dejong@arm.com    // queues where memory requests live
999614Srene.dejong@arm.com    std::vector<MessageBufferNode> m_message_queue;
10010345SCurtis.Dunham@arm.com
10110714Sandreas.hansson@arm.com};
10210345SCurtis.Dunham@arm.com
1039614Srene.dejong@arm.comstd::ostream& operator<<(std::ostream& out, const WireBuffer& obj);
1042810SN/A
1052810SN/A#endif // __MEM_RUBY_SYSTEM_WireBuffer_HH__
1062810SN/A