linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf annotate: Remove hist__account_cycles from callback
@ 2019-03-12 20:22 Jin Yao
  2019-03-14 11:34 ` Jin, Yao
  2019-03-14 12:04 ` Jiri Olsa
  0 siblings, 2 replies; 5+ messages in thread
From: Jin Yao @ 2019-03-12 20:22 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

The hist__account_cycles is executed when the hist_iter__branch_callback
is called. But it looks it's not necessary. In hist__account_cycles, it
already walks on all branch entries.

This patch moves the hist__account_cycles out of callback, now the data
processing is much faster than before.

For example,
perf record -b ...
perf annotate

The before/after output should be no change.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/builtin-annotate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 67f9d9f..77deb3a 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -159,8 +159,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,
 	struct perf_evsel *evsel = iter->evsel;
 	int err;
 
-	hist__account_cycles(sample->branch_stack, al, sample, false);
-
 	bi = he->branch_info;
 	err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
 
@@ -199,6 +197,8 @@ static int process_branch_callback(struct perf_evsel *evsel,
 	if (a.map != NULL)
 		a.map->dso->hit = 1;
 
+	hist__account_cycles(sample->branch_stack, al, sample, false);
+
 	ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
 	return ret;
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf annotate: Remove hist__account_cycles from callback
  2019-03-12 20:22 [PATCH] perf annotate: Remove hist__account_cycles from callback Jin Yao
@ 2019-03-14 11:34 ` Jin, Yao
  2019-03-14 12:04 ` Jiri Olsa
  1 sibling, 0 replies; 5+ messages in thread
From: Jin, Yao @ 2019-03-14 11:34 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin

Any comments for this patch or any issue is found? In testing, I just 
feel it accelerates the perf annotate data processing.

Thanks
Jin Yao

On 3/13/2019 4:22 AM, Jin Yao wrote:
> The hist__account_cycles is executed when the hist_iter__branch_callback
> is called. But it looks it's not necessary. In hist__account_cycles, it
> already walks on all branch entries.
> 
> This patch moves the hist__account_cycles out of callback, now the data
> processing is much faster than before.
> 
> For example,
> perf record -b ...
> perf annotate
> 
> The before/after output should be no change.
> 
> Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
> ---
>   tools/perf/builtin-annotate.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
> index 67f9d9f..77deb3a 100644
> --- a/tools/perf/builtin-annotate.c
> +++ b/tools/perf/builtin-annotate.c
> @@ -159,8 +159,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,
>   	struct perf_evsel *evsel = iter->evsel;
>   	int err;
>   
> -	hist__account_cycles(sample->branch_stack, al, sample, false);
> -
>   	bi = he->branch_info;
>   	err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
>   
> @@ -199,6 +197,8 @@ static int process_branch_callback(struct perf_evsel *evsel,
>   	if (a.map != NULL)
>   		a.map->dso->hit = 1;
>   
> +	hist__account_cycles(sample->branch_stack, al, sample, false);
> +
>   	ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
>   	return ret;
>   }
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf annotate: Remove hist__account_cycles from callback
  2019-03-12 20:22 [PATCH] perf annotate: Remove hist__account_cycles from callback Jin Yao
  2019-03-14 11:34 ` Jin, Yao
@ 2019-03-14 12:04 ` Jiri Olsa
  2019-03-14 14:17   ` Jin, Yao
  1 sibling, 1 reply; 5+ messages in thread
From: Jiri Olsa @ 2019-03-14 12:04 UTC (permalink / raw)
  To: Jin Yao
  Cc: acme, jolsa, peterz, mingo, alexander.shishkin, Linux-kernel, ak,
	kan.liang, yao.jin

On Wed, Mar 13, 2019 at 04:22:54AM +0800, Jin Yao wrote:
> The hist__account_cycles is executed when the hist_iter__branch_callback
> is called. But it looks it's not necessary. In hist__account_cycles, it
> already walks on all branch entries.
> 
> This patch moves the hist__account_cycles out of callback, now the data
> processing is much faster than before.
> 
> For example,
> perf record -b ...
> perf annotate
> 
> The before/after output should be no change.

so in the old code it was called multiple times per sample,
while after your change it's called just once per sample

it increases cycles stats for symbol, so it's strange
the behaviour is the same.. could you please exaplin this
in more detail?

> 
> Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
> ---
>  tools/perf/builtin-annotate.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
> index 67f9d9f..77deb3a 100644
> --- a/tools/perf/builtin-annotate.c
> +++ b/tools/perf/builtin-annotate.c
> @@ -159,8 +159,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,
>  	struct perf_evsel *evsel = iter->evsel;
>  	int err;
>  
> -	hist__account_cycles(sample->branch_stack, al, sample, false);
> -

there's similar code in perf report, could you please cover
that as well?

thanks,
jirka

>  	bi = he->branch_info;
>  	err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
>  
> @@ -199,6 +197,8 @@ static int process_branch_callback(struct perf_evsel *evsel,
>  	if (a.map != NULL)
>  		a.map->dso->hit = 1;
>  
> +	hist__account_cycles(sample->branch_stack, al, sample, false);
> +
>  	ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
>  	return ret;
>  }
> -- 
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf annotate: Remove hist__account_cycles from callback
  2019-03-14 12:04 ` Jiri Olsa
@ 2019-03-14 14:17   ` Jin, Yao
  2019-03-15  4:20     ` Jin, Yao
  0 siblings, 1 reply; 5+ messages in thread
From: Jin, Yao @ 2019-03-14 14:17 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: acme, jolsa, peterz, mingo, alexander.shishkin, Linux-kernel, ak,
	kan.liang, yao.jin



On 3/14/2019 8:04 PM, Jiri Olsa wrote:
> On Wed, Mar 13, 2019 at 04:22:54AM +0800, Jin Yao wrote:
>> The hist__account_cycles is executed when the hist_iter__branch_callback
>> is called. But it looks it's not necessary. In hist__account_cycles, it
>> already walks on all branch entries.
>>
>> This patch moves the hist__account_cycles out of callback, now the data
>> processing is much faster than before.
>>
>> For example,
>> perf record -b ...
>> perf annotate
>>
>> The before/after output should be no change.
> 
> so in the old code it was called multiple times per sample,
> while after your change it's called just once per sample
> 
> it increases cycles stats for symbol, so it's strange
> the behaviour is the same.. could you please exaplin this
> in more detail?
> 

In __symbol__account_cycles,
ch[offset].num_aggr++;
ch[offset].cycles_aggr += cycles;

In annotation__compute_ipc,
al = notes->offsets[offset];
al->cycles = ch->cycles_aggr / ch->num_aggr;

So the num_aggr and cycles_aggr are both increased n times, then the 
final result is the same.

>>
>> Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
>> ---
>>   tools/perf/builtin-annotate.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
>> index 67f9d9f..77deb3a 100644
>> --- a/tools/perf/builtin-annotate.c
>> +++ b/tools/perf/builtin-annotate.c
>> @@ -159,8 +159,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,
>>   	struct perf_evsel *evsel = iter->evsel;
>>   	int err;
>>   
>> -	hist__account_cycles(sample->branch_stack, al, sample, false);
>> -
> 
> there's similar code in perf report, could you please cover
> that as well?
> 

Sure, let me have a try.

Thanks
Jin Yao

> thanks,
> jirka
> 
>>   	bi = he->branch_info;
>>   	err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
>>   
>> @@ -199,6 +197,8 @@ static int process_branch_callback(struct perf_evsel *evsel,
>>   	if (a.map != NULL)
>>   		a.map->dso->hit = 1;
>>   
>> +	hist__account_cycles(sample->branch_stack, al, sample, false);
>> +
>>   	ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
>>   	return ret;
>>   }
>> -- 
>> 2.7.4
>>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf annotate: Remove hist__account_cycles from callback
  2019-03-14 14:17   ` Jin, Yao
@ 2019-03-15  4:20     ` Jin, Yao
  0 siblings, 0 replies; 5+ messages in thread
From: Jin, Yao @ 2019-03-15  4:20 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: acme, jolsa, peterz, mingo, alexander.shishkin, Linux-kernel, ak,
	kan.liang, yao.jin



On 3/14/2019 10:17 PM, Jin, Yao wrote:
> 
> 
> On 3/14/2019 8:04 PM, Jiri Olsa wrote:
>> On Wed, Mar 13, 2019 at 04:22:54AM +0800, Jin Yao wrote:
>>> The hist__account_cycles is executed when the hist_iter__branch_callback
>>> is called. But it looks it's not necessary. In hist__account_cycles, it
>>> already walks on all branch entries.
>>>
>>> This patch moves the hist__account_cycles out of callback, now the data
>>> processing is much faster than before.
>>>
>>> For example,
>>> perf record -b ...
>>> perf annotate
>>>
>>> The before/after output should be no change.
>>
>> so in the old code it was called multiple times per sample,
>> while after your change it's called just once per sample
>>
>> it increases cycles stats for symbol, so it's strange
>> the behaviour is the same.. could you please exaplin this
>> in more detail?
>>
> 
> In __symbol__account_cycles,
> ch[offset].num_aggr++;
> ch[offset].cycles_aggr += cycles;
> 
> In annotation__compute_ipc,
> al = notes->offsets[offset];
> al->cycles = ch->cycles_aggr / ch->num_aggr;
> 
> So the num_aggr and cycles_aggr are both increased n times, then the 
> final result is the same.
> 

There might be another potential issue in annotation__count_and_fill.

/* Hide data when there are too many overlaps. */
if (ch->reset >= 0x7fff || ch->reset >= ch->num / 2)
	return;

When ch->reset is 0 and ch->num is 1, it returns directly. But for this 
case, the data doesn't need to be hidden since there is no overlap 
happening.

I will post v2 and add this fix.

Thanks
Jin Yao

>>>
>>> Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
>>> ---
>>>   tools/perf/builtin-annotate.c | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/tools/perf/builtin-annotate.c 
>>> b/tools/perf/builtin-annotate.c
>>> index 67f9d9f..77deb3a 100644
>>> --- a/tools/perf/builtin-annotate.c
>>> +++ b/tools/perf/builtin-annotate.c
>>> @@ -159,8 +159,6 @@ static int hist_iter__branch_callback(struct 
>>> hist_entry_iter *iter,
>>>       struct perf_evsel *evsel = iter->evsel;
>>>       int err;
>>> -    hist__account_cycles(sample->branch_stack, al, sample, false);
>>> -
>>
>> there's similar code in perf report, could you please cover
>> that as well?
>>
> 
> Sure, let me have a try.
> 
> Thanks
> Jin Yao
> 
>> thanks,
>> jirka
>>
>>>       bi = he->branch_info;
>>>       err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
>>> @@ -199,6 +197,8 @@ static int process_branch_callback(struct 
>>> perf_evsel *evsel,
>>>       if (a.map != NULL)
>>>           a.map->dso->hit = 1;
>>> +    hist__account_cycles(sample->branch_stack, al, sample, false);
>>> +
>>>       ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
>>>       return ret;
>>>   }
>>> -- 
>>> 2.7.4
>>>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-03-15  4:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-12 20:22 [PATCH] perf annotate: Remove hist__account_cycles from callback Jin Yao
2019-03-14 11:34 ` Jin, Yao
2019-03-14 12:04 ` Jiri Olsa
2019-03-14 14:17   ` Jin, Yao
2019-03-15  4:20     ` Jin, Yao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).