提交 6c961062 编写于 作者: H hanxinke

atune: configuration items which are provided by shell script need to support...

atune: configuration items which are provided by shell script need to support backup and restore capabilities
上级 572d0db5
...@@ -54,7 +54,7 @@ class IrqAffinity(Configurator): ...@@ -54,7 +54,7 @@ class IrqAffinity(Configurator):
break break
return irq_id return irq_id
def _get(self, key): def _get(self, key, _):
irq_id = self.__get_irq_id(key) irq_id = self.__get_irq_id(key)
if irq_id is None: if irq_id is None:
err = LookupError("Fail to find irq {}".format(key)) err = LookupError("Fail to find irq {}".format(key))
......
...@@ -31,7 +31,7 @@ class ProcessidAffinity(Configurator): ...@@ -31,7 +31,7 @@ class ProcessidAffinity(Configurator):
def __init__(self, user=None): def __init__(self, user=None):
Configurator.__init__(self, user) Configurator.__init__(self, user)
def _get(self, key): def _get(self, key, _):
task_id = Utils.get_task_id(key) task_id = Utils.get_task_id(key)
task_id = " ".join(task_id) task_id = " ".join(task_id)
if task_id == "": if task_id == "":
......
...@@ -37,7 +37,7 @@ class TaskAffinity(Configurator): ...@@ -37,7 +37,7 @@ class TaskAffinity(Configurator):
self._set.__func__.__doc__ = Configurator._set.__doc__ % ( self._set.__func__.__doc__ = Configurator._set.__doc__ % (
'pid', 'cpumask in hex, no "0x" prefix, "," is permitted') 'pid', 'cpumask in hex, no "0x" prefix, "," is permitted')
def _get(self, key): def _get(self, key, _):
task_id = Utils.get_task_id(key) task_id = Utils.get_task_id(key)
if task_id is None: if task_id is None:
err = LookupError("Fail to find task {}".format(key)) err = LookupError("Fail to find task {}".format(key))
......
...@@ -37,7 +37,7 @@ class Bios(Configurator): ...@@ -37,7 +37,7 @@ class Bios(Configurator):
"Please change the BIOS configuration {key} to {val}.".format( "Please change the BIOS configuration {key} to {val}.".format(
key=key, val=value)) key=key, val=value))
def _get(self, key): def _get(self, key, _):
if key.lower() == "version": if key.lower() == "version":
output_dmi = subprocess.Popen(["dmidecode", "-t", "bios"], stdout=subprocess.PIPE, output_dmi = subprocess.Popen(["dmidecode", "-t", "bios"], stdout=subprocess.PIPE,
shell=False) shell=False)
......
...@@ -26,5 +26,5 @@ class Cmdline(Configurator): ...@@ -26,5 +26,5 @@ class Cmdline(Configurator):
def __init__(self, user=None): def __init__(self, user=None):
Configurator.__init__(self, user) Configurator.__init__(self, user)
def _get(self, key): def _get(self, key, _):
return Utils.get_value(key) return Utils.get_value(key)
...@@ -69,7 +69,7 @@ class Grub2(Configurator): ...@@ -69,7 +69,7 @@ class Grub2(Configurator):
end = search_obj.span(3) end = search_obj.span(3)
return {"START": start[0], "CMD": cmd[0], "END": end[1]} return {"START": start[0], "CMD": cmd[0], "END": end[1]}
def _get(self, key): def _get(self, key, _):
entry = self.__get_cfg_entry(self.__kernel_ver) entry = self.__get_cfg_entry(self.__kernel_ver)
with open(self.__cfg_file, 'r') as file: with open(self.__cfg_file, 'r') as file:
file.seek(entry["CMD"]) file.seek(entry["CMD"])
......
...@@ -97,7 +97,7 @@ class Configurator: ...@@ -97,7 +97,7 @@ class Configurator:
inspect.stack()[0][3], str(err)) inspect.stack()[0][3], str(err))
return err return err
if (ret == 0) and self.check(cfg[1], self.get(cfg[0])): if (ret == 0) and self.check(cfg[1], self.get(cfg[0], cfg[1])):
err = None err = None
elif cfg[1] is None: elif cfg[1] is None:
err = SetConfigError( err = SetConfigError(
...@@ -173,18 +173,19 @@ class Configurator: ...@@ -173,18 +173,19 @@ class Configurator:
inspect.stack()[0][3], str(err)) inspect.stack()[0][3], str(err))
raise err raise err
def get(self, key): def get(self, key, value=None):
""" """
Get the given config. Get the given config.
:param key: The config to be getted, string like "key" :param key: The config to be getted, string like "key"
:param value: The config to be getted, string like "value"
:returns None: Success :returns None: Success
:returns value: Success, config value string :returns value: Success, config value string
:returns Exceptions: Fail, error in _get() :returns Exceptions: Fail, error in _get()
:raises: None :raises: None
""" """
try: try:
ret = self._get(key) ret = self._get(key, value)
if ret is not None: if ret is not None:
ret = ret.replace('\n', ' ').strip() ret = ret.replace('\n', ' ').strip()
except Exception as err: except Exception as err:
...@@ -195,12 +196,13 @@ class Configurator: ...@@ -195,12 +196,13 @@ class Configurator:
return err return err
return ret return ret
def _get(self, key): def _get(self, key, value):
""" """
The inner method to get config. The inner method to get config.
The sub class should implement this method. The sub class should implement this method.
:param key: The config key :param key: The config key
:param value: The config value
:returns None: Success :returns None: Success
:returns value: Success, config value string :returns value: Success, config value string
:raises Exceptions: Fail, with info :raises Exceptions: Fail, with info
...@@ -239,18 +241,19 @@ class Configurator: ...@@ -239,18 +241,19 @@ class Configurator:
""" """
return config1 == config2 return config1 == config2
def _backup(self, key, _): def _backup(self, config, _):
""" """
The inner method to backup config. The inner method to backup config.
The sub class should implement this method if needed. The sub class should implement this method if needed.
:param key: The config key :param config: The config
:param rollback_info: The additional info for rollback, mostly a path :param rollback_info: The additional info for rollback, mostly a path
:returns value: Success, config info :returns value: Success, config info
:raises Exceptions: Fail, with info :raises Exceptions: Fail, with info
""" """
val = self._get(key).replace('\n', ' ').strip() cfg = self._getcfg(config)
return "{} = {}".format(key, val) val = self._get(cfg[0], cfg[1]).replace('\n', ' ').strip()
return "{} = {}".format(cfg[0], val)
def backup(self, config, rollback_info): def backup(self, config, rollback_info):
""" """
...@@ -262,9 +265,8 @@ class Configurator: ...@@ -262,9 +265,8 @@ class Configurator:
:returns value: Success, config info :returns value: Success, config info
:raises: None :raises: None
""" """
cfg = self._getcfg(config)
try: try:
ret = self._backup(cfg[0], rollback_info) ret = self._backup(config, rollback_info)
except Exception as err: except Exception as err:
if self._user == "UT": if self._user == "UT":
raise err raise err
......
...@@ -49,7 +49,7 @@ class KernelConfig(Configurator): ...@@ -49,7 +49,7 @@ class KernelConfig(Configurator):
"Please change the kernel configuration {key} to {val}.".format( "Please change the kernel configuration {key} to {val}.".format(
key=key, val=value)) key=key, val=value))
def _get(self, key): def _get(self, key, _):
file_type = os.path.splitext(self.__cfg_file)[-1] file_type = os.path.splitext(self.__cfg_file)[-1]
if file_type == ".gz": if file_type == ".gz":
with gzip.open(self.__cfg_file, 'rt') as file: with gzip.open(self.__cfg_file, 'rt') as file:
......
...@@ -52,15 +52,16 @@ class Script(Configurator): ...@@ -52,15 +52,16 @@ class Script(Configurator):
raise err raise err
return 0 return 0
def _get(self, key): def _get(self, key, value):
name = os.path.basename(key) name = os.path.basename(key)
script = "{}/get.sh".format(key) script = "{}/get.sh".format(key)
if not os.path.exists(script): if not os.path.exists(script):
raise GetConfigError("script {} not implement".format(script)) raise GetConfigError("script {} not implement".format(script))
output = subprocess.run( output = subprocess.run(
"{script}".format( "{script} {val}".format(
script=script).split(), script=script,
val=value).split(),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
shell=False, shell=False,
...@@ -76,9 +77,9 @@ class Script(Configurator): ...@@ -76,9 +77,9 @@ class Script(Configurator):
def check(_, __): def check(_, __):
return True return True
def _backup(self, key, rollback_info): def _backup(self, config, rollback_info):
name = os.path.basename(key) name = os.path.basename(config)
script = "{}/backup.sh".format(key) script = "{}/backup.sh".format(config)
if os.path.isfile(script): if os.path.isfile(script):
output = subprocess.run( output = subprocess.run(
"{script} {rb_info} {ver}".format( "{script} {rb_info} {ver}".format(
...@@ -95,7 +96,7 @@ class Script(Configurator): ...@@ -95,7 +96,7 @@ class Script(Configurator):
inspect.stack()[0][3], str(err)) inspect.stack()[0][3], str(err))
raise err raise err
return output.stdout.decode() return output.stdout.decode()
return Configurator._backup(self, key, rollback_info) return Configurator._backup(self, config, rollback_info)
def _resume(self, key, value): def _resume(self, key, value):
name = os.path.basename(key) name = os.path.basename(key)
......
...@@ -30,7 +30,7 @@ class Sysctl(Configurator): ...@@ -30,7 +30,7 @@ class Sysctl(Configurator):
Configurator.__init__(self, user) Configurator.__init__(self, user)
self.__cmd = "sysctl" self.__cmd = "sysctl"
def _get(self, key): def _get(self, key, _):
with open('/dev/null', 'w') as no_print: with open('/dev/null', 'w') as no_print:
output = subprocess.check_output("{cmd} -n {key}".format( output = subprocess.check_output("{cmd} -n {key}".format(
cmd=self.__cmd, key=key).split(), stderr=no_print) cmd=self.__cmd, key=key).split(), stderr=no_print)
......
...@@ -29,7 +29,7 @@ class Sysfs(Configurator): ...@@ -29,7 +29,7 @@ class Sysfs(Configurator):
def __init__(self, user=None): def __init__(self, user=None):
Configurator.__init__(self, user) Configurator.__init__(self, user)
def _get(self, key): def _get(self, key, _):
with open("{opt}/{key}".format(opt=self._option, key=key), mode='r', with open("{opt}/{key}".format(opt=self._option, key=key), mode='r',
buffering=-1, encoding=None, errors=None, newline=None, closefd=True) as file: buffering=-1, encoding=None, errors=None, newline=None, closefd=True) as file:
ret = file.read() ret = file.read()
......
...@@ -30,7 +30,7 @@ class Systemctl(Configurator): ...@@ -30,7 +30,7 @@ class Systemctl(Configurator):
Configurator.__init__(self, user) Configurator.__init__(self, user)
self.__cmd = "systemctl" self.__cmd = "systemctl"
def _get(self, key): def _get(self, key, _):
with open('/dev/null', 'w') as no_print: with open('/dev/null', 'w') as no_print:
output = subprocess.Popen( output = subprocess.Popen(
[self.__cmd, self._option, key], [self.__cmd, self._option, key],
...@@ -43,7 +43,7 @@ class Systemctl(Configurator): ...@@ -43,7 +43,7 @@ class Systemctl(Configurator):
def _set(self, key, value): def _set(self, key, value):
if not os.path.exists(self._path + key + ".service"): if not os.path.exists(self._path + key + ".service"):
return 0 return 0
status = self._get(key) status = self._get(key, value)
if status == "active" and value == "start" or status == "inactive" and value == "stop": if status == "active" and value == "start" or status == "inactive" and value == "stop":
return 0 return 0
with open('/dev/null', 'w') as no_print: with open('/dev/null', 'w') as no_print:
...@@ -55,10 +55,12 @@ class Systemctl(Configurator): ...@@ -55,10 +55,12 @@ class Systemctl(Configurator):
def check(_, __): def check(_, __):
return True return True
def _backup(self, key, _): def _backup(self, config, _):
val = self._get(key) cfg = self._getcfg(config)
val = self._get(cfg[0], cfg[1])
if val in ("active", "activating"): if val in ("active", "activating"):
val = "start" val = "start"
else: else:
val = "stop" val = "stop"
return "{} = {}".format(key, val) return "{} = {}".format(cfg[0], val)
...@@ -58,7 +58,7 @@ class Ulimit(Configurator): ...@@ -58,7 +58,7 @@ class Ulimit(Configurator):
domain=keyword[0], type=keyword[1], item=keyword[2], value=value)) domain=keyword[0], type=keyword[1], item=keyword[2], value=value))
return 0 return 0
def _get(self, key): def _get(self, key, _):
with open(self.__cfg_file, 'r') as file: with open(self.__cfg_file, 'r') as file:
info = file.read() info = file.read()
keyword = key.split(".") keyword = key.split(".")
......
...@@ -286,8 +286,8 @@ prefetch = off ...@@ -286,8 +286,8 @@ prefetch = off
ethtool = -K {network} gro on ethtool = -K {network} gro on
ethtool = -K {network} gso on ethtool = -K {network} gso on
ethtool = -K {network} tso on ethtool = -K {network} tso on
ethtool = -X {network} equal 32 hkey 6d:5a:56:da:25:5b:0e:c2:41:67:25:3d:43:a3:8f:b0:d0:ca:2b:cb:ae:7b:30:b4:77:cb:2d:a3:80:30:f2:0c:6a:42:b7:3b:be:ac:01:fa hfunc toeplitz ethtool = -X {network} hfunc toeplitz
swapoff = -a swap = -a off
[tip] [tip]
relogin into the system to enable limits setting = OS relogin into the system to enable limits setting = OS
...@@ -655,7 +655,7 @@ bind network interrupts to its affinity numa node = affinity ...@@ -655,7 +655,7 @@ bind network interrupts to its affinity numa node = affinity
[script] [script]
prefetch = off prefetch = off
ifconfig = {network} mtu 1500 ifconfig = {network} mtu 1500
ethtool = -c {network} adaptive-rx on ethtool = -C {network} adaptive-rx on
ethtool = -K {network} gro on ethtool = -K {network} gro on
ethtool = -K {network} gso on ethtool = -K {network} gso on
ethtool = -K {network} tso on ethtool = -K {network} tso on
...@@ -780,7 +780,7 @@ INSERT INTO tuned_item(property, item) VALUES("{user}.hard.nofile", "OS"); ...@@ -780,7 +780,7 @@ INSERT INTO tuned_item(property, item) VALUES("{user}.hard.nofile", "OS");
INSERT INTO tuned_item(property, item) VALUES("{user}.soft.nofile", "OS"); INSERT INTO tuned_item(property, item) VALUES("{user}.soft.nofile", "OS");
INSERT INTO tuned_item(property, item) VALUES("{user}.soft.stack", "OS"); INSERT INTO tuned_item(property, item) VALUES("{user}.soft.stack", "OS");
INSERT INTO tuned_item(property, item) VALUES("{user}.hard.stack", "OS"); INSERT INTO tuned_item(property, item) VALUES("{user}.hard.stack", "OS");
INSERT INTO tuned_item(property, item) VALUES("swapoff", "OS"); INSERT INTO tuned_item(property, item) VALUES("swap", "OS");
INSERT INTO tuned_item(property, item) VALUES("kernel.randomize_va_space", "OS"); INSERT INTO tuned_item(property, item) VALUES("kernel.randomize_va_space", "OS");
INSERT INTO tuned_item(property, item) VALUES("kernel.sched_cfs_bandwidth_slice_us", "OS"); INSERT INTO tuned_item(property, item) VALUES("kernel.sched_cfs_bandwidth_slice_us", "OS");
INSERT INTO tuned_item(property, item) VALUES("kernel.sched_migration_cost_ns", "OS"); INSERT INTO tuned_item(property, item) VALUES("kernel.sched_migration_cost_ns", "OS");
...@@ -831,4 +831,4 @@ INSERT INTO rule_tuned(name, class, expression, action, opposite_action, monitor ...@@ -831,4 +831,4 @@ INSERT INTO rule_tuned(name, class, expression, action, opposite_action, monitor
-- INSERT INTO tuned (class, name, type, value, range) VALUES("single_computer_intensive_jobs", "prefetech", "ENUM", "off", "on,off" ); -- INSERT INTO tuned (class, name, type, value, range) VALUES("single_computer_intensive_jobs", "prefetech", "ENUM", "off", "on,off" );
-- Schedule table -- Schedule table
INSERT INTO schedule (type, strategy) VALUES("all", "auto"); INSERT INTO schedule (type, strategy) VALUES("all", "auto");
\ No newline at end of file
#!/bin/sh
# Copyright (c) 2020 Huawei Technologies Co., Ltd.
# A-Tune is licensed under the Mulan PSL v1.
# You can use this software according to the terms and conditions of the Mulan PSL v1.
# You may obtain a copy of Mulan PSL v1 at:
# http://license.coscl.org.cn/MulanPSL
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v1 for more details.
# Create: 2020-02-06
declare -A kmap=(["gro"]="generic-receive-offload" ["gso"]="generic-segmentation-offload"
["tso"]="tcp-segmentation-offload" ["lro"]="large-receive-offload")
declare -A cmap=(["adaptive-rx"]="Adaptive" ["adaptive-tx"]="Adaptive")
koption="on off"
xoption="toeplitz xor crc32"
coption="on off"
function get_ethtool_value() {
OLD_IFS="$IFS"
IFS=" "
para=($*)
IFS="$OLD_IFS"
if [ "${#para[@]}" -lt 4 ]; then
echo "\033[31m the length of ethtool parameter must be greater than 4 \033[31m"
return 1
fi
option=${para[0]}
network=${para[1]}
case "$option" in
"-K")
value=$(ethtool -k "$network" | grep -w "${kmap["${para[2]}"]}" | awk '{print $2}')
if !(judge_value "$value" $koption); then
echo "\033[31m the last parameter of ethtool must select in [$koption] \033[31m"
return 1
fi
echo "-K $network "${para[2]}" $value"
;;
"-X")
for opt in $xoption; do
switch=$(ethtool -x "$network" | grep -w "$opt" | awk '{print $2}')
if [[ "$switch" == "on" ]]; then
value=$opt
break
fi
done
if !(judge_value "$value" $xoption); then
echo "\033[31m the last parameter of ethtool must select in [$xoption] \033[31m"
return 1
fi
out=$(echo "${para[@]}" | awk '{$NF="";print}')
echo "$out""$value"
;;
"-C")
line=2
[ "${para[2]}" == "adaptive-rx" ] && line=3
[ "${para[2]}" == "adaptive-tx" ] && line=5
value=$(ethtool -c "$network" | grep -w "${cmap["${para[2]}"]}" | awk "{print $"$line"}")
if !(judge_value "$value" $coption); then
echo "\033[31m the last parameter of ethtool must select in [$coption] \033[31m"
return 1
fi
echo "-C $network "${para[2]}" $value"
;;
*)
echo "\033[31m this option is not supported \033[31m" && return 1
;;
esac
}
function judge_value() {
if [ $# -lt 1 ]; then
echo "\033[31m the number of parameter must be greater than 1 \033[31m"
return 1
fi
value="$1"
shift
for para in $@; do
if [[ "$para" == "$value" ]]; then
return
fi
done
false
}
#!/bin/sh #!/bin/sh
# Copyright (c) 2019 Huawei Technologies Co., Ltd. # Copyright (c) 2020 Huawei Technologies Co., Ltd.
# A-Tune is licensed under the Mulan PSL v1. # A-Tune is licensed under the Mulan PSL v1.
# You can use this software according to the terms and conditions of the Mulan PSL v1. # You can use this software according to the terms and conditions of the Mulan PSL v1.
# You may obtain a copy of Mulan PSL v1 at: # You may obtain a copy of Mulan PSL v1 at:
...@@ -8,7 +8,17 @@ ...@@ -8,7 +8,17 @@
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR # IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE. # PURPOSE.
# See the Mulan PSL v1 for more details. # See the Mulan PSL v1 for more details.
# Create: 2019-10-29 # Create: 2020-02-06
RUN_HOME=$(
cd "$(dirname "$0")"
pwd
)
source "$RUN_HOME"/common.sh
command -v ethtool >/dev/null 2>&1
ret=$?
[ $ret -ne 0 ] && echo "\033[31m command ethtool is not exist \033[31m" && exit 1
get_ethtool_value "$@"
swapoff $*
exit $?
...@@ -10,5 +10,21 @@ ...@@ -10,5 +10,21 @@
# See the Mulan PSL v1 for more details. # See the Mulan PSL v1 for more details.
# Create: 2019-10-29 # Create: 2019-10-29
ethtool $* RUN_HOME=$(
exit $? cd "$(dirname "$0")"
pwd
)
source "$RUN_HOME"/common.sh
command -v ethtool >/dev/null 2>&1
ret=$?
[ $ret -ne 0 ] && echo "\033[31m command ethtool is not exist \033[31m" && exit 1
value=$(get_ethtool_value "$@")
if [[ "$value" == $(eval echo "$*") ]]; then
echo "no need to set"
exit 0
fi
ethtool "$@"
...@@ -12,12 +12,13 @@ ...@@ -12,12 +12,13 @@
MYPROF_PATH=~/.bash_tlbprof MYPROF_PATH=~/.bash_tlbprof
HugePages=`grep HugePages_Total /proc/meminfo | awk '{print $2}'` HugePages=$(grep HugePages_Total /proc/meminfo | awk '{print $2}')
if [ ${HugePages} = 0 ]; then if [ "${HugePages}" = 0 ]; then
rm -f ${MYPROF_PATH} rm -f ${MYPROF_PATH}
echo "0" && exit 0 echo "0" && exit 0
fi fi
[ -f ${MYPROF_PATH} ] && echo "1" && exit 0 [ -f ${MYPROF_PATH} ] && echo "1" && exit 0
echo "0" && exit 0 echo "0"
...@@ -13,32 +13,33 @@ ...@@ -13,32 +13,33 @@
SCRIPT=$(basename $0) SCRIPT=$(basename $0)
if [ $# != 1 ]; then if [ $# != 1 ]; then
echo "Usage: ${SCRIPT} 0:disable or 1:enable" echo "Usage: ${SCRIPT} 0:disable or 1:enable"
exit 1 exit 1
fi fi
PROF_PATH=~/.bash_profile PROF_PATH=~/.bash_profile
MYPROF_PATH=~/.bash_tlbprof MYPROF_PATH=~/.bash_tlbprof
HugePages=`grep HugePages_Total /proc/meminfo | awk '{print $2}'` HugePages=$(grep HugePages_Total /proc/meminfo | awk '{print $2}')
if [ ${HugePages} = 0 -o $1 = 0 ]; then if [ "${HugePages}" = 0 -o $1 = 0 ]; then
rm -f ${MYPROF_PATH} rm -f ${MYPROF_PATH}
exit 0 exit 0
fi fi
echo "export HUGETLB_MORECORE=yes" > ${MYPROF_PATH} echo "export HUGETLB_MORECORE=yes" >${MYPROF_PATH}
[ $? != 0 ] && exit 2 [ $? != 0 ] && exit 2
echo "export LD_PRELOAD=/usr/lib64/libhugetlbfs.so" >> ${MYPROF_PATH} echo "export LD_PRELOAD=/usr/lib64/libhugetlbfs.so" >>${MYPROF_PATH}
[ $? != 0 ] && exit 2 [ $? != 0 ] && exit 2
grep tlbprof ${PROF_PATH} > /dev/null grep tlbprof ${PROF_PATH} >/dev/null
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "if [ -f ${MYPROF_PATH} ]; then" >> ${PROF_PATH} echo "if [ -f ${MYPROF_PATH} ]; then" >>${PROF_PATH}
[ $? != 0 ] && exit 3 [ $? != 0 ] && exit 3
echo " . ${MYPROF_PATH}" >> ${PROF_PATH} echo " . ${MYPROF_PATH}" >>${PROF_PATH}
[ $? != 0 ] && exit 3 [ $? != 0 ] && exit 3
echo "fi" >> ${PROF_PATH} echo "fi" >>${PROF_PATH}
[ $? != 0 ] && exit 3 [ $? != 0 ] && exit 3
fi fi
exit 0 exit 0
#!/bin/sh
# Copyright (c) 2020 Huawei Technologies Co., Ltd.
# A-Tune is licensed under the Mulan PSL v1.
# You can use this software according to the terms and conditions of the Mulan PSL v1.
# You may obtain a copy of Mulan PSL v1 at:
# http://license.coscl.org.cn/MulanPSL
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v1 for more details.
# Create: 2020-02-08
command -v ifconfig >/dev/null 2>&1
ret=$?
[ $ret -ne 0 ] && echo "\033[31m command ifconfig is not exist \033[31m" && exit 1
OLD_IFS="$IFS"
IFS=" "
para=($*)
IFS="$OLD_IFS"
network=${para[0]}
value=$(ifconfig "$network" | grep -w "mtu" | awk '{print $4}')
echo "$network mtu $value"
...@@ -10,5 +10,9 @@ ...@@ -10,5 +10,9 @@
# See the Mulan PSL v1 for more details. # See the Mulan PSL v1 for more details.
# Create: 2019-10-29 # Create: 2019-10-29
ifconfig $* command -v ifconfig >/dev/null 2>&1
exit $? ret=$?
[ $ret -ne 0 ] && echo "\033[31m command ifconfig is not exist \033[31m" && exit 1
ifconfig "$@"
#!/bin/sh
# Copyright (c) 2020 Huawei Technologies Co., Ltd.
# A-Tune is licensed under the Mulan PSL v1.
# You can use this software according to the terms and conditions of the Mulan PSL v1.
# You may obtain a copy of Mulan PSL v1 at:
# http://license.coscl.org.cn/MulanPSL
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v1 for more details.
# Create: 2020-02-09
profile=/etc/profile
hisi_conf=$(cat "$profile" | grep -w "HISI_CONF_ENV" | awk -F "=" '{print $2}')
openss_lconf=$(cat "$profile" | grep -w "OPENSSL_CONF" | awk -F "=" '{print $2}')
if [ "$hisi_conf" != "" -a "$openss_lconf" != "" ]; then
echo 1
else
echo 0
fi
...@@ -11,102 +11,81 @@ ...@@ -11,102 +11,81 @@
# Create: 2019-10-29 # Create: 2019-10-29
SCRIPT=$(basename $0) SCRIPT=$(basename $0)
DIR=$(dirname $0) HPRE_HOME_PATH=$(
#echo $SCRIPT cd "$(dirname "$0")"
#echo $DIR pwd
)
HPRE_HOME_PATH=$(cd "$(dirname "$0")";pwd)
echo $HPRE_HOME_PATH
if [ $# != 1 ]; then if [ $# != 1 ]; then
echo "Usage: ${SCRIPT} 1:enable or 0: disable" echo "Usage: ${SCRIPT} 1:enable or 0:disable"
exit 1 exit 1
fi fi
#echo $1 if [ "$1" == "1" ]; then
#echo "Enable hpre"
if [ $1 == "1" ]; then if lspci | grep -q 'HPRE'; then
#echo "Enable hpre" echo " [check] This machine support HPRE device!"
else
echo "\033[31m This Machine can not support HPRE, try to upgrade bios to version 3.24.01 and re-power on the machine \033[0m"
if lspci | grep -q 'HPRE' ; then exit 1
echo " [check] This machine support HPRE device!" fi
else
echo "\033[31m This Machine can not support HPRE, try to upgrade bios to version 3.24.01 and re-power on the machine \033[0m"
exit 1
fi
if openssl version | grep -q 'OpenSSL' ; then
echo " [check] The openssl is installed, make sure its version is newer than 1.1.1"
else
echo "\033[31m NO openssl is installed, please installed it firstly! \033[31m"
exit 1
fi
if lsmod | grep -q 'hisi_hpre' ; then
echo " [check] The hpre kernel driver is detected"
else
echo "\033[31m No hpre kernel driver is detected, install the hpre driver firstlly! \033[31m"
exit 1
fi
if ls /usr/lib64/engines-1.1/ | grep -q "hpre2.so" ; then
echo " [check] Detect the hpre2 engine in the openssl engine libs"
else
echo "\033[31m No hpre2 engine in the openssl engine libs, install hpre2 engine into the openssl engine libs \033[31m"
exit 1
fi
if ls /usr/lib64 | grep -q "libwd.*" ; then
echo " [check] Detect the Union Acceleration Framework libwd.* in the /usr/lib64"
else
echo "\033[31m No Union Acceleration Framework is detected, install it to use hpre! \033[31m"
exit 1
fi
orig_openssl_conf=$(openssl version -d | awk '{print $2}' | sed 's/\"//g')
if [ ! -d "$orig_openssl_conf" ]; then
echo "Failed to Get orig openssl conf file: $orig_openssl_conf"
fi
orig_openssl_conf=$orig_openssl_conf"/openssl.cnf" if openssl version | grep -q 'OpenSSL'; then
echo " [check] The openssl is installed, make sure its version is newer than 1.1.1"
else
echo "\033[31m NO openssl is installed, please installed it firstly! \033[31m"
exit 1
fi
echo $orig_openssl_conf if lsmod | grep -q 'hisi_hpre'; then
echo " [check] The hpre kernel driver is detected"
else
echo "\033[31m No hpre kernel driver is detected, install the hpre driver firstlly! \033[31m"
exit 1
fi
cat ${HPRE_HOME_PATH}/openssl.cnf > ${HPRE_HOME_PATH}/openssl_hpre.cnf if ls /usr/lib64/engines-1.1/ | grep -q "hpre2.so"; then
cat $orig_openssl_conf >> ${HPRE_HOME_PATH}/openssl_hpre.cnf echo " [check] Detect the hpre2 engine in the openssl engine libs"
else
echo "\033[31m No hpre2 engine in the openssl engine libs, install hpre2 engine into the openssl engine libs \033[31m"
exit 1
fi
export HISI_CONF_ENV=${HPRE_HOME_PATH} if ls /usr/lib64 | grep -q "libwd.*"; then
export OPENSSL_CONF=${HPRE_HOME_PATH}/openssl_hpre.cnf echo " [check] Detect the Union Acceleration Framework libwd.* in the /usr/lib64"
else
echo "\033[31m No Union Acceleration Framework is detected, install it to use hpre! \033[31m"
exit 1
fi
sed -i '/export OPENSSL_CONF=/d' /etc/profile orig_openssl_conf=$(openssl version -d | awk '{print $2}' | sed 's/\"//g')
sed -i '/export HISI_CONF_ENV=/d' /etc/profile if [ ! -d "$orig_openssl_conf" ]; then
echo "Failed to Get orig openssl conf file: $orig_openssl_conf"
fi
echo "export HISI_CONF_ENV=${HPRE_HOME_PATH}" >> /etc/profile orig_openssl_conf=$orig_openssl_conf"/openssl.cnf"
echo "export OPENSSL_CONF=${HPRE_HOME_PATH}/openssl_hpre.cnf" >> /etc/profile cat "${HPRE_HOME_PATH}"/openssl.cnf >"${HPRE_HOME_PATH}"/openssl_hpre.cnf
cat "$orig_openssl_conf" >>"${HPRE_HOME_PATH}"/openssl_hpre.cnf
#alias openssl='HISI_CONF_ENV=${HPRE_HOME_PATH} OPENSSL_CONF=${HPRE_HOME_PATH}/openssl.cnf openssl' export HISI_CONF_ENV=${HPRE_HOME_PATH}
export OPENSSL_CONF=${HPRE_HOME_PATH}/openssl_hpre.cnf
source /etc/profile sed -i '/export OPENSSL_CONF=/d' /etc/profile
sed -i '/export HISI_CONF_ENV=/d' /etc/profile
echo -e "\033[31m Please execute cmd 'source /etc/profile' and restart application (e.g. nginx) to make hpre in use! \033[0m" echo "export HISI_CONF_ENV=${HPRE_HOME_PATH}" >>/etc/profile
echo "export OPENSSL_CONF=${HPRE_HOME_PATH}/openssl_hpre.cnf" >>/etc/profile
source /etc/profile
echo -e "\033[31m Please execute cmd 'source /etc/profile' and restart application (e.g. nginx) to make hpre in use! \033[0m"
else else
echo "Disable hpre" echo "Disable hpre"
sed -i '/export OPENSSL_CONF=/d' /etc/profile
sed -i '/export HISI_CONF_ENV=/d' /etc/profile
#sed -e ''
echo "export HISI_CONF_ENV=" >> /etc/profile sed -i '/export OPENSSL_CONF=/d' /etc/profile
echo "export OPENSSL_CONF=" >> /etc/profile sed -i '/export HISI_CONF_ENV=/d' /etc/profile
#source ${HPRE_HOME_PATH}/nohpre_env.sh echo "export HISI_CONF_ENV=" >>/etc/profile
echo "export OPENSSL_CONF=" >>/etc/profile
fi fi
exit 0
...@@ -10,14 +10,6 @@ ...@@ -10,14 +10,6 @@
# See the Mulan PSL v1 for more details. # See the Mulan PSL v1 for more details.
# Create: 2019-10-29 # Create: 2019-10-29
SCRIPT=$(basename $0)
SCRIPT_PATH=$(cd "$(dirname "$0")";pwd)
if [ $# != 0 ]; then
echo "Usage: ${SCRIPT}"
exit 1
fi
lsmod | grep prefetch_tuning &> /dev/null lsmod | grep prefetch_tuning &> /dev/null
[ $? != 0 ] && echo "reset" && exit 0 [ $? != 0 ] && echo "reset" && exit 0
...@@ -35,3 +27,4 @@ case "$policy" in ...@@ -35,3 +27,4 @@ case "$policy" in
esac esac
exit 0 exit 0
...@@ -11,40 +11,44 @@ ...@@ -11,40 +11,44 @@
# Create: 2019-10-29 # Create: 2019-10-29
SCRIPT=$(basename $0) SCRIPT=$(basename $0)
SCRIPT_PATH=$(cd "$(dirname "$0")";pwd) SCRIPT_PATH=$(
cd "$(dirname "$0")"
pwd
)
if [ $# != 1 ]; then if [ $# != 1 ]; then
echo "Usage: ${SCRIPT} on or off" echo "Usage: ${SCRIPT} on or off"
exit 1 exit 1
fi fi
lsmod | grep prefetch_tuning &> /dev/null lsmod | grep prefetch_tuning &>/dev/null
uninstall=$? uninstall=$?
case "$1" in case "$1" in
"on") "on")
policy=15 policy=15
;; ;;
"off") "off")
policy=0 policy=0
;; ;;
"reset") "reset")
if [ ${uninstall} = 0 ]; then if [ ${uninstall} = 0 ]; then
rmmod prefetch_tuning rmmod prefetch_tuning
fi fi
exit 0 exit 0
;; ;;
*) *)
exit 2 exit 2
;; ;;
esac esac
if [ ${uninstall} != 0 ]; then if [ ${uninstall} != 0 ]; then
modprobe prefetch_tuning modprobe prefetch_tuning
[ $? != 0 ] && exit 3 [ $? != 0 ] && exit 3
fi fi
echo ${policy} > /sys/class/misc/prefetch/policy echo ${policy} >/sys/class/misc/prefetch/policy
[ $? != 0 ] && exit 4 [ $? != 0 ] && exit 4
exit 0 exit 0
#!/bin/sh
# Copyright (c) 2020 Huawei Technologies Co., Ltd.
# A-Tune is licensed under the Mulan PSL v1.
# You can use this software according to the terms and conditions of the Mulan PSL v1.
# You may obtain a copy of Mulan PSL v1 at:
# http://license.coscl.org.cn/MulanPSL
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v1 for more details.
# Create: 2020-02-08
command -v swapon >/dev/null 2>&1
ret=$?
[ $ret -ne 0 ] && echo "\033[31m command swapon is not exist \033[31m" && exit 1
out=$(echo "$@" | awk '{$NF="";print}')
value=$(swapon -s)
if [[ "$value" != "" ]]; then
echo "$out""on"
else
echo "$out""off"
fi
#!/bin/sh
# Copyright (c) 2019 Huawei Technologies Co., Ltd.
# A-Tune is licensed under the Mulan PSL v1.
# You can use this software according to the terms and conditions of the Mulan PSL v1.
# You may obtain a copy of Mulan PSL v1 at:
# http://license.coscl.org.cn/MulanPSL
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v1 for more details.
# Create: 2019-10-29
command -v swapoff >/dev/null 2>&1
ret=$?
[ $ret -ne 0 ] && echo "\033[31m command swapoff is not exist \033[31m" && exit 1
command -v swapon >/dev/null 2>&1
ret=$?
[ $ret -ne 0 ] && echo "\033[31m command swapon is not exist \033[31m" && exit 1
value=$(echo "$@" | awk '{$NF="";print}')
option=$(echo "$@" | awk '{print $NF}')
case "$option" in
"off")
swapoff $(eval echo "$value")
;;
"on")
swapon $(eval echo "$value")
;;
*)
echo "\033[31m this command option is not supported \033[31m" && exit 1
;;
esac
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册