Hi Brice,

> > 
> > GREPLINES=$(lstopo --physical --cpuset - | wc -l)
> > lstopo --physical --cpuset - | grep -B${GREPLINES} "PU p#1\b" | grep Core
> > | tail -1
> 
> sed should reduce this dramatically, for instance with:
>   lstopo --physical --cpuset - | sed -n -e '0,/PU p#1/p' | grep Core |
> tail -1
> and probably something even more simple.

Good point! Thanks!


> 
> > With first grep I will get all lines before the line with processor I'm
> > interested in.
> > 
> > With second grep I will get information about Cores and finally I will
> > pick up the last line. (So it's first line with keyword Core before the
> > line with processor.)
> > 
> > Is there a better way to do it?
> 
> hwloc-calc is probably the best tool for such computations, but I don't
> see any easy way to find which object of a given type covers a given
> cpuset or set of objects. Except for PUs and NUMA nodes: we have
> --pulist and --nodelist which print a comma-separated list of object
> numbers. So you should be able to get the NUMA node you're looking for with
>    hwloc-calc --physical proc:1 --nodelist
> (assuming you want OS/physical indexes for both input and output).

hwloc-calc --physical proc:1 --nodelist is another useful hint!

It's much better than this piece of code:-)
======================================================
lstopo --physical --cpuset - | 
grep -B${GREPLINES} "PU p#1\b" | 
grep NUMANode | 
tail -1 | 
perl -nle "print for m/NUMANode p#([0-9]*)/g"
======================================================

I need to get NUMAnode since I'm comparing numactl and taskset commands.

> By the way, if you want the socket and core OS/physical indexes, you
> should note that they may be unknown or non-unique in the system.
> Basically, only PUs and NUMA nodes have meaningful OS/physical indexes.

I know. I use Socket and Core only as debugging information.

> In C, it's trivial. Once you have a PU object, you just go up using
> ->parent and look at ->type until you find what you want. To get the
> initial PU object, you may use hwloc_get_pu_obj_by_os_index() if you
> have a OS/physical index as input, or hwloc_get_obj_by_type() if you
> have a logical index as input.

It sounds easy. I have already checked-out the source code of hwloc utils. API 
seems to be simple and clean, very easy to use. I will consider to write a 
small utility instead of chain of sed and grep.

Thanks a lot!
Jirka

Reply via email to