Skip to content

Commit 139f42f

Browse files
ahunter6acmel
authored andcommitted
perf thread-stack: Allocate an array of thread stacks
In preparation for fixing thread stack processing for the idle task, allocate an array of thread stacks. Signed-off-by: Adrian Hunter <[email protected]> Acked-by: Jiri Olsa <[email protected]> Link: http://lkml.kernel.org/r/[email protected] [ No need to check for NULL when calling zfree(), noticed by Jiri Olsa ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 2e9e868 commit 139f42f

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

tools/perf/util/thread-stack.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,25 @@ static int thread_stack__init(struct thread_stack *ts, struct thread *thread,
114114
static struct thread_stack *thread_stack__new(struct thread *thread,
115115
struct call_return_processor *crp)
116116
{
117-
struct thread_stack *ts;
118-
119-
ts = zalloc(sizeof(struct thread_stack));
120-
if (!ts)
121-
return NULL;
122-
123-
ts->arr_sz = 1;
124-
125-
if (thread_stack__init(ts, thread, crp)) {
126-
free(ts);
127-
return NULL;
117+
struct thread_stack *ts = thread->ts, *new_ts;
118+
unsigned int old_sz = ts ? ts->arr_sz : 0;
119+
unsigned int new_sz = 1;
120+
121+
if (!ts || new_sz > old_sz) {
122+
new_ts = calloc(new_sz, sizeof(*ts));
123+
if (!new_ts)
124+
return NULL;
125+
if (ts)
126+
memcpy(new_ts, ts, old_sz * sizeof(*ts));
127+
new_ts->arr_sz = new_sz;
128+
zfree(&thread->ts);
129+
thread->ts = new_ts;
130+
ts = new_ts;
128131
}
129132

130-
thread->ts = ts;
133+
if (!ts->stack &&
134+
thread_stack__init(ts, thread, crp))
135+
return NULL;
131136

132137
return ts;
133138
}

0 commit comments

Comments
 (0)