gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 "cpu/thread_context.hh"
32 #include "sim/debug.hh"
33 
34 namespace gem5
35 {
36 
37 void
39 {
40  std::set<ThreadContext *>::iterator it;
41  bool success;
42  std::tie(it, success) = threads.insert(tc);
43  panic_if(!success, "Failed to add thread context %d.",
44  tc->contextId());
45 
46  if (gdb)
47  gdb->addThreadContext(tc);
48 }
49 
50 void
52 {
53  ContextID id = tc->contextId();
54 
55  for (auto *old: threads) {
56  if (old->contextId() != id)
57  continue;
58  threads.erase(old);
59 
60  std::set<ThreadContext *>::iterator it;
61  bool success;
62  std::tie(it, success) = threads.insert(tc);
63  panic_if(!success,
64  "Failed to insert replacement thread context %d.", id);
65 
66  if (gdb)
68 
69  return;
70  }
71  panic("Replacement thread context %d doesn't match any known id.", id);
72 }
73 
74 bool
75 Workload::trapToGdb(GDBSignal signal, ContextID ctx_id)
76 {
77  if (gdb && gdb->isAttached()) {
78  gdb->trap(ctx_id, signal);
79  return true;
80  }
81  return false;
82 };
83 bool
84 Workload::sendToGdb(std::string msg){
85  if (gdb)
86  return gdb->sendMessage(msg);
87  else
88  return false;
89  }
90 
91 
92 void
94 {
96 
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 %s.", name(),
101  gdb->hostSocket());
102  gdb->connect();
103  }
104 }
105 
106 } // namespace gem5
gem5::BaseRemoteGDB::hostSocket
const ListenSocket & hostSocket() const
Definition: remote_gdb.cc:448
gem5::BaseRemoteGDB::sendMessage
bool sendMessage(std::string message)
Definition: remote_gdb.cc:583
gem5::BaseRemoteGDB::isAttached
bool isAttached()
Definition: remote_gdb.hh:168
remote_gdb.hh
gem5::Workload::gdb
BaseRemoteGDB * gdb
Definition: workload.hh:77
gem5::ThreadContext::contextId
virtual ContextID contextId() const =0
gem5::Workload::trapToGdb
bool trapToGdb(GDBSignal sig, ContextID ctx_id)
Definition: workload.cc:75
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
workload.hh
debug.hh
gem5::Workload::threads
std::set< ThreadContext * > threads
Definition: workload.hh:79
gem5::Workload::waitForRemoteGDB
bool waitForRemoteGDB
Definition: workload.hh:78
gem5::Workload::sendToGdb
bool sendToGdb(std::string msg)
Definition: workload.cc:84
gem5::BaseRemoteGDB::replaceThreadContext
void replaceThreadContext(ThreadContext *tc)
Definition: remote_gdb.hh:54
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:214
gem5::BaseRemoteGDB::trap
bool trap(ContextID id, int type)
Definition: remote_gdb.hh:55
inform
#define inform(...)
Definition: logging.hh:257
gem5::SimObject::startup
virtual void startup()
startup() is the final initialization call before simulation.
Definition: sim_object.cc:96
gem5::Workload::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: workload.cc:93
gem5::Workload::replaceThreadContext
virtual void replaceThreadContext(ThreadContext *tc)
Definition: workload.cc:51
gem5::ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:239
gem5::BaseRemoteGDB::addThreadContext
void addThreadContext(ThreadContext *_tc)
Definition: remote_gdb.cc:506
gem5::Workload::registerThreadContext
virtual void registerThreadContext(ThreadContext *tc)
Definition: workload.cc:38
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::BaseRemoteGDB::connect
void connect()
Definition: remote_gdb.cc:430
thread_context.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188

Generated on Sun Jul 30 2023 01:56:50 for gem5 by doxygen 1.8.17