perf top: Do not convert address for perf_top__record_precise_ip()
Namhyung Kim
maintainerPATCH 1/4 perf top: Do not convert address for perf_top__record_precise_ip()
We call map->unmap_ip() before the function and call map->map_ip() inside the function. This is meaningless and look strange since only one of the two checks 'map'. Let's use al->addr directly.
--- tools/perf/builtin-top.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
tools/perf/builtin-top.c +2 -10
@@ -189,8 +189,6 @@ static void perf_top__record_precise_ip(struct perf_top *top,if (pthread_mutex_trylock (¬es->lock))return ; - ip = he->ms.map->map_ip (he->ms.map, ip); -if (ui__has_annotation ()) err =hist_entry__inc_addr_samples (he, counter, ip);
@@ -687,14 +685,8 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter,struct hist_entry *he = iter->he;struct perf_evsel *evsel = iter->evsel; -if (sort__has_sym && single) { -u64 ip = al->addr; - -if (al->map) - ip = al->map->unmap_ip (al->map, ip); - -perf_top__record_precise_ip (top, he, evsel->idx, ip); - } +if (sort__has_sym && single) +perf_top__record_precise_ip (top, he, evsel->idx, al->addr);hist__account_cycles (iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack &PERF_SAMPLE_BRANCH_ANY ));
Signature · 1 line
2.6.4
Namhyung Kim
maintainerPATCH 2/4 perf top: Access hists->lock only if needed
The perf_top__record_precise_ip() releases and regrabs the he->hists->lock because it can sleep if there's an error. But it should be done conditionally as it slows down the fast path.
--- tools/perf/builtin-top.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
tools/perf/builtin-top.c +15 -13
@@ -194,21 +194,23 @@ static void perf_top__record_precise_ip(struct perf_top *top,pthread_mutex_unlock (¬es->lock); -/* -* This function is now called with he->hists->lock held. -* Release it before going to sleep. -*/ -pthread_mutex_unlock (&he->hists->lock); +if (unlikely (err)) { +/* +* This function is now called with he->hists->lock held. +* Release it before going to sleep. +*/ +pthread_mutex_unlock (&he->hists->lock); + +if (err == -ERANGE && !he->ms.map->erange_warned) +ui__warn_map_erange (he->ms.map, sym, ip); +else if (err == -ENOMEM ) { +pr_err ("Not enough memory for annotating '%s' symbol!\n" , + sym->name); +sleep (1 ); + } -if (err == -ERANGE && !he->ms.map->erange_warned) -ui__warn_map_erange (he->ms.map, sym, ip); -else if (err == -ENOMEM ) { -pr_err ("Not enough memory for annotating '%s' symbol!\n" , - sym->name); -sleep (1 ); +pthread_mutex_lock (&he->hists->lock); } - -pthread_mutex_lock (&he->hists->lock); }static void perf_top__show_details (struct perf_top *top)
Signature · 1 line
2.6.4
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf top: Access hists->lock only if needed
perf top: Access hists->lock only if needed
Commit-ID: 151ee834cc946fa159ee406c62b4d5ce1ebd7115 Gitweb: http://git.kernel.org/tip/151ee834cc946fa159ee406c62b4d5ce1ebd7115 Author: Namhyung Kim <[email protected]> AuthorDate: Fri, 11 Dec 2015 11:56:54 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 11 Dec 2015 08:34:49 -0300
perf top: Access hists->lock only if needed
The perf_top__record_precise_ip() releases and regrabs the he->hists->lock because it can sleep if there's an error. But it should be done conditionally as it slows down the fast path.
--- tools/perf/builtin-top.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
tools/perf/builtin-top.c +15 -13
@@ -194,21 +194,23 @@ static void perf_top__record_precise_ip(struct perf_top *top,pthread_mutex_unlock (¬es->lock); -/* -* This function is now called with he->hists->lock held. -* Release it before going to sleep. -*/ -pthread_mutex_unlock (&he->hists->lock); +if (unlikely (err)) { +/* +* This function is now called with he->hists->lock held. +* Release it before going to sleep. +*/ +pthread_mutex_unlock (&he->hists->lock); + +if (err == -ERANGE && !he->ms.map->erange_warned) +ui__warn_map_erange (he->ms.map, sym, ip); +else if (err == -ENOMEM ) { +pr_err ("Not enough memory for annotating '%s' symbol!\n" , + sym->name); +sleep (1 ); + } -if (err == -ERANGE && !he->ms.map->erange_warned) -ui__warn_map_erange (he->ms.map, sym, ip); -else if (err == -ENOMEM ) { -pr_err ("Not enough memory for annotating '%s' symbol!\n" , - sym->name); -sleep (1 ); +pthread_mutex_lock (&he->hists->lock); } - -pthread_mutex_lock (&he->hists->lock); }static void perf_top__show_details (struct perf_top *top)
Namhyung Kim
maintainerPATCH 3/4 perf top: Fix annotation on --stdio
In reply to Namhyung KimThe ui__has_annotation() inside perf_top__record_precise_ip() should be removed since it returns true only for TUI (and when sort key has symbol). However the 'perf top --stdio' also supports annotation for a symbol which was specified by 's' key action.
Actually it already does the necessary checks before calling the function. So it's ok to get rid of the check here.
--- tools/perf/builtin-top.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/builtin-top.c +1 -2
@@ -189,8 +189,7 @@ static void perf_top__record_precise_ip(struct perf_top *top,if (pthread_mutex_trylock (¬es->lock))return ; -if (ui__has_annotation ()) - err =hist_entry__inc_addr_samples (he, counter, ip); + err =hist_entry__inc_addr_samples (he, counter, ip);pthread_mutex_unlock (¬es->lock);
Signature · 1 line
2.6.4
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf top: Fix annotation on --stdio
perf top: Fix annotation on --stdio
Commit-ID: 448f13b2d18fdc8dbaada97442e8954dcb4ef8fa Gitweb: http://git.kernel.org/tip/448f13b2d18fdc8dbaada97442e8954dcb4ef8fa Author: Namhyung Kim <[email protected]> AuthorDate: Fri, 11 Dec 2015 11:56:55 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 11 Dec 2015 08:36:18 -0300
perf top: Fix annotation on --stdio
The ui__has_annotation() inside perf_top__record_precise_ip() should be removed since it returns true only for TUI (and when sort key has symbol). However the 'perf top --stdio' also supports annotation for a symbol which was specified by 's' key action.
Actually it already does the necessary checks before calling the function. So it's ok to get rid of the check here.
--- tools/perf/builtin-top.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/builtin-top.c +1 -2
@@ -189,8 +189,7 @@ static void perf_top__record_precise_ip(struct perf_top *top,if (pthread_mutex_trylock (¬es->lock))return ; -if (ui__has_annotation ()) - err =hist_entry__inc_addr_samples (he, counter, ip); + err =hist_entry__inc_addr_samples (he, counter, ip);pthread_mutex_unlock (¬es->lock);
Namhyung Kim
maintainerPATCH 4/4 perf top: Cleanup condition in perf_top__record_precise_ip()
In reply to Namhyung KimThe 'he' cannot be NULL since it's caller hist_iter__top_callback() is called only if iter->he is not NULL (see hist_entry_iter__add). So setting 'sym' before the condition to simplify the code.
Also make it clearer that the top->symbol_filter_entry check is only meaningful on stdio mode (i.e. when use_browser is 0).
--- tools/perf/builtin-top.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
tools/perf/builtin-top.c +4 -5
@@ -175,15 +175,14 @@ static void perf_top__record_precise_ip(struct perf_top *top, int counter, u64 ip) {struct annotation *notes; -struct symbol *sym; +struct symbol *sym = he->ms.sym;int err =0 ; -if (he ==NULL || he->ms.sym ==NULL || - ((top->sym_filter_entry ==NULL || - top->sym_filter_entry->ms.sym != he->ms.sym) && use_browser !=1 )) +if (sym ==NULL || (use_browser ==0 && + (top->sym_filter_entry ==NULL || + top->sym_filter_entry->ms.sym != he->ms.sym)))return ; - sym = he->ms.sym; notes =symbol__annotation (sym);if (pthread_mutex_trylock (¬es->lock))
Signature · 1 line
2.6.4
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 4/4] perf top: Cleanup condition in perf_top__record_precise_ip()
Em Fri, Dec 11, 2015 at 11:56:56AM +0900, Namhyung Kim escreveu:
Quoted 20 lines
The 'he' cannot be NULL since it's caller
hist_iter__top_callback()is called only ifiter->heis not NULL (seehist_entry_iter__add). So setting 'sym' before the condition to simplify the code.Also make it clearer that the
top->symbol_filter_entrycheck is only meaningful on stdio mode (i.e. whenuse_browseris 0).Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/builtin-top.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)tools/perf/builtin-top.c +0
-0@@ -175,15 +175,14 @@ static void perf_top__record_precise_ip(struct perf_top *top, int counter, u64 ip) {struct annotation *notes;
tools/perf/builtin-top.c static void perf_top__record_precise_ip(struct perf_top *top, · line 183
Quoted 10 lines
tools/perf/builtin-top.c +4
-4-struct symbol *sym; +struct symbol *sym = he->ms.sym;int err =0 ; -if (he ==NULL || he->ms.sym ==NULL || - ((top->sym_filter_entry ==NULL || - top->sym_filter_entry->ms.sym != he->ms.sym) && use_browser !=1 )) +if (sym ==NULL || (use_browser ==0 && + (top->sym_filter_entry ==NULL || + top->sym_filter_entry->ms.sym != he->ms.sym)))
Since you're simplifying this... you missed replacing he->ms.sym with sym in this last line, doing that.
Quoted 8 lines
tools/perf/builtin-top.c +0
-1return ; - sym = he->ms.sym; notes =symbol__annotation (sym);if (pthread_mutex_trylock (¬es->lock))Signature · 1 line
2.6.4
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf top: Cleanup condition in perf_top__record_precise_ip()
In reply to Namhyung Kimperf top: Cleanup condition in perf_top__record_precise_ip()
Commit-ID: beefb8d0e556aaf3cb69168c5953e023ace6aa78 Gitweb: http://git.kernel.org/tip/beefb8d0e556aaf3cb69168c5953e023ace6aa78 Author: Namhyung Kim <[email protected]> AuthorDate: Fri, 11 Dec 2015 11:56:56 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 11 Dec 2015 08:38:10 -0300
perf top: Cleanup condition in perf_top__record_precise_ip()
The 'he' cannot be NULL since it's caller hist_iter__top_callback() is called only if iter->he is not NULL (see hist_entry_iter__add). So setting 'sym' before the condition to simplify the code.
Also make it clearer that the top->symbol_filter_entry check is only meaningful on stdio mode (i.e. when use_browser is 0).
--- tools/perf/builtin-top.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
tools/perf/builtin-top.c +4 -5
@@ -175,15 +175,14 @@ static void perf_top__record_precise_ip(struct perf_top *top, int counter, u64 ip) {struct annotation *notes; -struct symbol *sym; +struct symbol *sym = he->ms.sym;int err =0 ; -if (he ==NULL || he->ms.sym ==NULL || - ((top->sym_filter_entry ==NULL || - top->sym_filter_entry->ms.sym != he->ms.sym) && use_browser !=1 )) +if (sym ==NULL || (use_browser ==0 && + (top->sym_filter_entry ==NULL || + top->sym_filter_entry->ms.sym != sym)))return ; - sym = he->ms.sym; notes =symbol__annotation (sym);if (pthread_mutex_trylock (¬es->lock))
Arnaldo Carvalho de Melo
maintainerEm Fri, Dec 11, 2015 at 11:56:53AM +0900, Namhyung Kim escreveu:
Quoted 3 lines
We call
map->unmap_ip()before the function and callmap->map_ip()inside the function. This is meaningless and look strange since only one of the two checks 'map'. Let's useal->addrdirectly.
Thanks for breaking that patch down, this helps with reviewing and bisecting,
- Arnaldo
Quoted 37 lines
Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/builtin-top.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)tools/perf/builtin-top.c +2
-10@@ -189,8 +189,6 @@ static void perf_top__record_precise_ip(struct perf_top *top,if (pthread_mutex_trylock (¬es->lock))return ; - ip = he->ms.map->map_ip (he->ms.map, ip); -if (ui__has_annotation ()) err =hist_entry__inc_addr_samples (he, counter, ip);@@ -687,14 +685,8 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter,struct hist_entry *he = iter->he;struct perf_evsel *evsel = iter->evsel; -if (sort__has_sym && single) { -u64 ip = al->addr; - -if (al->map) - ip = al->map->unmap_ip (al->map, ip); - -perf_top__record_precise_ip (top, he, evsel->idx, ip); - } +if (sort__has_sym && single) +perf_top__record_precise_ip (top, he, evsel->idx, al->addr);hist__account_cycles (iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack &PERF_SAMPLE_BRANCH_ANY ));Signature · 1 line
2.6.4
tip-bot for Namhyung Kim
merge botperf top: Do not convert address for perf_top__record_precise_ip()
Commit-ID: 64226bcf64629996948dc03c38594f00511bfc2b Gitweb: http://git.kernel.org/tip/64226bcf64629996948dc03c38594f00511bfc2b Author: Namhyung Kim <[email protected]> AuthorDate: Fri, 11 Dec 2015 11:56:53 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 11 Dec 2015 08:33:18 -0300
perf top: Do not convert address for perf_top__record_precise_ip()
We call map->unmap_ip() before the function and call map->map_ip() inside the function. This is meaningless and look strange since only one of the two checks 'map'. Let's use al->addr directly.
--- tools/perf/builtin-top.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
tools/perf/builtin-top.c +2 -10
@@ -189,8 +189,6 @@ static void perf_top__record_precise_ip(struct perf_top *top,if (pthread_mutex_trylock (¬es->lock))return ; - ip = he->ms.map->map_ip (he->ms.map, ip); -if (ui__has_annotation ()) err =hist_entry__inc_addr_samples (he, counter, ip);
@@ -687,14 +685,8 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter,struct hist_entry *he = iter->he;struct perf_evsel *evsel = iter->evsel; -if (sort__has_sym && single) { -u64 ip = al->addr; - -if (al->map) - ip = al->map->unmap_ip (al->map, ip); - -perf_top__record_precise_ip (top, he, evsel->idx, ip); - } +if (sort__has_sym && single) +perf_top__record_precise_ip (top, he, evsel->idx, al->addr);hist__account_cycles (iter->sample->branch_stack, al, iter->sample, !(top->record_opts.branch_stack &PERF_SAMPLE_BRANCH_ANY ));