diff --git a/devicemodel/samples/apl-mrb/launch_uos.sh b/devicemodel/samples/apl-mrb/launch_uos.sh index 73c2dd7f8..c2be65a96 100755 --- a/devicemodel/samples/apl-mrb/launch_uos.sh +++ b/devicemodel/samples/apl-mrb/launch_uos.sh @@ -393,12 +393,79 @@ echo "-V 3 means launching 1 clearlinux UOS + 1 android UOS" echo "-V 4 means launching 2 clearlinux UOSs" echo "-V 5 means just launching 1 alios UOS" echo "-V 6 means auto check android/linux/alios UOS; if exist, launch it" +echo "-C means launching acrn-dm in runC container for QoS" } launch_type=1 debug=0 +runC_enable=0 -while getopts "V:M:hd" opt +function run_container() +{ +vm_name=vm1 +config_src="/usr/share/acrn/samples/apl-mrb/runC.json" +shell="/usr/share/acrn/conf/add/$vm_name.sh" +arg_file="/usr/share/acrn/conf/add/$vm_name.args" +runc_bundle="/usr/share/acrn/conf/add/runc/$vm_name" +rootfs_dir="/usr/share/acrn/conf/add/runc/rootfs" +config_dst="$runc_bundle/config.json" + + +input=$(runc list -f table | awk '{print $1}''{print $3}') +arr=(${input// / }) + +for((i=0;i<${#arr[@]};i++)) +do + if [ "$vm_name" = "${arr[$i]}" ]; then + if [ "running" = "${arr[$i+1]}" ]; then + echo "runC instance ${arr[$i]} is running" + exit + else + runc kill ${arr[$i]} + runc delete ${arr[$i]} + fi + fi +done +vmsts=$(acrnctl list) +vms=(${vmsts// / }) +for((i=0;i<${#vms[@]};i++)) +do + if [ "$vm_name" = "${vms[$i]}" ]; then + if [ "stopped" != "${vms[$i+1]}" ]; then + echo "Uos ${vms[$i]} ${vms[$i+1]}" + acrnctl stop ${vms[$i]} + fi + fi +done + +if [ ! -f "$shell" ]; then + echo "Pls add the vm at first!" + exit +fi + +if [ ! -f "$arg_file" ]; then + echo "Pls add the vm args!" + exit +fi + +if [ ! -d "$rootfs_dir" ]; then + mkdir -p "$rootfs_dir" +fi +if [ ! -d "$runc_bundle" ]; then + mkdir -p "$runc_bundle" +fi +if [ ! -f "$config_dst" ]; then + cp "$config_src" "$config_dst" + args=$(sed '{s/-C//g;s/^[ \t]*//g;s/^/\"/;s/ /\",\"/g;s/$/\"/}' ${arg_file}) + sed -i "s|\"sh\"|\"$shell\", $args|" $config_dst +fi +runc run --bundle $runc_bundle -d $vm_name +echo "The runC container is running in backgroud" +echo "'#runc exec bash' to login the container bash" +exit +} + +while getopts "V:M:hd:C" opt do case $opt in V) launch_type=$[$OPTARG] @@ -407,6 +474,8 @@ do ;; d) debug=1 ;; + C) runC_enable=1 + ;; h) help exit 1 ;; @@ -434,6 +503,15 @@ if [ $launch_type == 6 ]; then fi fi +if [ $runC_enable == 1 ]; then + if [ $(hostname) = "runc" ]; then + echo "Already in container exit!" + exit + fi + run_container + exit +fi + # offline SOS CPUs except BSP before launch UOS for i in `ls -d /sys/devices/system/cpu/cpu[1-99]`; do online=`cat $i/online`