lkml.org 
[lkml]   [2020]   [Jan]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 4/9] perf tools: Maintain cgroup hierarchy
On Thu, Jan 9, 2020 at 7:01 AM Jiri Olsa <jolsa@redhat.com> wrote:
>
> On Tue, Jan 07, 2020 at 10:34:56PM +0900, Namhyung Kim wrote:
>
> SNIP
>
> > + while (*p != NULL) {
> > + parent = *p;
> > + cgrp = rb_entry(parent, struct cgroup, node);
> > +
> > + if (cgrp->id == id)
> > + return cgrp;
> > +
> > + if (cgrp->id < id)
> > + p = &(*p)->rb_left;
> > + else
> > + p = &(*p)->rb_right;
> > + }
> > +
> > + cgrp = malloc(sizeof(*cgrp));
> > + if (cgrp == NULL)
> > + return NULL;
> > +
> > + cgrp->name = strdup(path);
> > + if (cgrp->name == NULL) {
> > + free(cgrp);
> > + return NULL;
> > + }
> > +
> > + cgrp->fd = -1;
> > + cgrp->id = id;
> > + refcount_set(&cgrp->refcnt, 1);
> > +
> > + rb_link_node(&cgrp->node, parent, p);
> > + rb_insert_color(&cgrp->node, &cgroup_tree);
> > +
> > + return cgrp;
> > +}
> > +
> > +struct cgroup *cgroup__find_by_path(const char *path)
> > +{
> > + struct rb_node *node;
> > +
> > + node = rb_first(&cgroup_tree);
> > + while (node) {
> > + struct cgroup *cgrp = rb_entry(node, struct cgroup, node);
> > +
> > + if (!strcmp(cgrp->name, path))
> > + return cgrp;
>
> you have it sorted on ids, but only search by path,
> why don't we sort it on path right away?

No, actually it only used cgroup__findnew() not __find_by_path().
I don't remember why I added this - will remove..

Thanks
Namhyung

\
 
 \ /
  Last update: 2020-01-09 01:56    [W:0.122 / U:0.404 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site