diff --git a/scripts/mcreboot-smp.sh.in b/scripts/mcreboot-smp.sh.in index 93d28ab7..d2237967 100644 --- a/scripts/mcreboot-smp.sh.in +++ b/scripts/mcreboot-smp.sh.in @@ -48,9 +48,11 @@ mon_interval="-1" DUMP_LEVEL=24 facility="LOG_LOCAL6" chown_option=`id -un 2> /dev/null` +SUDO="sudo" # For the case when the entire script is run with sudo fall back to login name if [ "${chown_option}" == "root" ]; then chown_option=`logname 2> /dev/null` + SUDO="" fi irqbalance_used="no" @@ -111,7 +113,7 @@ done # Start ihkmond pid=`pidof ihkmond` if [ "${pid}" != "" ]; then - sudo kill -9 ${pid} > /dev/null 2> /dev/null + ${SUDO} kill -9 ${pid} > /dev/null 2> /dev/null fi if [ "${redirect_kmsg}" != "0" -o "${mon_interval}" != "-1" ]; then ${SBINDIR}/ihkmond -f ${facility} -k ${redirect_kmsg} -i ${mon_interval} @@ -120,13 +122,13 @@ fi disable_irqbalance_mck() { if [ -f /run/systemd/system/irqbalance.service.d/mckernel.conf ]; then for f in /run/sysconfig/irqbalance_mck_affinities/proc/irq/*/smp_affinity; do - cat "$f" | sudo tee "${f#/run/sysconfig/irqbalance_mck_affinities}" >/dev/null 2>&1 + cat "$f" | ${SUDO} tee "${f#/run/sysconfig/irqbalance_mck_affinities}" >/dev/null 2>&1 done - sudo rm -rf /run/systemd/system/irqbalance.service.d/mckernel.conf \ + ${SUDO} rm -rf /run/systemd/system/irqbalance.service.d/mckernel.conf \ /run/sysconfig/irqbalance_mck /run/sysconfig/irqbalance_mck_affinities - sudo rmdir /run/systemd/system/irqbalance.service.d 2>/dev/null - sudo systemctl daemon-reload - sudo systemctl restart irqbalance.service + ${SUDO} rmdir /run/systemd/system/irqbalance.service.d 2>/dev/null + ${SUDO} systemctl daemon-reload + ${SUDO} systemctl restart irqbalance.service fi } @@ -142,36 +144,36 @@ error_exit() { if ls /dev/mcos* 1>/dev/null 2>&1; then for i in /dev/mcos*; do ind=`echo $i|cut -c10-`; - if ! sudo ${SBINDIR}/ihkconfig 0 destroy $ind; then + if ! ${SUDO} ${SBINDIR}/ihkconfig 0 destroy $ind; then echo "warning: failed to destroy LWK instance $ind" >&2 fi done fi ;& mcctrl_loaded) - sudo rmmod mcctrl 2>/dev/null || echo "warning: failed to remove mcctrl" >&2 + ${SUDO} rmmod mcctrl 2>/dev/null || echo "warning: failed to remove mcctrl" >&2 ;& cpus_reserved) - cpus=`sudo ${SBINDIR}/ihkconfig 0 query cpu` + cpus=`${SUDO} ${SBINDIR}/ihkconfig 0 query cpu` if [ "${cpus}" != "" ]; then - if ! sudo ${SBINDIR}/ihkconfig 0 release cpu $cpus > /dev/null; then + if ! ${SUDO} ${SBINDIR}/ihkconfig 0 release cpu $cpus > /dev/null; then echo "warning: failed to release CPUs" >&2 fi fi ;& mem_reserved) - mem=`sudo ${SBINDIR}/ihkconfig 0 query mem` + mem=`${SUDO} ${SBINDIR}/ihkconfig 0 query mem` if [ "${mem}" != "" ]; then - if ! sudo ${SBINDIR}/ihkconfig 0 release mem $mem > /dev/null; then + if ! ${SUDO} ${SBINDIR}/ihkconfig 0 release mem $mem > /dev/null; then echo "warning: failed to release memory" >&2 fi fi ;& ihk_smp_loaded) - sudo rmmod ihk_smp_@ARCH@ 2>/dev/null || echo "warning: failed to remove ihk_smp_@ARCH@" >&2 + ${SUDO} rmmod ihk_smp_@ARCH@ 2>/dev/null || echo "warning: failed to remove ihk_smp_@ARCH@" >&2 ;& ihk_loaded) - sudo rmmod ihk 2>/dev/null || echo "warning: failed to remove ihk" >&2 + ${SUDO} rmmod ihk 2>/dev/null || echo "warning: failed to remove ihk" >&2 ;& smp_affinity_modified) umask $umask_old @@ -181,7 +183,7 @@ error_exit() { ;& irqbalance_stopped) if [ "${irqbalance_used}" == "yes" ]; then - if ! sudo systemctl start irqbalance.service; then + if ! ${SUDO} systemctl start irqbalance.service; then echo "warning: failed to start irqbalance" >&2; fi fi @@ -222,13 +224,13 @@ if [ "$cpus" == "" ]; then fi # Stop irqbalance and save irq affinities (only first mcreboot) -sudo systemctl stop irqbalance.service >/dev/null 2>&1 +${SUDO} systemctl stop irqbalance.service >/dev/null 2>&1 if [[ "${irqbalance_used}" == "yes" && ! -e "/run/sysconfig/irqbalance_mck_affinities" ]]; then for f in /proc/irq/*/smp_affinity; do copy=/run/sysconfig/irqbalance_mck_affinities/$f - sudo mkdir -p "${copy%/*}" - sudo cat $f | sudo tee "$copy" >/dev/null || error_exit "irqbalance_stopped" + ${SUDO} mkdir -p "${copy%/*}" + ${SUDO} cat $f | ${SUDO} tee "$copy" >/dev/null || error_exit "irqbalance_stopped" done # Prevent /proc/irq/*/smp_affinity from getting zero after offlining @@ -240,7 +242,7 @@ if [[ "${irqbalance_used}" == "yes" && ! -e "/run/sysconfig/irqbalance_mck_affin smp_affinity_mask=`echo $cpus | ncpus=$ncpus perl -e 'while(<>){@tokens = split /,/;foreach $token (@tokens) {@nums = split /-/,$token; for($num = $nums[0]; $num <= $nums[$#nums]; $num++) {$ndx=int($num/32); $mask[$ndx] |= (1<<($num % 32))}}} $nint32s = int(($ENV{'ncpus'}+31)/32); for($j = $nint32s - 1; $j >= 0; $j--) { if($j != $nint32s - 1){print ",";} $nblks = ($j != $nint32s - 1) ? 8 : ($ENV{'ncpus'} % 32 != 0) ? int((($ENV{'ncpus'} + 3) % 32) / 4) : 8; for($i = $nblks - 1;$i >= 0;$i--){ printf("%01x",($mask[$j] >> ($i*4)) & 0xf);}}'` # echo cpus=$cpus ncpus=$ncpus smp_affinity_mask=$smp_affinity_mask - if ! ncpus=$ncpus smp_affinity_mask=$smp_affinity_mask perl -e '@dirs = grep { -d } glob "/proc/irq/*"; foreach $dir (@dirs) { $hit = 0; $affinity_str = `sudo cat $dir/smp_affinity`; chomp $affinity_str; @int32strs = split /,/, $affinity_str; @int32strs_mask=split /,/, $ENV{'smp_affinity_mask'}; for($i=0;$i <= $#int32strs_mask; $i++) { $int32strs_inv[$i] = sprintf("%08x",hex($int32strs_mask[$i])^0xffffffff); if($i == 0) { $len = int((($ENV{'ncpus'}%32)+3)/4); if($len != 0) { $int32strs_inv[$i] = substr($int32strs_inv[$i], -$len, $len); } } } $inv = join(",", @int32strs_inv); $nint32s = int(($ENV{'ncpus'}+31)/32); for($j = $nint32s - 1; $j >= 0; $j--) { if(hex($int32strs[$nint32s - 1 - $j]) & hex($int32strs_mask[$nint32s - 1 - $j])) { $hit = 1; }} if($hit == 1) { system("echo $inv | sudo tee $dir/smp_affinity >/dev/null 2>&1")}}'; then + if ! ncpus=$ncpus smp_affinity_mask=$smp_affinity_mask perl -e '@dirs = grep { -d } glob "/proc/irq/*"; foreach $dir (@dirs) { $hit = 0; $affinity_str = `'${SUDO}' cat $dir/smp_affinity`; chomp $affinity_str; @int32strs = split /,/, $affinity_str; @int32strs_mask=split /,/, $ENV{'smp_affinity_mask'}; for($i=0;$i <= $#int32strs_mask; $i++) { $int32strs_inv[$i] = sprintf("%08x",hex($int32strs_mask[$i])^0xffffffff); if($i == 0) { $len = int((($ENV{'ncpus'}%32)+3)/4); if($len != 0) { $int32strs_inv[$i] = substr($int32strs_inv[$i], -$len, $len); } } } $inv = join(",", @int32strs_inv); $nint32s = int(($ENV{'ncpus'}+31)/32); for($j = $nint32s - 1; $j >= 0; $j--) { if(hex($int32strs[$nint32s - 1 - $j]) & hex($int32strs_mask[$nint32s - 1 - $j])) { $hit = 1; }} if($hit == 1) { system("echo $inv | '${SUDO}' tee $dir/smp_affinity >/dev/null 2>&1")}}'; then echo "error: modifying /proc/irq/*/smp_affinity" >&2 error_exit "irqbalance_stopped" fi @@ -253,22 +255,22 @@ umask 0`printf "%o" ${umask_dec}` # Load IHK if not loaded if ! grep -E 'ihk\s' /proc/modules &>/dev/null; then - if ! taskset -c 0 sudo insmod ${KMODDIR}/ihk.ko 2>/dev/null; then + if ! taskset -c 0 ${SUDO} insmod ${KMODDIR}/ihk.ko 2>/dev/null; then echo "error: loading ihk" >&2 error_exit "smp_affinity_modified" fi fi # Increase swappiness so that we have better chance to allocate memory for IHK -echo 100 | sudo tee /proc/sys/vm/swappiness 1>/dev/null +echo 100 | ${SUDO} tee /proc/sys/vm/swappiness 1>/dev/null # Drop Linux caches to free memory -sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches 1>/dev/null +${SUDO} sync && echo 3 | ${SUDO} tee /proc/sys/vm/drop_caches 1>/dev/null # Merge free memory areas into large, physically contigous ones -echo 1 | sudo tee /proc/sys/vm/compact_memory 1>/dev/null 2>/dev/null +echo 1 | ${SUDO} tee /proc/sys/vm/compact_memory 1>/dev/null 2>/dev/null -sudo sync +${SUDO} sync # Load IHK-SMP if not loaded and reserve CPUs and memory if ! grep ihk_smp_@ARCH@ /proc/modules &>/dev/null; then @@ -290,7 +292,7 @@ if ! grep ihk_smp_@ARCH@ /proc/modules &>/dev/null; then IHK_IRQ_ARG="ihk_start_irq=${ihk_irq}" fi - if ! taskset -c 0 sudo insmod ${KMODDIR}/ihk-smp-@ARCH@.ko ${IHK_IRQ_ARG} ihk_ikc_irq_core=$ihk_ikc_irq_core 2>/dev/null; then + if ! taskset -c 0 ${SUDO} insmod ${KMODDIR}/ihk-smp-@ARCH@.ko ${IHK_IRQ_ARG} ihk_ikc_irq_core=$ihk_ikc_irq_core 2>/dev/null; then echo "error: loading ihk-smp-@ARCH@" >&2 error_exit "ihk_loaded" fi @@ -299,20 +301,20 @@ if ! grep ihk_smp_@ARCH@ /proc/modules &>/dev/null; then if [ "`hostname | grep "c[0-9][0-9][0-9][0-9].ofp"`" != "" ] && [ "`cat /sys/devices/system/node/online`" == "0-7" ]; then for i in 0 1 2 3; do find /sys/devices/system/node/node$i/memory*/ -name "online" | while read f; do - echo 0 | sudo tee $f 2>/dev/null + echo 0 | ${SUDO} tee $f 2>/dev/null done find /sys/devices/system/node/node$i/memory*/ -name "online" | while read f; do - echo 1 | sudo tee $f 2>/dev/null + echo 1 | ${SUDO} tee $f 2>/dev/null done done for i in 4 5 6 7; do find /sys/devices/system/node/node$i/memory*/ -name "online" | while read f; do - echo 0 | sudo tee $f 2>/dev/null + echo 0 | ${SUDO} tee $f 2>/dev/null done done for i in 4 5 6 7; do find /sys/devices/system/node/node$i/memory*/ -name "online" | while read f; do - echo 1 | sudo tee $f 2>/dev/null + echo 1 | ${SUDO} tee $f 2>/dev/null done done fi @@ -321,21 +323,21 @@ if ! grep ihk_smp_@ARCH@ /proc/modules &>/dev/null; then if [ "`hostname | grep "c[0-9][0-9][0-9][0-9].ofp"`" != "" ] && [ "`cat /sys/devices/system/node/online`" == "0-1" ]; then for i in 1; do find /sys/devices/system/node/node$i/memory*/ -name "online" | while read f; do - echo 0 | sudo tee $f 2>/dev/null + echo 0 | ${SUDO} tee $f 2>/dev/null done done for i in 1; do find /sys/devices/system/node/node$i/memory*/ -name "online" | while read f; do - echo 1 | sudo tee $f 2>/dev/null + echo 1 | ${SUDO} tee $f 2>/dev/null done done fi - if ! sudo ${SBINDIR}/ihkconfig 0 reserve mem ${mem}; 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 + if ! ${SUDO} ${SBINDIR}/ihkconfig 0 reserve cpu ${cpus}; then echo "error: reserving CPUs" >&2; error_exit "mem_reserved" fi @@ -343,14 +345,14 @@ 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 + if ! taskset -c 0 ${SUDO} insmod ${KMODDIR}/mcctrl.ko 2>/dev/null; then echo "error: inserting mcctrl.ko" >&2 error_exit "cpus_reserved" fi fi # Check that different versions of binaries/scripts are not mixed -IHK_BUILDID=`sudo ${SBINDIR}/ihkconfig 0 get buildid` +IHK_BUILDID=`${SUDO} ${SBINDIR}/ihkconfig 0 get buildid` if [ "${IHK_BUILDID}" != "${MCK_BUILDID}" ]; then echo "IHK build-id (${IHK_BUILDID}) didn't match McKernel build-id (${MCK_BUILDID})." >&2 error_exit "mcctrl_loaded" @@ -362,7 +364,7 @@ if ls /dev/mcos* 1>/dev/null 2>&1; then ind=`echo $i|cut -c10-`; # Retry when conflicting with ihkmond nretry=0 - until sudo ${SBINDIR}/ihkconfig 0 destroy $ind || [ $nretry -ge 4 ]; do + until ${SUDO} ${SBINDIR}/ihkconfig 0 destroy $ind || [ $nretry -ge 4 ]; do sleep 0.25 nretry=$[ $nretry + 1 ] done @@ -374,51 +376,51 @@ if ls /dev/mcos* 1>/dev/null 2>&1; then fi # Create OS instance -if ! sudo ${SBINDIR}/ihkconfig 0 create; then +if ! ${SUDO} ${SBINDIR}/ihkconfig 0 create; then echo "error: creating OS instance" >&2 error_exit "mcctrl_loaded" fi # Assign CPUs -if ! sudo ${SBINDIR}/ihkosctl 0 assign cpu ${cpus}; then +if ! ${SUDO} ${SBINDIR}/ihkosctl 0 assign cpu ${cpus}; then echo "error: assign CPUs" >&2 error_exit "os_created" fi if [ "$ikc_map" != "" ]; then # Specify IKC map - if ! sudo ${SBINDIR}/ihkosctl 0 set ikc_map ${ikc_map}; then + if ! ${SUDO} ${SBINDIR}/ihkosctl 0 set ikc_map ${ikc_map}; then echo "error: assign CPUs" >&2 error_exit "os_created" fi fi # Assign memory -if ! sudo ${SBINDIR}/ihkosctl 0 assign mem ${mem}; then +if ! ${SUDO} ${SBINDIR}/ihkosctl 0 assign mem ${mem}; then echo "error: assign memory" >&2 error_exit "os_created" fi # Load kernel image -if ! sudo ${SBINDIR}/ihkosctl 0 load ${KERNDIR}/mckernel.img; then +if ! ${SUDO} ${SBINDIR}/ihkosctl 0 load ${KERNDIR}/mckernel.img; then echo "error: loading kernel image: ${KERNDIR}/mckernel.img" >&2 error_exit "os_created" fi # Set kernel arguments -if ! sudo ${SBINDIR}/ihkosctl 0 kargs "hidos $turbo $safe_kernel_map $idle_halt dump_level=${DUMP_LEVEL} $extra_kopts $allow_oversubscribe $time_sharing"; then +if ! ${SUDO} ${SBINDIR}/ihkosctl 0 kargs "hidos $turbo $safe_kernel_map $idle_halt dump_level=${DUMP_LEVEL} $extra_kopts $allow_oversubscribe $time_sharing"; then echo "error: setting kernel arguments" >&2 error_exit "os_created" fi # Boot OS instance -if ! sudo ${SBINDIR}/ihkosctl 0 boot; then +if ! ${SUDO} ${SBINDIR}/ihkosctl 0 boot; then echo "error: booting" >&2 error_exit "os_created" fi # Set device file ownership -if ! sudo chown ${chown_option} /dev/mcd* /dev/mcos*; then +if ! ${SUDO} chown ${chown_option} /dev/mcd* /dev/mcos*; then echo "warning: failed to chown device files" >&2 fi @@ -427,13 +429,13 @@ if [ "${irqbalance_used}" == "yes" ]; then banirq=`cat /proc/interrupts| perl -e 'while(<>) { if(/^\s*(\d+).*IHK\-SMP\s*$/) {print $1;}}'` sed -e "s/%mask%/$smp_affinity_mask/g" -e "s/%banirq%/$banirq/g" \ - "$ETCDIR/irqbalance_mck.in" | sudo tee /run/sysconfig/irqbalance_mck >/dev/null - sudo mkdir /run/systemd/system/irqbalance.service.d 2>/dev/null + "$ETCDIR/irqbalance_mck.in" | ${SUDO} tee /run/sysconfig/irqbalance_mck >/dev/null + ${SUDO} mkdir /run/systemd/system/irqbalance.service.d 2>/dev/null echo -e '[Service]\nEnvironmentFile=\nEnvironmentFile=/run/sysconfig/irqbalance_mck' | \ - sudo tee /run/systemd/system/irqbalance.service.d/mckernel.conf >/dev/null - sudo systemctl daemon-reload + ${SUDO} tee /run/systemd/system/irqbalance.service.d/mckernel.conf >/dev/null + ${SUDO} systemctl daemon-reload - if ! sudo systemctl restart irqbalance.service 2>/dev/null ; then + if ! ${SUDO} systemctl restart irqbalance.service 2>/dev/null ; then echo "error: restarting irqbalance with mckernelconfig" >&2 error_exit "mcos_sys_mounted" fi