Apply Jan Rekorajski's CPUSET patch.
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Tue, 12 Sep 2006 12:16:53 +0000 (12:16 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Tue, 12 Sep 2006 12:16:53 +0000 (12:16 +0000)
(http://www.paul.sladen.org/vserver/archives/200511/0245.html)

git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2300 94cd875c-1c1d-0410-91d2-eb244daf1a30

doc/configuration.xml
scripts/vserver-setup.functions
scripts/vserver.functions
scripts/vserver.start
scripts/vserver.stop
scripts/vserver.suexec

index 8866b7a..3b728b6 100644 (file)
@@ -1200,5 +1200,26 @@ tools and can *not* be modified.
         </scalar>
       </collection>
     </collection>
+
+    <collection name="cpuset">
+      <scalar name="name">
+        <description>The name of the cpuset for this vserver</description>
+      </scalar>
+      <scalar name="cpus">
+        <description>The list of CPUs in this cpuset</description>
+      </scalar>
+      <scalar name="mems">
+        <description>The list of Memory Nodes in this cpuset</description>
+      </scalar>
+      <scalar name="cpu_exclusive">
+        <description>Is the CPU assignment exclusive?</description>
+      </scalar>
+      <scalar name="mems_exclusive">
+        <description>Is the memory node assignment exclusive?</description>
+      </scalar>
+      <scalar name="nocreate">
+        <description>When this file exists, the cpuset will be assumed to exist already</description>
+      </scalar>
+    </collection>
   </collection>
   </database>
index aed47d3..cb484fd 100644 (file)
@@ -24,11 +24,15 @@ SETUP_LOCKFILE=
 SETUP_CONFDIR=
 SETUP_CONTEXT=
 SETUP_INITSTYLE=
+SETUP_CPUSET=
+SETUP_CPUSETCPUS=
+SETUP_CPUSETMEMS=
+SETUP_CPUSETVIRT=
 
 declare -a SETUP_INTERFACES=()
 declare -a SETUP_FLAGS=()
 
-declare -r SETUP_OPTIONS="confdir:,lockfile:,hostname:,netdev:,netmask:,netprefix:,netbcast:,interface:,flags:,context:,initstyle:"
+declare -r SETUP_OPTIONS="confdir:,lockfile:,hostname:,netdev:,netmask:,netprefix:,netbcast:,interface:,flags:,context:,initstyle:,cpuset:,cpusetcpus:,cpusetmems:,cpusetvirt"
 declare -r SETUP_HELPMSG=$"
     --context   ...  the static context of the vserver [default: none; a dynamic
                      context will be assumed]
@@ -55,6 +59,19 @@ declare -r SETUP_HELPMSG=$"
                            this becomes a per vserver limit)
                     private: No other process can join this security context.
                            Even root
+    --cpuset <name>
+                ...  declares the CPUSET this vserver will run in [default: none]
+    --cpusetcpus <number[-number][:<exclusive>]>
+                ...  sets which cpus belong to the CPUSET,
+                     exclusive is a flag (0|1) prohibiting any other cpuset from
+                     using those cpus
+    --cpusetmems <number[-number][:<exclusive>]>
+                ...  sets which memory pools belong to the CPUSET,
+                     exclusive is a flag (0|1) prohibiting any other cpuset from
+                     using those memory pools
+    --cpusetvirt
+                ...  virtualize cpuset (guest will see only CPUs defined in cpuset)
+                     Requires kernel patch from http://www.bullopensource.org/cpuset/
     --initstyle <style>
                 ...  configures the initstyle (e.g. minit,sysv,plain)
 "
@@ -71,7 +88,23 @@ function setup_setOption2
        (--netprefix)   SETUP_NETPREFIX=$2;;
        (--netbcast)    SETUP_NETBCAST=$2;;
        (--interface)   SETUP_INTERFACES=( "${SETUP_INTERFACES[@]}" "$2" );;
-       (--initstyle)   SETUP_INITSTYLE=$2;;
+       (--initstyle)   SETUP_INITSTYLE=$2;;
+       (--cpuset)      SETUP_CPUSET=$2;;
+       (--cpusetcpus)  old_IFS=$IFS
+                       IFS=:
+                       set -- $2
+                       SETUP_CPUSETCPUS=$1
+                       SETUP_CPUSETCPUSEXCL=$2
+                       IFS=$old_IFS
+                       ;;
+       (--cpusetmems)  old_IFS=$IFS
+                       IFS=:
+                       set -- $2
+                       SETUP_CPUSETMEMS=$1
+                       SETUP_CPUSETMEMSEXCL=$2
+                       IFS=$old_IFS
+                       ;;
+       (--cpusetvirt)  SETUP_CPUSETVIRT=1;;
        (--flags)       old_IFS=$IFS
                        IFS=,
                        set -- $2
@@ -140,7 +173,7 @@ function setup_writeOption
     local cfgdir=${SETUP_CONFDIR:?}
     local i
 
-    mkdir -p "$cfgdir"/interfaces "$cfgdir"/apps/init "$cfgdir"/uts
+    mkdir -p "$cfgdir"/interfaces "$cfgdir"/apps/init "$cfgdir"/uts "$cfgdir"/cpuset
 
     _setup_writeSingleOption "$name"            "$cfgdir"/name
     _setup_writeSingleOption "$SETUP_CONTEXT"   "$cfgdir"/context
@@ -150,6 +183,12 @@ function setup_writeOption
     _setup_writeSingleOption "$SETUP_NETPREFIX" "$cfgdir"/interfaces/prefix
     _setup_writeSingleOption "$SETUP_NETBCAST"  "$cfgdir"/interfaces/bcast
     _setup_writeSingleOption "$SETUP_INITSTYLE" "$cfgdir"/apps/init/style
+    _setup_writeSingleOption "$SETUP_CPUSET"    "$cfgdir"/cpuset/name
+    _setup_writeSingleOption "$SETUP_CPUSETCPUS"     "$cfgdir"/cpuset/cpus
+    _setup_writeSingleOption "$SETUP_CPUSETCPUSEXCL" "$cfgdir"/cpuset/cpus_exclusive
+    _setup_writeSingleOption "$SETUP_CPUSETMEMS"     "$cfgdir"/cpuset/mems
+    _setup_writeSingleOption "$SETUP_CPUSETMEMSEXCL" "$cfgdir"/cpuset/mem_exclusive
+    _setup_writeSingleOption "$SETUP_CPUSETVIRT"     "$cfgdir"/cpuset/virtualized
 
     local idx=0
     for i in "${SETUP_INTERFACES[@]}"; do
index 0f812d4..c6fa4b5 100644 (file)
@@ -689,6 +689,54 @@ function generateOptions
     fi
 }
 
