summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2018-12-21 14:06:18 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-01-02 10:55:55 -0300
commit139f42f3b3b495e61bb2cfef40e1dd5e845e3052 (patch)
tree5431e14d34d6c15e8ba4fe23743296c2846aeec1 /tools
parent2e9e8688763ff80f032d9a78c3b4b951fb6dd7a4 (diff)
downloadlinux-stable-139f42f3b3b495e61bb2cfef40e1dd5e845e3052.tar.gz
linux-stable-139f42f3b3b495e61bb2cfef40e1dd5e845e3052.tar.bz2
linux-stable-139f42f3b3b495e61bb2cfef40e1dd5e845e3052.zip
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 <adrian.hunter@intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Link: http://lkml.kernel.org/r/20181221120620.9659-7-adrian.hunter@intel.com [ No need to check for NULL when calling zfree(), noticed by Jiri Olsa ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/thread-stack.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c
index 03770af9e5cd..248ed3945bec 100644
--- a/tools/perf/util/thread-stack.c
+++ b/tools/perf/util/thread-stack.c
@@ -114,20 +114,25 @@ static int thread_stack__init(struct thread_stack *ts, struct thread *thread,
static struct thread_stack *thread_stack__new(struct thread *thread,
struct call_return_processor *crp)
{
- struct thread_stack *ts;
-
- ts = zalloc(sizeof(struct thread_stack));
- if (!ts)
- return NULL;
-
- ts->arr_sz = 1;
-
- if (thread_stack__init(ts, thread, crp)) {
- free(ts);
- return NULL;
+ struct thread_stack *ts = thread->ts, *new_ts;
+ unsigned int old_sz = ts ? ts->arr_sz : 0;
+ unsigned int new_sz = 1;
+
+ if (!ts || new_sz > old_sz) {
+ new_ts = calloc(new_sz, sizeof(*ts));
+ if (!new_ts)
+ return NULL;
+ if (ts)
+ memcpy(new_ts, ts, old_sz * sizeof(*ts));
+ new_ts->arr_sz = new_sz;
+ zfree(&thread->ts);
+ thread->ts = new_ts;
+ ts = new_ts;
}
- thread->ts = ts;
+ if (!ts->stack &&
+ thread_stack__init(ts, thread, crp))
+ return NULL;
return ts;
}