From b8f166e6083add674ea364814bbd131e097ba8a5 Mon Sep 17 00:00:00 2001 From: Balazs Gerofi Date: Sat, 22 Aug 2015 18:55:53 +0900 Subject: [PATCH] mcreboot-smp-x86.sh: handle resource allocation after unloading; mcstop+release-smp-x86.sh --- Makefile.in | 3 +- arch/x86/tools/mcreboot-smp-x86.sh.in | 28 +++++++++--- arch/x86/tools/mcstop+release-smp-x86.sh.in | 47 +++++++++++++++++++++ configure | 3 +- configure.ac | 1 + 5 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 arch/x86/tools/mcstop+release-smp-x86.sh.in diff --git a/Makefile.in b/Makefile.in index 100e6e37..391d9684 100755 --- a/Makefile.in +++ b/Makefile.in @@ -44,7 +44,8 @@ install:: ;; \ smp-x86) \ mkdir -p -m 755 $(SBINDIR); \ - install -m 755 arch/x86/tools/mcreboot-smp-x86.sh $(SBINDIR)/mcreboot; \ + install -m 755 arch/x86/tools/mcreboot-smp-x86.sh $(SBINDIR)/mcreboot.sh; \ + install -m 755 arch/x86/tools/mcstop+release-smp-x86.sh $(SBINDIR)/mcstop+release.sh; \ mkdir -p -m 755 $(MANDIR)/man1; \ install -m 644 arch/x86/tools/mcreboot.1 $(MANDIR)/man1/mcreboot.1; \ ;; \ diff --git a/arch/x86/tools/mcreboot-smp-x86.sh.in b/arch/x86/tools/mcreboot-smp-x86.sh.in index 0a80e16c..15ab9938 100644 --- a/arch/x86/tools/mcreboot-smp-x86.sh.in +++ b/arch/x86/tools/mcreboot-smp-x86.sh.in @@ -19,14 +19,17 @@ KMODDIR="@KMODDIR@" KERNDIR="@KERNDIR@" mem="512M@0" +cpus="" -# Get the number of CPUs on NUMA node 0 -nr_cpus=`lscpu --parse | awk -F"," '{if ($4 == 0) print $4}' | wc -l` +if [ "$cpus" == "" ]; then + # Get the number of CPUs on NUMA node 0 + nr_cpus=`lscpu --parse | awk -F"," '{if ($4 == 0) print $4}' | wc -l` -# Use the second half of the cores -let nr_cpus="$nr_cpus / 2" -cpus=`lscpu --parse | awk -F"," '{if ($4 == 0) print $1}' | tail -n $nr_cpus | xargs echo -n | sed 's/ /,/g'` -if [ "$cpus" == "" ]; then echo "error: no available CPUs on NUMA node 0?"; exit; fi + # Use the second half of the cores + let nr_cpus="$nr_cpus / 2" + cpus=`lscpu --parse | awk -F"," '{if ($4 == 0) print $1}' | tail -n $nr_cpus | xargs echo -n | sed 's/ /,/g'` + if [ "$cpus" == "" ]; then echo "error: no available CPUs on NUMA node 0?"; exit; fi +fi # Remove delegator if loaded if [ "`lsmod | grep mcctrl`" != "" ]; then @@ -51,6 +54,19 @@ if [ "`lsmod | grep ihk_smp_x86`" == "" ]; then if ! insmod ${KMODDIR}/ihk-smp-x86.ko ihk_start_irq=$ihk_irq; then echo "error: loading ihk-smp-x86"; exit; fi; if ! ${SBINDIR}/ihkconfig 0 reserve cpu ${cpus}; then echo "error: reserving CPUs"; exit; fi if ! ${SBINDIR}/ihkconfig 0 reserve mem ${mem}; then echo "error: reserving memory"; exit; fi +# If loaded, but no resources allocated, get CPUs and memory +else + if ! ${SBINDIR}/ihkconfig 0 query cpu > /dev/null; then echo "error: querying cpus"; exit; fi + cpus_allocated=`${SBINDIR}/ihkosctl 0 query cpu` + if [ "$cpus_allocated" == "" ]; then + if ! ${SBINDIR}/ihkconfig 0 reserve cpu ${cpus}; then echo "error: reserving CPUs"; exit; fi + fi + + if ! ${SBINDIR}/ihkosctl 0 query mem > /dev/null; then echo "error: querying memory"; exit; fi + mem_allocated=`${SBINDIR}/ihkosctl 0 query mem` + if [ "$mem_allocated" == "" ]; then + if ! ${SBINDIR}/ihkconfig 0 reserve mem ${mem}; then echo "error: reserving memory"; exit; fi + fi fi # Check for existing OS instance and destroy diff --git a/arch/x86/tools/mcstop+release-smp-x86.sh.in b/arch/x86/tools/mcstop+release-smp-x86.sh.in new file mode 100644 index 00000000..d25789ad --- /dev/null +++ b/arch/x86/tools/mcstop+release-smp-x86.sh.in @@ -0,0 +1,47 @@ +#!/bin/bash + +# IHK SMP-x86 example McKernel unload script. +# author: Balazs Gerofi +# Copyright (C) 2015 RIKEN AICS +# +# This is an example script for destroying McKernel and releasing IHK resources +# Note that the script does no output anything unless an error occurs. + +prefix="@prefix@" +BINDIR="@BINDIR@" +SBINDIR="@SBINDIR@" +KMODDIR="@KMODDIR@" +KERNDIR="@KERNDIR@" + +mem="" +cpus="" + +# No SMP module? Exit. +if [ "`lsmod | grep ihk_smp_x86`" == "" ]; then exit; fi + +# Remove delegator if loaded +if [ "`lsmod | grep mcctrl`" != "" ]; then + if ! rmmod mcctrl; then echo "error: removing mcctrl"; exit; fi +fi + +# Destroy all LWK instances +for i in /dev/mcos*; do + ind=`echo $i|cut -c10-`; + if ! ${SBINDIR}/ihkconfig 0 destroy $ind; then echo "error: destroying LWK instance $ind failed"; exit; fi +done + +# Query IHK-SMP resources and release them +if ! ${SBINDIR}/ihkconfig 0 query cpu > /dev/null; then echo "error: querying cpus"; exit; fi +cpus=`${SBINDIR}/ihkconfig 0 query cpu` +if ! ${SBINDIR}/ihkconfig 0 release cpu $cpus > /dev/null; then echo "error: releasing CPUs"; exit; fi + +if ! ${SBINDIR}/ihkconfig 0 query mem > /dev/null; then echo "error: querying memory"; exit; fi +mem=`${SBINDIR}/ihkconfig 0 query mem` +if ! ${SBINDIR}/ihkconfig 0 release mem $mem > /dev/null; then echo "error: releasing memory"; exit; fi + +# Remove SMP module +if [ "`lsmod | grep ihk_smp_x86`" != "" ]; then + if ! rmmod ihk_smp_x86; then echo "error: removing ihk_smp_x86"; exit; fi +fi + + diff --git a/configure b/configure index d9d8c5ad..e529b2a6 100755 --- a/configure +++ b/configure @@ -3816,7 +3816,7 @@ TARGET="$WITH_TARGET" -ac_config_files="$ac_config_files Makefile executer/user/Makefile executer/kernel/Makefile kernel/Makefile kernel/Makefile.build arch/x86/tools/mcreboot-attached-mic.sh arch/x86/tools/mcshutdown-attached-mic.sh arch/x86/tools/mcreboot-builtin-x86.sh arch/x86/tools/mcreboot-smp-x86.sh arch/x86/tools/mcshutdown-builtin-x86.sh arch/x86/tools/mcreboot.1:arch/x86/tools/mcreboot.1in" +ac_config_files="$ac_config_files Makefile executer/user/Makefile executer/kernel/Makefile kernel/Makefile kernel/Makefile.build arch/x86/tools/mcreboot-attached-mic.sh arch/x86/tools/mcshutdown-attached-mic.sh arch/x86/tools/mcreboot-builtin-x86.sh arch/x86/tools/mcreboot-smp-x86.sh arch/x86/tools/mcstop+release-smp-x86.sh arch/x86/tools/mcshutdown-builtin-x86.sh arch/x86/tools/mcreboot.1:arch/x86/tools/mcreboot.1in" if test "x$enable_dcfa" = xyes; then : @@ -4539,6 +4539,7 @@ do "arch/x86/tools/mcshutdown-attached-mic.sh") CONFIG_FILES="$CONFIG_FILES arch/x86/tools/mcshutdown-attached-mic.sh" ;; "arch/x86/tools/mcreboot-builtin-x86.sh") CONFIG_FILES="$CONFIG_FILES arch/x86/tools/mcreboot-builtin-x86.sh" ;; "arch/x86/tools/mcreboot-smp-x86.sh") CONFIG_FILES="$CONFIG_FILES arch/x86/tools/mcreboot-smp-x86.sh" ;; + "arch/x86/tools/mcstop+release-smp-x86.sh") CONFIG_FILES="$CONFIG_FILES arch/x86/tools/mcstop+release-smp-x86.sh" ;; "arch/x86/tools/mcshutdown-builtin-x86.sh") CONFIG_FILES="$CONFIG_FILES arch/x86/tools/mcshutdown-builtin-x86.sh" ;; "arch/x86/tools/mcreboot.1") CONFIG_FILES="$CONFIG_FILES arch/x86/tools/mcreboot.1:arch/x86/tools/mcreboot.1in" ;; "kernel/Makefile.dcfa") CONFIG_FILES="$CONFIG_FILES kernel/Makefile.dcfa" ;; diff --git a/configure.ac b/configure.ac index fab17194..a478711c 100644 --- a/configure.ac +++ b/configure.ac @@ -167,6 +167,7 @@ AC_CONFIG_FILES([ arch/x86/tools/mcshutdown-attached-mic.sh arch/x86/tools/mcreboot-builtin-x86.sh arch/x86/tools/mcreboot-smp-x86.sh + arch/x86/tools/mcstop+release-smp-x86.sh arch/x86/tools/mcshutdown-builtin-x86.sh arch/x86/tools/mcreboot.1:arch/x86/tools/mcreboot.1in ])