Le 04/07/2010 23:34, Jirka Hladky a écrit :
> Hi folks,
>
> I need to get information about hwloc objects, particularly processor. I 
> would 
> love to get 
>
> NUMANode number
> Socket number
> Core number
>
> for given processor. 
>
> Currently, I'm parsing lstopo output but it's awkward:
>
> 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.

> 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).

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.

> Something like hwloc-info proc:1 ???
>   

hwloc-info is equivalent to lstopo -s IIRC. I made it this way to match
what plpa-info does.

> Or perhaps some c-api function to easily accomplish it?
>
>   

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.

Brice

Reply via email to