summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/hugepages.py45
-rw-r--r--tools/pkt_gen/moongen/moongen.py27
2 files changed, 65 insertions, 7 deletions
diff --git a/tools/hugepages.py b/tools/hugepages.py
index 3a434d6e..119f94b5 100644
--- a/tools/hugepages.py
+++ b/tools/hugepages.py
@@ -20,6 +20,7 @@ import re
import subprocess
import logging
import locale
+import math
from tools import tasks
from conf import settings
@@ -30,6 +31,46 @@ _LOGGER = logging.getLogger(__name__)
# hugepage management
#
+def get_hugepage_size():
+ """Return the size of the configured hugepages
+ """
+ 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()
+ for line in data:
+ match = hugepage_size_re.search(line)
+ if match:
+ _LOGGER.info('Hugepages size: %s', match.group('size_hp'))
+ return int(match.group('size_hp'))
+ else:
+ _LOGGER.error('Could not parse for hugepage size')
+ return 0
+
+
+
+def allocate_hugepages():
+ """Allocate hugepages on the fly
+ """
+ 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
+ return True
+
+ else:
+ _LOGGER.error('Division by 0 will be supported in next release')
+ return False
+
def is_hugepage_available():
"""Check if hugepages are available on the system.
@@ -47,8 +88,10 @@ def is_hugepage_available():
continue
num_huge = result.group('num_hp')
- if not num_huge:
+ if num_huge == '0':
_LOGGER.info('No free hugepages.')
+ if not allocate_hugepages():
+ return False
else:
_LOGGER.info('Found \'%s\' free hugepage(s).', num_huge)
return True
diff --git a/tools/pkt_gen/moongen/moongen.py b/tools/pkt_gen/moongen/moongen.py
index efd8e004..e14c6a79 100644
--- a/tools/pkt_gen/moongen/moongen.py
+++ b/tools/pkt_gen/moongen/moongen.py
@@ -20,10 +20,11 @@ Moongen Traffic Generator Model
"""
# python imports
-import logging
from collections import OrderedDict
-import subprocess
+import logging
+import math
import re
+import subprocess
# VSPerf imports
from conf import settings
@@ -49,6 +50,13 @@ class Moongen(ITrafficGenerator):
self._moongen_user = settings.getValue('TRAFFICGEN_MOONGEN_USER')
self._moongen_ports = settings.getValue('TRAFFICGEN_MOONGEN_PORTS')
+ if settings.getValue('TRAFFICGEN_MOONGEN_LINE_SPEED_GBPS') == '10':
+ self._moongen_line_speed = math.pow(10, 10)
+ else:
+ raise RuntimeError(
+ 'MOONGEN: Invalid line speed in configuration ' + \
+ 'file (today 10Gbps supported)')
+
@property
def traffic_defaults(self):
"""Default traffic values.
@@ -157,10 +165,17 @@ class Moongen(ITrafficGenerator):
if one_shot:
out_file.write("oneShot = true,\n")
- # Assume 10G line rates at the moment. Need to convert VSPERF
- # frame_rate (percentage of line rate) to Mpps for Moongen
+ # Need to convert VSPERF frame_rate (percentage of line rate)
+ # to Mpps for Moongen
+ start_rate = str(
+ (traffic['frame_rate'] / 100) * (self._moongen_line_speed / \
+ (8 * (traffic['l2']['framesize'] + 20)) / math.pow(10, 6)))
+
+ logging.debug("startRate = " + start_rate)
+
+ out_file.write("startRate = " + \
+ start_rate + "\n")
- out_file.write("startRate = " + str((traffic['frame_rate'] / 100) * 14.88) + "\n")
out_file.write("}" + "\n")
out_file.close()
@@ -476,7 +491,7 @@ class Moongen(ITrafficGenerator):
if results_match and parameters_match:
# Assume for now 10G link speed
max_theoretical_mfps = (
- (10000000000 / 8) / (frame_size + 20))
+ (self._moongen_line_speed / 8) / (frame_size + 20))
moongen_results[ResultsConstants.THROUGHPUT_RX_FPS] = (
float(results_match.group(6)) * 1000000)