thread.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __PERF_THREAD_H
  3. #define __PERF_THREAD_H
  4. #include <linux/refcount.h>
  5. #include <linux/rbtree.h>
  6. #include <linux/list.h>
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include <sys/types.h>
  10. #include "srccode.h"
  11. #include "symbol_conf.h"
  12. #include <strlist.h>
  13. #include <intlist.h>
  14. #include "rwsem.h"
  15. #include "event.h"
  16. #include "callchain.h"
  17. struct addr_location;
  18. struct map;
  19. struct perf_record_namespaces;
  20. struct thread_stack;
  21. struct unwind_libunwind_ops;
  22. struct lbr_stitch {
  23. struct list_head lists;
  24. struct list_head free_lists;
  25. struct perf_sample prev_sample;
  26. struct callchain_cursor_node *prev_lbr_cursor;
  27. };
  28. struct thread {
  29. union {
  30. struct rb_node rb_node;
  31. struct list_head node;
  32. };
  33. struct maps *maps;
  34. pid_t pid_; /* Not all tools update this */
  35. pid_t tid;
  36. pid_t ppid;
  37. int cpu;
  38. refcount_t refcnt;
  39. bool comm_set;
  40. int comm_len;
  41. bool dead; /* if set thread has exited */
  42. struct list_head namespaces_list;
  43. struct rw_semaphore namespaces_lock;
  44. struct list_head comm_list;
  45. struct rw_semaphore comm_lock;
  46. u64 db_id;
  47. void *priv;
  48. struct thread_stack *ts;
  49. struct nsinfo *nsinfo;
  50. struct srccode_state srccode_state;
  51. bool filter;
  52. int filter_entry_depth;
  53. /* LBR call stack stitch */
  54. bool lbr_stitch_enable;
  55. struct lbr_stitch *lbr_stitch;
  56. };
  57. struct machine;
  58. struct namespaces;
  59. struct comm;
  60. struct thread *thread__new(pid_t pid, pid_t tid);
  61. int thread__init_maps(struct thread *thread, struct machine *machine);
  62. void thread__delete(struct thread *thread);
  63. struct thread *thread__get(struct thread *thread);
  64. void thread__put(struct thread *thread);
  65. static inline void __thread__zput(struct thread **thread)
  66. {
  67. thread__put(*thread);
  68. *thread = NULL;
  69. }
  70. #define thread__zput(thread) __thread__zput(&thread)
  71. static inline void thread__exited(struct thread *thread)
  72. {
  73. thread->dead = true;
  74. }
  75. struct namespaces *thread__namespaces(struct thread *thread);
  76. int thread__set_namespaces(struct thread *thread, u64 timestamp,
  77. struct perf_record_namespaces *event);
  78. int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp,
  79. bool exec);
  80. static inline int thread__set_comm(struct thread *thread, const char *comm,
  81. u64 timestamp)
  82. {
  83. return __thread__set_comm(thread, comm, timestamp, false);
  84. }
  85. int thread__set_comm_from_proc(struct thread *thread);
  86. int thread__comm_len(struct thread *thread);
  87. struct comm *thread__comm(const struct thread *thread);
  88. struct comm *thread__exec_comm(const struct thread *thread);
  89. const char *thread__comm_str(struct thread *thread);
  90. int thread__insert_map(struct thread *thread, struct map *map);
  91. int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone);
  92. size_t thread__fprintf(struct thread *thread, FILE *fp);
  93. struct thread *thread__main_thread(struct machine *machine, struct thread *thread);
  94. struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
  95. struct addr_location *al);
  96. struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr,
  97. struct addr_location *al);
  98. struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
  99. u64 addr, struct addr_location *al);
  100. struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode,
  101. u64 addr, struct addr_location *al);
  102. void thread__find_cpumode_addr_location(struct thread *thread, u64 addr,
  103. struct addr_location *al);
  104. int thread__memcpy(struct thread *thread, struct machine *machine,
  105. void *buf, u64 ip, int len, bool *is64bit);
  106. static inline void *thread__priv(struct thread *thread)
  107. {
  108. return thread->priv;
  109. }
  110. static inline void thread__set_priv(struct thread *thread, void *p)
  111. {
  112. thread->priv = p;
  113. }
  114. static inline bool thread__is_filtered(struct thread *thread)
  115. {
  116. if (symbol_conf.comm_list &&
  117. !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) {
  118. return true;
  119. }
  120. if (symbol_conf.pid_list &&
  121. !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) {
  122. return true;
  123. }
  124. if (symbol_conf.tid_list &&
  125. !intlist__has_entry(symbol_conf.tid_list, thread->tid)) {
  126. return true;
  127. }
  128. return false;
  129. }
  130. void thread__free_stitch_list(struct thread *thread);
  131. #endif /* __PERF_THREAD_H */