gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  CopyOut(tc, &data, addr, sizeof(T));
62 
63  data = TheISA::gtoh(data);
64 
65  return true;
66  }
67 
68  public:
69  ThreadInfo(ThreadContext *_tc, Addr _pcbb = 0)
70  : tc(_tc), sys(tc->getSystemPtr()), pcbb(_pcbb)
71  {
72 
73  }
75  {}
76 
77  inline Addr
79  {
81  panic("curThreadInfo() not implemented for this ISA");
82 
83  Addr addr = pcbb;
84  Addr sp;
85 
86  if (!addr)
88 
89  PortProxy &p = tc->getPhysProxy();
90  p.readBlob(addr, (uint8_t *)&sp, sizeof(Addr));
91 
92  return sp & ~ULL(0x3fff);
93  }
94 
95  inline Addr
97  {
98  int32_t offset;
99  if (!get_data("thread_info_task", offset))
100  return 0;
101 
102  if (!thread_info)
104 
105  Addr addr;
106  CopyOut(tc, &addr, thread_info + offset, sizeof(addr));
107 
108  return addr;
109  }
110 
111  int32_t
113  {
114  int32_t offset;
115  if (!get_data("task_struct_pid", offset))
116  return -1;
117 
118  int32_t pid;
119  CopyOut(tc, &pid, curTaskInfo(thread_info) + offset, sizeof(pid));
120 
121  return pid;
122  }
123 
124  int32_t
126  {
127  int32_t offset;
128  if (!get_data("task_struct_tgid", offset))
129  return -1;
130 
131  int32_t tgid;
132  CopyOut(tc, &tgid, curTaskInfo(thread_info) + offset, sizeof(tgid));
133 
134  return tgid;
135  }
136 
137  int64_t
139  {
140  int32_t offset;
141  if (!get_data("task_struct_start_time", offset))
142  return -1;
143 
144  int64_t data;
145  // start_time is actually of type timespec, but if we just
146  // grab the first long, we'll get the seconds out of it
147  CopyOut(tc, &data, curTaskInfo(thread_info) + offset, sizeof(data));
148 
149  return data;
150  }
151 
152  std::string
154  {
155  int32_t offset;
156  int32_t size;
157 
158  if (!get_data("task_struct_comm", offset))
159  return "FailureIn_curTaskName";
160 
161  if (!get_data("task_struct_comm_size", size))
162  return "FailureIn_curTaskName";
163 
164  char buffer[size + 1];
165  CopyStringOut(tc, buffer, curTaskInfo(thread_info) + offset, size);
166 
167  return buffer;
168  }
169 
170  int32_t
172  {
173  int32_t offset;
174  if (!get_data("task_struct_mm", offset))
175  return -1;
176 
177  int32_t mm_ptr;
178  CopyOut(tc, &mm_ptr, curTaskInfo(thread_info) + offset, sizeof(mm_ptr));
179 
180  return mm_ptr;
181  }
182 };
183 
184 } // namespace Linux
185 
186 #endif // __ARCH_GENERIC_LINUX_THREADINFO_HH__
Addr curTaskInfo(Addr thread_info=0)
Definition: threadinfo.hh:96
#define panic(...)
Definition: misc.hh:153
int64_t curTaskStart(Addr thread_info=0)
Definition: threadinfo.hh:138
const bool CurThreadInfoImplemented
Definition: isa_traits.hh:121
ip6_addr_t addr
Definition: inet.hh:335
virtual MiscReg readMiscRegNoEffect(int misc_reg) const =0
Bitfield< 0 > sp
Definition: miscregs.hh:1386
#define warn_once(...)
Definition: misc.hh:226
Definition: system.hh:83
Bitfield< 23, 0 > offset
Definition: types.hh:149
bool findAddress(const std::string &symbol, Addr &address) const
Definition: symtab.hh:97
void CopyOut(ThreadContext *tc, void *dest, Addr src, size_t cplen)
ThreadInfo(ThreadContext *_tc, Addr _pcbb=0)
Definition: threadinfo.hh:69
ThreadContext is the external interface to all thread state for anything outside of the CPU...
T gtoh(T value)
Definition: byteswap.hh:179
const char data[]
Definition: circlebuf.cc:43
virtual PortProxy & getPhysProxy()=0
This class encapsulates the types, structures, constants, functions, and syscall-number mappings spec...
Definition: linux.hh:48
void CopyStringOut(ThreadContext *tc, char *dst, Addr vaddr, size_t maxlen)
ThreadContext * tc
Definition: threadinfo.hh:45
Addr curThreadInfo()
Definition: threadinfo.hh:78
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
SymbolTable * kernelSymtab
kernel symbol table
Definition: system.hh:227
virtual void readBlob(Addr addr, uint8_t *p, int size) const
Read size bytes memory at address and store in p.
Definition: port_proxy.cc:45
This object is a proxy for a structural port, to be used for debug accesses.
Definition: port_proxy.hh:84
int size()
Definition: pagetable.hh:146
int32_t curTaskPID(Addr thread_info=0)
Definition: threadinfo.hh:112
int32_t curTaskMm(Addr thread_info=0)
Definition: threadinfo.hh:171
std::string curTaskName(Addr thread_info=0)
Definition: threadinfo.hh:153
const int CurThreadInfoReg
Definition: isa_traits.hh:122
int32_t curTaskTGID(Addr thread_info=0)
Definition: threadinfo.hh:125
Bitfield< 0 > p
bool get_data(const char *symbol, T &data)
Definition: threadinfo.hh:51

Generated on Fri Jun 9 2017 13:03:39 for gem5 by doxygen 1.8.6