gem5 v24.0.0.0
Loading...
Searching...
No Matches
dramsys.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Fraunhofer IESE
3 * All rights reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "dramsys.hh"
30
31namespace gem5
32{
33
34namespace memory
35{
36
37DRAMSys::DRAMSys(Params const& params) :
38 AbstractMemory(params),
39 tlmWrapper(dramSysWrapper.tSocket, params.name + ".tlm", InvalidPortID),
40 config(::DRAMSys::Config::from_path(params.configuration,
41 params.resource_directory)),
42 dramSysWrapper(
43 params.name.c_str(), config, params.recordable, params.range)
44{
45 dramSysWrapper.dramsys->registerIdleCallback(
46 [this]
47 {
48 if (dramSysWrapper.dramsys->idle())
49 {
50 signalDrainDone();
51 }
52 });
53}
54
55gem5::Port& DRAMSys::getPort(const std::string& if_name, PortID idx)
56{
57 if (if_name != "tlm")
58 {
59 return AbstractMemory::getPort(if_name, idx);
60 }
61
62 return tlmWrapper;
63}
64
70
72{
73 std::filesystem::path checkpointPath = CheckpointIn::dir();
74
75 auto topLevelObjects = sc_core::sc_get_top_level_objects();
76 for (auto const* object : topLevelObjects)
77 {
78 std::function<void(sc_core::sc_object const*)> serialize;
79 serialize =
80 [&serialize, &checkpointPath](sc_core::sc_object const* object)
81 {
82 auto const* serializableObject =
83 dynamic_cast<::DRAMSys::Serialize const*>(object);
84
85 if (serializableObject != nullptr)
86 {
87 std::string dumpFileName(object->name());
88 dumpFileName += ".pmem";
89 std::ofstream stream(checkpointPath / dumpFileName,
90 std::ios::binary);
91 serializableObject->serialize(stream);
92 }
93
94 for (auto const* childObject : object->get_child_objects())
95 {
96 serialize(childObject);
97 }
98 };
99
100 serialize(object);
101 }
102}
103
105{
106 std::filesystem::path checkpointPath = CheckpointIn::dir();
107
108 auto topLevelObjects = sc_core::sc_get_top_level_objects();
109 for (auto* object : topLevelObjects)
110 {
111 std::function<void(sc_core::sc_object*)> deserialize;
112 deserialize =
113 [&deserialize, &checkpointPath](sc_core::sc_object* object)
114 {
115 auto* deserializableObject =
116 dynamic_cast<::DRAMSys::Deserialize*>(object);
117
118 if (deserializableObject != nullptr)
119 {
120 std::string dumpFileName(object->name());
121 dumpFileName += ".pmem";
122 std::ifstream stream(checkpointPath / dumpFileName,
123 std::ios::binary);
124 deserializableObject->deserialize(stream);
125 }
126
127 for (auto* childObject : object->get_child_objects())
128 {
129 deserialize(childObject);
130 }
131 };
132
133 deserialize(object);
134 }
135}
136
137} // namespace memory
138} // namespace gem5
ClockedObjectParams Params
Parameters of ClockedObject.
Ports are used to interface objects to each other.
Definition port.hh:62
An abstract memory represents a contiguous block of physical memory, with an associated address range...
std::shared_ptr<::DRAMSys::DRAMSys > dramsys
sc_gem5::TlmTargetWrapper tlmWrapper
Definition dramsys.hh:46
gem5::Port & getPort(const std::string &if_name, PortID idx) override
Get a port with a given name and index.
Definition dramsys.cc:55
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
Definition dramsys.cc:65
DRAMSys(Params const &params)
Definition dramsys.cc:37
DRAMSysWrapper dramSysWrapper
Definition dramsys.hh:60
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition dramsys.cc:71
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition dramsys.cc:104
DrainState
Object drain/handover states.
Definition drain.hh:75
@ Draining
Draining buffers pending serialization/handover.
@ Drained
Buffers drained, ready for serialization/handover.
static std::string dir()
Get the current checkout directory name.
Definition serialize.cc:157
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
const PortID InvalidPortID
Definition types.hh:246
std::ostream CheckpointOut
Definition serialize.hh:66
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
const std::vector< sc_object * > & sc_get_top_level_objects()
Definition sc_object.cc:161
Definition mem.h:38
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0