gem5 v24.0.0.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 char buffer[size + 1];
164 buffer, task_struct + offset, size);
165
166 return buffer;
167 }
168
169 std::string
174
175 int32_t
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
190};
191
192} // namespace linux
193} // namespace gem5
194
195#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.
Workload * workload
OS kernel.
Definition system.hh:326
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.
virtual const loader::SymbolTable & symtab(ThreadContext *tc)=0
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)
const_iterator find(Addr address) const
Search for a symbol by its address.
Definition symtab.hh:435
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define warn_once(...)
Definition logging.hh:260
Bitfield< 23, 0 > offset
Definition types.hh:144
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria 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 Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0