gem5  v21.1.0.2
workload.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2021 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 #include "sim/workload.hh"
29 
30 #include "base/remote_gdb.hh"
31 #include "config/the_isa.hh"
32 #include "cpu/thread_context.hh"
33 #include "sim/debug.hh"
34 
35 namespace gem5
36 {
37 
38 void
40 {
41  std::set<ThreadContext *>::iterator it;
42  bool success;
43  std::tie(it, success) = threads.insert(tc);
44  panic_if(!success, "Failed to add thread context %d.",
45  tc->contextId());
46 
47 # if THE_ISA != NULL_ISA
48  if (gdb)
49  gdb->addThreadContext(tc);
50 # endif
51 }
52 
53 void
55 {
56  ContextID id = tc->contextId();
57 
58  for (auto *old: threads) {
59  if (old->contextId() != id)
60  continue;
61  threads.erase(old);
62 
63  std::set<ThreadContext *>::iterator it;
64  bool success;
65  std::tie(it, success) = threads.insert(tc);
66  panic_if(!success,
67  "Failed to insert replacement thread context %d.", id);
68 
69 # if THE_ISA != NULL_ISA
70  if (gdb)
72 # endif
73 
74  return;
75  }
76  panic("Replacement thread context %d doesn't match any known id.", id);
77 }
78 
79 bool
80 Workload::trapToGdb(int signal, ContextID ctx_id)
81 {
82 # if THE_ISA != NULL_ISA
83  if (gdb) {
84  gdb->trap(ctx_id, signal);
85  return true;
86  }
87 # endif
88  return false;
89 };
90 
91 void
93 {
95 
96 # if THE_ISA != NULL_ISA
97  // Now that we're about to start simulation, wait for GDB connections if
98  // requested.
99  if (gdb && waitForRemoteGDB) {
100  inform("%s: Waiting for a remote GDB connection on port %d.", name(),
101  gdb->port());
102  gdb->connect();
103  }
104 # endif
105 }
106 
107 } // namespace gem5
remote_gdb.hh
gem5::Workload::gdb
BaseRemoteGDB * gdb
Definition: workload.hh:74
gem5::ThreadContext::contextId
virtual ContextID contextId() const =0
workload.hh
gem5::BaseRemoteGDB::port
int port() const
Definition: remote_gdb.cc:410
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:93
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
debug.hh
gem5::Workload::threads
std::set< ThreadContext * > threads
Definition: workload.hh:76
gem5::Workload::waitForRemoteGDB
bool waitForRemoteGDB
Definition: workload.hh:75
gem5::BaseRemoteGDB::replaceThreadContext
void replaceThreadContext(ThreadContext *tc)
Definition: remote_gdb.hh:54
gem5::Workload::trapToGdb
bool trapToGdb(int signal, ContextID ctx_id)
Definition: workload.cc:80
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:203
gem5::BaseRemoteGDB::trap
bool trap(ContextID id, int type)
Definition: remote_gdb.hh:55
inform
#define inform(...)
Definition: logging.hh:246
gem5::SimObject::startup
virtual void startup()
startup() is the final initialization call before simulation.
Definition: sim_object.cc:99
gem5::Workload::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: workload.cc:92
gem5::Workload::replaceThreadContext
virtual void replaceThreadContext(ThreadContext *tc)
Definition: workload.cc:54
gem5::ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:246
gem5::BaseRemoteGDB::addThreadContext
void addThreadContext(ThreadContext *_tc)
Definition: remote_gdb.cc:443
gem5::Workload::registerThreadContext
virtual void registerThreadContext(ThreadContext *tc)
Definition: workload.cc:39
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::BaseRemoteGDB::connect
void connect()
Definition: remote_gdb.cc:394
thread_context.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177

Generated on Tue Sep 21 2021 12:25:48 for gem5 by doxygen 1.8.17