FastNetMon

Monday 18 February 2013

Linux: physical id/processor mapping

How to get list of logical cores per every physical cpu in Linux?

It's very tricky and we need use Perl:
cat /proc/cpuinfo |egrep '(^processor)|(physical id)' | awk -F": " '{printf $2 " "}'| perl -e '$_=<>; @list=split/\s+/,$_; $hs={}; while(scalar @list > 0) { ($a,$b) = (shift @list, shift @list); push @{$hs->{$b}}, $a;} for my $cpu (keys %$hs) {print "cpu:$cpu\n";print join ",", @{$hs->{$cpu}}; print "\n"}' 
Sample script output looks like:
cpu:1
6,7,8,9,10,11,18,19,20,21,22,23
cpu:0
0,1,2,3,4,5,12,13,14,15,16,17 
But we have a very simple solution (works pretty on 2.6.18/rhel5):
for i in `ls /sys/devices/system/node|grep node`; do cpu=$(echo $i|sed 's/node//'); echo -n "$cpu: "; cat /sys/devices/system/node/$i/cpulist|sed 's/-/../g' | perl -e 'print join ",", (eval(<>)); '; echo  ;done 
Sample output is very similar, but script is too short.
0: 0,1,2,3,4,5,12,13,14,15,16,17
1: 6,7,8,9,10,11,18,19,20,21,22,23
Sample content of cpilist elements in proc fs:

# cat /sys/devices/system/node/node1/cpulist
6-11,18-23
# cat /sys/devices/system/node/node0/cpulist
0-5,12-17

No comments :

Post a Comment

Note: only a member of this blog may post a comment.