gem5  v19.0.0.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  * Authors: Gabe Black
28  */
29 
30 #ifndef __ARCH_ARM_FASTMODEL_IRIS_CPU_HH__
31 #define __ARCH_ARM_FASTMODEL_IRIS_CPU_HH__
32 
33 #include "cpu/base.hh"
34 #include "iris/detail/IrisInterface.h"
35 #include "params/IrisBaseCPU.hh"
39 
40 namespace Iris
41 {
42 
43 // The name of the event that should be notified when the CPU subsystem needs
44 // to adjust it's clock.
45 static const std::string ClockEventName = "gem5_clock_period_event";
46 // The name of the attribute the subsystem should create which can be set to
47 // the desired clock period, in gem5's Ticks.
48 static const std::string PeriodAttributeName = "gem5_clock_period_attribute";
49 // The name of the attribute the subsystem should create which will be set to
50 // a pointer to its corresponding gem5 CPU.
51 static const std::string Gem5CpuClusterAttributeName = "gem5_cpu_cluster";
52 // The name of the attribute the subsystem should create to hold the
53 // sendFunctional delegate for port proxies.
54 static const std::string SendFunctionalAttributeName = "gem5_send_functional";
55 
56 // This CPU class adds some mechanisms which help attach the gem5 and fast
57 // model CPUs to each other. It acts as a base class for the gem5 CPU, and
58 // holds a pointer to the EVS. It also has some methods for setting up some
59 // attributes in the fast model CPU to control its clock rate.
60 class BaseCPU : public ::BaseCPU
61 {
62  public:
63  BaseCPU(BaseCPUParams *params, sc_core::sc_module *_evs);
64  virtual ~BaseCPU();
65 
66  Port &
67  getDataPort() override
68  {
69  panic("%s not implemented.", __FUNCTION__);
70  }
71 
72  Port &
73  getInstPort() override
74  {
75  panic("%s not implemented.", __FUNCTION__);
76  }
77 
78  void
79  wakeup(ThreadID tid) override
80  {
81  auto *tc = threadContexts.at(tid);
82  if (tc->status() == ::ThreadContext::Suspended)
83  tc->activate();
84  }
85 
86  Counter totalInsts() const override;
87  Counter totalOps() const override { return totalInsts(); }
88 
90  getSendFunctional() override
91  {
92  if (sendFunctional)
93  return sendFunctional->value;
94  return ::BaseCPU::getSendFunctional();
95  }
96 
97  protected:
99 
100  private:
104 
105  protected:
106  void
108  {
109  if (!clockEvent || !periodAttribute) {
110  warn("Unable to notify EVS of clock change, missing:");
111  warn_if(!clockEvent, " Clock change event");
112  warn_if(!periodAttribute, " Clock period attribute");
113  return;
114  }
115 
116  periodAttribute->value = clockPeriod();
117  clockEvent->notify();
118  }
119 
120  void init() override;
121 
122  void serializeThread(CheckpointOut &cp, ThreadID tid) const override;
123 };
124 
125 // This class specializes the one above and sets up ThreadContexts based on
126 // its template parameters. These ThreadContexts provide the standard gem5
127 // interface and translate those accesses to use the Iris API to access that
128 // state in the target context.
129 template <class TC>
130 class CPU : public Iris::BaseCPU
131 {
132  public:
133  CPU(IrisBaseCPUParams *params, iris::IrisConnectionInterface *iris_if) :
134  BaseCPU(params, params->evs)
135  {
136  const std::string parent_path = evs->name();
137  System *sys = params->system;
138 
139  int thread_id = 0;
140  for (const std::string &sub_path: params->thread_paths) {
141  std::string path = parent_path + "." + sub_path;
142  auto *tc = new TC(this, thread_id++, sys,
143  params->dtb, params->itb,iris_if, path);
144  threadContexts.push_back(tc);
145  }
146  }
147 };
148 
149 } // namespace Iris
150 
151 #endif // __ARCH_ARM_FASTMODEL_IRIS_CPU_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
Ports are used to interface objects to each other.
Definition: port.hh:60
Counter totalOps() const override
Definition: cpu.hh:87
void wakeup(ThreadID tid) override
Definition: cpu.hh:79
static std::stack< std::string > path
Definition: serialize.hh:267
static const std::string PeriodAttributeName
Definition: cpu.hh:48
const char * name() const
Definition: sc_object.cc:46
Definition: system.hh:77
Definition: cprintf.cc:42
Tick clockPeriod() const
sc_core::sc_attribute< PortProxy::SendFunctionalFunc > * sendFunctional
Definition: cpu.hh:103
PortProxy::SendFunctionalFunc getSendFunctional() override
Returns a sendFunctional delegate for use with port proxies.
Definition: cpu.hh:90
std::vector< ThreadContext * > threadContexts
Definition: base.hh:267
sc_core::sc_module * evs
Definition: cpu.hh:98
sc_core::sc_attribute< Tick > * periodAttribute
Definition: cpu.hh:102
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Definition: logging.hh:228
Port & getInstPort() override
Purely virtual method that returns a reference to the instruction port.
Definition: cpu.hh:73
Port & getDataPort() override
Purely virtual method that returns a reference to the data port.
Definition: cpu.hh:67
CPU(IrisBaseCPUParams *params, iris::IrisConnectionInterface *iris_if)
Definition: cpu.hh:133
int64_t Counter
Statistics counter type.
Definition: types.hh:58
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: cpu.cc:90
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:227
static const std::string ClockEventName
Definition: cpu.hh:45
std::function< void(PacketPtr pkt)> SendFunctionalFunc
Definition: port_proxy.hh:85
void serializeThread(CheckpointOut &cp, ThreadID tid) const override
Serialize a single thread.
Definition: cpu.cc:98
static const std::string Gem5CpuClusterAttributeName
Definition: cpu.hh:51
std::ostream CheckpointOut
Definition: serialize.hh:68
static const std::string SendFunctionalAttributeName
Definition: cpu.hh:54
Temporarily inactive.
sc_core::sc_event * clockEvent
Definition: cpu.hh:101
#define warn(...)
Definition: logging.hh:212
BaseCPU(BaseCPUParams *params, sc_core::sc_module *_evs)
Definition: cpu.cc:39
Counter totalInsts() const override
Definition: cpu.cc:81
const Params * params() const
Definition: base.hh:311
virtual ~BaseCPU()
Definition: cpu.cc:73
void clockPeriodUpdated() override
A hook subclasses can implement so they can do any extra work that&#39;s needed when the clock rate is ch...
Definition: cpu.hh:107
Definition: cpu.cc:36

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13