[PATCH 5/8] perf thread-stack: Factor out thread_stack__init()

From: Adrian Hunter
Date: Fri Dec 21 2018 - 07:08:18 EST


In preparation for fixing thread stack processing for the idle task,
factor out thread_stack__init().

Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
---
tools/perf/util/thread-stack.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c
index e59f6fa4c67d..4340381d54c2 100644
--- a/tools/perf/util/thread-stack.c
+++ b/tools/perf/util/thread-stack.c
@@ -93,6 +93,24 @@ static int thread_stack__grow(struct thread_stack *ts)
return 0;
}

+static int thread_stack__init(struct thread_stack *ts, struct thread *thread,
+ struct call_return_processor *crp)
+{
+ int err;
+
+ err = thread_stack__grow(ts);
+ if (err)
+ return err;
+
+ if (thread->mg && thread->mg->machine)
+ ts->kernel_start = machine__kernel_start(thread->mg->machine);
+ else
+ ts->kernel_start = 1ULL << 63;
+ ts->crp = crp;
+
+ return 0;
+}
+
static struct thread_stack *thread_stack__new(struct thread *thread,
struct call_return_processor *crp)
{
@@ -104,17 +122,11 @@ static struct thread_stack *thread_stack__new(struct thread *thread,

ts->arr_sz = 1;

- if (thread_stack__grow(ts)) {
+ if (thread_stack__init(ts, thread, crp)) {
free(ts);
return NULL;
}

- if (thread->mg && thread->mg->machine)
- ts->kernel_start = machine__kernel_start(thread->mg->machine);
- else
- ts->kernel_start = 1ULL << 63;
- ts->crp = crp;
-
thread->ts = ts;

return ts;
--
2.17.1