2018-03-13 12:42:25

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH v2 -perf/core 1/2] perf mmap: Discard head in overwrite_rb_find_range

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 <[email protected]>
---
v2:
- rebase to perf/core

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 074c4fd..38ca3ff 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -199,19 +199,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;
@@ -262,7 +261,7 @@ int perf_mmap__read_init(struct perf_mmap *md)
* 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, &md->start, &md->end))
+ if (overwrite_rb_find_range(data, md->mask, &md->start, &md->end))
return -EINVAL;
}

--
1.7.12.4



2018-03-13 12:42:37

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH v2 -perf/core 2/2] perf debug: Avoid set quiet once more

When use --quiet to disable log, we will set quiet first, then check the
quiet to decide whether need to call perf_quiet_option, so no need to set
the quiet once more.

Signed-off-by: Yisheng Xie <[email protected]>
---
- This is a new add-on patch

tools/perf/util/debug.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index f3a71db..3d64596 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -232,7 +232,6 @@ int perf_quiet_option(void)
var++;
}

- quiet = true;
return 0;
}

--
1.7.12.4


2018-03-16 14:18:01

by Liang, Kan

[permalink] [raw]
Subject: Re: [PATCH v2 -perf/core 1/2] perf mmap: Discard head in overwrite_rb_find_range



On 3/13/2018 8:31 AM, 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.
>

Looks good to me.

Reviewed-by: Kan Liang <[email protected]>

Thanks,
Kan

> Signed-off-by: Yisheng Xie <[email protected]>
> ---
> v2:
> - rebase to perf/core
>
> 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 074c4fd..38ca3ff 100644
> --- a/tools/perf/util/mmap.c
> +++ b/tools/perf/util/mmap.c
> @@ -199,19 +199,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;
> @@ -262,7 +261,7 @@ int perf_mmap__read_init(struct perf_mmap *md)
> * 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, &md->start, &md->end))
> + if (overwrite_rb_find_range(data, md->mask, &md->start, &md->end))
> return -EINVAL;
> }
>
>

Subject: [tip:perf/core] perf debug: Avoid setting 'quiet' to 'true' unnecessarily

Commit-ID: a08f6dd4190e90dc7b013435acb66770f117e8b0
Gitweb: https://git.kernel.org/tip/a08f6dd4190e90dc7b013435acb66770f117e8b0
Author: Yisheng Xie <[email protected]>
AuthorDate: Tue, 13 Mar 2018 20:31:14 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 16 Mar 2018 16:39:02 -0300

perf debug: Avoid setting 'quiet' to 'true' unnecessarily

When using --quiet to disable messages, we will set the 'quiet' variable
to 'true' first, then check that variable to decide whether we need to
call perf_quiet_option(), so no need to set 'quiet' to 'true' once more
in perf_quiet_option().

Signed-off-by: Yisheng Xie <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Kan Liang <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/debug.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index f3a71db83947..3d6459626c2a 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -232,7 +232,6 @@ int perf_quiet_option(void)
var++;
}

- quiet = true;
return 0;
}


Subject: [tip:perf/core] perf mmap: Discard head in overwrite_rb_find_range()

Commit-ID: 699db111058798bcc9f92a93767062905a561bef
Gitweb: https://git.kernel.org/tip/699db111058798bcc9f92a93767062905a561bef
Author: Yisheng Xie <[email protected]>
AuthorDate: Tue, 13 Mar 2018 20:31:13 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 16 Mar 2018 16:33:05 -0300

perf mmap: Discard head in overwrite_rb_find_range()

In overwrite mode, start will be set to head in perf_mmap__read_init().
Therefore, there is no need to set the start one more time 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 <[email protected]>
Reviewed-by: Kan Liang <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
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 074c4fd3b67e..38ca3ffb9d61 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -199,19 +199,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;
@@ -262,7 +261,7 @@ int perf_mmap__read_init(struct perf_mmap *md)
* 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, &md->start, &md->end))
+ if (overwrite_rb_find_range(data, md->mask, &md->start, &md->end))
return -EINVAL;
}