linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf mmap: Discard head in overwrite_rb_find_range
@ 2018-03-06 11:44 Yisheng Xie
  2018-03-07 10:21 ` Jiri Olsa
  0 siblings, 1 reply; 5+ messages in thread
From: Yisheng Xie @ 2018-03-06 11:44 UTC (permalink / raw)
  To: acme
  Cc: mingo, peterz, namhyung, jolsa, alexander.shishkin, linux-kernel,
	Yisheng Xie

In overwrite mode, start will be set to head in perf_mmap__read_init.
Therefore, it is no need to set the start one more in
overwrite_rb_find_range and *start can be used as head instead of
passing head to overwrite_rb_find_range.

Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
---
 tools/perf/util/mmap.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 91531a7..6751ac9 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -223,19 +223,18 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd)
 	return 0;
 }
 
-static int overwrite_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64 *end)
+static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
 {
 	struct perf_event_header *pheader;
-	u64 evt_head = head;
+	u64 evt_head = *start;
 	int size = mask + 1;
 
-	pr_debug2("overwrite_rb_find_range: buf=%p, head=%"PRIx64"\n", buf, head);
-	pheader = (struct perf_event_header *)(buf + (head & mask));
-	*start = head;
+	pr_debug2("%s: buf=%p, start=%"PRIx64"\n", __func__, buf, *start);
+	pheader = (struct perf_event_header *)(buf + (*start & mask));
 	while (true) {
-		if (evt_head - head >= (unsigned int)size) {
+		if (evt_head - *start >= (unsigned int)size) {
 			pr_debug("Finished reading overwrite ring buffer: rewind\n");
-			if (evt_head - head > (unsigned int)size)
+			if (evt_head - *start > (unsigned int)size)
 				evt_head -= pheader->size;
 			*end = evt_head;
 			return 0;
@@ -287,7 +286,7 @@ int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,
 		 * Backward ring buffer is full. We still have a chance to read
 		 * most of data from it.
 		 */
-		if (overwrite_rb_find_range(data, md->mask, head, startp, endp))
+		if (overwrite_rb_find_range(data, md->mask, startp, endp))
 			return -EINVAL;
 	}
 
-- 
1.7.12.4

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

* Re: [PATCH] perf mmap: Discard head in overwrite_rb_find_range
  2018-03-06 11:44 [PATCH] perf mmap: Discard head in overwrite_rb_find_range Yisheng Xie
@ 2018-03-07 10:21 ` Jiri Olsa
  2018-03-07 11:01   ` Yisheng Xie
  2018-03-07 13:58   ` Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 5+ messages in thread
From: Jiri Olsa @ 2018-03-07 10:21 UTC (permalink / raw)
  To: Yisheng Xie
  Cc: acme, mingo, peterz, namhyung, alexander.shishkin, linux-kernel,
	Kan Liang

On Tue, Mar 06, 2018 at 07:44:23PM +0800, Yisheng Xie wrote:
> In overwrite mode, start will be set to head in perf_mmap__read_init.
> Therefore, it is no need to set the start one more in
> overwrite_rb_find_range and *start can be used as head instead of
> passing head to overwrite_rb_find_range.

it conflicts a little with recent cleanup from Kan Liang,,
  https://marc.info/?t=152035082800001&r=1&w=2

otherwise it looks ok to me

jirka

