~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/rcutorture/bin/kvm-assign-cpus.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/sh
  2 # SPDX-License-Identifier: GPL-2.0+
  3 #
  4 # Produce awk statements roughly depicting the system's CPU and cache
  5 # layout.  If the required information is not available, produce
  6 # error messages as awk comments.  Successful exit regardless.
  7 #
  8 # Usage: kvm-assign-cpus.sh /path/to/sysfs
  9 
 10 T="`mktemp -d ${TMPDIR-/tmp}/kvm-assign-cpus.sh.XXXXXX`"
 11 trap 'rm -rf $T' 0 2
 12 
 13 sysfsdir=${1-/sys/devices/system/node}
 14 if ! cd "$sysfsdir" > $T/msg 2>&1
 15 then
 16         sed -e 's/^/# /' < $T/msg
 17         exit 0
 18 fi
 19 nodelist="`ls -d node*`"
 20 for i in node*
 21 do
 22         if ! test -d $i/
 23         then
 24                 echo "# Not a directory: $sysfsdir/node*"
 25                 exit 0
 26         fi
 27         for j in $i/cpu*/cache/index*
 28         do
 29                 if ! test -d $j/
 30                 then
 31                         echo "# Not a directory: $sysfsdir/$j"
 32                         exit 0
 33                 else
 34                         break
 35                 fi
 36         done
 37         indexlist="`ls -d $i/cpu* | grep 'cpu[0-9][0-9]*' | head -1 | sed -e 's,^.*$,ls -d &/cache/index*,' | sh | sed -e 's,^.*/,,'`"
 38         break
 39 done
 40 for i in node*/cpu*/cache/index*/shared_cpu_list
 41 do
 42         if ! test -f $i
 43         then
 44                 echo "# Not a file: $sysfsdir/$i"
 45                 exit 0
 46         else
 47                 break
 48         fi
 49 done
 50 firstshared=
 51 for i in $indexlist
 52 do
 53         rm -f $T/cpulist
 54         for n in node*
 55         do
 56                 f="$n/cpu*/cache/$i/shared_cpu_list"
 57                 if ! cat $f > $T/msg 2>&1
 58                 then
 59                         sed -e 's/^/# /' < $T/msg
 60                         exit 0
 61                 fi
 62                 cat $f >> $T/cpulist
 63         done
 64         if grep -q '[-,]' $T/cpulist
 65         then
 66                 if test -z "$firstshared"
 67                 then
 68                         firstshared="$i"
 69                 fi
 70         fi
 71 done
 72 if test -z "$firstshared"
 73 then
 74         splitindex="`echo $indexlist | sed -e 's/ .*$//'`"
 75 else
 76         splitindex="$firstshared"
 77 fi
 78 nodenum=0
 79 for n in node*
 80 do
 81         cat $n/cpu*/cache/$splitindex/shared_cpu_list | sort -u -k1n |
 82         awk -v nodenum="$nodenum" '
 83         BEGIN {
 84                 idx = 0;
 85         }
 86 
 87         {
 88                 nlists = split($0, cpulists, ",");
 89                 for (i = 1; i <= nlists; i++) {
 90                         listsize = split(cpulists[i], cpus, "-");
 91                         if (listsize == 1)
 92                                 cpus[2] = cpus[1];
 93                         for (j = cpus[1]; j <= cpus[2]; j++) {
 94                                 print "cpu[" nodenum "][" idx "] = " j ";";
 95                                 idx++;
 96                         }
 97                 }
 98         }
 99 
100         END {
101                 print "nodecpus[" nodenum "] = " idx ";";
102         }'
103         nodenum=`expr $nodenum + 1`
104 done
105 echo "numnodes = $nodenum;"

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php