gem5  v20.0.0.2
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 
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 #include "sim/vptr.hh"
35 
36 namespace Linux {
37 
39 {
40  private:
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, TheISA::GuestByteOrder);
59 
60  return true;
61  }
62 
63  public:
64  ThreadInfo(ThreadContext *_tc, Addr _pcbb = 0)
65  : tc(_tc), sys(tc->getSystemPtr()), pcbb(_pcbb)
66  {
67 
68  }
70  {}
71 
72  inline Addr
74  {
76  panic("curThreadInfo() not implemented for this ISA");
77 
78  Addr addr = pcbb;
79  Addr sp;
80 
81  if (!addr)
83 
84  PortProxy &p = tc->getPhysProxy();
85  p.readBlob(addr, &sp, sizeof(Addr));
86 
87  return sp & ~ULL(0x3fff);
88  }
89 
90  inline Addr
92  {
93  // Note that in Linux 4.10 the thread_info struct will no longer have a
94  // pointer to the task_struct for arm64. See:
95  // https://patchwork.kernel.org/patch/9333699/
96  int32_t offset = 0;
97  if (!get_data("thread_info_task", offset))
98  return 0;
99 
100  if (!thread_info)
102 
103  return tc->getVirtProxy().read<Addr>(thread_info + offset);
104  }
105 
106  int32_t
108  int32_t offset = 0;
109  if (!get_data("task_struct_pid", offset))
110  return -1;
111 
112  return tc->getVirtProxy().read<int32_t>(task_struct + offset);
113  }
114 
115  int32_t
117  {
119  }
120 
121  int32_t
123  {
124  int32_t offset = 0;
125  if (!get_data("task_struct_tgid", offset))
126  return -1;
127 
128  return tc->getVirtProxy().read<int32_t>(task_struct + offset);
129  }
130 
131  int32_t
133  {
135  }
136 
137  int64_t
139  {
140  int32_t offset = 0;
141  if (!get_data("task_struct_start_time", offset))
142  return -1;
143 
144  // start_time is actually of type timespec, but if we just
145  // grab the first long, we'll get the seconds out of it
146  return tc->getVirtProxy().read<int64_t>(task_struct + offset);
147  }
148 
149  int64_t
151  {
153  }
154 
155  std::string
157  {
158  int32_t offset = 0;
159  int32_t size = 0;
160 
161  if (!get_data("task_struct_comm", offset))
162  return "FailureIn_curTaskName";
163 
164  if (!get_data("task_struct_comm_size", size))
165  return "FailureIn_curTaskName";
166 
167  char buffer[size + 1];
168  tc->getVirtProxy().readString(buffer, task_struct + offset, size);
169 
170  return buffer;
171  }
172 
173  std::string
175  {
177  }
178 
179  int32_t
181  {
182  int32_t offset;
183  if (!get_data("task_struct_mm", offset))
184  return -1;
185 
186  return tc->getVirtProxy().read<int32_t>(task_struct + offset);
187  }
188 
189  int32_t
191  {
193  }
194 };
195 
196 } // namespace Linux
197 
198 #endif // __ARCH_GENERIC_LINUX_THREADINFO_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
Addr curTaskInfo(Addr thread_info=0)
Definition: threadinfo.hh:91
virtual const Loader::SymbolTable * symtab(ThreadContext *tc)=0
const bool CurThreadInfoImplemented
Definition: isa_traits.hh:98
int64_t curTaskStart(Addr thread_info=0)
Definition: threadinfo.hh:150
ip6_addr_t addr
Definition: inet.hh:330
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:282
Definition: system.hh:72
Bitfield< 23, 0 > offset
Definition: types.hh:152
const int CurThreadInfoReg
Definition: isa_traits.hh:99
std::string curTaskNameFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:156
int64_t curTaskStartFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:138
ThreadInfo(ThreadContext *_tc, Addr _pcbb=0)
Definition: threadinfo.hh:64
ThreadContext is the external interface to all thread state for anything outside of the CPU...
int32_t curTaskMmFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:180
int32_t curTaskPIDFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:107
virtual PortProxy & getPhysProxy()=0
int32_t curTaskTGIDFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:122
ThreadContext * tc
Definition: threadinfo.hh:41
Workload * workload
OS kernel.
Definition: system.hh:213
Addr curThreadInfo()
Definition: threadinfo.hh:73
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
#define ULL(N)
uint64_t constant
Definition: types.hh:48
#define warn_once(...)
Definition: logging.hh:212
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
Definition: port_proxy.hh:177
This object is a proxy for a port or other object which implements the functional response protocol...
Definition: port_proxy.hh:80
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
Definition: port_proxy.hh:255
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
int32_t curTaskPID(Addr thread_info=0)
Definition: threadinfo.hh:116
int32_t curTaskMm(Addr thread_info=0)
Definition: threadinfo.hh:190
const_iterator find(Addr address) const
Definition: symtab.hh:181
std::string curTaskName(Addr thread_info=0)
Definition: threadinfo.hh:174
const ByteOrder GuestByteOrder
Definition: isa_traits.hh:51
int32_t curTaskTGID(Addr thread_info=0)
Definition: threadinfo.hh:132
Bitfield< 0 > p
const char data[]
bool get_data(const char *symbol, T &data)
Definition: threadinfo.hh:47

Generated on Mon Jun 8 2020 15:45:06 for gem5 by doxygen 1.8.13