* Re: [PATCH] perf util: optimize util/machine.c:machines__find().
2013-11-21 21:31 [PATCH] perf util: optimize util/machine.c:machines__find() Dongsheng Yang
@ 2013-11-21 21:16 ` David Ahern
2013-11-22 0:06 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 4+ messages in thread
From: David Ahern @ 2013-11-21 21:16 UTC (permalink / raw)
To: Dongsheng Yang, mingo; +Cc: linux-kernel, Arnaldo Carvalho de Melo
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] perf util: optimize util/machine.c:machines__find().
@ 2013-11-21 21:31 Dongsheng Yang
2013-11-21 21:16 ` David Ahern
0 siblings, 1 reply; 4+ messages in thread
From: Dongsheng Yang @ 2013-11-21 21:31 UTC (permalink / raw)
To: mingo, dsahern; +Cc: linux-kernel, Dongsheng Yang
* 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;
}
struct machine *machines__findnew(struct machines *machines, pid_t pid)
--
1.8.2.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] perf util: optimize util/machine.c:machines__find().
2013-11-21 21:16 ` David Ahern
@ 2013-11-22 0:06 ` Arnaldo Carvalho de Melo
2013-11-22 18:59 ` Dongsheng Yang
0 siblings, 1 reply; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2013-11-22 0:06 UTC (permalink / raw)
To: David Ahern; +Cc: Dongsheng Yang, mingo, linux-kernel
Em Thu, Nov 21, 2013 at 02:16:26PM -0700, David Ahern escreveu:
> 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>
> >+++ 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.
Nope:
/* Native host kernel uses -1 as pid index in machine */
#define HOST_KERNEL_ID (-1)
#define DEFAULT_GUEST_KERNEL_ID (0)
But I fail to see the point of the "optimization", we're looking for a
pid, not always for '0'.
And the changelog is horrible, why is it "unnecessary"? Please don't be
so terse :-)
- Arnaldo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf util: optimize util/machine.c:machines__find().
2013-11-22 0:06 ` Arnaldo Carvalho de Melo
@ 2013-11-22 18:59 ` Dongsheng Yang
0 siblings, 0 replies; 4+ messages in thread
From: Dongsheng Yang @ 2013-11-22 18:59 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo; +Cc: David Ahern, mingo, linux-kernel
On 11/21/2013 07:06 PM, Arnaldo Carvalho de Melo wrote:
>
>> This changes machines__find to always return the machine for the
>> host (pid == 0). This function is also used for VM lookups.
> Nope:
>
> /* Native host kernel uses -1 as pid index in machine */
> #define HOST_KERNEL_ID (-1)
> #define DEFAULT_GUEST_KERNEL_ID (0)
>
> But I fail to see the point of the "optimization", we're looking for a
> pid, not always for '0'.
>
> And the changelog is horrible, why is it "unnecessary"? Please don't be
> so terse :-)
>
> - Arnaldo
>
Hi David and Arnaldo,
It is my mistake about it!! The original code does the right thing.
Sorry to bother you, I am a newbie for perf.
I will send a patch after second and third thought next time.
Thanx for your reply.
- Yang
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-11-22 6:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-21 21:31 [PATCH] perf util: optimize util/machine.c:machines__find() Dongsheng Yang
2013-11-21 21:16 ` David Ahern
2013-11-22 0:06 ` Arnaldo Carvalho de Melo
2013-11-22 18:59 ` Dongsheng Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox