Lines Matching defs:thread
3 * thread-stack.c: Synthesize a thread's stack using call / return events
14 #include "thread.h"
22 #include "thread-stack.h"
40 * struct thread_stack_entry - thread stack entry.
68 * struct thread_stack - thread stack constructed from 'call' and 'return'
113 static inline bool thread_stack__per_cpu(struct thread *thread)
115 return !(thread->tid || thread->pid_);
136 static int thread_stack__init(struct thread_stack *ts, struct thread *thread,
158 if (thread->maps && thread->maps->machine) {
159 struct machine *machine = thread->maps->machine;
173 static struct thread_stack *thread_stack__new(struct thread *thread, int cpu,
178 struct thread_stack *ts = thread->ts, *new_ts;
182 if (thread_stack__per_cpu(thread) && cpu > 0)
192 zfree(&thread->ts);
193 thread->ts = new_ts;
197 if (thread_stack__per_cpu(thread) && cpu > 0 &&
202 thread_stack__init(ts, thread, crp, callstack, br_stack_sz))
208 static struct thread_stack *thread__cpu_stack(struct thread *thread, int cpu)
210 struct thread_stack *ts = thread->ts;
226 static inline struct thread_stack *thread__stack(struct thread *thread,
229 if (!thread)
232 if (thread_stack__per_cpu(thread))
233 return thread__cpu_stack(thread, cpu);
235 return thread->ts;
246 pr_warning("Out of memory: discarding thread stack\n");
298 static int thread_stack__call_return(struct thread *thread,
305 .thread = thread,
338 static int __thread_stack__flush(struct thread *thread, struct thread_stack *ts)
352 err = thread_stack__call_return(thread, ts, --ts->cnt,
355 pr_err("Error flushing thread stack!\n");
364 int thread_stack__flush(struct thread *thread)
366 struct thread_stack *ts = thread->ts;
372 int ret = __thread_stack__flush(thread, ts + pos);
406 int thread_stack__event(struct thread *thread, int cpu, u32 flags, u64 from_ip,
410 struct thread_stack *ts = thread__stack(thread, cpu);
412 if (!thread)
416 ts = thread_stack__new(thread, cpu, NULL, callstack, br_stack_sz);
418 pr_warning("Out of memory: no thread stack\n");
432 __thread_stack__flush(thread, ts);
473 void thread_stack__set_trace_nr(struct thread *thread, int cpu, u64 trace_nr)
475 struct thread_stack *ts = thread__stack(thread, cpu);
482 __thread_stack__flush(thread, ts);
487 static void __thread_stack__free(struct thread *thread, struct thread_stack *ts)
489 __thread_stack__flush(thread, ts);
494 static void thread_stack__reset(struct thread *thread, struct thread_stack *ts)
498 __thread_stack__free(thread, ts);
503 void thread_stack__free(struct thread *thread)
505 struct thread_stack *ts = thread->ts;
510 __thread_stack__free(thread, ts + pos);
511 zfree(&thread->ts);
520 void thread_stack__sample(struct thread *thread, int cpu,
524 struct thread_stack *ts = thread__stack(thread, cpu);
563 void thread_stack__sample_late(struct thread *thread, int cpu,
567 struct thread_stack *ts = thread__stack(thread, cpu);
616 void thread_stack__br_sample(struct thread *thread, int cpu,
619 struct thread_stack *ts = thread__stack(thread, cpu);
677 void thread_stack__br_sample_late(struct thread *thread, int cpu,
681 struct thread_stack *ts = thread__stack(thread, cpu);
813 static int thread_stack__pop_cp(struct thread *thread, struct thread_stack *ts,
826 return thread_stack__call_return(thread, ts, --ts->cnt,
832 return thread_stack__call_return(thread, ts, --ts->cnt,
843 err = thread_stack__call_return(thread, ts,
850 return thread_stack__call_return(thread, ts, --ts->cnt,
885 static int thread_stack__pop_ks(struct thread *thread, struct thread_stack *ts,
893 err = thread_stack__call_return(thread, ts, --ts->cnt,
902 static int thread_stack__no_call_return(struct thread *thread,
921 err = thread_stack__pop_ks(thread, ts, sample, ref);
933 err = thread_stack__pop_ks(thread, ts, sample, ref);
950 err = thread_stack__call_return(thread, ts, --ts->cnt,
993 return thread_stack__call_return(thread, ts, --ts->cnt, tm, ref, false);
996 static int thread_stack__trace_begin(struct thread *thread,
1009 err = thread_stack__call_return(thread, ts, --ts->cnt,
1102 int thread_stack__process(struct thread *thread, struct comm *comm,
1108 struct thread_stack *ts = thread__stack(thread, sample->cpu);
1114 thread_stack__reset(thread, ts);
1119 ts = thread_stack__new(thread, sample->cpu, crp, true, 0);
1130 if (ts->comm != comm && thread->pid_ == thread->tid) {
1131 err = __thread_stack__flush(thread, ts);
1186 return thread_stack__pop_ks(thread, ts, sample, ref);
1197 err = thread_stack__pop_cp(thread, ts, sample->addr,
1202 err = thread_stack__no_call_return(thread, ts, sample,
1206 err = thread_stack__trace_begin(thread, ts, sample->time, ref);
1233 size_t thread_stack__depth(struct thread *thread, int cpu)
1235 struct thread_stack *ts = thread__stack(thread, cpu);