gem5
v24.0.0.0
Loading...
Searching...
No Matches
arch
generic
linux
threadinfo.hh
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2004 The Regents of The University of Michigan
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
#ifndef __ARCH_GENERIC_LINUX_THREADINFO_HH__
30
#define __ARCH_GENERIC_LINUX_THREADINFO_HH__
31
32
#include "
cpu/thread_context.hh
"
33
#include "
mem/translating_port_proxy.hh
"
34
#include "
sim/system.hh
"
35
36
namespace
gem5
37
{
38
39
namespace
linux
40
{
41
42
class
ThreadInfo
43
{
44
private
:
45
ThreadContext
*
tc
;
46
System
*
sys
;
47
48
ByteOrder
byteOrder
;
49
50
template
<
typename
T>
51
bool
52
get_data
(
const
char
*symbol, T &
data
)
53
{
54
auto
&symtab =
sys
->
workload
->
symtab
(
tc
);
55
auto
it = symtab.
find
(symbol);
56
if
(it == symtab.end()) {
57
warn_once
(
"Unable to find kernel symbol %s\n"
, symbol);
58
warn_once
(
"Kernel not compiled with task_struct info; can't get "
59
"currently executing task/process/thread name/ids!\n"
);
60
return
false
;
61
}
62
63
data
=
TranslatingPortProxy
(
tc
).
read
<T>(it->address(),
byteOrder
);
64
65
return
true
;
66
}
67
68
public
:
69
ThreadInfo
(
ThreadContext
*_tc)
70
:
tc
(_tc),
sys
(
tc
->getSystemPtr()),
71
byteOrder
(
tc
->getSystemPtr()->getGuestByteOrder())
72
{
73
74
}
75
~ThreadInfo
()
76
{}
77
78
virtual
Addr
79
curThreadInfo
()
80
{
81
panic
(
"curThreadInfo() not implemented."
);
82
}
83
84
Addr
85
curTaskInfo
(
Addr
thread_info
= 0)
86
{
87
// Note that in Linux 4.10 the thread_info struct will no longer have a
88
// pointer to the task_struct for arm64. See:
89
// https://patchwork.kernel.org/patch/9333699/
90
int32_t
offset
= 0;
91
if
(!
get_data
(
"thread_info_task"
,
offset
))
92
return
0;
93
94
if
(!
thread_info
)
95
thread_info
=
curThreadInfo
();
96
97
return
TranslatingPortProxy
(
tc
).
read
<
Addr
>(
thread_info
+
offset
);
98
}
99
100
int32_t
101
curTaskPIDFromTaskStruct
(
Addr
task_struct)
102
{
103
int32_t
offset
= 0;
104
if
(!
get_data
(
"task_struct_pid"
,
offset
))
105
return
-1;
106
107
return
TranslatingPortProxy
(
tc
).
read
<int32_t>(task_struct +
offset
);
108
}
109
110
int32_t
111
curTaskPID
(
Addr
thread_info
= 0)
112
{
113
return
curTaskPIDFromTaskStruct
(
curTaskInfo
(
thread_info
));
114
}
115
116
int32_t
117
curTaskTGIDFromTaskStruct
(
Addr
task_struct)
118
{
119
int32_t
offset
= 0;
120
if
(!
get_data
(
"task_struct_tgid"
,
offset
))
121
return
-1;
122
123
return
TranslatingPortProxy
(
tc
).
read
<int32_t>(task_struct +
offset
);
124
}
125
126
int32_t
127
curTaskTGID
(
Addr
thread_info
= 0)
128
{
129
return
curTaskTGIDFromTaskStruct
(
curTaskInfo
(
thread_info
));
130
}
131
132
int64_t
133
curTaskStartFromTaskStruct
(
Addr
task_struct)
134
{
135
int32_t
offset
= 0;
136
if
(!
get_data
(
"task_struct_start_time"
,
offset
))
137
return
-1;
138
139
// start_time is actually of type timespec, but if we just
140
// grab the first long, we'll get the seconds out of it
141
return
TranslatingPortProxy
(
tc
).
read
<int64_t>(task_struct +
offset
);
142
}
143
144
int64_t
145
curTaskStart
(
Addr
thread_info
= 0)
146
{
147
return
curTaskStartFromTaskStruct
(
curTaskInfo
(
thread_info
));
148
}
149
150
std::string
151
curTaskNameFromTaskStruct
(
Addr
task_struct)
152
{
153
int32_t
offset
= 0;
154
int32_t size = 0;
155
156
if
(!
get_data
(
"task_struct_comm"
,
offset
))
157
return
"FailureIn_curTaskName"
;
158
159
if
(!
get_data
(
"task_struct_comm_size"
, size))
160
return
"FailureIn_curTaskName"
;
161
162
char
buffer[size + 1];
163
TranslatingPortProxy
(
tc
).
readString
(
164
buffer, task_struct +
offset
, size);
165
166
return
buffer;
167
}
168
169
std::string
170
curTaskName
(
Addr
thread_info
= 0)
171
{
172
return
curTaskNameFromTaskStruct
(
curTaskInfo
(
thread_info
));
173
}
174
175
int32_t
176
curTaskMmFromTaskStruct
(
Addr
task_struct)
177
{
178
int32_t
offset
;
179
if
(!
get_data
(
"task_struct_mm"
,
offset
))
180
return
-1;
181
182
return
TranslatingPortProxy
(
tc
).
read
<int32_t>(task_struct +
offset
);
183
}
184
185
int32_t
186
curTaskMm
(
Addr
thread_info
= 0)
187
{
188
return
curTaskMmFromTaskStruct
(
curTaskInfo
(
thread_info
));
189
}
190
};
191
192
}
// namespace linux
193
}
// namespace gem5
194
195
#endif
// __ARCH_GENERIC_LINUX_THREADINFO_HH__
data
const char data[]
Definition
circlebuf.test.cc:48
gem5::PortProxy::read
T read(Addr address) const
Read sizeof(T) bytes from address and return as object T.
Definition
port_proxy.hh:287
gem5::PortProxy::readString
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
Definition
port_proxy.hh:260
gem5::System
Definition
system.hh:75
gem5::System::workload
Workload * workload
OS kernel.
Definition
system.hh:326
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition
guest_abi.test.cc:41
gem5::TranslatingPortProxy
This proxy attempts to translate virtual addresses using the TLBs.
Definition
translating_port_proxy.hh:61
gem5::Workload::symtab
virtual const loader::SymbolTable & symtab(ThreadContext *tc)=0
gem5::linux::ThreadInfo
Definition
threadinfo.hh:43
gem5::linux::ThreadInfo::curTaskTGID
int32_t curTaskTGID(Addr thread_info=0)
Definition
threadinfo.hh:127
gem5::linux::ThreadInfo::curTaskStartFromTaskStruct
int64_t curTaskStartFromTaskStruct(Addr task_struct)
Definition
threadinfo.hh:133
gem5::linux::ThreadInfo::curTaskStart
int64_t curTaskStart(Addr thread_info=0)
Definition
threadinfo.hh:145
gem5::linux::ThreadInfo::ThreadInfo
ThreadInfo(ThreadContext *_tc)
Definition
threadinfo.hh:69
gem5::linux::ThreadInfo::~ThreadInfo
~ThreadInfo()
Definition
threadinfo.hh:75
gem5::linux::ThreadInfo::curTaskMmFromTaskStruct
int32_t curTaskMmFromTaskStruct(Addr task_struct)
Definition
threadinfo.hh:176
gem5::linux::ThreadInfo::curTaskPID
int32_t curTaskPID(Addr thread_info=0)
Definition
threadinfo.hh:111
gem5::linux::ThreadInfo::curTaskMm
int32_t curTaskMm(Addr thread_info=0)
Definition
threadinfo.hh:186
gem5::linux::ThreadInfo::get_data
bool get_data(const char *symbol, T &data)
Definition
threadinfo.hh:52
gem5::linux::ThreadInfo::curTaskInfo
Addr curTaskInfo(Addr thread_info=0)
Definition
threadinfo.hh:85
gem5::linux::ThreadInfo::sys
System * sys
Definition
threadinfo.hh:46
gem5::linux::ThreadInfo::curTaskName
std::string curTaskName(Addr thread_info=0)
Definition
threadinfo.hh:170
gem5::linux::ThreadInfo::curThreadInfo
virtual Addr curThreadInfo()
Definition
threadinfo.hh:79
gem5::linux::ThreadInfo::tc
ThreadContext * tc
Definition
threadinfo.hh:45
gem5::linux::ThreadInfo::curTaskTGIDFromTaskStruct
int32_t curTaskTGIDFromTaskStruct(Addr task_struct)
Definition
threadinfo.hh:117
gem5::linux::ThreadInfo::curTaskNameFromTaskStruct
std::string curTaskNameFromTaskStruct(Addr task_struct)
Definition
threadinfo.hh:151
gem5::linux::ThreadInfo::byteOrder
ByteOrder byteOrder
Definition
threadinfo.hh:48
gem5::linux::ThreadInfo::curTaskPIDFromTaskStruct
int32_t curTaskPIDFromTaskStruct(Addr task_struct)
Definition
threadinfo.hh:101
gem5::loader::SymbolTable::find
const_iterator find(Addr address) const
Search for a symbol by its address.
Definition
symtab.hh:435
thread_context.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition
logging.hh:188
warn_once
#define warn_once(...)
Definition
logging.hh:260
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition
types.hh:144
gem5
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition
binary32.hh:36
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition
types.hh:147
system.hh
gem5::linux::thread_info
Definition
thread_info.hh:40
translating_port_proxy.hh
Generated on Tue Jun 18 2024 16:23:57 for gem5 by
doxygen
1.11.0