perf/core improvements and fixes
Jiri Olsa
reviewerhi Ingo,
please consider pulling
thanks,
jirka
The following changes since commit 2933d7813d8618f18632a7dc7f4e7f1f7d17383a:
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf into perf/core (2014-04-25 10:04:46 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git tags/perf-core-for-mingo
for you to fetch changes up to fabf01238289e9ae009499594fc54642f5802a24:
perf tests: Add map groups sharing with thread object test (2014-04-28 13:43:40 +0200)
----------------------------------------------------------------
perf/core improvements and fixes:
. Add a test case for hists filtering (Namhyung Kim)
. Share map_groups among threads of the same group (Arnaldo Carvalho de Melo, Jiri Olsa)
----------------------------------------------------------------
Arnaldo Carvalho de Melo (2):
perf tools: Allocate thread map_groups's dynamically perf tools: Reference count map_groups objects
Jiri Olsa (3):
perf tests: Add thread maps lookup automated tests perf tools: Share map_groups among threads of the same group perf tests: Add map groups sharing with thread object test
Namhyung Kim (2):
perf tests: Factor out fake_setup_machine() perf tests: Add a test case for hists filtering
tools/perf/Makefile.perf | 4 + tools/perf/arch/x86/tests/dwarf-unwind.c | 2 +- tools/perf/perf.h | 6 + tools/perf/tests/builtin-test.c | 12 ++ tools/perf/tests/hists_common.c | 148 +++++++++++++++ tools/perf/tests/hists_common.h | 44 +++++ tools/perf/tests/hists_filter.c | 315 +++++++++++++++++++++++++++++++ tools/perf/tests/hists_link.c | 141 +------------- tools/perf/tests/mmap-thread-lookup.c | 233 +++++++++++++++++++++++ tools/perf/tests/tests.h | 3 + tools/perf/tests/thread-mg-share.c | 90 +++++++++ tools/perf/ui/stdio/hist.c | 2 +- tools/perf/util/event.c | 2 +- tools/perf/util/machine.c | 11 ++ tools/perf/util/map.c | 23 +++ tools/perf/util/map.h | 12 ++ tools/perf/util/thread.c | 52 +++-- tools/perf/util/thread.h | 3 +- 18 files changed, 948 insertions(+), 155 deletions(-) create mode 100644 tools/perf/tests/hists_common.c create mode 100644 tools/perf/tests/hists_common.h create mode 100644 tools/perf/tests/hists_filter.c create mode 100644 tools/perf/tests/mmap-thread-lookup.c create mode 100644 tools/perf/tests/thread-mg-share.c
Jiri Olsa
reviewerPATCH 1/7 perf tests: Factor out fake_setup_machine()
From: Namhyung Kim <[email protected]>
The fake_setup_machine() is for setting up a environment for testing various hists operations. As it'll be used for other test cases it'd better factoring it out.
--- tools/perf/Makefile.perf | 1 + tools/perf/tests/hists_common.c | 148 ++++++++++++++++++++++++++++++++++++++++ tools/perf/tests/hists_common.h | 44 ++++++++++++ tools/perf/tests/hists_link.c | 141 +------------------------------------- 4 files changed, 195 insertions(+), 139 deletions(-) create mode 100644 tools/perf/tests/hists_common.c create mode 100644 tools/perf/tests/hists_common.h
tools/perf/Makefile.perf +1 -0
@@ -397,6 +397,7 @@ LIB_OBJS += $(OUTPUT)tests/rdpmc.o LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o LIB_OBJS += $(OUTPUT)tests/pmu.o +LIB_OBJS += $(OUTPUT)tests/hists_common.o LIB_OBJS += $(OUTPUT)tests/hists_link.o LIB_OBJS += $(OUTPUT)tests/python-use.o LIB_OBJS += $(OUTPUT)tests/bp_signal.o
tools/perf/tests/hists_common.c new file +148 -0
148 lines not on this page · raw message
tools/perf/tests/hists_common.h new file +44 -0
44 lines not on this page · raw message
tools/perf/tests/hists_link.c +2 -139
153 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Jiri Olsa
reviewerPATCH 2/7 perf tests: Add a test case for hists filtering
In reply to Jiri OlsaFrom: Namhyung Kim <[email protected]>
Now we have changed how hists stats are accounted especially when filter(s) applied. So add a test case to verify it.
--- tools/perf/Makefile.perf | 1 + tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/hists_filter.c | 315 ++++++++++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + 4 files changed, 321 insertions(+) create mode 100644 tools/perf/tests/hists_filter.c
tools/perf/Makefile.perf +1 -0
@@ -399,6 +399,7 @@ LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o LIB_OBJS += $(OUTPUT)tests/pmu.o LIB_OBJS += $(OUTPUT)tests/hists_common.o LIB_OBJS += $(OUTPUT)tests/hists_link.o +LIB_OBJS += $(OUTPUT)tests/hists_filter.o LIB_OBJS += $(OUTPUT)tests/python-use.o LIB_OBJS += $(OUTPUT)tests/bp_signal.o LIB_OBJS += $(OUTPUT)tests/bp_signal_overflow.o
tools/perf/tests/builtin-test.c +4 -0
@@ -124,6 +124,10 @@ static struct test {#endif #endif { + .desc = "Test filtering hist entries", + .func = test__hists_filter, + }, + { .func = NULL, }, };
tools/perf/tests/hists_filter.c new file +315 -0
315 lines not on this page · raw message
tools/perf/tests/tests.h +1 -0
@@ -41,6 +41,7 @@ int test__sample_parsing(void);int test__keep_tracking (void );int test__parse_no_sample_id_all (void );int test__dwarf_unwind (void ); +int test__hists_filter (void );#if defined(__x86_64__) || defined(__i386__)#ifdef HAVE_DWARF_UNWIND_SUPPORT
Signature · 1 line
1.8.3.1
Jiri Olsa
reviewerPATCH 3/7 perf tests: Add thread maps lookup automated tests
In reply to Jiri OlsaAdding automated test for memory maps lookup within multiple machines threads.
The test creates 4 threads and separated memory maps. It checks that we could use thread__find_addr_map function with thread object based on TID to find memory maps.
--- tools/perf/Makefile.perf | 1 + tools/perf/perf.h | 6 + tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/mmap-thread-lookup.c | 233 ++++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + 5 files changed, 245 insertions(+) create mode 100644 tools/perf/tests/mmap-thread-lookup.c
tools/perf/Makefile.perf +1 -0
@@ -416,6 +416,7 @@ ifeq ($(ARCH),x86) LIB_OBJS += $(OUTPUT)tests/dwarf-unwind.o endif endif +LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/perf.h +6 -0
@@ -15,6 +15,9 @@#ifndef __NR_futex# define __NR_futex 240#endif +#ifndef __NR_gettid +# define __NR_gettid 224 +#endif #endif #if defined(__x86_64__)
@@ -29,6 +32,9 @@#ifndef __NR_futex# define __NR_futex 202#endif +#ifndef __NR_gettid +# define __NR_gettid 186 +#endif #endif #ifdef __powerpc__
tools/perf/tests/builtin-test.c +4 -0
@@ -128,6 +128,10 @@ static struct test { .func = test__hists_filter, }, { + .desc = "Test mmap thread lookup", + .func = test__mmap_thread_lookup, + }, + { .func = NULL, }, };
tools/perf/tests/mmap-thread-lookup.c new file +233 -0
233 lines not on this page · raw message
tools/perf/tests/tests.h +1 -0
@@ -42,6 +42,7 @@ int test__keep_tracking(void);int test__parse_no_sample_id_all (void );int test__dwarf_unwind (void );int test__hists_filter (void ); +int test__mmap_thread_lookup (void );#if defined(__x86_64__) || defined(__i386__)#ifdef HAVE_DWARF_UNWIND_SUPPORT
Signature · 1 line
1.8.3.1
Jiri Olsa
reviewerPATCH 4/7 perf tools: Allocate thread map_groups's dynamically
In reply to Jiri OlsaFrom: Arnaldo Carvalho de Melo <[email protected]>
Moving towards sharing map groups within a process threads.
Because of this we need the map groups to be dynamically allocated. No other functional change is intended in here.
Based on a patch by Jiri Olsa, but this time _just_ making the conversion from statically allocating thread->mg to turning it into a pointer and instead of initializing it at thread's constructor, introduce a constructor/destructor for the map_groups class and call at thread creation time.
Later we will introduce the get/put methods when we move to sharing those map_groups, when the get/put refcounting semantics will be needed.
--- tools/perf/arch/x86/tests/dwarf-unwind.c | 2 +- tools/perf/ui/stdio/hist.c | 2 +- tools/perf/util/event.c | 2 +- tools/perf/util/map.c | 16 ++++++++++++++++ tools/perf/util/map.h | 3 +++ tools/perf/util/thread.c | 18 ++++++++++++------ tools/perf/util/thread.h | 2 +- 7 files changed, 35 insertions(+), 10 deletions(-)
tools/perf/arch/x86/tests/dwarf-unwind.c +1 -1
@@ -23,7 +23,7 @@ static int sample_ustack(struct perf_sample *sample, sp = (unsigned long ) regs[PERF_REG_X86_SP ]; - map =map_groups__find (&thread->mg,MAP__FUNCTION , (u64 ) sp); + map =map_groups__find (thread->mg,MAP__FUNCTION , (u64 ) sp);if (!map) {pr_debug ("failed to get stack map\n" );free (buf);
tools/perf/ui/stdio/hist.c +1 -1
@@ -495,7 +495,7 @@ print_entries:break ;if (h->ms.map ==NULL && verbose >1 ) { -__map_groups__fprintf_maps (&h->thread->mg, +__map_groups__fprintf_maps (h->thread->mg,MAP__FUNCTION , verbose, fp);fprintf (fp,"%.10s end\n" , graph_dotted_line); }
tools/perf/util/event.c +1 -1
@@ -699,7 +699,7 @@ void thread__find_addr_map(struct thread *thread, enum map_type type, u64 addr, struct addr_location *al) { - struct map_groups *mg = &thread->mg; + struct map_groups *mg = thread->mg;bool load_map = false; al->machine = machine;
tools/perf/util/map.c +16 -0
@@ -358,6 +358,22 @@ void map_groups__exit(struct map_groups *mg) } } +struct map_groups *map_groups__new (void ) +{ +struct map_groups *mg =malloc (sizeof (*mg)); + +if (mg !=NULL ) +map_groups__init (mg); + +return mg; +} + +void map_groups__delete (struct map_groups *mg) +{ +map_groups__exit (mg); +free (mg); +} +void map_groups__flush (struct map_groups *mg) {int type;
tools/perf/util/map.h +3 -0
@@ -61,6 +61,9 @@ struct map_groups {struct machine *machine; }; +struct map_groups *map_groups__new (void ); +void map_groups__delete (struct map_groups *mg); +static inline struct kmap *map__kmap (struct map *map) {return (struct kmap *)(map +1 );
tools/perf/util/thread.c +12 -6
@@ -15,7 +15,10 @@ struct thread *thread__new(pid_t pid, pid_t tid)struct thread *thread =zalloc (sizeof (*thread));if (thread !=NULL ) { -map_groups__init (&thread->mg); + thread->mg =map_groups__new (); +if (thread->mg ==NULL ) + goto out_free; + thread->pid_ = pid; thread->tid = tid; thread->ppid =-1 ;
@@ -37,6 +40,8 @@ struct thread *thread__new(pid_t pid, pid_t tid)return thread; err_thread: +map_groups__delete (thread->mg); +out_free:free (thread);return NULL ; }
@@ -45,7 +50,8 @@ void thread__delete(struct thread *thread) {struct comm *comm, *tmp; -map_groups__exit (&thread->mg); +map_groups__delete (thread->mg); + thread->mg =NULL ;list_for_each_entry_safe (comm, tmp, &thread->comm_list, list) {list_del (&comm->list);comm__free (comm);
@@ -111,13 +117,13 @@ int thread__comm_len(struct thread *thread)size_t thread__fprintf (struct thread *thread,FILE *fp) {return fprintf (fp,"Thread %d %s\n" , thread->tid,thread__comm_str (thread)) + -map_groups__fprintf (&thread->mg, verbose, fp); +map_groups__fprintf (thread->mg, verbose, fp); }void thread__insert_map (struct thread *thread,struct map *map) { -map_groups__fixup_overlappings (&thread->mg, map, verbose, stderr); -map_groups__insert (&thread->mg, map); +map_groups__fixup_overlappings (thread->mg, map, verbose, stderr); +map_groups__insert (thread->mg, map); }int thread__fork (struct thread *thread,struct thread *parent,u64 timestamp)
@@ -135,7 +141,7 @@ int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp) }for (i =0 ; i <MAP__NR_TYPES ; ++i) -if (map_groups__clone (&thread->mg, &parent->mg, i) <0 ) +if (map_groups__clone (thread->mg, parent->mg, i) <0 )return -ENOMEM ; thread->ppid = parent->tid;
tools/perf/util/thread.h +1 -1
@@ -13,7 +13,7 @@ struct thread {struct rb_node rb_node;struct list_head node; }; -struct map_groups mg; +struct map_groups *mg;pid_t pid_;/* Not all tools update this */ pid_t tid;pid_t ppid;
Signature · 1 line
1.8.3.1
Jiri Olsa
reviewerPATCH 5/7 perf tools: Reference count map_groups objects
In reply to Jiri OlsaFrom: Arnaldo Carvalho de Melo <[email protected]>
We will share it among threads in the same process. Adding map_groups__get/map_groups__put interface for that.
--- tools/perf/util/map.c | 7 +++++++ tools/perf/util/map.h | 9 +++++++++ tools/perf/util/thread.c | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-)
tools/perf/util/map.c +7 -0
@@ -323,6 +323,7 @@ void map_groups__init(struct map_groups *mg)INIT_LIST_HEAD (&mg->removed_maps[i]); } mg->machine =NULL ; + mg->refcnt =1 ; }static void maps__delete (struct rb_root *maps)
@@ -374,6 +375,12 @@ void map_groups__delete(struct map_groups *mg)free (mg); } +void map_groups__put (struct map_groups *mg) +{ +if (--mg->refcnt ==0 ) +map_groups__delete (mg); +} +void map_groups__flush (struct map_groups *mg) {int type;
tools/perf/util/map.h +9 -0
@@ -59,11 +59,20 @@ struct map_groups {struct rb_root maps[MAP__NR_TYPES ];struct list_head removed_maps[MAP__NR_TYPES ];struct machine *machine; +int refcnt; };struct map_groups *map_groups__new (void );void map_groups__delete (struct map_groups *mg); +static inline struct map_groups *map_groups__get (struct map_groups *mg) +{ + ++mg->refcnt; +return mg; +} + +void map_groups__put (struct map_groups *mg); +static inline struct kmap *map__kmap (struct map *map) {return (struct kmap *)(map +1 );
tools/perf/util/thread.c +1 -1
@@ -50,7 +50,7 @@ void thread__delete(struct thread *thread) {struct comm *comm, *tmp; -map_groups__delete (thread->mg); +map_groups__put (thread->mg); thread->mg =NULL ;list_for_each_entry_safe (comm, tmp, &thread->comm_list, list) {list_del (&comm->list);
Signature · 1 line
1.8.3.1
Jiri Olsa
reviewerPATCH 6/7 perf tools: Share map_groups among threads of the same group
In reply to Jiri OlsaSharing map groups within all process threads. This way there's only one copy of mmap info and it's reachable from any thread within the process.
--- tools/perf/util/machine.c | 11 +++++++++++ tools/perf/util/thread.c | 48 ++++++++++++++++++++++++++++++++++------------- tools/perf/util/thread.h | 1 + 3 files changed, 47 insertions(+), 13 deletions(-)
tools/perf/util/machine.c +11 -0
@@ -316,6 +316,17 @@ static struct thread *__machine__findnew_thread(struct machine *machine,rb_link_node (&th->rb_node, parent, p);rb_insert_color (&th->rb_node, &machine->threads); machine->last_match = th; + +/* +* We have to initialize map_groups separately +* after rb tree is updated. +* +* The reason is that we call machine__findnew_thread +* within thread__init_map_groups to find the thread +* leader and that would screwed the rb tree. +*/ +if (thread__init_map_groups (th, machine)) +return NULL ; }return th;
tools/perf/util/thread.c +35 -13
81 lines not on this page · raw message
tools/perf/util/thread.h +1 -0
@@ -30,6 +30,7 @@ struct machine;struct comm ;struct thread *thread__new (pid_t pid,pid_t tid); +int thread__init_map_groups (struct thread *thread,struct machine *machine);void thread__delete (struct thread *thread);static inline void thread__exited (struct thread *thread) {
Signature · 1 line
1.8.3.1
Jiri Olsa
reviewerPATCH 7/7 perf tests: Add map groups sharing with thread object test
In reply to Jiri OlsaThis test create 2 processes abstractions, with several threads and checks they properly share and maintain map groups info.
--- tools/perf/Makefile.perf | 1 + tools/perf/tests/builtin-test.c | 4 ++ tools/perf/tests/tests.h | 1 + tools/perf/tests/thread-mg-share.c | 90 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 tools/perf/tests/thread-mg-share.c
tools/perf/Makefile.perf +1 -0
@@ -417,6 +417,7 @@ LIB_OBJS += $(OUTPUT)tests/dwarf-unwind.o endif endif LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o +LIB_OBJS += $(OUTPUT)tests/thread-mg-share.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/tests/builtin-test.c +4 -0
@@ -132,6 +132,10 @@ static struct test { .func = test__mmap_thread_lookup, }, { + .desc = "Test thread mg sharing", + .func = test__thread_mg_share, + }, + { .func = NULL, }, };
tools/perf/tests/tests.h +1 -0
@@ -43,6 +43,7 @@ int test__parse_no_sample_id_all(void);int test__dwarf_unwind (void );int test__hists_filter (void );int test__mmap_thread_lookup (void ); +int test__thread_mg_share (void );#if defined(__x86_64__) || defined(__i386__)#ifdef HAVE_DWARF_UNWIND_SUPPORT
tools/perf/tests/thread-mg-share.c new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Quoted 59 lines · Jiri Olsa
hi Ingo,
please consider pullingthanks,
jirkaThe following changes since commit
2933d7813d8618f18632a7dc7f4e7f1f7d17383a:Merge tag 'perf-core-for-mingo' of
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perfinto perf/core (2014-04-25 10:04:46 +0200)are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.gittags/perf-core-for-mingofor you to fetch changes up to
fabf01238289e9ae009499594fc54642f5802a24:perf tests: Add map groups sharing with thread object test (2014-04-28 13:43:40 +0200)
----------------------------------------------------------------
perf/core improvements and fixes:. Add a test case for hists filtering (Namhyung Kim)
. Share
map_groupsamong threads of the same group (Arnaldo Carvalho de Melo, Jiri Olsa)Signed-off-by Jiri Olsa <[email protected]>----------------------------------------------------------------
Arnaldo Carvalho de Melo (2):
perf tools: Allocate thread map_groups's dynamically perf tools: Reference countmap_groupsobjectsJiri Olsa (3):
perf tests: Add thread maps lookup automated tests perf tools: Sharemap_groupsamong threads of the same group perf tests: Add map groups sharing with thread object testNamhyung Kim (2):
perf tests: Factor outfake_setup_machine()perf tests: Add a test case for hists filteringtools/perf/Makefile.perf | 4 + tools/perf/arch/x86/tests/dwarf-unwind.c | 2 +- tools/perf/perf.h | 6 + tools/perf/tests/builtin-test.c | 12 ++ tools/perf/tests/hists_common.c | 148 +++++++++++++++ tools/perf/tests/hists_common.h | 44 +++++ tools/perf/tests/hists_filter.c | 315 +++++++++++++++++++++++++++++++ tools/perf/tests/hists_link.c | 141 +------------- tools/perf/tests/mmap-thread-lookup.c | 233 +++++++++++++++++++++++ tools/perf/tests/tests.h | 3 + tools/perf/tests/thread-mg-share.c | 90 +++++++++ tools/perf/ui/stdio/hist.c | 2 +- tools/perf/util/event.c | 2 +- tools/perf/util/machine.c | 11 ++ tools/perf/util/map.c | 23 +++ tools/perf/util/map.h | 12 ++
Quoted 8 lines
tools/perf/util/thread.c | 52 +++-- tools/perf/util/thread.h | 3 +- 18 files changed, 948 insertions(+), 155 deletions(-) create mode 100644 tools/perf/tests/hists_common.c create mode 100644 tools/perf/tests/hists_common.h create mode 100644 tools/perf/tests/hists_filter.c create mode 100644 tools/perf/tests/mmap-thread-lookup.c create mode 100644 tools/perf/tests/thread-mg-share.c
Pulled, thanks a lot Jiri!
Ingo