From: David Ahern <dsahern@gmail.com>
To: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>, mingo@kernel.org
Cc: linux-kernel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Subject: Re: [PATCH] perf util: optimize util/machine.c:machines__find().
Date: Thu, 21 Nov 2013 14:16:26 -0700 [thread overview]
Message-ID: <528E782A.9010509@gmail.com> (raw)
In-Reply-To: <1385069470-22692-1-git-send-email-yangds.fnst@cn.fujitsu.com>
On 11/21/13, 2:31 PM, Dongsheng Yang wrote:
> * Remove an unnecessary variable default_machine.
> * Return earlier to avoid unnecessary searching in children.
>
> Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
> ---
> tools/perf/util/machine.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index 84cdb07..f0dd5f6 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -175,8 +175,7 @@ struct machine *machines__find(struct machines *machines, pid_t pid)
> {
> struct rb_node **p = &machines->guests.rb_node;
> struct rb_node *parent = NULL;
> - struct machine *machine;
> - struct machine *default_machine = NULL;
> + struct machine *machine = NULL;
>
> if (pid == HOST_KERNEL_ID)
> return &machines->host;
> @@ -184,17 +183,17 @@ struct machine *machines__find(struct machines *machines, pid_t pid)
> while (*p != NULL) {
> parent = *p;
> machine = rb_entry(parent, struct machine, rb_node);
> + if (!machine->pid)
> + break;
> if (pid < machine->pid)
> p = &(*p)->rb_left;
> else if (pid > machine->pid)
> p = &(*p)->rb_right;
> else
> - return machine;
> - if (!machine->pid)
> - default_machine = machine;
> + break;
> }
>
> - return default_machine;
> + return machine;
> }
This changes machines__find to always return the machine for the host
(pid == 0). This function is also used for VM lookups.
David
next prev parent reply other threads:[~2013-11-21 21:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-21 21:31 [PATCH] perf util: optimize util/machine.c:machines__find() Dongsheng Yang
2013-11-21 21:16 ` David Ahern [this message]
2013-11-22 0:06 ` Arnaldo Carvalho de Melo
2013-11-22 18:59 ` Dongsheng Yang
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=528E782A.9010509@gmail.com \
--to=dsahern@gmail.com \
--cc=acme@ghostprotocols.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=yangds.fnst@cn.fujitsu.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.