> 
> Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
> ---
>  tools/perf/util/mmap.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
> index 91531a7..6751ac9 100644
> --- a/tools/perf/util/mmap.c
> +++ b/tools/perf/util/mmap.c
> @@ -223,19 +223,18 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd)
>  	return 0;
>  }
>  
> -static int overwrite_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64 *end)
> +static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
>  {
>  	struct perf_event_header *pheader;
> -	u64 evt_head = head;
> +	u64 evt_head = *start;
>  	int size = mask + 1;
>  
> -	pr_debug2("overwrite_rb_find_range: buf=%p, head=%"PRIx64"\n", buf, head);
> -	pheader = (struct perf_event_header *)(buf + (head & mask));
> -	*start = head;
> +	pr_debug2("%s: buf=%p, start=%"PRIx64"\n", __func__, buf, *start);
> +	pheader = (struct perf_event_header *)(buf + (*start & mask));
>  	while (true) {
> -		if (evt_head - head >= (unsigned int)size) {
> +		if (evt_head - *start >= (unsigned int)size) {
>  			pr_debug("Finished reading overwrite ring buffer: rewind\n");
> -			if (evt_head - head > (unsigned int)size)
> +			if (evt_head - *start > (unsigned int)size)
>  				evt_head -= pheader->size;
>  			*end = evt_head;
>  			return 0;
> @@ -287,7 +286,7 @@ int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,
>  		 * Backward ring buffer is full. We still have a chance to read
>  		 * most of data from it.
>  		 */
> -		if (overwrite_rb_find_range(data, md->mask, head, startp, endp))
> +		if (overwrite_rb_find_range(data, md->mask, startp, endp))
>  			return -EINVAL;
>  	}
>  
> -- 
> 1.7.12.4
> 

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

* Re: [PATCH] perf mmap: Discard head in overwrite_rb_find_range
  2018-03-07 10:21 ` Jiri Olsa
@ 2018-03-07 11:01   ` Yisheng Xie
  2018-03-07 13:58   ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 5+ messages in thread
From: Yisheng Xie @ 2018-03-07 11:01 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: acme, mingo, peterz, namhyung, alexander.shishkin, linux-kernel,
	Kan Liang

Hi jirka,

On 2018/3/7 18:21, Jiri Olsa wrote:
> On Tue, Mar 06, 2018 at 07:44:23PM +0800, Yisheng Xie wrote:
>> In overwrite mode, start will be set to head in perf_mmap__read_init.
>> Therefore, it is no need to set the start one more in
>> overwrite_rb_find_range and *start can be used as head instead of
>> passing head to overwrite_rb_find_range.
> 
> it conflicts a little with recent cleanup from Kan Liang,,
>   https://marc.info/?t=152035082800001&r=1&w=2
> 
> otherwise it looks ok to me
> 

I can send the next version based on Kan's patch after his patches are in the tree.

Thanks
Yisheng

> jirka
> 
>>
>> Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
>> ---
>>  tools/perf/util/mmap.c | 15 +++++++--------
>>  1 file changed, 7 insertions(+), 8 deletions(-)
>>
>> diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
>> index 91531a7..6751ac9 100644
>> --- a/tools/perf/util/mmap.c
>> +++ b/tools/perf/util/mmap.c
>> @@ -223,19 +223,18 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd)
>>  	return 0;
>>  }
>>  
>> -static int overwrite_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64 *end)
>> +static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
>>  {
>>  	struct perf_event_header *pheader;
>> -	u64 evt_head = head;
>> +	u64 evt_head = *start;
>>  	int size = mask + 1;
>>  
>> -	pr_debug2("overwrite_rb_find_range: buf=%p, head=%"PRIx64"\n", buf, head);
>> -	pheader = (struct perf_event_header *)(buf + (head & mask));
>> -	*start = head;
>> +	pr_debug2("%s: buf=%p, start=%"PRIx64"\n", __func__, buf, *start);
>> +	pheader = (struct perf_event_header *)(buf + (*start & mask));
>>  	while (true) {
>> -		if (evt_head - head >= (unsigned int)size) {
>> +		if (evt_head - *start >= (unsigned int)size) {
>>  			pr_debug("Finished reading overwrite ring buffer: rewind\n");
>> -			if (evt_head - head > (unsigned int)size)
>> +			if (evt_head - *start > (unsigned int)size)
>>  				evt_head -= pheader->size;
>>  			*end = evt_head;
>>  			return 0;
>> @@ -287,7 +286,7 @@ int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,
>>  		 * Backward ring buffer is full. We still have a chance to read
>>  		 * most of data from it.
>>  		 */
>> -		if (overwrite_rb_find_range(data, md->mask, head, startp, endp))
>> +		if (overwrite_rb_find_range(data, md->mask, startp, endp))
>>  			return -EINVAL;
>>  	}
>>  
>> -- 
>> 1.7.12.4
>>
> 
> .
> 

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

* Re: [PATCH] perf mmap: Discard head in overwrite_rb_find_range
  2018-03-07 10:21 ` Jiri Olsa
  2018-03-07 11:01   ` Yisheng Xie
@ 2018-03-07 13:58   ` Arnaldo Carvalho de Melo
  2018-03-08  1:05     ` Yisheng Xie
  1 sibling, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-03-07 13:58 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Yisheng Xie, mingo, peterz, namhyung, acme, alexander.shishkin,
	linux-kernel, Kan Liang

Em Wed, Mar 07, 2018 at 11:21:57AM +0100, Jiri Olsa escreveu:
> On Tue, Mar 06, 2018 at 07:44:23PM +0800, Yisheng Xie wrote:
> > In overwrite mode, start will be set to head in perf_mmap__read_init.
> > Therefore, it is no need to set the start one more in
> > overwrite_rb_find_range and *start can be used as head instead of
> > passing head to overwrite_rb_find_range.
> 
> it conflicts a little with recent cleanup from Kan Liang,,
>   https://marc.info/?t=152035082800001&r=1&w=2
> 
> otherwise it looks ok to me

yeah, wait a while till I push Kan's simplifications and then resubmit,
ok?

- Arnaldo
 
> jirka
> 
> > 
> > Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
> > ---
> >  tools/perf/util/mmap.c | 15 +++++++--------
> >  1 file changed, 7 insertions(+), 8 deletions(-)
> > 
> > diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
> > index 91531a7..6751ac9 100644
> > --- a/tools/perf/util/mmap.c
> > +++ b/tools/perf/util/mmap.c
> > @@ -223,19 +223,18 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd)
> >  	return 0;
> >  }
> >  
> > -static int overwrite_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64 *end)
> > +static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
> >  {
> >  	struct perf_event_header *pheader;
> > -	u64 evt_head = head;
> > +	u64 evt_head = *start;
> >  	int size = mask + 1;
> >  
> > -	pr_debug2("overwrite_rb_find_range: buf=%p, head=%"PRIx64"\n", buf, head);
> > -	pheader = (struct perf_event_header *)(buf + (head & mask));
> > -	*start = head;
> > +	pr_debug2("%s: buf=%p, start=%"PRIx64"\n", __func__, buf, *start);
> > +	pheader = (struct perf_event_header *)(buf + (*start & mask));
> >  	while (true) {
> > -		if (evt_head - head >= (unsigned int)size) {
> > +		if (evt_head - *start >= (unsigned int)size) {
> >  			pr_debug("Finished reading overwrite ring buffer: rewind\n");
> > -			if (evt_head - head > (unsigned int)size)
> > +			if (evt_head - *start > (unsigned int)size)
> >  				evt_head -= pheader->size;
> >  			*end = evt_head;
> >  			return 0;
> > @@ -287,7 +286,7 @@ int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,
> >  		 * Backward ring buffer is full. We still have a chance to read
> >  		 * most of data from it.
> >  		 */
> > -		if (overwrite_rb_find_range(data, md->mask, head, startp, endp))
> > +		if (overwrite_rb_find_range(data, md->mask, startp, endp))
> >  			return -EINVAL;
> >  	}
> >  
> > -- 
> > 1.7.12.4
> > 

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

* Re: [PATCH] perf mmap: Discard head in overwrite_rb_find_range
  2018-03-07 13:58   ` Arnaldo Carvalho de Melo
@ 2018-03-08  1:05     ` Yisheng Xie
  0 siblings, 0 replies; 5+ messages in thread
From: Yisheng Xie @ 2018-03-08  1:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: mingo, peterz, namhyung, acme, alexander.shishkin, linux-kernel,
	Kan Liang

Hi Arnaldo,

On 2018/3/7 21:58, Arnaldo Carvalho de Melo wrote:
> Em Wed, Mar 07, 2018 at 11:21:57AM +0100, Jiri Olsa escreveu:
>> On Tue, Mar 06, 2018 at 07:44:23PM +0800, Yisheng Xie wrote:
>>> In overwrite mode, start will be set to head in perf_mmap__read_init.
>>> Therefore, it is no need to set the start one more in
>>> overwrite_rb_find_range and *start can be used as head instead of
>>> passing head to overwrite_rb_find_range.
>>
>> it conflicts a little with recent cleanup from Kan Liang,,
>>   https://marc.info/?t=152035082800001&r=1&w=2
>>
>> otherwise it looks ok to me
> 
> yeah, wait a while till I push Kan's simplifications and then resubmit,
> ok?
> 
Sure, I will wait and resubmit.

Thanks
Yisheng

> - Arnaldo
>  
>> jirka
>>
>>>
>>> Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
>>> ---
>>>  tools/perf/util/mmap.c | 15 +++++++--------
>>>  1 file changed, 7 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
>>> index 91531a7..6751ac9 100644
>>> --- a/tools/perf/util/mmap.c
>>> +++ b/tools/perf/util/mmap.c
>>> @@ -223,19 +223,18 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd)
>>>  	return 0;
>>>  }
>>>  
>>> -static int overwrite_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64 *end)
>>> +static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
>>>  {
>>>  	struct perf_event_header *pheader;
>>> -	u64 evt_head = head;
>>> +	u64 evt_head = *start;
>>>  	int size = mask + 1;
>>>  
>>> -	pr_debug2("overwrite_rb_find_range: buf=%p, head=%"PRIx64"\n", buf, head);
>>> -	pheader = (struct perf_event_header *)(buf + (head & mask));
>>> -	*start = head;
>>> +	pr_debug2("%s: buf=%p, start=%"PRIx64"\n", __func__, buf, *start);
>>> +	pheader = (struct perf_event_header *)(buf + (*start & mask));
>>>  	while (true) {
>>> -		if (evt_head - head >= (unsigned int)size) {
>>> +		if (evt_head - *start >= (unsigned int)size) {
>>>  			pr_debug("Finished reading overwrite ring buffer: rewind\n");
>>> -			if (evt_head - head > (unsigned int)size)
>>> +			if (evt_head - *start > (unsigned int)size)
>>>  				evt_head -= pheader->size;
>>>  			*end = evt_head;
>>>  			return 0;
>>> @@ -287,7 +286,7 @@ int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,
>>>  		 * Backward ring buffer is full. We still have a chance to read
>>>  		 * most of data from it.
>>>  		 */
>>> -		if (overwrite_rb_find_range(data, md->mask, head, startp, endp))
>>> +		if (overwrite_rb_find_range(data, md->mask, startp, endp))
>>>  			return -EINVAL;
>>>  	}
>>>  
>>> -- 
>>> 1.7.12.4
>>>
> 
> .
> 

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

end of thread, other threads:[~2018-03-08  1:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-06 11:44 [PATCH] perf mmap: Discard head in overwrite_rb_find_range Yisheng Xie
2018-03-07 10:21 ` Jiri Olsa
2018-03-07 11:01   ` Yisheng Xie
2018-03-07 13:58   ` Arnaldo Carvalho de Melo
2018-03-08  1:05     ` Yisheng Xie

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).