gem5  v21.1.0.2
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 
35 namespace gem5
36 {
37 
39 namespace 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 = tc->getVirtProxy().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 
97  return tc->getVirtProxy().read<Addr>(thread_info + offset);
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 tc->getVirtProxy().read<int32_t>(task_struct + offset);
108  }
109 
110  int32_t
112  {
114  }
115 
116  int32_t
118  {
119  int32_t offset = 0;
120  if (!get_data("task_struct_tgid", offset))
121  return -1;
122 
123  return tc->getVirtProxy().read<int32_t>(task_struct + offset);
124  }
125 
126  int32_t
128  {
130  }
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 tc->getVirtProxy().read<int64_t>(task_struct + offset);
142  }
143 
144  int64_t
146  {
148  }
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];
163  tc->getVirtProxy().readString(buffer, task_struct + offset, size);
164 
165  return buffer;
166  }
167 
168  std::string
170  {
172  }
173 
174  int32_t
176  {
177  int32_t offset;
178  if (!get_data("task_struct_mm", offset))
179  return -1;
180 
181  return tc->getVirtProxy().read<int32_t>(task_struct + offset);
182  }
183 
184  int32_t
186  {
188  }
189 };
190 
191 } // namespace linux
192 } // namespace gem5
193 
194 #endif // __ARCH_GENERIC_LINUX_THREADINFO_HH__
gem5::linux::ThreadInfo::curTaskMmFromTaskStruct
int32_t curTaskMmFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:175
gem5::linux::ThreadInfo::curTaskPID
int32_t curTaskPID(Addr thread_info=0)
Definition: threadinfo.hh:111
gem5::linux::ThreadInfo
Definition: threadinfo.hh:42
system.hh
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::PortProxy::readString
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
Definition: port_proxy.hh:260
gem5::linux::ThreadInfo::~ThreadInfo
~ThreadInfo()
Definition: threadinfo.hh:75
warn_once
#define warn_once(...)
Definition: logging.hh:249
gem5::linux::ThreadInfo::ThreadInfo
ThreadInfo(ThreadContext *_tc)
Definition: threadinfo.hh:69
gem5::linux::ThreadInfo::curTaskMm
int32_t curTaskMm(Addr thread_info=0)
Definition: threadinfo.hh:185
gem5::linux::thread_info
Definition: thread_info.hh:40
gem5::System::workload
Workload * workload
OS kernel.
Definition: system.hh:335
gem5::linux::ThreadInfo::curTaskPIDFromTaskStruct
int32_t curTaskPIDFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:101
gem5::linux::ThreadInfo::get_data
bool get_data(const char *symbol, T &data)
Definition: threadinfo.hh:52
gem5::linux::ThreadInfo::sys
System * sys
Definition: threadinfo.hh:46
gem5::linux::ThreadInfo::curTaskInfo
Addr curTaskInfo(Addr thread_info=0)
Definition: threadinfo.hh:85
gem5::System
Definition: system.hh:77
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:93
gem5::ThreadContext::getVirtProxy
virtual PortProxy & getVirtProxy()=0
gem5::PortProxy::read
T read(Addr address) const
Read sizeof(T) bytes from address and return as object T.
Definition: port_proxy.hh:287
gem5::linux::ThreadInfo::curTaskStart
int64_t curTaskStart(Addr thread_info=0)
Definition: threadinfo.hh:145
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::linux::ThreadInfo::curTaskNameFromTaskStruct
std::string curTaskNameFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:151
gem5::linux::ThreadInfo::curTaskTGID
int32_t curTaskTGID(Addr thread_info=0)
Definition: threadinfo.hh:127
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
gem5::linux::ThreadInfo::tc
ThreadContext * tc
Definition: threadinfo.hh:45
gem5::Workload::symtab
virtual const loader::SymbolTable & symtab(ThreadContext *tc)=0
gem5::linux::ThreadInfo::curTaskName
std::string curTaskName(Addr thread_info=0)
Definition: threadinfo.hh:169
gem5::loader::SymbolTable::find
const_iterator find(Addr address) const
Search for a symbol by its address.
Definition: symtab.hh:322
gem5::linux::ThreadInfo::curThreadInfo
virtual Addr curThreadInfo()
Definition: threadinfo.hh:79
gem5::linux::ThreadInfo::curTaskTGIDFromTaskStruct
int32_t curTaskTGIDFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:117
gem5::linux::ThreadInfo::byteOrder
ByteOrder byteOrder
Definition: threadinfo.hh:48
gem5::linux::ThreadInfo::curTaskStartFromTaskStruct
int64_t curTaskStartFromTaskStruct(Addr task_struct)
Definition: threadinfo.hh:133
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
thread_context.hh
gem5::loader::Linux
@ Linux
Definition: object_file.hh:73
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177

Generated on Tue Sep 21 2021 12:24:47 for gem5 by doxygen 1.8.17