aboutsummaryrefslogtreecommitdiffstats
path: root/tools/hugepages.py
diff options
context:
space:
mode:
authorgoldammx <martinx.goldammer@intel.com>2017-02-09 08:03:00 -0500
committergoldammx <martinx.goldammer@intel.com>2017-02-13 06:21:28 -0500
commitca9c9275ed6d5d852987c69a378e88a3502cb2ab (patch)
tree23a28663a4db92cd1c409b887691650642f18023 /tools/hugepages.py
parentea4376cb3c89f4e3605d7f48036fd61325a52fcf (diff)
pylint: Fixing pylint errors and warnings
All python files must reach pylint score 10/10. This will be regularly verified by Jenkins jobs to keep constant code quality. VSPERF specific pylintrc file was updated according to the vsperf coding standards. Distro version included in reports will be slightly different, due to migration to new python package distro. Previously used platform.distro() will be deprecated since python 3.7. JIRA: VSPERF-487 Change-Id: I934120208b9624787a3567ccaa49e14d77d7a5bf Signed-off-by: Martin Goldammer <martinx.goldammer@intel.com> Reviewed-by: Martin Klozik <martinx.klozik@intel.com> Reviewed-by: Al Morton <acmorton@att.com> Reviewed-by: Christian Trautman <ctrautma@redhat.com> Reviewed-by: Bill Michalowski <bmichalo@redhat.com> Reviewed-by: Antonio Fischetti <antonio.fischetti@intel.com> Reviewed-by: Sridhar Rao <sridhar.rao@spirent.com>
Diffstat (limited to 'tools/hugepages.py')
-rw-r--r--tools/hugepages.py58
1 files changed, 29 insertions, 29 deletions
diff --git a/tools/hugepages.py b/tools/hugepages.py
index d233f04d..4c91e7d2 100644
--- a/tools/hugepages.py
+++ b/tools/hugepages.py
@@ -1,4 +1,4 @@
-# Copyright 2015-2016 Intel Corporation.
+# Copyright 2015-2017 Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ from tools import tasks
from conf import settings
_LOGGER = logging.getLogger(__name__)
-_allocated_hugepages = False
+_ALLOCATED_HUGEPAGES = False
#
# hugepage management
#
@@ -37,16 +37,15 @@ def get_hugepage_size():
"""
hugepage_size_re = re.compile(r'^Hugepagesize:\s+(?P<size_hp>\d+)\s+kB',
re.IGNORECASE)
- with open('/proc/meminfo', 'r') as fh:
- data = fh.readlines()
+ with open('/proc/meminfo', 'r') as result_file:
+ data = result_file.readlines()
for line in data:
match = hugepage_size_re.search(line)
if match:
_LOGGER.info('Hugepages size: %s kb', match.group('size_hp'))
return int(match.group('size_hp'))
- else:
- _LOGGER.error('Could not parse for hugepage size')
- return 0
+ _LOGGER.error('Could not parse for hugepage size')
+ return 0
def allocate_hugepages():
@@ -54,19 +53,20 @@ def allocate_hugepages():
"""
hp_size = get_hugepage_size()
if hp_size > 0:
- nr_hp = int(math.ceil(settings.getValue('HUGEPAGE_RAM_ALLOCATION')/hp_size))
- _LOGGER.info('Will allocate %s hugepages.', nr_hp)
-
- nr_hugepages = 'vm.nr_hugepages=' + str(nr_hp)
- try:
- tasks.run_task(['sudo', 'sysctl', nr_hugepages],
- _LOGGER, 'Trying to allocate hugepages..', True)
- except subprocess.CalledProcessError:
- _LOGGER.error('Unable to allocate hugepages.')
- return False
- global _allocated_hugepages
- _allocated_hugepages = True
- return True
+ nr_hp = int(math.ceil(settings.getValue('HUGEPAGE_RAM_ALLOCATION')/hp_size))
+ _LOGGER.info('Will allocate %s hugepages.', nr_hp)
+
+ nr_hugepages = 'vm.nr_hugepages=' + str(nr_hp)
+ try:
+ tasks.run_task(['sudo', 'sysctl', nr_hugepages],
+ _LOGGER, 'Trying to allocate hugepages..', True)
+ except subprocess.CalledProcessError:
+ _LOGGER.error('Unable to allocate hugepages.')
+ return False
+ # pylint: disable=global-statement
+ global _ALLOCATED_HUGEPAGES
+ _ALLOCATED_HUGEPAGES = True
+ return True
else:
_LOGGER.error('Division by 0 will be supported in next release')
@@ -75,8 +75,9 @@ def allocate_hugepages():
def deallocate_hugepages():
"""De-allocate hugepages that were allocated on the fly
"""
- global _allocated_hugepages
- if _allocated_hugepages:
+ # pylint: disable=global-statement
+ global _ALLOCATED_HUGEPAGES
+ if _ALLOCATED_HUGEPAGES:
nr_hugepages = 'vm.nr_hugepages= 0'
try:
tasks.run_task(['sudo', 'sysctl', nr_hugepages],
@@ -84,7 +85,7 @@ def deallocate_hugepages():
except subprocess.CalledProcessError:
_LOGGER.error('Unable to de-allocate hugepages.')
return False
- _allocated_hugepages = False
+ _ALLOCATED_HUGEPAGES = False
return True
@@ -102,22 +103,21 @@ def get_free_hugepages(socket=None):
meminfo_path = '/sys/devices/system/node/node{}/meminfo'.format(
socket)
else:
- _LOGGER.info('No hugepage info found for socket {}'.format(socket))
+ _LOGGER.info('No hugepage info found for socket %s', socket)
return 0
else:
meminfo_path = '/proc/meminfo'
- with open(meminfo_path, 'r') as fh:
- data = fh.readlines()
+ with open(meminfo_path, 'r') as result_file:
+ data = result_file.readlines()
for line in data:
match = hugepage_free_re.search(line)
if match:
_LOGGER.info('Hugepages free: %s %s', match.group('free_hp'),
'on socket {}'.format(socket) if socket else '')
return int(match.group('free_hp'))
- else:
- _LOGGER.info('Could not parse for hugepage size')
- return 0
+ _LOGGER.info('Could not parse for hugepage size')
+ return 0
def is_hugepage_available():