+function addtoCPUSET
+{
+    local vdir=$1
+    local cpuset
+    local f="$vdir"/cpuset
+    local i
+    local configured=0
+
+    test -d "$f" || return 0
+    test -e "$f"/name || return 0
+
+    read cpuset < "$f"/name
+    test -e "$f"/nocreate || {
+       test -d /dev/cpuset/"$cpuset" || mkdir /dev/cpuset/"$cpuset" || configured=1
+       for i in cpus mems cpu_exclusive mem_exclusive virtualized; do
+           if test -e "$f"/"$i"; then
+               cat "$f"/"$i" >/dev/cpuset/"$cpuset"/"$i" 2>/dev/null || {
+                   configured=1
+                   break
+               }
+           fi
+       done
+    }
+
+    echo $$ >/dev/cpuset/"$cpuset"/tasks || configured=1
+    if [ "$configured" -ne 0 ]; then
+       warning $"\
+WARNING: Failed to create or CPUSET \"$cpuset\" does not exist! Not using it!" >&2
+       rmdir /dev/cpuset/"$cpuset" 2>/dev/null || :
+       return 0
+    fi
+}
+
+function removeCPUSET
+{
+    local vdir=$1
+    local cpuset
+    local f="$vdir"/cpuset
+
+    test -d "$f" || return 0
+    test -e "$f"/name || return 0
+
+    read cpuset < "$f"/name
+    test -e "$f"/nocreate || {
+       rmdir /dev/cpuset/"$cpuset" 2>/dev/null || :
+    }
+}
+
 function _mountVserverInternal
 {
     local fstab="$1"
index 7890c13..98a07cd 100644 (file)
@@ -113,6 +113,7 @@ enableInterfaces "$VSERVER_DIR" && have_interfaces=1
 
 mountVserver "$VSERVER_DIR"     && is_mounted=1
 prepareInit  "$VSERVER_DIR"
+addtoCPUSET  "$VSERVER_DIR"
 
 pushd "$VSERVER_DIR"/vdir/ >/dev/null
 execScriptlets   "$VSERVER_DIR" "$VSERVER_NAME" pre-start
index 79fb97a..9a5b292 100644 (file)
@@ -101,3 +101,4 @@ disableInterfaces "$VSERVER_DIR"
 saveDiskLimits    "$VSERVER_DIR"
 
 execScriptlets    "$VSERVER_DIR" "$VSERVER_NAME" postpost-stop
+removeCPUSET      "$VSERVER_DIR"
index 88f1ae4..bc6a7db 100644 (file)
@@ -22,6 +22,7 @@ test -z "$is_stopped" -o "$OPTION_INSECURE" || {
     exit 1
 }
 generateOptions  "$VSERVER_DIR"
+addtoCPUSET  "$VSERVER_DIR"
 
 user=$1
 shift