gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
34namespace gem5
35{
36
37void
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)
48}
49
50void
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
74bool
75Workload::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};
83bool
84Workload::sendToGdb(std::string msg){
85 if (gdb)
86 return gdb->sendMessage(msg);
87 else
88 return false;
89 }
90
91
92void
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
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:77
bool waitForRemoteGDB
Definition workload.hh:78
void startup() override
startup() is the final initialization call before simulation.
Definition workload.cc:93
virtual void registerThreadContext(ThreadContext *tc)
Definition workload.cc:38
bool trapToGdb(GDBSignal sig, ContextID ctx_id)
Definition workload.cc:75
std::set< ThreadContext * > threads
Definition workload.hh:79
bool sendToGdb(std::string msg)
Definition workload.cc:84
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#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
bool sendMessage(std::string message)
const ListenSocket & hostSocket() const
void addThreadContext(ThreadContext *_tc)
virtual void startup()
startup() is the final initialization call before simulation.
Definition sim_object.cc:96
#define inform(...)
Definition logging.hh:257
Bitfield< 33 > id
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
int ContextID
Globally unique thread context ID.
Definition types.hh:239

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