public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: Jiri Olsa <jolsa@redhat.com>,
	linux-kernel@vger.kernel.org,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH v2] perf map: optimize maps__fixup_overlappings()
Date: Tue, 7 Aug 2018 17:02:37 -0300	[thread overview]
Message-ID: <20180807200237.GA5395@kernel.org> (raw)
In-Reply-To: <153365189407.435244.7234821822450484712.stgit@buzz>

Em Tue, Aug 07, 2018 at 05:24:54PM +0300, Konstantin Khlebnikov escreveu:
> This function splits and removes overlapping areas.
> 
> Maps in tree are ordered by start address thus we could find
> first overlap and stop if next map does not overlap.
> 
> Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>

Jiri, I'm applying this one with your Acked-by, ok?

- Arnaldo
 
> ---
> 
> v2:
> * add comments
> * replace map__overlap with minimal check
> * remove remove map__overlap, that was the only user
> ---
>  tools/perf/util/map.c |   44 ++++++++++++++++++++++++++------------------
>  tools/perf/util/map.h |    1 -
>  2 files changed, 26 insertions(+), 19 deletions(-)
> 
> diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
> index 89ac5b5dc218..36d0763311ef 100644
> --- a/tools/perf/util/map.c
> +++ b/tools/perf/util/map.c
> @@ -381,20 +381,6 @@ struct map *map__clone(struct map *from)
>  	return map;
>  }
>  
> -int map__overlap(struct map *l, struct map *r)
> -{
> -	if (l->start > r->start) {
> -		struct map *t = l;
> -		l = r;
> -		r = t;
> -	}
> -
> -	if (l->end > r->start)
> -		return 1;
> -
> -	return 0;
> -}
> -
>  size_t map__fprintf(struct map *map, FILE *fp)
>  {
>  	return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s\n",
> @@ -675,20 +661,42 @@ static void __map_groups__insert(struct map_groups *mg, struct map *map)
>  static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
>  {
>  	struct rb_root *root;
> -	struct rb_node *next;
> +	struct rb_node *next, *first;
>  	int err = 0;
>  
>  	down_write(&maps->lock);
>  
>  	root = &maps->entries;
> -	next = rb_first(root);
>  
> +	/*
> +	 * Find first map where end > map->start.
> +	 * Same as find_vma() in kernel.
> +	 */
> +	next = root->rb_node;
> +	first = NULL;
> +	while (next) {
> +		struct map *pos = rb_entry(next, struct map, rb_node);
> +
> +		if (pos->end > map->start) {
> +			first = next;
> +			if (pos->start <= map->start)
> +				break;
> +			next = next->rb_left;
> +		} else
> +			next = next->rb_right;
> +	}
> +
> +	next = first;
>  	while (next) {
>  		struct map *pos = rb_entry(next, struct map, rb_node);
>  		next = rb_next(&pos->rb_node);
>  
> -		if (!map__overlap(pos, map))
> -			continue;
> +		/*
> +		 * Stop if current map starts after map->end.
> +		 * Maps are ordered by start: next will not overlap for sure.
> +		 */
> +		if (pos->start >= map->end)
> +			break;
>  
>  		if (verbose >= 2) {
>  
> diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
> index 4cb90f242bed..e0f327b51e66 100644
> --- a/tools/perf/util/map.h
> +++ b/tools/perf/util/map.h
> @@ -166,7 +166,6 @@ static inline void __map__zput(struct map **map)
>  
>  #define map__zput(map) __map__zput(&map)
>  
> -int map__overlap(struct map *l, struct map *r);
>  size_t map__fprintf(struct map *map, FILE *fp);
>  size_t map__fprintf_dsoname(struct map *map, FILE *fp);
>  char *map__srcline(struct map *map, u64 addr, struct symbol *sym);

  reply	other threads:[~2018-08-07 20:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-07  9:09 [PATCH 1/2] perf map: synthesize maps only for thread group leader Konstantin Khlebnikov
2018-08-07  9:09 ` [PATCH 2/2] perf map: optimize maps__fixup_overlappings() Konstantin Khlebnikov
2018-08-07 12:55   ` Jiri Olsa
2018-08-07 13:15     ` Arnaldo Carvalho de Melo
2018-08-07 14:24   ` [PATCH v2] " Konstantin Khlebnikov
2018-08-07 20:02     ` Arnaldo Carvalho de Melo [this message]
2018-08-07 23:03       ` Jiri Olsa
2018-08-08 12:40         ` Arnaldo Carvalho de Melo
2018-08-18 11:42     ` [tip:perf/urgent] perf map: Optimize maps__fixup_overlappings() tip-bot for Konstantin Khlebnikov
2018-08-07 12:43 ` [PATCH 1/2] perf map: synthesize maps only for thread group leader Jiri Olsa
2018-08-07 13:15   ` Arnaldo Carvalho de Melo
2018-08-18 11:41 ` [tip:perf/urgent] perf map: Synthesize " tip-bot for Konstantin Khlebnikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180807200237.GA5395@kernel.org \
    --to=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=khlebnikov@yandex-team.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox