#!/bin/sh
#
# Create CPU partitions
#

RUN_SPECIFIC_FILE="/home/qlx/cfg/run_specific"

case "$1" in
  start)
  	if [ -e ${RUN_SPECIFIC_FILE} ]; then
		echo "SPI AFFINITY CHANGE - SLEEP 5 SECONDS"
		echo "Creating CPU partitions..."
		#enable the creation of cpuset folder
		mount -t tmpfs none /sys/fs/cgroup
		#create the cpuset folder and mount the cgroup filesystem
		mkdir /sys/fs/cgroup/cpuset/
		mount -t cgroup -o cpuset none /sys/fs/cgroup/cpuset/
		#create the partitions
		mkdir /sys/fs/cgroup/cpuset/rt
		mkdir /sys/fs/cgroup/cpuset/nrt

		# add the general purpose CPUs to the nRT set
#		echo 0,1 > /sys/fs/cgroup/cpuset/nrt/cpuset.cpus
		echo 1 > /sys/fs/cgroup/cpuset/nrt/cpuset.cpus
		# add the real-time CPUs to the RT set
#		echo 2,3 > /sys/fs/cgroup/cpuset/rt/cpuset.cpus
		echo 0,2,3 > /sys/fs/cgroup/cpuset/rt/cpuset.cpus
		# make CPUs in RT set exclusive
#		echo 1 > /sys/fs/cgroup/cpuset/rt/cpuset.cpu_exclusive

		# not NUMA-enabled
		# Associate the nRT and RT set with NUMA node 0
		echo 0 > /sys/fs/cgroup/cpuset/nrt/cpuset.mems
		echo 0 > /sys/fs/cgroup/cpuset/rt/cpuset.mems

		# Disable load balancing in the root cpuset. 
		# This is necessary for settings in the child cpusets to take effect
		echo 0 > /sys/fs/cgroup/cpuset/cpuset.sched_load_balance
		# disable load balancing in the RT cpuset
		echo 0 > /sys/fs/cgroup/cpuset/rt/cpuset.sched_load_balance
			# enable load balancing in the nRT cpuset
#		echo 1 > /sys/fs/cgroup/cpuset/nrt/cpuset.sched_load_balance
		echo 1 > /sys/fs/cgroup/cpuset/rt/cpuset.cpu_exclusive
	else
		echo "NO CPU Partitions"
		echo "RUN_GENERAL"
	fi;
	;;
  stop)
	;;
  restart|reload)
	"$0" stop
	"$0" start
	;;
  *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?

