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