diff options
author | Namhyung Kim <namhyung@kernel.org> | 2016-12-08 09:47:51 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-12-15 14:25:44 -0500 |
commit | 3bc2fa9cb829ccf6527e7117d9af769d93ee6d39 (patch) | |
tree | 5dbb24c56276a631354c2d2473c405903b7700d2 /tools/perf/builtin-sched.c | |
parent | 96039c7c52e03b7d6dd773664e74b79e3ae9856a (diff) |
perf sched timehist: Introduce struct idle_time_data
The struct idle_time_data is to keep idle stats with callchains entering
to the idle task. The normal thread_runtime calculation is done
transparently since it extends the struct thread_runtime.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20161208144755.16673-3-namhyung@kernel.org
[ Align struct field names ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-sched.c')
-rw-r--r-- | tools/perf/builtin-sched.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 966eddce1609..e108b0f6a246 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -230,6 +230,15 @@ struct evsel_runtime { | |||
230 | u32 ncpu; /* highest cpu slot allocated */ | 230 | u32 ncpu; /* highest cpu slot allocated */ |
231 | }; | 231 | }; |
232 | 232 | ||
233 | /* per cpu idle time data */ | ||
234 | struct idle_thread_runtime { | ||
235 | struct thread_runtime tr; | ||
236 | struct thread *last_thread; | ||
237 | struct rb_root sorted_root; | ||
238 | struct callchain_root callchain; | ||
239 | struct callchain_cursor cursor; | ||
240 | }; | ||
241 | |||
233 | /* track idle times per cpu */ | 242 | /* track idle times per cpu */ |
234 | static struct thread **idle_threads; | 243 | static struct thread **idle_threads; |
235 | static int idle_max_cpu; | 244 | static int idle_max_cpu; |
@@ -1997,13 +2006,31 @@ static void save_task_callchain(struct perf_sched *sched, | |||
1997 | } | 2006 | } |
1998 | } | 2007 | } |
1999 | 2008 | ||
2009 | static int init_idle_thread(struct thread *thread) | ||
2010 | { | ||
2011 | struct idle_thread_runtime *itr; | ||
2012 | |||
2013 | thread__set_comm(thread, idle_comm, 0); | ||
2014 | |||
2015 | itr = zalloc(sizeof(*itr)); | ||
2016 | if (itr == NULL) | ||
2017 | return -ENOMEM; | ||
2018 | |||
2019 | init_stats(&itr->tr.run_stats); | ||
2020 | callchain_init(&itr->callchain); | ||
2021 | callchain_cursor_reset(&itr->cursor); | ||
2022 | thread__set_priv(thread, itr); | ||
2023 | |||
2024 | return 0; | ||
2025 | } | ||
2026 | |||
2000 | /* | 2027 | /* |
2001 | * Track idle stats per cpu by maintaining a local thread | 2028 | * Track idle stats per cpu by maintaining a local thread |
2002 | * struct for the idle task on each cpu. | 2029 | * struct for the idle task on each cpu. |
2003 | */ | 2030 | */ |
2004 | static int init_idle_threads(int ncpu) | 2031 | static int init_idle_threads(int ncpu) |
2005 | { | 2032 | { |
2006 | int i; | 2033 | int i, ret; |
2007 | 2034 | ||
2008 | idle_threads = zalloc(ncpu * sizeof(struct thread *)); | 2035 | idle_threads = zalloc(ncpu * sizeof(struct thread *)); |
2009 | if (!idle_threads) | 2036 | if (!idle_threads) |
@@ -2017,7 +2044,9 @@ static int init_idle_threads(int ncpu) | |||
2017 | if (idle_threads[i] == NULL) | 2044 | if (idle_threads[i] == NULL) |
2018 | return -ENOMEM; | 2045 | return -ENOMEM; |
2019 | 2046 | ||
2020 | thread__set_comm(idle_threads[i], idle_comm, 0); | 2047 | ret = init_idle_thread(idle_threads[i]); |
2048 | if (ret < 0) | ||
2049 | return ret; | ||
2021 | } | 2050 | } |
2022 | 2051 | ||
2023 | return 0; | 2052 | return 0; |
@@ -2064,8 +2093,8 @@ static struct thread *get_idle_thread(int cpu) | |||
2064 | idle_threads[cpu] = thread__new(0, 0); | 2093 | idle_threads[cpu] = thread__new(0, 0); |
2065 | 2094 | ||
2066 | if (idle_threads[cpu]) { | 2095 | if (idle_threads[cpu]) { |
2067 | idle_threads[cpu]->tid = 0; | 2096 | if (init_idle_thread(idle_threads[cpu]) < 0) |
2068 | thread__set_comm(idle_threads[cpu], idle_comm, 0); | 2097 | return NULL; |
2069 | } | 2098 | } |
2070 | } | 2099 | } |
2071 | 2100 | ||