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

Generated on Wed Sep 30 2020 14:01:58 for gem5 by doxygen 1.8.17