[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140319133815.GA25953@redhat.com>
Date: Wed, 19 Mar 2014 09:38:15 -0400
From: Don Zickus <dzickus@...hat.com>
To: Jiri Olsa <jolsa@...hat.com>
Cc: acme@...stprotocols.net, LKML <linux-kernel@...r.kernel.org>,
jmario@...hat.com, fowles@...each.com, eranian@...gle.com
Subject: Re: [PATCH 04/19] perf: Allow ability to map cpus to nodes easily
On Wed, Mar 19, 2014 at 01:48:27PM +0100, Jiri Olsa wrote:
> On Fri, Feb 28, 2014 at 12:42:53PM -0500, Don Zickus wrote:
> > This patch figures out the max number of cpus and nodes that are on the
>
> SNIP
>
> > +
> > +int cpu_map__setup_cpunode_map(void)
> > +{
> > + struct dirent *dent1, *dent2;
> > + DIR *dir1, *dir2;
> > + unsigned int cpu, mem;
> > + char buf[PATH_MAX];
> > +
> > + /* initialize globals */
> > + if (init_cpunode_map())
> > + return -1;
> > +
> > + dir1 = opendir(PATH_SYS_NODE);
> > + if (!dir1)
> > + return 0;
> > +
> > + /* walk tree and setup map */
> > + while ((dent1 = readdir(dir1)) != NULL) {
> > + if (dent1->d_type != DT_DIR ||
> > + sscanf(dent1->d_name, "node%u", &mem) < 1)
> > + continue;
> > +
> > + snprintf(buf, PATH_MAX, "%s/%s", PATH_SYS_NODE, dent1->d_name);
> > + dir2 = opendir(buf);
> > + if (!dir2)
> > + continue;
> > + while ((dent2 = readdir(dir2)) != NULL) {
> > + if (dent2->d_type != DT_LNK ||
> > + sscanf(dent2->d_name, "cpu%u", &cpu) < 1)
> > + continue;
> > + cpunode_map[cpu] = mem;
> > + }
> > + closedir(dir2);
> > + }
> > + closedir(dir1);
> > + return 0;
> > +}
> > +
> > diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
> > index b123bb9..d6fde2b 100644
> > --- a/tools/perf/util/cpumap.h
> > +++ b/tools/perf/util/cpumap.h
> > @@ -4,6 +4,9 @@
> > #include <stdio.h>
> > #include <stdbool.h>
> >
> > +#include "perf.h"
> > +#include "util/debug.h"
> > +
> > struct cpu_map {
> > int nr;
> > int map[];
> > @@ -46,4 +49,36 @@ static inline bool cpu_map__empty(const struct cpu_map *map)
> > return map ? map->map[0] == -1 : true;
> > }
> >
> > +int max_cpu_num;
> > +int max_node_num;
> > +int *cpunode_map;
> > +
> > +int cpu_map__setup_cpunode_map(void);
> > +
> > +static inline int cpu_map__max_node(void)
> > +{
> > + if (unlikely(!max_node_num))
> > + pr_debug("cpu_map not initiailzed\n");
> > +
> > + return max_node_num;
> > +}
> > +
> > +static inline int cpu_map__max_cpu(void)
> > +{
> > + if (unlikely(!max_cpu_num))
> > + pr_debug("cpu_map not initiailzed\n");
> > +
> > + return max_cpu_num;
> > +}
> > +
> > +static inline int cpu_map__get_node(int cpu)
> > +{
> > + if (unlikely(cpunode_map == NULL)) {
> > + pr_debug("cpu_map not initialized\n");
> > + return -1;
> > + }
> > +
> > + return cpunode_map[cpu];
> > +}
>
> cool, maybe above function names should not have 'cpu_map..',
> it's like pure cpu-ish stuff, maybe:
>
> setup_cpunode_map
> cpu__max_node
> cpu__max_cpu
> cpu__get_node
>
> or something like that ;-)
Sure. That works for me. :-)
Cheers,
Don
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists