From bbfb296c26b042013d6cf008fc329a508703733f Mon Sep 17 00:00:00 2001 From: Balazs Gerofi Date: Fri, 10 Jan 2020 15:51:01 +0900 Subject: [PATCH] TO RESET: mcreboot, mcstop+release.sh: add functions Change-Id: Ic3992dc4e16b7ade00e93edbd107c64a32068c02 --- scripts/mcreboot-lwk.sh.in | 99 ++++++++++++++++++++++++++++++++ scripts/mcreboot-smp.sh.in | 16 +++++- scripts/mcstop+release-smp.sh.in | 10 +++- 3 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 scripts/mcreboot-lwk.sh.in diff --git a/scripts/mcreboot-lwk.sh.in b/scripts/mcreboot-lwk.sh.in new file mode 100644 index 00000000..9b8d71a3 --- /dev/null +++ b/scripts/mcreboot-lwk.sh.in @@ -0,0 +1,99 @@ +#!/bin/bash +# IHK/McKernel user priviledge reboot script. +# author: Balazs Gerofi +# Copyright (C) 2019 RIKEN +# +prefix="@prefix@" +BINDIR="${prefix}/bin" +SBINDIR="${prefix}/sbin" +KERNDIR="@MCKERNELDIR@" + +mem="" +cpus="" +ikc_map="" + +while getopts c:m:r: OPT +do + case ${OPT} in + c) cpus=${OPTARG} + ;; + m) mem=${OPTARG} + ;; + r) ikc_map=${OPTARG} + ;; + \?) exit 1 + ;; + esac +done + +if [ "${ikc_map}" == "" ]; then + # Query IKC map + if ! ${SBINDIR}/ihkosctl 0 get ikc_map > /dev/null; then + echo "error: querying IKC map" >&2 + exit 1 + fi + + ikc_map=`${SBINDIR}/ihkosctl 0 get ikc_map` +fi + + +# Shutdown OS +if ! ${SBINDIR}/ihkosctl 0 shutdown; then + echo "error: shuting down OS" >&2 + exit 1 +fi + +sleep 2 + +# Query IHK-SMP resources and reassign +if ! ${SBINDIR}/ihkconfig 0 query cpu > /dev/null; then + echo "error: querying cpus" >&2 + exit 1 +fi + +cpus=`${SBINDIR}/ihkconfig 0 query cpu` +if [ "${cpus}" == "" ]; then + echo "error: querying CPUs" >&2 + exit 1 +fi + +# Assign CPUs +if ! ${SBINDIR}/ihkosctl 0 assign cpu ${cpus}; then + echo "error: assign CPUs" >&2 + exit 1 +fi + +# Assign memory +for i in `seq 0 15`; do + if ! ${SBINDIR}/ihkosctl 0 assign mem all@${i}; then + echo "error: assign memory" >&2 + exit 1 + fi +done + +if [ "${ikc_map}" != "" ]; then + # Set IKC map + if ! ${SBINDIR}/ihkosctl 0 set ikc_map ${ikc_map}; then + echo "error: setting IKC map" >&2 + exit 1 + fi +fi + +# Load kernel image +if ! ${SBINDIR}/ihkosctl 0 load ${KERNDIR}/mckernel.img; then + echo "error: loading kernel image: ${KERNDIR}/mckernel.img" >&2 + exit 1 +fi + +# Set kernel arguments +if ! ${SBINDIR}/ihkosctl 0 kargs "hidos dump_level=24"; then + echo "error: setting kernel arguments" >&2 + exit 1 +fi + +# Boot OS instance +if ! ${SBINDIR}/ihkosctl 0 boot; then + echo "error: booting" >&2 + exit 1 +fi + diff --git a/scripts/mcreboot-smp.sh.in b/scripts/mcreboot-smp.sh.in index d2237967..9729cfbb 100644 --- a/scripts/mcreboot-smp.sh.in +++ b/scripts/mcreboot-smp.sh.in @@ -65,8 +65,9 @@ umask_old=`umask` idle_halt="" allow_oversubscribe="" time_sharing="time_sharing" +force_reserve="no" -while getopts stk:c:m:o:f:r:q:i:d:e:hOT: OPT +while getopts stk:c:m:o:f:r:q:i:d:e:hROT: OPT do case ${OPT} in f) facility=${OPTARG} @@ -97,6 +98,8 @@ do ;; O) allow_oversubscribe="allow_oversubscribe" ;; + R) force_reserve="yes" + ;; T) case ${OPTARG} in 1) time_sharing="time_sharing" @@ -343,6 +346,17 @@ if ! grep ihk_smp_@ARCH@ /proc/modules &>/dev/null; then fi fi +if [ ${force_reserve} == "yes" ]; then + if ! ${SUDO} ${SBINDIR}/ihkconfig 0 reserve mem ${mem}; then + echo "error: reserving memory" >&2 + error_exit "ihk_smp_loaded" + fi + if ! ${SUDO} ${SBINDIR}/ihkconfig 0 reserve cpu ${cpus}; then + echo "error: reserving CPUs" >&2; + error_exit "mem_reserved" + fi +fi + # Load mcctrl if not loaded if ! grep mcctrl /proc/modules &>/dev/null; then if ! taskset -c 0 ${SUDO} insmod ${KMODDIR}/mcctrl.ko 2>/dev/null; then diff --git a/scripts/mcstop+release-smp.sh.in b/scripts/mcstop+release-smp.sh.in index 5910f2cc..f714e585 100644 --- a/scripts/mcstop+release-smp.sh.in +++ b/scripts/mcstop+release-smp.sh.in @@ -18,9 +18,10 @@ KERNDIR="@KERNDIR@" mem="" cpus="" kill_in_use="" +dont_unload="no" RMMOD_PATH=/sbin/rmmod -while getopts r:k OPT +while getopts r:kR OPT do case ${OPT} in r) @@ -29,6 +30,9 @@ do k) kill_in_use=1 ;; + R) + dont_unload="yes" + ;; \?) exit 1 ;; esac @@ -115,6 +119,10 @@ if ! sudo ${SBINDIR}/ihkconfig 0 release mem "all" > /dev/null; then exit 1 fi +if [ "${dont_unload}" == "yes" ]; then + exit 0 +fi + # Remove delegator if loaded if grep mcctrl /proc/modules &>/dev/null; then if ! sudo ${RMMOD_PATH} mcctrl 2>/dev/null; then