gem5  v21.0.1.0
cpu.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __ARCH_ARM_FASTMODEL_IRIS_CPU_HH__
29 #define __ARCH_ARM_FASTMODEL_IRIS_CPU_HH__
30 
31 #include "cpu/base.hh"
32 #include "iris/detail/IrisInterface.h"
33 #include "params/IrisBaseCPU.hh"
37 
38 namespace Iris
39 {
40 
41 // The base interface of the EVS used by gem5 BaseCPU below.
43 {
44  public:
45  virtual void sendFunc(PacketPtr pkt) = 0;
46  virtual void setClkPeriod(Tick clk_period) = 0;
47  virtual void setSysCounterFrq(uint64_t sys_counter_frq) = 0;
48  virtual void setCluster(SimObject *cluster) = 0;
49 };
50 
51 // This CPU class adds some mechanisms which help attach the gem5 and fast
52 // model CPUs to each other. It acts as a base class for the gem5 CPU, and
53 // holds a pointer to the EVS. It also has some methods for setting up some
54 // attributes in the fast model CPU to control its clock rate.
55 class BaseCPU : public ::BaseCPU
56 {
57  public:
58  BaseCPU(const BaseCPUParams &params, sc_core::sc_module *_evs);
59  virtual ~BaseCPU();
60 
61  Port &
62  getDataPort() override
63  {
64  panic("%s not implemented.", __FUNCTION__);
65  }
66 
67  Port &
68  getInstPort() override
69  {
70  panic("%s not implemented.", __FUNCTION__);
71  }
72 
73  void
74  wakeup(ThreadID tid) override
75  {
76  auto *tc = threadContexts.at(tid);
77  if (tc->status() == ::ThreadContext::Suspended)
78  tc->activate();
79  }
80 
81  Counter totalInsts() const override;
82  Counter totalOps() const override { return totalInsts(); }
83 
85  getSendFunctional() override
86  {
87  return [this] (PacketPtr pkt) { evs_base_cpu->sendFunc(pkt); };
88  }
89 
90  protected:
92  // Hold casted pointer to *evs.
94 
95  protected:
96  void
97  clockPeriodUpdated() override
98  {
100  }
101 
102  void init() override;
103 
104  void serializeThread(CheckpointOut &cp, ThreadID tid) const override;
105 };
106 
107 // This class specializes the one above and sets up ThreadContexts based on
108 // its template parameters. These ThreadContexts provide the standard gem5
109 // interface and translate those accesses to use the Iris API to access that
110 // state in the target context.
111 template <class TC>
112 class CPU : public Iris::BaseCPU
113 {
114  public:
115  CPU(const IrisBaseCPUParams &params,
116  iris::IrisConnectionInterface *iris_if) :
118  {
119  const std::string parent_path = evs->name();
120  System *sys = params.system;
121 
122  int thread_id = 0;
123  for (const std::string &sub_path: params.thread_paths) {
124  std::string path = parent_path + "." + sub_path;
125  auto id = thread_id++;
126  auto *tc = new TC(this, id, sys, params.mmu,
127  params.isa[id], iris_if, path);
128  threadContexts.push_back(tc);
129  }
130  }
131 };
132 
133 } // namespace Iris
134 
135 #endif // __ARCH_ARM_FASTMODEL_IRIS_CPU_HH__
Iris::BaseCPU::wakeup
void wakeup(ThreadID tid) override
Definition: cpu.hh:74
Iris::BaseCPU::clockPeriodUpdated
void clockPeriodUpdated() override
A hook subclasses can implement so they can do any extra work that's needed when the clock rate is ch...
Definition: cpu.hh:97
Iris
Definition: cpu.cc:34
sc_core::sc_module
Definition: sc_module.hh:97
Iris::BaseCPU::~BaseCPU
virtual ~BaseCPU()
Definition: cpu.cc:50
ThreadID
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:233
Iris::BaseCPU::serializeThread
void serializeThread(CheckpointOut &cp, ThreadID tid) const override
Serialize a single thread.
Definition: cpu.cc:75
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:59
Iris::BaseCPU::totalOps
Counter totalOps() const override
Definition: cpu.hh:82
Iris::BaseCpuEvs::setSysCounterFrq
virtual void setSysCounterFrq(uint64_t sys_counter_frq)=0
Iris::BaseCPU::evs_base_cpu
Iris::BaseCpuEvs * evs_base_cpu
Definition: cpu.hh:93
Iris::BaseCPU::getSendFunctional
PortProxy::SendFunctionalFunc getSendFunctional() override
Returns a sendFunctional delegate for use with port proxies.
Definition: cpu.hh:85
Iris::BaseCPU::totalInsts
Counter totalInsts() const override
Definition: cpu.cc:58
sc_event.hh
Counter
int64_t Counter
Statistics counter type.
Definition: types.hh:54
cp
Definition: cprintf.cc:37
Iris::BaseCPU::evs
sc_core::sc_module * evs
Definition: cpu.hh:91
Iris::BaseCpuEvs::setCluster
virtual void setCluster(SimObject *cluster)=0
Iris::CPU::CPU
CPU(const IrisBaseCPUParams &params, iris::IrisConnectionInterface *iris_if)
Definition: cpu.hh:115
System
Definition: system.hh:73
Iris::BaseCPU::getDataPort
Port & getDataPort() override
Purely virtual method that returns a reference to the data port.
Definition: cpu.hh:62
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
BaseCPU::threadContexts
std::vector< ThreadContext * > threadContexts
Definition: base.hh:269
PortProxy::SendFunctionalFunc
std::function< void(PacketPtr pkt)> SendFunctionalFunc
Definition: port_proxy.hh:83
Iris::BaseCPU::BaseCPU
BaseCPU(const BaseCPUParams &params, sc_core::sc_module *_evs)
Definition: cpu.cc:37
sc_module.hh
Clocked::clockPeriod
Tick clockPeriod() const
Definition: clocked_object.hh:214
Iris::BaseCpuEvs::sendFunc
virtual void sendFunc(PacketPtr pkt)=0
ThreadContext::Suspended
@ Suspended
Temporarily inactive.
Definition: thread_context.hh:107
base.hh
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
Iris::BaseCPU::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: cpu.cc:67
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:64
SimObject::params
const Params & params() const
Definition: sim_object.hh:168
Iris::BaseCPU::getInstPort
Port & getInstPort() override
Purely virtual method that returns a reference to the instruction port.
Definition: cpu.hh:68
Iris::BaseCPU
Definition: cpu.hh:55
Serializable::path
static std::stack< std::string > path
Definition: serialize.hh:321
Iris::BaseCpuEvs::setClkPeriod
virtual void setClkPeriod(Tick clk_period)=0
sc_attr.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
Iris::BaseCpuEvs
Definition: cpu.hh:42
Iris::CPU
Definition: cpu.hh:112
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:141

Generated on Tue Jun 22 2021 15:28:19 for gem5 by doxygen 1.8.17