gem5  v22.1.0.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(int 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 port %d.", name(),
101  gdb->port());
102  gdb->connect();
103  }
104 }
105 
106 } // namespace gem5
bool trap(ContextID id, int type)
Definition: remote_gdb.hh:55
void replaceThreadContext(ThreadContext *tc)
Definition: remote_gdb.hh:54
virtual std::string name() const
Definition: named.hh:47
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual ContextID contextId() const =0
virtual void replaceThreadContext(ThreadContext *tc)
Definition: workload.cc:51
BaseRemoteGDB * gdb
Definition: workload.hh:76
bool waitForRemoteGDB
Definition: workload.hh:77
void startup() override
startup() is the final initialization call before simulation.
Definition: workload.cc:93
bool trapToGdb(int signal, ContextID ctx_id)
Definition: workload.cc:75
virtual void registerThreadContext(ThreadContext *tc)
Definition: workload.cc:38
std::set< ThreadContext * > threads
Definition: workload.hh:78
bool sendToGdb(std::string msg)
Definition: workload.cc:84
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
bool sendMessage(std::string message)
Definition: remote_gdb.cc:585
void addThreadContext(ThreadContext *_tc)
Definition: remote_gdb.cc:510
int port() const
Definition: remote_gdb.cc:452
virtual void startup()
startup() is the final initialization call before simulation.
Definition: sim_object.cc:99
#define inform(...)
Definition: logging.hh:247
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
int ContextID
Globally unique thread context ID.
Definition: types.hh:239

Generated on Wed Dec 21 2022 10:22:27 for gem5 by doxygen 1.9.1