Skip to content

Commit f6060ac

Browse files
ahunter6acmel
authored andcommitted
perf thread-stack: Allow for a thread stack array
In preparation for fixing thread stack processing for the idle task, allow for a thread stack array. Signed-off-by: Adrian Hunter <[email protected]> Acked-by: Jiri Olsa <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent bd8e68a commit f6060ac

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

tools/perf/util/thread-stack.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct thread_stack_entry {
6060
* @last_time: last timestamp
6161
* @crp: call/return processor
6262
* @comm: current comm
63+
* @arr_sz: size of array if this is the first element of an array
6364
*/
6465
struct thread_stack {
6566
struct thread_stack_entry *stack;
@@ -71,6 +72,7 @@ struct thread_stack {
7172
u64 last_time;
7273
struct call_return_processor *crp;
7374
struct comm *comm;
75+
unsigned int arr_sz;
7476
};
7577

7678
static int thread_stack__grow(struct thread_stack *ts)
@@ -100,6 +102,8 @@ static struct thread_stack *thread_stack__new(struct thread *thread,
100102
if (!ts)
101103
return NULL;
102104

105+
ts->arr_sz = 1;
106+
103107
if (thread_stack__grow(ts)) {
104108
free(ts);
105109
return NULL;
@@ -234,11 +238,19 @@ static int __thread_stack__flush(struct thread *thread, struct thread_stack *ts)
234238
int thread_stack__flush(struct thread *thread)
235239
{
236240
struct thread_stack *ts = thread->ts;
241+
unsigned int pos;
242+
int err = 0;
237243

238-
if (ts)
239-
return __thread_stack__flush(thread, ts);
244+
if (ts) {
245+
for (pos = 0; pos < ts->arr_sz; pos++) {
246+
int ret = __thread_stack__flush(thread, ts + pos);
240247

241-
return 0;
248+
if (ret)
249+
err = ret;
250+
}
251+
}
252+
253+
return err;
242254
}
243255

244256
int thread_stack__event(struct thread *thread, u32 flags, u64 from_ip,
@@ -314,13 +326,29 @@ void thread_stack__set_trace_nr(struct thread *thread, u64 trace_nr)
314326
}
315327
}
316328

329+
static void __thread_stack__free(struct thread *thread, struct thread_stack *ts)
330+
{
331+
__thread_stack__flush(thread, ts);
332+
zfree(&ts->stack);
333+
}
334+
335+
static void thread_stack__reset(struct thread *thread, struct thread_stack *ts)
336+
{
337+
unsigned int arr_sz = ts->arr_sz;
338+
339+
__thread_stack__free(thread, ts);
340+
memset(ts, 0, sizeof(*ts));
341+
ts->arr_sz = arr_sz;
342+
}
343+
317344
void thread_stack__free(struct thread *thread)
318345
{
319346
struct thread_stack *ts = thread->ts;
347+
unsigned int pos;
320348

321349
if (ts) {
322-
__thread_stack__flush(thread, ts);
323-
zfree(&ts->stack);
350+
for (pos = 0; pos < ts->arr_sz; pos++)
351+
__thread_stack__free(thread, ts + pos);
324352
zfree(&thread->ts);
325353
}
326354
}
@@ -611,7 +639,7 @@ int thread_stack__process(struct thread *thread, struct comm *comm,
611639

612640
if (ts && !ts->crp) {
613641
/* Supersede thread_stack__event() */
614-
thread_stack__free(thread);
642+
thread_stack__reset(thread, ts);
615643
ts = NULL;
616644
}
617645

0 commit comments

Comments
 (0)