gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
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"
34#include "sim/system.hh"
35
36namespace gem5
37{
38
39namespace linux
40{
41
43{
44 private:
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:
70 : tc(_tc), sys(tc->getSystemPtr()),
71 byteOrder(tc->getSystemPtr()->getGuestByteOrder())
72 {
73
74 }
76 {}
77
78 virtual Addr
80 {
81 panic("curThreadInfo() not implemented.");
82 }
83
84 Addr
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)
96
98 }
99
100 int32_t
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
115
116 int32_t
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
131
132 int64_t
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
149
150 std::string
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 std::string buffer;
163 buffer.reserve(size + 1);
165 buffer.data(), task_struct + offset, size);
166
167 return buffer;
168 }
169
170 std::string
175
176 int32_t
178 {
179 int32_t offset;
180 if (!get_data("task_struct_mm", offset))
181 return -1;
182
183 return TranslatingPortProxy(tc).read<int32_t>(task_struct + offset);
184 }
185
186 int32_t
191};
192
193} // namespace linux
194} // namespace gem5
195
196#endif // __ARCH_GENERIC_LINUX_THREADINFO_HH__
const char data[]
T read(Addr address) const
Read sizeof(T) bytes from address and return as object T.
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
This proxy attempts to translate virtual addresses using the TLBs.
int32_t curTaskTGID(Addr thread_info=0)
int64_t curTaskStartFromTaskStruct(Addr task_struct)
int64_t curTaskStart(Addr thread_info=0)
ThreadInfo(ThreadContext *_tc)
Definition threadinfo.hh:69
int32_t curTaskMmFromTaskStruct(Addr task_struct)
int32_t curTaskPID(Addr thread_info=0)
int32_t curTaskMm(Addr thread_info=0)
bool get_data(const char *symbol, T &data)
Definition threadinfo.hh:52
Addr curTaskInfo(Addr thread_info=0)
Definition threadinfo.hh:85
std::string curTaskName(Addr thread_info=0)
virtual Addr curThreadInfo()
Definition threadinfo.hh:79
ThreadContext * tc
Definition threadinfo.hh:45
int32_t curTaskTGIDFromTaskStruct(Addr task_struct)
std::string curTaskNameFromTaskStruct(Addr task_struct)
int32_t curTaskPIDFromTaskStruct(Addr task_struct)
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:220
#define warn_once(...)
Definition logging.hh:292
Bitfield< 23, 0 > offset
Definition types.hh:144
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147

Generated on Mon May 26 2025 09:18:58 for gem5 by doxygen 1.13.2