gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Ali Saidi
29  * Nathan Binkert
30  * Dam Sunwoo
31  */
32 
33 #ifndef __ARCH_GENERIC_LINUX_THREADINFO_HH__
34 #define __ARCH_GENERIC_LINUX_THREADINFO_HH__
35 
36 #include "cpu/thread_context.hh"
37 #include "sim/system.hh"
38 #include "sim/vptr.hh"
39 
40 namespace Linux {
41 
43 {
44  private:
48 
49  template <typename T>
50  bool
51  get_data(const char *symbol, T &data)
52  {
53  Addr addr = 0;
54  if (!sys->kernelSymtab->findAddress(symbol, addr)) {
55  warn_once("Unable to find kernel symbol %s\n", symbol);
56  warn_once("Kernel not compiled with task_struct info; can't get "
57  "currently executing task/process/thread name/ids!\n");
58  return false;
59  }
60 
61  data = tc->getVirtProxy().read<T>(addr, TheISA::GuestByteOrder);
62 
63  return true;
64  }
65 
66  public:
67  ThreadInfo(ThreadContext *_tc, Addr _pcbb = 0)
68  : tc(_tc), sys(tc->getSystemPtr()), pcbb(_pcbb)
69  {
70 
71  }
73  {}
74 
75  inline Addr
77  {
79  panic("curThreadInfo() not implemented for this ISA");
80 
81  Addr addr = pcbb;
82  Addr sp;
83 
84  if (!addr)
86 
87  PortProxy &p = tc->getPhysProxy();
88  p.readBlob(addr, &sp, sizeof(Addr));
89 
90  return sp & ~ULL(0x3fff);
91  }
92 
93  inline Addr
95  {
96  // Note that in Linux 4.10 the thread_info struct will no longer have a
97  // pointer to the task_struct for arm64. See:
98  // https://patchwork.kernel.org/patch/9333699/
99  int32_t offset = 0;
100  if (!get_data("thread_info_task", offset))
101  return 0;
102 
103  if (!thread_info)
105 
106  return tc->getVirtProxy().read<Addr>(thread_info + offset);
107  }
108 
109  int32_t
111  int32_t offset = 0;
112  if (!get_data("task_struct_pid", offset))
113  return -1;
114 
115  return tc->getVirtProxy().read<int32_t>(task_struct + offset);
116  }
117 
118  int32_t
120  {
122  }
123 
124  int32_t
126  {
127  int32_t offset = 0;
128  if (!get_data("task_struct_tgid", offset))
129  return -1;
130 
131  return tc->getVirtProxy().read<int32_t>(task_struct + offset);
132  }
133 
134  int32_t
136  {
138  }
139 
140  int64_t
142  {
143  int32_t offset = 0;
144  if (!get_data("task_struct_start_time", offset))
145  return -1;
146 
147  // start_time is actually of type timespec, but if we just
148  // grab the first long, we'll get the seconds out of it
149  return tc->getVirtProxy().read<int64_t>(task_struct + offset);
150  }
151 
152  int64_t
154  {
156  }
157 
158  std::string
160  {
161  int32_t offset = 0;
162  int32_t size = 0;
163 
164  if (!get_data("task_struct_comm", offset))
165  return "FailureIn_curTaskName";
166 
167  if (!get_data("task_struct_comm_size", size))
168  return "FailureIn_curTaskName";
169 
170  char buffer[size + 1];
171  tc->getVirtProxy().readString(buffer, task_struct + offset, size);
172 
173  return buffer;
174  }
175 
176  std::string
178  {
180  }
181 
182  int32_t
184  {
185  int32_t offset;
186  if (!get_data("task_struct_mm", offset))
187  return -1;
188 
189  return tc->getVirtProxy().read<int32_t>(task_struct + offset);
190  }
191 
192  int32_t
194  {
196  }
197 };
198 
199 } // namespace Linux
200 
201 #endif // __ARCH_GENERIC_LINUX_THREADINFO_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
Addr curTaskInfo(Addr thread_info=0)
Definition: threadinfo.hh:94
int64_t curTaskStart(Addr thread_info=0)
Definition: threadinfo.hh:153
const bool CurThreadInfoImplemented
Definition: isa_traits.hh:112
ip6_addr_t addr
Definition: inet.hh:335
virtual PortProxy & getVirtProxy()=0
Bitfield< 0 > sp
T read(Addr address) const
Read sizeof(T) bytes from address and return as object T.
Definition: port_proxy.hh:284
Definition: system.hh:77
Bitfield< 23, 0 > offset
Definition: types.hh:154
std::string curTaskNameFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:159
int64_t curTaskStartFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:141
ThreadInfo(ThreadContext *_tc, Addr _pcbb=0)
Definition: threadinfo.hh:67
ThreadContext is the external interface to all thread state for anything outside of the CPU...
const ByteOrder GuestByteOrder
Definition: isa_traits.hh:42
int32_t curTaskMmFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:183
int32_t curTaskPIDFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:110
virtual PortProxy & getPhysProxy()=0
bool findAddress(const std::string &symbol, Addr &address) const
Definition: symtab.hh:97
int32_t curTaskTGIDFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:125
ThreadContext * tc
Definition: threadinfo.hh:45
Addr curThreadInfo()
Definition: threadinfo.hh:76
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
#define ULL(N)
uint64_t constant
Definition: types.hh:50
#define warn_once(...)
Definition: logging.hh:216
SymbolTable * kernelSymtab
kernel symbol table
Definition: system.hh:221
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
Definition: port_proxy.hh:179
This object is a proxy for a port or other object which implements the functional response protocol...
Definition: port_proxy.hh:82
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
Definition: port_proxy.hh:257
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
int32_t curTaskPID(Addr thread_info=0)
Definition: threadinfo.hh:119
int32_t curTaskMm(Addr thread_info=0)
Definition: threadinfo.hh:193
std::string curTaskName(Addr thread_info=0)
Definition: threadinfo.hh:177
const int CurThreadInfoReg
Definition: isa_traits.hh:113
int32_t curTaskTGID(Addr thread_info=0)
Definition: threadinfo.hh:135
Bitfield< 0 > p
const char data[]
bool get_data(const char *symbol, T &data)
Definition: threadinfo.hh:51

Generated on Fri Feb 28 2020 16:26:57 for gem5 by doxygen 1.8.13