gem5  v22.1.0.0
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 
36 namespace gem5
37 {
38 
40 namespace linux
41 {
42 
44 {
45  private:
48 
49  ByteOrder byteOrder;
50 
51  template <typename T>
52  bool
53  get_data(const char *symbol, T &data)
54  {
55  auto &symtab = sys->workload->symtab(tc);
56  auto it = symtab.find(symbol);
57  if (it == symtab.end()) {
58  warn_once("Unable to find kernel symbol %s\n", symbol);
59  warn_once("Kernel not compiled with task_struct info; can't get "
60  "currently executing task/process/thread name/ids!\n");
61  return false;
62  }
63 
64  data = TranslatingPortProxy(tc).read<T>(it->address, byteOrder);
65 
66  return true;
67  }
68 
69  public:
71  : tc(_tc), sys(tc->getSystemPtr()),
72  byteOrder(tc->getSystemPtr()->getGuestByteOrder())
73  {
74 
75  }
77  {}
78 
79  virtual Addr
81  {
82  panic("curThreadInfo() not implemented.");
83  }
84 
85  Addr
87  {
88  // Note that in Linux 4.10 the thread_info struct will no longer have a
89  // pointer to the task_struct for arm64. See:
90  // https://patchwork.kernel.org/patch/9333699/
91  int32_t offset = 0;
92  if (!get_data("thread_info_task", offset))
93  return 0;
94 
95  if (!thread_info)
97 
99  }
100 
101  int32_t
103  {
104  int32_t offset = 0;
105  if (!get_data("task_struct_pid", offset))
106  return -1;
107 
108  return TranslatingPortProxy(tc).read<int32_t>(task_struct + offset);
109  }
110 
111  int32_t
113  {
115  }
116 
117  int32_t
119  {
120  int32_t offset = 0;
121  if (!get_data("task_struct_tgid", offset))
122  return -1;
123 
124  return TranslatingPortProxy(tc).read<int32_t>(task_struct + offset);
125  }
126 
127  int32_t
129  {
131  }
132 
133  int64_t
135  {
136  int32_t offset = 0;
137  if (!get_data("task_struct_start_time", offset))
138  return -1;
139 
140  // start_time is actually of type timespec, but if we just
141  // grab the first long, we'll get the seconds out of it
142  return TranslatingPortProxy(tc).read<int64_t>(task_struct + offset);
143  }
144 
145  int64_t
147  {
149  }
150 
151  std::string
153  {
154  int32_t offset = 0;
155  int32_t size = 0;
156 
157  if (!get_data("task_struct_comm", offset))
158  return "FailureIn_curTaskName";
159 
160  if (!get_data("task_struct_comm_size", size))
161  return "FailureIn_curTaskName";
162 
163  char buffer[size + 1];
165  buffer, task_struct + offset, size);
166 
167  return buffer;
168  }
169 
170  std::string
172  {
174  }
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
188  {
190  }
191 };
192 
193 } // namespace linux
194 } // namespace gem5
195 
196 #endif // __ARCH_GENERIC_LINUX_THREADINFO_HH__
const char data[]
This class encapsulates the types, structures, constants, functions, and syscall-number mappings spec...
Definition: linux.hh:62
T read(Addr address) const
Read sizeof(T) bytes from address and return as object T.
Definition: port_proxy.hh:287
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
Definition: port_proxy.hh:260
Workload * workload
OS kernel.
Definition: system.hh:329
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)
Definition: threadinfo.hh:128
int64_t curTaskStartFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:134
int64_t curTaskStart(Addr thread_info=0)
Definition: threadinfo.hh:146
ThreadInfo(ThreadContext *_tc)
Definition: threadinfo.hh:70
int32_t curTaskMmFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:177
int32_t curTaskPID(Addr thread_info=0)
Definition: threadinfo.hh:112
int32_t curTaskMm(Addr thread_info=0)
Definition: threadinfo.hh:187
bool get_data(const char *symbol, T &data)
Definition: threadinfo.hh:53
Addr curTaskInfo(Addr thread_info=0)
Definition: threadinfo.hh:86
std::string curTaskName(Addr thread_info=0)
Definition: threadinfo.hh:171
virtual Addr curThreadInfo()
Definition: threadinfo.hh:80
ThreadContext * tc
Definition: threadinfo.hh:46
int32_t curTaskTGIDFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:118
std::string curTaskNameFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:152
int32_t curTaskPIDFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:102
const_iterator find(Addr address) const
Search for a symbol by its address.
Definition: symtab.hh:322
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define warn_once(...)
Definition: logging.hh:250
Bitfield< 23, 0 > offset
Definition: types.hh:144
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)

Generated on Wed Dec 21 2022 10:22:27 for gem5 by doxygen 1.9.1